Search in sources :

Example 21 with SourceSet

use of org.gradle.api.tasks.SourceSet in project rest.li by linkedin.

the class PegasusPlugin method configureAvroSchemaGeneration.

@SuppressWarnings("deprecation")
protected void configureAvroSchemaGeneration(Project project, SourceSet sourceSet) {
    File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
    File avroDir = project.file(getGeneratedDirPath(project, sourceSet, AVRO_SCHEMA_GEN_TYPE) + File.separatorChar + "avro");
    // generate avro schema files from data schema
    Task generateAvroSchemaTask = project.getTasks().create(sourceSet.getTaskName("generate", "avroSchema"), GenerateAvroSchemaTask.class, task -> {
        task.setInputDir(dataSchemaDir);
        task.setDestinationDir(avroDir);
        task.setResolverPath(getDataModelConfig(project, sourceSet));
        task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
        if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
            task.setEnableArgFile(true);
        }
        task.onlyIf(t -> {
            if (task.getInputDir().exists()) {
                @SuppressWarnings("unchecked") Map<String, PegasusOptions> pegasusOptions = (Map<String, PegasusOptions>) project.getExtensions().getExtraProperties().get("pegasus");
                if (pegasusOptions.get(sourceSet.getName()).hasGenerationMode(PegasusOptions.GenerationMode.AVRO)) {
                    return true;
                }
            }
            return !project.getConfigurations().getByName("avroSchemaGenerator").isEmpty();
        });
        task.doFirst(new CacheableAction<>(t -> deleteGeneratedDir(project, sourceSet, AVRO_SCHEMA_GEN_TYPE)));
    });
    project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(generateAvroSchemaTask);
    // create avro schema jar file
    Task avroSchemaJarTask = project.getTasks().create(sourceSet.getName() + "AvroSchemaJar", Jar.class, task -> {
        // add path prefix to each file in the data schema directory
        task.from(avroDir, copySpec -> copySpec.eachFile(fileCopyDetails -> fileCopyDetails.setPath("avro" + File.separatorChar + fileCopyDetails.getPath())));
        // FIXME change to #getArchiveAppendix().set(...); breaks backwards-compatibility before 5.1
        task.setAppendix(getAppendix(sourceSet, "avro-schema"));
        task.setDescription("Generate an avro schema jar");
    });
    if (!isTestSourceSet(sourceSet)) {
        project.getArtifacts().add("avroSchema", avroSchemaJarTask);
    } else {
        project.getArtifacts().add("testAvroSchema", avroSchemaJarTask);
    }
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) Arrays(java.util.Arrays) PublishRestModelTask(com.linkedin.pegasus.gradle.tasks.PublishRestModelTask) ValidateExtensionSchemaTask(com.linkedin.pegasus.gradle.tasks.ValidateExtensionSchemaTask) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) CheckSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask) EclipsePlugin(org.gradle.plugins.ide.eclipse.EclipsePlugin) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) Locale(java.util.Locale) Map(java.util.Map) TranslateSchemasTask(com.linkedin.pegasus.gradle.tasks.TranslateSchemasTask) CheckPegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask) Method(java.lang.reflect.Method) Path(java.nio.file.Path) GradleVersion(org.gradle.util.GradleVersion) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) Delete(org.gradle.api.tasks.Delete) Project(org.gradle.api.Project) Collection(java.util.Collection) ChangedFileReportTask(com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask) Set(java.util.Set) IvyPublishPlugin(org.gradle.api.publish.ivy.plugins.IvyPublishPlugin) GeneratePegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask) Collectors(java.util.stream.Collectors) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) IdlOptions(com.linkedin.pegasus.gradle.PegasusOptions.IdlOptions) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Pattern(java.util.regex.Pattern) ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) GenerateRestClientTask(com.linkedin.pegasus.gradle.tasks.GenerateRestClientTask) GenerateRestModelTask(com.linkedin.pegasus.gradle.tasks.GenerateRestModelTask) HashMap(java.util.HashMap) Function(java.util.function.Function) FileCollection(org.gradle.api.file.FileCollection) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Sync(org.gradle.api.tasks.Sync) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) CheckRestModelTask(com.linkedin.pegasus.gradle.tasks.CheckRestModelTask) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Properties(java.util.Properties) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ValidateSchemaAnnotationTask(com.linkedin.pegasus.gradle.tasks.ValidateSchemaAnnotationTask) IOException(java.io.IOException) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel) File(java.io.File) CheckIdlTask(com.linkedin.pegasus.gradle.tasks.CheckIdlTask) GenerateDataTemplateTask(com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask) GenerateAvroSchemaTask(com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask) GradleException(org.gradle.api.GradleException) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) InputStream(java.io.InputStream) PublishRestModelTask(com.linkedin.pegasus.gradle.tasks.PublishRestModelTask) ValidateExtensionSchemaTask(com.linkedin.pegasus.gradle.tasks.ValidateExtensionSchemaTask) CheckSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask) Task(org.gradle.api.Task) TranslateSchemasTask(com.linkedin.pegasus.gradle.tasks.TranslateSchemasTask) CheckPegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask) ChangedFileReportTask(com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask) GeneratePegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask) GenerateRestClientTask(com.linkedin.pegasus.gradle.tasks.GenerateRestClientTask) GenerateRestModelTask(com.linkedin.pegasus.gradle.tasks.GenerateRestModelTask) CheckRestModelTask(com.linkedin.pegasus.gradle.tasks.CheckRestModelTask) ValidateSchemaAnnotationTask(com.linkedin.pegasus.gradle.tasks.ValidateSchemaAnnotationTask) CheckIdlTask(com.linkedin.pegasus.gradle.tasks.CheckIdlTask) GenerateDataTemplateTask(com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask) GenerateAvroSchemaTask(com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with SourceSet

use of org.gradle.api.tasks.SourceSet in project rest.li by linkedin.

the class PegasusPlugin method configureConversionUtilities.

protected void configureConversionUtilities(Project project, SourceSet sourceSet) {
    File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
    boolean reverse = isPropertyTrue(project, CONVERT_TO_PDL_REVERSE);
    boolean keepOriginal = isPropertyTrue(project, CONVERT_TO_PDL_KEEP_ORIGINAL);
    boolean skipVerification = isPropertyTrue(project, CONVERT_TO_PDL_SKIP_VERIFICATION);
    String preserveSourceCmd = getNonEmptyProperty(project, CONVERT_TO_PDL_PRESERVE_SOURCE_CMD);
    // Utility task for migrating between PDSC and PDL.
    project.getTasks().create(sourceSet.getTaskName("convert", "ToPdl"), TranslateSchemasTask.class, task -> {
        task.setInputDir(dataSchemaDir);
        task.setDestinationDir(dataSchemaDir);
        task.setResolverPath(getDataModelConfig(project, sourceSet));
        task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
        task.setPreserveSourceCmd(preserveSourceCmd);
        if (reverse) {
            task.setSourceFormat(SchemaFileType.PDL);
            task.setDestinationFormat(SchemaFileType.PDSC);
        } else {
            task.setSourceFormat(SchemaFileType.PDSC);
            task.setDestinationFormat(SchemaFileType.PDL);
        }
        task.setKeepOriginal(keepOriginal);
        task.setSkipVerification(skipVerification);
        if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
            task.setEnableArgFile(true);
        }
        task.onlyIf(t -> task.getInputDir().exists());
        task.doLast(new CacheableAction<>(t -> {
            project.getLogger().lifecycle("Pegasus schema conversion complete.");
            project.getLogger().lifecycle("All pegasus schema files in " + dataSchemaDir + " have been converted");
            project.getLogger().lifecycle("You can use '-PconvertToPdl.reverse=true|false' to change the direction of conversion.");
        }));
    });
    // Helper task for reformatting existing PDL schemas by generating them again.
    project.getTasks().create(sourceSet.getTaskName("reformat", "Pdl"), TranslateSchemasTask.class, task -> {
        task.setInputDir(dataSchemaDir);
        task.setDestinationDir(dataSchemaDir);
        task.setResolverPath(getDataModelConfig(project, sourceSet));
        task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
        task.setSourceFormat(SchemaFileType.PDL);
        task.setDestinationFormat(SchemaFileType.PDL);
        task.setKeepOriginal(true);
        task.setSkipVerification(true);
        if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
            task.setEnableArgFile(true);
        }
        task.onlyIf(t -> task.getInputDir().exists());
        task.doLast(new CacheableAction<>(t -> project.getLogger().lifecycle("PDL reformat complete.")));
    });
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) Arrays(java.util.Arrays) PublishRestModelTask(com.linkedin.pegasus.gradle.tasks.PublishRestModelTask) ValidateExtensionSchemaTask(com.linkedin.pegasus.gradle.tasks.ValidateExtensionSchemaTask) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) CheckSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask) EclipsePlugin(org.gradle.plugins.ide.eclipse.EclipsePlugin) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) Locale(java.util.Locale) Map(java.util.Map) TranslateSchemasTask(com.linkedin.pegasus.gradle.tasks.TranslateSchemasTask) CheckPegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask) Method(java.lang.reflect.Method) Path(java.nio.file.Path) GradleVersion(org.gradle.util.GradleVersion) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) Delete(org.gradle.api.tasks.Delete) Project(org.gradle.api.Project) Collection(java.util.Collection) ChangedFileReportTask(com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask) Set(java.util.Set) IvyPublishPlugin(org.gradle.api.publish.ivy.plugins.IvyPublishPlugin) GeneratePegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask) Collectors(java.util.stream.Collectors) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) IdlOptions(com.linkedin.pegasus.gradle.PegasusOptions.IdlOptions) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Pattern(java.util.regex.Pattern) ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) GenerateRestClientTask(com.linkedin.pegasus.gradle.tasks.GenerateRestClientTask) GenerateRestModelTask(com.linkedin.pegasus.gradle.tasks.GenerateRestModelTask) HashMap(java.util.HashMap) Function(java.util.function.Function) FileCollection(org.gradle.api.file.FileCollection) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Sync(org.gradle.api.tasks.Sync) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) CheckRestModelTask(com.linkedin.pegasus.gradle.tasks.CheckRestModelTask) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Properties(java.util.Properties) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ValidateSchemaAnnotationTask(com.linkedin.pegasus.gradle.tasks.ValidateSchemaAnnotationTask) IOException(java.io.IOException) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel) File(java.io.File) CheckIdlTask(com.linkedin.pegasus.gradle.tasks.CheckIdlTask) GenerateDataTemplateTask(com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask) GenerateAvroSchemaTask(com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask) GradleException(org.gradle.api.GradleException) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) InputStream(java.io.InputStream) File(java.io.File)

