Skip to content

Commit

Permalink
prevent some CNFE during tests with call token macro with reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
olamy committed Mar 17, 2011
1 parent 3bd3ff9 commit c2cd2d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
16 changes: 10 additions & 6 deletions maven-plugin/src/main/java/hudson/maven/MavenBuild.java
@@ -1,7 +1,7 @@
/*
* 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
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -45,13 +45,15 @@
import hudson.tasks.Maven.MavenInstallation;
import hudson.util.ArgumentListBuilder;
import hudson.util.IOUtils;
import hudson.util.ReflectionUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
Expand All @@ -66,8 +68,6 @@
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.monitor.event.EventDispatcher;
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.Stapler;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -682,9 +682,13 @@ public String getMavenOpts(TaskListener listener) {
String opts = mms.getMavenOpts();
if (opts == null ) return null;
try {
opts = TokenMacro.expand(this, listener, opts);
} catch (MacroEvaluationException e) {
listener.error( "Ignore MacroEvaluationException " + e.getMessage() );
Class<?> clazz = Class.forName( "org.jenkinsci.plugins.tokenmacro.MacroEvaluationException" );
Method expandMethod =
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) {
listener.error("Ignore Problem expanding maven opts macros " + tokenException.getMessage());
Expand Down
16 changes: 9 additions & 7 deletions maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
Expand Up @@ -60,13 +60,15 @@
import hudson.util.ArgumentListBuilder;
import hudson.util.IOUtils;
import hudson.util.MaskingClassLoader;
import hudson.util.ReflectionUtils;
import hudson.util.StreamTaskListener;

import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -92,11 +94,7 @@
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.project.MavenProject;
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.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.sonatype.aether.transfer.TransferCancelledException;
Expand Down Expand Up @@ -528,9 +526,13 @@ public String getMavenOpts(TaskListener listener) {
String opts = project.getMavenOpts();
if (opts == null ) return null;
try {
opts = TokenMacro.expand(this, listener, opts);
} catch (MacroEvaluationException e) {
listener.error( "Ignore MacroEvaluationException " + e.getMessage() );
Class<?> clazz = Class.forName( "org.jenkinsci.plugins.tokenmacro.MacroEvaluationException" );
Method expandMethod =
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) {
listener.error("Ignore Problem expanding maven opts macros " + tokenException.getMessage());
Expand Down

0 comments on commit c2cd2d1

Please sign in to comment.