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

The following examples show how to use org.gradle.api.tasks.bundling.Zip. 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: CloudServicesPackagingPlugin.java    From commerce-gradle-plugin with Apache License 2.0 5 votes vote down vote up
private void setupSolrPackaging(Project p, PackagingExtension extension, Path packageFolder, Zip zipPackage, Task cleanTargetFolder) {
    // FIXME This is only POC for Solr configuration only.
    Set<String> environments = extension.getEnvironments().get();
    Path configurationFolder = extension.getConfigurationFolder().getAsFile().get().toPath();
    for (String environment : environments) {
        Path sourceFolder = configurationFolder.resolve(environment).resolve("solr");
        Path commonFolder = configurationFolder.resolve(COMMON_CONFIG).resolve("solr");
        Path targetFolder = packageFolder.resolve("solr/config/" + environment);

        Copy copySolrCommonConfig = p.getTasks().create("copySolrCommonEnv_" + environment, Copy.class, t -> {
            t.from(commonFolder);
            t.into(targetFolder);
            t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
            t.exclude(SOLR_CONFIG_EXCLUDE);
        });
        copySolrCommonConfig.dependsOn(cleanTargetFolder);

        Copy copySolrConfig = p.getTasks().create("copySolrEnv_" + environment, Copy.class, t -> {
            t.from(sourceFolder);
            t.into(targetFolder);
            t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
            t.exclude(SOLR_CONFIG_EXCLUDE);
        });
        copySolrConfig.dependsOn(copySolrCommonConfig);

        zipPackage.dependsOn(copySolrConfig);
    }
}
 
Example #2
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 #3
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 #4
Source File: AndroidComponetCreator.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void createAndroidComponent(Zip bundleTask) {
    //Add a components. Android
    if (atlasExtension.getBundleConfig().isAwbBundle()) {
        Configuration compileConfiguration = project.getConfigurations()
            .getByName(COMPILE_CONFIGURATION_NAME);
        ArchivePublishArtifact bundleArtifact = new ArchivePublishArtifact(bundleTask);
        compileConfiguration.getArtifacts().add(bundleArtifact);
    }
}
 
Example #5
Source File: JarExtractTask.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Create a basic AWB task
 */
public void generateJarArtifict(final Zip bundleTask) {

    bundleTask.doLast(new Action<Task>() {

        @Override
        public void execute(Task task) {

            File outputFile = new File(bundleTask.getDestinationDir(),
                                       bundleTask.getArchiveName());

            if (!outputFile.exists()) {
                return;
            }

            File f = ZipUtils.extractZipFileToFolder(outputFile,
                                                     "classes.jar",
                                                     outputFile.getParentFile());

            if (null != f && f.exists()) {
                File jar = new File(new File(bundleTask.getDestinationDir().getParentFile(), "jar"),
                                    FilenameUtils.getBaseName(bundleTask.getArchiveName()) +
                                        ".jar");
                jar.getParentFile().mkdirs();
                f.renameTo(jar);

            }

        }
    });
}
 
Example #6
Source File: LibVariantContext.java    From atlas with Apache License 2.0 5 votes vote down vote up
public List<Zip> getZipTasks() {
    List<Zip> zipTasks = TaskQueryHelper.findTask(project, Zip.class, getBaseVariantData());
    List<Zip> result = new ArrayList<Zip>();
    if (null != zipTasks) {
        for (Zip zipTask : zipTasks) {
            if (zipTask.getName().contains("bundle")) {
                result.add(zipTask);
            }
        }
    }
    return result;
}
 
Example #7
Source File: CloudServicesPackagingPlugin.java    From commerce-gradle-plugin with Apache License 2.0 4 votes vote down vote up
private void setupDatahubPackaging(Project p, PackagingExtension extension, Path packageFolder, Zip zipPackage, Task cleanTargetFolder) {
    Copy copyDataHubWar = p.getTasks().create("copyDataHubWar", Copy.class, t -> {
        t.from(extension.getDatahubWar(), s -> s.rename(".*", "datahub-webapp.war"));
        t.into(packageFolder.resolve("datahub/bin"));
        t.onlyIf(a -> {
            if (a.getInputs().getSourceFiles().isEmpty()) {
                throw new StopExecutionException("no datahub file found");
            }
            return true;
        });
    });
    copyDataHubWar.dependsOn(cleanTargetFolder);
    zipPackage.dependsOn(copyDataHubWar);

    Set<String> environments = extension.getEnvironments().get();
    Path configurationFolder = extension.getConfigurationFolder().getAsFile().get().toPath();
    for (String environment : environments) {
        Path sourceFolder = configurationFolder.resolve(environment).resolve("datahub");
        Path commonFolder = configurationFolder.resolve(COMMON_CONFIG).resolve("datahub");
        Path targetFolder = packageFolder.resolve("datahub/config/" + environment);

        Copy copyCommonConfig = p.getTasks().create("copyDatahubCommonEnv_" + environment, Copy.class, t -> {
            t.from(commonFolder);
            t.into(targetFolder);
            t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
            t.exclude(DATAHUB_CONFIG_EXCLUDE);
        });
        copyCommonConfig.dependsOn(cleanTargetFolder);

        Copy copyDatahubConfig = p.getTasks().create("copyDatahubEnv_" + environment, Copy.class, t -> {
            t.from(sourceFolder);
            t.into(targetFolder);
            t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
            t.exclude(DATAHUB_CONFIG_EXCLUDE);
        });
        copyDatahubConfig.dependsOn(copyCommonConfig);

        MergePropertyFiles mergeProperties = p.getTasks().create("mergeDatahub_customer.properties_" + environment, MergePropertyFiles.class, t -> {
            t.getInputFiles().setFrom(Arrays.asList(
                    commonFolder.resolve("customer.properties"),
                    sourceFolder.resolve("customer.properties")
            ));
            t.setOutputFile(targetFolder.resolve("customer.properties"));
        });
        mergeProperties.dependsOn(copyDatahubConfig);

        zipPackage.dependsOn(mergeProperties);
    }
}
 
Example #8
Source File: LibVariantContext.java    From atlas with Apache License 2.0 4 votes vote down vote up
public Zip getBundleTask() {
    return bundleTask;
}
 
Example #9
Source File: LibVariantContext.java    From atlas with Apache License 2.0 4 votes vote down vote up
public void setBundleTask(Zip bundleTask) {
    this.bundleTask = bundleTask;
}
 
Example #10
Source File: LibraryVariantOutputImpl.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Zip getPackageLibrary() {
    return variantOutputData.packageLibTask;
}
 
Example #11
Source File: Sample.java    From native-samples with Apache License 2.0 4 votes vote down vote up
public void zipSource(Action<Zip> action) {
    zipActions.add(action);
}
 
Example #12
Source File: Sample.java    From native-samples with Apache License 2.0 4 votes vote down vote up
public List<Action<Zip>> getZipActions() {
    return zipActions;
}
 
Example #13
Source File: LibraryVariantOutput.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the Library AAR packaging task.
 */
@Nullable
Zip getPackageLibrary();