diff --git a/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/GradleDependencyIndexCreator.java b/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/GradleDependencyIndexCreator.java index de3d70b37..0bf6f62d0 100644 --- a/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/GradleDependencyIndexCreator.java +++ b/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/GradleDependencyIndexCreator.java @@ -11,12 +11,12 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.gradle.api.artifacts.PublishArtifact; -import org.gradle.api.artifacts.PublishArtifactSet; +import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.file.FileCollection; import org.gradle.api.logging.Logger; import org.jboss.jandex.CompositeIndex; @@ -34,23 +34,20 @@ public GradleDependencyIndexCreator(Logger logger) { this.logger = logger; } - IndexView createIndex(PublishArtifactSet allArtifacts, FileCollection classesDirs) + IndexView createIndex(Set dependencies, FileCollection classesDirs) throws Exception { - List> indexDurations = new ArrayList<>(); - List artifacts = new ArrayList<>(); - if (allArtifacts != null) { - artifacts.addAll(allArtifacts); - } + + List> indexDurations = new ArrayList<>(); List indexes = new ArrayList<>(); for (File f : classesDirs.getFiles()) { indexes.add(indexModuleClasses(f)); } - for (PublishArtifact artifact : artifacts) { + for (ResolvedArtifact artifact : dependencies) { try { if (artifact.getFile().isDirectory()) { - // Don't cache local worskpace artifacts. Incremental compilation in IDE's would + // Don't cache local workspace artifacts. Incremental compilation in IDE's would // otherwise use the cached index instead of new one. // Right now, support for incremental compilation inside eclipse is blocked by: // https://github.com/eclipse-m2e/m2e-core/issues/364#issuecomment-939987848 @@ -70,30 +67,29 @@ IndexView createIndex(PublishArtifactSet allArtifacts, FileCollection classesDir return CompositeIndex.create(indexes); } - private Index index(PublishArtifact artifact) throws IOException { + private Index index(ResolvedArtifact artifact) throws IOException { Result result = JarIndexer.createJarIndex(artifact.getFile(), new Indexer(), false, false, false); return result.getIndex(); } - private void printIndexDurations(List> indexDurations) { + private void printIndexDurations(List> indexDurations) { if (logger.isDebugEnabled()) { indexDurations.sort(Map.Entry.comparingByValue()); indexDurations.forEach(e -> { if (e.getValue().toMillis() > 25) { - PublishArtifact artifact = e.getKey(); - logger.debug("Indexing took {} for {}, {}, {}, {}, {}, {}", e.getValue(), artifact.getName(), - artifact.getExtension(), artifact.getClassifier(), artifact.getType(), artifact.getDate(), - artifact.getFile()); + ResolvedArtifact artifact = e.getKey(); + logger.debug("Indexing took {} for {}, {}, {}, {}, {}", e.getValue(), artifact.getName(), + artifact.getExtension(), artifact.getClassifier(), artifact.getType(), artifact.getFile()); } }); } } private IndexView timedIndex( - List> indexDurations, - PublishArtifact artifact) throws Exception { + List> indexDurations, + ResolvedArtifact artifact) throws Exception { LocalDateTime start = LocalDateTime.now(); IndexView result = index(artifact); LocalDateTime end = LocalDateTime.now(); @@ -102,7 +98,7 @@ private IndexView timedIndex( return result; } - private Index indexModuleClasses(PublishArtifact artifact) throws IOException { + private Index indexModuleClasses(ResolvedArtifact artifact) throws IOException { return indexModuleClasses(artifact.getFile()); } diff --git a/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/SmallryeOpenApiTask.java b/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/SmallryeOpenApiTask.java index dfef81a2f..e233f346f 100644 --- a/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/SmallryeOpenApiTask.java +++ b/tools/gradle-plugin/src/main/java/io/smallrye/openapi/gradleplugin/SmallryeOpenApiTask.java @@ -14,6 +14,7 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Objects; @@ -27,7 +28,7 @@ import org.gradle.api.GradleException; import org.gradle.api.NamedDomainObjectProvider; import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.PublishArtifactSet; +import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.FileCollection; import org.gradle.api.file.ProjectLayout; @@ -111,9 +112,11 @@ public void generate() { Configuration config = configProvider.get(); - PublishArtifactSet allArtifacts = properties.scanDependenciesDisable.get() ? null : config.getAllArtifacts(); + Set dependencies = properties.scanDependenciesDisable.get().booleanValue() + ? Collections.emptySet() + : config.getResolvedConfiguration().getResolvedArtifacts(); - IndexView index = new GradleDependencyIndexCreator(getLogger()).createIndex(allArtifacts, + IndexView index = new GradleDependencyIndexCreator(getLogger()).createIndex(dependencies, classesDirs); OpenApiDocument schema = generateSchema(index, resourcesSrcDirs, config); write(schema);