branch feature/GIT updated (8dc4c8d -> d8f2c22)
This is an automated email from the git hooks/post-receive script. New change to branch feature/GIT in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git from 8dc4c8d It is now possible to upload a new file to a Git repository new d8f2c22 Handling more errors and some messages are clearer The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit d8f2c2251fa58c2dd2b991fa6be496a1a0a72ac0 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Mon Apr 27 17:17:12 2015 +0200 Handling more errors and some messages are clearer Summary of changes: .../org/nuiton/scmwebeditor/GitConnection.java | 35 ++++++++-- .../nuiton/scmwebeditor/ScmConnectionFactory.java | 7 +- .../java/org/nuiton/scmwebeditor/ScmSession.java | 6 +- .../org/nuiton/scmwebeditor/SvnConnection.java | 24 +++---- .../nuiton/scmwebeditor/SweSessionListener.java | 4 ++ .../nuiton/scmwebeditor/actions/SearchAction.java | 78 +++++++++++----------- .../resources/i18n/scmwebeditor_en_GB.properties | 1 + .../resources/i18n/scmwebeditor_fr_FR.properties | 1 + src/main/webapp/WEB-INF/content/search.jsp | 6 +- src/main/webapp/WEB-INF/web.xml | 5 ++ 10 files changed, 100 insertions(+), 67 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/GIT in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git commit d8f2c2251fa58c2dd2b991fa6be496a1a0a72ac0 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Mon Apr 27 17:17:12 2015 +0200 Handling more errors and some messages are clearer --- .../org/nuiton/scmwebeditor/GitConnection.java | 35 ++++++++-- .../nuiton/scmwebeditor/ScmConnectionFactory.java | 7 +- .../java/org/nuiton/scmwebeditor/ScmSession.java | 6 +- .../org/nuiton/scmwebeditor/SvnConnection.java | 24 +++---- .../nuiton/scmwebeditor/SweSessionListener.java | 4 ++ .../nuiton/scmwebeditor/actions/SearchAction.java | 78 +++++++++++----------- .../resources/i18n/scmwebeditor_en_GB.properties | 1 + .../resources/i18n/scmwebeditor_fr_FR.properties | 1 + src/main/webapp/WEB-INF/content/search.jsp | 6 +- src/main/webapp/WEB-INF/web.xml | 5 ++ 10 files changed, 100 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/nuiton/scmwebeditor/GitConnection.java b/src/main/java/org/nuiton/scmwebeditor/GitConnection.java index d9a3bae..304b988 100644 --- a/src/main/java/org/nuiton/scmwebeditor/GitConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/GitConnection.java @@ -69,7 +69,7 @@ public class GitConnection implements ScmConnection { protected static final String MASTER_BRANCH = "master"; - public GitConnection(String address, String sessionId) throws IOException { + public GitConnection(String address, String sessionId) throws IOException, ScmNotFoundException { if(log.isDebugEnabled()) { log.debug("Git repository"); @@ -151,6 +151,7 @@ public class GitConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Can't clone the remote repository"); } + throw new ScmNotFoundException("Can not find a Git repository at address " + addressGit); } } @@ -164,6 +165,7 @@ public class GitConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("The repository at address " + addressGit + " doesn't exist"); + throw new ScmNotFoundException("The repository at address " + addressGit + " doesn't exist"); } } } @@ -181,6 +183,8 @@ public class GitConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Error while getting the head branch name", e); } + action.setError(true); + return SearchAction.SUCCESS; } action.setHeadBranchName(headBranchName); @@ -218,6 +222,8 @@ public class GitConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Can't access to the repository", e); } + action.setError(true); + return SearchAction.SUCCESS; } String id = action.getId(); @@ -238,11 +244,24 @@ public class GitConnection implements ScmConnection { if (!gitRepo.getObjectDatabase().exists()) { - action.setError("The repository at address " + address + " doesn't exist"); + action.setError(true); + return SearchAction.SUCCESS; } + RevCommit commit = null; RevWalk revWalk = new RevWalk(gitRepo); - RevCommit commit = revWalk.parseCommit(commitId); + + if (commitId != null) { + commit = revWalk.parseCommit(commitId); + } else { + + if (log.isDebugEnabled()) { + log.debug("Can not access to repository " + url); + } + action.setError(true); + + return SearchAction.SUCCESS; + } RevTree tree = commit.getTree(); // making a list of the repository's files and directories @@ -282,8 +301,12 @@ public class GitConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Can't access to the repository", e); } + action.setError(true); + return SearchAction.SUCCESS; } + action.setError(false); + return SearchAction.SUCCESS; } @@ -315,6 +338,10 @@ public class GitConnection implements ScmConnection { } // authentication + if (action.getUsername() == null || action.getPw() == null) { + return action.LOGIN; + } + CredentialsProvider credentials = new UsernamePasswordCredentialsProvider(action.getUsername(), action.getPw()); // applying the changes on the local file @@ -397,7 +424,7 @@ public class GitConnection implements ScmConnection { log.error("Can not push", e); } - return action.ERROR; + return action.LOGIN; } } catch (IOException e) { if (log.isErrorEnabled()) { diff --git a/src/main/java/org/nuiton/scmwebeditor/ScmConnectionFactory.java b/src/main/java/org/nuiton/scmwebeditor/ScmConnectionFactory.java index b9f5544..faac19c 100644 --- a/src/main/java/org/nuiton/scmwebeditor/ScmConnectionFactory.java +++ b/src/main/java/org/nuiton/scmwebeditor/ScmConnectionFactory.java @@ -2,6 +2,7 @@ package org.nuiton.scmwebeditor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.tmatesoft.svn.core.SVNException; import java.io.IOException; @@ -40,9 +41,9 @@ public class ScmConnectionFactory { try { scmConn = new SvnConnection(address); - } catch (StringIndexOutOfBoundsException e) { - if (log.isDebugEnabled()) { - log.debug("Parameter is not valid ", e); + } catch (SVNException e) { + if (log.isErrorEnabled()) { + log.error("Can not reach the repository", e); } } } else { diff --git a/src/main/java/org/nuiton/scmwebeditor/ScmSession.java b/src/main/java/org/nuiton/scmwebeditor/ScmSession.java index 947ed96..0bc0c8e 100644 --- a/src/main/java/org/nuiton/scmwebeditor/ScmSession.java +++ b/src/main/java/org/nuiton/scmwebeditor/ScmSession.java @@ -21,6 +21,7 @@ */ package org.nuiton.scmwebeditor; +import javax.servlet.http.HttpSession; import java.util.HashMap; import java.util.Map; @@ -62,10 +63,5 @@ public class ScmSession { } } - public String getUUID(String address) { - SvnConnection svnConnection = new SvnConnection(address); - return svnConnection.getRepositoryId(); - } - } diff --git a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java index 503d13d..2d5f7e1 100644 --- a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java @@ -77,23 +77,19 @@ public class SvnConnection implements ScmConnection { public File getCheckoutdir() { return checkoutdir; } - public SvnConnection(String address) throws StringIndexOutOfBoundsException { + public SvnConnection(String address) throws SVNException { if(log.isDebugEnabled()) { log.debug("SVN repository"); } - svnPath = address.substring(0, address.lastIndexOf("/")); - fileName = address.substring(address.lastIndexOf("/") + 1); + if (address.lastIndexOf("/") != -1){ + svnPath = address.substring(0, address.lastIndexOf("/")); + fileName = address.substring(address.lastIndexOf("/") + 1); + } addressSvn = address; - try { - remoteUrl = SVNURL.parseURIEncoded(svnPath); - } catch (SVNException e) { - if (log.isErrorEnabled()) { - log.error("Can't parse scmPath", e); - } - } + remoteUrl = SVNURL.parseURIEncoded(svnPath); authManager = SVNWCUtil.createDefaultAuthenticationManager(); svnOption = SVNWCUtil.createDefaultOptions(false); @@ -143,7 +139,7 @@ public class SvnConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Can't access to the repository", e); } - action.setError("Can't access to the repository"); + action.setError(true); } return SearchAction.ROOT; @@ -171,7 +167,7 @@ public class SvnConnection implements ScmConnection { if (log.isWarnEnabled()) { log.warn("There is no entry at '" + url + "'."); } - action.setError("There is no entry at '" + url + "'."); + action.setError(true); return SearchAction.SUCCESS; } else if (nodeKind == SVNNodeKind.FILE) { if (log.isDebugEnabled()) { @@ -201,13 +197,15 @@ public class SvnConnection implements ScmConnection { if (log.isErrorEnabled()) { log.error("Can't access to the repository"); } - action.setError("Can't access to the repository"); + action.setError(true); } if (log.isDebugEnabled()) { log.debug("Search success"); } + action.setError(false); + return SearchAction.SUCCESS; } diff --git a/src/main/java/org/nuiton/scmwebeditor/SweSessionListener.java b/src/main/java/org/nuiton/scmwebeditor/SweSessionListener.java index bd258ef..42e71a8 100644 --- a/src/main/java/org/nuiton/scmwebeditor/SweSessionListener.java +++ b/src/main/java/org/nuiton/scmwebeditor/SweSessionListener.java @@ -21,6 +21,10 @@ public class SweSessionListener implements HttpSessionListener { @Override public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { + if (log.isDebugEnabled()) { + log.debug("Session destroyed"); + } + String sessionId = httpSessionEvent.getSession().getId(); String localReposPath = ScmWebEditorConfig.getLocalRepositoriesPath(); diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java index 7ef3351..fdd4d52 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java @@ -53,7 +53,7 @@ public class SearchAction extends ScmWebEditorBaseAction { protected String pw; - protected String error; + protected boolean error; protected int numberOfFile; @@ -71,9 +71,9 @@ public class SearchAction extends ScmWebEditorBaseAction { protected String headBranchName; - public String getError() { return error; } + public boolean getError() { return error; } - public void setError(String error) { this.error = error; } + public void setError(boolean error) { this.error = error; } public String getList() { return list; } @@ -135,7 +135,7 @@ public class SearchAction extends ScmWebEditorBaseAction { try { scmConn = ScmConnectionFactory.createScmConnection(address, scmType, sessionId); } catch (ScmNotFoundException e) { - error = "Can't access to the repository"; + error = true; if (log.isErrorEnabled()) { log.error("Can not create a connection to the SCM", e); } @@ -145,46 +145,40 @@ public class SearchAction extends ScmWebEditorBaseAction { String returnCode = null; // getting the files and directories - try { - returnCode = scmConn.search(this); - } catch (NullPointerException e) { - error = "Can't access to the repository"; - if (log.isErrorEnabled()) { - log.error("Can't access to the repository", e); - } - return SUCCESS; - } + returnCode = scmConn.search(this); - if (returnCode != SUCCESS) { + if (files == null && directories == null) { return returnCode; } // building the tree - - for (String file : files) { - TreeNode node = new TreeNode(); - node.setId(file); - node.setTitle(file.substring(file.lastIndexOf("/") + 1)); - node.setState(TreeNode.NODE_STATE_LEAF); - node.setIcon("ui-icon-document"); - nodes.add(node); + if (files != null) { + for (String file : files) { + TreeNode node = new TreeNode(); + node.setId(file); + node.setTitle(file.substring(file.lastIndexOf("/") + 1)); + node.setState(TreeNode.NODE_STATE_LEAF); + node.setIcon("ui-icon-document"); + nodes.add(node); + } } + if (directories != null) { + Iterator<Entry<String, String>> iter1 = directories.entrySet().iterator(); + while (iter1.hasNext()) { + Map.Entry<String, String> ent = (Map.Entry<String, String>) iter1.next(); - Iterator<Entry<String, String>> iter1 = directories.entrySet().iterator(); - while (iter1.hasNext()) { - Map.Entry<String, String> ent = (Map.Entry<String, String>) iter1.next(); + String value = ent.getValue(); - String value = ent.getValue(); + TreeNode node = new TreeNode(); + node.setId(value); - TreeNode node = new TreeNode(); - node.setId(value); - - node.setTitle(value.substring(value.lastIndexOf("/"))); - nodes.add(node); + node.setTitle(value.substring(value.lastIndexOf("/"))); + nodes.add(node); + } } - return SUCCESS; + return returnCode; } @@ -228,18 +222,22 @@ public class SearchAction extends ScmWebEditorBaseAction { public String getBranchesJSON() { - String json = "{\"branches\":["; branches = GitConnection.getBranches(address); + String json = ""; - // creating the JSON String - for (String branch : branches) { - json += "{\"name\":\"" + branch + "\"},"; - } + if (branches.size() > 0) { + // creating the JSON String + json = "{\"branches\":["; - // we don't take the last coma - json = json.substring(0, json.length() - 2); + for (String branch : branches) { + json += "{\"name\":\"" + branch + "\"},"; + } + + // we don't take the last coma + json = json.substring(0, json.length() - 2); - json += "]}"; + json += "]}"; + } return json; } diff --git a/src/main/resources/i18n/scmwebeditor_en_GB.properties b/src/main/resources/i18n/scmwebeditor_en_GB.properties index a4798dc..4d897dd 100644 --- a/src/main/resources/i18n/scmwebeditor_en_GB.properties +++ b/src/main/resources/i18n/scmwebeditor_en_GB.properties @@ -5,6 +5,7 @@ scm.badUsernameOrPassword=Bad username or password scm.beTransferred=You should be transferred automatically to the new page. If not please scm.by=By scm.cannotSave=Can't save modification. +scm.cantFindRepo=Can't find the repository. scm.clickHere=click here scm.commitMessage=Commit message scm.commitMessageTitle=let a message for commit diff --git a/src/main/resources/i18n/scmwebeditor_fr_FR.properties b/src/main/resources/i18n/scmwebeditor_fr_FR.properties index fd98aff..1d144f0 100644 --- a/src/main/resources/i18n/scmwebeditor_fr_FR.properties +++ b/src/main/resources/i18n/scmwebeditor_fr_FR.properties @@ -5,6 +5,7 @@ scm.badUsernameOrPassword=Identifiant ou mot de passe incorrect scm.beTransferred=Vous devriez être redirigé sur une nouvelle page. si non scm.by=Par scm.cannotSave=Modification impossible +scm.cantFindRepo=Impossible de trouver le dépôt. scm.clickHere=cliquez ici scm.commitMessage=Message associé au commit scm.commitMessageTitle=laisser un message pour le commit diff --git a/src/main/webapp/WEB-INF/content/search.jsp b/src/main/webapp/WEB-INF/content/search.jsp index c9224a5..1621721 100644 --- a/src/main/webapp/WEB-INF/content/search.jsp +++ b/src/main/webapp/WEB-INF/content/search.jsp @@ -41,7 +41,7 @@ </script> -<s:if test="scmType.equals('Git')"> +<s:if test="scmType.equals('Git') && !error"> <s:text name="scm.outConnection.headBranch"/> <s:if test="selectedBranch != null"> <s:if test="selectedBranch != ''"> @@ -79,5 +79,7 @@ </div> -<s:label name="error"></s:label> +<s:if test="error"> + <s:text name="scm.cantFindRepo"/> +</s:if> diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 4cdb6bb..e4b3eb4 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -40,6 +40,11 @@ <welcome-file>/WEB-INF/content/index.jsp</welcome-file> </welcome-file-list> + <listener> + <description>sessionListener</description> + <listener-class>org.nuiton.scmwebeditor.SweSessionListener</listener-class> + </listener> + <listener> <description>Init</description> <listener-class>org.nuiton.scmwebeditor.ScmWebEditorApplicationListener</listener-class> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm