com.android.build.gradle.api.AndroidSourceSet Java Examples

The following examples show how to use com.android.build.gradle.api.AndroidSourceSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void applyProjectSourceSet() {
    for (FunctionalSourceSet source : getSources()) {
        String name = source.getName();
        AndroidSourceSet androidSource = name.equals(BuilderConstants.MAIN) ?
                sourceSetsContainer.maybeCreate(getDefaultConfig().getName()) :
                sourceSetsContainer.maybeCreate(name);

        convertSourceFile(androidSource.getManifest(), source, "manifest");
        convertSourceSet(androidSource.getResources(), source, "resource");
        convertSourceSet(androidSource.getJava(), source, "java");
        convertSourceSet(androidSource.getRes(), source, "res");
        convertSourceSet(androidSource.getAssets(), source, "assets");
        convertSourceSet(androidSource.getAidl(), source, "aidl");
        convertSourceSet(androidSource.getJni(), source, "jni");
        convertSourceSet(androidSource.getJniLibs(), source, "jniLibs");
    }
}
 
Example #2
Source File: VariantManager.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static void createCompoundSourceSets(
        @NonNull List<? extends ProductFlavor> productFlavorList,
        GradleVariantConfiguration variantConfig,
        NamedDomainObjectContainer<AndroidSourceSet> sourceSetsContainer) {
    if (!productFlavorList.isEmpty() && !variantConfig.getType().isSingleBuildType()) {
        DefaultAndroidSourceSet variantSourceSet =
                (DefaultAndroidSourceSet) sourceSetsContainer.maybeCreate(
                        computeSourceSetName(
                                variantConfig.getFullName(),
                                variantConfig.getType()));
        variantConfig.setVariantSourceProvider(variantSourceSet);
    }

    if (productFlavorList.size() > 1) {
        DefaultAndroidSourceSet multiFlavorSourceSet =
                (DefaultAndroidSourceSet) sourceSetsContainer.maybeCreate(
                        computeSourceSetName(
                                variantConfig.getFlavorName(),
                                variantConfig.getType()));
        variantConfig.setMultiFlavorSourceProvider(multiFlavorSourceSet);
    }
}
 
Example #3
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static AndroidSourceSet findAndroidSourceSet(
        VariantManager variantManager,
        String name) {
    BuildTypeData buildTypeData = variantManager.getBuildTypes().get(name);
    if (buildTypeData != null) {
        return buildTypeData.getSourceSet();
    }

    ProductFlavorData productFlavorData = variantManager.getProductFlavors().get(name);
    if (productFlavorData != null) {
        return productFlavorData.getSourceSet();
    }
    return null;
}
 
Example #4
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public AndroidConfigAdaptor(
        AndroidConfig model,
        NamedDomainObjectContainer<AndroidSourceSet> sourceSetsContainer) {
    this.model = model;
    this.sourceSetsContainer = sourceSetsContainer;
    applyProjectSourceSet();
}
 
Example #5
Source File: ProcessJavaResConfigAction.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@NonNull Sync processResources) {
    scope.getVariantData().processJavaResourcesTask = processResources;

    // set the input
    processResources.from(((AndroidSourceSet) scope.getVariantConfiguration().getDefaultSourceSet()).getResources().getSourceFiles());
    processResources.from(((AndroidSourceSet) scope.getVariantConfiguration().getBuildTypeSourceSet()).getResources().getSourceFiles());
    if (scope.getVariantConfiguration().hasFlavors()) {
        for (SourceProvider flavorSourceSet : scope.getVariantConfiguration().getFlavorSourceProviders()) {
            processResources.from(((AndroidSourceSet) flavorSourceSet).getResources().getSourceFiles());
        }

    }
    processResources.setDestinationDir(new File(scope.getSourceFoldersJavaResDestinationDir(), "src"));
}
 
Example #6
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet setRoot(String path) {
    javaSource.setSrcDirs(Collections.singletonList(path + "/java"));
    javaResources.setSrcDirs(Collections.singletonList(path + "/resources"));
    res.setSrcDirs(Collections.singletonList(path + "/" + SdkConstants.FD_RES));
    assets.setSrcDirs(Collections.singletonList(path + "/" + SdkConstants.FD_ASSETS));
    manifest.srcFile(path + "/" + SdkConstants.FN_ANDROID_MANIFEST_XML);
    aidl.setSrcDirs(Collections.singletonList(path + "/aidl"));
    jni.setSrcDirs(Collections.singletonList(path + "/jni"));
    jniLibs.setSrcDirs(Collections.singletonList(path + "/jniLibs"));
    return this;
}
 
