Skip to content

Commit

Permalink
Integration test for Maven reactor make behaviours
Browse files Browse the repository at this point in the history
These test the functionality of TychoGraphBuilder (provided by the
tycho-build extension) for a simple reactor build.
  • Loading branch information
joeshannon committed Feb 1, 2022
1 parent 18e3a62 commit 0f689a8
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,20 @@ public Result<ProjectDependencyGraph> build(MavenSession session) {
while (!queue.isEmpty()) {
ProjectRequest projectRequest = queue.poll();
if (selectedProjects.add(projectRequest.mavenProject)) {
if (projectRequest.requestDownstream) {
if (projectRequest.requestUpstream) {
Collection<IInstallableUnit> depends = projectDependenciesMap
.getOrDefault(projectRequest.mavenProject, Collections.emptyList());
depends.stream()//
.map(iuProjectMap::get)//
.filter(Objects::nonNull)//
.distinct()//
.peek(project -> loggerAdapter.debug(" + add downstream project '" + project.getName()
.peek(project -> loggerAdapter.debug(" + add upstream project '" + project.getName()
+ "' of project '" + projectRequest.mavenProject.getName() + "'..."))//
// make behaviors are both false here as projectDependenciesMap includes transitive already
.forEach(
project -> queue.add(new ProjectRequest(project, true, false, projectRequest)));
project -> queue.add(new ProjectRequest(project, false, false, projectRequest)));
}
if (projectRequest.requestUpstream) {
if (projectRequest.requestDownstream) {
projectDependenciesMap.entrySet().stream()//
.filter(entry -> {
return entry.getValue().stream()//
Expand All @@ -217,10 +218,11 @@ public Result<ProjectDependencyGraph> build(MavenSession session) {
})//
.map(Entry::getKey)//
.distinct()//
.peek(project -> loggerAdapter.debug(" + add upstream project '" + project.getName()
.peek(project -> loggerAdapter.debug(" + add downstream project '" + project.getName()
+ "' of project '" + projectRequest.mavenProject.getName() + "'..."))//
// make behaviors are both false here as projectDependenciesMap includes transitive already
.forEach(
project -> queue.add(new ProjectRequest(project, true, false, projectRequest)));
project -> queue.add(new ProjectRequest(project, false, false, projectRequest)));
}
}
}
Expand Down Expand Up @@ -361,6 +363,12 @@ private static final class ProjectRequest {
boolean matches(MavenProject mavenproject) {
return this.mavenProject == mavenproject;
}

@Override
public String toString() {
return "ProjectRequest [mavenProject=" + mavenProject + ", parent=" + parent + ", requestDownstream="
+ requestDownstream + ", requestUpstream=" + requestUpstream + "]";
}
}

}
10 changes: 10 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<!-- TODO this should be a property
see https://issues.apache.org/jira/browse/MNG-7395 -->
<version>2.7.0-SNAPSHOT</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle 1
Bundle-SymbolicName: bundle1;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
16 changes: 16 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/bundle1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<version>1.0.0-SNAPSHOT</version>
<artifactId>bundle1</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>tycho-its-project.reactor.makeBehaviour</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle 2
Bundle-SymbolicName: bundle2;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
16 changes: 16 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/bundle2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<version>1.0.0-SNAPSHOT</version>
<artifactId>bundle2</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>tycho-its-project.reactor.makeBehaviour</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes=feature.xml
13 changes: 13 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/feature1/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="feature1"
version="1.0.0.qualifier">

<plugin
id="bundle1"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
14 changes: 14 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/feature1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>tycho-its-project.reactor.makeBehaviour</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>feature1</artifactId>
<packaging>eclipse-feature</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes=feature.xml
17 changes: 17 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/feature2/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="feature2"
version="1.0.0.qualifier">

<includes
id="feature1"
version="0.0.0"/>

<plugin
id="bundle2"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
14 changes: 14 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/feature2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>tycho-its-project.reactor.makeBehaviour</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>feature2</artifactId>
<packaging>eclipse-feature</packaging>
</project>
28 changes: 28 additions & 0 deletions tycho-its/projects/reactor.makeBehaviour/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>tycho-its-project.reactor.makeBehaviour</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>feature1</module>
<module>feature2</module>
<module>bundle1</module>
<module>bundle2</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.eclipse.tycho.test.reactor.makeBehaviour;

import static org.junit.Assert.fail;

import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Before;
import org.junit.Test;

/**
* Test Maven reactor make behaviours
*
* Test project dependencies:
*
* <pre>
* feature2 -> feature1,bundle2
* feature1 -> bundle1
* </pre>
*
*/
public class MavenReactorMakeOptionsTest extends AbstractTychoIntegrationTest {

private Verifier verifier;

@Before
public void setUp() throws Exception {
verifier = getVerifier("reactor.makeBehaviour");
verifier.executeGoal("clean");
}

@Test
public void testCompleteBuild() throws Exception {
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
verifier.assertFilePresent("bundle1/target/bundle1-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("bundle2/target/bundle2-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature1/target/feature1-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature2/target/feature2-1.0.0-SNAPSHOT.jar");
}

@Test
public void testAlsoMake() throws Exception {
// REACTOR_MAKE_UPSTREAM
verifier.addCliOption("-am");
verifier.addCliOption("-pl feature1");
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
verifier.assertFilePresent("bundle1/target/bundle1-1.0.0-SNAPSHOT.jar");
verifier.assertFileNotPresent("bundle2/target/bundle2-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature1/target/feature1-1.0.0-SNAPSHOT.jar");
verifier.assertFileNotPresent("feature2/target/feature2-1.0.0-SNAPSHOT.jar");
}

@Test
public void testAlsoMakeDependents() throws Exception {
// REACTOR_MAKE_DOWNSTREAM
verifier.addCliOption("-amd");
verifier.addCliOption("-pl bundle1,bundle2");
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
verifier.assertFilePresent("bundle1/target/bundle1-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("bundle2/target/bundle2-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature1/target/feature1-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature2/target/feature2-1.0.0-SNAPSHOT.jar");
}

@Test
public void testBoth() throws Exception {
// REACTOR_MAKE_BOTH
verifier.addCliOption("-am");
verifier.addCliOption("-amd");
verifier.addCliOption("-pl feature1,bundle2");
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
verifier.assertFilePresent("bundle1/target/bundle1-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("bundle2/target/bundle2-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature1/target/feature1-1.0.0-SNAPSHOT.jar");
verifier.assertFilePresent("feature2/target/feature2-1.0.0-SNAPSHOT.jar");
}

@Test
public void testSingleProjectNoOptionFails() throws Exception {
try {
verifier.addCliOption("-pl feature1");
verifier.executeGoal("verify");
fail("Build should fail due to missing reactor dependency");
} catch (VerificationException e) {
verifier.verifyTextInLog(
"Missing requirement: feature1.feature.group 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; bundle1 0.0.0' but it could not be found");
}
}

@Test
public void testDownstreamFailsIfMissingDownstreamDependency() throws Exception {
// Downstream brings in feature2 but this requires bundle2 which is unrelated
// to specified projects
try {
verifier.addCliOption("-amd");
verifier.addCliOption("-pl bundle1,feature1");
verifier.executeGoal("verify");
fail("Build should fail due to missing reactor dependency");
} catch (VerificationException e) {
verifier.verifyTextInLog(
"Missing requirement: feature2.feature.group 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; bundle2 0.0.0' but it could not be found");
}
}

}

0 comments on commit 0f689a8

Please sign in to comment.