com.faker.android.gradle.StableIdsTask Maven / Gradle / Ivy
The newest version!
package com.faker.android.gradle;
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension;
import com.android.build.gradle.internal.scope.VariantScope;
import com.android.build.gradle.internal.tasks.VariantAwareTask;
import com.android.build.gradle.internal.tasks.factory.VariantTaskCreationAction;
import org.gradle.api.DefaultTask;
import org.gradle.api.Incubating;
import org.gradle.api.Project;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.impldep.org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Set;
public class StableIdsTask extends DefaultTask implements VariantAwareTask {
private File stableIdFile;
private String applicationId;
@Input
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
@OutputFile
public File getStableIdFile() {
return stableIdFile;
}
public void setStableIdFile(File stableIdFile) {
this.stableIdFile = stableIdFile;
}
private String variantName;
@NotNull
@Override
public String getVariantName() {
return variantName;
}
@Override
public void setVariantName(@NotNull String variantName) {
this.variantName = variantName;
}
File publicXmlSource;
@Nullable
@InputFile
@Incubating
@PathSensitive(PathSensitivity.RELATIVE)
@SkipWhenEmpty
public File getPublicXmlSource() {
return publicXmlSource;
}
public void setPublicXmlSource(File publicXmlSource) {
this.publicXmlSource = publicXmlSource;
}
@TaskAction
protected void xml2AaptArg() {
if(publicXmlSource.exists()){
StableIdUtlis.xml2AaptArg(applicationId,publicXmlSource,getStableIdFile());
}
}
public static class CreationAction extends VariantTaskCreationAction {
File stableIdFile;
public CreationAction(@NotNull VariantScope variantScope) {
super(variantScope);
}
@NotNull
@Override
public String getName() {
return getVariantScope().getTaskName("stableIds");
}
@NotNull
@Override
public Class getType() {
return StableIdsTask.class;
}
@Override
public void preConfigure(@NotNull String taskName) {
super.preConfigure(taskName);
stableIdFile = getVariantScope().getArtifacts().appendArtifact(FakerBuildArtifactType.STABLEIDS, taskName, "public.txt");
}
@Override
public void configure(@NotNull StableIdsTask task) {
super.configure(task);
task.setStableIdFile(stableIdFile);
Project project = getVariantScope().getVariantData().getScope().getGlobalScope().getProject();
BaseAppModuleExtension appExtension = project.getExtensions().getByType(BaseAppModuleExtension.class);
String applicationId = appExtension.getDefaultConfig().getApplicationId();
task.setApplicationId(applicationId);
Set srcDirs = appExtension.getSourceSets().getByName("main").getRes().getSrcDirs();
File srcDir = srcDirs.iterator().next();
File publicXml = new File(srcDir,"values/public.xml");
task.setPublicXmlSource(publicXml);
String path = getVariantScope().getArtifacts().getFinalArtifactFiles(FakerBuildArtifactType.STABLEIDS).get().getAsPath();
appExtension.getAaptOptions().additionalParameters("--stable-ids",path);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy