Skip to content

Commit

Permalink
Added manifest processing options to log or turn off manifest generat…
Browse files Browse the repository at this point in the history
…ion output.
  • Loading branch information
johncarl81 committed Feb 1, 2014
1 parent 182ff1b commit 113428c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/gradle/GradleTransfuse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
buildToolsVersion '19.0.0'

defaultConfig {
minSdkVersion 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.androidtransfuse;

import com.google.common.collect.ImmutableSet;
import org.androidtransfuse.adapter.ASTType;
import org.androidtransfuse.adapter.element.ASTElementConverterFactory;
import org.androidtransfuse.annotations.*;
Expand All @@ -26,6 +27,7 @@
import org.androidtransfuse.model.r.RBuilder;
import org.androidtransfuse.model.r.RResource;
import org.androidtransfuse.model.r.RResourceComposite;
import org.androidtransfuse.processor.GenerateModuleProcessor;
import org.androidtransfuse.processor.ReloadableASTElementFactory;
import org.androidtransfuse.processor.TransfuseProcessor;
import org.androidtransfuse.scope.ScopeKey;
Expand Down Expand Up @@ -191,6 +193,8 @@ private Collection<ASTType> wrapASTCollection(Collection<? extends Element> elem

@Override
public Set<String> getSupportedOptions() {
return Collections.singleton(ManifestLocator.ANDROID_MANIFEST_FILE_OPTION);
return ImmutableSet.of(
GenerateModuleProcessor.MANIFEST_PROCESSING_OPTION,
ManifestLocator.ANDROID_MANIFEST_FILE_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.androidtransfuse.processor.*;
import org.androidtransfuse.transaction.*;
import org.androidtransfuse.util.Logger;
import org.androidtransfuse.util.ManifestLocator;
import org.androidtransfuse.util.MessagerLogger;

import javax.annotation.processing.Filer;
Expand Down Expand Up @@ -85,7 +86,6 @@ public class TransfuseAndroidModule {
public static final String SCOPES_UTIL_TRANSACTION_WORKER = "scopesUtilTransactionWorker";
public static final String ORIGINAL_MANIFEST = "originalManifest";
public static final String MANIFEST_FILE = "manifestFile";
public static final String PROCESSING_ENVIRONMENT_OPTIONS = "processingEnvironmentOptions";

@Provides
@CodeGenerationScope
Expand Down Expand Up @@ -118,10 +118,15 @@ public Filer getFiler(ProcessingEnvironment processingEnvironment){
}

@Provides
@Singleton
@Named(PROCESSING_ENVIRONMENT_OPTIONS)
public Map<String,String> getOptions(ProcessingEnvironment processingEnvironment){
return processingEnvironment.getOptions();
@Named(ManifestLocator.ANDROID_MANIFEST_FILE_OPTION)
public String getManifestFileLocation(ProcessingEnvironment processingEnvironment){
return processingEnvironment.getOptions().get(ManifestLocator.ANDROID_MANIFEST_FILE_OPTION);
}

@Provides
@Named(GenerateModuleProcessor.MANIFEST_PROCESSING_OPTION)
public String getManifestProcessing(ProcessingEnvironment processingEnvironment){
return processingEnvironment.getOptions().get(GenerateModuleProcessor.MANIFEST_PROCESSING_OPTION);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
*/
public class GenerateModuleProcessor extends AbstractCompletionTransactionWorker<Void, Void> {

public static final String MANIFEST_PROCESSING_OPTION = "transfuseManifestProcessing";

private final ManifestManager manifestManager;
private final Merger merger;
private final Manifest originalManifest;
private final Logger logger;
private final File manifestFile;
private ManifestSerializer manifestParser;
private final String manifestProcessingOption;

@Inject
public GenerateModuleProcessor(ManifestManager manifestManager,
Expand All @@ -47,13 +50,16 @@ public GenerateModuleProcessor(ManifestManager manifestManager,
Logger logger,
@Named(TransfuseAndroidModule.MANIFEST_FILE)
File manifestFile,
ManifestSerializer manifestParser) {
ManifestSerializer manifestParser,
@Named(MANIFEST_PROCESSING_OPTION)
String manifestProcessingOption) {
this.manifestManager = manifestManager;
this.merger = merger;
this.originalManifest = originalManifest;
this.logger = logger;
this.manifestFile = manifestFile;
this.manifestParser = manifestParser;
this.manifestProcessingOption = manifestProcessingOption;
}

@Override
Expand All @@ -62,8 +68,19 @@ public Void innerRun(Void value) {
//assembling generated code
Manifest updatedManifest = buildManifest();

//write manifest back out, updating from processed classes
manifestParser.writeManifest(updatedManifest, manifestFile);
if(!"off".equals(manifestProcessingOption)){
if("log".equals(manifestProcessingOption)){
logger.info("Manifest generation piped to log");
manifestParser.writeManifest(updatedManifest, System.out);
}
else{
//write manifest back out, updating from processed classes
manifestParser.writeManifest(updatedManifest, manifestFile);
}
}
else{
logger.info("Manifest generation disabled");
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.androidtransfuse.util;

import org.androidtransfuse.TransfuseAnalysisException;
import org.androidtransfuse.config.TransfuseAndroidModule;

import javax.annotation.processing.Filer;
import javax.inject.Inject;
Expand All @@ -26,7 +25,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

/**
* Copied respectfully from the AndroidAnnotations project:
Expand Down Expand Up @@ -55,21 +53,19 @@ public class ManifestLocator {

private static final int MAX_PARENTS_FROM_SOURCE_FOLDER = 10;

private final Map<String,String> options;
private final String androidManifestFilePath;
private final Filer filer;
private final Logger logger;

@Inject
public ManifestLocator(Filer filer, Logger logger, @Named(TransfuseAndroidModule.PROCESSING_ENVIRONMENT_OPTIONS) Map<String,String> options) {
public ManifestLocator(Filer filer, Logger logger, @Named(ANDROID_MANIFEST_FILE_OPTION) String androidManifestFilePath) {
this.filer = filer;
this.logger = logger;
this.options = options;
this.androidManifestFilePath = androidManifestFilePath;
}

public File findManifest() {
String androidManifestFilePath = options.get(ANDROID_MANIFEST_FILE_OPTION);

File androidManifestFile = null;
File androidManifestFile;

try {
if (androidManifestFilePath != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public void writeManifest(Manifest manifest, OutputStream manifestStream) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(manifest, writer);
} catch (IOException e) {
logger.error("IOException while writing manifest", e);
throw new TransfuseRuntimeException("IOException while writing manifest", e);
} catch (JAXBException e) {
logger.error("JAXBException while writing manifest", e);
throw new TransfuseRuntimeException("JAXBException while writing manifest", e);
}
}
Expand All @@ -75,7 +77,7 @@ public void writeManifest(Manifest manifest, File manifestFile) {
writeManifest(manifest, new FileOutputStream(manifestFile));
} catch (IOException e) {
logger.error("IOException while writing manifest", e);
throw new TransfuseInjectionException(e);
throw new TransfuseInjectionException("IOException while writing manifest", e);
}
}
}

0 comments on commit 113428c

Please sign in to comment.