Skip to content

Commit

Permalink
fix in case project doesn't start at repo root.
Browse files Browse the repository at this point in the history
I came up with the following fix for some of our legacy projects and
https://issues.jenkins-ci.org/browse/JENKINS-24373

Maybe there is a more elegant solution (e.g. getting the „offset“ from
the SCM), but as I’m new to jenkins plugin dev I would need some
pointers.
  • Loading branch information
rompic committed Dec 16, 2014
1 parent 36a7837 commit e628f09
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/main/java/hudson/plugins/redmine/RedmineRepositoryBrowser.java
Expand Up @@ -23,18 +23,23 @@
*/
public class RedmineRepositoryBrowser extends SubversionRepositoryBrowser {
private final String repositoryId;

private final String repositoryOffset;
@DataBoundConstructor
public RedmineRepositoryBrowser(String repositoryId) {
public RedmineRepositoryBrowser(String repositoryId, String repositoryOffset) {
this.repositoryId = repositoryId;
this.repositoryOffset = repositoryOffset;
}

/**
* @deprecated use {@link #RedmineRepositoryBrowser(String)}
* @deprecated use {@link #RedmineRepositoryBrowser(String,String)}
*/
@Deprecated
public RedmineRepositoryBrowser() {
this(null);
this(null,null);
}

public String getRepositoryOffset() {
return repositoryOffset;
}

public String getRepositoryId() {
Expand Down Expand Up @@ -149,11 +154,19 @@ private String getRepositoryId(LogEntry logEntry) {
return "/" + this.repositoryId.trim();
}
}

private String getRepositoryOffset(LogEntry logEntry) {
if (this.repositoryOffset == null || this.repositoryOffset.trim().length() == 0){
return "";
} else {
return this.repositoryOffset.trim();
}
}

private String getFilePath(LogEntry logEntry, String fileFullPath) {
AbstractProject<?,?> p = (AbstractProject<?,?>)logEntry.getParent().build.getProject();
RedmineProjectProperty rpp = p.getProperty(RedmineProjectProperty.class);

String rOffset=getRepositoryOffset(logEntry);
String filePath = "";
if(VersionUtil.isVersionBefore081(rpp.getRedmineWebsite().versionNumber)) {
String[] filePaths = fileFullPath.split("/");
Expand All @@ -169,6 +182,12 @@ private String getFilePath(LogEntry logEntry, String fileFullPath) {
} else {
filePath = fileFullPath;
}

if (rOffset.length()>0){
if(filePath.startsWith(rOffset)){
filePath="/"+filePath.substring(rOffset.length());
}
}
return filePath;

}
Expand Down
Expand Up @@ -2,4 +2,7 @@
<f:entry field="repositoryId" title="${%Redmine repository identifier}" help="/plugin/redmine/help-repo.html">
<f:textbox />
</f:entry>
<f:entry field="repositoryOffset" title="${%Redmine repository offset}" help="/plugin/redmine/help-repo-offset.html">
<f:textbox />
</f:entry>
</j:jelly>
@@ -1 +1,2 @@
Redmine\ repository\ identifier=Redmine repository identifier
Redmine\ repository\ offset=Redmine repository offset
3 changes: 3 additions & 0 deletions src/main/webapp/help-repo-offset.html
@@ -0,0 +1,3 @@
<div>
If the Redmine repository is not the project's root, specify the offset here.
</div>

0 comments on commit e628f09

Please sign in to comment.