Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ under the License.
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>

<javaVersion>8</javaVersion>
<mdoVersion>2.2.0</mdoVersion>
<mdoVersion>2.3.0</mdoVersion>
<mavenVersion>3.6.3</mavenVersion>
<slf4jVersion>1.7.5</slf4jVersion>
<mavenFilteringVersion>3.4.0</mavenFilteringVersion>
Expand Down
70 changes: 70 additions & 0 deletions src/it/projects/dependency-sets/massembly-832/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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 http://maven.apache.org/maven-v4_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-832</artifactId>
<packaging>pom</packaging>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.7</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>9.3.0</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
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/plugins/maven-assembly-plugin/assembly/2.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.3.0
http://maven.apache.org/xsd/assembly-2.3.0.xsd">
<id>bin</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<outputDirectory></outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useOptionalDependencies>false</useOptionalDependencies>
</dependencySet>
</dependencySets>
</assembly>
37 changes: 37 additions & 0 deletions src/it/projects/dependency-sets/massembly-832/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

def expectedFilenames = [
"checker-qual-3.49.3.jar",
"postgresql-42.7.7.jar"
]

File assemblyBasedir = new File( basedir, "target/massembly-832-1-bin/" )

assert assemblyBasedir.listFiles().length == expectedFilenames.size()

for ( fileName in expectedFilenames )
{
File file = new File( assemblyBasedir, fileName )
assert file.isFile() // exists and is file
}

// defined set vs listed set: same cardinality and all present: OK

return true
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,18 @@ Set<Artifact> resolveDependencyArtifacts(final DependencySet dependencySet)

final ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(scopeFilter);

final ArtifactFilter optionalFilter =
artifact -> !artifact.isOptional() || dependencySet.isUseOptionalDependencies();

FilterUtils.filterArtifacts(
dependencyArtifacts,
dependencySet.getIncludes(),
dependencySet.getExcludes(),
dependencySet.isUseStrictFiltering(),
dependencySet.isUseTransitiveFiltering(),
LOGGER,
filter);
filter,
optionalFilter);

return dependencyArtifacts;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/mdo/assembly-component.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,15 @@
build should be included in this dependency set. Default value is false. (Since 2.2)
]]></description>
</field>
<field>
<name>useOptionalDependencies</name>
<version>2.3.0+</version>
<type>boolean</type>
Copy link
Contributor

@elharo elharo Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a boolean or a list? What if someone wants to include some optional dependencies and not others?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could possibly achieve this by declaring a separate dependencySet. It doesn't make much sense to make this very specific cause in that case we could use the existing include/exclude options.

<defaultValue>true</defaultValue>
<description>
Determines whether optional dependencies should be included in this dependency set.
</description>
</field>
<field>
<name>useTransitiveDependencies</name>
<version>1.1.0+</version>
Expand Down
9 changes: 9 additions & 0 deletions src/main/mdo/assembly.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,15 @@
build should be included in this dependency set. (Since 2.2-beta-1)
]]></description>
</field>
<field>
<name>useOptionalDependencies</name>
<version>2.3.0+</version>
<type>boolean</type>
<defaultValue>true</defaultValue>
<description>
Determines whether optional dependencies should be included in this dependency set.
</description>
</field>
<field>
<name>useTransitiveDependencies</name>
<version>1.1.0+</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
import java.util.Properties;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
Expand Down Expand Up @@ -387,6 +390,62 @@ public void testGetDependencyArtifacts_ShouldFilterOneDependencyArtifactViaInclu
assertSame(am1, result.iterator().next());
}

@Test
public void testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsByDefault() throws Exception {
Artifact artifact1 = artifact(1);
artifact1.setOptional(true);
Artifact artifact2 = artifact(2);
Set<Artifact> resolvedArtifacts =
resolveDependencyArtifacts(new DependencySet(), ImmutableSet.of(artifact1, artifact2));
assertEquals(2, resolvedArtifacts.size());
}

@Test
public void testGetDependencyArtifacts_ShouldFilterOptionalArtifactsExplicitly() throws Exception {
Artifact artifact1 = artifact(1);
artifact1.setOptional(true);
Artifact artifact2 = artifact(2);
DependencySet dependencySet = new DependencySet();
dependencySet.setUseOptionalDependencies(false);

Set<Artifact> resolvedArtifacts =
resolveDependencyArtifacts(dependencySet, ImmutableSet.of(artifact1, artifact2));
assertEquals(1, resolvedArtifacts.size());
assertSame(artifact2, resolvedArtifacts.iterator().next());
}

@Test
public void testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsExplicitly() throws Exception {
Artifact artifact1 = artifact(1);
artifact1.setOptional(true);
Artifact artifact2 = artifact(2);
DependencySet dependencySet = new DependencySet();
dependencySet.setUseOptionalDependencies(true);

Set<Artifact> resolvedArtifacts =
resolveDependencyArtifacts(dependencySet, ImmutableSet.of(artifact1, artifact2));
assertEquals(2, resolvedArtifacts.size());
}

private static Artifact artifact(int id) {
return new DefaultArtifact(
"org.apache.maven.plugins",
"artifact" + id,
"1.0",
Artifact.SCOPE_COMPILE,
"jar",
null,
new DefaultArtifactHandler());
}

private Set<Artifact> resolveDependencyArtifacts(DependencySet dependencySet, Set<Artifact> artifacts)
throws Exception {
MavenProject project = new MavenProject(new Model());
AddDependencySetsTask task =
new AddDependencySetsTask(Collections.singletonList(dependencySet), artifacts, project, null);
return task.resolveDependencyArtifacts(dependencySet);
}

@Test
public void testGetDependencyArtifacts_ShouldIgnoreTransitivePathFilteringWhenIncludeNotTransitive()
throws Exception {
Expand Down