@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); if (!sourceSet.getName().startsWith(VariantType.UNIT_TEST.getPrefix())) { 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("RenderScript sources", sourceSet.getRenderscript(), 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(); }
System.out.printf("sets.name %s\n", sourceSets.getName()); // "testMinApi24DemoDebug" System.out.printf("sets.java.name %s\n", sourceSets.getJava().getName()); // "test min api21 demo debug Java source" // 何用?flavorは"minApi24"なのにわけられているし。 AndroidSourceDirectorySet java = sourceSets.getJava(); for (File f : java.getSrcDirs()) { System.out.printf(" src: %s\n", f.getAbsolutePath());
/** * @see SourceSet#getOutput() */ protected FileCollection getOutput(AndroidSourceSet androidSourceSet) { List<FileTreeInternal> sourceTrees = getAllVariants(androidSourceSet) .map(BaseVariant::getJavaCompiler) .filter(JavaCompile.class::isInstance) .map(JavaCompile.class::cast) .map(AbstractCompile::getDestinationDir) .map(outputDir -> (FileTreeInternal) getProject().fileTree(outputDir)) .collect(Collectors.toList()); return new UnionFileTree(androidSourceSet.getName() + " output", sourceTrees); }
AppExtension appExtension = project.getExtensions().findByType(AppExtension.class); if (appExtension != null) { mainRes = appExtension.getSourceSets().getByName("main").getRes(); } else { LibraryExtension libraryExtension = project.getExtensions().findByType(LibraryExtension.class); mainRes = libraryExtension.getSourceSets().getByName("main").getRes();
/** * All Java source files for this source set. This includes, for example, source which is directly compiled, and * source which is indirectly compiled through joint compilation. * * @return the Java source. Never returns null. * @see SourceSet#getAllJava() */ protected static FileTree getAllJava(AndroidSourceSet androidSourceSet) { return androidSourceSet.getJava().getSourceFiles(); }
/** * Returns the name of a task for this source set. * * @param verb The action, may be null. * @param target The target, may be null * @return The task name, generally of the form ${verb}${name}${noun} * @see SourceSet#getTaskName(String, String) */ protected static String getTaskName(AndroidSourceSet sourceSet, String verb, String target) { return new ClassDirectoryBinaryNamingScheme(sourceSet.getName()).getTaskName(verb, target); }
/** * Computes the user specified Java sources to use for compilation. * * Every entry is a ConfigurableFileTree instance to enable incremental java compilation. */ @NonNull public List<ConfigurableFileTree> getUserJavaSources() { // Build the list of source folders. ImmutableList.Builder<ConfigurableFileTree> sourceSets = ImmutableList.builder(); // First the actual source folders. List<SourceProvider> providers = variantConfiguration.getSortedSourceProviders(); for (SourceProvider provider : providers) { sourceSets.addAll(((AndroidSourceSet) provider).getJava().getSourceDirectoryTrees()); } return sourceSets.build(); }
@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); if (!sourceSet.getName().startsWith(VariantType.UNIT_TEST.getPrefix())) { 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("RenderScript sources", sourceSet.getRenderscript(), 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(); }
@Override protected void configureForSourceSet(final AndroidSourceSet sourceSet, Checkstyle task) { task.setDescription("Run Checkstyle analysis for " + sourceSet.getName() + " classes"); task.setClasspath(getOutput(sourceSet).plus(getCompileClasspath(sourceSet))); task.setSource(getAllJava(sourceSet)); } }
private void addSourceSetToPath(Project project, String path) { LibraryExtension androidLibraryExtension = (LibraryExtension)project.getProperties().get("android"); androidLibraryExtension.getSourceSets().getByName("main").getJava().srcDirs(new File(path)); }
@Override protected void configureForSourceSet(final AndroidSourceSet sourceSet, final Pmd task) { task.setDescription("Run PMD analysis for " + sourceSet.getName() + " classes"); task.setSource(getAllJava(sourceSet)); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classpath", () -> getOutput(sourceSet).plus(getCompileClasspath(sourceSet))); } }
sourceList.add(((AndroidSourceSet) provider).getJava().getSourceFiles());
public void createConfigurationForVariant() { ConfigurationContainer configurations = project.getConfigurations(); extension.getSourceSets().all(androidSourceSet -> { if (!androidSourceSet.getName().startsWith(TEST)) { // don't support unit test Configuration configuration = configurations.maybeCreate(sourceSetToConfigurationName(androidSourceSet.getName())); configuration.setDescription("Classpath for the capt plugin for " + androidSourceSet.getName() + "."); configuration.setVisible(false); configuration.setCanBeConsumed(false);
private void configureEtaSourceSetConvention() { androidExtension.getSourceSets().all(sourceSet -> { project.getLogger().debug("Creating EtaSourceSet for source set " + sourceSet); final DefaultEtaSourceSet etaSourceSet = project.getObjects().newInstance (DefaultEtaSourceSet.class, null, ETA_SOURCE_SET_NAME, ((DefaultAndroidSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory); ExtensionHelper.createConvention (sourceSet, ETA_SOURCE_SET_DSL_NAME, etaSourceSet); ExtensionHelper.createConvention(sourceSet, "eta", etaSourceSet); etaSourceSet.getEta().srcDir("src/" + sourceSet.getName() + "/eta"); }); }