Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-43616] special handling of the pom file when using the flatt…
…en-maven-plugin
  • Loading branch information
Cyrille Le Clerc committed Apr 20, 2017
1 parent 70cbc0a commit 8819434
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 2 deletions.
Expand Up @@ -173,6 +173,48 @@ public void maven_build_jar_project_on_master_succeeds() throws Exception {
assertThat(tasksResultAction.getProjectActions().size(), is(1));
}

@Test
public void maven_build_maven_jar_with_flatten_pom_project_on_master_succeeds() throws Exception {
loadMavenJarWithFlattenPomProjectInGitRepo(this.gitRepoRule);

String pipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn package'\n" +
" }\n" +
"}";

WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-jar-with-flatten-pom-project-on-master");
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

jenkinsRule.assertLogNotContains("[jenkins-maven-event-spy] WARNING: unexpected Maven project file name '.flattened-pom.xml', problems may occur", build);


// verify Maven installation provided by the build agent is used
// can be either "by the build agent with executable..." or "by the build agent with the environment variable MAVEN_HOME=..."
jenkinsRule.assertLogContains("[withMaven] use Maven installation provided by the build agent with", build);

// verify .pom is archived and fingerprinted
jenkinsRule.assertLogContains("under jenkins/mvn/test/maven-jar-with-flattened-pom/0.1-SNAPSHOT/maven-jar-with-flattened-pom-0.1-SNAPSHOT.pom", build);

// verify .jar is archived and fingerprinted
jenkinsRule.assertLogContains("under jenkins/mvn/test/maven-jar-with-flattened-pom/0.1-SNAPSHOT/maven-jar-with-flattened-pom-0.1-SNAPSHOT.jar", build);

System.out.println(getClass() + " artifacts: " + build.getArtifacts());
// TODO build.getArtifacts() is always empty (size=0), skip verification

verifyFileIsFingerPrinted(pipeline, build, "jenkins/mvn/test/maven-jar-with-flattened-pom/0.1-SNAPSHOT/maven-jar-with-flattened-pom-0.1-SNAPSHOT.jar");
verifyFileIsFingerPrinted(pipeline, build, "jenkins/mvn/test/maven-jar-with-flattened-pom/0.1-SNAPSHOT/maven-jar-with-flattened-pom-0.1-SNAPSHOT.pom");

// verify Junit Archiver is called for jenkins.mvn.test:maven-jar-with-flattened-pom
jenkinsRule.assertLogContains("[withMaven] Archive test results for Maven artifact MavenArtifact{jenkins.mvn.test:maven-jar-with-flattened-pom::0.1-SNAPSHOT} generated by", build);

// verify Task Scanner is called for jenkins.mvn.test:maven-jar-with-flattened-pom
jenkinsRule.assertLogContains("[withMaven] Scan Tasks for Maven artifact MavenArtifact{jenkins.mvn.test:maven-jar-with-flattened-pom::0.1-SNAPSHOT} in source directory", build);
}


@Test
public void maven_build_maven_hpi_project_on_master_succeeds() throws Exception {
loadJenkinsPluginProjectInGitRepo(this.gitRepoRule);
Expand Down Expand Up @@ -328,13 +370,16 @@ private void loadMavenJarProjectInGitRepo(GitSampleRepoRule gitRepo) throws Exce
loadSourceCodeInGitRepository(gitRepo, "/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_jar_project/");
}

private void loadMavenJarWithFlattenPomProjectInGitRepo(GitSampleRepoRule gitRepo) throws Exception {
loadSourceCodeInGitRepository(gitRepo, "/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_jar_with_flatten_pom_project/");
}

private void loadMavenPluginProjectInGitRepo(GitSampleRepoRule gitRepo) throws Exception {
loadSourceCodeInGitRepository(gitRepo, "/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_plugin_project/");
}

private void loadJenkinsPluginProjectInGitRepo(GitSampleRepoRule gitRepo) throws Exception {
String name = "/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_hpi_project/";
loadSourceCodeInGitRepository(gitRepo, name);
loadSourceCodeInGitRepository(gitRepo, "/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_hpi_project/");
}

private void loadSourceCodeInGitRepository(GitSampleRepoRule gitRepo, String name) throws Exception {
Expand Down
@@ -0,0 +1,6 @@
target/
work/

.flattened-pom.xml

*.log
@@ -0,0 +1,51 @@
<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>
<groupId>jenkins.mvn.test</groupId>
<artifactId>maven-jar-with-flattened-pom</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<developers>
<developer>
<id>will-be-removed-by-the-flatten-plugin</id>
<name>will-be-removed-by-the-flatten-plugin</name>
<email>example@example.com</email>
</developer>
</developers>
<licenses>
<license>
<name>Apache Software Licenese</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<comments/>
</license>
</licenses>
</project>

@@ -0,0 +1,11 @@
package com.example;

public class MonoModuleMavenApp {
/**
* TODO message
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello MonoModuleMavenApp");
}
}
@@ -0,0 +1,11 @@
package com.example;

import org.junit.Test;

public class MonoModuleMavenAppTest {

@Test
public void success(){
System.out.println("MonoModuleMavenAppTest#success");
}
}
Expand Up @@ -105,6 +105,10 @@ public Xpp3Dom newElement(@Nonnull String name, @Nullable MavenProject project)
// JENKINS-42302: maven-shade-plugin creates a temporary project file dependency-reduced-pom.xml
// TODO see if there is a better way to implement this "workaround"
absolutePath = absolutePath.replace(File.separator + "dependency-reduced-pom.xml", File.separator + "pom.xml");
} else if (absolutePath.endsWith(File.separator + ".flattened-pom.xml")) {
// JENKINS-43616: maven-shade-plugin creates a temporary project file .flattened-pom.xml
// TODO see if there is a better way to implement this "workaround"
absolutePath = absolutePath.replace(File.separator + ".flattened-pom.xml", File.separator + "pom.xml");
} else {
System.out.println("[jenkins-maven-event-spy] WARNING: unexpected Maven project file name '"
+ projectFile.getName() + "', problems may occur");
Expand Down

0 comments on commit 8819434

Please sign in to comment.