Skip to content

Commit

Permalink
Fix error when the reactor contains duplicate groupId:artifactId, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 18, 2021
1 parent 724f766 commit 9e6ceed
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ private ReactorBuildStats(Map<String, AtomicLong> serviceTimes,
this.bottleneckTimes = ImmutableMap.copyOf(bottleneckTimes);
}

private static String projectGA(MavenProject project) {
return project.getGroupId() + ":" + project.getArtifactId();
private static String projectGAV(MavenProject project) {
return project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
}

public static ReactorBuildStats create(Collection<MavenProject> projects) {
ImmutableMap.Builder<String, AtomicLong> serviceTimes = ImmutableMap.builder();
ImmutableMap.Builder<String, AtomicLong> bottleneckTimes = ImmutableMap.builder();
projects.stream().map(ReactorBuildStats::projectGA).forEach(key -> {
projects.stream().map(ReactorBuildStats::projectGAV).forEach(key -> {
serviceTimes.put(key, new AtomicLong());
bottleneckTimes.put(key, new AtomicLong());
});
Expand All @@ -79,9 +79,9 @@ public void recordStop() {
}

public void recordServiceTime(MavenProject project, long durationNanos) {
AtomicLong serviceTime = serviceTimes.get(projectGA(project));
AtomicLong serviceTime = serviceTimes.get(projectGAV(project));
if (serviceTime == null) {
throw new IllegalStateException("Unknown project " + projectGA(project) + ", found " + serviceTimes.keySet());
throw new IllegalStateException("Unknown project " + projectGAV(project) + ", found " + serviceTimes.keySet());
}
serviceTime.addAndGet(durationNanos);
}
Expand All @@ -90,7 +90,7 @@ public void recordBottlenecks(Set<MavenProject> projects, int degreeOfConcurrenc
long durationNanos) {
// only projects that result in single-threaded builds
if (projects.size() == 1) {
projects.forEach(p -> bottleneckTimes.get(projectGA(p)).addAndGet(durationNanos));
projects.forEach(p -> bottleneckTimes.get(projectGAV(p)).addAndGet(durationNanos));
}
}

Expand All @@ -108,7 +108,7 @@ public long walltimeTime(TimeUnit unit) {
}

public String renderCriticalPath(DependencyGraph<MavenProject> graph) {
return renderCriticalPath(graph, ReactorBuildStats::projectGA);
return renderCriticalPath(graph, ReactorBuildStats::projectGAV);
}

public <K> String renderCriticalPath(DependencyGraph<K> graph, Function<K, String> toKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mvndaemon.mvnd.it;

import java.io.IOException;
import javax.inject.Inject;
import org.junit.jupiter.api.Test;
import org.mvndaemon.mvnd.assertj.TestClientOutput;
import org.mvndaemon.mvnd.client.Client;
import org.mvndaemon.mvnd.client.DaemonParameters;
import org.mvndaemon.mvnd.junit.MvndTest;

@MvndTest(projectDir = "src/test/projects/dup-ga")
public class DupGATest {

@Inject
Client client;

@Inject
DaemonParameters parameters;

@Test
void cleanInstall() throws IOException, InterruptedException {
final TestClientOutput output = new TestClientOutput();
client.execute(output, "clean", "install", "-e").assertSuccess();
}
}
3 changes: 3 additions & 0 deletions integration-tests/src/test/projects/dup-ga/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
-Dmaven.wagon.http.retryHandler.count=10
31 changes: 31 additions & 0 deletions integration-tests/src/test/projects/dup-ga/hi1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
Copyright 2021 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<groupId>org.mvndaemon.mvnd.test.dup-ga</groupId>
<artifactId>dup-ga</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dup-ga-hi</artifactId>
<version>1.0-SNAPSHOT</version>

</project>
31 changes: 31 additions & 0 deletions integration-tests/src/test/projects/dup-ga/hi2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
Copyright 2021 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<groupId>org.mvndaemon.mvnd.test.dup-ga</groupId>
<artifactId>dup-ga</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dup-ga-hi</artifactId>
<version>2.0-SNAPSHOT</version>

</project>
76 changes: 76 additions & 0 deletions integration-tests/src/test/projects/dup-ga/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--
Copyright 2021 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>org.mvndaemon.mvnd.test.dup-ga</groupId>
<artifactId>dup-ga</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>

<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>

<modules>
<module>hi1</module>
<module>hi2</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>

0 comments on commit 9e6ceed

Please sign in to comment.