public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) { ConventionMapping conventionMapping; compile.setDescription("Compiles the " + sourceSet.getJava() + "."); conventionMapping = compile.getConventionMapping(); compile.setSource(sourceSet.getJava()); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getOutput().getClassesDir(); } }); }
/** * Makes the given task the one used by top-level "compile" task. */ public static void setJavaCompilerTask( @NonNull AndroidTask<? extends AbstractCompile> javaCompilerTask, @NonNull TaskFactory tasks, @NonNull VariantScope scope) { scope.getCompileTask().dependsOn(tasks, javaCompilerTask); scope.setJavaCompilerTask(javaCompilerTask); // TODO: Get rid of it once we stop keeping tasks in variant data. //noinspection VariableNotUsedInsideIf if (scope.getVariantData().javacTask != null) { // This is not the experimental plugin, let's update variant data, so Variants API // keeps working. scope.getVariantData().javaCompilerTask = (AbstractCompile) tasks.named(javaCompilerTask.getName()); } }
/** * Preconfigures the specified compile task based on the specified source set and class directory binary. * * @param compile the compile task to be preconfigured * @param sourceSet the source set for the compile task * @param binary the binary for the compile task */ public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinarySpec binary) { compile.setDescription(String.format("Compiles %s.", sourceSet)); compile.setSource(sourceSet.getSource()); compile.dependsOn(sourceSet); ConventionMapping conventionMapping = compile.getConventionMapping(); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath().getFiles(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return binary.getClassesDir(); } }); }
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) { ConventionMapping conventionMapping; compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava())); conventionMapping = compile.getConventionMapping(); compile.setSource(sourceSet.getJava()); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getOutput().getClassesDir(); } }); }
/** * Preconfigures the specified compile task based on the specified source set and class directory binary. * * @param compile the compile task to be preconfigured * @param sourceSet the source set for the compile task * @param binary the binary for the compile task */ public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinary binary) { compile.setDescription(String.format("Compiles %s.", sourceSet)); compile.setSource(sourceSet.getSource()); compile.dependsOn(sourceSet); ConventionMapping conventionMapping = compile.getConventionMapping(); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath().getFiles(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return binary.getClassesDir(); } }); }
@Override public void execute(AbstractCompile task) { if (byteBuddyExtension.implies(task)) { task.doLast(new TransformationAction(project, byteBuddyExtension, task)); } else { project.getLogger().info("Skipping non-specified task {}", task.getName()); } }
/** * Determines the java language level to use and sets it on the given task and * {@link CompileOptions}. The latter is to propagate the information to Studio. */ public static void configureLanguageLevel( AbstractCompile compileTask, final CompileOptions compileOptions, String compileSdkVersion) { final AndroidVersion hash = AndroidTargetHash.getVersionFromHash(compileSdkVersion); Integer compileSdkLevel = (hash == null ? null : hash.getApiLevel()); JavaVersion javaVersionToUse; if (compileSdkLevel == null || (0 <= compileSdkLevel && compileSdkLevel <= 20)) { javaVersionToUse = JavaVersion.VERSION_1_6; } else { javaVersionToUse = JavaVersion.VERSION_1_7; } JavaVersion jdkVersion = JavaVersion.toVersion(System.getProperty("java.specification.version")); if (jdkVersion.compareTo(javaVersionToUse) < 0) { compileTask.getLogger().warn( "Default language level for compileSdkVersion '{}' is " + "{}, but the JDK used is {}, so the JDK language level will be used.", compileSdkVersion, javaVersionToUse, jdkVersion); javaVersionToUse = jdkVersion; } compileOptions.setDefaultJavaVersion(javaVersionToUse); ConventionMappingHelper.map(compileTask, "sourceCompatibility", new Callable<String>() { @Override public String call() throws Exception { return compileOptions.getSourceCompatibility().toString(); } }); ConventionMappingHelper.map(compileTask, "targetCompatibility", new Callable<String>() { @Override public String call() throws Exception { return compileOptions.getTargetCompatibility().toString(); } }); }
private void createUnitTestTask(@NonNull TaskFactory tasks, @NonNull final TestVariantData variantData) { final BaseVariantData testedVariantData = (BaseVariantData) variantData.getTestedVariantData(); final Test runTestsTask = project.getTasks().create( variantData.getScope().getTaskName(UNIT_TEST.getPrefix()), Test.class); runTestsTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP); runTestsTask.setDescription( "Run unit tests for the " + testedVariantData.getVariantConfiguration().getFullName() + " build."); fixTestTaskSources(runTestsTask); runTestsTask.dependsOn(variantData.assembleVariantTask); final AbstractCompile testCompileTask = variantData.javacTask; runTestsTask.setTestClassesDir(testCompileTask.getDestinationDir()); ConventionMappingHelper.map(runTestsTask, "classpath", new Callable<ConfigurableFileCollection>() { @Override public ConfigurableFileCollection call() throws Exception { Iterable<File> filteredBootClasspath = Iterables.filter( androidBuilder.getBootClasspath(), new Predicate<File>() { @Override public boolean apply(@Nullable File file) { return file != null && !SdkConstants.FN_FRAMEWORK_LIBRARY .equals(file.getName()); } }); return project.files( testCompileTask.getClasspath(), testCompileTask.getOutputs().getFiles(), variantData.processJavaResourcesTask.getOutputs(), testedVariantData.processJavaResourcesTask.getOutputs(), filteredBootClasspath, // Mockable JAR is last, to make sure you can shadow the classes // withdependencies. createMockableJar.getOutputFile()); } }); // Put the variant name in the report path, so that different testing tasks don't // overwrite each other's reports. TestTaskReports testTaskReports = runTestsTask.getReports(); for (ConfigurableReport report : new ConfigurableReport[] { testTaskReports.getJunitXml(), testTaskReports.getHtml()}) { report.setDestination(new File(report.getDestination(), testedVariantData.getName())); } tasks.named(JavaPlugin.TEST_TASK_NAME, new Action<Task>() { @Override public void execute(Task test) { test.dependsOn(runTestsTask); } }); extension.getTestOptions().getUnitTests().applyConfiguration(runTestsTask); }
@Nullable public AndroidTask<? extends AbstractCompile> getJavaCompilerTask() { return javaCompilerTask; }
public void setJavaCompilerTask( @NonNull AndroidTask<? extends AbstractCompile> javaCompileTask) { this.javaCompilerTask = javaCompileTask; }
@Override public void apply(Project project) { project.getTasks().withType(AbstractCompile.class, PostCompilationAction.of(project)); }
/** * Creates a post compilation action. * * @param project The project to apply the action upon. * @return An appropriate action. */ public static Action<AbstractCompile> of(Project project) { return new PostCompilationAction(project, project.getExtensions().create("byteBuddy", ByteBuddyExtension.class, project)); }
/** * Creates a new transformation action. * * @param project The current project. * @param extension The current project's Byte Buddy extension. * @param task The task to which this transformation was appended. */ public TransformationAction(Project project, ByteBuddyExtension extension, AbstractCompile task) { this.project = project; this.byteBuddyExtension = extension; this.task = task; }