From d7f0c9f33a2f610e9a7f95bf08f10d79ade20136 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 10 Dec 2011 14:31:11 +0100 Subject: [PATCH] added revision for mercurial sub repositories --- .../java/sonia/scm/repository/FileObject.java | 18 +- .../sonia/scm/repository/SubRepository.java | 179 ++++++++++++++++++ .../src/main/resources/sonia/scm/hgbrowse.py | 28 ++- .../scm/repository/SvnRepositoryBrowser.java | 4 +- scm-webapp/pom.xml | 2 +- .../sonia.repository.repositorybrowser.js | 19 +- 6 files changed, 232 insertions(+), 18 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/SubRepository.java diff --git a/scm-core/src/main/java/sonia/scm/repository/FileObject.java b/scm-core/src/main/java/sonia/scm/repository/FileObject.java index 71517cf4a3..44272cb675 100644 --- a/scm-core/src/main/java/sonia/scm/repository/FileObject.java +++ b/scm-core/src/main/java/sonia/scm/repository/FileObject.java @@ -39,6 +39,9 @@ import sonia.scm.LastModifiedAware; //~--- JDK imports ------------------------------------------------------------ +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** @@ -47,6 +50,7 @@ import javax.xml.bind.annotation.XmlRootElement; * @since 1.5 */ @XmlRootElement(name = "file") +@XmlAccessorType(XmlAccessType.FIELD) public class FileObject implements LastModifiedAware { @@ -112,9 +116,9 @@ public class FileObject implements LastModifiedAware * @since 1.10 * @return */ - public String getSubRepositoryUrl() + public SubRepository getSubRepository() { - return subRepositoryUrl; + return subRepository; } /** @@ -200,12 +204,13 @@ public class FileObject implements LastModifiedAware * Method description * * - * @param subRepositoryUrl * @since 1.10 + * + * @param subRepository */ - public void setSubRepositoryUrl(String subRepositoryUrl) + public void setSubRepository(SubRepository subRepository) { - this.subRepositoryUrl = subRepositoryUrl; + this.subRepository = subRepository; } //~--- fields --------------------------------------------------------------- @@ -229,5 +234,6 @@ public class FileObject implements LastModifiedAware private String path; /** Field description */ - private String subRepositoryUrl; + @XmlElement(name = "subrepository") + private SubRepository subRepository; } diff --git a/scm-core/src/main/java/sonia/scm/repository/SubRepository.java b/scm-core/src/main/java/sonia/scm/repository/SubRepository.java new file mode 100644 index 0000000000..5325f94ac6 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/SubRepository.java @@ -0,0 +1,179 @@ +/** + * 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.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @since 1.10 + * @author Sebastian Sdorra + */ +@XmlRootElement(name = "subrepository") +@XmlAccessorType(XmlAccessType.FIELD) +public class SubRepository +{ + + /** + * Constructs ... + * + */ + public SubRepository() {} + + /** + * Constructs ... + * + * + * @param repositoryUrl + */ + public SubRepository(String repositoryUrl) + { + this.repositoryUrl = repositoryUrl; + } + + /** + * Constructs ... + * + * + * @param revision + * @param repositoryUrl + */ + public SubRepository(String repositoryUrl, String revision) + { + this.repositoryUrl = repositoryUrl; + this.revision = revision; + } + + /** + * Constructs ... + * + * + * @param revision + * @param repositoryUrl + * @param browserUrl + */ + public SubRepository(String repositoryUrl, String browserUrl, String revision) + { + this.repositoryUrl = repositoryUrl; + this.browserUrl = browserUrl; + this.revision = revision; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public String getBrowserUrl() + { + return browserUrl; + } + + /** + * Method description + * + * + * @return + */ + public String getRepositoryUrl() + { + return repositoryUrl; + } + + /** + * Method description + * + * + * @return + */ + public String getRevision() + { + return revision; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param browserUrl + */ + public void setBrowserUrl(String browserUrl) + { + this.browserUrl = browserUrl; + } + + /** + * Method description + * + * + * @param repositoryUrl + */ + public void setRepositoryUrl(String repositoryUrl) + { + this.repositoryUrl = repositoryUrl; + } + + /** + * Method description + * + * + * @param revision + */ + public void setRevision(String revision) + { + this.revision = revision; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @XmlElement(name = "browser-url") + private String browserUrl; + + /** Field description */ + @XmlElement(name = "repository-url") + private String repositoryUrl; + + /** Field description */ + private String revision; +} diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py index f77a244dc1..ccbeb0c86f 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py @@ -29,6 +29,10 @@ # # +class SubRepository: + url = None + revision = None + import sys, os pythonPath = os.environ['SCM_PYTHON_PATH'] @@ -65,11 +69,25 @@ try: for line in hgsub: parts = line.split('=') if len(parts) > 1: - subrepos[parts[0].strip()] = parts[1].strip() + subrepo = SubRepository() + subrepo.url = parts[1].strip() + subrepos[parts[0].strip()] = subrepo print '' except Exception: - # howto drop execptions + # howto drop execptions in python? print '' + +try: + hgsubstate = revCtx.filectx('.hgsubstate').data().split('\n') + for line in hgsubstate: + parts = line.split(' ') + if len(parts) > 1: + subrev = parts[0].strip() + subrepo = subrepos[parts[1].strip()] + subrepo.revision = subrev +except Exception: + # howto drop execptions in python? + print '' if path is "": length = 1 @@ -112,7 +130,11 @@ for dir in directories: print ' true' if dir in subrepos: subrepo = subrepos[dir] - print ' ' + subrepo + '' + print ' ' + if subrepo.revision != None: + print ' ' + subrepo.revision + '' + print ' ' + subrepo.url + '' + print ' ' print ' ' for file in files: diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryBrowser.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryBrowser.java index 5ae704df28..a233951739 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryBrowser.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnRepositoryBrowser.java @@ -267,7 +267,9 @@ public class SvnRepositoryBrowser implements RepositoryBrowser if (Util.isNotEmpty(externals)) { - fileObject.setSubRepositoryUrl(externals); + SubRepository subRepository = new SubRepository(externals); + + fileObject.setSubRepository(subRepository); } } catch (SVNException ex) diff --git a/scm-webapp/pom.xml b/scm-webapp/pom.xml index b5d0a53547..d04dd7e2a9 100644 --- a/scm-webapp/pom.xml +++ b/scm-webapp/pom.xml @@ -362,7 +362,7 @@ 1.13 1.0 3.0.3 - Tomcat + gfv3ee6 diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js index 684c030968..cc2e0ae282 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js @@ -56,7 +56,7 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { url: restUrl + 'repositories/' + this.repository.id + '/browse.json', method: 'GET' }), - fields: ['path', 'name', 'length', 'lastModified', 'directory', 'description', 'subRepositoryUrl'], + fields: ['path', 'name', 'length', 'lastModified', 'directory', 'description', 'subrepository'], root: 'files', idProperty: 'path', autoLoad: true, @@ -111,8 +111,8 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { dataIndex: 'description', header: 'Description' },{ - id: 'subRepositoryUrl', - dataIndex: 'subRepositoryUrl', + id: 'subrepository', + dataIndex: 'subrepository', hidden: true }] }); @@ -336,17 +336,21 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { }, renderName: function(name, p, record){ - var subRepository = record.get('subRepositoryUrl'); + var subRepository = record.get('subrepository'); var folder = record.get('directory'); var path = null; var template = null; if ( subRepository ){ // get real revision (.hgsubstate)? - path = this.transformLink(subRepository); + var subRepositoryUrl = subRepository['browser-url']; + if (!subRepositoryUrl){ + subRepositoryUrl = subRepository['repository-url']; + } + path = this.transformLink(subRepositoryUrl); if ( path ){ template = this.templateInternalLink; } else { - path = subRepository; + path = subRepositoryUrl; template = this.templateExternalLink; } } else { @@ -364,7 +368,8 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, { renderIcon: function(directory, p, record){ var icon = null; - var subRepository = record.get('subRepositoryUrl'); + var subRepository = record.get('subrepository'); + var name = record.get('name'); if ( subRepository ){ icon = this.iconSubRepository;