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();
}
}
}
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);
}
}
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.");
}
}
}
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);
}
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;
}
Aggregations