Skip to content

Commit c4bc399

Browse files
committed
Add a check on API and core versions
1 parent 9dcfe8d commit c4bc399

8 files changed

Lines changed: 115 additions & 13 deletions

File tree

‎AndroidAnnotations/androidannotations-api/pom.xml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
<target>1.6</target>
4444
</configuration>
4545
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-resources-plugin</artifactId>
49+
</plugin>
4650
<plugin>
4751
<artifactId>maven-javadoc-plugin</artifactId>
4852
<executions>
@@ -66,6 +70,16 @@
6670
</executions>
6771
</plugin>
6872
</plugins>
73+
74+
<resources>
75+
<resource>
76+
<directory>src/main/resources</directory>
77+
<filtering>true</filtering>
78+
<includes>
79+
<include>**/*.properties</include>
80+
</includes>
81+
</resource>
82+
</resources>
6983
</build>
7084

7185
</project>

AndroidAnnotations/androidannotations/src/main/resources/androidannotations-version.properties renamed to AndroidAnnotations/androidannotations-api/src/main/resources/androidannotations-api.properties

File renamed without changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +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
5+
encoding//src/main/resources/androidannotations.properties=utf-8
66
encoding//src/main/resources/rebel.xml=UTF-8
77
encoding//src/test/java=UTF-8
88
encoding//src/test/resources=UTF-8

‎AndroidAnnotations/androidannotations/pom.xml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@
8080
<plugin>
8181
<groupId>org.apache.maven.plugins</groupId>
8282
<artifactId>maven-resources-plugin</artifactId>
83-
<version>2.5</version>
84-
<configuration>
85-
<encoding>${project.build.sourceEncoding}</encoding>
86-
</configuration>
8783
</plugin>
8884
</plugins>
8985

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.androidannotations.helper.ModelConstants.TRACE_OPTION;
2222
import static org.androidannotations.rclass.ProjectRClassFinder.RESOURCE_PACKAGE_NAME_OPTION;
2323

24+
import java.io.FileNotFoundException;
2425
import java.io.IOException;
2526
import java.net.URL;
2627
import java.util.Collections;
@@ -124,6 +125,7 @@
124125
import org.androidannotations.annotations.sharedpreferences.Pref;
125126
import org.androidannotations.annotations.sharedpreferences.SharedPref;
126127
import org.androidannotations.exception.ProcessingException;
128+
import org.androidannotations.exception.VersionMismatchException;
127129
import org.androidannotations.generation.CodeModelGenerator;
128130
import org.androidannotations.helper.AndroidManifest;
129131
import org.androidannotations.helper.AndroidManifestFinder;
@@ -285,6 +287,7 @@
285287
public class AndroidAnnotationProcessor extends AbstractProcessor {
286288

287289
private final Properties properties = new Properties();
290+
private final Properties propertiesApi = new Properties();
288291
private final TimeStats timeStats = new TimeStats();
289292
private final ErrorHelper errorHelper = new ErrorHelper();
290293

@@ -296,11 +299,27 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
296299

297300
Messager messager = processingEnv.getMessager();
298301

299-
loadPropertyFile();
302+
try {
303+
loadPropertyFile();
304+
loadApiPropertyFile();
305+
checkApiAndCoreVersions();
306+
} catch (Exception e) {
307+
messager.printMessage(Diagnostic.Kind.ERROR, "AndroidAnnotations processing failed: " + e.getMessage());
308+
}
300309

301310
timeStats.setMessager(messager);
302311

303312
messager.printMessage(Diagnostic.Kind.NOTE, "Starting AndroidAnnotations annotation processing");
313+
314+
}
315+
316+
private void checkApiAndCoreVersions() throws VersionMismatchException {
317+
String apiVersion = getAAApiVersion();
318+
String coreVersion = getAAProcessorVersion();
319+
320+
if (!apiVersion.equals(coreVersion)) {
321+
throw new VersionMismatchException("AndroidAnnotation version for API (" + apiVersion + ") and core (" + coreVersion + " doesn't match. Please check your classpath)");
322+
}
304323
}
305324

306325
@Override
@@ -319,23 +338,34 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
319338
return true;
320339
}
321340

322-
private void loadPropertyFile() {
323-
String filename = "androidannotations-version.properties";
341+
private void loadPropertyFile() throws FileNotFoundException {
342+
String filename = "androidannotations.properties";
324343
try {
325344
URL url = getClass().getClassLoader().getResource(filename);
326345
properties.load(url.openStream());
327346
} catch (Exception e) {
328-
e.printStackTrace();
347+
throw new FileNotFoundException(filename + " couldn't be parsed");
348+
}
349+
}
329350

330-
Messager messager = processingEnv.getMessager();
331-
messager.printMessage(Diagnostic.Kind.NOTE, "AndroidAnnotations processing failed because " + filename + " couldn't be parsed : " + e.getLocalizedMessage());
351+
private void loadApiPropertyFile() throws FileNotFoundException {
352+
String filename = "androidannotations-api.properties";
353+
try {
354+
URL url = getClass().getClassLoader().getResource(filename);
355+
propertiesApi.load(url.openStream());
356+
} catch (Exception e) {
357+
throw new FileNotFoundException(filename + " couldn't be parsed");
332358
}
333359
}
334360

335361
private String getAAProcessorVersion() {
336362
return properties.getProperty("version", "3.0+");
337363
}
338364

365+
private String getAAApiVersion() {
366+
return propertiesApi.getProperty("version", null);
367+
}
368+
339369
private void processThrowing(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws ProcessingException, Exception {
340370
if (nothingToDo(annotations, roundEnv)) {
341371
return;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.exception;
17+
18+
public class VersionMismatchException extends Exception {
19+
20+
private static final long serialVersionUID = 1457334941140141471L;
21+
22+
public VersionMismatchException() {
23+
super();
24+
}
25+
26+
public VersionMismatchException(String message, Throwable cause) {
27+
super(message, cause);
28+
}
29+
30+
public VersionMismatchException(String message) {
31+
super(message);
32+
}
33+
34+
public VersionMismatchException(Throwable cause) {
35+
super(cause);
36+
}
37+
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (C) 2010-2013 eBusiness Information, Excilys Group
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
# use this file except in compliance with the License. You may obtain a copy of
6+
# the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed To in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
17+
version=${project.version}

‎AndroidAnnotations/pom.xml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
43
<modelVersion>4.0.0</modelVersion>
54

65
<parent>
@@ -196,6 +195,14 @@
196195
<artifactId>maven-compiler-plugin</artifactId>
197196
<version>2.3.2</version>
198197
</plugin>
198+
<plugin>
199+
<groupId>org.apache.maven.plugins</groupId>
200+
<artifactId>maven-resources-plugin</artifactId>
201+
<version>2.5</version>
202+
<configuration>
203+
<encoding>${project.build.sourceEncoding}</encoding>
204+
</configuration>
205+
</plugin>
199206
<plugin>
200207
<groupId>org.apache.maven.plugins</groupId>
201208
<artifactId>maven-jar-plugin</artifactId>

0 commit comments

Comments
 (0)