Java Code Examples for org.gradle.language.jvm.tasks.ProcessResources

The following examples show how to use org.gradle.language.jvm.tasks.ProcessResources. These examples are extracted from open source projects. 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
public SourceTransformTaskConfig getTransformTask() {
    return new SourceTransformTaskConfig() {
        public String getTaskPrefix() {
            return "process";
        }

        public Class<? extends DefaultTask> getTaskType() {
            return ProcessResources.class;
        }

        public void configureTask(Task task, BinarySpec binary, LanguageSourceSet sourceSet) {
            ProcessResources resourcesTask = (ProcessResources) task;
            JvmResourceSet resourceSet = (JvmResourceSet) sourceSet;
            JvmBinarySpec jvmBinary = (JvmBinarySpec) binary;
            resourcesTask.from(resourceSet.getSource());
            resourcesTask.setDestinationDir(jvmBinary.getResourcesDir());
            jvmBinary.getTasks().getJar().dependsOn(resourcesTask);
        }
    };
}
 
Example 2
private void createProcessResourcesTaskForBinary(final ClassDirectoryBinarySpecInternal binary, final Project target) {
    final BinaryNamingScheme namingScheme = binary.getNamingScheme();
    binary.getSource().withType(JvmResourceSet.class).all(new Action<JvmResourceSet>() {
        public void execute(JvmResourceSet resourceSet) {
            Copy resourcesTask = target.getTasks().create(namingScheme.getTaskName("process", "resources"), ProcessResources.class);
            resourcesTask.setDescription(String.format("Processes %s.", resourceSet));
            new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() {
                public File call() throws Exception {
                    return binary.getResourcesDir();
                }
            });
            binary.getTasks().add(resourcesTask);
            binary.builtBy(resourcesTask);
            resourcesTask.from(resourceSet.getSource());
        }
    });
}
 
Example 3
Source Project: gradle-plugins   Source File: JSassJavaPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JSassWebjarsPlugin.class);

    project.getPlugins().apply(JavaPlugin.class);

    File baseDestinationDir = new File(project.getBuildDir(), "jsass");

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> {
        String taskName = sourceSet.getCompileTaskName("Sass");

        TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register(taskName, SassCompile.class, sassCompile -> {
            sassCompile.setSource(sourceSet.getResources());
            sassCompile.getDestinationDir().set(new File(baseDestinationDir, sourceSet.getName()));
            sassCompile.setGroup(BasePlugin.BUILD_GROUP);
            sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set");
        });

        project.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class)
                .configure(processResources -> processResources.from(sassCompileTaskProvider));
    });
}
 
Example 4
Source Project: gradle-plugins   Source File: JSassJavaPlugin.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JSassWebjarsPlugin.class);

    project.getPlugins().apply(JavaPlugin.class);

    File baseDestinationDir = new File(project.getBuildDir(), "jsass");

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> {
        String taskName = sourceSet.getCompileTaskName("Sass");

        TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register(taskName, SassCompile.class, sassCompile -> {
            sassCompile.setSource(sourceSet.getResources());
            sassCompile.getDestinationDir().set(new File(baseDestinationDir, sourceSet.getName()));
            sassCompile.setGroup(BasePlugin.BUILD_GROUP);
            sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set");
        });

        project.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class)
                .configure(processResources -> processResources.from(sassCompileTaskProvider));
    });
}
 
Example 5
public SourceTransformTaskConfig getTransformTask() {
    return new SourceTransformTaskConfig() {
        public String getTaskPrefix() {
            return "process";
        }

        public Class<? extends DefaultTask> getTaskType() {
            return ProcessResources.class;
        }

        public void configureTask(Task task, BinarySpec binary, LanguageSourceSet sourceSet) {
            ProcessResources resourcesTask = (ProcessResources) task;
            JvmResourceSet resourceSet = (JvmResourceSet) sourceSet;
            JvmBinarySpec jvmBinary = (JvmBinarySpec) binary;
            resourcesTask.from(resourceSet.getSource());
            resourcesTask.setDestinationDir(jvmBinary.getResourcesDir());
            jvmBinary.getTasks().getJar().dependsOn(resourcesTask);
        }
    };
}
 
