[Git][java-team/ivyplusplus][upstream] New upstream version 1.40

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Thu May 12 07:46:33 BST 2022



Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / ivyplusplus


Commits:
99b40203 by Emmanuel Bourg at 2022-05-11T10:46:01+02:00
New upstream version 1.40
- - - - -


5 changed files:

- README.markdown
- + src/com/zwitserloot/ivyplusplus/AnnotationProcessorEntry.java
- src/com/zwitserloot/ivyplusplus/Compile.java
- src/com/zwitserloot/ivyplusplus/Version.java
- src/com/zwitserloot/ivyplusplus/ecj/EcjAdapter.java


Changes:

=====================================
README.markdown
=====================================
@@ -127,6 +127,8 @@ The _destdir_ directory is also created automatically, so you don't have to `<mk
 
 (since ipp 1.22: You can also set ecj="true" to use ecj instead. Useful if you want to compile with old source/target).
 
+(since ipp 1.40: You can include a `<annotationProcessor jar="path/to/processor.jar" processor="fully.qualified.ClassName">` element, which is required to run APs in ecj).
+
 _Supported since ipp 1.0_
 
 ### `<ivy:cachedunjar>` - similar to unjar, except will not unpack jars that don't need to be unpacked.


=====================================
src/com/zwitserloot/ivyplusplus/AnnotationProcessorEntry.java
=====================================
@@ -0,0 +1,24 @@
+package com.zwitserloot.ivyplusplus;
+
+import java.io.File;
+
+public class AnnotationProcessorEntry {
+	private String processorClass;
+	private File jar;
+	
+	public void setProcessor(String proc) {
+		this.processorClass = proc;
+	}
+	
+	public void setJar(File jar) {
+		this.jar = jar;
+	}
+	
+	public String getProcessor() {
+		return processorClass;
+	}
+	
+	public File getJar() {
+		return jar;
+	}
+}
\ No newline at end of file


=====================================
src/com/zwitserloot/ivyplusplus/Compile.java
=====================================
@@ -27,8 +27,10 @@ import java.io.File;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DynamicAttribute;
@@ -201,6 +203,7 @@ public class Compile extends MatchingTask implements DynamicAttribute {
 	}
 	
 	private List<ImplementationSpecificArgument> compilerArgs = new ArrayList<ImplementationSpecificArgument>();
