org.gradle.api.tasks.SourceSet Java Examples

The following examples show how to use org.gradle.api.tasks.SourceSet. 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: GroovyBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 7 votes vote down vote up
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        public void execute(SourceSet sourceSet) {
            final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver);
            new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet);

            groovySourceSet.getGroovy().srcDir(String.format("src/%s/groovy", sourceSet.getName()));
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return groovySourceSet.getGroovy().contains(element.getFile());
                }
            });
            sourceSet.getAllJava().source(groovySourceSet.getGroovy());
            sourceSet.getAllSource().source(groovySourceSet.getGroovy());

            String compileTaskName = sourceSet.getCompileTaskName("groovy");
            GroovyCompile compile = project.getTasks().create(compileTaskName, GroovyCompile.class);
            javaBasePlugin.configureForSourceSet(sourceSet, compile);
            compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription(String.format("Compiles the %s Groovy source.", sourceSet.getName()));
            compile.setSource(groovySourceSet.getGroovy());

            project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
        }
    });
}
 
Example #2
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 #3
Source File: SourcesJarPlugin.java    From gradle-plugins with MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #4
Source File: JavaBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 7 votes vote down vote up
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();
        }
    });
}
 
Example #5
Source File: AspectJPlugin.java    From gradle-plugins with MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(AspectJBasePlugin.class);
    project.getPlugins().apply(JavaBasePlugin.class);

    JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);

    plugin.getSourceSets().all(this::configureSourceSet);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

        DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
        DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);

        Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
        Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());

        testAspectpath.extendsFrom(aspectpath);

        testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
    });
}
 
Example #6
Source File: CpdPluginTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void CpdPlugin_shouldSetCpdCheckSourceEqualsToMainAndTestSourceSetsIfJavaPluginIsApplied(Project project, TaskProvider<Cpd> cpd) {
    // Given:
    String mainFile = "src/main/java/Clazz.java";
    String testFile = "src/test/java/ClazzTest.java";

    // When:
    project.getPlugins().apply(JavaPlugin.class);
    createProjectFiles(project, mainFile, "src/resources/java/message.properties", testFile);

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME, sourceSet -> {
        sourceSet.getJava().srcDir(testFile(JAVA, "de/aaschmid/annotation"));
        sourceSet.getAllJava().srcDir(testFile(JAVA, "de/aaschmid/clazz"));
        sourceSet.getResources().srcDir(testFile(JAVA, "de/aaschmid/foo"));
    });
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME, sourceSet ->
            sourceSet.getJava().srcDir(testFile(JAVA, "de/aaschmid/test")));

    // Then:
    List<File> expected = testFilesRecurseIn(JAVA, "de/aaschmid/annotation", "de/aaschmid/clazz", "de/aaschmid/test");
    expected.add(project.file(mainFile));
    expected.add(project.file(testFile));

    assertThat(cpd.get().getSource()).containsExactlyInAnyOrderElementsOf(expected);
}
 
Example #7
Source File: JavaBasePlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void defineConfigurationsForSourceSet(SourceSet sourceSet, ConfigurationContainer configurations) {
    Configuration compileConfiguration = configurations.maybeCreate(sourceSet.getCompileConfigurationName());
    compileConfiguration.setVisible(false);
    compileConfiguration.setDescription("Dependencies for " + sourceSet + ".");

    Configuration runtimeConfiguration = configurations.maybeCreate(sourceSet.getRuntimeConfigurationName());
    runtimeConfiguration.setVisible(false);
    runtimeConfiguration.extendsFrom(compileConfiguration);
    runtimeConfiguration.setDescription("Runtime dependencies for " + sourceSet + ".");

    Configuration compileOnlyConfiguration = configurations.maybeCreate(sourceSet.getCompileOnlyConfigurationName());
    compileOnlyConfiguration.setVisible(false);
    compileOnlyConfiguration.extendsFrom(compileConfiguration);
    compileOnlyConfiguration.setDescription("Compile dependencies for " + sourceSet + ".");

    Configuration compileClasspathConfiguration = configurations.maybeCreate(sourceSet.getCompileClasspathConfigurationName());
    compileClasspathConfiguration.setVisible(false);
    compileClasspathConfiguration.extendsFrom(compileOnlyConfiguration);
    compileClasspathConfiguration.setDescription("Compile classpath for " + sourceSet + ".");

    sourceSet.setCompileClasspath(compileClasspathConfiguration);
    sourceSet.setRuntimeClasspath(sourceSet.getOutput().plus(runtimeConfiguration));
}
 
