r212 - in trunk/src/main/java/org/nuiton/scmwebeditor: . actions
Author: kcardineaud Date: 2011-08-12 10:50:11 +0200 (Fri, 12 Aug 2011) New Revision: 212 Url: http://nuiton.org/repositories/revision/scmwebeditor/212 Log: Add a method that get the last revision of a file, on the repository, in base action Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-08-11 13:11:10 UTC (rev 211) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-08-12 08:50:11 UTC (rev 212) @@ -36,8 +36,14 @@ import org.apache.tika.sax.BodyContentHandler; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNNodeKind; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.io.SVNRepository; +import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNUpdateClient; +import org.tmatesoft.svn.core.wc.SVNWCUtil; import org.xml.sax.SAXException; import com.opensymphony.xwork2.ActionContext; @@ -190,7 +196,12 @@ } } - + /** + * + * @param svnSess + * @param checkoutdir + * @throws SVNException + */ public void checkout(SvnConnection svnSess, File checkoutdir) throws SVNException { SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); @@ -204,6 +215,93 @@ } + /** + * + * @param svnFile + * @param username + * @param password + * @return + * @throws SVNException + * @throws IOException + */ + public String getHeadRevision(String address, String login, String password) throws SVNException { + + String lastRevision = ""; + + SvnConnection svnConn = null; + + svnConn = new SvnConnection(address); + + + String url = svnConn.getSvnPath(); + String file = svnConn.getFileName(); + + //Si le repo n'est pas protege en ecriture on recupere sont UUID + String repositoryUUID = svnConn.getUUID(); + if (repositoryUUID==null) { + repositoryUUID=address; + } + + + if(login==null && password==null) { + if(getScmSession().getUsername(repositoryUUID)!=null && getScmSession().getPassword(repositoryUUID)!=null) { + //On recupère les identifiants en session + login = getScmSession().getUsername(repositoryUUID); + password = getScmSession().getPassword(repositoryUUID); + } + else { + login = "anonymous"; + password = "anonymous"; + } + } + else { + getScmSession().addScmUser(repositoryUUID, login , password); + } + + + + SVNRepository repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url )); + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , password ); + repository.setAuthenticationManager( authManager ); + + SVNNodeKind nodeKind = repository.checkPath( file , -1 ); + + + if ( nodeKind == SVNNodeKind.NONE ) { + if(log.isErrorEnabled()) { + log.error( "There is no entry at '" + url + "'." ); + } + throw new IllegalArgumentException("There is no entry at '" + url + "'."); + } else if ( nodeKind == SVNNodeKind.DIR ) { + if(log.isErrorEnabled()) { + log.error( "The entry at '" + url + "' is a file while a directory was expected." ); + } + throw new IllegalArgumentException("The entry at '" + url + "' is a file while a directory was expected."); + } + + + ByteArrayOutputStream baos = new ByteArrayOutputStream( ); + + repository.getFile( file , -1 , null , baos ); + + lastRevision = baos.toString(); + + try { + baos.close(); + } catch (IOException e) { + if(log.isDebugEnabled()) { + log.debug("Can't close stream",e); + } + } + + return lastRevision; + } + + + /** + * Use to delete the checkout temp directory + * @param checkoutdir The dir temp directory + */ public void delTempDirectory(File checkoutdir) { try { FileUtils.deleteDirectory(checkoutdir); @@ -354,6 +452,8 @@ return getScmSession().getPassword(url); } + + Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java 2011-08-11 13:11:10 UTC (rev 211) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java 2011-08-12 08:50:11 UTC (rev 212) @@ -1,19 +1,10 @@ package org.nuiton.scmwebeditor.actions; -import java.io.ByteArrayOutputStream; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; -import org.nuiton.scmwebeditor.SvnConnection; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; -import org.tmatesoft.svn.core.io.SVNRepository; -import org.tmatesoft.svn.core.io.SVNRepositoryFactory; -import org.tmatesoft.svn.core.wc.SVNWCUtil; import com.opensymphony.xwork2.Action; @@ -59,94 +50,39 @@ public String execute() { - SvnConnection svnConn = null; - try { - svnConn = new SvnConnection(address); - } catch (StringIndexOutOfBoundsException e) { - if(log.isErrorEnabled()) { - log.error("Can't reach the svn repository"); - } - error = "errorPath"; - return "errorPath"; - } + + lastRevision = getHeadRevision(address, username, pw); - String url = svnConn.getSvnPath(); - String file = svnConn.getFileName(); - - String login = this.username; - String password = this.pw; - - //Si le repo n'est pas protege en ecriture on recupere sont UUID - String repositoryUUID = svnConn.getUUID(); - if (repositoryUUID==null) { - repositoryUUID=address; - } - - - if(login==null && password==null) { - if(getScmSession().getUsername(repositoryUUID)!=null && getScmSession().getPassword(repositoryUUID)!=null) { - //On recupère les identifiants en session - login = getScmSession().getUsername(repositoryUUID); - password = getScmSession().getPassword(repositoryUUID); - } - else { - login = "anonymous"; - password = "anonymous"; - } - } - else { - getScmSession().addScmUser(repositoryUUID, login , password); - } - - - try { - SVNRepository repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) ); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , password ); - repository.setAuthenticationManager( authManager ); - - SVNNodeKind nodeKind = repository.checkPath( file , -1 ); - - - if ( nodeKind == SVNNodeKind.NONE ) { + } catch (SVNAuthenticationException authexep) { if(log.isErrorEnabled()) { - log.error( "There is no entry at '" + url + "'." ); - } - return Action.SUCCESS; - } else if ( nodeKind == SVNNodeKind.DIR ) { - if(log.isErrorEnabled()) { - log.error( "The entry at '" + url + "' is a file while a directory was expected." ); - } - return Action.SUCCESS; - } - - - ByteArrayOutputStream baos = new ByteArrayOutputStream( ); - - repository.getFile( file , -1 , null , baos ); - - lastRevision=baos.toString(); - - - } - catch (SVNAuthenticationException authexep) { - if(log.isErrorEnabled()) { log.error("AUTH FAIL"); } error = "authError"; return "authError"; - } - catch (SVNException e) { + } catch (SVNException e1) { if(log.isErrorEnabled()) { log.error("Can't reach the svn repository"); } error = "errorPath"; return "errorPath"; - } + } catch (StringIndexOutOfBoundsException e) { + if(log.isErrorEnabled()) { + log.error("Can't reach the svn repository"); + } + error = "errorPath"; + return "errorPath"; + } catch (IllegalArgumentException e) { + if(log.isErrorEnabled()) { + log.error("Problem with file path",e); + } + error = "errorPath"; + return "errorPath"; + } return Action.SUCCESS; - + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-08-11 13:11:10 UTC (rev 211) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-08-12 08:50:11 UTC (rev 212) @@ -1,6 +1,5 @@ package org.nuiton.scmwebeditor.actions; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URL; import java.util.HashMap; @@ -20,11 +19,6 @@ import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolverEngine; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; -import org.tmatesoft.svn.core.io.SVNRepository; -import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import com.opensymphony.xwork2.Action; @@ -233,8 +227,6 @@ String login = this.getUsername(); String password = this.getPw(); - String url = svnConn.getSvnPath(); - String file = svnConn.getFileName(); //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = svnConn.getUUID(); @@ -263,44 +255,9 @@ svnConn.updateAuthentication(login, password); - SVNRepository repository = null; try { - repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) ); - ISVNAuthenticationManager authManager = svnConn.getAuthManager(); - repository.setAuthenticationManager( authManager ); - - SVNNodeKind nodeKind = repository.checkPath( file , -1 ); - - - - - if ( nodeKind == SVNNodeKind.NONE ) { - if(log.isErrorEnabled()) { - log.error( "There is no entry at '" + url + "'." ); - } - request.setAttribute("projectUrl", projectUrl); - return "errorPath"; - - } else if ( nodeKind == SVNNodeKind.DIR ) { - if(log.isErrorEnabled()) { - log.error( "The entry at '" + url + "' is a file while a directory was expected." ); - } - request.setAttribute("projectUrl", projectUrl); - if(log.isErrorEnabled()) { - log.error("Error with svn path or file "); - } - return "errorPath"; - } - - - ByteArrayOutputStream baos = new ByteArrayOutputStream( ); - - //On récupere le contenu du fichier, et on le met dans un outputStream - repository.getFile( file , -1 , null , baos ); - - originalText=baos.toString(); - baos.close(); + originalText = getHeadRevision(address, username, pw); } catch (SVNAuthenticationException authexep) { @@ -308,8 +265,10 @@ // if svn authentication failed user is redirected on login page if(log.isDebugEnabled()) { - log.debug("Private SCM on reading " + svnConn.getRemoteUrl()); + log.debug("Auth Fail " ,authexep); } + + getScmSession().delScmUser(repositoryUUID); //redirect to a login page return Action.LOGIN; @@ -320,12 +279,7 @@ log.error("SVN error ",e); } return "errorPath"; - } catch (IOException e) { - if(log.isErrorEnabled()) { - log.error("IO error ",e); - } - return "errorPath"; - } + } @@ -342,22 +296,6 @@ } - /* - String[] mimeTypes =null; - try { - mimeTypes = getMimeTypes(originalText, svnConn.getFileName()); - - log.info("size : "+mimeTypes.length); - - for (String element : mimeTypes){ - log.info("Type : "+element); - } - } catch (Exception e) { - log.error("tika error",e); - } - */ - - Properties properties=null; String[] editableFiles=null;
participants (1)
-
kcardineaud@users.nuiton.org