org.gradle.api.tasks.SourceSetContainer Java Examples

The following examples show how to use org.gradle.api.tasks.SourceSetContainer. 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 File: JigsawPlugin.java    From gradle-java-modules with Apache License 2.0 7 votes vote down vote up
private void configureCompileTestJavaTask(final Project project) {
    final JavaCompile compileTestJava = (JavaCompile) project.getTasks()
            .findByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    compileTestJava.getInputs().property("moduleName", module.geName());
    compileTestJava.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(compileTestJava.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("junit");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath());
            compileTestJava.getOptions().setCompilerArgs(args);
            compileTestJava.setClasspath(project.files());
        }
    });
}
 
Example #2
Source File: MavenProjectWrapper.java    From gradle-plugins with MIT License 6 votes vote down vote up
public MavenProjectWrapper(Project project, File pomFile) throws IOException, XmlPullParserException {
    this.project = project;
    this.pomFile = pomFile;

    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader(pomFile));

    setModel(model);

    getBuild().setDirectory(project.getBuildDir().getAbsolutePath());

    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();

    SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    getBuild().setSourceDirectory(main.getJava().getSrcDirs().iterator().next().getAbsolutePath());
    getBuild().setOutputDirectory(main.getJava().getOutputDir().getAbsolutePath());

    SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    getBuild().setTestSourceDirectory(test.getJava().getSrcDirs().iterator().next().getAbsolutePath());
    getBuild().setTestOutputDirectory(test.getJava().getOutputDir().getAbsolutePath());

    setArtifact(new ProjectArtifact(this));
}
 
Example #3
Source File: MavenProjectWrapper.java    From gradle-plugins with MIT License 6 votes vote down vote up
public MavenProjectWrapper(Project project, File pomFile) throws IOException, XmlPullParserException {
    this.project = project;
    this.pomFile = pomFile;

    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader(pomFile));

    setModel(model);

    getBuild().setDirectory(project.getBuildDir().getAbsolutePath());

    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();

    SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    getBuild().setSourceDirectory(main.getJava().getSrcDirs().iterator().next().getAbsolutePath());
    getBuild().setOutputDirectory(main.getJava().getOutputDir().getAbsolutePath());

    SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    getBuild().setTestSourceDirectory(test.getJava().getSrcDirs().iterator().next().getAbsolutePath());
    getBuild().setTestOutputDirectory(test.getJava().getOutputDir().getAbsolutePath());

    setArtifact(new ProjectArtifact(this));
}
 
Example #4
Source File: JigsawPlugin.java    From gradle-java-modules with Apache License 2.0 6 votes vote down vote up
private void configureTestTask(final Project project) {
    final Test testTask = (Test) project.getTasks().findByName(JavaPlugin.TEST_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    testTask.getInputs().property("moduleName", module.geName());
    testTask.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(testTask.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("ALL-MODULE-PATH");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getOutputDir());
            testTask.setJvmArgs(args);
            testTask.setClasspath(project.files());
        }
    });
}
 
Example #5
Source File: DocletPlugin.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Project project) {
	Configuration config = project.getConfigurations().create("crnkJavaDocToXml");

	project.getDependencies().add("crnkJavaDocToXml", "com.github.markusbernhardt:xml-doclet:1.0.5");

	Javadoc task = project.getTasks().create(TASK_NAME, Javadoc.class);
	task.setTitle(null);
	task.setDestinationDir(new File(project.getBuildDir(), "crnk-xml-docs"));

	MinimalJavadocOptions options = task.getOptions();
	options.setDoclet("com.github.markusbernhardt.xmldoclet.XmlDoclet");
	options.setMemberLevel(JavadocMemberLevel.PRIVATE);
	options.setDocletpath(new ArrayList<>(config.getFiles()));

	SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
	SourceSet mainSourceSet = sourceSets.getByName("main");
	task.source(mainSourceSet.getAllJava());
	task.setClasspath(mainSourceSet.getCompileClasspath());
}
 
