org.gradle.api.tasks.StopExecutionException Java Examples

The following examples show how to use org.gradle.api.tasks.StopExecutionException. 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: GenerateLombokConfig.java    From gradle-plugins with MIT License 6 votes vote down vote up
@TaskAction
@SneakyThrows
public void generateLombokConfig() {
    File file = outputFile.getAsFile().get();

    if (file.isFile()) {
        try (Stream<String> lines = Files.lines(file.toPath(), StandardCharsets.ISO_8859_1)) {
            if (lines.noneMatch(line -> line.startsWith("#") && line.contains("io.freefair.lombok"))) {
                String message = file + " already exists and was not generated by this task";
                getLogger().warn(message);
                throw new StopExecutionException(message);
            }
        }
    }

    try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(file, "ISO-8859-1")) {
        writer.println("# This file is generated by the 'io.freefair.lombok' Gradle plugin");
        properties.get().entrySet().stream()
                .sorted(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER))
                .forEach(entry ->
                        writer.println(entry.getKey() + " = " + entry.getValue())
                );
    }
}
 
Example #2
Source File: GenerateLombokConfig.java    From gradle-plugins with MIT License 6 votes vote down vote up
@TaskAction
@SneakyThrows
public void generateLombokConfig() {
    File file = outputFile.getAsFile().get();

    if (file.isFile()) {
        try (Stream<String> lines = Files.lines(file.toPath(), StandardCharsets.ISO_8859_1)) {
            if (lines.noneMatch(line -> line.startsWith("#") && line.contains("io.freefair.lombok"))) {
                String message = file + " already exists and was not generated by this task";
                getLogger().warn(message);
                throw new StopExecutionException(message);
            }
        }
    }

    try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(file, "ISO-8859-1")) {
        writer.println("# This file is generated by the 'io.freefair.lombok' Gradle plugin");
        properties.get().entrySet().stream()
                .sorted(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER))
                .forEach(entry ->
                        writer.println(entry.getKey() + " = " + entry.getValue())
                );
    }
}
 
Example #3
Source File: InjectTransformManager.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Update the parameters for the transformTask
 *
 * @param transformTask
 * @param consumedInputStreams
 * @param referencedInputStreams
 * @param outputStream
 */
private void updateTransformTaskConfig(TransformTask transformTask,
                                       @NonNull Collection<TransformStream> consumedInputStreams,
                                       @NonNull Collection<TransformStream> referencedInputStreams,
                                       @Nullable IntermediateStream outputStream) throws IllegalAccessException {
    Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
                                                                  "consumedInputStreams",
                                                                  true);
    Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
                                                                    "referencedInputStreams",
                                                                    true);
    Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class,
                                                          "outputStream",
                                                          true);

    if (null == consumedInputStreamsField ||
            null == referencedInputStreamsField ||
            null == outputStreamField) {
        throw new StopExecutionException(
                "The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!");
    }
    consumedInputStreamsField.set(transformTask, consumedInputStreams);
    referencedInputStreamsField.set(transformTask, referencedInputStreams);
    outputStreamField.set(transformTask, outputStream);
}
 
Example #4
Source File: InjectTransformManager.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameters of a transformTask
 *
 * @param transformTask
 * @return
 * @throws IllegalAccessException
 */
private TransformTaskParam getTransformParam(TransformTask transformTask) throws IllegalAccessException {
    TransformTaskParam transformTaskParam = new TransformTaskParam();
    Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
                                                                  "consumedInputStreams",
                                                                  true);
    Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
                                                                    "referencedInputStreams",
                                                                    true);
    Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class,
                                                          "outputStream",
                                                          true);

    if (null == consumedInputStreamsField ||
            null == referencedInputStreamsField ||
            null == outputStreamField) {
        throw new StopExecutionException(
                "The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!");
    }
    transformTaskParam.consumedInputStreams = (Collection<TransformStream>) consumedInputStreamsField
            .get(transformTask);
    transformTaskParam.referencedInputStreams = (Collection<TransformStream>) referencedInputStreamsField
            .get(transformTask);
    transformTaskParam.outputStream = (IntermediateStream) outputStreamField.get(transformTask);
    return transformTaskParam;
}
 
Example #5
Source File: BasePlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check the sub-projects structure :
 * So far, checks that 2 modules do not have the same identification (group+name).
 */
private void checkModulesForErrors() {
    Project rootProject = project.getRootProject();
    Map<String, Project> subProjectsById = new HashMap<String, Project>();
    for (Project subProject : rootProject.getAllprojects()) {
        String id = subProject.getGroup().toString() + ":" + subProject.getName();
        if (subProjectsById.containsKey(id)) {
            String message = String.format(
                    "Your project contains 2 or more modules with the same " +
                            "identification %1$s\n" +
                            "at \"%2$s\" and \"%3$s\".\n" +
                            "You must use different identification (either name or group) for " +
                            "each modules.",
                    id,
                    subProjectsById.get(id).getPath(),
                    subProject.getPath());
            throw new StopExecutionException(message);
        } else {
            subProjectsById.put(id, subProject);
        }
    }
}
 
