提交 d9f6e205 编写于 作者: K kohsuke

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
上级 827c7be9
......@@ -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;
}
}
......@@ -22,6 +22,12 @@
<st:include page="/hudson/model/BuildAuthorizationToken/config.jelly" />
</f:section>
<f:section title="Build">
<f:entry title="root POM" help="/help/maven/root-pom.html">
<f:textbox name="rootPOM" value="${it.rootPOM}"/>
</f:entry>
</f:section>
<f:block>
<input type="submit" name="Submit" value="Save" />
</f:block>
......
<div>
If your workspace has the top-level <tt>pom.xml</tt> in somewhere other
than the root directory of the workspace, specify the path (relative to
the workspace root) here, such as <tt>parent/pom.xml</tt>.
<br>
If left empty, treated as <tt>pom.xml</tt>
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册