Example #6
Source File: GeneratePlugin.java    From jpa2ddl with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Project project) {
	GeneratePluginExtension generatePluginExtension = project.getExtensions().create(EXTENSION_NAME,
			GeneratePluginExtension.class, project);

	GenerateTask generateTask = project.getTasks().create(TASK_NAME, GenerateTask.class);
	generateTask.setGroup(BasePlugin.BUILD_GROUP);
	generateTask.setDescription("Generates DDL scripts based on JPA model.");
	generateTask.setExtension(generatePluginExtension);
	generateTask.dependsOn(JavaBasePlugin.BUILD_TASK_NAME);


	project.afterEvaluate(evaluatedProject -> {
		fillDefaults(evaluatedProject, generatePluginExtension);
		SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
		Set<File> paths;
		if (sourceSets != null) {
			UnionFileCollection mainClasspath = (UnionFileCollection) sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
			paths = mainClasspath.getFiles();
		} else {
			paths = new HashSet<>();
		}
		generateTask.setOutputClassesDirs(paths);
	});
}
 
Example #7
Source File: OptionalDependenciesPlugin.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Project project) {
	Configuration optional = project.getConfigurations().create(OPTIONAL_CONFIGURATION_NAME);
	optional.attributes((attributes) -> attributes.attribute(Usage.USAGE_ATTRIBUTE,
			project.getObjects().named(Usage.class, Usage.JAVA_RUNTIME)));
	project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
		SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
		                                       .getSourceSets();
		sourceSets.all((sourceSet) -> {
			sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(optional));
			sourceSet.setRuntimeClasspath(sourceSet.getRuntimeClasspath().plus(optional));
		});
		project.getTasks().withType(Javadoc.class)
		       .all((javadoc) -> javadoc.setClasspath(javadoc.getClasspath().plus(optional)));
	});
	project.getPlugins().withType(EclipsePlugin.class,
			(eclipsePlugin) -> project.getExtensions().getByType(EclipseModel.class)
			                          .classpath((classpath) -> classpath.getPlusConfigurations().add(optional)));
}
 
Example #8
Source File: ClojureCommonPlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(ClojureBasePlugin.class);
  project.getPlugins().apply(JavaPlugin.class);

  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  configureDev(project, sourceSets);
  configureDependencyConstraints(project);

  configureDevSource(sourceSets, SourceSet::getResources);
}
 
Example #9
Source File: EntitasGradleProject.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public List<String> getSrcDirs() {
    SourceSetContainer sourceSets = javaConvention.getSourceSets();
    SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    return mainSourceSet.getAllSource().getSrcDirs().stream().map(f -> {
        try {
            return f.getCanonicalPath();
        } catch (IOException e) {
            return "";
        }
    }).collect(Collectors.toList());
}
 
Example #10
Source File: AggregateJacocoReportPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JacocoPlugin.class);

    project.getTasks().register("aggregateJacocoReport", JacocoReport.class, reportTask -> {

        reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
        reportTask.setDescription(String.format("Generates aggregated code coverage report for the %s project.", project.getPath()));

        project.allprojects(subproject -> {
            subproject.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
                SourceSetContainer sourceSets = subproject.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                reportTask.sourceSets(main);
            });

            subproject.getTasks()
                    .withType(Test.class)
                    .forEach(reportTask::executionData);
        });

        JacocoPluginExtension reportingExtension = project.getExtensions().getByType(JacocoPluginExtension.class);
        reportTask.getReports().getHtml().setEnabled(true);
        reportTask.getReports().all(report -> {
            if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + report.getName())));
            }
            else {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName())));
            }
        });
    });


}
 
Example #11
Source File: AggregateJacocoReportPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JacocoPlugin.class);

    project.getTasks().register("aggregateJacocoReport", JacocoReport.class, reportTask -> {

        reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
        reportTask.setDescription(String.format("Generates aggregated code coverage report for the %s project.", project.getPath()));

        project.allprojects(subproject -> {
            subproject.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
                SourceSetContainer sourceSets = subproject.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                reportTask.sourceSets(main);
            });

            subproject.getTasks()
                    .withType(Test.class)
                    .forEach(reportTask::executionData);
        });

        JacocoPluginExtension reportingExtension = project.getExtensions().getByType(JacocoPluginExtension.class);
        reportTask.getReports().getHtml().setEnabled(true);
        reportTask.getReports().all(report -> {
            if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + report.getName())));
            }
            else {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName())));
            }
        });
    });


}
 