Example #8
Source File: SourceSetUtils.java    From transport with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static String getConfigurationNameForSourceSet(SourceSet sourceSet, ConfigurationType configurationType) {
  final String configName;
  switch (configurationType) {
    case ANNOTATION_PROCESSOR:
      configName = sourceSet.getAnnotationProcessorConfigurationName();
      break;
    case IMPLEMENTATION:
      configName = sourceSet.getImplementationConfigurationName();
      break;
    case COMPILE_ONLY:
      configName = sourceSet.getCompileOnlyConfigurationName();
      break;
    case RUNTIME_CLASSPATH:
      configName = sourceSet.getRuntimeClasspathConfigurationName();
      break;
    case RUNTIME_ONLY:
      configName = sourceSet.getRuntimeOnlyConfigurationName();
      break;
    default:
      throw new UnsupportedOperationException("Configuration " + configurationType + " not supported");
  }
  return configName;
}
 
Example #9
Source File: PlayApplicationPlugin.java    From playframework with Apache License 2.0 6 votes vote down vote up
private void configureJavaAndScalaSourceSet(Project project) {
    SourceSet mainSourceSet = PlayPluginHelper.getMainJavaSourceSet(project);
    SourceDirectorySet mainResourcesDirectorySet = mainSourceSet.getResources();
    mainResourcesDirectorySet.setSrcDirs(Arrays.asList("conf"));

    SourceDirectorySet mainScalaSourceDirectorySet = PlayPluginHelper.getMainScalaSourceDirectorySet(project);
    mainScalaSourceDirectorySet.setSrcDirs(Arrays.asList("app"));
    mainScalaSourceDirectorySet.include("**/*.scala", "**/*.java");

    mainScalaSourceDirectorySet.srcDir(getTwirlCompileTask(project).flatMap(task -> task.getOutputDirectory()));
    mainScalaSourceDirectorySet.srcDir(getRoutesCompileTask(project).flatMap(task -> task.getOutputDirectory()));

    SourceDirectorySet testScalaSourceDirectorySet = PlayPluginHelper.getTestScalaSourceDirectorySet(project);
    testScalaSourceDirectorySet.setSrcDirs(Arrays.asList("test"));
    testScalaSourceDirectorySet.include("**/*.scala", "**/*.java");
}
 
Example #10
Source File: DefaultAndroidSourceSet.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public String getPackageConfigurationName() {
    if (isLibrary) {
        if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
            return "publish";
        } else {
            return String.format("%sPublish", name);
        }
    }

    if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
        return "apk";
    } else {
        return String.format("%sApk", name);
    }
}
 
Example #11
Source File: JavaBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #12
Source File: JavaBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #13
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 #14
Source File: ShadedJarPackaging.java    From transport with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a {@link ShadeTask} which generates a shaded JAR containing all runtime dependencies of the platform's
 * {@link SourceSet}
 *
 * TODO: This code is borrowed from the Shade plugin. Call the functionality residing in the Shade plugin once it is
 * available
 */
private TaskProvider<ShadeTask> createShadeTask(Project project, Platform platform, SourceSet sourceSet,
    SourceSet mainSourceSet) {
  TaskProvider<ShadeTask> shadeTask =
      project.getTasks().register(sourceSet.getTaskName("shade", "Jar"), ShadeTask.class, task -> {
        task.setGroup(ShadowJavaPlugin.getSHADOW_GROUP());
        task.setDescription("Create a combined JAR of " + platform.getName() + " output and runtime dependencies");
        task.setClassifier(platform.getName());
        task.getManifest()
            .inheritFrom(project.getTasks().named(mainSourceSet.getJarTaskName(), Jar.class).get().getManifest());
        task.from(sourceSet.getOutput());
        task.setConfigurations(ImmutableList.of(getConfigurationForSourceSet(project, sourceSet, RUNTIME_CLASSPATH)));
        task.exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA");
      });

  // TODO: Figure out why this artifact is generated but not being published in Maven
  project.getArtifacts().add(ShadowBasePlugin.getCONFIGURATION_NAME(), shadeTask);
  return shadeTask;
}
 
