Skip to content

Commit 511119d

Browse files
committed
Uses a property instead of a constant for AA processor version
1 parent 918e869 commit 511119d

5 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎AndroidAnnotations/androidannotations/.settings/org.eclipse.core.resources.prefs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ eclipse.preferences.version=1
22
encoding//src/main/java=UTF-8
33
encoding//src/main/java/rebel.xml=UTF-8
44
encoding//src/main/resources=UTF-8
5+
encoding//src/main/resources/androidannotations-version.properties=utf-8
56
encoding//src/main/resources/rebel.xml=UTF-8
67
encoding//src/test/java=UTF-8
78
encoding//src/test/resources=UTF-8

‎AndroidAnnotations/androidannotations/pom.xml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@
7777
</execution>
7878
</executions>
7979
</plugin>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-resources-plugin</artifactId>
83+
<version>2.5</version>
84+
<configuration>
85+
<encoding>${project.build.sourceEncoding}</encoding>
86+
</configuration>
87+
</plugin>
8088
</plugins>
89+
8190
<resources>
8291
<resource>
8392
<directory>src/main/resources</directory>
@@ -88,7 +97,14 @@
8897
<resource>
8998
<directory>src/main/java</directory>
9099
<includes>
91-
<include>org/androidannotations/api/**</include>
100+
<include>org/androidannotations/api/**</include>
101+
</includes>
102+
</resource>
103+
<resource>
104+
<directory>src/main/resources</directory>
105+
<filtering>true</filtering>
106+
<includes>
107+
<include>**/*.properties</include>
92108
</includes>
93109
</resource>
94110
</resources>

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
import static org.androidannotations.helper.ModelConstants.TRACE_OPTION;
2222

2323
import java.io.IOException;
24+
import java.net.URL;
2425
import java.util.Collections;
2526
import java.util.HashSet;
2627
import java.util.Map;
28+
import java.util.Properties;
2729
import java.util.Set;
2830

2931
import javax.annotation.processing.AbstractProcessor;
@@ -270,9 +272,7 @@
270272
@SupportedOptions({ TRACE_OPTION, ANDROID_MANIFEST_FILE_OPTION })
271273
public class AndroidAnnotationProcessor extends AbstractProcessor {
272274

273-
// TODO: We whould find a better way
274-
public static final String ANDROIDANNOTATION_VERSION = "3.0-SNAPSHOT";
275-
275+
private final Properties properties = new Properties();
276276
private final TimeStats timeStats = new TimeStats();
277277
private final ErrorHelper errorHelper = new ErrorHelper();
278278

@@ -284,6 +284,8 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
284284

285285
Messager messager = processingEnv.getMessager();
286286

287+
loadPropertyFile();
288+
287289
timeStats.setMessager(messager);
288290

289291
messager.printMessage(Diagnostic.Kind.NOTE, "Starting AndroidAnnotations annotation processing");
@@ -305,6 +307,23 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
305307
return true;
306308
}
307309

310+
private void loadPropertyFile() {
311+
String filename = "androidannotations-version.properties";
312+
try {
313+
URL url = getClass().getClassLoader().getResource(filename);
314+
properties.load(url.openStream());
315+
} catch (Exception e) {
316+
e.printStackTrace();
317+
318+
Messager messager = processingEnv.getMessager();
319+
messager.printMessage(Diagnostic.Kind.NOTE, "AndroidAnnotations processing failed because " + filename + " couldn't be parsed : " + e.getLocalizedMessage());
320+
}
321+
}
322+
323+
private String getAAProcessorVersion() {
324+
return properties.getProperty("version", "3.0+");
325+
}
326+
308327
private void processThrowing(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws ProcessingException, Exception {
309328
if (nothingToDo(annotations, roundEnv)) {
310329
return;
@@ -571,7 +590,7 @@ private void generateSources(ProcessResult processResult) throws IOException {
571590
}
572591

573592
private void handleException(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv, ProcessingException e) {
574-
String errorMessage = errorHelper.getErrorMessage(processingEnv, e);
593+
String errorMessage = errorHelper.getErrorMessage(processingEnv, e, getAAProcessorVersion());
575594

576595
Messager messager = processingEnv.getMessager();
577596
messager.printMessage(Diagnostic.Kind.ERROR, errorMessage);

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/ErrorHelper.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
import javax.lang.model.element.Element;
1212
import javax.lang.model.util.Elements;
1313

14-
import org.androidannotations.AndroidAnnotationProcessor;
1514
import org.androidannotations.exception.ProcessingException;
1615

1716
public class ErrorHelper {
1817

19-
public String getErrorMessage(ProcessingEnvironment processingEnv, ProcessingException e) {
20-
String errorMessage = "Unexpected error. Please report an issue on AndroidAnnotations " + AndroidAnnotationProcessor.ANDROIDANNOTATION_VERSION + ", with the following content and tell us if you can reproduce it or not. The error was thrown on:\n";
18+
public String getErrorMessage(ProcessingEnvironment processingEnv, ProcessingException e, String aaVersion) {
19+
String errorMessage = "Unexpected error. Please report an issue on AndroidAnnotations " + aaVersion + ", with the following content and tell us if you can reproduce it or not. The error was thrown on:\n";
2120
if (e.getElement() != null) {
2221
errorMessage += elementFullString(processingEnv, e.getElement()) + "\n";
2322
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=${project.version}

0 commit comments

Comments
 (0)