Example 23 with SourceSet

use of org.gradle.api.tasks.SourceSet in project coffeenet-starter by coffeenet.

the class OptionalVariantPlugin method apply.

@Override
public void apply(Project project) {
    // J-
    // @formatter:off
    project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
        project.getExtensions().configure(JavaPluginExtension.class, (java) -> {
            java.registerFeature(OPTIONAL_VARIANT_NAME, feature -> {
                SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                feature.usingSourceSet(mainSourceSet);
            });
        });
    });
// @formatter:off
// J+
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 24 with SourceSet

use of org.gradle.api.tasks.SourceSet in project spring-boot by spring-projects.

the class JavaConventions method configureJarManifestConventions.

private void configureJarManifestConventions(Project project) {
    ExtractResources extractLegalResources = project.getTasks().create("extractLegalResources", ExtractResources.class);
    extractLegalResources.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("legal"));
    extractLegalResources.setResourcesNames(Arrays.asList("LICENSE.txt", "NOTICE.txt"));
    extractLegalResources.property("version", project.getVersion().toString());
    SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
    Set<String> sourceJarTaskNames = sourceSets.stream().map(SourceSet::getSourcesJarTaskName).collect(Collectors.toSet());
    Set<String> javadocJarTaskNames = sourceSets.stream().map(SourceSet::getJavadocJarTaskName).collect(Collectors.toSet());
    project.getTasks().withType(Jar.class, (jar) -> project.afterEvaluate((evaluated) -> {
        jar.metaInf((metaInf) -> metaInf.from(extractLegalResources));
        jar.manifest((manifest) -> {
            Map<String, Object> attributes = new TreeMap<>();
            attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
            attributes.put("Build-Jdk-Spec", SOURCE_AND_TARGET_COMPATIBILITY);
            attributes.put("Built-By", "Spring");
            attributes.put("Implementation-Title", determineImplementationTitle(project, sourceJarTaskNames, javadocJarTaskNames, jar));
            attributes.put("Implementation-Version", project.getVersion());
            manifest.attributes(attributes);
        });
    }));
}
Also used : Arrays(java.util.Arrays) CheckFormat(io.spring.javaformat.gradle.tasks.CheckFormat) OptionalDependenciesPlugin(org.springframework.boot.build.optional.OptionalDependenciesPlugin) TestRetryTaskExtension(org.gradle.testretry.TestRetryTaskExtension) JavaPlugin(org.gradle.api.plugins.JavaPlugin) TestFailuresPlugin(org.springframework.boot.build.testing.TestFailuresPlugin) DependencySet(org.gradle.api.artifacts.DependencySet) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Map(java.util.Map) Test(org.gradle.api.tasks.testing.Test) CheckstylePlugin(org.gradle.api.plugins.quality.CheckstylePlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Checkstyle(org.gradle.api.plugins.quality.Checkstyle) CheckClasspathForProhibitedDependencies(org.springframework.boot.build.classpath.CheckClasspathForProhibitedDependencies) Jar(org.gradle.api.tasks.bundling.Jar) Project(org.gradle.api.Project) Set(java.util.Set) Collectors(java.util.stream.Collectors) JavaVersion(org.gradle.api.JavaVersion) TestRetryPlugin(org.gradle.testretry.TestRetryPlugin) List(java.util.List) SpringJavaFormatPlugin(io.spring.javaformat.gradle.SpringJavaFormatPlugin) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) TreeMap(java.util.TreeMap) Format(io.spring.javaformat.gradle.tasks.Format) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) CheckstyleExtension(org.gradle.api.plugins.quality.CheckstyleExtension) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) ToolchainPlugin(org.springframework.boot.build.toolchain.ToolchainPlugin) StringUtils(org.springframework.util.StringUtils) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 25 with SourceSet

