本文整理汇总了Java中com.android.ide.common.res2.ResourceSet类的典型用法代码示例。如果您正苦于以下问题:Java ResourceSet类的具体用法?Java ResourceSet怎么用?Java ResourceSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceSet类属于com.android.ide.common.res2包,在下文中一共展示了ResourceSet类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupResourceSets
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
private void setupResourceSets(MergeResources mergeResources) {
List<ResourceSet> resourceSets = mergeResources.getInputResourceSets();
List<ResourceSet> newResourceSets = new ArrayList<>(resourceSets.size());
for (ResourceSet resourceSet : resourceSets) {
// Change ResourceSets files to ignore res files.
List<File> newFiles = new ArrayList<>();
Iterator<File> iterator = resourceSet.getSourceFiles().iterator();
while (iterator.hasNext()) {
File file = iterator.next();
if (FileUtils.inFolder(file, mResFiles)) {
iterator.remove();
newFiles.add(new IgnoreResFileFile(file.getPath(), mResFiles));
}
}
if (newFiles.size() > 0) {
resourceSet.getSourceFiles().addAll(newFiles);
}
newResourceSets.add(resourceSet);
}
mVariant.getMergeResources().setInputResourceSets(newResourceSets);
}
示例2: execute
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
@Override
public StepExecutionResult execute(ExecutionContext context)
throws IOException, InterruptedException {
ResourceMerger merger = new ResourceMerger(1);
try {
for (Path resPath : getResPaths()) {
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(
getOutFolderPath().toFile(),
null /*publicFile*/,
null /*blameLogFolder*/,
new NoOpResourcePreprocessor(),
getTmpFolderPath().toFile());
merger.mergeData(writer, /* cleanUp */ false);
} catch (MergingException e) {
LOG.error(e, "Failed merging resources.");
return StepExecutionResults.ERROR;
}
return StepExecutionResults.SUCCESS;
}
示例3: doFullTaskAction
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
@Override
protected void doFullTaskAction() {
// this is full run, clean the previous output
File destinationDir = getOutputDir();
emptyFolder(destinationDir);
List<ResourceSet> resourceSets = getInputResourceSets();
// create a new merger and populate it with the sets.
ResourceMerger merger = new ResourceMerger();
try {
for (ResourceSet resourceSet : resourceSets) {
resourceSet.setNormalizeResources(normalizeResources);
// set needs to be loaded.
resourceSet.loadFromFiles(getILogger());
merger.addDataSet(resourceSet);
}
// get the merged set and write it down.
MergedResourceWriter writer = new MergedResourceWriter(
destinationDir, getCruncher(),
getCrunchPng(), getProcess9Patch(), getPublicFile());
writer.setInsertSourceMarkers(getInsertSourceMarkers());
merger.mergeData(writer, false /*doCleanUp*/);
// No exception? Write the known state.
merger.writeBlobTo(getIncrementalFolder(), writer);
} catch (MergingException e) {
System.out.println(e.getMessage());
merger.cleanBlob(getIncrementalFolder());
throw new ResourceException(e.getMessage(), e);
}
}
示例4: doIncrementalTaskAction
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
@Override
protected void doIncrementalTaskAction(Map<File, FileStatus> changedInputs) {
// create a merger and load the known state.
ResourceMerger merger = new ResourceMerger();
try {
if (!merger.loadFromBlob(getIncrementalFolder(), true /*incrementalState*/)) {
doFullTaskAction();
return;
}
// compare the known state to the current sets to detect incompatibility.
// This is in case there's a change that's too hard to do incrementally. In this case
// we'll simply revert to full build.
List<ResourceSet> resourceSets = getInputResourceSets();
for (ResourceSet resourceSet : resourceSets) {
resourceSet.setNormalizeResources(normalizeResources);
}
if (!merger.checkValidUpdate(resourceSets)) {
getLogger().info("Changed Resource sets: full task run!");
doFullTaskAction();
return;
}
// The incremental process is the following:
// Loop on all the changed files, find which ResourceSet it belongs to, then ask
// the resource set to update itself with the new file.
for (Map.Entry<File, FileStatus> entry : changedInputs.entrySet()) {
File changedFile = entry.getKey();
merger.findDataSetContaining(changedFile, fileValidity);
if (fileValidity.getStatus() == FileValidity.FileStatus.UNKNOWN_FILE) {
doFullTaskAction();
return;
} else if (fileValidity.getStatus() == FileValidity.FileStatus.VALID_FILE) {
if (!fileValidity.getDataSet().updateWith(
fileValidity.getSourceFile(), changedFile, entry.getValue(),
getILogger())) {
getLogger().info(
String.format("Failed to process %s event! Full task run",
entry.getValue()));
doFullTaskAction();
return;
}
}
}
MergedResourceWriter writer = new MergedResourceWriter(
getOutputDir(), getCruncher(),
getCrunchPng(), getProcess9Patch(), getPublicFile());
writer.setInsertSourceMarkers(getInsertSourceMarkers());
merger.mergeData(writer, false /*doCleanUp*/);
// No exception? Write the known state.
merger.writeBlobTo(getIncrementalFolder(), writer);
} catch (MergingException e) {
merger.cleanBlob(getIncrementalFolder());
throw new ResourceException(e.getMessage(), e);
} finally {
// some clean up after the task to help multi variant/module builds.
fileValidity.clear();
}
}
示例5: getInputResourceSets
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
public List<ResourceSet> getInputResourceSets() {
return inputResourceSets;
}
示例6: setInputResourceSets
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
public void setInputResourceSets(
List<ResourceSet> inputResourceSets) {
this.inputResourceSets = inputResourceSets;
}
示例7: execute
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
@Override
public void execute(MergeResources mergeResourcesTask) {
final BaseVariantData<? extends BaseVariantOutputData> variantData = scope
.getVariantData();
mergeResourcesTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
mergeResourcesTask.setIncrementalFolder(new File(
scope.getGlobalScope().getBuildDir() + "/" + AndroidProject.FD_INTERMEDIATES +
"/incremental/" + taskNamePrefix + "Resources" +
variantData.getVariantConfiguration().getDirName()));
mergeResourcesTask.process9Patch = process9Patch;
mergeResourcesTask.crunchPng = scope.getGlobalScope().getExtension().getAaptOptions()
.getCruncherEnabled();
mergeResourcesTask.normalizeResources =
scope.getGlobalScope().getExtension().getBuildToolsRevision()
.compareTo(NORMALIZE_RESOURCES_BUILD_TOOLS) < 0;
ConventionMappingHelper.map(mergeResourcesTask, "useNewCruncher",
new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return scope.getGlobalScope().getExtension().getAaptOptions()
.getUseNewCruncher();
}
});
ConventionMappingHelper.map(mergeResourcesTask, "inputResourceSets",
new Callable<List<ResourceSet>>() {
@Override
public List<ResourceSet> call() throws Exception {
List<File> generatedResFolders = Lists.newArrayList(
scope.getRenderscriptResOutputDir(),
scope.getGeneratedResOutputDir());
if (variantData.getExtraGeneratedResFolders() != null) {
generatedResFolders.addAll(
variantData.getExtraGeneratedResFolders());
}
if (variantData.generateApkDataTask != null &&
variantData.getVariantConfiguration().getBuildType()
.isEmbedMicroApp()) {
generatedResFolders.add(
variantData.generateApkDataTask.getResOutputDir());
}
return variantData.getVariantConfiguration()
.getResourceSets(generatedResFolders, includeDependencies);
}
});
ConventionMappingHelper.map(mergeResourcesTask, "outputDir", new Callable<File>() {
@Override
public File call() throws Exception {
return outputLocation != null ? outputLocation
: scope.getDefaultMergeResourcesOutputDir();
}
});
variantData.mergeResourcesTask = mergeResourcesTask;
}
示例8: createRes2
import com.android.ide.common.res2.ResourceSet; //导入依赖的package包/类
/**
* Creates a res2 resource repository for a resource folder whose contents is identified
* by the pairs of relative paths and file contents
*
* @see #create(boolean, Object[])
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
@NonNull
public static com.android.ide.common.res2.ResourceRepository createRes2(
boolean isFramework, Object[] data)
throws IOException, MergingException {
File dir = Files.createTempDir();
File res = new File(dir, FD_RES);
res.mkdirs();
assertTrue("Expected even number of items (path,contents)", data.length % 2 == 0);
for (int i = 0; i < data.length; i += 2) {
Object relativePathObject = data[i];
assertTrue(relativePathObject instanceof String);
String relativePath = (String) relativePathObject;
relativePath = relativePath.replace('/', File.separatorChar);
File file = new File(res, relativePath);
File parent = file.getParentFile();
parent.mkdirs();
Object fileContents = data[i + 1];
if (fileContents instanceof String) {
String text = (String) fileContents;
Files.write(text, file, Charsets.UTF_8);
} else if (fileContents instanceof byte[]) {
byte[] bytes = (byte[]) fileContents;
Files.write(bytes, file);
} else {
fail("File contents must be Strings or byte[]'s");
}
}
File resFolder = new File(dir, FD_RES);
ResourceMerger merger = new ResourceMerger();
ResourceSet resourceSet = new ResourceSet("main");
resourceSet.addSource(resFolder);
resourceSet.loadFromFiles(new RecordingLogger());
merger.addDataSet(resourceSet);
com.android.ide.common.res2.ResourceRepository repository;
repository = new com.android.ide.common.res2.ResourceRepository(isFramework);
merger.mergeData(repository.createMergeConsumer(), true /*doCleanUp*/);
return repository;
}