Example #12
Source File: ClojurePlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(ClojureBasePlugin.class);
  project.getPlugins().apply(ClojureCommonPlugin.class);

  ClojureExtension extension = project.getExtensions().getByType(ClojureExtension.class);
  configureBuilds(project, extension);

  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  ClojureCommonPlugin.configureDevSource(sourceSets, sourceSet -> {
    ClojureSourceSet src = (ClojureSourceSet) new DslObject(sourceSet).getConvention().getPlugins().get("clojure");
    return src.getClojure();
  });
}
 
Example #13
Source File: ClojureBasePlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
private void configureSourceSetDefaults(Project project, ClojureExtension extension) {
  project.getExtensions().getByType(SourceSetContainer.class).all(sourceSet -> {
    ClojureSourceSet clojureSourceSet = new DefaultClojureSourceSet("clojure", objects);
    new DslObject(sourceSet).getConvention().getPlugins().put("clojure", clojureSourceSet);

    clojureSourceSet.getClojure().srcDir(String.format("src/%s/clojure", sourceSet.getName()));
    // in case the clojure source overlaps with the resources source
    sourceSet.getResources().getFilter().exclude(element -> clojureSourceSet.getClojure().contains(element.getFile()));
    sourceSet.getAllSource().source(clojureSourceSet.getClojure());

    ClojureBuild build = extension.getBuilds().create(sourceSet.getName());
    build.getSourceSet().set(sourceSet);

    project.getTasks().named(sourceSet.getClassesTaskName(), task -> {
      task.dependsOn(build.getTaskName("compile"));
      task.dependsOn(build.getTaskName("check"));
    });

    Provider<FileCollection> output = project.provider(() -> {
      if (build.isCompilerConfigured()) {
        return project.files(build.getOutputDir());
      } else {
        return clojureSourceSet.getClojure().getSourceDirectories();
      }
    });

    ((DefaultSourceSetOutput) sourceSet.getOutput()).getClassesDirs().from(output);
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(build.getTaskName("compile"));
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(build.getTaskName("check"));
  });
}
 
Example #14
Source File: ClojureCommonBasePlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
private void configureToolsConfigurations(Project project) {
  Configuration tools = project.getConfigurations().create(TOOLS_CONFIGURATION_NAME);
  tools.defaultDependencies(deps -> {
    deps.add(project.getDependencies().create("dev.clojurephant:clojurephant-tools:" + getVersion()));
  });

  // TODO does this JAR get included via shadow or application plugins?
  project.getExtensions().getByType(SourceSetContainer.class).all(sourceSet -> {
    project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(tools);
    project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(tools);
  });
}
 
Example #15
Source File: TestProject.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public List<String> getSrcDirs() {
    SourceSetContainer sourceSets = javaConvention.getSourceSets();
    SourceSet mainSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    return mainSourceSet.getAllSource().getSrcDirs().stream().map(f -> {
        try {
            return f.getCanonicalPath();
        } catch (IOException e) {
            return "";
        }
    }).collect(Collectors.toList());
}
 
Example #16
Source File: ClojureCommonBasePlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPluginManager().apply(JavaBasePlugin.class);

  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  configureSourceSets(project, sourceSets);
  configureToolsConfigurations(project);
}
 
Example #17
Source File: ClojureCommonPlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
public static void configureDevSource(SourceSetContainer sourceSets, Function<SourceSet, SourceDirectorySet> languageMapper) {
  SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
  SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
  SourceSet dev = sourceSets.getByName(DEV_SOURCE_SET_NAME);
  languageMapper.apply(dev).source(languageMapper.apply(test));
  languageMapper.apply(dev).source(languageMapper.apply(main));
}
 
Example #18
Source File: ClojureScriptPlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(ClojureScriptBasePlugin.class);
  project.getPlugins().apply(ClojureCommonPlugin.class);

  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  ClojureCommonPlugin.configureDevSource(sourceSets, sourceSet -> {
    ClojureScriptSourceSet src = (ClojureScriptSourceSet) new DslObject(sourceSet).getConvention().getPlugins().get("clojurescript");
    return src.getClojureScript();
  });
}
 