Example #6
Source File: ExecCommandFactory.java    From shipkit with MIT License 5 votes vote down vote up
public static Action<ExecResult> stopExecution() {
    return exec -> {
        if (exec.getExitValue() != 0) {
            LOG.info("External process returned exit code: {}. Stopping the execution of the task.", exec.getExitValue());
            //Cleanly stop executing the task, without making the task failed.
            throw new StopExecutionException();
        }
    };
}
 
Example #7
Source File: MtlBaseTaskAction.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected void setFieldValueByReflection(Task task, String fieldName, Object value) {
    Field field = FieldUtils.getField(task.getClass(), fieldName, true);
    if (null == field) {
        throw new StopExecutionException("The field with name:" +
                                                 fieldName +
                                                 " does not existed in class:" +
                                                 task.getClass().getName());
    }
    try {
        FieldUtils.writeField(field, task, value, true);
    } catch (IllegalAccessException e) {
        throw new StopExecutionException(e.getMessage());
    }
}
 
Example #8
Source File: ApkFileListUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Records resource information for apk files
 */
public static ApkFiles recordApkFileInfos(AppVariantContext appVariantContext) {

    ApkFiles apkFiles = new ApkFiles();

    List<File> mainBundleResFolders = new ArrayList<File>();
    mainBundleResFolders.add(appVariantContext.getScope().getVariantData().mergeResourcesTask.getOutputDir());
    prepareApkFileList(appVariantContext.getScope().getVariantData().mergeAssetsTask.getOutputDir(),
                       "assets", apkFiles);
    for (File resFolder : mainBundleResFolders) {
        prepareApkFileList(resFolder, "res", apkFiles);
    }

    // Record the resource information for each bundle
    AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().
        getVariantConfiguration().getFullName());
    if (null == dependencyTree) {
        throw new StopExecutionException("DependencyTree cannot be null!");
    }

    List<AwbBundle> libs = dependencyTree.getAwbBundles();

    for (AwbBundle awbLib : libs) {
        File mergeAssertFolder = appVariantContext.getMergeAssets(awbLib);
        File mergeResFolder = appVariantContext.getMergeResources(awbLib);
        String awbName = awbLib.getName();
        prepareApkFileList(mergeAssertFolder, "assets", awbName, apkFiles);
        prepareApkFileList(mergeResFolder, "res", awbName, apkFiles);
    }

    return apkFiles;
}
 
Example #9
Source File: AwoPropHandler.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void process(TBuildType buildType, BundleConfig bundleConfig) throws Exception {

        String propfile = EnvHelper.getEnv("awoprop");

        if (StringUtils.isEmpty(propfile)) {
            return;
        }

        Properties properties = new Properties();
        properties.load(new FileInputStream(propfile));

        String ap_path = properties.getProperty(AP_PATH);
        boolean refresh_ap = "true".equals(properties.getProperty(REFRESH_AP));
        String mtl_url = properties.getProperty(MTL_URL);

        if (!refresh_ap && StringUtils.isNotEmpty(ap_path) && new File(ap_path).exists()) {
            //not need download
            System.out.println("[awo] ap file exist");
        }

        if (StringUtils.isEmpty(mtl_url)) {
            throw new StopExecutionException("mtl_url is not configed");
        }

        ap_path = ApDownloader.downloadAP(mtl_url, new File(propfile).getParentFile()).getAbsolutePath();
        properties.setProperty(AP_PATH, ap_path);
        properties.store(new FileOutputStream(propfile), "update path");

        buildType.setBaseApFile(new File(ap_path));

        bundleConfig.setAwoBuildEnabled(true);
        bundleConfig.setAwoDynDeploy("true".equals(properties.getProperty(SUPPORT_DYN, "true")));
        bundleConfig.setAwoApkBuild("true".equals(properties.getProperty(SUPPORT_APK, "true")));
    }
 
Example #10
Source File: MergeResources.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doFullTaskAction() throws IOException {
    // this is full run, clean the previous output
    File destinationDir = getOutputDir();
    FileUtils.emptyFolder(destinationDir);

    List<ResourceSet> resourceSets = getConfiguredResourceSets();

    // create a new merger and populate it with the sets.
    ResourceMerger merger = new ResourceMerger();

    try {
        for (ResourceSet resourceSet : resourceSets) {
            resourceSet.loadFromFiles(getILogger());
            merger.addDataSet(resourceSet);
        }

        // get the merged set and write it down.
        MergedResourceWriter writer = new MergedResourceWriter(
                destinationDir, getCruncher(),
                getCrunchPng(), getProcess9Patch(), getPublicFile(), preprocessor);
        writer.setInsertSourceMarkers(getInsertSourceMarkers());

        merger.mergeData(writer, false /*doCleanUp*/);

        // No exception? Write the known state.
        merger.writeBlobTo(getIncrementalFolder(), writer);
        throw new StopExecutionException("Stop for now.");
    } catch (MergingException e) {
        System.out.println(e.getMessage());
        merger.cleanBlob(getIncrementalFolder());
        throw new ResourceException(e.getMessage(), e);
    }
}
 
