提交 c2cd2d11 编写于 作者: O Olivier Lamy

prevent some CNFE during tests with call token macro with reflection

上级 3bd3ff9b
/* /*
* The MIT License * The MIT License
* *
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Olivier Lamy
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
...@@ -45,6 +45,7 @@ import hudson.tasks.BuildWrapper; ...@@ -45,6 +45,7 @@ import hudson.tasks.BuildWrapper;
import hudson.tasks.Maven.MavenInstallation; import hudson.tasks.Maven.MavenInstallation;
import hudson.util.ArgumentListBuilder; import hudson.util.ArgumentListBuilder;
import hudson.util.IOUtils; import hudson.util.IOUtils;
import hudson.util.ReflectionUtils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
...@@ -52,6 +53,7 @@ import java.io.FileOutputStream; ...@@ -52,6 +53,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
...@@ -66,8 +68,6 @@ import org.apache.maven.execution.ReactorManager; ...@@ -66,8 +68,6 @@ import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.stapler.Ancestor; import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
...@@ -682,9 +682,13 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> { ...@@ -682,9 +682,13 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
String opts = mms.getMavenOpts(); String opts = mms.getMavenOpts();
if (opts == null ) return null; if (opts == null ) return null;
try { try {
opts = TokenMacro.expand(this, listener, opts); Class<?> clazz = Class.forName( "org.jenkinsci.plugins.tokenmacro.MacroEvaluationException" );
} catch (MacroEvaluationException e) { Method expandMethod =
listener.error( "Ignore MacroEvaluationException " + e.getMessage() ); ReflectionUtils.findMethod(clazz, "expand", new Class[]{ this.getClass(), listener.getClass(), String.class} );
opts = (String) expandMethod.invoke( null, this, listener, opts );
//opts = TokenMacro.expand(this, listener, opts);
//} catch (MacroEvaluationException e) {
// listener.error( "Ignore MacroEvaluationException " + e.getMessage() );
} }
catch(Exception tokenException) { catch(Exception tokenException) {
listener.error("Ignore Problem expanding maven opts macros " + tokenException.getMessage()); listener.error("Ignore Problem expanding maven opts macros " + tokenException.getMessage());
......
...@@ -60,6 +60,7 @@ import hudson.tasks.Maven.MavenInstallation; ...@@ -60,6 +60,7 @@ import hudson.tasks.Maven.MavenInstallation;
import hudson.util.ArgumentListBuilder; import hudson.util.ArgumentListBuilder;
import hudson.util.IOUtils; import hudson.util.IOUtils;
import hudson.util.MaskingClassLoader; import hudson.util.MaskingClassLoader;
import hudson.util.ReflectionUtils;
import hudson.util.StreamTaskListener; import hudson.util.StreamTaskListener;
import java.io.File; import java.io.File;
...@@ -67,6 +68,7 @@ import java.io.IOException; ...@@ -67,6 +68,7 @@ import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
...@@ -92,11 +94,7 @@ import org.apache.maven.model.building.ModelBuildingRequest; ...@@ -92,11 +94,7 @@ import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
import org.codehaus.plexus.util.PathTool; import org.codehaus.plexus.util.PathTool;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.StaplerResponse;
import org.sonatype.aether.transfer.TransferCancelledException; import org.sonatype.aether.transfer.TransferCancelledException;
...@@ -528,9 +526,13 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven ...@@ -528,9 +526,13 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
String opts = project.getMavenOpts(); String opts = project.getMavenOpts();
if (opts == null ) return null; if (opts == null ) return null;
try { try {
opts = TokenMacro.expand(this, listener, opts); Class<?> clazz = Class.forName( "org.jenkinsci.plugins.tokenmacro.MacroEvaluationException" );
} catch (MacroEvaluationException e) { Method expandMethod =
listener.error( "Ignore MacroEvaluationException " + e.getMessage() ); ReflectionUtils.findMethod(clazz, "expand", new Class[]{ this.getClass(), listener.getClass(), String.class} );
opts = (String) expandMethod.invoke( null, this, listener, opts );
//opts = TokenMacro.expand(this, listener, opts);
//} catch (MacroEvaluationException e) {
// listener.error( "Ignore MacroEvaluationException " + e.getMessage() );
} }
catch(Exception tokenException) { catch(Exception tokenException) {
listener.error("Ignore Problem expanding maven opts macros " + tokenException.getMessage()); listener.error("Ignore Problem expanding maven opts macros " + tokenException.getMessage());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册