Example #7
Source File: SourceSetsTask.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void generate(Project project) throws IOException {
    if (config != null) {
        for (AndroidSourceSet sourceSet : config.getSourceSets()) {
            mRenderer.getBuilder().subheading(sourceSet.getName());


            renderKeyValue("Compile configuration: ", sourceSet.getCompileConfigurationName());
            renderKeyValue("build.gradle name: ", "android.sourceSets." + sourceSet.getName());

            renderDirectorySet("Java sources", sourceSet.getJava(), project);

            renderKeyValue(
                    "Manifest file: ",
                    project.getRootProject().relativePath(
                            sourceSet.getManifest().getSrcFile()));

            renderDirectorySet("Android resources", sourceSet.getRes(), project);
            renderDirectorySet("Assets", sourceSet.getAssets(), project);
            renderDirectorySet("AIDL sources", sourceSet.getAidl(), project);
            renderDirectorySet("JNI sources", sourceSet.getJni(), project);
            renderDirectorySet("JNI libraries", sourceSet.getJniLibs(), project);

            renderDirectorySet("Java-style resources", sourceSet.getResources(), project);

            mRenderer.getTextOutput().println();
        }
    }

    mRenderer.complete();
}
 
Example #8
Source File: BaseVariantData.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Computes the Java sources to use for compilation. This Object[] contains
 * {@link org.gradle.api.file.FileCollection} and {@link File} instances
 */
@NonNull
public Object[] getJavaSources() {
    if (javaSources == null) {
        // Build the list of source folders.
        List<Object> sourceList = Lists.newArrayList();

        // First the actual source folders.
        List<SourceProvider> providers = variantConfiguration.getSortedSourceProviders();
        for (SourceProvider provider : providers) {
            sourceList.add(((AndroidSourceSet) provider).getJava().getSourceFiles());
        }

        // then all the generated src folders.
        if (getScope().getGenerateRClassTask() != null) {
            sourceList.add(getScope().getRClassSourceOutputDir());
        }

        // for the other, there's no duplicate so no issue.
        if (getScope().getGenerateBuildConfigTask() != null) {
            sourceList.add(scope.getBuildConfigSourceOutputDir());
        }

        if (getScope().getAidlCompileTask() != null) {
            sourceList.add(scope.getAidlSourceOutputDir());
        }

        javaSources = sourceList.toArray();
    }

    return javaSources;
}
 
Example #9
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet jniLibs(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getJniLibs());
    return this;
}
 
Example #10
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet aidl(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getAidl());
    return this;
}
 
Example #11
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet java(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getJava());
    return this;
}
 
Example #12
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet resources(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getResources());
    return this;
}
 
Example #13
Source File: AndroidConfigHelper.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static NamedDomainObjectContainer<AndroidSourceSet> createSourceSetsContainer(
        @NonNull final Project project,
        @NonNull Instantiator instantiator,
        final boolean isLibrary) {
    NamedDomainObjectContainer<AndroidSourceSet> sourceSetsContainer = project.container(
            AndroidSourceSet.class,
            new AndroidSourceSetFactory(instantiator, project, isLibrary));

    sourceSetsContainer.whenObjectAdded(new Action<AndroidSourceSet>() {
        @Override
        public void execute(AndroidSourceSet sourceSet) {
            ConfigurationContainer configurations = project.getConfigurations();

            createConfiguration(
                    configurations,
                    sourceSet.getCompileConfigurationName(),
                    "Classpath for compiling the ${sourceSet.name} sources.");

            String packageConfigDescription;
            if (isLibrary) {
                packageConfigDescription
                        = "Classpath only used when publishing '${sourceSet.name}'.";
            } else {
                packageConfigDescription
                        = "Classpath packaged with the compiled '${sourceSet.name}' classes.";
            }
            createConfiguration(
                    configurations,
                    sourceSet.getPackageConfigurationName(),
                    packageConfigDescription);

            createConfiguration(
                    configurations,
                    sourceSet.getProvidedConfigurationName(),
                    "Classpath for only compiling the ${sourceSet.name} sources.");

            createConfiguration(
                    configurations,
                    sourceSet.getWearAppConfigurationName(),
                    "Link to a wear app to embed for object '${sourceSet.name}'.");

            sourceSet.setRoot(String.format("src/%s", sourceSet.getName()));

        }
    });
    return sourceSetsContainer;
}
 
