Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adjust logs
  • Loading branch information
DayS committed Dec 8, 2013
commit ed00b2eb4bda092ca3a929ff12a28b462c4fd735
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ private void checkApiAndCoreVersions() throws VersionMismatchException {
String coreVersion = getAAProcessorVersion();

if (!apiVersion.equals(coreVersion)) {
LOGGER.error("AndroidAnnotation version for API ({}) and core ({}) doesn't match. Please check your classpath", apiVersion, coreVersion);
throw new VersionMismatchException("AndroidAnnotation version for API (" + apiVersion + ") and core (" + coreVersion + ") doesn't match. Please check your classpath");
}
}
Expand Down Expand Up @@ -359,7 +360,8 @@ private void loadPropertyFile() throws FileNotFoundException {
URL url = getClass().getClassLoader().getResource(filename);
properties.load(url.openStream());
} catch (Exception e) {
throw new FileNotFoundException(filename + " couldn't be parsed.");
LOGGER.error("Core property file {} couldn't be parse");
throw new FileNotFoundException("Core property file " + filename + " couldn't be parsed.");
}
}

Expand All @@ -369,7 +371,8 @@ private void loadApiPropertyFile() throws FileNotFoundException {
URL url = EActivity.class.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");
LOGGER.error("API property file {} couldn't be parse");
throw new FileNotFoundException("API property file " + filename + " couldn't be parsed. Please check your classpath and verify that AA-API's version is at least 3.0");
}
}

