Search in sources :

Example 1 with ResourceSet

use of com.android.ide.common.res2.ResourceSet in project atlas by alibaba.

the class MergeAwbResourceConfigAction method execute.

@Override
public void execute(MergeResources mergeResourcesTask) {
    VariantScope scope = variantContext.getScope();
    final BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData();
    final AndroidConfig extension = scope.getGlobalScope().getExtension();
    //final VariantConfiguration variantConfig = variantData.getVariantConfiguration();
    mergeResourcesTask.setMinSdk(variantData.getVariantConfiguration().getMinSdkVersion().getApiLevel());
    mergeResourcesTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
    mergeResourcesTask.setVariantName(scope.getVariantConfiguration().getFullName());
    GlobalScope globalScope = scope.getGlobalScope();
    mergeResourcesTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
    try {
        FieldUtils.writeField(mergeResourcesTask, "variantScope", scope, true);
    } catch (IllegalAccessException e) {
        throw new GradleException("exception", e);
    }
    // where blame is useful, and once for packaging where it is not.
    if (includeDependencies) {
        mergeResourcesTask.setBlameLogFolder(scope.getResourceBlameLogDir());
    } else {
    //            if (variantContext instanceof AppVariantContext) {
    //                mergeResourcesTask.setBlameLogFolder(((AppVariantContext) variantContext).getAwbBlameLogFolder(awbBundle));
    //            }
    }
    mergeResourcesTask.setProcess9Patch(process9Patch);
    mergeResourcesTask.setCrunchPng(extension.getAaptOptions().getCruncherEnabled());
    VectorDrawablesOptions vectorDrawablesOptions = variantData.getVariantConfiguration().getMergedFlavor().getVectorDrawables();
    Set<String> generatedDensities = vectorDrawablesOptions.getGeneratedDensities();
    mergeResourcesTask.setGeneratedDensities(Objects.firstNonNull(generatedDensities, Collections.<String>emptySet()));
    mergeResourcesTask.setDisableVectorDrawables(vectorDrawablesOptions.getUseSupportLibrary() || mergeResourcesTask.getGeneratedDensities().isEmpty());
    //mergeResourcesTask.setUseNewCruncher(extension.getAaptOptions().getUseNewCruncher());
    final boolean validateEnabled = AndroidGradleOptions.isResourceValidationEnabled(scope.getGlobalScope().getProject());
    mergeResourcesTask.setValidateEnabled(validateEnabled);
    ConventionMappingHelper.map(mergeResourcesTask, "inputResourceSets", new Callable<List<ResourceSet>>() {

        @Override
        public List<ResourceSet> call() throws Exception {
            List<ResourceSet> resourceSets = Lists.newArrayList();
            List<? extends AndroidLibrary> bundleDeps = awbBundle.getLibraryDependencies();
            // the list of dependency must be reversed to use the right overlay order.
            for (int n = bundleDeps.size() - 1; n >= 0; n--) {
                AndroidLibrary dependency = bundleDeps.get(n);
                File resFolder = dependency.getResFolder();
                if (resFolder.isDirectory()) {
                    ResourceSet resourceSet = new ResourceSet(dependency.getFolder().getName(), true);
                    resourceSet.addSource(resFolder);
                    resourceSets.add(resourceSet);
                }
            }
            File awbResourceFolder = awbBundle.getResFolder();
            if (awbResourceFolder.isDirectory()) {
                ResourceSet resourceSet = new ResourceSet(awbBundle.getFolder().getName(), true);
                resourceSet.addSource(awbResourceFolder);
                resourceSets.add(resourceSet);
            }
            return resourceSets;
        }
    });
    mergeResourcesTask.setOutputDir(variantContext.getMergeResources(awbBundle));
    mergeResourcesTask.setGeneratedPngsOutputDir(variantContext.getPngsOutputDir(awbBundle));
//        if (variantContext instanceof AppVariantContext) {
//            AppVariantContext appVariantContext = (AppVariantContext) variantContext;
//            appVariantContext.getAwbMergeResourceTasks().put(awbBundle.getName(), mergeResourcesTask);
//        }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) ResourceSet(com.android.ide.common.res2.ResourceSet) AndroidConfig(com.android.build.gradle.AndroidConfig) GradleException(org.gradle.api.GradleException) VectorDrawablesOptions(com.android.builder.model.VectorDrawablesOptions) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleException(org.gradle.api.GradleException) List(java.util.List) File(java.io.File)

Example 2 with ResourceSet

use of com.android.ide.common.res2.ResourceSet in project buck by facebook.

the class MergeAndroidResourceSourcesStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
    ResourceMerger merger = new ResourceMerger(1);
    try {
        for (Path resPath : resPaths) {
            Preconditions.checkState(resPath.isAbsolute());
            ResourceSet set = new ResourceSet(resPath.toString(), true);
            set.setDontNormalizeQualifiers(true);
            set.addSource(resPath.toFile());
            set.loadFromFiles(new ResourcesSetLoadLogger(context.getBuckEventBus()));
            merger.addDataSet(set);
        }
        MergedResourceWriter writer = MergedResourceWriter.createWriterWithoutPngCruncher(outFolderPath.toFile(), null, /*publicFile*/
        null, /*blameLogFolder*/
        new NoOpResourcePreprocessor(), tmpFolderPath.toFile());
        merger.mergeData(writer, /* cleanUp */
        false);
    } catch (MergingException e) {
        LOG.error(e, "Failed merging resources.");
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) MergedResourceWriter(com.android.ide.common.res2.MergedResourceWriter) MergingException(com.android.ide.common.res2.MergingException) ResourceMerger(com.android.ide.common.res2.ResourceMerger) ResourceSet(com.android.ide.common.res2.ResourceSet) NoOpResourcePreprocessor(com.android.ide.common.res2.NoOpResourcePreprocessor)

Aggregations

ResourceSet (com.android.ide.common.res2.ResourceSet)2 AndroidConfig (com.android.build.gradle.AndroidConfig)1 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)1 VariantScope (com.android.build.gradle.internal.scope.VariantScope)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 VectorDrawablesOptions (com.android.builder.model.VectorDrawablesOptions)1 MergedResourceWriter (com.android.ide.common.res2.MergedResourceWriter)1 MergingException (com.android.ide.common.res2.MergingException)1 NoOpResourcePreprocessor (com.android.ide.common.res2.NoOpResourcePreprocessor)1 ResourceMerger (com.android.ide.common.res2.ResourceMerger)1 File (java.io.File)1 Path (java.nio.file.Path)1 List (java.util.List)1 GradleException (org.gradle.api.GradleException)1