Example #15
Source File: AspectJPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(AspectJBasePlugin.class);
    project.getPlugins().apply(JavaBasePlugin.class);

    JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);

    plugin.getSourceSets().all(this::configureSourceSet);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

        DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
        DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);

        Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
        Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());

        testAspectpath.extendsFrom(aspectpath);

        testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
    });
}
 
Example #16
Source File: JavaBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #17
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 #18
Source File: MavenPluginPlugin.java    From gradle-plugins with 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 #19
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 #20
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 #21
Source File: GroovyPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureGroovydoc(final Project project) {
    Groovydoc groovyDoc = project.getTasks().create(GROOVYDOC_TASK_NAME, Groovydoc.class);
    groovyDoc.setDescription("Generates Groovydoc API documentation for the main source code.");
    groovyDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);

    JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
    SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    groovyDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath()));

    GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
    groovyDoc.setSource(groovySourceSet.getGroovy());
}
 
Example #22
Source File: SourceSetUtils.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns the {@link SourceDirectorySet} for a given {@link SourceSet} depending on the language of the sources
 */
static SourceDirectorySet getSourceDirectorySet(SourceSet sourceSet, Language language) {
  switch (language) {
    case JAVA:
      return sourceSet.getJava();
    case SCALA:
      Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
      ScalaSourceSet scalaSourceSet = sourceSetConvention.getPlugin(ScalaSourceSet.class);
      return scalaSourceSet.getScala();
    default:
      throw new UnsupportedOperationException("Language " + language + " not supported");
  }
}
 
Example #23
Source File: TransportPlugin.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Configures SourceSets, dependencies and tasks related to each Transport UDF platform
 */
private void configurePlatform(Project project, Platform platform, SourceSet mainSourceSet, SourceSet testSourceSet,
    File baseOutputDir) {
  SourceSet sourceSet = configureSourceSet(project, platform, mainSourceSet, baseOutputDir);
  configureGenerateWrappersTask(project, platform, mainSourceSet, sourceSet);
  List<TaskProvider<? extends Task>> packagingTasks =
      configurePackagingTasks(project, platform, sourceSet, mainSourceSet);
  // Add Transport tasks to build task dependencies
  project.getTasks().named(LifecycleBasePlugin.BUILD_TASK_NAME).configure(task -> task.dependsOn(packagingTasks));

  TaskProvider<Test> testTask = configureTestTask(project, platform, mainSourceSet, testSourceSet);
  project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(task -> task.dependsOn(testTask));
}
 
Example #24
Source File: AspectJPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureSourceSet(SourceSet sourceSet) {
    DefaultAspectjSourceSet aspectjSourceSet = new DefaultAspectjSourceSet(project.getObjects(), sourceSet);
    new DslObject(sourceSet).getConvention().getPlugins().put("aspectj", aspectjSourceSet);

    aspectjSourceSet.getAspectj().srcDir("src/" + sourceSet.getName() + "/aspectj");
    sourceSet.getResources().getFilter().exclude(element -> aspectjSourceSet.getAspectj().contains(element.getFile()));
    sourceSet.getAllJava().source(aspectjSourceSet.getAspectj());
    sourceSet.getAllSource().source(aspectjSourceSet.getAspectj());

    Configuration aspect = project.getConfigurations().create(aspectjSourceSet.getAspectConfigurationName());
    aspectjSourceSet.setAspectPath(aspect);

    Configuration inpath = project.getConfigurations().create(aspectjSourceSet.getInpathConfigurationName());
    aspectjSourceSet.setInPath(inpath);

    project.getConfigurations().getByName(sourceSet.getImplementationConfigurationName()).extendsFrom(aspect);

    project.getConfigurations().getByName(sourceSet.getCompileOnlyConfigurationName()).extendsFrom(inpath);

    final Provider<AspectjCompile> compileTask = project.getTasks().register(sourceSet.getCompileTaskName("aspectj"), AspectjCompile.class, compile -> {
        JvmPluginsHelper.configureForSourceSet(sourceSet, aspectjSourceSet.getAspectj(), compile, compile.getOptions(), project);
        compile.dependsOn(sourceSet.getCompileJavaTaskName());
        compile.setDescription("Compiles the " + sourceSet.getName() + " AspectJ source.");
        compile.setSource(aspectjSourceSet.getAspectj());
        compile.getAjcOptions().getAspectpath().from(aspectjSourceSet.getAspectPath());
        compile.getAjcOptions().getInpath().from(aspectjSourceSet.getInPath());
    });
    JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, aspectjSourceSet.getAspectj(), project, compileTask, compileTask.map(AspectjCompile::getOptions));

    project.getTasks().named(sourceSet.getClassesTaskName(), task -> task.dependsOn(compileTask));
}
 
