hudson.tasks.Maven Java Examples

The following examples show how to use hudson.tasks.Maven. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerContainerITest.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Build a maven project on a docker container agent.
 *
 * @throws IOException
 *         When the node assignment of the agent fails.
 * @throws InterruptedException
 *         If the creation of the docker container fails.
 */
@Test
public void shouldBuildMavenOnAgent() throws IOException, InterruptedException {
    assumeThat(isWindows()).as("Running on Windows").isFalse();

    DumbSlave agent = createDockerContainerAgent(javaDockerRule.get());

    FreeStyleProject project = createFreeStyleProject();
    project.setAssignedNode(agent);

    createFileInAgentWorkspace(agent, project, "src/main/java/Test.java", getSampleJavaFile());
    createFileInAgentWorkspace(agent, project, "pom.xml", getSampleMavenFile());
    project.getBuildersList().add(new Maven("compile", null));
    enableWarnings(project, createTool(new Java(), ""));

    scheduleSuccessfulBuild(project);

    FreeStyleBuild lastBuild = project.getLastBuild();
    AnalysisResult result = getAnalysisResult(lastBuild);

    assertThat(result).hasTotalSize(2);
    assertThat(lastBuild.getBuiltOn().getLabelString()).isEqualTo(((Node) agent).getLabelString());
}
 
Example #2
Source File: MavenConfigurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@NonNull
@Override
public Set<Attribute<GlobalMavenConfig,?>> describe() {
    final Set<Attribute<GlobalMavenConfig,?>> attributes = super.describe();
    final Descriptor descriptor = Jenkins.get().getDescriptorOrDie(Maven.class);
    final Configurator<Descriptor> task = new DescriptorConfigurator(descriptor);

    for (Attribute attribute : task.describe()) {
        attributes.add(new Attribute<GlobalMavenConfig,Object>(attribute.getName(), attribute.getType())
            .multiple(attribute.isMultiple())
            .getter(g -> attribute.getValue(descriptor))
            .setter((g,v) -> attribute.setValue(descriptor,v)));
    }
    return attributes;
}
 
Example #3
Source File: MavenConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("MavenConfiguratorTest.yml")
public void should_configure_maven_tools_and_global_config() {
    final Maven.DescriptorImpl descriptor= (Maven.DescriptorImpl) j.jenkins.getDescriptorOrDie(Maven.class);
    Assert.assertEquals(1, descriptor.getInstallations().length);
    Assert.assertEquals("/usr/share/maven", descriptor.getInstallations()[0].getHome());

    InstallSourceProperty installSourceProperty = descriptor.getInstallations()[0].getProperties().get(InstallSourceProperty.class);
    Assert.assertEquals("3.5.0", installSourceProperty.installers.get(Maven.MavenInstaller.class).id);

    final SettingsProvider provider = GlobalMavenConfig.get().getSettingsProvider();
    Assert.assertTrue(provider instanceof FilePathSettingsProvider);
    Assert.assertEquals("/usr/share/maven-settings.xml", ((FilePathSettingsProvider)provider).getPath());
}
 
Example #4
Source File: AbstractIntegrationTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
    Maven.MavenInstallation maven3 = ExtendedToolInstallations.configureMaven35();

    mavenInstallationName = maven3.getName();

    GlobalMavenConfig globalMavenConfig = jenkinsRule.get(GlobalMavenConfig.class);
    globalMavenConfig.setGlobalSettingsProvider(new DefaultGlobalSettingsProvider());
    globalMavenConfig.setSettingsProvider(new DefaultSettingsProvider());
}
 
Example #5
Source File: ExtendedToolInstallations.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Declare "Maven 3.5.0" as the "default" Maven installation in Jenkins and as the Maven installation named "apache-maven-3.5.0".
 * Note that both {@link hudson.tasks.Maven.MavenInstallation} share the same Maven binaries.
 *
 * @return the "apache-maven-3.5.0" Maven {@link hudson.tasks.Maven.MavenInstallation}
 * @throws Exception
 */
public static Maven.MavenInstallation configureMaven35() throws Exception {
    Maven.MavenInstallation mvn =  ToolInstallations.configureDefaultMaven("apache-maven-3.5.0", Maven.MavenInstallation.MAVEN_30);

    Maven.MavenInstallation maven350 = new Maven.MavenInstallation("apache-maven-3.5.0", mvn.getHome(), JenkinsRule.NO_PROPERTIES);
    Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(maven350);
    return maven350;
}
 
Example #6
Source File: ExtendedToolInstallations.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Declare "Maven 3.6.1" as the "default" Maven installation in Jenkins and as the Maven installation named "apache-maven-3.5.0".
 * Note that both {@link hudson.tasks.Maven.MavenInstallation} share the same Maven binaries.
 *
 * @return the "apache-maven-3.6.1" Maven {@link hudson.tasks.Maven.MavenInstallation}
 * @throws Exception
 */
public static Maven.MavenInstallation configureMaven36() throws Exception {
    Maven.MavenInstallation mvn =  ToolInstallations.configureDefaultMaven("apache-maven-3.6.1", Maven.MavenInstallation.MAVEN_30);

    Maven.MavenInstallation maven361 = new Maven.MavenInstallation("apache-maven-3.6.1", mvn.getHome(), JenkinsRule.NO_PROPERTIES);
    Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(maven361);
    return maven361;
}
 
Example #7
Source File: DollarSecretPatternFactoryTest.java    From credentials-binding-plugin with MIT License 5 votes vote down vote up
@Issue("JENKINS-24805")
@Test
public void maskingFreeStyleSecrets() throws Exception {
    String firstCredentialsId = "creds_1";
    String firstPassword = "a$build";
    StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, firstCredentialsId, "sample1", Secret.fromString(firstPassword));

    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);

    String secondCredentialsId = "creds_2";
    String secondPassword = "a$$b";
    StringCredentialsImpl secondCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, secondCredentialsId, "sample2", Secret.fromString(secondPassword));

    CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secondCreds);

    SecretBuildWrapper wrapper = new SecretBuildWrapper(Arrays.asList(new StringBinding("PASS_1", firstCredentialsId),
            new StringBinding("PASS_2", secondCredentialsId)));

    FreeStyleProject project = r.createFreeStyleProject();

    project.setConcurrentBuild(true);
    project.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_1%") : new Shell("echo \"$PASS_1\""));
    project.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %PASS_2%") : new Shell("echo \"$PASS_2\""));
    project.getBuildersList().add(new Maven("$PASS_1 $PASS_2", "default"));
    project.getBuildWrappersList().add(wrapper);

    r.configRoundtrip((Item)project);

    QueueTaskFuture<FreeStyleBuild> future = project.scheduleBuild2(0);
    FreeStyleBuild build = future.get();
    r.assertLogNotContains(firstPassword, build);
    r.assertLogNotContains(firstPassword.replace("$", "$$"), build);
    r.assertLogNotContains(secondPassword, build);
    r.assertLogNotContains(secondPassword.replace("$", "$$"), build);
    r.assertLogContains("****", build);
}
 
Example #8
Source File: WithMavenStepExecution2.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
/**
 * @return maven installations on this instance
 */
private static MavenInstallation[] getMavenInstallations() {
    return Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).getInstallations();
}
 
Example #9
Source File: WithMavenStep.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
private Maven.DescriptorImpl getMavenDescriptor() {
    return Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class);
}