Search in sources :

Example 6 with StopExecutionException

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

the class GenerateAvroSchemaTask method generate.

@TaskAction
public void generate() {
    FileTree inputDataSchemaFiles = getSuffixedFiles(getProject(), _inputDir, PegasusPlugin.DATA_TEMPLATE_FILE_SUFFIXES);
    List<String> inputDataSchemaFilenames = StreamSupport.stream(inputDataSchemaFiles.spliterator(), false).map(File::getPath).collect(Collectors.toList());
    if (inputDataSchemaFilenames.isEmpty()) {
        throw new StopExecutionException("There are no data schema input files. Skip generating avro schema.");
    }
    getProject().getLogger().info("Generating Avro schemas ...");
    getProject().getLogger().lifecycle("There are {} data schema input files. Using input root folder: {}", inputDataSchemaFilenames.size(), _inputDir);
    _destinationDir.mkdirs();
    String resolverPathStr = _resolverPath.plus(getProject().files(_inputDir)).getAsPath();
    FileCollection _pathedCodegenClasspath;
    try {
        _pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _codegenClasspath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        String resolverPathArg = resolverPathStr;
        if (isEnableArgFile()) {
            resolverPathArg = ArgumentFileGenerator.getArgFileSyntax(ArgumentFileGenerator.createArgFile("generateAvro_resolverPath", Collections.singletonList(resolverPathArg), getTemporaryDir()));
        }
        javaExecSpec.setMain("com.linkedin.data.avro.generator.AvroSchemaGenerator");
        javaExecSpec.setClasspath(_pathedCodegenClasspath);
        javaExecSpec.jvmArgs("-Dgenerator.resolver.path=" + resolverPathArg);
        String translateOptionalDefault = getTranslateOptionalDefault();
        if (translateOptionalDefault != null) {
            javaExecSpec.jvmArgs("-Dgenerator.avro.optional.default=" + translateOptionalDefault);
        }
        String overrideNamespace = getOverrideNamespace();
        if (overrideNamespace != null) {
            javaExecSpec.jvmArgs("-Dgenerator.avro.namespace.override=" + overrideNamespace);
        }
        String typeRefPropertiesExcludeList = getTypeRefPropertiesExcludeList();
        if (typeRefPropertiesExcludeList == null) {
            // unless overridden,
            // by default gradle plugin tasks will set this to have "validate" "java" so it is backward compatible
            typeRefPropertiesExcludeList = "validate,data";
        }
        javaExecSpec.jvmArgs(String.format("-D%s=%s", TYPERF_PROPERTIES_EXCLUDE, typeRefPropertiesExcludeList));
        javaExecSpec.args(_destinationDir.getPath());
        javaExecSpec.args(inputDataSchemaFilenames);
    });
}
Also used : StopExecutionException(org.gradle.api.tasks.StopExecutionException) GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Example 7 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project gradle by gradle.

the class TaskExecution method executeActions.

private void executeActions(TaskInternal task, @Nullable InputChangesInternal inputChanges) {
    boolean hasTaskListener = listenerManager.hasListeners(org.gradle.api.execution.TaskActionListener.class) || listenerManager.hasListeners(org.gradle.api.execution.TaskExecutionListener.class);
    Iterator<InputChangesAwareTaskAction> actions = new ArrayList<>(task.getTaskActions()).iterator();
    while (actions.hasNext()) {
        InputChangesAwareTaskAction action = actions.next();
        task.getState().setDidWork(true);
        task.getStandardOutputCapture().start();
        boolean hasMoreWork = hasTaskListener || actions.hasNext();
        try {
            executeAction(action.getDisplayName(), task, action, inputChanges, hasMoreWork);
        } catch (StopActionException e) {
            // Ignore
            LOGGER.debug("Action stopped by some action with message: {}", e.getMessage());
        } catch (StopExecutionException e) {
            LOGGER.info("Execution stopped by some action with message: {}", e.getMessage());
            break;
        } finally {
            task.getStandardOutputCapture().stop();
        }
    }
}
Also used : InputChangesAwareTaskAction(org.gradle.api.internal.tasks.InputChangesAwareTaskAction) StopExecutionException(org.gradle.api.tasks.StopExecutionException) StopActionException(org.gradle.api.tasks.StopActionException)

Example 8 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project atlas by alibaba.

the class BasePlugin method checkModulesForErrors.

/**
     * 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);
        }
    }
}
Also used : Project(org.gradle.api.Project) AndroidProject(com.android.builder.model.AndroidProject) StopExecutionException(org.gradle.api.tasks.StopExecutionException) HashMap(java.util.HashMap)

Example 9 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project atlas by alibaba.

the class PreProcessManifestTask method addAwbManifest2Merge.

private void addAwbManifest2Merge() {
    AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
    for (final BaseVariantOutputData vod : appVariantContext.getVariantData().getOutputs()) {
        ManifestProcessorTask manifestProcessorTask = vod.manifestProcessorTask;
        Set<String> notMergedArtifacts = Sets.newHashSet();
        if (null != atlasExtension.getManifestOptions() && null != atlasExtension.getManifestOptions().getNotMergedBundles()) {
            notMergedArtifacts = atlasExtension.getManifestOptions().getNotMergedBundles();
        }
        if (manifestProcessorTask instanceof MergeManifests) {
            MergeManifests mergeManifests = (MergeManifests) manifestProcessorTask;
            VariantScope variantScope = appVariantContext.getScope();
            GradleVariantConfiguration config = variantScope.getVariantConfiguration();
            AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
            if (null == dependencyTree) {
                throw new StopExecutionException("DependencyTree cannot be null!");
            }
            List<? extends AndroidLibrary> awbManifests = ManifestDependencyUtil.getManifestDependencies(dependencyTree.getAwbBundles(), notMergedArtifacts, getLogger());
            for (AndroidLibrary manifest : awbManifests) {
                getLogger().info("[MTLPlugin]Add manifest:" + manifest.getName() + ",path is:" + manifest.getManifest().getAbsolutePath());
            }
            //FIXME 不加这一步,每次的getibraries 都会从mapping里去重新计算
            mergeManifests.setLibraries(mergeManifests.getLibraries());
            mergeManifests.getLibraries().addAll(awbManifests);
        }
    }
}
Also used : AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) VariantScope(com.android.build.gradle.internal.scope.VariantScope) MergeManifests(com.android.build.gradle.tasks.MergeManifests) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) ManifestProcessorTask(com.android.build.gradle.tasks.ManifestProcessorTask)

Example 10 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project atlas by alibaba.

the class AwbProguradHook method hookProguardTask.

/**
     * hook混淆的任务,加入awb的混淆配置
     *
     * @param appVariantContext
     */
public void hookProguardTask(final AppVariantContext appVariantContext) {
    final VariantScope variantScope = appVariantContext.getScope();
    List<TransformTask> proguaradTransformTasks = getTransformTaskByTransformType(appVariantContext, ProGuardTransform.class);
    for (TransformTask proguaradTransformTask : proguaradTransformTasks) {
        final ProGuardTransform proGuardTransform = (ProGuardTransform) proguaradTransformTask.getTransform();
        if (null != proGuardTransform) {
            proguaradTransformTask.doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    GlobalScope globalScope = variantScope.getGlobalScope();
                    File proguardOut = new File(Joiner.on(File.separatorChar).join(String.valueOf(globalScope.getBuildDir()), FD_OUTPUTS, "mapping", variantScope.getVariantConfiguration().getDirName()));
                    //为了方便排查,先把configuration打印到目录
                    proGuardTransform.printconfiguration(new File(proguardOut, "tmp_config.cfg"));
                    final File outConfigFile = new File(proguardOut, "awb_config.cfg");
                    //增加awb的配置
                    AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getVariantConfiguration().getFullName());
                    if (null == dependencyTree) {
                        throw new StopExecutionException("DependencyTree cannot be null!");
                    }
                    if (dependencyTree.getAwbBundles().size() > 0) {
                        BaseVariantOutputData vod = appVariantContext.getVariantData().getOutputs().get(0);
                        AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext(appVariantContext, vod);
                        File awbObfuscatedDir = new File(globalScope.getIntermediatesDir(), "/classes-proguard/" + variantScope.getVariantConfiguration().getDirName());
                        AwbProguardConfiguration awbProguardConfiguration = new AwbProguardConfiguration(appVariantOutputContext.getAwbTransformMap().values(), awbObfuscatedDir, appVariantOutputContext);
                        try {
                            awbProguardConfiguration.printConfigFile(outConfigFile);
                        } catch (IOException e) {
                            throw new GradleException("", e);
                        }
                        proGuardTransform.setConfigurationFiles(new Supplier<Collection<File>>() {

                            @Override
                            public Collection<File> get() {
                                Set<File> proguardFiles = new HashSet<File>();
                                ((HashSet<File>) proguardFiles).add(outConfigFile);
                                return proguardFiles;
                            }
                        });
                    }
                    File mappingFile = null;
                    if (null != appVariantContext.apContext.getApExploredFolder() && appVariantContext.apContext.getApExploredFolder().exists()) {
                        mappingFile = new File(appVariantContext.apContext.getApExploredFolder(), "mapping.txt");
                    } else {
                        mappingFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "mapping.txt");
                    }
                    if (null != mappingFile && mappingFile.exists()) {
                        proGuardTransform.applyTestedMapping(mappingFile);
                    }
                }
            });
        }
    }
}
Also used : GlobalScope(com.android.build.gradle.internal.scope.GlobalScope) VariantScope(com.android.build.gradle.internal.scope.VariantScope) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Task(org.gradle.api.Task) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) BaseVariantOutputData(com.android.build.gradle.internal.variant.BaseVariantOutputData) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) IOException(java.io.IOException) ProGuardTransform(com.android.build.gradle.internal.transforms.ProGuardTransform) StopExecutionException(org.gradle.api.tasks.StopExecutionException) AwbProguardConfiguration(com.taobao.android.builder.tasks.app.bundle.AwbProguardConfiguration) GradleException(org.gradle.api.GradleException) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Supplier(java.util.function.Supplier) File(java.io.File)

Aggregations

StopExecutionException (org.gradle.api.tasks.StopExecutionException)14 File (java.io.File)5 VariantScope (com.android.build.gradle.internal.scope.VariantScope)2 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)2 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 GradleException (org.gradle.api.GradleException)2 StopActionException (org.gradle.api.tasks.StopActionException)2 TaskAction (org.gradle.api.tasks.TaskAction)2 CompiledFile (android.aapt.pb.internal.ResourcesInternal.CompiledFile)1 ApkFiles (com.android.build.gradle.internal.api.ApkFiles)1 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)1 GradleVariantConfiguration (com.android.build.gradle.internal.core.GradleVariantConfiguration)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)1 DefaultAndroidTask (com.android.build.gradle.internal.tasks.DefaultAndroidTask)1 ProGuardTransform (com.android.build.gradle.internal.transforms.ProGuardTransform)1 ManifestProcessorTask (com.android.build.gradle.tasks.ManifestProcessorTask)1