+	private List<AnnotationProcessorEntry> annotationProcessorEntries = new ArrayList<AnnotationProcessorEntry>();
 	
 	public ImplementationSpecificArgument createCompilerArg() {
 		ImplementationSpecificArgument arg = new ImplementationSpecificArgument();
@@ -208,6 +211,12 @@ public class Compile extends MatchingTask implements DynamicAttribute {
 		return arg;
 	}
 	
+	public AnnotationProcessorEntry createAnnotationProcessor() {
+		AnnotationProcessorEntry entry = new AnnotationProcessorEntry();
+		annotationProcessorEntries.add(entry);
+		return entry;
+	}
+	
 	public void execute() {
 		if (destdirLoc == null) throw new BuildException("mandatory property 'destdir' not set.");
 		log(getLocation().toString() + "compiling to " + destdirLoc, Project.MSG_VERBOSE);
@@ -236,7 +245,15 @@ public class Compile extends MatchingTask implements DynamicAttribute {
 		if (compileClasspath != null) javacTask.setClasspath(compileClasspath);
 		if (compileSourcepath != null) javacTask.setSourcepath(compileSourcepath);
 		if (extdirs != null) javacTask.setExtdirs(extdirs);
+		
+		Set<String> procClasses = new LinkedHashSet<String>();
+		Set<File> procJars = new LinkedHashSet<File>();
 		try {
+			for (AnnotationProcessorEntry entry : annotationProcessorEntries) {
+				procClasses.add(entry.getProcessor());
+				procJars.add(entry.getJar());
+			}
+			
 			Field f = MatchingTask.class.getDeclaredField("fileset");
 			f.setAccessible(true);
 			f.set(javacTask, getImplicitFileSet().clone());
@@ -244,11 +261,40 @@ public class Compile extends MatchingTask implements DynamicAttribute {
 			f.setAccessible(true);
 			FacadeTaskHelper facade = (FacadeTaskHelper) f.get(javacTask);
 			for (ImplementationSpecificArgument isa : compilerArgs) facade.addImplementationArgument(isa);
+			if (!procJars.isEmpty()) {
+				ImplementationSpecificArgument arg = new ImplementationSpecificArgument();
+				arg.setValue("-processorpath");
+				facade.addImplementationArgument(arg);
+				StringBuilder sb = new StringBuilder();
+				for (File procJar : procJars) {
+					if (sb.length() > 0) sb.append(File.pathSeparator);
+					sb.append(procJar.getAbsolutePath());
+				}
+				arg = new ImplementationSpecificArgument();
+				arg.setValue(sb.toString());
+				facade.addImplementationArgument(arg);
+			}
+			if (!procClasses.isEmpty()) {
+				ImplementationSpecificArgument arg = new ImplementationSpecificArgument();
+				arg.setValue("-processor");
+				facade.addImplementationArgument(arg);
+				StringBuilder sb = new StringBuilder();
+				for (String procClass : procClasses) {
+					if (sb.length() > 0) sb.append(",");
+					sb.append(procClass);
+				}
+				arg = new ImplementationSpecificArgument();
+				arg.setValue(sb.toString());
+				facade.addImplementationArgument(arg);
+				
+			}
 		} catch (Exception e) {
 			throw new BuildException(e, getLocation());
 		}
 		if (ecj) {
+			if (!compilerArgs.isEmpty()) throw new BuildException("compilerArg is not supported for ecj=\"true\"");
 			EcjAdapter ecjAdapter = new EcjAdapter();
+			ecjAdapter.setAnnotationProcessorEntries(procClasses, procJars);
 			if (includeSystemBootclasspath) ecjAdapter.setIncludeSystemBootclasspath(true);
 			javacTask.add(ecjAdapter);
 		} else {


=====================================
src/com/zwitserloot/ivyplusplus/Version.java
=====================================
@@ -23,7 +23,7 @@ package com.zwitserloot.ivyplusplus;
 
 public class Version {
 	// ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries).
-	private static final String VERSION = "1.38";
+	private static final String VERSION = "1.40";
 	
 	private Version() {
 		//Prevent instantiation


=====================================
src/com/zwitserloot/ivyplusplus/ecj/EcjAdapter.java
=====================================
@@ -7,19 +7,25 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
 import java.nio.channels.FileChannel;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
+
+import javax.tools.StandardLocation;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Javac;
 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
-import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.FileResource;
@@ -28,8 +34,13 @@ import org.eclipse.jdt.internal.compiler.Compiler;
 import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
 import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
 import org.eclipse.jdt.internal.compiler.IProblemFactory;
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager;
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager;
+import org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl;
+import org.eclipse.jdt.internal.compiler.apt.util.EclipseFileManager;
 import org.eclipse.jdt.internal.compiler.batch.FileSystem;
 import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
+import org.eclipse.jdt.internal.compiler.batch.Main;
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
 import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment;
 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
@@ -47,6 +58,8 @@ public class EcjAdapter implements CompilerAdapter {
 	
 	private Javac javac;
 	private boolean includeSystemBootclasspath;
+	private Set<String> procClasses;
+	private Set<File> procJars;
 	
 	public void setJavac(Javac javac) {
 		this.javac = javac;
@@ -287,11 +300,7 @@ public class EcjAdapter implements CompilerAdapter {
 	private String getDefaultEncoding() {
 		String encoding = javac.getEncoding();
 		if (encoding != null) return encoding;
-		
-		if (Os.isFamily(Os.FAMILY_WINDOWS) && Charset.isSupported("Cp1252")) return "Cp1252";
-		if (Os.isFamily(Os.FAMILY_UNIX) && Charset.isSupported("UTF-8")) return "UTF-8";
-		if (Os.isFamily(Os.FAMILY_MAC) && Charset.isSupported("MacRoman")) return "MacRoman";
-		return System.getProperty("file.encoding");
+		return "UTF-8";
 	}
 	
 	private boolean hasSourceFolder(File sourceFile) {
@@ -335,14 +344,70 @@ public class EcjAdapter implements CompilerAdapter {
 	
 	public CompileJobResult compile(CompileJobDescription description) {
 		IModuleAwareNameEnvironment nameEnvironment = new MyFileSystem(description.getClasspaths());
-		Map<String, String> compilerOptions = description.getCompilerOptions();
+		Map<String, String> compilerOptionsMap = description.getCompilerOptions();
 		ICompilationUnit[] sources = getCompilationUnits(description.getSourceFiles());
 		IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
 		IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
 		CompilerRequestorImpl requestor = new CompilerRequestorImpl();
-		Compiler compiler = new Compiler(nameEnvironment, policy, new CompilerOptions(compilerOptions), requestor, problemFactory);
+		CompilerOptions compilerOptions = new CompilerOptions(compilerOptionsMap);
+		compilerOptions.storeAnnotations = true;
+		Compiler compiler = new Compiler(nameEnvironment, policy, compilerOptions, requestor, problemFactory);
 		
 		if (Boolean.getBoolean("ecj.useMultiThreading")) compiler.useSingleThread = false;
+		BatchAnnotationProcessorManager aptManager = new BatchAnnotationProcessorManager();
+		Main m = makeDummyMain();
+		m.batchCompiler = compiler;
+		List<String> aptArgs = new ArrayList<String>();
+		if (!procJars.isEmpty()) {
+			aptArgs.add("-processorpath");
+			StringBuilder sb = new StringBuilder();
+			for (File procJar : procJars) {
+				if (sb.length() > 0) sb.append(File.pathSeparator);
+				sb.append(procJar.getAbsolutePath());
+			}
+			aptArgs.add(sb.toString());
+		}
+		if (!procClasses.isEmpty()) {
+			aptArgs.add("-processor");
+			StringBuilder sb = new StringBuilder();
+			for (String procClass : procClasses) {
+				if (sb.length() > 0) sb.append(",");
+				sb.append(procClass);
+			}
+			aptArgs.add(sb.toString());
+		}
+		
+		aptManager.configure(m, aptArgs.toArray(new String[0]));
+		compiler.annotationProcessorManager = aptManager;
+		
+		EclipseFileManager filer = null;
+		
+		try {
+			Field f = BaseAnnotationProcessorManager.class.getDeclaredField("_processingEnv");
+			f.setAccessible(true);
+			BatchProcessingEnvImpl procEnv = (BatchProcessingEnvImpl) f.get(aptManager);
+			filer = (EclipseFileManager) procEnv.getFileManager();
+		} catch (NoSuchFieldException e) {
+			// we tried - maybe it's different infra.
+		} catch (IllegalAccessException e) {
+			// we tried - maybe it's different infra.
+		}
+		
+		if (filer != null) {
+			Set<File> sourcePath = new HashSet<File>();
+			Set<File> destinationPath = new HashSet<File>();
+			for (SourceFile sf : description.getSourceFiles()) {
+				sourcePath.add(sf.getSourceFolder());
+				destinationPath.add(sf.getDestinationFolder());
+			}
+			try {
+				filer.setLocation(StandardLocation.SOURCE_PATH, sourcePath);
+				filer.setLocation(StandardLocation.CLASS_OUTPUT, destinationPath);
+			} catch (IOException e) {
+				throw new BuildException("Can't set annotation processor filer paths", e);
+			}
+		}
+		
 		compiler.compile(sources);
 		CompileJobResultImpl result = new CompileJobResultImpl();
 		result.setSucceeded(requestor.isCompilationSuccessful());
@@ -351,6 +416,19 @@ public class EcjAdapter implements CompilerAdapter {
 		return result;
 	}
 	
+	private Main makeDummyMain() {
+		// Make a dummy 'Main', because the ecj code is hard-linked to it existing. This is all hackery to get around
+		// an utterly unusable API. This API has been replaced, but the replacement cannot process annotations,
+		// unless you rewrite a ton of infrastructure.
+		
+		PrintWriter outWriter = new PrintWriter(new OutputStream() {
+			@Override public void write(int b) throws IOException {
+				// just ignore it silently.
+			}
+		});
+		return new Main(outWriter, outWriter, false, new HashMap<String, String>(), null);
+	}
+	
 	private ICompilationUnit[] getCompilationUnits(SourceFile[] sourceFiles) {
 		List<ICompilationUnit> result = new ArrayList<ICompilationUnit>();
 		for (SourceFile sourceFile : sourceFiles) {
@@ -363,4 +441,9 @@ public class EcjAdapter implements CompilerAdapter {
 	public void setIncludeSystemBootclasspath(boolean includeSystemBootclasspath) {
 		this.includeSystemBootclasspath = includeSystemBootclasspath;
 	}
+	
+	public void setAnnotationProcessorEntries(Set<String> procClasses, Set<File> procJars) {
+		this.procClasses = procClasses;
+		this.procJars = procJars;
+	}
 }



View it on GitLab: https://salsa.debian.org/java-team/ivyplusplus/-/commit/99b40203da17c263e557cde1abee0da3e880ee54

-- 
View it on GitLab: https://salsa.debian.org/java-team/ivyplusplus/-/commit/99b40203da17c263e557cde1abee0da3e880ee54
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20220512/ddd61380/attachment.htm>


More information about the pkg-java-commits mailing list