Skip to content

Commit

Permalink
jdt 3.37.0
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Apr 13, 2024
1 parent c6131b5 commit a9e7af0
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment

Filer filer = processingEnv.getFiler();
elements.stream().filter(e -> e.getKind().isInterface()).forEach(type -> {

System.out.println("Found annotated type: " + type);

//emit a new class for that type, with no-arg string methods
try {
ClassName origClassName = ClassName.get((TypeElement) type);
Expand Down Expand Up @@ -79,7 +82,9 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
}
}
JavaFile newFile = JavaFile.builder(origClassName.packageName(), builder.build()).build();
System.out.println("writing: " + origClassName.simpleName() + "_Impl");
newFile.writeTo(filer);
System.out.println("wrote: " + origClassName.simpleName() + "_Impl");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
10 changes: 9 additions & 1 deletion j2cl-tasks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.34.0</version>
<version>3.37.0</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.platform</groupId>
Expand All @@ -96,6 +96,14 @@
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String getOutputType() {

@Override
public String getTaskName() {
return "default";
return "javac";
}

@Override
Expand Down Expand Up @@ -161,10 +161,7 @@ protected File getGeneratedClassesDir(TaskContext context) {
return context.outputPath().toFile();
}

private Set<String> maybeAddInReactorAptProcessor(List<Input> reactorProcessors, Set<String> processors) {
if (processors.isEmpty()) {
return Collections.emptySet();
}
public Set<String> maybeAddInReactorAptProcessor(List<Input> reactorProcessors, Set<String> processors) {
Set<String> existingProcessors = new HashSet<>(processors);
reactorProcessors.forEach(input -> input.getFilesAndHashes().forEach(file -> {
try (Stream<String> lines = Files.lines(file.getAbsolutePath())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Task resolve(Project project, Config config) {
.stream()
//.filter(dependency -> !dependency.isJsZip())
.forEach(dependency -> {
System.out.println("Dependency: " + dependency.getKey());
//System.out.println("Dependency: " + dependency.getKey());
});

List<Input> bytecodeClasspath = scope(project.getDependencies()
Expand Down Expand Up @@ -142,23 +142,16 @@ public Task resolve(Project project, Config config) {
File generatedClassesDir = getGeneratedClassesDir(context);
File classOutputDir = context.outputPath().toFile();


sourcePaths.forEach(s -> {
System.out.println("Source Path: " + s.getAbsolutePath());
});

classpathDirs.forEach(f -> {
System.out.println("Classpath Dir: " + f.getAbsolutePath());
});


System.out.println("started : " + project.getKey());
Jdt javac = new Jdt(context, generatedClassesDir, sourcePaths, classpathDirs, classOutputDir, aptProcessors);
System.out.println("finished : " + project.getKey());


// TODO convention for mapping to original file paths, provide FileInfo out of Inputs instead of Paths,
// automatically relativized?
List<SourceUtils.FileInfo> sources = inputSources.getFilesAndHashes()
.stream()
.filter(p -> !p.getAbsolutePath().toFile().getName().equals("moduleinfo.java"))
.filter(p -> !p.getAbsolutePath().toFile().getName().equals("module-info.java"))
.map(p -> SourceUtils.FileInfo.create(p.getAbsolutePath().toString(), p.getSourcePath().toString()))
.collect(Collectors.toUnmodifiableList());

Expand Down
89 changes: 89 additions & 0 deletions j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Jdt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.vertispan.j2cl.tools;

import com.google.j2cl.common.SourceUtils;
import com.vertispan.j2cl.build.task.BuildLog;
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.batch.Main;

import javax.lang.model.SourceVersion;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class Jdt {

private final BuildLog log;
private final List<String> javacOptions;

public Jdt(BuildLog log, File generatedClassesPath, List<File> sourcePaths, List<File> classpath, File classesDirFile, Set<String> processors) {
this.log = log;
this.javacOptions = new ArrayList<>(Arrays.asList("-encoding", "utf8"));
//this.javacOptions = new ArrayList<>();



if (generatedClassesPath == null) {
javacOptions.add("-proc:none");
}
if (SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_11) >= 0) {
//none
}
javacOptions.add("-11");

if (!processors.isEmpty()) {
javacOptions.add("-processor");
javacOptions.add(String.join(",", processors));
System.out.println("processors: " + String.join(",", processors));

} else {
System.out.println("No processors");
javacOptions.add("-proc:none");
}

javacOptions.add("-sourcepath");
javacOptions.add(sourcePaths.stream().map(File::getAbsolutePath).collect(Collectors.joining(":")));

System.out.println("sourcepath: " + sourcePaths.stream().map(File::getAbsolutePath).collect(Collectors.joining(":")));

javacOptions.add("-classpath");

System.out.println("classpath: ");
classpath.stream().map(File::getAbsolutePath).forEach(e -> {
//System.out.println(e);
});

javacOptions.add(classpath.stream().map(File::getAbsolutePath).collect(Collectors.joining(":")));

javacOptions.add("-d"); // -d <dir> destination directory
javacOptions.add(classesDirFile.getAbsolutePath());
javacOptions.add("-s"); //-s <dir> destination directory for generated source files
javacOptions.add(generatedClassesPath.getAbsolutePath());
javacOptions.add("-time");
javacOptions.add("-XprintProcessorInfo");
javacOptions.add("-XprintRounds");

System.out.println("-D " + classesDirFile.getAbsolutePath());
System.out.println("-S " + generatedClassesPath.getAbsolutePath());

}

public boolean compile(List<SourceUtils.FileInfo> modifiedJavaFiles) {
modifiedJavaFiles.forEach(f -> javacOptions.add(f.sourcePath()));

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();

boolean result = BatchCompiler.compile(javacOptions.toArray(new String[javacOptions.size()]), new PrintWriter(outputStream), new PrintWriter(errorOutputStream), null);

log.info(outputStream.toString(Charset.defaultCharset()));
log.error(errorOutputStream.toString(Charset.defaultCharset()));
return result;
}
}

This file was deleted.

0 comments on commit a9e7af0

Please sign in to comment.