Skip to content

Commit

Permalink
Fixed JENKINS-10889
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Sep 5, 2011
1 parent 757aaf9 commit c4c2085
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
8 changes: 7 additions & 1 deletion pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -48,6 +49,11 @@
<version>${guice.version}</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
</dependency>

</dependencies>

</project>
Expand Down
Expand Up @@ -6,10 +6,9 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.*;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
Expand Down Expand Up @@ -174,13 +173,15 @@ public String getDisplayName() {
}

@Override
public String getHelpFile() {
return "/plugin/postbuildscript/help.html";
}
public String getHelpFile() {
return "/plugin/postbuildscript/help.html";
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
return Project.class.isAssignableFrom(jobType)
|| MatrixProject.class.isAssignableFrom(jobType)
|| MavenModuleSet.class.isAssignableFrom(jobType);
}
}
}
@@ -1,10 +1,9 @@
package org.jenkinsci.plugins.postbuildscript;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Project;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.*;
import hudson.model.listeners.RunListener;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
Expand All @@ -25,14 +24,29 @@ public class PostBuildScriptListener extends RunListener<Run> implements Seriali

@Override
public void onStarted(Run run, TaskListener listener) {
try {
Job job = run.getParent();
if (job instanceof MavenModuleSet) {
putLastListPostBuildPublisher(MavenModuleSet.class, (MavenModuleSet) job);
} else if (job instanceof MatrixProject) {
putLastListPostBuildPublisher(MatrixProject.class, (MatrixProject) job);
} else {
putLastListPostBuildPublisher(Project.class, (Project) job);
}
} catch (PostBuildScriptException pe) {
LOGGER.severe("[PostBuildScript] - Severe error to start" + pe.getMessage());
pe.printStackTrace();
}

}

Project jenkinsProject = (Project) run.getParent();

private void putLastListPostBuildPublisher(Class<? extends AbstractProject> jobClass, AbstractProject project) throws PostBuildScriptException {
Field publishersField;
try {
publishersField = Project.class.getDeclaredField("publishers");
publishersField = jobClass.getDeclaredField("publishers");
publishersField.setAccessible(true);
DescribableList<Publisher, Descriptor<Publisher>> publishers = (DescribableList<Publisher, Descriptor<Publisher>>) publishersField.get(jenkinsProject);
DescribableList<Publisher, Descriptor<Publisher>> publishers = (DescribableList<Publisher, Descriptor<Publisher>>) publishersField.get(project);
Iterator<Publisher> it = publishers.iterator();
while (it.hasNext()) {
Publisher curPublisher = it.next();
Expand All @@ -41,17 +55,15 @@ public void onStarted(Run run, TaskListener listener) {
publishers.add(curPublisher);
}
}
publishersField.set(jenkinsProject, publishers);
publishersField.set(project, publishers);

} catch (NoSuchFieldException nse) {
LOGGER.severe("[PostBuildScript] - Severe error to start" + nse.getMessage());
nse.printStackTrace();
} catch (IllegalAccessException ie) {
LOGGER.severe("[PostBuildScript] - Severe error to start" + ie.getMessage());
ie.printStackTrace();
throw new PostBuildScriptException(nse);
} catch (IllegalAccessException iae) {
throw new PostBuildScriptException(iae);
} catch (IOException ioe) {
LOGGER.severe("[PostBuildScript] - Severe error to start" + ioe.getMessage());
ioe.printStackTrace();
throw new PostBuildScriptException(ioe);
}
}

}

0 comments on commit c4c2085

Please sign in to comment.