use of org.gradle.api.tasks.SourceSet in project spring-boot by spring-projects.

the class MavenPluginPlugin method addGeneratePluginDescriptorTask.

private MavenExec addGeneratePluginDescriptorTask(Project project, Jar jarTask, MavenExec generateHelpMojoTask) {
    File pluginDescriptorDir = new File(project.getBuildDir(), "plugin-descriptor");
    File generatedHelpMojoDir = new File(project.getBuildDir(), "generated/sources/helpMojo");
    SourceSet mainSourceSet = getMainSourceSet(project);
    project.getTasks().withType(Javadoc.class, this::setJavadocOptions);
    FormatHelpMojoSourceTask copyFormattedHelpMojoSourceTask = createCopyFormattedHelpMojoSourceTask(project, generateHelpMojoTask, generatedHelpMojoDir);
    project.getTasks().getByName(mainSourceSet.getCompileJavaTaskName()).dependsOn(copyFormattedHelpMojoSourceTask);
    mainSourceSet.java((javaSources) -> javaSources.srcDir(copyFormattedHelpMojoSourceTask));
    Copy pluginDescriptorInputs = createCopyPluginDescriptorInputs(project, pluginDescriptorDir, mainSourceSet);
    pluginDescriptorInputs.dependsOn(mainSourceSet.getClassesTaskName());
    MavenExec task = createGeneratePluginDescriptorTask(project, pluginDescriptorDir);
    task.dependsOn(pluginDescriptorInputs);
    includeDescriptorInJar(jarTask, task);
    return task;
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Copy(org.gradle.api.tasks.Copy) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File)

Aggregations

SourceSet (org.gradle.api.tasks.SourceSet)55 File (java.io.File)28 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)24 Project (org.gradle.api.Project)20 Configuration (org.gradle.api.artifacts.Configuration)19 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)18 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)15 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)14 List (java.util.List)13 Task (org.gradle.api.Task)13 JavaPlugin (org.gradle.api.plugins.JavaPlugin)12 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)12 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 Collections (java.util.Collections)10 Action (org.gradle.api.Action)10 Plugin (org.gradle.api.Plugin)10 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)10 Jar (org.gradle.api.tasks.bundling.Jar)10 HashSet (java.util.HashSet)9