Skip to content

Commit 0645c13

Browse files
committed
Maps from dependency names to files.
1 parent 9ecd2ba commit 0645c13

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2018 Google LLC. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.google.cloud.tools.jib.gradle;
18+
19+
import java.nio.file.Path;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import java.util.Set;
23+
import java.util.function.Consumer;
24+
import java.util.stream.Collectors;
25+
import org.gradle.api.Project;
26+
import org.gradle.api.artifacts.Configuration;
27+
import org.gradle.api.artifacts.ResolvedDependency;
28+
import org.gradle.api.tasks.SourceSet;
29+
30+
public class GradleProjectDependencies {
31+
32+
Map<String, Set<Path>> getDependencies(Project project, SourceSet sourceSet) {
33+
Map<String, Set<Path>> dependencyMap = new HashMap<>();
34+
35+
Consumer<ResolvedDependency> handleDep =
36+
resolvedDependency -> {
37+
Set<Path> artifactSet =
38+
resolvedDependency
39+
.getModuleArtifacts()
40+
.stream()
41+
.map(resolvedArtifact -> resolvedArtifact.getFile().toPath())
42+
.collect(Collectors.toSet());
43+
dependencyMap.put(resolvedDependency.getName(), artifactSet);
44+
};
45+
Consumer<ResolvedDependency> recursiveDependencyConsumer =
46+
resolvedDependency -> {
47+
handleDep.accept(resolvedDependency);
48+
resolvedDependency.getChildren().forEach(handleDep);
49+
};
50+
51+
Configuration runtimeClasspathConfiguration =
52+
project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName());
53+
runtimeClasspathConfiguration
54+
.getResolvedConfiguration()
55+
.getFirstLevelModuleDependencies()
56+
.forEach(recursiveDependencyConsumer);
57+
58+
return dependencyMap;
59+
}
60+
}

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleSourceFilesConfiguration.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
import java.nio.file.Path;
2525
import java.util.ArrayList;
2626
import java.util.List;
27+
import java.util.function.Consumer;
2728
import java.util.stream.Stream;
2829
import org.gradle.api.Project;
30+
import org.gradle.api.artifacts.Configuration;
31+
import org.gradle.api.artifacts.ResolvedDependency;
2932
import org.gradle.api.file.FileCollection;
3033
import org.gradle.api.plugins.JavaPluginConvention;
3134
import org.gradle.api.tasks.SourceSet;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2018 Google LLC. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.google.cloud.tools.jib.maven;
18+
19+
import java.nio.file.Path;
20+
import java.util.Collections;
21+
import java.util.HashMap;
22+
import java.util.HashSet;
23+
import java.util.Map;
24+
import java.util.Set;
25+
import org.apache.maven.artifact.Artifact;
26+
27+
public class MavenProjectDependencies {
28+
29+
Map<String, Set<Path>> getDependencies(Set<Artifact> artifacts) {
30+
Map<String, Set<Path>> dependencyMap = new HashMap<>();
31+
32+
artifacts.forEach(
33+
artifact -> {
34+
String artifactName =
35+
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
36+
dependencyMap.put(artifactName, Collections.singleton(artifact.getFile().toPath()));
37+
});
38+
39+
return dependencyMap;
40+
}
41+
}

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenSourceFilesConfiguration.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.nio.file.Paths;
2626
import java.util.ArrayList;
2727
import java.util.List;
28+
import java.util.logging.Logger;
2829
import java.util.stream.Stream;
2930
import org.apache.maven.artifact.Artifact;
3031
import org.apache.maven.project.MavenProject;

0 commit comments

Comments
 (0)