Example #11
Source File: AbstractFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() {
    if (isEmpty()) {
        throw new StopExecutionException(String.format("%s does not contain any files.", getCapDisplayName()));
    }
    return this;
}
 
Example #12
Source File: AbstractFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() {
    if (isEmpty()) {
        throw new StopExecutionException(String.format("%s does not contain any files.", getCapDisplayName()));
    }
    return this;
}
 
Example #13
Source File: DelegatingFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() throws StopExecutionException {
    return getDelegate().stopExecutionIfEmpty();
}
 
Example #14
Source File: AbstractFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() {
    if (isEmpty()) {
        throw new StopExecutionException(String.format("%s does not contain any files.", getCapDisplayName()));
    }
    return this;
}
 
Example #15
Source File: DelegatingFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() throws StopExecutionException {
    return getDelegate().stopExecutionIfEmpty();
}
 
Example #16
Source File: SupportPortalDownload.java    From commerce-gradle-plugin with Apache License 2.0 4 votes vote down vote up
public SupportPortalDownload() {
    supportPortalUrl = getProject().getObjects().property(String.class);
    username = getProject().getObjects().property(String.class);
    password = getProject().getObjects().property(String.class);
    md5Hash = getProject().getObjects().property(String.class);
    sha256Sum = getProject().getObjects().property(String.class);
    targetFile = getProject().getObjects().fileProperty();

    Spec<Task> hashesMatch = t -> {
        String md5HashOrNull = md5Hash.getOrNull();
        String sha256SumOrNull = sha256Sum.getOrNull();
        if (md5HashOrNull == null && sha256SumOrNull == null) {
            throw new StopExecutionException("Please define either md5Hash or sha256Sum");
        }

        try {
            Path target = targetFile.get().getAsFile().toPath();
            if (!Files.exists(target)) {
                return false;
            }
            DownloadInfoFile infoFile = getInfoFileForTarget();
            boolean md5 = true;
            String expectedHash = md5HashOrNull;
            if (expectedHash == null) {
                expectedHash = sha256SumOrNull;
                md5 = false;
            }
            String fileHash;
            if (!infoFile.getCachedMd5Hash().isEmpty()) {
                fileHash = infoFile.getCachedMd5Hash();
                getLogger().debug("Using cached hash to compare", fileHash);
            } else {
                getLogger().debug("No valid hash found for {}, recalculating...", target.getFileName());
                if (md5) {
                    fileHash = HashUtil.md5Hash(target);
                } else {
                    fileHash = HashUtil.sha256Sum(target);
                }
                infoFile.setCachedMd5Hash(fileHash);
                infoFile.write();
            }
            getLogger().debug("{}: Expected hash: {} File hash: {}", target.getFileName(), expectedHash, fileHash);
            return fileHash.equals(expectedHash);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    getOutputs().upToDateWhen(hashesMatch);
    onlyIf(t -> !hashesMatch.isSatisfiedBy(t));
}
 
Example #17
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 #18
Source File: AbstractFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() {
    if (isEmpty()) {
        throw new StopExecutionException(String.format("%s does not contain any files.", getCapDisplayName()));
    }
    return this;
}
 
Example #19
Source File: DelegatingFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() throws StopExecutionException {
    return getDelegate().stopExecutionIfEmpty();
}
 
Example #20
Source File: DelegatingFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileCollection stopExecutionIfEmpty() throws StopExecutionException {
    return getDelegate().stopExecutionIfEmpty();
}
 
Example #21
Source File: FileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Throws a {@link StopExecutionException} if this collection is empty.
 *
 * @return this
 * @throws StopExecutionException When this collection is empty.
 */
FileCollection stopExecutionIfEmpty() throws StopExecutionException;
 
Example #22
Source File: FileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Throws a {@link StopExecutionException} if this collection is empty.
 *
 * @return this
 * @throws StopExecutionException When this collection is empty.
 */
FileCollection stopExecutionIfEmpty() throws StopExecutionException;
 
Example #23
Source File: FileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Throws a {@link StopExecutionException} if this collection is empty.
 *
 * @return this
 * @throws StopExecutionException When this collection is empty.
 */
FileCollection stopExecutionIfEmpty() throws StopExecutionException;
 
Example #24
Source File: FileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Throws a {@link StopExecutionException} if this collection is empty.
 *
 * @return this
 * @throws StopExecutionException When this collection is empty.
 */
FileCollection stopExecutionIfEmpty() throws StopExecutionException;