Example 6
private void createProcessResourcesTaskForBinary(final ClassDirectoryBinarySpecInternal binary, final Project target) {
    final BinaryNamingScheme namingScheme = binary.getNamingScheme();
    binary.getSource().withType(JvmResourceSet.class).all(new Action<JvmResourceSet>() {
        public void execute(JvmResourceSet resourceSet) {
            Copy resourcesTask = target.getTasks().create(namingScheme.getTaskName("process", "resources"), ProcessResources.class);
            resourcesTask.setDescription(String.format("Processes %s.", resourceSet));
            new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() {
                public File call() throws Exception {
                    return binary.getResourcesDir();
                }
            });
            binary.getTasks().add(resourcesTask);
            binary.builtBy(resourcesTask);
            resourcesTask.from(resourceSet.getSource());
        }
    });
}
 
Example 7
Source Project: javaide   Source File: JavaBasePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void createProcessResourcesTaskForBinary(final SourceSet sourceSet, SourceDirectorySet resourceSet, final Project target) {
    Copy resourcesTask = target.getTasks().create(sourceSet.getProcessResourcesTaskName(), ProcessResources.class);
    resourcesTask.setDescription("Processes " + resourceSet + ".");
    new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() {
        public File call() throws Exception {
            return sourceSet.getOutput().getResourcesDir();
        }
    });
    resourcesTask.from(resourceSet);
}
 
Example 8
Source Project: gradle-plugins   Source File: MavenPluginPlugin.java    License: MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    MavenPublishJavaPlugin mavenPublishJavaPlugin = project.getPlugins().apply(MavenPublishJavaPlugin.class);

    // https://github.com/gradle/gradle/issues/10555#issue-492150084
    if (project.getGradle().getGradleVersion().matches("5\\.6(\\.[12])?")) {
        mavenPublishJavaPlugin.getPublication().getPom().withXml(xmlProvider ->
                xmlProvider.asNode().appendNode("packaging", "maven-plugin")
        );
    }
    else {
        mavenPublishJavaPlugin.getPublication().getPom().setPackaging("maven-plugin");
    }

    TaskProvider<GenerateMavenPom> generateMavenPom = project.getTasks().named("generatePomFileForMavenJavaPublication", GenerateMavenPom.class);

    TaskProvider<DescriptorGeneratorTask> descriptorGeneratorTaskProvider = project.getTasks().register("generateMavenPluginDescriptor", DescriptorGeneratorTask.class, generateMavenPluginDescriptor -> {

        generateMavenPluginDescriptor.dependsOn(generateMavenPom);
        generateMavenPluginDescriptor.getPomFile().set(generateMavenPom.get().getDestination());

        generateMavenPluginDescriptor.getOutputDirectory().set(
                project.getLayout().getBuildDirectory().dir("maven-plugin")
        );

        SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main");
        generateMavenPluginDescriptor.getSourceDirectories().from(main.getAllJava().getSourceDirectories());
        JavaCompile javaCompile = (JavaCompile) project.getTasks().getByName(main.getCompileJavaTaskName());

        generateMavenPluginDescriptor.getClassesDirectories().from(javaCompile);
        generateMavenPluginDescriptor.getEncoding().convention(javaCompile.getOptions().getEncoding());
    });

    project.getTasks().named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, ProcessResources.class)
            .configure(processResources -> processResources.from(descriptorGeneratorTaskProvider));
}
 
Example 9
Source Project: gradle-plugins   Source File: MavenPluginPlugin.java    License: MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    MavenPublishJavaPlugin mavenPublishJavaPlugin = project.getPlugins().apply(MavenPublishJavaPlugin.class);

    // https://github.com/gradle/gradle/issues/10555#issue-492150084
    if (project.getGradle().getGradleVersion().matches("5\\.6(\\.[12])?")) {
        mavenPublishJavaPlugin.getPublication().getPom().withXml(xmlProvider ->
                xmlProvider.asNode().appendNode("packaging", "maven-plugin")
        );
    }
    else {
        mavenPublishJavaPlugin.getPublication().getPom().setPackaging("maven-plugin");
    }

    TaskProvider<GenerateMavenPom> generateMavenPom = project.getTasks().named("generatePomFileForMavenJavaPublication", GenerateMavenPom.class);

    TaskProvider<DescriptorGeneratorTask> descriptorGeneratorTaskProvider = project.getTasks().register("generateMavenPluginDescriptor", DescriptorGeneratorTask.class, generateMavenPluginDescriptor -> {

        generateMavenPluginDescriptor.dependsOn(generateMavenPom);
        generateMavenPluginDescriptor.getPomFile().set(generateMavenPom.get().getDestination());

        generateMavenPluginDescriptor.getOutputDirectory().set(
                project.getLayout().getBuildDirectory().dir("maven-plugin")
        );

        SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main");
        generateMavenPluginDescriptor.getSourceDirectories().from(main.getAllJava().getSourceDirectories());
        JavaCompile javaCompile = (JavaCompile) project.getTasks().getByName(main.getCompileJavaTaskName());

        generateMavenPluginDescriptor.getClassesDirectories().from(javaCompile);
        generateMavenPluginDescriptor.getEncoding().convention(javaCompile.getOptions().getEncoding());
    });

    project.getTasks().named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, ProcessResources.class)
            .configure(processResources -> processResources.from(descriptorGeneratorTaskProvider));
}
 
