Search in sources :

Example 1 with IncrementalCompileOptions

use of org.gradle.api.tasks.scala.IncrementalCompileOptions in project gradle by gradle.

the class ScalaBasePlugin method configureScalaCompile.

private static void configureScalaCompile(final Project project, JavaBasePlugin javaPlugin, final SourceSet sourceSet) {
    String taskName = sourceSet.getCompileTaskName("scala");
    final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
    scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
    javaPlugin.configureForSourceSet(sourceSet, scalaCompile);
    Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
    ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
    scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
    scalaCompile.setSource(scalaSourceSet.getScala());
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);
    // cannot use convention mapping because the resulting object won't be serializable
    // cannot compute at task execution time because we need association with source set
    project.getGradle().addBuildListener(new BuildAdapter() {

        @Override
        public void projectsEvaluated(Gradle gradle) {
            IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
            if (incrementalOptions.getAnalysisFile() == null) {
                String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
                incrementalOptions.setAnalysisFile(new File(analysisFilePath));
            }
            if (incrementalOptions.getPublishedCode() == null) {
                Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
                incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
            }
        }
    });
}
Also used : IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) ScalaSourceSet(org.gradle.api.tasks.ScalaSourceSet) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) BuildAdapter(org.gradle.BuildAdapter) Jar(org.gradle.jvm.tasks.Jar) Gradle(org.gradle.api.invocation.Gradle) File(java.io.File)

Example 2 with IncrementalCompileOptions

use of org.gradle.api.tasks.scala.IncrementalCompileOptions in project gradle by gradle.

the class PlayTestPlugin method createTestTasks.

@Mutate
void createTestTasks(ModelMap<Task> tasks, @Path("binaries") ModelMap<PlayApplicationBinarySpecInternal> playBinaries, final PlayPluginConfigurations configurations, final FileResolver fileResolver, final ProjectIdentifier projectIdentifier, @Path("buildDir") final File buildDir) {
    for (final PlayApplicationBinarySpecInternal binary : playBinaries) {
        final PlayToolProvider playToolProvider = binary.getToolChain().select(binary.getTargetPlatform());
        final FileCollection testCompileClasspath = getTestCompileClasspath(binary, playToolProvider, configurations);
        final String testCompileTaskName = binary.getTasks().taskName("compile", "tests");
        final File testSourceDir = fileResolver.resolve("test");
        final FileCollection testSources = new SimpleFileCollection(testSourceDir).getAsFileTree().matching(new PatternSet().include("**/*.scala", "**/*.java"));
        final File testClassesDir = new File(buildDir, binary.getProjectScopedName() + "/testClasses");
        tasks.create(testCompileTaskName, PlatformScalaCompile.class, new Action<PlatformScalaCompile>() {

            public void execute(PlatformScalaCompile scalaCompile) {
                scalaCompile.setDescription("Compiles the scala and java test sources for the " + binary.getDisplayName() + ".");
                scalaCompile.setClasspath(testCompileClasspath);
                scalaCompile.dependsOn(binary.getBuildTask());
                scalaCompile.setPlatform(binary.getTargetPlatform().getScalaPlatform());
                scalaCompile.setDestinationDir(testClassesDir);
                scalaCompile.setSource(testSources);
                String targetCompatibility = binary.getTargetPlatform().getJavaPlatform().getTargetCompatibility().getMajorVersion();
                scalaCompile.setSourceCompatibility(targetCompatibility);
                scalaCompile.setTargetCompatibility(targetCompatibility);
                IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
                incrementalOptions.setAnalysisFile(new File(buildDir, "tmp/scala/compilerAnalysis/" + testCompileTaskName + ".analysis"));
            }
        });
        final String testTaskName = binary.getTasks().taskName("test");
        final File binaryBuildDir = new File(buildDir, binary.getProjectScopedName());
        tasks.create(testTaskName, Test.class, new Action<Test>() {

            public void execute(Test test) {
                test.setDescription("Runs " + WordUtils.uncapitalize(binary.getDisplayName() + "."));
                test.setClasspath(getRuntimeClasspath(testClassesDir, testCompileClasspath));
                test.setTestClassesDir(testClassesDir);
                test.setBinResultsDir(new File(binaryBuildDir, "results/" + testTaskName + "/bin"));
                test.getReports().getJunitXml().setDestination(new File(binaryBuildDir, "reports/test/xml"));
                test.getReports().getHtml().setDestination(new File(binaryBuildDir, "reports/test"));
                test.dependsOn(testCompileTaskName);
                test.setWorkingDir(projectIdentifier.getProjectDir());
            }
        });
        binary.getTasks().add(tasks.get(testTaskName));
    }
}
Also used : PlatformScalaCompile(org.gradle.language.scala.tasks.PlatformScalaCompile) IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) PlayApplicationBinarySpecInternal(org.gradle.play.internal.PlayApplicationBinarySpecInternal) Test(org.gradle.api.tasks.testing.Test) SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) PlayToolProvider(org.gradle.play.internal.toolchain.PlayToolProvider) SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet) Mutate(org.gradle.model.Mutate)

Aggregations

File (java.io.File)2 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)2 BuildAdapter (org.gradle.BuildAdapter)1 FileCollection (org.gradle.api.file.FileCollection)1 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)1 DefaultScalaSourceSet (org.gradle.api.internal.tasks.DefaultScalaSourceSet)1 Gradle (org.gradle.api.invocation.Gradle)1 Convention (org.gradle.api.plugins.Convention)1 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)1 ScalaSourceSet (org.gradle.api.tasks.ScalaSourceSet)1 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)1 Test (org.gradle.api.tasks.testing.Test)1 PatternSet (org.gradle.api.tasks.util.PatternSet)1 Jar (org.gradle.jvm.tasks.Jar)1 PlatformScalaCompile (org.gradle.language.scala.tasks.PlatformScalaCompile)1 Mutate (org.gradle.model.Mutate)1 PlayApplicationBinarySpecInternal (org.gradle.play.internal.PlayApplicationBinarySpecInternal)1 PlayToolProvider (org.gradle.play.internal.toolchain.PlayToolProvider)1