location of the top-level pom.xml is now configurable.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2021 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-02-01 07:15:31 +00:00
1 parent 827c7be955
commit d9f6e205f7
4 files changed
+46 -4

No files matched your search

@@ -2,6 +2,7 @@ package hudson.maven;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.triggers.Trigger;
import hudson.model.AbstractProject;
import hudson.model.DependencyGraph;
@@ -48,6 +49,8 @@ public class MavenModuleSet extends AbstractProject<MavenModuleSet,MavenModuleSe
*/
private ModuleName rootModule;
private String rootPOM;
public MavenModuleSet(String name) {
super(Hudson.getInstance(),name);
}
@@ -202,6 +205,15 @@ public class MavenModuleSet extends AbstractProject<MavenModuleSet,MavenModuleSe
return modules.get(rootModule);
}
/**
* Gets the location of top-level <tt>pom.xml</tt> relative to the workspace root.
*/
public String getRootPOM() {
if(rootPOM==null) return "pom.xml";
return rootPOM;
}
/*package*/ void setRootModule(ModuleName rootModule) throws IOException {
if(this.rootModule!=null && this.rootModule.equals(rootModule))
return; // no change
@@ -219,6 +231,9 @@ public class MavenModuleSet extends AbstractProject<MavenModuleSet,MavenModuleSe
if(!Hudson.adminCheck(req,rsp))
return;
rootPOM = Util.fixEmpty(req.getParameter("rootPOM"));
if(rootPOM.equals("pom.xml")) rootPOM=null; // normalization
super.doConfigSubmit(req,rsp);
save();
@@ -58,7 +58,7 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
protected Result doRun(final BuildListener listener) throws Exception {
try {
listener.getLogger().println("Parsing POMs");
List<PomInfo> poms = project.getWorkspace().act(new PomParser(listener));
List<PomInfo> poms = project.getWorkspace().act(new PomParser(listener,project.getRootPOM()));
// update the module list
Map<ModuleName,MavenModule> modules = project.modules;
@@ -93,6 +93,9 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
project.getRootModule().scheduleBuild();
return null;
} catch (AbortException e) {
// error should have been already reported.
return Result.FAILURE;
} catch (IOException e) {
e.printStackTrace(listener.error("Failed to parse POMs"));
return Result.FAILURE;
@@ -112,14 +115,21 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
private static final class PomParser implements FileCallable<List<PomInfo>> {
private final BuildListener listener;
private final String rootPOM;
public PomParser(BuildListener listener) {
public PomParser(BuildListener listener, String rootPOM) {
this.listener = listener;
this.rootPOM = rootPOM;
}
public List<PomInfo> invoke(File ws, VirtualChannel channel) throws IOException {
// TODO: this logic needs to be smarter
File pom = new File(ws,"pom.xml");
File pom = new File(ws,rootPOM);
if(!pom.exists()) {
listener.getLogger().println("No such file "+pom);
listener.getLogger().println("Perhaps you need to specify the correct POM file path in the project configuration?");
throw new AbortException();
}
try {
MavenEmbedder embedder = MavenUtil.createEmbedder(listener);
@@ -146,4 +156,8 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
private static final long serialVersionUID = 1L;
}
private static class AbortException extends IOException {
private static final long serialVersionUID = 1L;
}
}