Example #19
Source File: ClojureScriptBasePlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
private void configureSourceSetDefaults(Project project, ClojureScriptExtension extension) {
  project.getExtensions().getByType(SourceSetContainer.class).all((SourceSet sourceSet) -> {
    ClojureScriptSourceSet clojurescriptSourceSet = new DefaultClojureScriptSourceSet("clojurescript", objects);
    new DslObject(sourceSet).getConvention().getPlugins().put("clojurescript", clojurescriptSourceSet);

    clojurescriptSourceSet.getClojureScript().srcDir(String.format("src/%s/clojurescript", sourceSet.getName()));
    // in case the clojure source overlaps with the resources source
    sourceSet.getResources().getFilter().exclude(element -> clojurescriptSourceSet.getClojureScript().contains(element.getFile()));
    sourceSet.getAllSource().source(clojurescriptSourceSet.getClojureScript());

    ClojureScriptBuild build = extension.getBuilds().create(sourceSet.getName());
    build.getSourceSet().set(sourceSet);

    project.getTasks().named(sourceSet.getClassesTaskName(), task -> {
      task.dependsOn(build.getTaskName("compile"));
    });

    Provider<FileCollection> output = project.provider(() -> {
      if (build.isCompilerConfigured()) {
        return project.files(build.getOutputDir());
      } else {
        return clojurescriptSourceSet.getClojureScript().getSourceDirectories();
      }
    });

    ((DefaultSourceSetOutput) sourceSet.getOutput()).getClassesDirs().from(output);

    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(build.getTaskName("compile"));
  });
}
 
Example #20
Source File: RuntimeClassLoaderFactory.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
public Set<File> getProjectLibraries() {
    Set<File> classpath = new HashSet<>();

    SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");

    if (sourceSets != null) {
        SortedSet<String> availableSourceSetNames = sourceSets.getNames();
        for (String sourceSetName : Arrays.asList("main", "test", "integrationTest")) {
            if (availableSourceSetNames.contains(sourceSetName)) {
                SourceSet sourceSet = sourceSets.getByName(sourceSetName);
                classpath.addAll(sourceSet.getOutput().getClassesDirs().getFiles());
                classpath.add(sourceSet.getOutput().getResourcesDir());
            }
        }
    }

    // add  dependencies from configured gradle configuration to url (usually test or integrationTest)
    GeneratorConfig generatorConfiguration = project.getExtensions().getByType(GeneratorExtension.class);
    String configurationName = generatorConfiguration.getRuntime().getConfiguration();

    ConfigurationContainer configurations = project.getConfigurations();
    Configuration runtimeConfiguration = configurations.findByName(configurationName + "Runtime");
    if (runtimeConfiguration == null) {
        runtimeConfiguration = configurations.getByName(configurationName);
    }
    classpath.addAll(runtimeConfiguration.getFiles());

    for (File file : classpath) {
        LOGGER.debug("classpath entry: {}", file);
    }

    return classpath;
}
 
Example #21
Source File: GradleProject.java    From juniversal with MIT License 5 votes vote down vote up
public SourceSet getSourceSet(SourceType sourceType) {
    JavaPluginConvention javaPluginConvention;
    try {
        javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    } catch (IllegalStateException e) {
        throw new RuntimeException("Gradle project apparently isn't a Java project--it doesn't use the Java plugin");
    }

    SourceSetContainer sourceSets = javaPluginConvention.getSourceSets();
    return sourceSets.getByName(getSourceSetName(sourceType));
}
 
Example #22
Source File: JarConfigurator.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
public void createBundleJar(File manifestFile) {
  Jar jarTask = (Jar) project.getTasks().findByName(JAR_TASK_NAME);

  if (jarTask == null)
    throw new GradleException("Unable to find the gradle task: " + JAR_TASK_NAME);

  jarTask.manifest((Manifest mf) -> mf.from(manifestFile));
  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  jarTask.from(sourceSets.getByName(JAVA_MAIN_SOURCE_SET_NAME).getOutput());
  jarTask.into(
      JAR_LIB_DESTINATION,
      (CopySpec cs) -> cs.from(project.getConfigurations().getByName(RELEASE_CONFIG_NAME)));
}
 