Example #14
Source File: BaseExtension.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
BaseExtension(
        @NonNull final ProjectInternal project,
        @NonNull Instantiator instantiator,
        @NonNull AndroidBuilder androidBuilder,
        @NonNull SdkHandler sdkHandler,
        @NonNull NamedDomainObjectContainer<BuildType> buildTypes,
        @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors,
        @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs,
        @NonNull ExtraModelInfo extraModelInfo,
        final boolean isLibrary) {
    this.androidBuilder = androidBuilder;
    this.sdkHandler = sdkHandler;
    this.buildTypes = buildTypes;
    //noinspection unchecked
    this.productFlavors = (NamedDomainObjectContainer) productFlavors;
    this.signingConfigs = signingConfigs;
    this.extraModelInfo = extraModelInfo;
    this.project = project;

    logger = Logging.getLogger(this.getClass());

    defaultConfig = instantiator.newInstance(ProductFlavor.class, BuilderConstants.MAIN,
            project, instantiator, project.getLogger());

    aaptOptions = instantiator.newInstance(AaptOptions.class);
    dexOptions = instantiator.newInstance(DexOptions.class);
    lintOptions = instantiator.newInstance(LintOptions.class);
    compileOptions = instantiator.newInstance(CompileOptions.class);
    packagingOptions = instantiator.newInstance(PackagingOptions.class);
    preprocessingOptions = instantiator.newInstance(PreprocessingOptions.class);
    splits = instantiator.newInstance(Splits.class, instantiator);

    sourceSetsContainer = project.container(AndroidSourceSet.class,
            new AndroidSourceSetFactory(instantiator, project, isLibrary));

    sourceSetsContainer.whenObjectAdded(new Action<AndroidSourceSet>() {
        @Override
        public void execute(AndroidSourceSet sourceSet) {
            ConfigurationContainer configurations = project.getConfigurations();

            createConfiguration(
                    configurations,
                    sourceSet.getCompileConfigurationName(),
                    "Classpath for compiling the " + sourceSet.getName() + " sources.");

            String packageConfigDescription;
            if (isLibrary) {
                packageConfigDescription
                        = "Classpath only used when publishing '" + sourceSet.getName() + "'.";
            } else {
                packageConfigDescription
                        = "Classpath packaged with the compiled '" + sourceSet.getName() + "' classes.";
            }
            createConfiguration(
                    configurations,
                    sourceSet.getPackageConfigurationName(),
                    packageConfigDescription);

            createConfiguration(
                    configurations,
                    sourceSet.getProvidedConfigurationName(),
                    "Classpath for only compiling the " + sourceSet.getName() + " sources.");

            createConfiguration(
                    configurations,
                    sourceSet.getWearAppConfigurationName(),
                    "Link to a wear app to embed for object '" + sourceSet.getName() + "'.");

            sourceSet.setRoot(String.format("src/%s", sourceSet.getName()));
        }
    });

    sourceSetsContainer.create(defaultConfig.getName());
}
 
Example #15
Source File: BaseExtension.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Configures the source sets. Note that the Android plugin uses its own implementation of
 * source sets, {@link AndroidSourceSet}.
 */
public void sourceSets(Action<NamedDomainObjectContainer<AndroidSourceSet>> action) {
    checkWritability();
    action.execute(sourceSetsContainer);
}
 
Example #16
Source File: BaseExtension.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * All source sets. Note that the Android plugin uses its own implementation of
 * source sets, {@link AndroidSourceSet}.
 */
@Override
public NamedDomainObjectContainer<AndroidSourceSet> getSourceSets() {
    return sourceSetsContainer;
}
 
Example #17
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public NamedDomainObjectContainer<AndroidSourceSet> getSourceSets() {
    return sourceSetsContainer;
}
 
Example #18
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet jni(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getJni());
    return this;
}
 
