diff --git a/AndroidAnnotations/androidannotations-api/pom.xml b/AndroidAnnotations/androidannotations-api/pom.xml index 7744a43615..d56464c833 100644 --- a/AndroidAnnotations/androidannotations-api/pom.xml +++ b/AndroidAnnotations/androidannotations-api/pom.xml @@ -43,6 +43,10 @@ 1.6 + + org.apache.maven.plugins + maven-resources-plugin + maven-javadoc-plugin @@ -66,6 +70,16 @@ + + + + src/main/resources + true + + **/*.properties + + + diff --git a/AndroidAnnotations/androidannotations/src/main/resources/androidannotations-version.properties b/AndroidAnnotations/androidannotations-api/src/main/resources/androidannotations-api.properties similarity index 100% rename from AndroidAnnotations/androidannotations/src/main/resources/androidannotations-version.properties rename to AndroidAnnotations/androidannotations-api/src/main/resources/androidannotations-api.properties diff --git a/AndroidAnnotations/androidannotations/.settings/org.eclipse.core.resources.prefs b/AndroidAnnotations/androidannotations/.settings/org.eclipse.core.resources.prefs index d25a71a2d6..02b3260d3f 100644 --- a/AndroidAnnotations/androidannotations/.settings/org.eclipse.core.resources.prefs +++ b/AndroidAnnotations/androidannotations/.settings/org.eclipse.core.resources.prefs @@ -2,7 +2,7 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/java/rebel.xml=UTF-8 encoding//src/main/resources=UTF-8 -encoding//src/main/resources/androidannotations-version.properties=utf-8 +encoding//src/main/resources/androidannotations.properties=utf-8 encoding//src/main/resources/rebel.xml=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 diff --git a/AndroidAnnotations/androidannotations/pom.xml b/AndroidAnnotations/androidannotations/pom.xml index c5b2d0aa85..36e030f5a1 100644 --- a/AndroidAnnotations/androidannotations/pom.xml +++ b/AndroidAnnotations/androidannotations/pom.xml @@ -80,10 +80,6 @@ org.apache.maven.plugins maven-resources-plugin - 2.5 - - ${project.build.sourceEncoding} - diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java index d80624f0bf..2b853c141c 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java @@ -21,10 +21,12 @@ import static org.androidannotations.helper.ModelConstants.TRACE_OPTION; import static org.androidannotations.rclass.ProjectRClassFinder.RESOURCE_PACKAGE_NAME_OPTION; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -124,6 +126,7 @@ import org.androidannotations.annotations.sharedpreferences.Pref; import org.androidannotations.annotations.sharedpreferences.SharedPref; import org.androidannotations.exception.ProcessingException; +import org.androidannotations.exception.VersionMismatchException; import org.androidannotations.generation.CodeModelGenerator; import org.androidannotations.helper.AndroidManifest; import org.androidannotations.helper.AndroidManifestFinder; @@ -285,6 +288,7 @@ public class AndroidAnnotationProcessor extends AbstractProcessor { private final Properties properties = new Properties(); + private final Properties propertiesApi = new Properties(); private final TimeStats timeStats = new TimeStats(); private final ErrorHelper errorHelper = new ErrorHelper(); @@ -296,18 +300,36 @@ public synchronized void init(ProcessingEnvironment processingEnv) { Messager messager = processingEnv.getMessager(); - loadPropertyFile(); + try { + loadPropertyFile(); + loadApiPropertyFile(); + } catch (Exception e) { + messager.printMessage(Diagnostic.Kind.ERROR, "AndroidAnnotations processing failed: " + e.getMessage()); + throw new RuntimeException("AndroidAnnotations processing failed", e); + } timeStats.setMessager(messager); messager.printMessage(Diagnostic.Kind.NOTE, "Starting AndroidAnnotations annotation processing"); + + } + + private void checkApiAndCoreVersions() throws VersionMismatchException { + String apiVersion = getAAApiVersion(); + String coreVersion = getAAProcessorVersion(); + + if (!apiVersion.equals(coreVersion)) { + throw new VersionMismatchException("AndroidAnnotation version for API (" + apiVersion + ") and core (" + coreVersion + " doesn't match. Please check your classpath)"); + } } @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { timeStats.clear(); timeStats.start("Whole Processing"); + try { + checkApiAndCoreVersions(); processThrowing(annotations, roundEnv); } catch (ProcessingException e) { handleException(annotations, roundEnv, e); @@ -319,16 +341,23 @@ public boolean process(Set annotations, RoundEnvironment return true; } - private void loadPropertyFile() { - String filename = "androidannotations-version.properties"; + private void loadPropertyFile() throws FileNotFoundException { + String filename = "androidannotations.properties"; try { URL url = getClass().getClassLoader().getResource(filename); properties.load(url.openStream()); } catch (Exception e) { - e.printStackTrace(); + throw new FileNotFoundException(filename + " couldn't be parsed."); + } + } - Messager messager = processingEnv.getMessager(); - messager.printMessage(Diagnostic.Kind.NOTE, "AndroidAnnotations processing failed because " + filename + " couldn't be parsed : " + e.getLocalizedMessage()); + private void loadApiPropertyFile() throws FileNotFoundException { + String filename = "androidannotations-api.properties"; + try { + URL url = getClass().getClassLoader().getResource(filename); + propertiesApi.load(url.openStream()); + } catch (Exception e) { + throw new FileNotFoundException(filename + " couldn't be parsed. Please check your classpath and verify that AA-API's version is at least 3.0"); } } @@ -336,6 +365,10 @@ private String getAAProcessorVersion() { return properties.getProperty("version", "3.0+"); } + private String getAAApiVersion() { + return propertiesApi.getProperty("version", null); + } + private void processThrowing(Set annotations, RoundEnvironment roundEnv) throws ProcessingException, Exception { if (nothingToDo(annotations, roundEnv)) { return; @@ -619,8 +652,16 @@ private void handleException(Set annotations, RoundEnviro * eclipse. */ - Element element = roundEnv.getElementsAnnotatedWith(annotations.iterator().next()).iterator().next(); - messager.printMessage(Diagnostic.Kind.ERROR, errorMessage, element); + Iterator iterator = annotations.iterator(); + if (iterator.hasNext()) { + Element element = roundEnv.getElementsAnnotatedWith(iterator.next()).iterator().next(); + messager.printMessage(Diagnostic.Kind.ERROR, errorMessage, element); + } else { + // Sometime this is a total mess and javac could not even find one + // element on which we could print the error. So we should just + // throw an exception and let it go. + throw new RuntimeException("An error occured and couldn't be printed on an element: " + errorMessage); + } } @Override diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/exception/VersionMismatchException.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/exception/VersionMismatchException.java new file mode 100644 index 0000000000..1c1b58e1cb --- /dev/null +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/exception/VersionMismatchException.java @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2010-2013 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.exception; + +public class VersionMismatchException extends Exception { + + private static final long serialVersionUID = 1457334941140141471L; + + public VersionMismatchException() { + super(); + } + + public VersionMismatchException(String message, Throwable cause) { + super(message, cause); + } + + public VersionMismatchException(String message) { + super(message); + } + + public VersionMismatchException(Throwable cause) { + super(cause); + } + +} diff --git a/AndroidAnnotations/androidannotations/src/main/resources/androidannotations.properties b/AndroidAnnotations/androidannotations/src/main/resources/androidannotations.properties new file mode 100644 index 0000000000..46d482f4cf --- /dev/null +++ b/AndroidAnnotations/androidannotations/src/main/resources/androidannotations.properties @@ -0,0 +1,17 @@ +# +# Copyright (C) 2010-2013 eBusiness Information, Excilys Group +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed To in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# + +version=${project.version} \ No newline at end of file diff --git a/AndroidAnnotations/pom.xml b/AndroidAnnotations/pom.xml index 8243af898b..7f18f73c38 100644 --- a/AndroidAnnotations/pom.xml +++ b/AndroidAnnotations/pom.xml @@ -1,6 +1,5 @@ - + 4.0.0 @@ -196,6 +195,14 @@ maven-compiler-plugin 2.3.2 + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + ${project.build.sourceEncoding} + + org.apache.maven.plugins maven-jar-plugin