提交 e295fdf1 编写于 作者: C Christoph Kutzinski

Merge branch 'filterimpl-serialization' of github.com:kutzi/jenkins

......@@ -23,6 +23,8 @@
*/
package hudson.maven;
import hudson.Launcher;
import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.model.BuildListener;
import hudson.model.Executor;
import hudson.model.Result;
......@@ -33,6 +35,8 @@ import hudson.remoting.Future;
import java.io.IOException;
import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
......@@ -42,6 +46,7 @@ import jenkins.model.Jenkins;
/**
* @author Olivier Lamy
* @author Christoph Kutzinski
*
*/
public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,IOException> {
......@@ -61,16 +66,45 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
*/
protected final BuildListener listener;
protected Map<ModuleName,FilterImpl> proxies;
/**
* Kept so that we can finalize them in the end method.
*/
protected final transient Map<ModuleName,ProxyImpl2> sourceProxies = new HashMap<ModuleName, MavenBuild.ProxyImpl2>();
protected final Map<ModuleName,List<MavenReporter>> reporters = new HashMap<ModuleName,List<MavenReporter>>();
/**
* Record all asynchronous executions as they are scheduled,
* to make sure they are all completed before we finish.
*/
private transient /*final*/ List<Future<?>> futures;
protected transient /*final*/ List<Future<?>> futures;
protected AbstractMavenBuilder(BuildListener listener, List<String> goals, Map<String, String> systemProps) {
protected AbstractMavenBuilder(BuildListener listener, Collection<MavenModule> modules, List<String> goals, Map<String, String> systemProps) {
this.listener = listener;
this.goals = goals;
this.systemProps = systemProps;
for (MavenModule m : modules) {
reporters.put(m.getModuleName(),m.createReporters());
}
}
/**
* Invoked after the maven has finished running, and in the master, not in the maven process.
*/
void end(Launcher launcher) throws IOException, InterruptedException {
for (Map.Entry<ModuleName,ProxyImpl2> e : sourceProxies.entrySet()) {
ProxyImpl2 p = e.getValue();
for (MavenReporter r : reporters.get(e.getKey())) {
// we'd love to do this when the module build ends, but doing so requires
// we know how many task segments are in the current build.
r.end(p.owner(),launcher,listener);
p.appendLastLog();
}
p.close();
}
}
protected String formatArgs(List<String> args) {
......@@ -119,6 +153,11 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
*/
protected void initializeAsynchronousExecutions() {
futures = new CopyOnWriteArrayList<Future<?>>();
if (this.proxies != null) {
for(FilterImpl proxy : this.proxies.values()) {
proxy.setFutures(futures);
}
}
}
/**
......@@ -160,7 +199,7 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
}
}
protected class FilterImpl extends MavenBuildProxy2.Filter<MavenBuildProxy2> implements Serializable {
protected static class FilterImpl extends MavenBuildProxy2.Filter<MavenBuildProxy2> implements Serializable {
private MavenBuildInformation mavenBuildInformation;
......@@ -173,6 +212,8 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
*/
private transient Channel channel;
private transient List<Future<?>> futures;
public FilterImpl(MavenBuildProxy2 core, MavenBuildInformation mavenBuildInformation) {
super(core);
this.mavenBuildInformation = mavenBuildInformation;
......@@ -189,7 +230,7 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
@Override
public void executeAsync(final BuildCallable<?,?> program) throws IOException {
recordAsynchronousExecution(
futures.add(
channel.callAsync(
new AsyncInvoker(core,program)));
}
......@@ -197,6 +238,10 @@ public abstract class AbstractMavenBuilder implements DelegatingCallable<Result,
public MavenBuildInformation getMavenBuildInformation() {
return mavenBuildInformation;
}
public void setFutures(List<Future<?>> futures) {
this.futures = futures;
}
public Object readResolve() {
channel = Channel.current();
......
......@@ -24,7 +24,6 @@
*/
package hudson.maven;
import hudson.Launcher;
import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.model.BuildListener;
import hudson.model.Result;
......@@ -53,42 +52,19 @@ import org.apache.maven.project.MavenProject;
*/
@SuppressWarnings("deprecation") // as we're restricted to Maven 2.x API here, but compile against Maven 3.x, we cannot avoid deprecations
final class Maven2Builder extends MavenBuilder {
private final Map<ModuleName,MavenBuildProxy2> proxies;
private final Map<ModuleName,List<MavenReporter>> reporters = new HashMap<ModuleName,List<MavenReporter>>();
private final Map<ModuleName,List<ExecutedMojo>> executedMojos = new HashMap<ModuleName,List<ExecutedMojo>>();
private long mojoStartTime;
private MavenBuildProxy2 lastProxy;
/**
* Kept so that we can finalize them in the end method.
*/
private final transient Map<ModuleName,ProxyImpl2> sourceProxies;
public Maven2Builder(BuildListener listener,Map<ModuleName,ProxyImpl2> proxies, Collection<MavenModule> modules, List<String> goals, Map<String,String> systemProps, MavenBuildInformation mavenBuildInformation) {
super(listener,goals,systemProps);
this.sourceProxies = proxies;
this.proxies = new HashMap<ModuleName, MavenBuildProxy2>(proxies);
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet())
e.setValue(new FilterImpl(e.getValue(), mavenBuildInformation));
for (MavenModule m : modules)
reporters.put(m.getModuleName(),m.createReporters());
}
/**
* Invoked after the maven has finished running, and in the master, not in the maven process.
*/
void end(Launcher launcher) throws IOException, InterruptedException {
for (Map.Entry<ModuleName,ProxyImpl2> e : sourceProxies.entrySet()) {
ProxyImpl2 p = e.getValue();
for (MavenReporter r : reporters.get(e.getKey())) {
// we'd love to do this when the module build ends, but doing so requires
// we know how many task segments are in the current build.
r.end(p.owner(),launcher,listener);
p.appendLastLog();
}
p.close();
super(listener,modules,goals,systemProps);
this.sourceProxies.putAll(proxies);
this.proxies = new HashMap<ModuleName, FilterImpl>();
for (Entry<ModuleName,ProxyImpl2> e : this.sourceProxies.entrySet()) {
this.proxies.put(e.getKey(), new FilterImpl(e.getValue(), mavenBuildInformation));
}
}
......@@ -116,7 +92,7 @@ final class Maven2Builder extends MavenBuilder {
buildingProjects.add(new ModuleName(p));
}
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet()) {
for (Entry<ModuleName,FilterImpl> e : this.proxies.entrySet()) {
if (! buildingProjects.contains(e.getKey())) {
MavenBuildProxy2 proxy = e.getValue();
proxy.start();
......
......@@ -37,13 +37,13 @@ import java.io.PrintStream;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;
......@@ -77,29 +77,21 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
HudsonMavenExecutionResult mavenExecutionResult;
private final Map<ModuleName,MavenBuildProxy2> proxies;
private final Map<ModuleName,ProxyImpl2> sourceProxies;
private final Map<ModuleName,List<MavenReporter>> reporters = new HashMap<ModuleName,List<MavenReporter>>();
private final MavenBuildInformation mavenBuildInformation;
protected Maven3Builder(BuildListener listener,Map<ModuleName,ProxyImpl2> proxies, Map<ModuleName,List<MavenReporter>> reporters, List<String> goals, Map<String, String> systemProps, MavenBuildInformation mavenBuildInformation) {
super( listener, goals, systemProps );
this.mavenBuildInformation = mavenBuildInformation;
sourceProxies = new HashMap<ModuleName, ProxyImpl2>(proxies);
this.proxies = new HashMap<ModuleName, MavenBuildProxy2>(proxies);
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet())
e.setValue(new FilterImpl(e.getValue(), this.mavenBuildInformation));
this.reporters.putAll( reporters );
protected Maven3Builder(BuildListener listener,Map<ModuleName,ProxyImpl2> proxies, Collection<MavenModule> modules, List<String> goals, Map<String, String> systemProps, MavenBuildInformation mavenBuildInformation) {
super( listener, modules, goals, systemProps );
this.sourceProxies.putAll(proxies);
this.proxies = new HashMap<ModuleName, FilterImpl>();
for (Entry<ModuleName,ProxyImpl2> e : this.sourceProxies.entrySet()) {
this.proxies.put(e.getKey(), new FilterImpl(e.getValue(), mavenBuildInformation));
}
}
public Result call() throws IOException {
MavenExecutionListener mavenExecutionListener = new MavenExecutionListener( this );
try {
initializeAsynchronousExecutions();
MavenExecutionListener mavenExecutionListener = new MavenExecutionListener( this );
Maven3Launcher.setMavenExecutionListener( mavenExecutionListener );
markAsSuccess = false;
......@@ -167,22 +159,6 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
}
}
/**
* Invoked after the maven has finished running, and in the master, not in the maven process.
*/
void end(Launcher launcher) throws IOException, InterruptedException {
for (Map.Entry<ModuleName,ProxyImpl2> e : sourceProxies.entrySet()) {
ProxyImpl2 p = e.getValue();
for (MavenReporter r : reporters.get(e.getKey())) {
// we'd love to do this when the module build ends, but doing so requires
// we know how many task segments are in the current build.
r.end(p.owner(),launcher,listener);
p.appendLastLog();
}
p.close();
}
}
private static final class MavenExecutionListener extends AbstractExecutionListener implements Serializable, ExecutionListener {
private static final long serialVersionUID = 4942789836756366116L;
......@@ -195,11 +171,11 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
long overheadTime;
private final Map<ModuleName,MavenBuildProxy2> proxies;
private final Map<ModuleName,FilterImpl> proxies;
private final Map<ModuleName,List<ExecutedMojo>> executedMojosPerModule = new ConcurrentHashMap<ModuleName, List<ExecutedMojo>>();
private final Map<ModuleName,List<MavenReporter>> reporters = new ConcurrentHashMap<ModuleName,List<MavenReporter>>();
private final Map<ModuleName,List<MavenReporter>> reporters;
private final Map<ModuleName, Long> currentMojoStartPerModuleName = new ConcurrentHashMap<ModuleName, Long>();
......@@ -207,18 +183,16 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
public MavenExecutionListener(Maven3Builder maven3Builder) {
this.maven3Builder = maven3Builder;
this.proxies = new ConcurrentHashMap<ModuleName, MavenBuildProxy2>(maven3Builder.proxies);
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet())
{
e.setValue(maven3Builder.new FilterImpl(e.getValue(), maven3Builder.mavenBuildInformation, Channel.current()));
executedMojosPerModule.put( e.getKey(), new CopyOnWriteArrayList<ExecutedMojo>() );
this.proxies = new ConcurrentHashMap<ModuleName, FilterImpl>(maven3Builder.proxies);
for (ModuleName name : this.proxies.keySet()) {
executedMojosPerModule.put( name, new CopyOnWriteArrayList<ExecutedMojo>() );
}
this.reporters.putAll( new ConcurrentHashMap<ModuleName, List<MavenReporter>>(maven3Builder.reporters) );
this.reporters = new ConcurrentHashMap<ModuleName, List<MavenReporter>>(maven3Builder.reporters);
this.eventLogger = new ExecutionEventLogger( new PrintStreamLogger( maven3Builder.listener.getLogger() ) );
}
private MavenBuildProxy2 getMavenBuildProxy2(MavenProject mavenProject) {
for (Entry<ModuleName,MavenBuildProxy2> entry : proxies.entrySet()) {
for (Entry<ModuleName,FilterImpl> entry : proxies.entrySet()) {
if (entry.getKey().compareTo( new ModuleName( mavenProject ) ) == 0) {
return entry.getValue();
}
......@@ -235,7 +209,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
}
private void initMojoStartTime( MavenProject mavenProject) {
this.currentMojoStartPerModuleName.put( new ModuleName(mavenProject), new Date().getTime() );
this.currentMojoStartPerModuleName.put( new ModuleName( mavenProject), Long.valueOf( System.currentTimeMillis() ) );
}
private Long getMojoStartTime(MavenProject mavenProject) {
......@@ -264,7 +238,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
buildingProjects.add(new ModuleName(p));
}
for (Entry<ModuleName,MavenBuildProxy2> e : this.proxies.entrySet()) {
for (Entry<ModuleName,FilterImpl> e : this.proxies.entrySet()) {
if (! buildingProjects.contains(e.getKey())) {
//maven3Builder.listener.getLogger().println("Project " + e.getKey() + " needs not be build");
MavenBuildProxy2 proxy = e.getValue();
......@@ -521,7 +495,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
executedMojosPerModule.put(new ModuleName(p), m=new CopyOnWriteArrayList<ExecutedMojo>());
Long startTime = getMojoStartTime( event.getProject() );
m.add(new ExecutedMojo( mojoInfo, startTime == null ? 0 : new Date().getTime() - startTime ));
m.add(new ExecutedMojo( mojoInfo, startTime == null ? 0 : System.currentTimeMillis() - startTime ));
}
/**
......
......@@ -296,19 +296,19 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
*/
private static final class Builder extends MavenBuilder {
private final MavenBuildProxy buildProxy;
private final MavenReporter[] reporters;
/**
* Records of what was executed.
*/
private final List<ExecutedMojo> executedMojos = new ArrayList<ExecutedMojo>();
private final ModuleName moduleName;
private long startTime;
public Builder(BuildListener listener,MavenBuildProxy buildProxy,MavenReporter[] reporters, List<String> goals, Map<String,String> systemProps) {
super(listener,goals,systemProps);
public Builder(BuildListener listener,MavenBuildProxy buildProxy,MavenModule module, List<String> goals, Map<String,String> systemProps) {
super(listener,Collections.singleton(module),goals,systemProps);
this.buildProxy = new FilterImpl(buildProxy);
this.reporters = reporters;
this.moduleName = module.getModuleName();
}
private class FilterImpl extends MavenBuildProxy.Filter<MavenBuildProxy> implements Serializable {
......@@ -326,20 +326,20 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
@Override
void preBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException, IOException, InterruptedException {
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
r.preBuild(buildProxy,rm.getTopLevelProject(),listener);
}
@Override
void postBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException, IOException, InterruptedException {
buildProxy.setExecutedMojos(executedMojos);
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
r.postBuild(buildProxy,rm.getTopLevelProject(),listener);
}
@Override
void preExecute(MavenProject project, MojoInfo info) throws IOException, InterruptedException, AbortException {
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
if(!r.preExecute(buildProxy,project,info,listener))
throw new AbortException(r+" failed");
......@@ -350,28 +350,28 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
void postExecute(MavenProject project, MojoInfo info, Exception exception) throws IOException, InterruptedException, AbortException {
executedMojos.add(new ExecutedMojo(info,System.currentTimeMillis()-startTime));
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
if(!r.postExecute(buildProxy,project,info,listener,exception))
throw new AbortException(r+" failed");
}
@Override
void onReportGenerated(MavenProject project, MavenReportInfo report) throws IOException, InterruptedException, AbortException {
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
if(!r.reportGenerated(buildProxy,project,report,listener))
throw new AbortException(r+" failed");
}
@Override
void preModule(MavenProject project) throws InterruptedException, IOException, AbortException {
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
if(!r.enterModule(buildProxy,project,listener))
throw new AbortException(r+" failed");
}
@Override
void postModule(MavenProject project) throws InterruptedException, IOException, AbortException {
for (MavenReporter r : reporters)
for (MavenReporter r : reporters.get(moduleName))
if(!r.leaveModule(buildProxy,project,listener))
throw new AbortException(r+" failed");
}
......@@ -725,7 +725,7 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
try {
Result r = process.call(new Builder(
listener,new ProxyImpl(),
reporters.toArray(new MavenReporter[reporters.size()]), margs.toList(), systemProps));
getProject(), margs.toList(), systemProps));
normalExit = true;
return r;
} finally {
......
......@@ -40,6 +40,7 @@ import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.maven.BuildFailureException;
......@@ -79,8 +80,8 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
*/
private final boolean profile = MavenProcessFactory.profile;
protected MavenBuilder(BuildListener listener, List<String> goals, Map<String, String> systemProps) {
super( listener, goals, systemProps );
protected MavenBuilder(BuildListener listener, Collection<MavenModule> modules, List<String> goals, Map<String, String> systemProps) {
super( listener, modules, goals, systemProps );
}
/**
......
......@@ -388,7 +388,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
public void setMavenVersionUsed( String mavenVersionUsed ) throws IOException {
this.mavenVersionUsed = mavenVersionUsed;
this.mavenVersionUsed = Util.intern(mavenVersionUsed);
save();
}
......@@ -699,7 +699,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
pom = parentLoc;
ProcessCache.MavenProcess process = null;
final ProcessCache.MavenProcess process;
boolean maven3orLater = mavenBuildInformation.isMaven3OrLater();
if ( maven3orLater )
......@@ -778,44 +778,27 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
}
if (maven3orLater)
{
Map<ModuleName,List<MavenReporter>> reporters = new HashMap<ModuleName, List<MavenReporter>>(project.sortedActiveModules.size());
for (MavenModule mavenModule : project.sortedActiveModules)
{
reporters.put( mavenModule.getModuleName(), mavenModule.createReporters() );
}
Maven3Builder maven3Builder =
new Maven3Builder( slistener, proxies, reporters, margs.toList(), envVars, mavenBuildInformation );
MavenProbeAction mpa=null;
try {
mpa = new MavenProbeAction(project,process.channel);
addAction(mpa);
r = process.call(maven3Builder);
return r;
} finally {
maven3Builder.end(launcher);
getActions().remove(mpa);
process.discard();
}
final AbstractMavenBuilder builder;
if (maven3orLater) {
builder =
new Maven3Builder( slistener, proxies, project.sortedActiveModules, margs.toList(), envVars, mavenBuildInformation );
} else {
Maven2Builder builder =
builder =
new Maven2Builder(slistener, proxies, project.sortedActiveModules, margs.toList(), envVars, mavenBuildInformation);
MavenProbeAction mpa=null;
try {
mpa = new MavenProbeAction(project,process.channel);
addAction(mpa);
r = process.call(builder);
return r;
} finally {
builder.end(launcher);
getActions().remove(mpa);
process.discard();
}
}
MavenProbeAction mpa=null;
try {
mpa = new MavenProbeAction(project,process.channel);
addAction(mpa);
r = process.call(builder);
return r;
} finally {
builder.end(launcher);
getActions().remove(mpa);
process.discard();
}
} catch (InterruptedException e) {
r = Executor.currentExecutor().abortResult();
throw e;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册