Skip to content

Commit

Permalink
Use resolved configuration and artifacts for Gradle plugin dependencies
Browse files Browse the repository at this point in the history
Fixes smallrye#1321

Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar committed Jan 13, 2023
1 parent 377d75b commit 86b65da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,23 +34,20 @@ public GradleDependencyIndexCreator(Logger logger) {
this.logger = logger;
}

IndexView createIndex(PublishArtifactSet allArtifacts, FileCollection classesDirs)
IndexView createIndex(Set<ResolvedArtifact> dependencies, FileCollection classesDirs)
throws Exception {
List<Entry<PublishArtifact, Duration>> indexDurations = new ArrayList<>();
List<PublishArtifact> artifacts = new ArrayList<>();
if (allArtifacts != null) {
artifacts.addAll(allArtifacts);
}

List<Entry<ResolvedArtifact, Duration>> indexDurations = new ArrayList<>();
List<IndexView> 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
Expand All @@ -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<Map.Entry<PublishArtifact, Duration>> indexDurations) {
private void printIndexDurations(List<Map.Entry<ResolvedArtifact, Duration>> 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<Map.Entry<PublishArtifact, Duration>> indexDurations,
PublishArtifact artifact) throws Exception {
List<Map.Entry<ResolvedArtifact, Duration>> indexDurations,
ResolvedArtifact artifact) throws Exception {
LocalDateTime start = LocalDateTime.now();
IndexView result = index(artifact);
LocalDateTime end = LocalDateTime.now();
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -111,9 +112,11 @@ public void generate() {

Configuration config = configProvider.get();

PublishArtifactSet allArtifacts = properties.scanDependenciesDisable.get() ? null : config.getAllArtifacts();
Set<ResolvedArtifact> 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);
Expand Down

0 comments on commit 86b65da

Please sign in to comment.