Skip to content

Commit

Permalink
[MASSEMBLY-1022] Unresolved artifacts should be not processed
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Mar 15, 2024
1 parent cb56382 commit 74e858a
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 12 deletions.
82 changes: 82 additions & 0 deletions src/it/projects/bugs/massembly-1022/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!--
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.plugin.assembly.test</groupId>
<artifactId>it-project-parent</artifactId>
<version>1</version>
</parent>

<groupId>test</groupId>
<artifactId>massembly-1022</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<description>
We have scope compile in assembly descriptor, so dependencies in runtime scope can be unresolved
</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<formats>
<format>zip</format>
</formats>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>

</project>
31 changes: 31 additions & 0 deletions src/it/projects/bugs/massembly-1022/src/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
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.
-->
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">

<id>assembly</id>
<includeBaseDirectory>false</includeBaseDirectory>

<dependencySets>
<dependencySet>
<scope>compile</scope>
</dependencySet>
</dependencySets>
</assembly>
24 changes: 24 additions & 0 deletions src/it/projects/bugs/massembly-1022/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

import java.util.zip.ZipFile

def zipFile = new ZipFile(new File(basedir, "target/massembly-1022-0.0.1-SNAPSHOT-assembly.zip"));
assert zipFile.getEntry("slf4j-simple-1.7.36.jar") != null
assert zipFile.entries().size() == 1
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,19 @@ public boolean visitEnter(DependencyNode node) {

@Override
public boolean visitLeave(DependencyNode node) {
if (node.getDependency() != null) {
Dependency dependency = node.getDependency();
if (dependency != null) {
Artifact artifact = aetherToMavenArtifacts.computeIfAbsent(
node.getDependency().getArtifact(), RepositoryUtils::toArtifact);
List<String> depTrail = new ArrayList<>();
stack.descendingIterator().forEachRemaining(depTrail::add);
dependency.getArtifact(), RepositoryUtils::toArtifact);
if (artifact.isResolved() && artifact.getFile() != null) {
List<String> depTrail = new ArrayList<>();
stack.descendingIterator().forEachRemaining(depTrail::add);
artifact.setDependencyTrail(depTrail);
artifact.setOptional(dependency.isOptional());
artifact.setScope(dependency.getScope());
artifacts.add(artifact);
}
stack.pop();
artifact.setDependencyTrail(depTrail);
artifacts.add(artifact);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public void test_getDependencySetResolutionRequirements_transitive() throws Exce
artifacts.add(newArtifact("g.id", "a-id", "1"));
artifacts.add(newArtifact("g.id", "a-id-2", "2"));

DefaultDependencyNode node1 = new DefaultDependencyNode(
new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id:1"), "runtime"));
DefaultDependencyNode node2 = new DefaultDependencyNode(
new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id-2:2"), "runtime"));
DefaultDependencyNode node1 = new DefaultDependencyNode(new Dependency(
new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id:1").setFile(new File(".")), "runtime"));
DefaultDependencyNode node2 = new DefaultDependencyNode(new Dependency(
new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id-2:2").setFile(new File(".")), "runtime"));

DependencyResult dependencyResult = new DependencyResult(new DependencyRequest());
DefaultDependencyNode rootDependencyNode = new DefaultDependencyNode((Dependency) null);
Expand Down Expand Up @@ -177,8 +177,9 @@ public void test_getModuleSetResolutionRequirements_includeDeps() throws Excepti
// FIXME - this is not checked - because ms.UseAllReactorProjects is false
ms.addInclude("*:module-1");

DefaultDependencyNode node1 = new DefaultDependencyNode(
new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("group.id:module-1-dep:1"), "runtime"));
DefaultDependencyNode node1 = new DefaultDependencyNode(new Dependency(
new org.eclipse.aether.artifact.DefaultArtifact("group.id:module-1-dep:1").setFile(new File(".")),
"runtime"));

DependencyResult dependencyResult = new DependencyResult(new DependencyRequest());
DefaultDependencyNode rootDependencyNode = new DefaultDependencyNode((Dependency) null);
Expand Down

0 comments on commit 74e858a

Please sign in to comment.