Example 10
Source Project: clojurephant   Source File: ClojureCommonPlugin.java    License: Apache License 2.0 4 votes vote down vote up
private void configureDev(Project project, SourceSetContainer sourceSets) {
  SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
  SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
  SourceSet dev = sourceSets.create(DEV_SOURCE_SET_NAME);

  Configuration nrepl = project.getConfigurations().create(NREPL_CONFIGURATION_NAME);
  project.getDependencies().add(NREPL_CONFIGURATION_NAME, "nrepl:nrepl:0.6.0");

  project.getConfigurations().getByName(dev.getCompileClasspathConfigurationName()).extendsFrom(nrepl);
  project.getConfigurations().getByName(dev.getRuntimeClasspathConfigurationName()).extendsFrom(nrepl);

  Function<SourceSet, FileCollection> nonClojureOutput = sourceSet -> {
    FileCollection allOutput = sourceSet.getOutput();
    return allOutput.filter((File file) -> {
      return project.getTasks().stream()
          .filter(task -> task instanceof ClojureCompile || task instanceof ClojureScriptCompile || task instanceof ProcessResources)
          .allMatch(task -> !task.getOutputs().getFiles().contains(file));
    });
  };

  dev.setCompileClasspath(project.files(
      test.getOutput(),
      main.getOutput(),
      project.getConfigurations().getByName(dev.getCompileClasspathConfigurationName())));
  dev.setRuntimeClasspath(project.files(
      dev.getAllSource().getSourceDirectories(),
      nonClojureOutput.apply(dev),
      nonClojureOutput.apply(test),
      nonClojureOutput.apply(main),
      project.getConfigurations().getByName(dev.getRuntimeClasspathConfigurationName())));

  Consumer<Function<SourceSet, String>> devExtendsTest = getConfName -> {
    Configuration devConf = project.getConfigurations().getByName(getConfName.apply(dev));
    Configuration testConf = project.getConfigurations().getByName(getConfName.apply(test));
    devConf.extendsFrom(testConf);
  };

  devExtendsTest.accept(SourceSet::getImplementationConfigurationName);
  devExtendsTest.accept(SourceSet::getRuntimeOnlyConfigurationName);

  TaskProvider<ClojureNRepl> repl = project.getTasks().register(NREPL_TASK_NAME, ClojureNRepl.class, task -> {
    task.setGroup("run");
    task.setDescription("Starts an nREPL server.");
    task.setClasspath(dev.getRuntimeClasspath());
  });

  // if you only ask for the REPL task, don't pre-compile/check the Clojure code (besides the dev one
  // for the user namespace)
  project.getGradle().getTaskGraph().whenReady(graph -> {
    // using this string concat approach to avoid realizing the task provider, if it's not needed
    if (!graph.hasTask(project.getPath() + NREPL_TASK_NAME)) {
      return;
    }
    Set<Task> selectedTasks = new HashSet<>(graph.getAllTasks());

    Queue<Task> toProcess = new LinkedList<>();
    toProcess.add(repl.get());

    Set<Task> toDisable = new HashSet<>();

    while (!toProcess.isEmpty()) {
      Task next = toProcess.remove();
      selectedTasks.remove(next);

      if (next instanceof ClojureCompile || next instanceof ClojureScriptCompile) {
        toDisable.add(next);
      } else if (next instanceof ClojureCheck && !"checkDevClojure".equals(next.getName())) {
        toDisable.add(next);
      }

      graph.getDependencies(next).forEach(toProcess::add);
    }

    // if empty, only the REPL was requested to run, so we can optimize for that use case
    if (selectedTasks.isEmpty()) {
      toDisable.forEach(task -> task.setEnabled(false));
    }
  });
}