-
Notifications
You must be signed in to change notification settings - Fork 3k
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 1 commit
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; | ||
|
|
||
|
|
@@ -217,13 +218,43 @@ private File determineBuildOutputDirectoryForArtifact(final MavenProject project | |
| if (projectHasOutputFromPreviousSession || projectCompiledDuringThisSession) { | ||
| return outputDirectory; | ||
| } | ||
|
|
||
| if (hasSiteLifecyclePhase(project) && "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 = getArtifactPath(artifact); | ||
| synchronized (this) { | ||
| if (Files.isRegularFile(target)) { | ||
|
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. Using private final ConcurrentHashMap<Path, File> emptyArtifactCache = new ConcurrentHashMap<>();
private File ensureEmptyArtifactFile(final Artifact artifact) {
Path target = getArtifactPath(artifact);
return emptyArtifactCache.computeIfAbsent(target, p -> {
// create empty jar ...
});
} |
||
| return target.toFile(); | ||
| } | ||
| try { | ||
| Files.createDirectories(target.getParent()); | ||
| try (JarOutputStream ignored = new JarOutputStream(Files.newOutputStream(target))) { | ||
| // create an empty jar for site reports that inspect reactor artifacts before package | ||
| } | ||
| return target.toFile(); | ||
|
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. This empty JAR is written to the project-local-repo. If the user subsequently runs Consider either:
|
||
| } catch (IOException e) { | ||
| LOGGER.warn("Unable to create empty reactor artifact for '{}'.", artifact, e); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private boolean hasSiteLifecyclePhase(MavenProject project) { | ||
| return project.hasLifecyclePhase("pre-site") | ||
| || project.hasLifecyclePhase("site") | ||
| || project.hasLifecyclePhase("post-site") | ||
| || project.hasLifecyclePhase("site-deploy"); | ||
| } | ||
|
|
||
| private boolean isPackagedArtifactUpToDate(MavenProject project, File packagedArtifactFile) { | ||
| Path outputDirectory = Paths.get(project.getBuild().getOutputDirectory()); | ||
| if (!outputDirectory.toFile().exists()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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"); | ||
| } | ||
| } |
| 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.
This checks whether the producer project has entered a site lifecycle phase. But dependency resolution for a consumer module can happen before the producer's mojos have started, meaning
project.hasLifecyclePhase("pre-site")etc. would all returnfalseat the time we need it most.Wouldn't it be more reliable to check the session's top-level goals instead? Something like:
with a helper that inspects
session.getGoals()for site-related goals. That way the check doesn't depend on mojo execution order.