Skip to content

Commit

Permalink
post review 2
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Jan 26, 2024
1 parent a68e2b1 commit 81bd0cb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
49 changes: 15 additions & 34 deletions build-caching/src/main/java/com/vertispan/j2cl/build/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
Expand All @@ -27,9 +28,7 @@ public class Project implements com.vertispan.j2cl.build.task.Project {

private File jar;

private Optional<Boolean> isAPT = Optional.empty();

private Set<String> processors = new HashSet<>();
private Set<String> processors;

public Project(String key) {
this.key = key;
Expand Down Expand Up @@ -99,53 +98,35 @@ public boolean isJsZip() {
return isJsZip;
}

/*
* This is a bit of a hack, but it's the only way to know if a jar contains APT processors
* Note: isAPT() must be called before getProcessors
*/
@Override
public boolean isAPT() {
if (isAPT.isEmpty()) {
public File getJar() {
return jar;
}

public void setJar(File jar) {
this.jar = jar;
}

@Override
public Set<String> getProcessors() {
if (processors == null) {
if (jar == null || isJsZip() || hasSourcesMapped()) {
isAPT = Optional.of(false);
return false;
processors = Collections.emptySet();
} else if (jar.exists()) {
processors = new HashSet<>();
try (ZipFile zipFile = new ZipFile(jar)) {
ZipEntry entry = zipFile.getEntry("META-INF/services/javax.annotation.processing.Processor");
if (entry != null) {
this.isAPT = Optional.of(true);

try (InputStreamReader inputStreamReader = new InputStreamReader(zipFile.getInputStream(entry), StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
bufferedReader.lines().forEach(line -> processors.add(line.trim()));
if (!processors.isEmpty()) {
this.isAPT = Optional.of(true);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
this.isAPT = Optional.of(false);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return isAPT.get();
}

@Override
public File getJar() {
return jar;
}

public void setJar(File jar) {
this.jar = jar;
}

@Override
public Set<String> getProcessors() {
return processors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public interface Project {
* @return true if this project should only be used for its JS content, false otherwise
*/
boolean isJsZip();

boolean isAPT();


File getJar();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Task resolve(Project project, Config config) {

List<Input> bytecodeClasspath = scope(project.getDependencies()
.stream()
.filter(dependency -> !dependency.getProject().isAPT()).collect(Collectors.toSet()),
.filter(dependency -> dependency.getProject().getProcessors().isEmpty()).collect(Collectors.toSet()),
com.vertispan.j2cl.build.task.Dependency.Scope.COMPILE)
.stream()
.map(inputs(OutputTypes.BYTECODE))
Expand All @@ -101,7 +101,7 @@ public Task resolve(Project project, Config config) {
project.getDependencies()
.stream()
.map(d -> d.getProject())
.filter(Project::isAPT)
.filter(p -> !p.getProcessors().isEmpty())
.forEach(p -> {
processors.addAll(p.getProcessors());
extraClasspath.add(p.getJar());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Task resolve(Project project, Config config) {

// From our classpath, j2cl is only interested in our compile classpath's bytecode
List<Input> classpathHeaders = scope(project.getDependencies().stream()
.filter(dep -> !dep.getProject().isAPT())
.filter(dep -> dep.getProject().getProcessors().isEmpty())
.collect(Collectors.toSet()), com.vertispan.j2cl.build.task.Dependency.Scope.COMPILE)
.stream()
.map(inputs(OutputTypes.STRIPPED_BYTECODE_HEADERS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Task resolve(Project project, Config config) {
List<File> extraClasspath = config.getExtraClasspath();

List<Input> compileClasspath = scope(project.getDependencies().stream()
.filter(dep -> !dep.getProject().isAPT())
.filter(dep -> dep.getProject().getProcessors().isEmpty())
.collect(Collectors.toSet()), Dependency.Scope.COMPILE)
.stream()
.map(p -> input(p, OutputTypes.STRIPPED_BYTECODE_HEADERS))
Expand Down

0 comments on commit 81bd0cb

Please sign in to comment.