diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java b/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java index f453cf2539..159a14facd 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstractSimpleRepositoryHandler.java @@ -35,7 +35,9 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.base.Charsets; import com.google.common.base.Throwables; +import com.google.common.io.Resources; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,6 +54,8 @@ import sonia.scm.util.IOUtil; import java.io.File; import java.io.IOException; +import java.net.URL; + /** * * @author Sebastian Sdorra @@ -63,6 +67,9 @@ public abstract class AbstractSimpleRepositoryHandler { + /** Field description */ + public static final String DEFAULT_VERSION_INFORMATION = "unknown"; + /** Field description */ public static final String DIRECTORY_REPOSITORY = "repositories"; @@ -267,6 +274,18 @@ public abstract class AbstractSimpleRepositoryHandlertrue META-INF/scm/plugin.xml + sonia/scm/version/* @@ -47,6 +48,7 @@ false META-INF/scm/plugin.xml + sonia/scm/version/* diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java index c62839c77f..372d6deaf1 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitRepositoryHandler.java @@ -65,6 +65,10 @@ public class GitRepositoryHandler /** Field description */ public static final String DIRECTORY_REFS = "refs"; + /** Field description */ + public static final String RESOURCE_VERSION = + "/sonia/scm/version/scm-git-plugin"; + /** Field description */ public static final String TYPE_DISPLAYNAME = "Git"; @@ -224,6 +228,18 @@ public class GitRepositoryHandler return TYPE; } + /** + * Method description + * + * + * @return + */ + @Override + public String getVersionInformation() + { + return getStringFromResource(RESOURCE_VERSION, DEFAULT_VERSION_INFORMATION); + } + //~--- methods -------------------------------------------------------------- /** diff --git a/scm-plugins/scm-git-plugin/src/main/resources/sonia/scm/version/scm-git-plugin b/scm-plugins/scm-git-plugin/src/main/resources/sonia/scm/version/scm-git-plugin new file mode 100644 index 0000000000..759da3c519 --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/resources/sonia/scm/version/scm-git-plugin @@ -0,0 +1 @@ +scm-git-plugin/${project.version} org.eclipse.jgit/${jgit.version} \ No newline at end of file diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java index fed3690674..e61682e547 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java @@ -111,7 +111,7 @@ public class AbstractHgHandler LoggerFactory.getLogger(AbstractHgHandler.class); //~--- constructors --------------------------------------------------------- - + /** * Constructs ... * diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgPythonScript.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgPythonScript.java index eb3245df3e..927236d6ea 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgPythonScript.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgPythonScript.java @@ -47,7 +47,7 @@ import java.io.File; public enum HgPythonScript { BLAME("blame.py"), CHANGELOG("changelog.py"), FILELOG("filelog.py"), - UTIL("util.py"), HOOK("scmhooks.py"), HGWEB("hgweb.py"); + UTIL("util.py"), HOOK("scmhooks.py"), HGWEB("hgweb.py"), VERSION("version.py"); /** Field description */ private static final String BASE_DIRECTORY = diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java index 165cef0366..1fa70ea2b1 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgRepositoryHandler.java @@ -68,6 +68,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.MessageFormat; + import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -84,6 +86,10 @@ public class HgRepositoryHandler /** Field description */ public static final String PATH_HOOK = ".hook-1.8"; + /** Field description */ + public static final String RESOURCE_VERSION = + "/sonia/scm/version/scm-git-plugin"; + /** Field description */ public static final String TYPE_DISPLAYNAME = "Mercurial"; @@ -336,6 +342,39 @@ public class HgRepositoryHandler return TYPE; } + /** + * Method description + * + * + * @return + */ + @Override + public String getVersionInformation() + { + String version = getStringFromResource(RESOURCE_VERSION, + DEFAULT_VERSION_INFORMATION); + + try + { + JAXBContext context = JAXBContext.newInstance(HgVersion.class); + HgVersion hgVersion = new HgVersionHandler(this, context, + hgContextProvider.get(), + baseDirectory).getVersion(); + + if (hgVersion != null) + { + version = MessageFormat.format(version, hgVersion.getPython(), + hgVersion.getMercurial()); + } + } + catch (Exception ex) + { + logger.error("could not read version informations", ex); + } + + return version; + } + //~--- methods -------------------------------------------------------------- /** diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgVersion.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgVersion.java new file mode 100644 index 0000000000..616d2dbab5 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgVersion.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.repository; + +//~--- JDK imports ------------------------------------------------------------ + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Sebastian Sdorra + */ +@XmlRootElement(name = "version") +@XmlAccessorType(XmlAccessType.FIELD) +public class HgVersion +{ + + /** + * Method description + * + * + * @return + */ + public String getMercurial() + { + return mercurial; + } + + /** + * Method description + * + * + * @return + */ + public String getPython() + { + return python; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param mercurial + */ + public void setMercurial(String mercurial) + { + this.mercurial = mercurial; + } + + /** + * Method description + * + * + * @param python + */ + public void setPython(String python) + { + this.python = python; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private String mercurial; + + /** Field description */ + private String python; +} diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgVersionHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgVersionHandler.java new file mode 100644 index 0000000000..722b09fab4 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgVersionHandler.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.repository; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +import javax.xml.bind.JAXBContext; + +/** + * + * @author Sebastian Sdorra + */ +public class HgVersionHandler extends AbstractHgHandler +{ + + /** + * Constructs ... + * + * + * @param handler + * @param jaxbContext + * @param context + * @param directory + */ + public HgVersionHandler(HgRepositoryHandler handler, JAXBContext jaxbContext, + HgContext context, File directory) + { + super(handler, jaxbContext, context, directory); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + * + * @throws IOException + * @throws RepositoryException + */ + public HgVersion getVersion() throws IOException, RepositoryException + { + return getResultFromScript(HgVersion.class, HgPythonScript.VERSION); + } +} diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/version.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/version.py new file mode 100644 index 0000000000..5e98ec154b --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/version.py @@ -0,0 +1,21 @@ +import sys +from mercurial import util +from xml.dom.minidom import Document + +pyVersion = sys.version_info +pyVersion = str(pyVersion.major) + "." + str(pyVersion.minor) + "." + str(pyVersion.micro) +hgVersion = util.version() + +doc = Document() +root = doc.createElement('verion') + +pyNode = doc.createElement('python') +pyNode.appendChild(doc.createTextNode(pyVersion)) +root.appendChild(pyNode) + +hgNode = doc.createElement('mercurial') +hgNode.appendChild(doc.createTextNode(hgVersion)) +root.appendChild(hgNode) + +doc.appendChild(root) +doc.writexml(sys.stdout, encoding='UTF-8') \ No newline at end of file diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/version/scm-hg-plugin b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/version/scm-hg-plugin new file mode 100644 index 0000000000..7ca58dea27 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/version/scm-hg-plugin @@ -0,0 +1 @@ +scm-hg-version/${project.version} python/{0} mercurial/{1} \ No newline at end of file diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java index 7b0dceaa7e..cafe7a9bb9 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryHandler.java @@ -46,7 +46,6 @@ import org.tmatesoft.svn.core.internal.io.fs.FSHooks; import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; -import sonia.scm.NotSupportedFeatuerException; import sonia.scm.Type; import sonia.scm.io.FileSystem; import sonia.scm.plugin.ext.Extension; @@ -68,6 +67,10 @@ public class SvnRepositoryHandler extends AbstractSimpleRepositoryHandler { + /** Field description */ + public static final String RESOURCE_VERSION = + "/sonia/scm/version/scm-git-plugin"; + /** Field description */ public static final String TYPE_DISPLAYNAME = "Subversion"; @@ -247,6 +250,18 @@ public class SvnRepositoryHandler return TYPE; } + /** + * Method description + * + * + * @return + */ + @Override + public String getVersionInformation() + { + return getStringFromResource(RESOURCE_VERSION, DEFAULT_VERSION_INFORMATION); + } + //~--- methods -------------------------------------------------------------- /** diff --git a/scm-plugins/scm-svn-plugin/src/main/resources/sonia/scm/version/scm-svn-plugin b/scm-plugins/scm-svn-plugin/src/main/resources/sonia/scm/version/scm-svn-plugin new file mode 100644 index 0000000000..76ed46fd46 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/main/resources/sonia/scm/version/scm-svn-plugin @@ -0,0 +1 @@ +scm-svn-plugin/${project.version} svnkit/${svnkit-dav.version} \ No newline at end of file