Example #19
Source File: FirebaseLibraryPlugin.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
private static void setupApiInformationAnalysis(Project project, LibraryExtension android) {
  File metalavaOutputJarFile = new File(project.getRootProject().getBuildDir(), "metalava.jar");
  AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main");
  File outputFile =
      project
          .getRootProject()
          .file(
              Paths.get(
                  project.getRootProject().getBuildDir().getPath(),
                  "apiinfo",
                  project.getPath().substring(1).replace(":", "_")));
  File outputApiFile = new File(outputFile.getAbsolutePath() + "_api.txt");

  project
      .getTasks()
      .register(
          "getMetalavaJar",
          GetMetalavaJarTask.class,
          task -> {
            task.setOutputFile(metalavaOutputJarFile);
          });
  File apiTxt =
      project.file("api.txt").exists()
          ? project.file("api.txt")
          : project.file(project.getRootDir() + "/empty-api.txt");
  TaskProvider<ApiInformationTask> apiInfo =
      project
          .getTasks()
          .register(
              "apiInformation",
              ApiInformationTask.class,
              task -> {
                task.setApiTxt(apiTxt);
                task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
                task.setSourceSet(mainSourceSet);
                task.setOutputFile(outputFile);
                task.setBaselineFile(project.file("baseline.txt"));
                task.setOutputApiFile(outputApiFile);
                if (project.hasProperty("updateBaseline")) {
                  task.setUpdateBaseline(true);
                } else {
                  task.setUpdateBaseline(false);
                }
                task.dependsOn("getMetalavaJar");
              });

  TaskProvider<GenerateApiTxtFileTask> generateApiTxt =
      project
          .getTasks()
          .register(
              "generateApiTxtFile",
              GenerateApiTxtFileTask.class,
              task -> {
                task.setApiTxt(project.file("api.txt"));
                task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
                task.setSourceSet(mainSourceSet);
                task.setBaselineFile(project.file("baseline.txt"));
                task.setUpdateBaseline(project.hasProperty("updateBaseline"));
                task.dependsOn("getMetalavaJar");
              });

  TaskProvider<GenerateStubsTask> docStubs =
      project
          .getTasks()
          .register(
              "docStubs",
              GenerateStubsTask.class,
              task -> {
                task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath());
                task.setOutputDir(new File(project.getBuildDir(), "doc-stubs"));
                task.dependsOn("getMetalavaJar");

                task.setSourceSet(mainSourceSet);
              });
  project.getTasks().getByName("check").dependsOn(docStubs);

  android
      .getLibraryVariants()
      .all(
          v -> {
            if (v.getName().equals("release")) {
              FileCollection jars =
                  v.getCompileConfiguration()
                      .getIncoming()
                      .artifactView(
                          config ->
                              config.attributes(
                                  container ->
                                      container.attribute(
                                          Attribute.of("artifactType", String.class), "jar")))
                      .getArtifacts()
                      .getArtifactFiles();
              apiInfo.configure(t -> t.setClassPath(jars));
              generateApiTxt.configure(t -> t.setClassPath(jars));
              docStubs.configure(t -> t.setClassPath(jars));
            }
          });
}
 
Example #20
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet assets(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getAssets());
    return this;
}
 
Example #21
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet res(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getRes());
    return this;
}
 
Example #22
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
@NonNull
public AndroidSourceSet manifest(Closure configureClosure) {
    ConfigureUtil.configure(configureClosure, getManifest());
    return this;
}
 
Example #23
Source File: AndroidSourceSetFactory.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AndroidSourceSet create(String name) {
    return instantiator.newInstance(DefaultAndroidSourceSet.class,
            name, project, isLibrary);
}
 
Example #24
Source File: AndroidConfig.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Source sets for all variants
 */
NamedDomainObjectContainer<AndroidSourceSet> getSourceSets();
 
Example #25
Source File: GenerateApiTxtFileTask.java    From firebase-android-sdk with Apache License 2.0 votes vote down vote up
public abstract void setSourceSet(AndroidSourceSet value); 
Example #26
Source File: GenerateApiTxtFileTask.java    From firebase-android-sdk with Apache License 2.0 votes vote down vote up
abstract AndroidSourceSet getSourceSet(); 
Example #27
Source File: ApiInformationTask.java    From firebase-android-sdk with Apache License 2.0 votes vote down vote up
public abstract void setSourceSet(AndroidSourceSet value); 
Example #28
Source File: ApiInformationTask.java    From firebase-android-sdk with Apache License 2.0 votes vote down vote up
abstract AndroidSourceSet getSourceSet(); 
Example #29
Source File: GenerateStubsTask.java    From firebase-android-sdk with Apache License 2.0 votes vote down vote up
public abstract void setSourceSet(AndroidSourceSet sourceSet); 
Example #30
Source File: GenerateStubsTask.java    From firebase-android-sdk with Apache License 2.0 votes vote down vote up
public abstract AndroidSourceSet getSourceSet();