提交 ec5b5217 编写于 作者: K kohsuke

bake build number to the manifest of jar, war, and ear.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3180 71c3de6d-444a-0410-be80-ed276b4c234a
上级 9ad6242e
......@@ -6,6 +6,7 @@ import hudson.maven.reporters.MavenFingerprinter;
import hudson.maven.reporters.MavenJavadocArchiver;
import hudson.maven.reporters.SurefireArchiver;
import hudson.maven.reporters.MavenMailer;
import hudson.maven.reporters.BuildInfoRecorder;
import java.util.List;
import java.util.ArrayList;
......@@ -23,7 +24,8 @@ public final class MavenReporters {
MavenFingerprinter.DescriptorImpl.DESCRIPTOR,
MavenJavadocArchiver.DescriptorImpl.DESCRIPTOR,
SurefireArchiver.DescriptorImpl.DESCRIPTOR,
MavenMailer.DescriptorImpl.DESCRIPTOR
MavenMailer.DescriptorImpl.DESCRIPTOR,
BuildInfoRecorder.DescriptorImpl.DESCRIPTOR
);
/**
......
package hudson.maven.reporters;
import hudson.maven.MavenModule;
import hudson.maven.MavenReporter;
import hudson.maven.MavenReporterDescriptor;
import hudson.maven.MavenBuildProxy;
import hudson.maven.MojoInfo;
import hudson.maven.MavenBuild;
import hudson.maven.MavenBuildProxy.BuildCallable;
import hudson.model.BuildListener;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import java.io.IOException;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.Map.Entry;
/**
* @author Kohsuke Kawaguchi
*/
public class BuildInfoRecorder extends MavenReporter {
private static final Set<String> keys = new HashSet<String>(Arrays.asList(
"maven-jar-plugin:jar",
"maven-jar-plugin:test-jar",
"maven-war-plugin:war",
"maven-ear-plugin:ear"
));
public boolean preExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException, IOException {
if(mojo.pluginName.groupId.equals("org.apache.maven.plugins")
&& keys.contains(mojo.pluginName.artifactId+':'+mojo.getGoal())) {
// touch <archive><manifestEntries><Build-Numer>#n
Map<String,String> props = build.execute(new BuildCallable<Map<String,String>,IOException>() {
public Map<String,String> call(MavenBuild build) throws IOException, InterruptedException {
Map<String,String> r = new HashMap<String, String>();
r.put("Hudson-Build-Number",String.valueOf(build.getNumber()));
r.put("Hudson-Project",build.getParent().getParent().getName());
return r;
}
});
PlexusConfiguration archive = mojo.configuration.getChild("archive");
PlexusConfiguration manifestEntries = archive.getChild("manifestEntries",true);
for (Entry<String,String> e : props.entrySet()) {
XmlPlexusConfiguration configuration = new XmlPlexusConfiguration(e.getKey());
configuration.setValue(e.getValue());
manifestEntries.addChild(configuration);
}
}
return super.preExecute(build, pom, mojo, listener);
}
public DescriptorImpl getDescriptor() {
return DescriptorImpl.DESCRIPTOR;
}
public static final class DescriptorImpl extends MavenReporterDescriptor {
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
private DescriptorImpl() {
super(BuildInfoRecorder.class);
}
public String getDisplayName() {
return "Record build information";
}
public BuildInfoRecorder newAutoInstance(MavenModule module) {
return new BuildInfoRecorder();
}
}
private static final long serialVersionUID = 1L;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册