Skip to content

Commit a64b6af

Browse files
authored
Use resolved configuration and artifacts for Gradle plugin dependencies (#1352)
Fixes #1321 Signed-off-by: Michael Edgar <[email protected]>
1 parent b29019e commit a64b6af

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/GradleDependencyIndexCreator.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import java.util.List;
1212
import java.util.Map;
1313
import java.util.Map.Entry;
14+
import java.util.Set;
1415
import java.util.concurrent.ExecutionException;
1516
import java.util.stream.Collectors;
1617
import java.util.stream.Stream;
1718

18-
import org.gradle.api.artifacts.PublishArtifact;
19-
import org.gradle.api.artifacts.PublishArtifactSet;
19+
import org.gradle.api.artifacts.ResolvedArtifact;
2020
import org.gradle.api.file.FileCollection;
2121
import org.gradle.api.logging.Logger;
2222
import org.jboss.jandex.CompositeIndex;
@@ -34,23 +34,20 @@ public GradleDependencyIndexCreator(Logger logger) {
3434
this.logger = logger;
3535
}
3636

37-
IndexView createIndex(PublishArtifactSet allArtifacts, FileCollection classesDirs)
37+
IndexView createIndex(Set<ResolvedArtifact> dependencies, FileCollection classesDirs)
3838
throws Exception {
39-
List<Entry<PublishArtifact, Duration>> indexDurations = new ArrayList<>();
40-
List<PublishArtifact> artifacts = new ArrayList<>();
41-
if (allArtifacts != null) {
42-
artifacts.addAll(allArtifacts);
43-
}
39+
40+
List<Entry<ResolvedArtifact, Duration>> indexDurations = new ArrayList<>();
4441
List<IndexView> indexes = new ArrayList<>();
4542

4643
for (File f : classesDirs.getFiles()) {
4744
indexes.add(indexModuleClasses(f));
4845
}
4946

50-
for (PublishArtifact artifact : artifacts) {
47+
for (ResolvedArtifact artifact : dependencies) {
5148
try {
5249
if (artifact.getFile().isDirectory()) {
53-
// Don't cache local worskpace artifacts. Incremental compilation in IDE's would
50+
// Don't cache local workspace artifacts. Incremental compilation in IDE's would
5451
// otherwise use the cached index instead of new one.
5552
// Right now, support for incremental compilation inside eclipse is blocked by:
5653
// https://github.com/eclipse-m2e/m2e-core/issues/364#issuecomment-939987848
@@ -70,30 +67,29 @@ IndexView createIndex(PublishArtifactSet allArtifacts, FileCollection classesDir
7067
return CompositeIndex.create(indexes);
7168
}
7269

73-
private Index index(PublishArtifact artifact) throws IOException {
70+
private Index index(ResolvedArtifact artifact) throws IOException {
7471
Result result = JarIndexer.createJarIndex(artifact.getFile(), new Indexer(), false,
7572
false, false);
7673
return result.getIndex();
7774
}
7875

79-
private void printIndexDurations(List<Map.Entry<PublishArtifact, Duration>> indexDurations) {
76+
private void printIndexDurations(List<Map.Entry<ResolvedArtifact, Duration>> indexDurations) {
8077
if (logger.isDebugEnabled()) {
8178
indexDurations.sort(Map.Entry.comparingByValue());
8279

8380
indexDurations.forEach(e -> {
8481
if (e.getValue().toMillis() > 25) {
85-
PublishArtifact artifact = e.getKey();
86-
logger.debug("Indexing took {} for {}, {}, {}, {}, {}, {}", e.getValue(), artifact.getName(),
87-
artifact.getExtension(), artifact.getClassifier(), artifact.getType(), artifact.getDate(),
88-
artifact.getFile());
82+
ResolvedArtifact artifact = e.getKey();
83+
logger.debug("Indexing took {} for {}, {}, {}, {}, {}", e.getValue(), artifact.getName(),
84+
artifact.getExtension(), artifact.getClassifier(), artifact.getType(), artifact.getFile());
8985
}
9086
});
9187
}
9288
}
9389

9490
private IndexView timedIndex(
95-
List<Map.Entry<PublishArtifact, Duration>> indexDurations,
96-
PublishArtifact artifact) throws Exception {
91+
List<Map.Entry<ResolvedArtifact, Duration>> indexDurations,
92+
ResolvedArtifact artifact) throws Exception {
9793
LocalDateTime start = LocalDateTime.now();
9894
IndexView result = index(artifact);
9995
LocalDateTime end = LocalDateTime.now();
@@ -102,7 +98,7 @@ private IndexView timedIndex(
10298
return result;
10399
}
104100

105-
private Index indexModuleClasses(PublishArtifact artifact) throws IOException {
101+
private Index indexModuleClasses(ResolvedArtifact artifact) throws IOException {
106102
return indexModuleClasses(artifact.getFile());
107103
}
108104

tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/SmallryeOpenApiTask.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.nio.file.Paths;
1515
import java.nio.file.StandardOpenOption;
1616
import java.util.Collection;
17+
import java.util.Collections;
1718
import java.util.HashSet;
1819
import java.util.Map;
1920
import java.util.Objects;
@@ -27,7 +28,7 @@
2728
import org.gradle.api.GradleException;
2829
import org.gradle.api.NamedDomainObjectProvider;
2930
import org.gradle.api.artifacts.Configuration;
30-
import org.gradle.api.artifacts.PublishArtifactSet;
31+
import org.gradle.api.artifacts.ResolvedArtifact;
3132
import org.gradle.api.file.DirectoryProperty;
3233
import org.gradle.api.file.FileCollection;
3334
import org.gradle.api.file.ProjectLayout;
@@ -111,9 +112,11 @@ public void generate() {
111112

112113
Configuration config = configProvider.get();
113114

114-
PublishArtifactSet allArtifacts = properties.scanDependenciesDisable.get() ? null : config.getAllArtifacts();
115+
Set<ResolvedArtifact> dependencies = properties.scanDependenciesDisable.get().booleanValue()
116+
? Collections.emptySet()
117+
: config.getResolvedConfiguration().getResolvedArtifacts();
115118

116-
IndexView index = new GradleDependencyIndexCreator(getLogger()).createIndex(allArtifacts,
119+
IndexView index = new GradleDependencyIndexCreator(getLogger()).createIndex(dependencies,
117120
classesDirs);
118121
OpenApiDocument schema = generateSchema(index, resourcesSrcDirs, config);
119122
write(schema);

0 commit comments

Comments
 (0)