Search in sources :

Example 6 with TaskExecutionException

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

the class UpgradeBom method upgradeDependencies.

@TaskAction
@SuppressWarnings("deprecation")
void upgradeDependencies() {
    GitHubRepository repository = createGitHub().getRepository(this.bom.getUpgrade().getGitHub().getOrganization(), this.bom.getUpgrade().getGitHub().getRepository());
    List<String> availableLabels = repository.getLabels();
    List<String> issueLabels = this.bom.getUpgrade().getGitHub().getIssueLabels();
    if (!availableLabels.containsAll(issueLabels)) {
        List<String> unknownLabels = new ArrayList<>(issueLabels);
        unknownLabels.removeAll(availableLabels);
        throw new InvalidUserDataException("Unknown label(s): " + StringUtils.collectionToCommaDelimitedString(unknownLabels));
    }
    Milestone milestone = determineMilestone(repository);
    List<Issue> existingUpgradeIssues = repository.findIssues(issueLabels, milestone);
    List<Upgrade> upgrades = new InteractiveUpgradeResolver(new MavenMetadataVersionResolver(this.repositoryUrls), this.bom.getUpgrade().getPolicy(), getServices().get(UserInputHandler.class)).resolveUpgrades(this.bom.getLibraries());
    Path buildFile = getProject().getBuildFile().toPath();
    Path gradleProperties = new File(getProject().getRootProject().getProjectDir(), "gradle.properties").toPath();
    UpgradeApplicator upgradeApplicator = new UpgradeApplicator(buildFile, gradleProperties);
    for (Upgrade upgrade : upgrades) {
        String title = "Upgrade to " + upgrade.getLibrary().getName() + " " + upgrade.getVersion();
        Issue existingUpgradeIssue = findExistingUpgradeIssue(existingUpgradeIssues, upgrade);
        if (existingUpgradeIssue != null) {
            System.out.println(title + " (supersedes #" + existingUpgradeIssue.getNumber() + " " + existingUpgradeIssue.getTitle() + ")");
        } else {
            System.out.println(title);
        }
        try {
            Path modified = upgradeApplicator.apply(upgrade);
            int issueNumber = repository.openIssue(title, (existingUpgradeIssue != null) ? "Supersedes #" + existingUpgradeIssue.getNumber() : "", issueLabels, milestone);
            if (existingUpgradeIssue != null) {
                existingUpgradeIssue.label(Arrays.asList("type: task", "status: superseded"));
            }
            if (new ProcessBuilder().command("git", "add", modified.toFile().getAbsolutePath()).start().waitFor() != 0) {
                throw new IllegalStateException("git add failed");
            }
            if (new ProcessBuilder().command("git", "commit", "-m", title + "\n\nCloses gh-" + issueNumber).start().waitFor() != 0) {
                throw new IllegalStateException("git commit failed");
            }
        } catch (IOException ex) {
            throw new TaskExecutionException(this, ex);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Path(java.nio.file.Path) Issue(org.springframework.boot.build.bom.bomr.github.Issue) Milestone(org.springframework.boot.build.bom.bomr.github.Milestone) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GitHubRepository(org.springframework.boot.build.bom.bomr.github.GitHubRepository) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 7 with TaskExecutionException

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

the class BuildInfo method generateBuildProperties.

/**
 * Generates the {@code build-info.properties} file in the configured
 * {@link #setDestinationDir(File) destination}.
 */
@TaskAction
public void generateBuildProperties() {
    try {
        ProjectDetails details = new ProjectDetails(this.properties.getGroup(), this.properties.getArtifact(), this.properties.getVersion(), this.properties.getName(), this.properties.getTime(), coerceToStringValues(this.properties.getAdditional()));
        new BuildPropertiesWriter(new File(getDestinationDir(), "build-info.properties")).writeBuildProperties(details);
    } catch (IOException ex) {
        throw new TaskExecutionException(this, ex);
    }
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) ProjectDetails(org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetails) BuildPropertiesWriter(org.springframework.boot.loader.tools.BuildPropertiesWriter) IOException(java.io.IOException) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 8 with TaskExecutionException

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

the class LocalTaskNode method resolveMutations.

@Override
public void resolveMutations() {
    final LocalTaskNode taskNode = this;
    final TaskInternal task = getTask();
    final MutationInfo mutations = getMutationInfo();
    ProjectInternal project = (ProjectInternal) task.getProject();
    ServiceRegistry serviceRegistry = project.getServices();
    final FileCollectionFactory fileCollectionFactory = serviceRegistry.get(FileCollectionFactory.class);
    PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
    try {
        taskProperties = DefaultTaskProperties.resolve(propertyWalker, fileCollectionFactory, task);
        addOutputFilesToMutations(taskProperties.getOutputFileProperties());
        addLocalStateFilesToMutations(taskProperties.getLocalStateFiles());
        addDestroyablesToMutations(taskProperties.getDestroyableFiles());
        mutations.hasFileInputs = !taskProperties.getInputFileProperties().isEmpty();
    } catch (Exception e) {
        throw new TaskExecutionException(task, e);
    }
    mutations.resolved = true;
    if (!mutations.destroyablePaths.isEmpty()) {
        if (mutations.hasOutputs) {
            throw new IllegalStateException("Task " + taskNode + " has both outputs and destroyables defined.  A task can define either outputs or destroyables, but not both.");
        }
        if (mutations.hasFileInputs) {
            throw new IllegalStateException("Task " + taskNode + " has both inputs and destroyables defined.  A task can define either inputs or destroyables, but not both.");
        }
        if (mutations.hasLocalState) {
            throw new IllegalStateException("Task " + taskNode + " has both local state and destroyables defined.  A task can define either local state or destroyables, but not both.");
        }
    }
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) TaskInternal(org.gradle.api.internal.TaskInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory)

Example 9 with TaskExecutionException

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

the class DefaultTaskProperties method resolve.

public static TaskProperties resolve(PropertyWalker propertyWalker, FileCollectionFactory fileCollectionFactory, TaskInternal task) {
    String beanName = task.toString();
    GetInputPropertiesVisitor inputPropertiesVisitor = new GetInputPropertiesVisitor();
    GetInputFilesVisitor inputFilesVisitor = new GetInputFilesVisitor(beanName, fileCollectionFactory);
    ValidationVisitor validationVisitor = new ValidationVisitor();
    OutputFilesCollector outputFilesCollector = new OutputFilesCollector();
    OutputUnpacker outputUnpacker = new OutputUnpacker(beanName, fileCollectionFactory, true, true, OutputUnpacker.UnpackedOutputConsumer.composite(outputFilesCollector, validationVisitor));
    GetLocalStateVisitor localStateVisitor = new GetLocalStateVisitor(beanName, fileCollectionFactory);
    GetDestroyablesVisitor destroyablesVisitor = new GetDestroyablesVisitor(beanName, fileCollectionFactory);
    ReplayingTypeValidationContext validationContext = new ReplayingTypeValidationContext();
    try {
        TaskPropertyUtils.visitProperties(propertyWalker, task, validationContext, new CompositePropertyVisitor(inputPropertiesVisitor, inputFilesVisitor, outputUnpacker, validationVisitor, destroyablesVisitor, localStateVisitor));
    } catch (Exception e) {
        throw new TaskExecutionException(task, e);
    }
    return new DefaultTaskProperties(inputPropertiesVisitor.getProperties(), inputFilesVisitor.getFileProperties(), outputFilesCollector.getFileProperties(), outputUnpacker.hasDeclaredOutputs(), localStateVisitor.getFiles(), destroyablesVisitor.getFiles(), validationVisitor.getTaskPropertySpecs(), validationContext);
}
Also used : ReplayingTypeValidationContext(org.gradle.internal.reflect.validation.ReplayingTypeValidationContext) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException)

Example 10 with TaskExecutionException

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

the class ExceptionMetadataHelper method getMetadata.

public static Map<String, String> getMetadata(Throwable t) {
    Map<String, String> metadata = new LinkedHashMap<>();
    if (t instanceof TaskExecutionException) {
        TaskExecutionException taskExecutionException = (TaskExecutionException) t;
        String taskPath = ((TaskInternal) taskExecutionException.getTask()).getIdentityPath().getPath();
        metadata.put(METADATA_KEY_TASK_PATH, taskPath);
    }
    if (t instanceof ScriptCompilationException) {
        ScriptCompilationException sce = (ScriptCompilationException) t;
        metadata.put(METADATA_KEY_SCRIPT_FILE, sce.getScriptSource().getFileName());
        Integer sceLineNumber = sce.getLineNumber();
        if (sceLineNumber != null) {
            metadata.put(METADATA_KEY_SCRIPT_LINE_NUMBER, sceLineNumber.toString());
        }
    }
    if (t instanceof LocationAwareException) {
        LocationAwareException lae = (LocationAwareException) t;
        metadata.put(METADATA_KEY_SOURCE_DISPLAY_NAME, lae.getSourceDisplayName());
        Integer laeLineNumber = lae.getLineNumber();
        if (laeLineNumber != null) {
            metadata.put(METADATA_KEY_LINE_NUMBER, laeLineNumber.toString());
        }
        metadata.put(METADATA_KEY_LOCATION, lae.getLocation());
    }
    if (t instanceof MultiCauseException) {
        metadata.put(METADATA_KEY_IS_MULTICAUSE, String.valueOf(true));
    }
    return metadata;
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) MultiCauseException(org.gradle.internal.exceptions.MultiCauseException) ScriptCompilationException(org.gradle.groovy.scripts.ScriptCompilationException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)20 TaskAction (org.gradle.api.tasks.TaskAction)9 IOException (java.io.IOException)5 File (java.io.File)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GradleException (org.gradle.api.GradleException)2 GradleScriptException (org.gradle.api.GradleScriptException)2 TaskInternal (org.gradle.api.internal.TaskInternal)2 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 Test (org.junit.Test)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 GsonBuilder (com.google.gson.GsonBuilder)1 FunctionConfiguration (com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration)1 AnnotationHandler (com.microsoft.azure.gradle.functions.handlers.AnnotationHandler)1 FunctionTemplate (com.microsoft.azure.gradle.functions.template.FunctionTemplate)1 AzureAuthFailureException (com.microsoft.azure.gradle.webapp.auth.AzureAuthFailureException)1