From 2091f6a1b43a301c84d69656502d5d14135bc5ac Mon Sep 17 00:00:00 2001 From: Steve Tynor Date: Fri, 24 Aug 2012 17:36:44 -0400 Subject: [PATCH 1/2] Fixes Redmine links for compatibility with more recent versions of Redmine. Tested with Redmine 2.0.2. Adds a new property to handle cases where the repo is not the redmine project's default repo. --- src/main/webapp/help-repo.html | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) create mode 100755 src/main/webapp/help-repo.html diff --git a/src/main/webapp/help-repo.html b/src/main/webapp/help-repo.html new file mode 100755 index 0000000..e3fc21f --- /dev/null +++ b/src/main/webapp/help-repo.html @@ -0,0 +1,3 @@ +
+ If the Redmine repository is not the project's default repository, name it. +
\ No newline at end of file -- 1.7.9 From 5cb6d3ff823fb8b86aac351a19e88588a4778a9e Mon Sep 17 00:00:00 2001 From: Steve Tynor Date: Fri, 24 Aug 2012 17:37:57 -0400 Subject: [PATCH 2/2] Fixes Redmine links for compatibility with more recent versions of Redmine. Tested with Redmine 2.0.2. Adds a new property to handle cases where the repo is not the redmine project's default repo. --- .../hudson/plugins/redmine/RedmineLinkAction.java | 6 +- .../plugins/redmine/RedmineProjectProperty.java | 10 +- .../plugins/redmine/RedmineRepositoryBrowser.java | 145 ++++++++++++-------- .../redmine/RedmineProjectProperty/config.jelly | 4 + 4 files changed, 105 insertions(+), 60 deletions(-) mode change 100644 => 100755 src/main/java/hudson/plugins/redmine/RedmineRepositoryBrowser.java diff --git a/src/main/java/hudson/plugins/redmine/RedmineLinkAction.java b/src/main/java/hudson/plugins/redmine/RedmineLinkAction.java index 4f16c15..3f59871 100644 --- a/src/main/java/hudson/plugins/redmine/RedmineLinkAction.java +++ b/src/main/java/hudson/plugins/redmine/RedmineLinkAction.java @@ -23,7 +23,11 @@ public class RedmineLinkAction implements Action { } public String getUrlName() { - return prop.redmineWebsite; + if (prop.projectName == null) { + return prop.redmineWebsite; + } else { + return prop.redmineWebsite + "projects/" + prop.projectName; + } } } diff --git a/src/main/java/hudson/plugins/redmine/RedmineProjectProperty.java b/src/main/java/hudson/plugins/redmine/RedmineProjectProperty.java index bd51e79..9512fe9 100644 --- a/src/main/java/hudson/plugins/redmine/RedmineProjectProperty.java +++ b/src/main/java/hudson/plugins/redmine/RedmineProjectProperty.java @@ -24,10 +24,12 @@ public class RedmineProjectProperty extends JobProperty> { public final String projectName; + public final String projectRepoName; + public final Boolean redmineVersion; @DataBoundConstructor - public RedmineProjectProperty(String redmineWebsite, String projectName, Boolean redmineVersion) { + public RedmineProjectProperty(String redmineWebsite, String projectName, String projectRepoName, Boolean redmineVersion) { if (StringUtils.isBlank(redmineWebsite)) { redmineWebsite = null; } else { @@ -37,6 +39,7 @@ public class RedmineProjectProperty extends JobProperty> { } this.redmineWebsite = redmineWebsite; this.projectName = projectName; + this.projectRepoName = projectRepoName; this.redmineVersion = redmineVersion; } @@ -75,13 +78,14 @@ public class RedmineProjectProperty extends JobProperty> { try { String redmineWebSite = req.getParameter("redmine.redmineWebsite"); String projectName = req.getParameter("redmine.projectName"); + String projectRepoName = req.getParameter("redmine.projectRepoName"); String redmineVersion = req.getParameter("redmine.version"); - + Boolean version = false; if(StringUtils.isNotBlank(redmineVersion) && redmineVersion.equals("on")) { version = true; } - return new RedmineProjectProperty(redmineWebSite, projectName, version); + return new RedmineProjectProperty(redmineWebSite, projectName, projectRepoName, version); } catch (IllegalArgumentException e) { throw new FormException("redmine.redmineWebsite", "redmine.redmineWebSite"); diff --git a/src/main/java/hudson/plugins/redmine/RedmineRepositoryBrowser.java b/src/main/java/hudson/plugins/redmine/RedmineRepositoryBrowser.java old mode 100644 new mode 100755 index 254b905..a17ae5e --- a/src/main/java/hudson/plugins/redmine/RedmineRepositoryBrowser.java +++ b/src/main/java/hudson/plugins/redmine/RedmineRepositoryBrowser.java @@ -24,97 +24,130 @@ import hudson.scm.SubversionChangeLogSet.Path; public class RedmineRepositoryBrowser extends SubversionRepositoryBrowser { @DataBoundConstructor - public RedmineRepositoryBrowser() { - } - + public RedmineRepositoryBrowser() { + } + @Override public URL getDiffLink(Path path) throws IOException { if(path.getEditType()!= EditType.EDIT) { - return null; + return null; } - URL baseUrl = getRedmineURL(path.getLogEntry()); - String projectName = getProject(path.getLogEntry()); - String filePath = getFilePath(path.getLogEntry(), path.getValue()); - - int revision = path.getLogEntry().getRevision(); - return new URL(baseUrl, "repositories/diff/" + projectName + filePath + "?rev=" + revision); + URL baseUrl = getRedmineURL(path.getLogEntry()); + String repo = getRepo(path.getLogEntry()); + String filePath = getFilePath(path.getLogEntry(), path.getValue()); + + int revision = path.getLogEntry().getRevision(); + return new URL(baseUrl, "repository"+repo+"/revisions/"+revision+"/diff" + filePath + "?rev=" + revision); } @Override public URL getFileLink(Path path) throws IOException { URL baseUrl = getRedmineURL(path.getLogEntry()); - String projectName = getProject(path.getLogEntry()); + String repo = getRepo(path.getLogEntry()); String filePath = getFilePath(path.getLogEntry(), path.getValue()); - - return baseUrl == null ? null : new URL(baseUrl, "repositories/entry/" + projectName + filePath); + int revision = path.getLogEntry().getRevision(); + + return baseUrl == null ? null : new URL(baseUrl, "repository"+ repo + "/revisions/"+ revision+"/entry" +filePath); } @Override public URL getChangeSetLink(LogEntry changeSet) throws IOException { URL baseUrl = getRedmineURL(changeSet); - String projectName = getProject(changeSet); - return baseUrl == null ? null : new URL(baseUrl, "repositories/revision/" + projectName + "/" + changeSet.getRevision()); + String repo = getRepo(changeSet); + return baseUrl == null ? null : new URL(baseUrl, "repository" +repo+ "/revisions/" + changeSet.getRevision()); } @Override public Descriptor> getDescriptor() { - return DESCRIPTOR; + return DESCRIPTOR; } - + + /** + * The raw Redmine URL is documented with the example http://myhost/redmine. This + * function returns the _project_'s base URL which concatenates the redmine base url + * with the "/projects//" (if a project name is supplied) + * @param logEntry + * @return + * @throws MalformedURLException + */ private URL getRedmineURL(LogEntry logEntry) throws MalformedURLException { - AbstractProject p = (AbstractProject)logEntry.getParent().build.getProject(); - RedmineProjectProperty rpp = p.getProperty(RedmineProjectProperty.class); - if(rpp == null) { - return null; - } else { - return new URL(rpp.redmineWebsite); - } - } + AbstractProject p = (AbstractProject)logEntry.getParent().build.getProject(); + RedmineProjectProperty rpp = p.getProperty(RedmineProjectProperty.class); + String url = ""; + if(rpp == null) { + url = ""; + } else { + // NOTE: we force the website string to have a trailing slash in the constructor + url = rpp.redmineWebsite; + if (rpp.projectName != null) { + url += "projects/" + rpp.projectName + "/"; + } + } + return new URL(url); + } private String getProject(LogEntry logEntry) { AbstractProject p = (AbstractProject)logEntry.getParent().build.getProject(); RedmineProjectProperty rpp = p.getProperty(RedmineProjectProperty.class); - if(rpp == null) { - return null; - } else { - return rpp.projectName; - } + if(rpp == null) { + return null; + } else { + return rpp.projectName; + } + } + + /** + * For projects with multiple repositories, provides the repo name. If not specified, + * produces an empty string which when concatentated in the "repo" part of the URL, + * results in a correct Redmine link for such a project + */ + private String getRepo(LogEntry logEntry) { + AbstractProject p = (AbstractProject)logEntry.getParent().build.getProject(); + RedmineProjectProperty rpp = p.getProperty(RedmineProjectProperty.class); + if(rpp == null) { + return ""; + } else if (rpp.projectRepoName == null){ + return ""; + } else { + return "/" + rpp.projectRepoName; + } + } private String getFilePath(LogEntry logEntry, String fileFullPath) { AbstractProject p = (AbstractProject)logEntry.getParent().build.getProject(); RedmineProjectProperty rpp = p.getProperty(RedmineProjectProperty.class); - + String filePath = ""; - if(rpp.redmineVersion.booleanValue()) { // 0.8.1 or after - filePath = fileFullPath; - - } else { // 0.8.0 or before - String[] filePaths = fileFullPath.split("/"); - filePath = "/"; - if(filePaths.length > 2) { - for(int i = 2 ; i < filePaths.length; i++) { - filePath = filePath + filePaths[i]; - if(i != filePaths.length - 1) { - filePath = filePath + "/"; - } - } - } - } - return filePath; - + if(rpp.redmineVersion.booleanValue()) { // 0.8.1 or after + filePath = fileFullPath; + + } else { // 0.8.0 or before + String[] filePaths = fileFullPath.split("/"); + filePath = "/"; + if(filePaths.length > 2) { + for(int i = 2 ; i < filePaths.length; i++) { + filePath = filePath + filePaths[i]; + if(i != filePaths.length - 1) { + filePath = filePath + "/"; + } + } + } + } + return filePath; + } @Extension public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); - public static final class DescriptorImpl extends Descriptor> { - public DescriptorImpl() { - super(RedmineRepositoryBrowser.class); - } + public static final class DescriptorImpl extends Descriptor> { + public DescriptorImpl() { + super(RedmineRepositoryBrowser.class); + } - public String getDisplayName() { - return "Redmine"; - } - } + public String getDisplayName() { + return "Redmine"; + } + } } diff --git a/src/main/resources/hudson/plugins/redmine/RedmineProjectProperty/config.jelly b/src/main/resources/hudson/plugins/redmine/RedmineProjectProperty/config.jelly index 5d7abf8..db3c263 100644 --- a/src/main/resources/hudson/plugins/redmine/RedmineProjectProperty/config.jelly +++ b/src/main/resources/hudson/plugins/redmine/RedmineProjectProperty/config.jelly @@ -6,6 +6,10 @@ + + + -- 1.7.9