Skip to content
Permalink
Browse files

[JENKINS-41636] Call Maven3MojoNote.encode on master.

  • Loading branch information...
jglick authored and aheritier committed Jan 24, 2017
1 parent e8955ae commit 1a19f4c860fb46d36b380e571b519080d2ac74d6
@@ -31,6 +31,8 @@
import hudson.model.Result;
import hudson.remoting.Channel;
import hudson.remoting.DelegatingCallable;
import hudson.tasks._maven.Maven3MojoNote;
import jenkins.model.Jenkins;
import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.AbstractExecutionListener;
import org.apache.maven.execution.ExecutionEvent;
@@ -79,7 +81,9 @@
Class<?> maven3LauncherClass;
boolean supportEventSpy = false;

protected Maven3Builder(Maven3BuilderRequest maven3BuilderRequest) {
private final String mojoNote;

protected Maven3Builder(Maven3BuilderRequest maven3BuilderRequest) throws IOException {
super( maven3BuilderRequest.listener, maven3BuilderRequest.modules, maven3BuilderRequest.goals, maven3BuilderRequest.systemProps );
this.sourceProxies.putAll(maven3BuilderRequest.proxies);
this.proxies = new HashMap<ModuleName, FilterImpl>();
@@ -89,6 +93,8 @@ protected Maven3Builder(Maven3BuilderRequest maven3BuilderRequest) {
this.maven3LauncherClass = maven3BuilderRequest.maven3LauncherClass;
this.maven3MainClass = maven3BuilderRequest.maven3MainClass;
this.supportEventSpy = maven3BuilderRequest.supportEventSpy;
assert Jenkins.getInstance() != null : "this is supposed to be run on master";
mojoNote = new Maven3MojoNote().encode();
}

protected static class Maven3BuilderRequest {
@@ -191,7 +197,7 @@ private void configureConsoleLogging() {
private static final class JenkinsEventSpy extends MavenExecutionListener implements EventSpy,Serializable{
private static final long serialVersionUID = 4942789836756366117L;

public JenkinsEventSpy(AbstractMavenBuilder maven3Builder) {
JenkinsEventSpy(Maven3Builder maven3Builder) {
super(maven3Builder);
// avoid log event output duplication for maven 3.1 build which use eventSpy
// there is a delagation which duplicate log event.
@@ -358,7 +364,7 @@ public void close()

protected ExecutionEventLogger eventLogger;

public MavenExecutionListener(AbstractMavenBuilder maven3Builder) {
MavenExecutionListener(Maven3Builder maven3Builder) {
this.maven3Builder = maven3Builder;
this.proxies = new ConcurrentHashMap<ModuleName, FilterImpl>(maven3Builder.proxies);
for (ModuleName name : this.proxies.keySet()) {
@@ -368,7 +374,7 @@ public MavenExecutionListener(AbstractMavenBuilder maven3Builder) {


// E.g. there's also the option to redirect logging to a file which is handled there, but not here.
this.eventLogger = new ExecutionEventLogger( logger );
this.eventLogger = new ExecutionEventLogger( logger, maven3Builder.mojoNote );
}


@@ -19,10 +19,6 @@
* under the License.
*/

import hudson.tasks._maven.Maven3MojoNote;

import java.io.IOException;

import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
@@ -34,17 +30,26 @@
extends org.apache.maven.cli.event.ExecutionEventLogger
{
private final Logger logger;
private final String mojoNote;

public ExecutionEventLogger()
{
super();
logger = LoggerFactory.getLogger( ExecutionEventLogger.class );
mojoNote = null; // Maven 3.1+, so unused; cf. JenkinsEventSpy
}

@Deprecated
public ExecutionEventLogger( Logger logger )
{
this(logger, null);
}

public ExecutionEventLogger( Logger logger, String mojoNote )
{
super(logger);
this.logger = logger;
this.mojoNote = mojoNote;
}

/**
@@ -53,16 +58,10 @@ public ExecutionEventLogger( Logger logger )
@Override
public void mojoStarted( ExecutionEvent event )
{
if ( logger.isInfoEnabled() )
if ( mojoNote != null && logger.isInfoEnabled() )
{
final Maven3MojoNote note = new Maven3MojoNote();
final StringBuilder buffer = new StringBuilder( 128 );
try {
buffer.append( note.encode() );
} catch ( IOException e ) {
// As we use only memory buffers this should not happen, ever.
throw new RuntimeException( "Could not encode note?", e );
}
buffer.append(mojoNote);
buffer.append( "--- " );
append( buffer, event.getMojoExecution() );
append( buffer, event.getProject() );

0 comments on commit 1a19f4c

Please sign in to comment.
You can’t perform that action at this time.