org.gradle.api.tasks.bundling.Tar Java Examples

The following examples show how to use org.gradle.api.tasks.bundling.Tar. 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: DistributionPackaging.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public List<TaskProvider<? extends Task>> configurePackagingTasks(Project project, Platform platform,
    SourceSet platformSourceSet, SourceSet mainSourceSet) {
  // Create a thin JAR to be included in the distribution
  final TaskProvider<Jar> platformThinJarTask = createThinJarTask(project, platformSourceSet, platform.getName());

  /*
    Include the thin JAR and all the runtime dependencies into the distribution for a given platform

    distributions {
      <platformName> {
        contents {
          from <platformThinJarTask>
          from project.configurations.<platformRuntimeClasspath>
        }
      }
    }
   */
  DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
  distributions.register(platform.getName(), distribution -> {
    distribution.setBaseName(project.getName());
    distribution.getContents()
        .from(platformThinJarTask)
        .from(getConfigurationForSourceSet(project, platformSourceSet, RUNTIME_CLASSPATH));
  });

  // Explicitly set classifiers for the created distributions or else leads to Maven packaging issues due to multiple
  // artifacts with the same classifier
  project.getTasks().named(platform.getName() + "DistTar", Tar.class, tar -> tar.setClassifier(platform.getName()));
  project.getTasks().named(platform.getName() + "DistZip", Zip.class, zip -> zip.setClassifier(platform.getName()));
  return ImmutableList.of(project.getTasks().named(platform.getName() + "DistTar", Tar.class),
      project.getTasks().named(platform.getName() + "DistZip", Zip.class));
}
 
Example #2
Source File: PlayDistributionPlugin.java    From playframework with Apache License 2.0 5 votes vote down vote up
private void createDistributionZipTasks(Project project, Distribution distribution, TaskProvider<Task> stageLifecycleTask, TaskProvider<Task> distLifecycleTask) {
    final String capitalizedDistName = capitalizeDistributionName(distribution.getName());
    final String stageTaskName = "stage" + capitalizedDistName + "Dist";
    final File stageDir = new File(project.getBuildDir(), "stage");
    final String baseName = (distribution.getBaseName() != null && "".equals(distribution.getBaseName())) ? distribution.getBaseName() : distribution.getName();

    TaskProvider<Sync> stageSyncTask = project.getTasks().register(stageTaskName, Sync.class, sync -> {
        sync.setDescription("Copies the '" + distribution.getName() + "' distribution to a staging directory.");
        sync.setDestinationDir(stageDir);

        sync.into(baseName, copySpec -> copySpec.with(distribution.getContents()));
    });

    stageLifecycleTask.configure(task -> task.dependsOn(stageSyncTask));

    final String distributionZipTaskName = "create" + capitalizedDistName + "ZipDist";
    TaskProvider<Zip> distZipTask = project.getTasks().register(distributionZipTaskName, Zip.class, zip -> {
        zip.setDescription("Packages the '" + distribution.getName() + "' distribution as a zip file.");
        zip.setBaseName(baseName);
        zip.setDestinationDir(new File(project.getBuildDir(), "distributions"));
        zip.from(stageSyncTask);
    });

    final String distributionTarTaskName = "create" + capitalizedDistName + "TarDist";
    TaskProvider<Tar> distTarTask = project.getTasks().register(distributionTarTaskName, Tar.class, tar -> {
        tar.setDescription("Packages the '" + distribution.getName() + "' distribution as a tar file.");
        tar.setBaseName(baseName);
        tar.setDestinationDir(new File(project.getBuildDir(), "distributions"));
        tar.from(stageSyncTask);
    });

    distLifecycleTask.configure(task -> {
        task.dependsOn(distZipTask);
        task.dependsOn(distTarTask);
    });
}
 
Example #3
Source File: DocumentationPlugin.java    From pygradle with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(final Tar tar) {
    tar.setCompression(Compression.GZIP);
    tar.setBaseName(tar.getProject().getName());
    tar.setClassifier("docs-" + documentationTask.type.getBuilderName());
    tar.setExtension("tar.gz");
    tar.from(documentationTask);
    tar.into(tar.getBaseName() + "-" + tar.getVersion() + "-" + tar.getClassifier());
}
 
Example #4
Source File: DocumentationPlugin.java    From pygradle with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(final Project project) {

    PythonExtension settings = ExtensionUtils.getPythonExtension(project);

    /*
     * Create documentation using Sphinx.
     */
    final SphinxDocumentationTask sphinxHtml = project.getTasks().create(TASK_BUILD_DOCS.getValue() + "Html", SphinxDocumentationTask.class, task -> {
        task.type = SphinxDocumentationTask.DocType.HTML;
        task.dependsOn(TASK_INSTALL_PROJECT.getValue());
        task.onlyIf(it -> project.file(settings.docsDir).exists());
    });

    final SphinxDocumentationTask sphinxJson = project.getTasks().create(TASK_BUILD_DOCS.getValue() + "Json", SphinxDocumentationTask.class, task -> {
        task.type = SphinxDocumentationTask.DocType.JSON;
        task.dependsOn(TASK_INSTALL_PROJECT.getValue());
        task.onlyIf(it -> project.file(settings.docsDir).exists());
    });

    project.getTasks().withType(SphinxDocumentationTask.class, task -> {
        task.setGroup(DOCUMENTATION_GROUP.getValue());
        task.setDescription("Generate Sphinx documentation in " + task.type.getBuilderName() + " format");
    });

    project.getTasks().create(TASK_BUILD_DOCS.getValue(), it -> it.dependsOn(sphinxHtml, sphinxJson));

    /*
     * Tar up the documentation.
     */
    Tar packageDocsTask = project.getTasks().create(TASK_PACKAGE_DOCS.getValue(), Tar.class, new PackageDocumentationAction(sphinxHtml));
    packageDocsTask.dependsOn(project.getTasks().getByName(TASK_BUILD_DOCS.getValue()));

    /*
     * Tar up the JSON documentation.
     */
    Tar packageJsonDocsTask = project.getTasks().create(TASK_PACKAGE_JSON_DOCS.getValue(), Tar.class, new PackageDocumentationAction(sphinxJson));
    packageJsonDocsTask.dependsOn(project.getTasks().getByName(TASK_BUILD_DOCS.getValue()));

    // Only build the artifact if the docs source directory actually exists
    if (project.file(settings.docsDir).exists()) {
        project.getArtifacts().add(CONFIGURATION_PYDOCS.getValue(), packageDocsTask);
        project.getArtifacts().add(CONFIGURATION_PYDOCS.getValue(), packageJsonDocsTask);
    }

}