Expand All @@ -389,27 +392,23 @@ private void processThrowing(Set<? extends TypeElement> annotations, RoundEnviro
AnnotationElementsHolder extractedModel = extractAnnotations(annotations, roundEnv);

Option<AndroidManifest> androidManifestOption = extractAndroidManifest();

if (androidManifestOption.isAbsent()) {
return;
}

AndroidManifest androidManifest = androidManifestOption.get();

Option<IRClass> rClassOption = findRClasses(androidManifest);
LOGGER.info("AndroidManifest.xml found: {}", androidManifest);

Option<IRClass> rClassOption = findRClasses(androidManifest);
if (rClassOption.isAbsent()) {
return;
}

IRClass rClass = rClassOption.get();

AndroidSystemServices androidSystemServices = new AndroidSystemServices();

AnnotationElements validatedModel = validateAnnotations(extractedModel, rClass, androidSystemServices, androidManifest);

ProcessResult processResult = processAnnotations(validatedModel, rClass, androidSystemServices, androidManifest);

generateSources(processResult);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import javax.lang.model.element.Element;
import javax.tools.JavaFileObject;

import org.androidannotations.logger.Logger;
import org.androidannotations.logger.LoggerFactory;
import org.androidannotations.processing.OriginatingElements;

public class ApiCodeGenerator {

private static final Logger LOGGER = LoggerFactory.getLogger(ApiCodeGenerator.class);
private static final byte[] BUFFER = new byte[4096];

private static void copyStream(InputStream input, OutputStream output) throws IOException {
Expand All @@ -46,6 +49,8 @@ public ApiCodeGenerator(Filer filer) {

public void writeApiClasses(Set<Class<?>> apiClassesToGenerate, OriginatingElements originatingElements) {

LOGGER.info("Writting following API classes in project: {}", apiClassesToGenerate);

for (Class<?> apiClassToGenerate : apiClassesToGenerate) {

String canonicalApiClassName = apiClassToGenerate.getCanonicalName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SourceCodewriter(Filer filer, OriginatingElements originatingElements) {
@Override
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
String qualifiedClassName = toQualifiedClassName(pkg, fileName);
LOGGER.info("Generating source file: {}", qualifiedClassName);
LOGGER.debug("Generating class: {}", qualifiedClassName);

Element[] classOriginatingElements = originatingElements.getClassOriginatingElements(qualifiedClassName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class AndroidManifest {
private final int maxSdkVersion;
private final int targetSdkVersion;

@Override
public String toString() {
return "AndroidManifest [applicationPackage=" + applicationPackage + ", componentQualifiedNames=" + componentQualifiedNames + ", permissionQualifiedNames=" + permissionQualifiedNames + ", applicationClassName=" + applicationClassName + ", libraryProject=" + libraryProject + ", debugabble=" + debugabble + ", minSdkVersion=" + minSdkVersion + ", maxSdkVersion=" + maxSdkVersion + ", targetSdkVersion=" + targetSdkVersion + "]";
}

public static AndroidManifest createManifest(String applicationPackage, String applicationClassName, List<String> componentQualifiedNames, List<String> permissionQualifiedNames, int minSdkVersion, int maxSdkVersion, int targetSdkVersion, boolean debugabble) {
return new AndroidManifest(false, applicationPackage, applicationClassName, componentQualifiedNames, permissionQualifiedNames, minSdkVersion, maxSdkVersion, targetSdkVersion, debugabble);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Option<AndroidManifest> extractAndroidManifest() {
String androidLibraryProperty = properties.getProperty("android.library");
libraryProject = androidLibraryProperty.equals("true");

LOGGER.info("Found android.library property in project.properties, value: {}", libraryProject);
LOGGER.debug("Found android.library={} property in project.properties", libraryProject);
}
} catch (IOException ignored) {
}
Expand All @@ -95,7 +95,7 @@ private Option<File> findManifestInSpecifiedPath() {
LOGGER.error("Could not find the AndroidManifest.xml file in specified path : {}", path);
return Option.absent();
} else {
LOGGER.info("AndroidManifest.xml file found: {}", androidManifestFile.toString());
LOGGER.debug("AndroidManifest.xml file found with specified path: {}", androidManifestFile.toString());
}
return Option.of(androidManifestFile);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ private Option<File> findManifestInParentsDirectories() {
LOGGER.error("Could not find the AndroidManifest.xml file, going up from path [{}] found using dummy file [] (max atempts: {})", projectRootHolder.sourcesGenerationFolder.getAbsolutePath(), projectRootHolder.dummySourceFilePath, MAX_PARENTS_FROM_SOURCE_FOLDER);
return Option.absent();
} else {
LOGGER.info("AndroidManifest.xml file found: {}", androidManifestFile.toString());
LOGGER.debug("AndroidManifest.xml file found in parent folder {}: {}", projectRoot.getAbsolutePath(), androidManifestFile.toString());
}

return Option.of(androidManifestFile);
Expand Down Expand Up @@ -185,7 +185,7 @@ private Option<AndroidManifest> parse(File androidManifestFile, boolean libraryP

if (applicationClassQualifiedName == null) {
if (nameAttribute != null) {
LOGGER.info("The class application declared in the AndroidManifest.xml cannot be found in the compile path: [{}]", nameAttribute.getNodeValue());
LOGGER.warn("The class application declared in the AndroidManifest.xml cannot be found in the compile path: [{}]", nameAttribute.getNodeValue());
}
}

Expand Down Expand Up @@ -249,9 +249,9 @@ private List<String> extractComponentNames(String applicationPackage, NodeList c
componentQualifiedNames.add(qualifiedName);
} else {
if (nameAttribute != null) {
LOGGER.info("A class activity declared in the AndroidManifest.xml cannot be found in the compile path: [{}]", nameAttribute.getNodeValue());
LOGGER.warn("A class activity declared in the AndroidManifest.xml cannot be found in the compile path: [{}]", nameAttribute.getNodeValue());
} else {
LOGGER.info("The {} activity node in the AndroidManifest.xml has no android:name attribute", i);
LOGGER.warn("The {} activity node in the AndroidManifest.xml has no android:name attribute", i);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
import javax.lang.model.element.TypeElement;

import org.androidannotations.exception.ProcessingException;
import org.androidannotations.logger.Logger;
import org.androidannotations.logger.LoggerFactory;
import org.androidannotations.model.AnnotationElements;
import org.androidannotations.model.AnnotationElements.AnnotatedAndRootElements;

import com.sun.codemodel.JCodeModel;

public class ModelProcessor {

private static final Logger LOGGER = LoggerFactory.getLogger(ModelProcessor.class);

public static class ProcessResult {

public final JCodeModel codeModel;
Expand Down Expand Up @@ -61,14 +65,19 @@ public void register(GeneratingElementProcessor processor) {
}

public ProcessResult process(AnnotationElements validatedModel) throws ProcessingException, Exception {

JCodeModel codeModel = new JCodeModel();

EBeansHolder eBeansHolder = new EBeansHolder(codeModel);

LOGGER.info("Processing root elements");

for (GeneratingElementProcessor processor : typeProcessors) {
String annotationName = processor.getTarget();
Set<? extends Element> annotatedElements = validatedModel.getRootAnnotatedElements(annotationName);

if (!annotatedElements.isEmpty()) {
LOGGER.debug("Processing root elements with {}: {}", processor.getClass().getSimpleName(), annotatedElements);
}

for (Element annotatedElement : annotatedElements) {
/*
* We do not generate code for abstract classes, because the
Expand All @@ -77,6 +86,8 @@ public ProcessResult process(AnnotationElements validatedModel) throws Processin
*/
if (!isAbstractClass(annotatedElement)) {
processThrowing(processor, annotatedElement, codeModel, eBeansHolder);
} else {
LOGGER.trace("Skip element {} because it's abstract", annotatedElement);
}
}
/*
Expand All @@ -85,6 +96,8 @@ public ProcessResult process(AnnotationElements validatedModel) throws Processin
*/
}

LOGGER.info("Processing enclosed elements");

for (DecoratingElementProcessor processor : enclosedProcessors) {
String annotationName = processor.getTarget();

Expand All @@ -93,6 +106,11 @@ public ProcessResult process(AnnotationElements validatedModel) throws Processin
* but uses the holder for the root element
*/
Set<AnnotatedAndRootElements> ancestorAnnotatedElements = validatedModel.getAncestorAnnotatedElements(annotationName);

if (!ancestorAnnotatedElements.isEmpty()) {
LOGGER.debug("Processing enclosed elements with {}: {}", processor.getClass().getSimpleName(), ancestorAnnotatedElements);
}

for (AnnotatedAndRootElements elements : ancestorAnnotatedElements) {
EBeanHolder holder = eBeansHolder.getEBeanHolder(elements.rootTypeElement);
/*
Expand Down Expand Up @@ -122,6 +140,8 @@ public ProcessResult process(AnnotationElements validatedModel) throws Processin
if (!isAbstractClass(enclosingElement)) {
EBeanHolder holder = eBeansHolder.getEBeanHolder(enclosingElement);
processThrowing(processor, annotatedElement, codeModel, holder);
} else {
LOGGER.trace("Skip element {} because enclosing element {} is abstract", annotatedElement, enclosingElement);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public Option<IRClass> find() {
LOGGER.error("The android.R class cannot be found");
return Option.absent();
}

LOGGER.info("Found Android class: {}", androidRType.toString());

return Option.<IRClass> of(new RClass(androidRType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public ProjectRClassFinder(ProcessingEnvironment processingEnv) {
}

public Option<IRClass> find(AndroidManifest manifest) {

Elements elementUtils = processingEnv.getElementUtils();
String rClass = getRClassPackageName(manifest) + ".R";
TypeElement rType = elementUtils.getTypeElement(rClass);
Expand All @@ -46,6 +45,8 @@ public Option<IRClass> find(AndroidManifest manifest) {
return Option.absent();
}

LOGGER.info("Found project R class: {}", rType.toString());

return Option.<IRClass> of(new RClass(rType));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
import javax.lang.model.element.Element;

import org.androidannotations.exception.ProcessingException;
import org.androidannotations.logger.Logger;
import org.androidannotations.logger.LoggerFactory;
import org.androidannotations.model.AnnotationElements;
import org.androidannotations.model.AnnotationElementsHolder;

public class ModelValidator {

private static final Logger LOGGER = LoggerFactory.getLogger(ModelValidator.class);

private List<ElementValidator> validators = new ArrayList<ElementValidator>();

public void register(ElementValidator validator) {
Expand All @@ -36,6 +40,8 @@ public void register(ElementValidator validator) {

public AnnotationElements validate(AnnotationElementsHolder extractedModel) throws ProcessingException, Exception {

LOGGER.info("Validating elements");

/*
* We currently do not validate the elements on the ancestors, assuming
* they've already been validated. This also means some checks such as
Expand All @@ -44,6 +50,8 @@ public AnnotationElements validate(AnnotationElementsHolder extractedModel) thro
AnnotationElementsHolder validatedElements = extractedModel.validatingHolder();

for (ElementValidator validator : validators) {
String validatorSimpleName = validator.getClass().getSimpleName();

String annotationName = validator.getTarget();

Set<? extends Element> annotatedElements = extractedModel.getRootAnnotatedElements(annotationName);
Expand All @@ -52,12 +60,19 @@ public AnnotationElements validate(AnnotationElementsHolder extractedModel) thro

validatedElements.putRootAnnotatedElements(annotationName, validatedAnnotatedElements);

if (!annotatedElements.isEmpty()) {
LOGGER.debug("Validating with {}: {}", validatorSimpleName, annotatedElements);
}

for (Element annotatedElement : annotatedElements) {
if (validateThrowing(validator, annotatedElement, validatedElements)) {
validatedAnnotatedElements.add(annotatedElement);
} else {
LOGGER.warn("Element {} unvalidated by {}", annotatedElement, validatorSimpleName);
}
}
}

return validatedElements;
}

Expand Down