Skip to content

Commit

Permalink
Added classpath of dependencies for java sources sets to javaProvenan…
Browse files Browse the repository at this point in the history
…ce. (#69)
  • Loading branch information
traceyyoshima authored Aug 6, 2021
1 parent 2537d41 commit 9a04b93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ protected List<SourceFile> parse(Project subproject, List<NamedStyles> styles, I
.projectName(getProject().getName())
.buildToolVersion(GradleVersion.current().getVersion())
.vmRuntimeVersion(System.getProperty("java.runtime.version"))
.vmVendor(System.getProperty("java.vm.vendor"));
.vmVendor(System.getProperty("java.vm.vendor"))
.classpath(new HashSet<>());

Set<SourceSet> sourceSets;
if(javaConvention == null) {
Expand All @@ -212,10 +213,6 @@ protected List<SourceFile> parse(Project subproject, List<NamedStyles> styles, I

List<SourceFile> sourceFiles = new ArrayList<>();
for(SourceSet sourceSet : sourceSets) {
JavaProvenance javaProvenance = getRewrite()
.javaProvenanceBuilder(sharedProvenance)
.sourceSetName(sourceSet.getName())
.build();

List<Path> javaPaths = sourceSet.getAllJava().getFiles().stream()
.filter(it -> it.isFile() && it.getName().endsWith(".java"))
Expand All @@ -228,6 +225,12 @@ protected List<SourceFile> parse(Project subproject, List<NamedStyles> styles, I
.map(AbstractRewriteTask::toRealPath)
.collect(toList());

JavaProvenance javaProvenance = getRewrite()
.javaProvenanceBuilder(sharedProvenance)
.sourceSetName(sourceSet.getName())
.classpath(dependencyPaths)
.build();

if(javaPaths.size() > 0) {
getLog().lifecycle("Parsing " + javaPaths.size() + " Java files from " + sourceSet.getAllJava().getSourceDirectories().getAsPath());
Instant start = Instant.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ public class JavaProvenanceBuilder {
private String sourceCompatibility;
private String targetCompatibility;

//Classpath
private Iterable<Path> classpath;

//Publication
private String publicationGroupId;
private String publicationArtifactId;
Expand Down Expand Up @@ -328,6 +331,10 @@ public JavaProvenanceBuilder targetCompatibility(String targetCompatibility) {
this.targetCompatibility = targetCompatibility;
return this;
}
public JavaProvenanceBuilder classpath(Iterable<Path> classpath) {
this.classpath = classpath;
return this;
}
public JavaProvenanceBuilder publicationGroupId(String publicationGroupId) {
this.publicationGroupId = publicationGroupId;
return this;
Expand Down Expand Up @@ -366,11 +373,9 @@ public JavaProvenance build() {
.newInstance(this.publicationGroupId, this.publicationArtifactId, this.publicationVersion);

//Provenance
return new JavaProvenance(getClassLoader()
.loadClass("org.openrewrite.java.marker.JavaProvenance")
.getConstructor(UUID.class, String.class, String.class, buildTool.getClass(), javaVersion.getClass(), Set.class, publication.getClass())
.newInstance(UUID.randomUUID(), this.projectName, this.sourceSetName, buildTool, javaVersion, Collections.emptySet(), publication));

Class<?> c = getClassLoader().loadClass("org.openrewrite.java.marker.JavaProvenance");
Method javaProvenanceBuilder = c.getMethod("build", String.class, String.class, buildTool.getClass(), javaVersion.getClass(), Iterable.class, publication.getClass());
return new JavaProvenance(javaProvenanceBuilder.invoke(c.getName(), this.projectName, this.sourceSetName, buildTool, javaVersion, classpath, publication));
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 9a04b93

Please sign in to comment.