mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
compute the relative path among modules so that workspace root can be computed accordingly.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1870 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
1225d1c43a
commit
9ccc797fc4
4 files changed
+47
-17
No files matched your search
@@ -34,9 +34,16 @@ public final class MavenModule extends AbstractProject<MavenModule,MavenBuild> i
|
||||
|
||||
private transient ModuleName moduleName;
|
||||
|
||||
/**
|
||||
* Relative path to this module's root directory
|
||||
* from {@link MavenModuleSet#getWorkspace()}
|
||||
*/
|
||||
private String relativePath;
|
||||
|
||||
/*package*/ MavenModule(MavenModuleSet parent, PomInfo pom) {
|
||||
super(parent, pom.name.toFileSystemName());
|
||||
displayName = pom.displayName;
|
||||
this.displayName = pom.displayName;
|
||||
this.relativePath = pom.relativePath;
|
||||
}
|
||||
|
||||
protected void doSetName(String name) {
|
||||
@@ -54,8 +61,7 @@ public final class MavenModule extends AbstractProject<MavenModule,MavenBuild> i
|
||||
|
||||
@Override
|
||||
public FilePath getWorkspace() {
|
||||
// TODO: implement this method later
|
||||
throw new UnsupportedOperationException();
|
||||
return getParent().getWorkspace().child(relativePath);
|
||||
}
|
||||
|
||||
public ModuleName getModuleName() {
|
||||
|
||||
@@ -6,18 +6,18 @@ import hudson.Launcher;
|
||||
import hudson.Util;
|
||||
import hudson.model.AbstractItem;
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import hudson.model.DirectoryBrowserSupport;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.Item;
|
||||
import hudson.model.ItemGroup;
|
||||
import hudson.model.Items;
|
||||
import hudson.model.JDK;
|
||||
import hudson.model.LargeText;
|
||||
import hudson.model.Node;
|
||||
import hudson.model.Project;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.model.TopLevelItem;
|
||||
import hudson.model.TopLevelItemDescriptor;
|
||||
import hudson.model.LargeText;
|
||||
import hudson.model.Item;
|
||||
import hudson.model.DirectoryBrowserSupport;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.scm.NullSCM;
|
||||
import hudson.scm.SCM;
|
||||
@@ -37,10 +37,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Group of {@link MavenModule}s.
|
||||
@@ -215,10 +216,11 @@ public class MavenModuleSet extends AbstractItem implements TopLevelItem, ItemGr
|
||||
try {
|
||||
MavenEmbedder embedder = MavenUtil.createEmbedder(listener);
|
||||
MavenProject mp = embedder.readProject(pom);
|
||||
MavenUtil.resolveModules(embedder,mp);
|
||||
Map<MavenProject,String> relPath = new HashMap<MavenProject,String>();
|
||||
MavenUtil.resolveModules(embedder,mp,"",relPath);
|
||||
|
||||
List<PomInfo> infos = new ArrayList<PomInfo>();
|
||||
toPomInfo(mp,infos);
|
||||
toPomInfo(mp,relPath,infos);
|
||||
return infos;
|
||||
} catch (MavenEmbedderException e) {
|
||||
// TODO: better error handling needed
|
||||
@@ -228,10 +230,10 @@ public class MavenModuleSet extends AbstractItem implements TopLevelItem, ItemGr
|
||||
}
|
||||
}
|
||||
|
||||
private void toPomInfo(MavenProject mp, List<PomInfo> infos) {
|
||||
infos.add(new PomInfo(mp));
|
||||
private void toPomInfo(MavenProject mp, Map<MavenProject,String> relPath, List<PomInfo> infos) {
|
||||
infos.add(new PomInfo(mp,relPath.get(mp)));
|
||||
for (MavenProject child : (List<MavenProject>)mp.getCollectedProjects())
|
||||
toPomInfo(child,infos);
|
||||
toPomInfo(child,relPath,infos);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.apache.maven.project.ProjectBuildingException;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -40,18 +41,30 @@ class MavenUtil {
|
||||
* Recursively resolves module POMs that are referenced from
|
||||
* the given {@link MavenProject} and parses them into
|
||||
* {@link MavenProject}s.
|
||||
*
|
||||
* @param rel
|
||||
* Used to compute the relative path. Pass in "" to begin.
|
||||
* @param relativePathInfo
|
||||
* Upon the completion of this method, this variable stores the relative path
|
||||
* from the root directory of the given {@link MavenProject} to the root directory
|
||||
* of each of the newly parsed {@link MavenProject}.
|
||||
*/
|
||||
public static void resolveModules(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {
|
||||
public static void resolveModules(MavenEmbedder embedder, MavenProject project, String rel, Map<MavenProject,String> relativePathInfo) throws ProjectBuildingException {
|
||||
|
||||
File basedir = project.getFile().getParentFile();
|
||||
relativePathInfo.put(project,rel);
|
||||
|
||||
List<MavenProject> modules = new ArrayList<MavenProject>();
|
||||
|
||||
for (String modulePath : (List<String>) project.getModules()) {
|
||||
File moduleFile = new File(new File(basedir, modulePath),"pom.xml");
|
||||
|
||||
String relativePath = rel;
|
||||
if(relativePath.length()>0) relativePath+='/';
|
||||
relativePath+=modulePath;
|
||||
|
||||
MavenProject child = embedder.readProject(moduleFile);
|
||||
resolveModules(embedder,child);
|
||||
resolveModules(embedder,child,relativePath,relativePathInfo);
|
||||
modules.add(child);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,18 @@ final class PomInfo implements Serializable {
|
||||
*/
|
||||
public final String displayName;
|
||||
|
||||
public PomInfo(MavenProject project) {
|
||||
/**
|
||||
* Relative path from the root directory of the root POM to
|
||||
* the root directory of this module.
|
||||
*
|
||||
* Strings like "" (if this is the root), "abc", "foo/bar/zot".
|
||||
*/
|
||||
public final String relativePath;
|
||||
|
||||
public PomInfo(MavenProject project, String relPath) {
|
||||
this.name = new ModuleName(project.getGroupId(),project.getArtifactId());
|
||||
this.displayName = project.getName();
|
||||
this.relativePath = relPath;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
Reference in new issue
Block a user