Example #23
Source File: QuarkusTestNative.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public QuarkusTestNative() {
    setDescription("Runs native image tests");
    setGroup("verification");

    JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class);
    SourceSetContainer sourceSets = javaPlugin.getSourceSets();
    SourceSet sourceSet = sourceSets.findByName(QuarkusPlugin.NATIVE_TEST_SOURCE_SET_NAME);

    setTestClassesDirs(sourceSet.getOutput().getClassesDirs());
    setClasspath(sourceSet.getRuntimeClasspath());
}
 
Example #24
Source File: Web3jPlugin.java    From web3j-gradle-plugin with Apache License 2.0 5 votes vote down vote up
public void apply(final Project target) {
    target.getPluginManager().apply(JavaPlugin.class);
    target.getPluginManager().apply(SolidityPlugin.class);
    target.getExtensions().create(Web3jExtension.NAME, Web3jExtension.class, target);
    target.getDependencies().add("implementation", "org.web3j:core:" + getProjectVersion());

    final SourceSetContainer sourceSets =
            target.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();

    target.afterEvaluate(p -> sourceSets.all(sourceSet -> configure(target, sourceSet)));
}
 
Example #25
Source File: ConfigBuild.java    From client-gradle-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private List<Path> getClassPathFromSourceSets() {
    List<Path> classPath = Collections.emptyList();
    SourceSetContainer sourceSetContainer = (SourceSetContainer) project.getProperties().get("sourceSets");
    SourceSet mainSourceSet = sourceSetContainer.findByName("main");
    if (mainSourceSet != null) {
        classPath = mainSourceSet.getRuntimeClasspath().getFiles().stream()
                .filter(File::exists)
                .map(File::toPath).collect(Collectors.toList());
    }
    return classPath;
}
 
Example #26
Source File: AvroPlugin.java    From gradle-avro-plugin with Apache License 2.0 4 votes vote down vote up
private static SourceSetContainer getSourceSets(Project project) {
    return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
}
 
Example #27
Source File: ClojureCommonBasePlugin.java    From clojurephant with Apache License 2.0 4 votes vote down vote up
private void configureSourceSets(Project project, SourceSetContainer sourceSets) {
  sourceSets.all(sourceSet -> {
    sourceSet.getResources().exclude("**/.keep");
  });
}
 
Example #28
Source File: ClojureCommonPlugin.java    From clojurephant with 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));
    }
  });
}
 
