Skip to content
Permalink
Browse files

Merge pull request #11 from jglick/CreationException-JENKINS-39134

[JENKINS-39134] Work around Guice problem
  • Loading branch information...
alvarolobato committed Dec 1, 2016
2 parents a1bd50a + 14bf1c5 commit 0fbb0d2e553eae676519b496918aaf54621345a7
30 pom.xml
@@ -29,7 +29,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.11</version>
<version>2.19</version>
<relativePath/>
</parent>

<artifactId>pipeline-maven</artifactId>
@@ -87,12 +88,37 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.2</version>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
<version>2.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.23</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.11</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -24,33 +24,42 @@

package org.jenkinsci.plugins.pipeline.maven;

import com.google.common.collect.ImmutableSet;
import hudson.EnvVars;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig.GlobalMavenSettingsConfigProvider;
import org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig.MavenSettingsConfigProvider;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import hudson.Extension;
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.JDK;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.Maven;
import hudson.tasks.Maven.MavenInstallation;
import hudson.util.ListBoxModel;
import java.util.Set;
import jenkins.model.Jenkins;
import jenkins.mvn.GlobalMavenConfig;
import jenkins.mvn.SettingsProvider;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.StepExecution;

/**
* Configures maven environment to use within a pipeline job by calling <tt>sh mvn</tt> or <tt>bat mvn</tt>.
* The selected maven installation will be configured and prepended to the path.
*
*/
public class WithMavenStep extends AbstractStepImpl {
public class WithMavenStep extends Step {


private String mavenSettingsConfig;
@@ -139,12 +148,13 @@ public void setMavenLocalRepo(String mavenLocalRepo) {
this.mavenLocalRepo = mavenLocalRepo;
}

@Extension
public static class DescriptorImpl extends AbstractStepDescriptorImpl {
@Override
public StepExecution start(StepContext context) throws Exception {
return new WithMavenStepExecution(context, this);
}

public DescriptorImpl() {
super(WithMavenStepExecution.class);
}
@Extension
public static class DescriptorImpl extends StepDescriptor {

@Override
public String getFunctionName() {
@@ -161,6 +171,11 @@ public boolean takesImplicitBlockArgument() {
return true;
}

@Override
public Set<Class<?>> getRequiredContext() {
return ImmutableSet.of(TaskListener.class, FilePath.class, Launcher.class, EnvVars.class, Run.class);
}

@Restricted(NoExternalUse.class) // Only for UI calls
public SettingsProvider getDefaultSettingsProvider() {
return GlobalMavenConfig.get().getSettingsProvider();
@@ -49,16 +49,14 @@
import org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig;
import org.jenkinsci.plugins.configfiles.maven.security.CredentialsHelper;
import org.jenkinsci.plugins.configfiles.maven.security.ServerCredentialMapping;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import org.jenkinsci.plugins.workflow.steps.BodyExecution;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
import org.jenkinsci.plugins.workflow.steps.BodyInvoker;
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.google.inject.Inject;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import hudson.AbortException;
import hudson.EnvVars;
@@ -75,8 +73,10 @@
import hudson.tasks._maven.MavenConsoleAnnotator;
import hudson.util.ArgumentListBuilder;
import jenkins.model.*;
import org.jenkinsci.plugins.workflow.steps.StepExecution;

public class WithMavenStepExecution extends AbstractStepExecutionImpl {
@SuppressFBWarnings(value="SE_TRANSIENT_FIELD_NOT_RESTORED", justification="Contextual fields used only in start(); no onResume needed")
class WithMavenStepExecution extends StepExecution {

private static final long serialVersionUID = 1L;
private static final String MAVEN_HOME = "MAVEN_HOME";
@@ -85,19 +85,13 @@

private static final Logger LOGGER = Logger.getLogger(WithMavenStepExecution.class.getName());

@Inject(optional = true)
private transient WithMavenStep step;
@StepContextParameter
private transient TaskListener listener;
@StepContextParameter
private transient FilePath ws;
@StepContextParameter
private transient Launcher launcher;
@StepContextParameter
private transient EnvVars env;
private final transient WithMavenStep step;
private final transient TaskListener listener;
private final transient FilePath ws;
private final transient Launcher launcher;
private final transient EnvVars env;
private transient EnvVars envOverride;
@StepContextParameter
private transient Run<?, ?> build;
private final transient Run<?, ?> build;

private transient Computer computer;
private transient FilePath tempBinDir;
@@ -110,6 +104,17 @@

private transient PrintStream console;

WithMavenStepExecution(StepContext context, WithMavenStep step) throws Exception {
super(context);
this.step = step;
// Or just delete these fields and inline:
listener = context.get(TaskListener.class);
ws = context.get(FilePath.class);
launcher = context.get(Launcher.class);
env = context.get(EnvVars.class);
build = context.get(Run.class);
}

@Override
public boolean start() throws Exception {
envOverride = new EnvVars();
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2016 CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<div>
This plugin provides integration with Pipeline, configures maven environment to use within a pipeline job by calling sh mvn or bat mvn.
The selected maven installation will be configured and prepended to the path.
</div>
@@ -0,0 +1,71 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jenkinsci.plugins.pipeline.maven;

import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.Rule;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.RestartableJenkinsRule;

public class WithMavenStepTest {

@ClassRule
public static BuildWatcher buildWatcher = new BuildWatcher();

@Rule
public RestartableJenkinsRule rr = new RestartableJenkinsRule();

@Issue("JENKINS-39134")
@Test
public void resume() throws Exception {
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = rr.j.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {withMaven {semaphore 'wait'}}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
}
});
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = rr.j.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
SemaphoreStep.success("wait/1", null);
rr.j.assertBuildStatusSuccess(rr.j.waitForCompletion(b));
SemaphoreStep.success("wait/2", null);
rr.j.buildAndAssertSuccess(p);
}
});
}

}

0 comments on commit 0fbb0d2

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