|
24 | 24 |
|
25 | 25 | import org.gradle.api.Project;
|
26 | 26 | import org.gradle.api.artifacts.Configuration;
|
| 27 | +import org.gradle.api.artifacts.Dependency; |
| 28 | +import org.gradle.api.artifacts.FileCollectionDependency; |
27 | 29 | import org.gradle.api.artifacts.ModuleVersionIdentifier;
|
28 | 30 | import org.gradle.api.artifacts.ResolvedArtifact;
|
29 | 31 | import org.springframework.boot.gradle.SpringBootPluginExtension;
|
@@ -72,70 +74,100 @@ public void setCustomConfigurationName(String customConfigurationName) {
|
72 | 74 |
|
73 | 75 | @Override
|
74 | 76 | public void doWithLibraries(LibraryCallback callback) throws IOException {
|
75 |
| - Set<ResolvedArtifact> custom = getArtifacts(this.customConfigurationName); |
| 77 | + Set<Library> custom = getLibraries(this.customConfigurationName, |
| 78 | + LibraryScope.CUSTOM); |
76 | 79 | if (custom != null) {
|
77 |
| - libraries(LibraryScope.CUSTOM, custom, callback); |
| 80 | + libraries(custom, callback); |
78 | 81 | }
|
79 | 82 | else {
|
80 |
| - Set<ResolvedArtifact> compile = getArtifacts("compile"); |
| 83 | + Set<Library> compile = getLibraries("compile", LibraryScope.COMPILE); |
81 | 84 |
|
82 |
| - Set<ResolvedArtifact> runtime = getArtifacts("runtime"); |
| 85 | + Set<Library> runtime = getLibraries("runtime", LibraryScope.RUNTIME); |
83 | 86 | runtime = minus(runtime, compile);
|
84 | 87 |
|
85 |
| - Set<ResolvedArtifact> provided = getArtifacts(this.providedConfigurationName); |
| 88 | + Set<Library> provided = getLibraries(this.providedConfigurationName, |
| 89 | + LibraryScope.PROVIDED); |
86 | 90 | if (provided != null) {
|
87 | 91 | compile = minus(compile, provided);
|
88 | 92 | runtime = minus(runtime, provided);
|
89 | 93 | }
|
90 | 94 |
|
91 |
| - libraries(LibraryScope.COMPILE, compile, callback); |
92 |
| - libraries(LibraryScope.RUNTIME, runtime, callback); |
93 |
| - libraries(LibraryScope.PROVIDED, provided, callback); |
| 95 | + libraries(compile, callback); |
| 96 | + libraries(runtime, callback); |
| 97 | + libraries(provided, callback); |
94 | 98 | }
|
95 | 99 | }
|
96 | 100 |
|
97 |
| - private Set<ResolvedArtifact> getArtifacts(String configurationName) { |
| 101 | + private Set<Library> getLibraries(String configurationName, LibraryScope scope) { |
98 | 102 | Configuration configuration = (configurationName == null ? null : this.project
|
99 | 103 | .getConfigurations().findByName(configurationName));
|
100 |
| - return (configuration == null ? null : configuration.getResolvedConfiguration() |
101 |
| - .getResolvedArtifacts()); |
| 104 | + if (configuration == null) { |
| 105 | + return null; |
| 106 | + } |
| 107 | + Set<Library> libraries = new LinkedHashSet<Library>(); |
| 108 | + for (ResolvedArtifact artifact : configuration.getResolvedConfiguration() |
| 109 | + .getResolvedArtifacts()) { |
| 110 | + libraries.add(new ResolvedArtifactLibrary(artifact, scope)); |
| 111 | + } |
| 112 | + for (Dependency dependency : configuration.getIncoming().getDependencies()) { |
| 113 | + if (dependency instanceof FileCollectionDependency) { |
| 114 | + FileCollectionDependency fileDependency = (FileCollectionDependency) dependency; |
| 115 | + for (File file : fileDependency.resolve()) { |
| 116 | + libraries.add(new Library(file, scope)); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + return libraries; |
102 | 121 | }
|
103 | 122 |
|
104 |
| - private Set<ResolvedArtifact> minus(Set<ResolvedArtifact> source, |
105 |
| - Set<ResolvedArtifact> toRemove) { |
| 123 | + private Set<Library> minus(Set<Library> source, Set<Library> toRemove) { |
106 | 124 | if (source == null || toRemove == null) {
|
107 | 125 | return source;
|
108 | 126 | }
|
109 | 127 | Set<File> filesToRemove = new HashSet<File>();
|
110 |
| - for (ResolvedArtifact artifact : toRemove) { |
111 |
| - filesToRemove.add(artifact.getFile()); |
| 128 | + for (Library library : toRemove) { |
| 129 | + filesToRemove.add(library.getFile()); |
112 | 130 | }
|
113 |
| - Set<ResolvedArtifact> result = new LinkedHashSet<ResolvedArtifact>(); |
114 |
| - for (ResolvedArtifact artifact : source) { |
115 |
| - if (!filesToRemove.contains(artifact.getFile())) { |
116 |
| - result.add(artifact); |
| 131 | + Set<Library> result = new LinkedHashSet<Library>(); |
| 132 | + for (Library library : source) { |
| 133 | + if (!filesToRemove.contains(library.getFile())) { |
| 134 | + result.add(library); |
117 | 135 | }
|
118 | 136 | }
|
119 | 137 | return result;
|
120 | 138 | }
|
121 | 139 |
|
122 |
| - private void libraries(LibraryScope scope, Set<ResolvedArtifact> artifacts, |
123 |
| - LibraryCallback callback) throws IOException { |
124 |
| - if (artifacts != null) { |
125 |
| - for (ResolvedArtifact artifact : artifacts) { |
126 |
| - callback.library(new Library(artifact.getFile(), scope, |
127 |
| - isUnpackRequired(artifact))); |
| 140 | + private void libraries(Set<Library> libraries, LibraryCallback callback) |
| 141 | + throws IOException { |
| 142 | + if (libraries != null) { |
| 143 | + for (Library library : libraries) { |
| 144 | + callback.library(library); |
128 | 145 | }
|
129 | 146 | }
|
130 | 147 | }
|
131 | 148 |
|
132 |
| - private boolean isUnpackRequired(ResolvedArtifact artifact) { |
133 |
| - if (this.extension.getRequiresUnpack() != null) { |
134 |
| - ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); |
135 |
| - return this.extension.getRequiresUnpack().contains( |
136 |
| - id.getGroup() + ":" + id.getName()); |
| 149 | + /** |
| 150 | + * Adapts a {@link ResolvedArtifact} to a {@link Library}. |
| 151 | + */ |
| 152 | + private class ResolvedArtifactLibrary extends Library { |
| 153 | + |
| 154 | + private final ResolvedArtifact artifact; |
| 155 | + |
| 156 | + public ResolvedArtifactLibrary(ResolvedArtifact artifact, LibraryScope scope) { |
| 157 | + super(artifact.getFile(), scope); |
| 158 | + this.artifact = artifact; |
| 159 | + } |
| 160 | + |
| 161 | + @Override |
| 162 | + public boolean isUnpackRequired() { |
| 163 | + if (ProjectLibraries.this.extension.getRequiresUnpack() != null) { |
| 164 | + ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); |
| 165 | + return ProjectLibraries.this.extension.getRequiresUnpack().contains( |
| 166 | + id.getGroup() + ":" + id.getName()); |
| 167 | + } |
| 168 | + return false; |
137 | 169 | }
|
138 |
| - return false; |
| 170 | + |
139 | 171 | }
|
140 | 172 |
|
141 | 173 | }
|
0 commit comments