Example #29
Source File: QuarkusPlugin.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("Convert2Lambda")
private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
    TaskContainer tasks = project.getTasks();
    tasks.create(LIST_EXTENSIONS_TASK_NAME, QuarkusListExtensions.class);
    tasks.create(ADD_EXTENSION_TASK_NAME, QuarkusAddExtension.class);
    tasks.create(REMOVE_EXTENSION_TASK_NAME, QuarkusRemoveExtension.class);
    tasks.create(GENERATE_CONFIG_TASK_NAME, QuarkusGenerateConfig.class);

    Task quarkusBuild = tasks.create(QUARKUS_BUILD_TASK_NAME, QuarkusBuild.class);
    Task quarkusDev = tasks.create(QUARKUS_DEV_TASK_NAME, QuarkusDev.class);
    Task quarkusRemoteDev = tasks.create(QUARKUS_REMOTE_DEV_TASK_NAME, QuarkusRemoteDev.class);
    tasks.create(QUARKUS_TEST_CONFIG_TASK_NAME, QuarkusTestConfig.class);

    Task buildNative = tasks.create(BUILD_NATIVE_TASK_NAME, DefaultTask.class);
    buildNative.finalizedBy(quarkusBuild);
    buildNative.doFirst(t -> project.getLogger()
            .warn("The 'buildNative' task has been deprecated in favor of 'build -Dquarkus.package.type=native'"));

    configureBuildNativeTask(project);

    final Consumer<Test> configureTestTask = t -> {
        // Quarkus test configuration action which should be executed before any Quarkus test
        // Use anonymous classes in order to leverage task avoidance.
        t.doFirst(new Action<Task>() {
            @Override
            public void execute(Task test) {
                quarkusExt.beforeTest(t);
            }
        });
        // also make each task use the JUnit platform since it's the only supported test environment
        t.useJUnitPlatform();
        // quarkusBuild is expected to run after the project has passed the tests
        quarkusBuild.shouldRunAfter(t);
    };

    project.getPlugins().withType(
            BasePlugin.class,
            basePlugin -> tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(quarkusBuild));
    project.getPlugins().withType(
            JavaPlugin.class,
            javaPlugin -> {
                project.afterEvaluate(this::afterEvaluate);

                Task classesTask = tasks.getByName(JavaPlugin.CLASSES_TASK_NAME);
                Task resourcesTask = tasks.getByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME);
                quarkusDev.dependsOn(classesTask, resourcesTask);
                quarkusRemoteDev.dependsOn(classesTask, resourcesTask);
                quarkusBuild.dependsOn(classesTask, resourcesTask, tasks.getByName(JavaPlugin.JAR_TASK_NAME));

                SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
                        .getSourceSets();
                SourceSet nativeTestSourceSet = sourceSets.create(NATIVE_TEST_SOURCE_SET_NAME);
                SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);

                nativeTestSourceSet.setCompileClasspath(
                        nativeTestSourceSet.getCompileClasspath()
                                .plus(mainSourceSet.getOutput())
                                .plus(testSourceSet.getOutput()));

                nativeTestSourceSet.setRuntimeClasspath(
                        nativeTestSourceSet.getRuntimeClasspath()
                                .plus(mainSourceSet.getOutput())
                                .plus(testSourceSet.getOutput()));

                // create a custom configuration to be used for the dependencies of the testNative task
                ConfigurationContainer configurations = project.getConfigurations();
                configurations.maybeCreate(NATIVE_TEST_IMPLEMENTATION_CONFIGURATION_NAME)
                        .extendsFrom(configurations.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME));
                configurations.maybeCreate(NATIVE_TEST_RUNTIME_ONLY_CONFIGURATION_NAME)
                        .extendsFrom(configurations.findByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME));

                Task testNative = tasks.create(TEST_NATIVE_TASK_NAME, QuarkusTestNative.class);
                testNative.dependsOn(quarkusBuild);
                testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName(JavaPlugin.TEST_TASK_NAME)));

                tasks.withType(Test.class).forEach(configureTestTask);
                tasks.withType(Test.class).whenTaskAdded(configureTestTask::accept);
            });
}
 
Example #30
Source File: QuarkusDev.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void addLocalProject(Project project, DevModeContext context, Set<AppArtifactKey> addeDeps, boolean root) {
    final AppArtifactKey key = new AppArtifactKey(project.getGroup().toString(), project.getName());
    if (addeDeps.contains(key)) {
        return;
    }
    final JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
    if (javaConvention == null) {
        return;
    }

    SourceSetContainer sourceSets = javaConvention.getSourceSets();
    SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    Set<String> sourcePaths = new HashSet<>();

    for (File sourceDir : mainSourceSet.getAllJava().getSrcDirs()) {
        if (sourceDir.exists()) {
            sourcePaths.add(sourceDir.getAbsolutePath());
        }
    }
    //TODO: multiple resource directories
    final File resourcesSrcDir = mainSourceSet.getResources().getSourceDirectories().getSingleFile();

    if (sourcePaths.isEmpty() && !resourcesSrcDir.exists()) {
        return;
    }

    String classesDir = QuarkusGradleUtils.getClassesDir(mainSourceSet, project.getBuildDir());

    final String resourcesOutputPath;
    if (resourcesSrcDir.exists()) {
        resourcesOutputPath = mainSourceSet.getOutput().getResourcesDir().getAbsolutePath();
        if (!Files.exists(Paths.get(classesDir))) {
            // currently classesDir can't be null and is expected to exist
            classesDir = resourcesOutputPath;
        }
    } else {
        // currently resources dir should exist
        resourcesOutputPath = classesDir;
    }

    DevModeContext.ModuleInfo wsModuleInfo = new DevModeContext.ModuleInfo(key,
            project.getName(),
            project.getProjectDir().getAbsolutePath(),
            sourcePaths,
            classesDir,
            resourcesSrcDir.getAbsolutePath(),
            resourcesOutputPath);
    if (root) {
        context.setApplicationRoot(wsModuleInfo);
    } else {
        context.getAdditionalModules().add(wsModuleInfo);
    }
    addeDeps.add(key);
}