提交 e95bd4fb 编写于 作者: K kohsuke

fixed a bug where upstream/downstream links from a maven module in one project...

fixed a bug where upstream/downstream links from a maven module in one project to a maven module in another project is broken.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3015 71c3de6d-444a-0410-be80-ed276b4c234a
上级 06af1a9a
package hudson;
import hudson.maven.ExecutedMojo;
import hudson.model.Action;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Items;
import hudson.model.Job;
import hudson.model.JobPropertyDescriptor;
import hudson.model.ModelObject;
import hudson.model.Node;
import hudson.model.Project;
import hudson.model.Run;
import hudson.model.Items;
import hudson.model.JobPropertyDescriptor;
import hudson.model.Job;
import hudson.model.Action;
import hudson.maven.ExecutedMojo;
import hudson.model.TopLevelItem;
import hudson.model.View;
import org.apache.commons.jexl.parser.ASTSizeFunction;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.apache.commons.jexl.parser.ASTSizeFunction;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
......@@ -380,4 +386,46 @@ public class Functions {
public static ExecutedMojo.Cache createExecutedMojoCache() {
return new ExecutedMojo.Cache();
}
/**
* Computes the relative path from the current page to the given item.
*/
public static String getRelativeLinkTo(Item p) {
Map<Object,String> ancestors = new HashMap<Object,String>();
View view=null;
StaplerRequest request = Stapler.getCurrentRequest();
for( Ancestor a : request.getAncestors() ) {
ancestors.put(a.getObject(),a.getRelativePath());
if(a.getObject() instanceof View)
view = (View) a.getObject();
}
String path = ancestors.get(p);
if(path!=null) return path;
Item i=p;
String url = "";
while(true) {
ItemGroup ig = i.getParent();
url = i.getShortUrl()+url;
if(ig==Hudson.getInstance()) {
assert i instanceof TopLevelItem;
if(view!=null && view.contains((TopLevelItem)i)) {
// if p and the current page belongs to the same view, then return a relative path
return ancestors.get(view)+'/'+url;
} else {
// otherwise return a path from the root Hudson
return request.getContextPath()+'/'+p.getUrl();
}
}
path = ancestors.get(ig);
if(path!=null) return path+'/'+url;
assert ig instanceof Item; // if not, ig must have been the Hudson instance
i = (Item) ig;
}
}
}
......@@ -62,7 +62,7 @@
<j:forEach var="item" items="${upstream}">
<li>
<img src="${rootURL}/images/16x16/${item.buildStatusUrl}"/>
<a href="../${item.name}/">${item.displayName}</a>
<a href="${h.getRelativeLinkTo(item)}">${item.displayName}</a>
<local:relationship lhs="${item}" rhs="${it}"/>
</li>
</j:forEach>
......@@ -75,7 +75,7 @@
<j:forEach var="item" items="${downstream}">
<li>
<img src="${rootURL}/images/16x16/${item.buildStatusUrl}"/>
<a href="../${item.name}/">${item.displayName}</a>
<a href="${h.getRelativeLinkTo(item)}">${item.displayName}</a>
<local:relationship lhs="${it}" rhs="${item}"/>
</li>
</j:forEach>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册