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 a2783b8f8eb4329954b90c630ed72c9adfaf96b7 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Thu May 7 17:31:13 2015 +0200 Fix the upload of a new file for SVN repositories --- .../org/nuiton/scmwebeditor/SvnConnection.java | 59 ++++++++++++---------- .../nuiton/scmwebeditor/actions/UploadAction.java | 1 - .../org/nuiton/scmwebeditor/dto/UploadDto.java | 11 ---- src/main/webapp/WEB-INF/content/uploadForm.jsp | 8 ++- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java index 46b2d50..677c8e3 100644 --- a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java @@ -92,14 +92,6 @@ public class SvnConnection implements ScmConnection { svnOption = SVNWCUtil.createDefaultOptions(false); svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); manager = SVNClientManager.newInstance(svnOption, authManager); - - try { - createCheckoutdir(); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can not create checkoutdir", e); - } - } } @@ -221,6 +213,14 @@ public class SvnConnection implements ScmConnection { @Override public CommitResultDto commit(CommitDto dto) { + try { + createCheckoutdir(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Can not create checkoutdir", e); + } + } + CommitResultDto resultDto = new CommitResultDto(); updateAuthentication(dto.getUsername(), dto.getPassword()); @@ -427,7 +427,7 @@ public class SvnConnection implements ScmConnection { } resultDto.setScmRoot(getSvnRoot(dto.getUsername(), dto.getPassword())); - resultDto.setFileRoot(addressSvn); + resultDto.setFileRoot(svnPath); if (resultDto.getScmRoot() == null) { resultDto.setScmRoot(resultDto.getFileRoot()); @@ -469,7 +469,7 @@ public class SvnConnection implements ScmConnection { */ SVNUpdateClient upclient = new SVNUpdateClient(manager, svnOption); - File checkoutDir = null; + checkoutdir = null; try { createCheckoutdir(); } catch (IOException e1) { @@ -481,12 +481,14 @@ public class SvnConnection implements ScmConnection { return resultDto; } + String svnRoot = getSvnRoot(dto.getUsername(), dto.getPassword()); try { + if (log.isDebugEnabled()) { - log.debug("Do Checkout of " + dto.getScmRoot()); + log.debug("Do Checkout of " + svnRoot); } - upclient.doCheckout(SVNURL.parseURIEncoded(dto.getScmRoot()), checkoutDir, + upclient.doCheckout(SVNURL.parseURIEncoded(svnRoot), checkoutdir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); } catch (SVNAuthenticationException authexep) { @@ -495,7 +497,7 @@ public class SvnConnection implements ScmConnection { log.debug("Private SCM on reading " + remoteUrl); } // deleting the temporary directory - delTempDirectory(checkoutDir); + delTempDirectory(checkoutdir); //redirect to a login page resultDto.setError(UploadResultDto.ERROR); @@ -503,7 +505,7 @@ public class SvnConnection implements ScmConnection { } catch (SVNException e) { // deleting the temporary directory - delTempDirectory(checkoutDir); + delTempDirectory(checkoutdir); resultDto.setError(UploadResultDto.ERROR); return resultDto; @@ -518,9 +520,9 @@ public class SvnConnection implements ScmConnection { //Copy file in checkoutdir - String checkoutPath = checkoutDir.getAbsolutePath(); + String checkoutPath = checkoutdir.getAbsolutePath(); - File file = new File(checkoutPath + svnPath.replace(dto.getScmRoot(), ""), dto.getUploadFileName()); + File file = new File(checkoutPath + dto.getScmPath().replace(svnRoot, ""), dto.getUploadFileName()); try { FileUtils.copyFile(dto.getUpload(), file); @@ -552,17 +554,17 @@ public class SvnConnection implements ScmConnection { } catch (SVNException e) { if (log.isErrorEnabled()) { - log.error("Erreur SVN Add", e); + log.error("Erreur SVN Add : " + e.getMessage() + " ; " + e.toString(), e); } // deleting the temporary directory - delTempDirectory(checkoutDir); + delTempDirectory(checkoutdir); resultDto.setError(UploadResultDto.CONNECTION_FAILED); return resultDto; } File[] checkoutDirTab = new File[1]; - checkoutDirTab[0] = checkoutDir; + checkoutDirTab[0] = checkoutdir; try { manager.getCommitClient().doCommit(checkoutDirTab, false, "From scmwebeditor -- add the file : " + @@ -577,7 +579,7 @@ public class SvnConnection implements ScmConnection { log.error("authentification fail"); } // deleting the temporary directory - delTempDirectory(checkoutDir); + delTempDirectory(checkoutdir); resultDto.setError(UploadResultDto.CONNECTION_FAILED); return resultDto; @@ -586,7 +588,7 @@ public class SvnConnection implements ScmConnection { log.error("Erreur SVN commit", e); } // deleting the temporary directory - delTempDirectory(checkoutDir); + delTempDirectory(checkoutdir); resultDto.setError(UploadResultDto.ERROR); return resultDto; @@ -594,7 +596,7 @@ public class SvnConnection implements ScmConnection { // deleting the temporary directory - delTempDirectory(checkoutDir); + delTempDirectory(checkoutdir); if (log.isDebugEnabled()) { log.debug("File upload successful"); @@ -867,11 +869,14 @@ public class SvnConnection implements ScmConnection { * @param checkoutdir The dir temp directory */ public void delTempDirectory(File checkoutdir) { - try { - FileUtils.deleteDirectory(checkoutdir); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't delete temp directory"); + + if (checkoutdir != null) { + try { + FileUtils.deleteDirectory(checkoutdir); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Can't delete temp directory"); + } } } } diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java index 8bb8e3d..756bc69 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java @@ -174,7 +174,6 @@ public class UploadAction extends AbstractScmWebEditorAction implements ServletR dto.setUploadFileName(uploadFileName); dto.setUploadContentType(uploadContentType); dto.setScmPath(scmPath); - dto.setScmRoot(scmRoot); UploadResultDto resultDto = scmConn.uploadFile(dto); diff --git a/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java b/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java index 1f142a6..283d2b6 100644 --- a/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java +++ b/src/main/java/org/nuiton/scmwebeditor/dto/UploadDto.java @@ -22,9 +22,6 @@ public class UploadDto { /** path to the SCM */ protected String scmPath; - /** the root directory of the SCM */ - protected String scmRoot; - public String getUsername() { return username; @@ -73,12 +70,4 @@ public class UploadDto { public void setScmPath(String scmPath) { this.scmPath = scmPath; } - - public String getScmRoot() { - return scmRoot; - } - - public void setScmRoot(String scmRoot) { - this.scmRoot = scmRoot; - } } diff --git a/src/main/webapp/WEB-INF/content/uploadForm.jsp b/src/main/webapp/WEB-INF/content/uploadForm.jsp index b21882f..f367e8d 100644 --- a/src/main/webapp/WEB-INF/content/uploadForm.jsp +++ b/src/main/webapp/WEB-INF/content/uploadForm.jsp @@ -45,8 +45,12 @@ $.subscribe('treeClicked', function(event, data) { var item = event.originalEvent.data.rslt.obj; - if (item.text().indexOf("/") != -1) { - window.document.getElementById("scmPath").value = item.attr("id"); + if (item.length == 1) { + var classAttr = item[0].getAttribute("class"); + + if (!classAttr.contains("jstree-leaf")) { + window.document.getElementById("scmPath").value = item.attr("id"); + } } }); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.