org.gradle.api.tasks.SourceTask Java Examples

The following examples show how to use org.gradle.api.tasks.SourceTask. 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 Project: javaccPlugin   Author: johnmartel   File: JavaccCompilerInputOutputConfigurationTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getCompleteSourceTreeReturnsSourceAndJavaSourceWhenProjectHasJavaCompileTasks() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class);
    testFolder.newFolder("inputJava");
    File javaFile = addTaskWithSourceFile(project, "compileJava", "inputJava/MyClass.java", JavaCompile.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource())
        .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class))
        .build();

    FileTree completeSourceTree = configuration.getCompleteSourceTree();

    assertThat(completeSourceTree, containsInAnyOrder(javaccFile.getCanonicalFile(), javaFile.getCanonicalFile()));
}
 
Example #2
Source Project: javaccPlugin   Author: johnmartel   File: JavaccCompilerInputOutputConfigurationTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getCompleteSourceTreeExcludesOutputFolder() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class);
    File outputFile = addTaskWithSourceFile(project, "compileJavaccGenerated", "output/Generated.java", JavaCompile.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource())
        .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class))
        .build();

    FileTree completeSourceTree = configuration.getCompleteSourceTree();

    assertThat(completeSourceTree, contains(javaccFile.getCanonicalFile()));
    assertThat(completeSourceTree, not(contains(outputFile.getCanonicalFile())));
}
 
Example #3
Source Project: javaccPlugin   Author: johnmartel   File: JavaccCompilerInputOutputConfigurationTest.java    License: MIT License 5 votes vote down vote up
private File addTaskWithSourceFile(Project project, String taskName, String sourceFileName, Class<? extends SourceTask> taskType) throws IOException {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(Task.TASK_TYPE, taskType);

    SourceTask compileJava = (SourceTask) project.task(options, taskName);
    File javaFile = testFolder.newFile(sourceFileName);
    compileJava.source(javaFile.getCanonicalFile());

    return javaFile;
}
 
Example #4
Source Project: javaccPlugin   Author: johnmartel   File: JavaccCompilerInputOutputConfigurationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void getCompleteSourceTreeReturnsSourceWhenNoJavaCompileTask() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource())
        .build();

    FileTree completeSourceTree = configuration.getCompleteSourceTree();

    assertThat(completeSourceTree, contains(javaccFile.getCanonicalFile()));
}
 
Example #5
Source Project: gradle-avro-plugin   Author: davidmc24   File: AvroPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private static void configureTaskDependencies(final Project project, final SourceSet sourceSet,
                                              final TaskProvider<GenerateAvroJavaTask> javaTaskProvider) {
    project.getPluginManager().withPlugin("org.jetbrains.kotlin.jvm", appliedPlugin ->
        project.getTasks()
            .withType(SourceTask.class)
            .matching(task -> sourceSet.getCompileTaskName("kotlin").equals(task.getName()))
            .configureEach(task ->
                task.source(javaTaskProvider.get().getOutputs())
            )
    );
}
 
Example #6
Source Project: web3j-gradle-plugin   Author: web3j   File: Web3jPlugin.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Configures code generation tasks for the Solidity source sets defined in the project (e.g.
 * main, test).
 *
 * <p>The generated task name for the <code>main</code> source set will be <code>
 * generateContractWrappers</code>, and for <code>test</code> <code>generateTestContractWrappers
 * </code>.
 */
private void configure(final Project project, final SourceSet sourceSet) {

    final Web3jExtension extension =
            (Web3jExtension) InvokerHelper.getProperty(project, Web3jExtension.NAME);

    final File outputDir = buildSourceDir(extension, sourceSet);

    // Add source set to the project Java source sets
    sourceSet.getJava().srcDir(outputDir);

    final String srcSetName =
            sourceSet.getName().equals("main")
                    ? ""
                    : capitalize((CharSequence) sourceSet.getName());

    final String generateTaskName = "generate" + srcSetName + "ContractWrappers";

    final GenerateContractWrappers task =
            project.getTasks().create(generateTaskName, GenerateContractWrappers.class);

    // Set the sources for the generation task
    task.setSource(buildSourceDirectorySet(sourceSet));
    task.setDescription(
            "Generates " + sourceSet.getName() + " Java contract wrappers from Solidity ABIs.");

    // Set the task output directory
    task.getOutputs().dir(outputDir);

    // Set the task generated package name, classpath and group
    task.setGeneratedJavaPackageName(extension.getGeneratedPackageName());
    task.setUseNativeJavaTypes(extension.getUseNativeJavaTypes());
    task.setGroup(Web3jExtension.NAME);

    // Set task excluded contracts
    task.setExcludedContracts(extension.getExcludedContracts());
    task.setIncludedContracts(extension.getIncludedContracts());

    // Set the contract addresses length (default 160)
    task.setAddressLength(extension.getAddressBitLength());

    task.dependsOn(
            project.getTasks()
                    .withType(SolidityCompile.class)
                    .named("compile" + srcSetName + "Solidity"));

    final SourceTask compileJava =
            (SourceTask) project.getTasks().getByName("compile" + srcSetName + "Java");

    compileJava.source(task.getOutputs().getFiles().getSingleFile());
    compileJava.dependsOn(task);
}