Example #25
Source File: GeneratorPlugin.java    From doov with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project target) {
    NamedDomainObjectContainer<ModelMapGenerator> container = target.container(ModelMapGenerator.class,
            name -> new ModelMapGenerator(name, target));
    target.getExtensions().add("doovCodeGen", container);

    JavaCompile compileJava = target.getTasks().withType(JavaCompile.class).getByName("compileJava");
    JavaPluginConvention javaPluginConvention = target.getConvention().findPlugin(JavaPluginConvention.class);
    SourceSet main = javaPluginConvention.getSourceSets().maybeCreate("main");

    container.all(modelMap -> {
        ModelMapGenTask task = target.getTasks().create(modelMap.getName(), ModelMapGenTask.class);
        main.getJava().srcDir(modelMap.getOutputDirectory());

        target.afterEvaluate(project -> {
            task.setClasspath(main.getCompileClasspath());
            task.getBaseClassProperty().set(modelMap.getBaseClass());
            task.getOutputDirectory().set(modelMap.getOutputDirectory());
            task.getOutputResourceDirectory().set(modelMap.getOutputResourceDirectory());
            task.getSourceClassProperty().set(modelMap.getSourceClass());
            task.getFieldClassProperty().set(modelMap.getFieldClass());
            task.getPackageFilter().set(modelMap.getPackageFilter());
            task.getEnumFieldInfo().set(modelMap.getEnumFieldInfo());
            task.getFieldPathProviderProperty().set(modelMap.getFieldPathProvider());
            task.getTypeAdaptersProperty().set(modelMap.getTypeAdapters());
            task.getDslModelPackage().set(modelMap.getDslModelPackage());
            task.getWrapperPackage().set(modelMap.getWrapperPackage());
            task.getFieldInfoPackage().set(modelMap.getFieldInfoPackage());
            task.getDslEntrypointMethods().set(modelMap.getDslEntrypointMethods());

            compileJava.dependsOn(task);
        });

    });

}
 
Example #26
Source File: JavaPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureSourceSets(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();

    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);

    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CONFIGURATION_NAME)));
}
 
Example #27
Source File: SpringJavaFormatPlugin.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private <T extends FormatterTask> T addSourceTask(SourceSet sourceSet, Class<T> taskType, String name,
		String desc) {
	String taskName = sourceSet.getTaskName(name, null);
	T task = this.project.getTasks().create(taskName, taskType);
	task.setDescription(desc + " for " + sourceSet.getName());
	task.setSource(sourceSet.getAllJava());
	return task;
}
 
Example #28
Source File: DefaultAspectjSourceSet.java    From gradle-plugins with MIT License 5 votes vote down vote up
public DefaultAspectjSourceSet(ObjectFactory objectFactory, SourceSet sourceSet) {
    super(sourceSet);

    String name = sourceSet.getName();
    String displayName = ((DefaultSourceSet) sourceSet).getDisplayName();

    aspectj = objectFactory.sourceDirectorySet("aspectj", displayName + " AspectJ source");
    aspectj.getFilter().include("**/*.java", "**/*.aj");
    allAspectj = objectFactory.sourceDirectorySet("all" + name, displayName + " AspectJ source");
    allAspectj.source(aspectj);
    allAspectj.getFilter().include("**/*.aj");
}
 
Example #29
Source File: QuarkusBuild.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Classpath
public FileCollection getClasspath() {
    SourceSet mainSourceSet = QuarkusGradleUtils.getSourceSet(getProject(), SourceSet.MAIN_SOURCE_SET_NAME);
    return mainSourceSet.getCompileClasspath().plus(mainSourceSet.getRuntimeClasspath())
            .plus(mainSourceSet.getAnnotationProcessorPath())
            .plus(mainSourceSet.getResources());
}
 
Example #30
Source File: QuarkusGradleUtils.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static SourceSet getSourceSet(Project project, String sourceSetName) {
    final Convention convention = project.getConvention();
    JavaPluginConvention javaConvention = convention.findPlugin(JavaPluginConvention.class);
    if (javaConvention == null) {
        throw new IllegalArgumentException("The project does not include the Java plugin");
    }
    return javaConvention.getSourceSets().getByName(sourceSetName);
}