Remove explicit dependencies from netui-compiler, modify ConvertAnnotationProcessorFactory to not crash when internal is null, such as when a class isn't on the classpath

This commit is contained in:
moparisthebest 2014-04-21 10:36:43 -04:00
parent 7a02261fc5
commit fe5d6e8469
2 changed files with 14 additions and 21 deletions

View File

@ -81,16 +81,15 @@ public class ConvertAnnotationProcessorFactory implements Processor {
internal = (AnnotationProcessorFactory) Class.forName(annotationProcessorFactoryName).newInstance(); internal = (AnnotationProcessorFactory) Class.forName(annotationProcessorFactoryName).newInstance();
System.out.println("ConvertAnnotationProcessorFactory running " + internal.getClass().getName()); System.out.println("ConvertAnnotationProcessorFactory running " + internal.getClass().getName());
} catch (Throwable e) { } catch (Throwable e) {
System.out.printf("Not running AnnotationProcessorFactory '%s' because of error!\n", annotationProcessorFactoryName); System.out.printf("Not running AnnotationProcessorFactory '%s' because of error! Not on classpath?\n", annotationProcessorFactoryName);
if(Debug.debug)
e.printStackTrace(); e.printStackTrace();
} }
this.internal = internal; this.internal = internal;
} }
public ConvertAnnotationProcessorFactory(AnnotationProcessorFactory internal) { public ConvertAnnotationProcessorFactory(AnnotationProcessorFactory internal) {
if (internal == null) System.out.println("ConvertAnnotationProcessorFactory running " + (internal == null ? "null" : internal.getClass().getName()));
throw new NullPointerException("AnnotationProcessorFactory cannot be null!");
System.out.println("ConvertAnnotationProcessorFactory running " + internal.getClass().getName());
this.internal = internal; this.internal = internal;
} }
@ -105,11 +104,15 @@ public class ConvertAnnotationProcessorFactory implements Processor {
@Override @Override
public Set<String> getSupportedOptions() { public Set<String> getSupportedOptions() {
if(internal == null)
return Collections.emptySet();
return cleanOptions(internal.supportedOptions()); return cleanOptions(internal.supportedOptions());
} }
@Override @Override
public Set<String> getSupportedAnnotationTypes() { public Set<String> getSupportedAnnotationTypes() {
if(internal == null)
return Collections.emptySet();
if (Debug.debug) if (Debug.debug)
System.out.printf("factory: '%s' supportedAnnotationTypes: '%s'\n", internal.getClass().getName(), internal.supportedAnnotationTypes()); System.out.printf("factory: '%s' supportedAnnotationTypes: '%s'\n", internal.getClass().getName(), internal.supportedAnnotationTypes());
return Convertable.toSet(internal.supportedAnnotationTypes()); return Convertable.toSet(internal.supportedAnnotationTypes());
@ -173,6 +176,8 @@ public class ConvertAnnotationProcessorFactory implements Processor {
*/ */
@Override @Override
public synchronized boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public synchronized boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if(internal == null)
return false;
env.getFiler().setModified(false); env.getFiler().setModified(false);
env.setRoundEnv(roundEnv); env.setRoundEnv(roundEnv);
internal.getProcessorFor(ConvertDeclaration.getConvertable().convertToSet(annotations, AnnotationTypeDeclaration.class), env).process(); internal.getProcessorFor(ConvertDeclaration.getConvertable().convertToSet(annotations, AnnotationTypeDeclaration.class), env).process();
@ -194,21 +199,21 @@ public class ConvertAnnotationProcessorFactory implements Processor {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o instanceof AnnotationProcessorFactory) return internal.equals(o); if (o instanceof AnnotationProcessorFactory) return o.equals(internal);
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ConvertAnnotationProcessorFactory that = (ConvertAnnotationProcessorFactory) o; ConvertAnnotationProcessorFactory that = (ConvertAnnotationProcessorFactory) o;
return internal.equals(that.internal); return internal == that.internal || (internal != null && internal.equals(that.internal));
} }
@Override @Override
public int hashCode() { public int hashCode() {
return internal.hashCode(); return internal == null ? 0 : internal.hashCode();
} }
@Override @Override
public String toString() { public String toString() {
return internal.toString(); return internal == null ? "null" : internal.toString();
} }
} }

View File

@ -34,18 +34,6 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.beehive</groupId>
<artifactId>beehive-controls</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.beehive</groupId>
<artifactId>beehive-netui-compiler</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>