branch feature/GIT updated (bf83c20 -> 82b6979)
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 bf83c20 The user can now choose which SCM to use. An automatic detection based on the repository's address helps the user to make the choice. new 82b6979 Added the authentication when saving a Git file: the saving feature works now. Fixed the reset feature for SVN repositories. Improved the detection of the SCM to use when giving the repository's address. 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 82b6979596a7c25024b9f3d6e4c9036565029010 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Fri Apr 24 17:17:35 2015 +0200 Added the authentication when saving a Git file: the saving feature works now. Fixed the reset feature for SVN repositories. Improved the detection of the SCM to use when giving the repository's address. Summary of changes: .../org/nuiton/scmwebeditor/GitConnection.java | 45 +++++++++++++++--- .../nuiton/scmwebeditor/ScmWebEditorConfig.java | 9 ++++ .../scmwebeditor/ScmWebEditorConfigOption.java | 5 +- .../org/nuiton/scmwebeditor/SvnConnection.java | 21 --------- .../actions/ScmWebEditorCommitAction.java | 15 ++++++ .../actions/ScmWebEditorMainAction.java | 7 +-- .../nuiton/scmwebeditor/actions/SearchAction.java | 55 ++++++++++------------ src/main/resources/scmwebeditor.properties | 1 + src/main/webapp/WEB-INF/content/outConnection.jsp | 9 +--- src/main/webapp/WEB-INF/content/reset.jsp | 2 +- src/main/webapp/js/scmDetector.js | 19 +++++++- 11 files changed, 118 insertions(+), 70 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 82b6979596a7c25024b9f3d6e4c9036565029010 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Fri Apr 24 17:17:35 2015 +0200 Added the authentication when saving a Git file: the saving feature works now. Fixed the reset feature for SVN repositories. Improved the detection of the SCM to use when giving the repository's address. --- .../org/nuiton/scmwebeditor/GitConnection.java | 45 +++++++++++++++--- .../nuiton/scmwebeditor/ScmWebEditorConfig.java | 9 ++++ .../scmwebeditor/ScmWebEditorConfigOption.java | 5 +- .../org/nuiton/scmwebeditor/SvnConnection.java | 21 --------- .../actions/ScmWebEditorCommitAction.java | 15 ++++++ .../actions/ScmWebEditorMainAction.java | 7 +-- .../nuiton/scmwebeditor/actions/SearchAction.java | 55 ++++++++++------------ src/main/resources/scmwebeditor.properties | 1 + src/main/webapp/WEB-INF/content/outConnection.jsp | 9 +--- src/main/webapp/WEB-INF/content/reset.jsp | 2 +- src/main/webapp/js/scmDetector.js | 19 +++++++- 11 files changed, 118 insertions(+), 70 deletions(-) diff --git a/src/main/java/org/nuiton/scmwebeditor/GitConnection.java b/src/main/java/org/nuiton/scmwebeditor/GitConnection.java index 184f432..b70752c 100644 --- a/src/main/java/org/nuiton/scmwebeditor/GitConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/GitConnection.java @@ -22,13 +22,11 @@ package org.nuiton.scmwebeditor; import com.google.common.collect.Lists; -import com.jcraft.jsch.HASH; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.shiro.crypto.hash.Hash; import org.eclipse.jgit.api.*; -import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.*; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -38,8 +36,12 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.treewalk.TreeWalk; -import org.nuiton.scmwebeditor.actions.*; +import org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction; +import org.nuiton.scmwebeditor.actions.SearchAction; +import org.nuiton.scmwebeditor.actions.UploadAction; import java.io.File; import java.io.FileNotFoundException; @@ -313,7 +315,7 @@ public class GitConnection implements ScmConnection { } // authentication - //UsernamePasswordCredentialsProvider userPassProvider = + CredentialsProvider credentials = new UsernamePasswordCredentialsProvider(action.getUsername(), action.getPw()); // applying the changes on the local file try { @@ -336,7 +338,7 @@ public class GitConnection implements ScmConnection { CommitCommand commit = git.commit(); commit.setAll(true); - commit.setAuthor("SCMWebEditor", "mail@scmwebeditor.com"); + commit.setAuthor(action.getUsername(), "unknown"); commit.setMessage(action.getCommitMessage()); try { @@ -356,9 +358,40 @@ public class GitConnection implements ScmConnection { // push PushCommand push = git.push(); push.setRemote(addressGit); + push.setCredentialsProvider(credentials); try { push.call(); + } catch (NoHeadException e) { + if (log.isErrorEnabled()) { + log.error("Can not push : the Git repository has no HEAD reference", e); + } + + return action.ERROR; + } catch (UnmergedPathsException e) { + if (log.isErrorEnabled()) { + log.error("Can not push : conflicts found (unmerged paths)", e); + } + + return action.ERROR; + } catch (ConcurrentRefUpdateException e) { + if (log.isErrorEnabled()) { + log.error("Can not push : someone else is updating the HEAD or the branch", e); + } + + return action.ERROR; + } catch (WrongRepositoryStateException e) { + if (log.isErrorEnabled()) { + log.error("Can not push : the repository is not in the right state", e); + } + + return action.ERROR; + } catch (RejectCommitException e) { + if (log.isErrorEnabled()) { + log.error("Can not push : commit rejected", e); + } + + return action.ERROR; } catch (GitAPIException e) { if (log.isErrorEnabled()) { log.error("Can not push", e); diff --git a/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java b/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java index 35e4065..6788c43 100644 --- a/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java +++ b/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java @@ -21,11 +21,13 @@ */ package org.nuiton.scmwebeditor; +import javafx.application.Application; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ArgumentsParserException; +import java.util.Arrays; import java.util.List; public class ScmWebEditorConfig { @@ -69,6 +71,13 @@ public class ScmWebEditorConfig { return config.getOption(key); } + public static List<String> getSupportedScms() { return getSupportedScms(getConfig()); } + + public static List<String> getSupportedScms(ApplicationConfig config) { + String key = ScmWebEditorConfigOption.SUPPORTED_SCMS.getKey(); + return Arrays.asList(config.getOption(key).split(",")); + } + public static String getKey() { return getKey(getConfig()); } diff --git a/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java b/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java index acf9b20..9f7f419 100644 --- a/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java +++ b/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java @@ -24,12 +24,15 @@ package org.nuiton.scmwebeditor; import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ConfigOptionDef; +import java.util.List; + public enum ScmWebEditorConfigOption implements ConfigOptionDef { CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME, "The file name", "scmwebeditor.properties", String.class, false, false), EDITABLESFILES("editableFiles", "description", "Files types that are editable", String.class, true, true), COOKIES_PRIVATE_KEY("cookiePrivateKey", "Private key for cookies", null, String.class, true, true), - LOCAL_REPOSITORIES_PATH("localRepositoriesPath", "The path where the local repositories will be stored", "/var/local/swe", String.class, false, true); + LOCAL_REPOSITORIES_PATH("localRepositoriesPath", "The path where the local repositories will be stored", "/var/local/swe", String.class, false, true), + SUPPORTED_SCMS("supportedScms", "The SCMs which can be used", null, String.class, false, true); private final String key; diff --git a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java index db53321..9b735f1 100644 --- a/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java +++ b/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java @@ -409,28 +409,7 @@ public class SvnConnection implements ScmConnection { action.setSvnRoot(action.getFileRoot()); } - - //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = getRepositoryId(); - if (repositoryUUID == null) { - repositoryUUID = action.getAddress(); - } - - - if (action.getUsername() == null && action.getPw() == null) { - if (action.getScmSession().getUsername(repositoryUUID) != null && - action.getScmSession().getPassword(repositoryUUID) != null) { - //On recupère les identifiants en session - action.setUsername(action.getScmSession().getUsername(repositoryUUID)); - action.setPw(action.getScmSession().getPassword(repositoryUUID)); - } else { - action.setUsername(null); - action.setPw(null); - } - } else { - action.getScmSession().addScmUser(repositoryUUID, action.getUsername(), action.getPw()); - } - updateAuthentication(action.getUsername(), action.getPw()); diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java index 09051ae..461c23c 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java @@ -311,6 +311,21 @@ public class ScmWebEditorCommitAction extends ScmWebEditorBaseAction implements getScmSession().addScmUser(repositoryUUID, login, password); } + + if (username == null && pw == null) { + if (getScmSession().getUsername(repositoryUUID) != null && + getScmSession().getPassword(repositoryUUID) != null) { + //On recupère les identifiants en session + username = getScmSession().getUsername(repositoryUUID); + pw = getScmSession().getPassword(repositoryUUID); + } else { + username = null; + pw = null; + } + } else { + getScmSession().addScmUser(repositoryUUID, username, pw); + } + username = login; pw = password; diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java index 896fdd9..07ee875 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java @@ -25,18 +25,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.shiro.codec.Base64; import org.apache.shiro.crypto.BlowfishCipherService; -import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.nuiton.scmwebeditor.*; -import org.tmatesoft.svn.core.SVNAuthenticationException; -import org.tmatesoft.svn.core.SVNException; import javax.naming.AuthenticationException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; +import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletResponseAware { @@ -154,6 +153,8 @@ public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements Se return badLogin; } + public List<String> getSupportedScms() { return ScmWebEditorConfig.getSupportedScms(); } + /** * On test si les parametres ne sont pas vide * diff --git a/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java b/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java index e63a660..7ef3351 100644 --- a/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java +++ b/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java @@ -127,43 +127,38 @@ public class SearchAction extends ScmWebEditorBaseAction { address = address.substring(0, address.length() - 1); } - if (!address.equals("")) { - - // connection to the repository - HttpSession session = request.getSession(); - String sessionId = session.getId(); - - ScmConnection scmConn = null; - try { - scmConn = ScmConnectionFactory.createScmConnection(address, scmType, sessionId); - } catch (ScmNotFoundException e) { - error = e.getMessage(); - if (log.isErrorEnabled()) { - log.error("Can not create a connection to the SCM", e); - } - } + // connection to the repository + HttpSession session = request.getSession(); + String sessionId = session.getId(); - 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; + ScmConnection scmConn = null; + try { + scmConn = ScmConnectionFactory.createScmConnection(address, scmType, sessionId); + } catch (ScmNotFoundException e) { + error = "Can't access to the repository"; + if (log.isErrorEnabled()) { + log.error("Can not create a connection to the SCM", e); } + return SUCCESS; + } + + String returnCode = null; - if (returnCode != SUCCESS) { - return returnCode; + // 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); } - } else { - error = "No address given"; return SUCCESS; } + if (returnCode != SUCCESS) { + return returnCode; + } + // building the tree for (String file : files) { diff --git a/src/main/resources/scmwebeditor.properties b/src/main/resources/scmwebeditor.properties index e6bd17b..b1dbd70 100644 --- a/src/main/resources/scmwebeditor.properties +++ b/src/main/resources/scmwebeditor.properties @@ -22,3 +22,4 @@ editableFiles=text,xml,javascript,sh,x-tex,x-java cookiePrivateKey=ZvcCyhfRTVZoQz3B/IpYdw== localRepositoriesPath=/var/local/swe +supportedScms=SVN,Git diff --git a/src/main/webapp/WEB-INF/content/outConnection.jsp b/src/main/webapp/WEB-INF/content/outConnection.jsp index c7c99a2..96642f2 100644 --- a/src/main/webapp/WEB-INF/content/outConnection.jsp +++ b/src/main/webapp/WEB-INF/content/outConnection.jsp @@ -123,13 +123,8 @@ </center> - <p> - <s:text name="scm.outConnection.scmType"/> - <select id="scmType" name="scmType"> - <option>SVN</option> - <option>Git</option> - </select> - </p> + <s:text name="scm.outConnection.scmType"/> + <s:select id="scmType" name="scmType" list="supportedScms"/> <div id="branches"> <s:text name="scm.outConnection.selectBranch"/> diff --git a/src/main/webapp/WEB-INF/content/reset.jsp b/src/main/webapp/WEB-INF/content/reset.jsp index 69e9b44..3842096 100644 --- a/src/main/webapp/WEB-INF/content/reset.jsp +++ b/src/main/webapp/WEB-INF/content/reset.jsp @@ -35,7 +35,7 @@ <s:else> <script type="text/javascript"> - editor.mirror.setValue(document.getElementById('valueOfLastRevision').value); + editor.setValue(document.getElementById('valueOfLastRevision').value); var numrev = <s:property value="numRevision" />; if (numrev != null) { diff --git a/src/main/webapp/js/scmDetector.js b/src/main/webapp/js/scmDetector.js index a76d1f0..229676d 100644 --- a/src/main/webapp/js/scmDetector.js +++ b/src/main/webapp/js/scmDetector.js @@ -2,8 +2,25 @@ $(document).ready(function() { $("#addressInput").on("input", function() { var address = $("#addressInput").val(); - if (address.contains(".git")) { + + if (address.contains(".git") && scmsListContains("Git")) { $("#scmType").val("Git"); } + + }); + + + function scmsListContains(scm) { + + var $children = $("#scmType").children(); + + for (var i = 0 ; i < $children.length ; i++) { + if ($children[i].value == scm) { + return true; + } + } + + return false; + } }); \ No newline at end of file -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm