-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix site lifecycle reactor dependency resolution #12069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.jar.JarOutputStream; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
|
|
@@ -80,6 +81,8 @@ class ReactorReader implements MavenWorkspaceReader { | |
| private Map<String, Map<String, Map<String, MavenProject>>> projects; | ||
| private Map<String, Map<String, Map<String, MavenProject>>> allProjects; | ||
| private Path projectLocalRepository; | ||
| private Path emptyArtifactRepository; | ||
| private final ConcurrentHashMap<Path, File> emptyArtifactCache = new ConcurrentHashMap<>(); | ||
| // projectId -> Deque<lifecycle> | ||
| private final Map<String, Deque<String>> lifecycles = new ConcurrentHashMap<>(); | ||
|
|
||
|
|
@@ -217,13 +220,49 @@ private File determineBuildOutputDirectoryForArtifact(final MavenProject project | |
| if (projectHasOutputFromPreviousSession || projectCompiledDuringThisSession) { | ||
| return outputDirectory; | ||
| } | ||
|
|
||
| if (isSiteGoalRequested() && "jar".equals(artifact.getExtension()) && "jar".equals(type)) { | ||
| return ensureEmptyArtifactFile(artifact); | ||
| } | ||
| } | ||
|
|
||
| // The fall-through indicates that the artifact cannot be found; | ||
| // for instance if package produced nothing or classifier problems. | ||
| return null; | ||
| } | ||
|
|
||
| private File ensureEmptyArtifactFile(final Artifact artifact) { | ||
| Path target = getEmptyArtifactPath(artifact); | ||
| return emptyArtifactCache.computeIfAbsent(target, path -> { | ||
| if (Files.isRegularFile(path)) { | ||
| return path.toFile(); | ||
| } | ||
| try { | ||
| Files.createDirectories(path.getParent()); | ||
| try (JarOutputStream ignored = new JarOutputStream(Files.newOutputStream(path))) { | ||
| // create an empty jar for site reports that inspect reactor artifacts before package | ||
| } | ||
| return path.toFile(); | ||
| } catch (IOException e) { | ||
| LOGGER.warn("Unable to create empty reactor artifact for '{}'.", artifact, e); | ||
| return null; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private boolean isSiteGoalRequested() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [medium] The |
||
| return session.getGoals().stream().anyMatch(ReactorReader::isSiteGoal); | ||
| } | ||
|
|
||
| private static boolean isSiteGoal(String goal) { | ||
| return "pre-site".equals(goal) | ||
| || "site".equals(goal) | ||
| || "post-site".equals(goal) | ||
| || "site-deploy".equals(goal) | ||
| || goal.endsWith(":site") | ||
| || goal.endsWith(":site-deploy"); | ||
| } | ||
|
|
||
| private boolean isPackagedArtifactUpToDate(MavenProject project, File packagedArtifactFile) { | ||
| Path outputDirectory = Paths.get(project.getBuild().getOutputDirectory()); | ||
| if (!outputDirectory.toFile().exists()) { | ||
|
|
@@ -485,12 +524,26 @@ private Path getArtifactPath(Artifact artifact) { | |
| String version = artifact.getBaseVersion(); | ||
| String classifier = artifact.getClassifier(); | ||
| String extension = artifact.getExtension(); | ||
| return getArtifactPath(groupId, artifactId, version, classifier, extension); | ||
| return getArtifactPath(getProjectLocalRepo(), groupId, artifactId, version, classifier, extension); | ||
| } | ||
|
|
||
| private Path getArtifactPath( | ||
| String groupId, String artifactId, String version, String classifier, String extension) { | ||
| Path repo = getProjectLocalRepo(); | ||
| return getArtifactPath(getProjectLocalRepo(), groupId, artifactId, version, classifier, extension); | ||
| } | ||
|
|
||
| private Path getEmptyArtifactPath(Artifact artifact) { | ||
| return getArtifactPath( | ||
| getEmptyArtifactRepo(), | ||
| artifact.getGroupId(), | ||
| artifact.getArtifactId(), | ||
| artifact.getBaseVersion(), | ||
| artifact.getClassifier(), | ||
| artifact.getExtension()); | ||
| } | ||
|
|
||
| private Path getArtifactPath( | ||
| Path repo, String groupId, String artifactId, String version, String classifier, String extension) { | ||
| return repo.resolve(groupId) | ||
| .resolve(artifactId) | ||
| .resolve(version) | ||
|
|
@@ -502,6 +555,13 @@ private Path getArtifactPath( | |
| + extension); | ||
| } | ||
|
|
||
| private Path getEmptyArtifactRepo() { | ||
| if (emptyArtifactRepository == null) { | ||
| emptyArtifactRepository = getProjectLocalRepo().resolveSibling("reactor-empty-artifacts"); | ||
| } | ||
| return emptyArtifactRepository; | ||
| } | ||
|
|
||
| private Path getProjectLocalRepo() { | ||
| if (projectLocalRepository == null) { | ||
| Path root = session.getRequest().getRootDirectory(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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.apache.maven.it; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
|
||
| /** | ||
| * This is a test set for <a href="https://github.com/apache/maven/issues/12064">GH-12064</a>. | ||
| */ | ||
| class MavenITgh12064SiteReactorDependenciesTest extends AbstractMavenIntegrationTestCase { | ||
|
|
||
| @Test | ||
| void testSiteLifecycleResolvesReactorDependencies() throws Exception { | ||
| File testDir = extractResources("/gh-12064-site-reactor-dependencies"); | ||
|
|
||
| Verifier verifier = newVerifier(testDir.getAbsolutePath()); | ||
| verifier.setAutoclean(false); | ||
| verifier.deleteDirectory("producer/target"); | ||
| verifier.deleteDirectory("consumer/target"); | ||
| verifier.deleteArtifacts("org.apache.maven.its.gh12064"); | ||
| verifier.addCliArgument("site"); | ||
| verifier.execute(); | ||
| verifier.verifyErrorFreeLog(); | ||
|
|
||
| verifier.verifyFilePresent("consumer/target/site/dependencies.html"); | ||
| assertFalse(new File(testDir, "producer/target/classes").exists(), "site must not require compile first"); | ||
| assertFalse( | ||
| new File( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] The integration test only exercises basic |
||
| testDir, | ||
| "target/project-local-repo/org.apache.maven.its.gh12064/producer/1.0-SNAPSHOT/" | ||
| + "producer-1.0-SNAPSHOT.jar") | ||
| .exists(), | ||
| "site must not leave synthetic artifacts in the project-local-repo"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you 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="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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.apache.maven.its.gh12064</groupId> | ||
| <artifactId>parent</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>consumer</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.maven.its.gh12064</groupId> | ||
| <artifactId>producer</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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.apache.maven.its.gh12064; | ||
|
|
||
| public class Consumer { | ||
| public String message() { | ||
| return Producer.message(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you 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="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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>org.apache.maven.its.gh12064</groupId> | ||
| <artifactId>parent</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>pom</packaging> | ||
|
|
||
| <modules> | ||
| <module>producer</module> | ||
| <module>consumer</module> | ||
| </modules> | ||
|
|
||
| <properties> | ||
| <maven.compiler.release>17</maven.compiler.release> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you 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="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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.apache.maven.its.gh12064</groupId> | ||
| <artifactId>parent</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>producer</artifactId> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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.apache.maven.its.gh12064; | ||
|
|
||
| public class Producer { | ||
| public static String message() { | ||
| return "producer"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[high] The empty JAR injection silently masks missing compiled output. Report plugins that inspect bytecode or source paths resolved from the classpath (
maven-javadoc-plugin,maven-jxr-plugin,spotbugs-maven-plugin) would silently produce empty or incomplete output instead of failing with a clear error. Today the failure is explicit — users know they needmvn compile site. With this workaround, the build passes but the output is wrong.