-
Notifications
You must be signed in to change notification settings - Fork 73
[MASSEMBLY-832] Consider dependency optional attribute when gather de… #49
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 |
|---|---|---|
| @@ -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> |
| 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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| 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.handler.ArtifactHandler; | ||
| import org.apache.maven.execution.MavenSession; | ||
|
|
@@ -387,6 +388,54 @@ public void testGetDependencyArtifacts_ShouldFilterOneDependencyArtifactViaInclu | |
| assertSame(am1, result.iterator().next()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsByDefault() throws Exception { | ||
| Artifact am1 = mockArtifact(1); | ||
|
||
| when(am1.isOptional()).thenReturn(true); | ||
| Artifact am2 = mockArtifact(2); | ||
| Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(new DependencySet(), ImmutableSet.of(am1, am2)); | ||
| assertEquals(2, resolvedArtifacts.size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetDependencyArtifacts_ShouldFilterOptionalArtifactsExplicitly() throws Exception { | ||
| Artifact am1 = mockArtifact(1); | ||
|
||
| when(am1.isOptional()).thenReturn(true); | ||
| Artifact am2 = mockArtifact(2); | ||
| DependencySet dependencySet = new DependencySet(); | ||
| dependencySet.setUseOptionalDependencies(false); | ||
|
|
||
| Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(dependencySet, ImmutableSet.of(am1, am2)); | ||
| assertEquals(1, resolvedArtifacts.size()); | ||
| assertSame(am2, resolvedArtifacts.iterator().next()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsExplicitly() throws Exception { | ||
| Artifact am1 = mockArtifact(1); | ||
| when(am1.isOptional()).thenReturn(true); | ||
| Artifact am2 = mockArtifact(2); | ||
| DependencySet dependencySet = new DependencySet(); | ||
| dependencySet.setUseOptionalDependencies(true); | ||
|
|
||
| Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(dependencySet, ImmutableSet.of(am1, am2)); | ||
| assertEquals(2, resolvedArtifacts.size()); | ||
| } | ||
|
|
||
| private static Artifact mockArtifact(int id) { | ||
| Artifact a = mock(Artifact.class); | ||
|
||
| when(a.getId()).thenReturn("group:artifact" + id + ":1.0:jar"); | ||
| return a; | ||
| } | ||
|
|
||
| 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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Is this a boolean or a list? What if someone wants to include some optional dependencies and not others?
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.
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.