JDK-5048535 : apt should revise discovery policy to query already loaded factories
Type:Bug
Component:tools
Sub-Component:apt
Affected Version:5.0
Priority:P3
Status:Resolved
Resolution:Fixed
OS:generic
CPU:generic
Submitted:2004-05-17
Updated:2017-05-16
Resolved:2004-06-25
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
apt might query a factory on one round but not that next. This complicates efforts to implement a callback or listener mechanism.
Comments
CONVERTED DATA
BugTraq+ Release Management Values
COMMIT TO FIX:
tiger-rc
FIXED IN:
tiger-rc
INTEGRATED IN:
tiger-b58
tiger-rc
21-07-2004
SUGGESTED FIX
src/share/classes/com/sun/mirror/apt>sccs sccsdiff -r1.7 -r1.8 AnnotationProcessorFactory.java
------- AnnotationProcessorFactory.java -------
68,69c68,69
< * Returns an annotation processor for a set of annotation types.
< * The set will be empty if the factory supports
---
> * Returns an annotation processor for a set of annotation
> * types. The set will be empty if the factory supports
71c71,78
< * no annotations.
---
> * no annotations. Note that the set of annotation types may be
> * empty for other reasons, such as giving the factory an
> * opportunity to register a listener. An
> * <tt>AnnotationProcessorFactory</tt> must gracefully handle an
> * empty set of annotations; an appropriate response to an empty
> * set will often be returning {@link
> * com.sun.mirror.AnnotationProcessors#NO_OP
> * AnnotationProcessors.NO_OP}.
src/share/classes/com/sun/mirror/apt>sccs sccsdiff -r1.1 -r1.2 AnnotationProcessors.java
------- AnnotationProcessors.java -------
71c71
< public final static AnnotationProcessor NoOpAnnotationProcessor = new NoOpAP();
---
> public final static AnnotationProcessor NO_OP = new NoOpAP();
src/share/classes/com/sun/mirror/util>sccs sccsdiff -r1.2 -r1.3 DeclarationVisitors.java
------- DeclarationVisitors.java -------
24c24
< public static final DeclarationVisitor NoOpDeclVisitor = new SimpleDeclarationVisitor();
---
> public static final DeclarationVisitor NO_OP = new SimpleDeclarationVisitor();
kalimantan:/local/ws/jdk/1.5/Apt-work/src/share/classes/com/sun/tools/apt/main>sccs sccsdiff -r1.12 -r1.13 Main.java
------- Main.java -------
38a39
> import com.sun.mirror.apt.AnnotationProcessorFactory;
52a54,56
> // Preserve parameter names from class files if the class was
> // compiled with debug enabled
> "-XDsave-parameter-names"
556c560
< /** List of top level names of generated source files.
---
> /** List of top level names of generated source files from most recent apt round.
560c564
< /** List of names of generated class files.
---
> /** List of names of generated class files from most recent apt round.
563a568,590
> /**
> * List of all the generated source file names across all apt rounds.
> */
> java.util.Set<String> aggregateGenSourceFileNames = new java.util.LinkedHashSet<String>();
>
> /**
> * List of all the generated class file names across all apt rounds.
> */
> java.util.Set<String> aggregateGenClassFileNames = new java.util.LinkedHashSet<String>();
>
> /**
> * List of all the generated file names across all apt rounds.
> */
> java.util.Set<java.io.File> aggregateGenFiles = new java.util.LinkedHashSet<java.io.File>();
>
> /**
> * Set of all factories that have provided a processor on some apt round.
> */
> java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories =
> new java.util.LinkedHashSet<Class<? extends AnnotationProcessorFactory> >();
>
>
>
637,639c664
< : (Source.JDK1_5);
< options.put("-source", source.name );
<
---
> : Source.DEFAULT;
643,645c668
< : Target.JDK1_5;
< options.put("-target", target.name );
<
---
> : Target.DEFAULT;
651,653c674,690
< if (Character.isDigit(target.toString().charAt(0)) &&
< target.compareTo(source.requiredTarget()) < 0)
< warning("warn.source.target.conflict", source, source.requiredTarget());
---
> if (Character.isDigit(target.name.charAt(0)) &&
> target.compareTo(source.requiredTarget()) < 0) {
> if (targetString != null) {
> if (sourceString == null) {
> warning("warn.target.default.source.conflict",
> targetString,
> source.requiredTarget().name);
> } else {
> warning("warn.source.target.conflict",
> sourceString,
> source.requiredTarget().name);
> }
> return null;
> } else {
> options.put("-target", source.requiredTarget().name);
> }
> }
661,668d697
< /*
< * Lists of all the generated source and class files
< * (respectively), across different runs of annotation
< * processors by apt.
< */
< java.util.Set<String> aggregateGenSourceFileNames = new java.util.LinkedHashSet<String>();
< java.util.Set<String> aggregateGenClassFileNames = new java.util.LinkedHashSet<String>();
<
731c760
< boolean firstRun = true;
---
> boolean firstRound = true;
738,739c767,768
< * If any of the prior apt runs generated any new source
< * files, the n'th apt run (and any javac invocation) has the
---
> * If any of the prior apt rounds generated any new source
> * files, the n'th apt round (and any javac invocation) has the
743,744c772,773
< * If any of the prior apt runs generated any new class files,
< * the n'th apt run (and any javac invocation) has the class
---
> * If any of the prior apt rounds generated any new class files,
> * the n'th apt round (and any javac invocation) has the class
842c871
< int run = 0; // For -XPrintAptRounds
---
> int round = 0; // For -XPrintAptRounds
844c873
< run++;
---
> round++;
853c882
< if (genSourceFileNames.size() > 0 && !firstRun) {
---
> if (genSourceFileNames.size() > 0 && !firstRound) {
873c902
< out.println("apt Run : " + run);
---
> out.println("apt Round : " + round);
879c908
< firstRun = false;
---
> firstRound = false;
901,902c930
< aggregateGenSourceFileNames.size() +
< 2; // source and target
---
> aggregateGenSourceFileNames.size();
958,961d985
< newArgs[j++] = "-XD-source=" + options.get("-source");
<
< newArgs[j++] = "-XD-target=" + options.get("-target");
<
995c1019,1021
< aptCL);
---
> aptCL,
> productiveFactories,
> aggregateGenFiles);
src/share/classes/com/sun/tools/apt/main>sccs sccsdiff -r1.7 -r1.8 JavaCompiler.java
------- JavaCompiler.java -------
27a28
> import com.sun.mirror.apt.AnnotationProcessorFactory;
69a71
> java.util.Set<java.io.File> aggregateGenFiles = java.util.Collections.emptySet();
70a73,75
> public java.util.Set<java.io.File> getAggregateGenFiles() {
> return aggregateGenFiles;
> }
75a81,84
> /** The log to be used for error reporting.
> */
> Log log;
>
147a157
> log = Log.instance(context);
293c303,304
< Name prev = bark.useSource(names.fromString(filename));
---
> Name prev1 = log.useSource(names.fromString(filename));
> Name prev2 = bark.useSource(names.fromString(filename));
313c324,325
< bark.useSource(prev);
---
> bark.useSource(prev2);
> log.useSource(prev1);
402c414,417
< ClassLoader aptCL) throws Throwable {
---
> ClassLoader aptCL,
> java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories,
> java.util.Set<java.io.File> aggregateGenFiles)
> throws Throwable {
407a423,424
> this.aggregateGenFiles = aggregateGenFiles;
>
423c440,441
< apt.main(roots, origOptions, aptCL);
---
> apt.main(roots, origOptions, aptCL,
> productiveFactories);
504a523
> log.flush();
src/share/classes/com/sun/tools/apt/comp>sccs sccsdiff -r1.13 -r1.14 Apt.java
------- Apt.java -------
10d9
<
19a19
> import java.util.regex.*;
20a21,22
> import java.lang.reflect.InvocationTargetException;
> import java.io.IOException;
31d32
< //import com.sun.mirror.util.*;
34,35d34
<
<
39,40d37
< import java.lang.reflect.InvocationTargetException;
< import java.io.IOException;
42,43d38
< import java.util.regex.*;
<
172c167,168
< ClassLoader aptCL) {
---
> ClassLoader aptCL,
> java.util.Set<Class<? extends AnnotationProcessorFactory> > productiveFactories) {
189a186,188
> Set<AnnotationTypeDeclaration> emptyATDS = Collections.emptySet();
> Set<Class<? extends AnnotationProcessorFactory> > currentRoundFactories =
> new LinkedHashSet<Class<? extends AnnotationProcessorFactory> >();
253c252
< } else {
---
> } else
255d253
< }
261c259
< if (!providers.hasNext()) {
---
> if (!providers.hasNext() && productiveFactories.size() == 0) {
310,311c308,309
< // convert annotation names to
< // annotation type decls
---
> // convert annotation names to annotation
> // type decls
315,316c313,314
< // empty string, pass in an empty set
< // of annotation type declarations.
---
> // empty string, pass in an empty set of
> // annotation type declarations.
334c332,334
<
---
>
> currentRoundFactories.add(apf.getClass());
> productiveFactories.add(apf.getClass());
335a336,342
> } else if (productiveFactories.contains(apf.getClass())) {
> // If a factory provided a processor in a
> // previous round but doesn't match any
> // annotations this round, call it with an
> // empty set of declarations.
> currentRoundFactories.add(apf.getClass());
> factoryToAnnotation.put(apf, emptyATDS );
348a356,373
> // If the set difference of productiveFactories and
> // currentRoundFactories is non-empty, call the remaining
> // productive factories with an empty set of declarations.
> {
> java.util.Set<Class<? extends AnnotationProcessorFactory> > neglectedFactories =
> new LinkedHashSet<Class<? extends AnnotationProcessorFactory>>(productiveFactories);
> neglectedFactories.removeAll(currentRoundFactories);
> for(Class<? extends AnnotationProcessorFactory> working : neglectedFactories) {
> try {
> AnnotationProcessorFactory factory = working.newInstance();
> factoryToAnnotation.put(factory, emptyATDS);
> } catch (Exception e ) {
> bark.warning(Position.NOPOS, "FactoryCantInstantiate", working.getName());
> }
>
> }
> }
>
src/share/classes/com/sun/tools/apt/mirror/apt> sccs sccsdiff -r1.8 -r1.9 AnnotationProcessorEnvironmentImpl.java
------- AnnotationProcessorEnvironmentImpl.java -------
124c124
< NoOpDeclVisitor));
---
> NO_OP));
src/share/classes/com/sun/tools/apt/mirror/apt>sccs sccsdiff -r1.4 -r1.5 FilerImpl.java
------- FilerImpl.java -------
34a35
> private final com.sun.tools.apt.main.JavaCompiler comp;
52a54,56
> // All created files.
> private final Set<File> filesCreated;
>
74a79
> comp = com.sun.tools.apt.main.JavaCompiler.instance(context);
75a81,82
> this.filesCreated = comp.getAggregateGenFiles();
>
98a106
> PrintWriter pw = getPrintWriter(file, encoding);
100c108
< return getPrintWriter(file, encoding);
---
> return pw;
107a116
> OutputStream os = getOutputStream(CLASS_TREE, pathname);
109c118
< return getOutputStream(CLASS_TREE, pathname);
---
> return os;
196,197d204
< // The newly created files.
< private final HashSet<File> filesCreated = new HashSet<File>();
###@###.### 2004-06-21
21-06-2004
EVALUATION
Should be fixed.
###@###.### 2004-05-17