use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class PublishToMavenRepository method publish.
@TaskAction
public void publish() {
MavenPublicationInternal publicationInternal = getPublicationInternal();
if (publicationInternal == null) {
throw new InvalidUserDataException("The 'publication' property is required");
}
MavenArtifactRepository repository = getRepository();
if (repository == null) {
throw new InvalidUserDataException("The 'repository' property is required");
}
doPublish(publicationInternal, repository);
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class TaskFactory method create.
@Override
public <S extends Task> S create(String name, final Class<S> type, final Object... args) {
if (!Task.class.isAssignableFrom(type)) {
throw new InvalidUserDataException(String.format("Cannot create task of type '%s' as it does not implement the Task interface.", type.getSimpleName()));
}
NameValidator.validate(name, "task name", "");
final Class<? extends Task> generatedType;
if (type.isAssignableFrom(DefaultTask.class)) {
generatedType = generator.generate(DefaultTask.class);
} else {
generatedType = generator.generate(type);
}
return type.cast(AbstractTask.injectIntoNewInstance(project, name, type, new Callable<Task>() {
public Task call() throws Exception {
try {
if (args != null) {
return instantiator.newInstance(generatedType, args);
}
return instantiator.newInstance(generatedType);
} catch (ObjectInstantiationException e) {
throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()), e.getCause());
}
}
}));
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class DefaultTaskContainer method create.
public Task create(Map<String, ?> options) {
Map<String, ?> factoryOptions = options;
boolean replace = false;
if (options.containsKey(Task.TASK_OVERWRITE)) {
factoryOptions = new HashMap<String, Object>(options);
Object replaceStr = factoryOptions.remove(Task.TASK_OVERWRITE);
replace = "true".equals(replaceStr.toString());
}
Map<String, ?> actualArgs = checkTaskArgsAndCreateDefaultValues(factoryOptions);
String name = actualArgs.get(Task.TASK_NAME).toString();
if (!GUtil.isTrue(name)) {
throw new InvalidUserDataException("The task name must be provided.");
}
Class<? extends TaskInternal> type = Cast.uncheckedCast(actualArgs.get(Task.TASK_TYPE));
Object[] constructorArgs = getConstructorArgs(actualArgs);
TaskInternal task;
if (constructorArgs != null) {
task = createTask(name, type, constructorArgs);
} else {
task = createTask(name, type);
}
Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
if (dependsOnTasks != null) {
task.dependsOn(dependsOnTasks);
}
Object description = actualArgs.get(Task.TASK_DESCRIPTION);
if (description != null) {
task.setDescription(description.toString());
}
Object group = actualArgs.get(Task.TASK_GROUP);
if (group != null) {
task.setGroup(group.toString());
}
Object action = actualArgs.get(Task.TASK_ACTION);
if (action instanceof Action) {
Action<? super Task> taskAction = Cast.uncheckedCast(action);
task.doFirst(taskAction);
} else if (action != null) {
Closure closure = (Closure) action;
task.doFirst(closure);
}
return addTask(task, replace);
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class FindBugsSpecBuilder method build.
public FindBugsSpec build() {
ArrayList<String> args = new ArrayList<String>();
args.add("-pluginList");
args.add(pluginsList == null ? "" : pluginsList.getAsPath());
args.add("-sortByClass");
args.add("-timestampNow");
if (showProgress) {
args.add("-progress");
}
if (reports != null && !reports.getEnabled().isEmpty()) {
if (reports.getEnabled().size() == 1) {
FindBugsReportsImpl reportsImpl = (FindBugsReportsImpl) reports;
String outputArg = "-" + reportsImpl.getFirstEnabled().getName();
if (reportsImpl.getFirstEnabled() instanceof FindBugsXmlReportImpl) {
FindBugsXmlReportImpl r = (FindBugsXmlReportImpl) reportsImpl.getFirstEnabled();
if (r.isWithMessages()) {
outputArg += ":withMessages";
}
} else if (reportsImpl.getFirstEnabled() instanceof CustomizableHtmlReportImpl) {
CustomizableHtmlReportImpl r = (CustomizableHtmlReportImpl) reportsImpl.getFirstEnabled();
if (r.getStylesheet() != null) {
outputArg += ':' + r.getStylesheet().asFile().getAbsolutePath();
}
}
args.add(outputArg);
args.add("-outputFile");
args.add(reportsImpl.getFirstEnabled().getDestination().getAbsolutePath());
} else {
throw new InvalidUserDataException("FindBugs tasks can only have one report enabled, however more than one report was enabled. You need to disable all but one of them.");
}
}
if (has(sources)) {
args.add("-sourcepath");
args.add(sources.getAsPath());
}
if (has(classpath)) {
args.add("-auxclasspath");
// Filter unexisting files as FindBugs can't handle them.
args.add(classpath.filter(new Spec<File>() {
public boolean isSatisfiedBy(File element) {
return element.exists();
}
}).getAsPath());
}
if (has(effort)) {
args.add(String.format("-effort:%s", effort));
}
if (has(reportLevel)) {
args.add(String.format("-%s", reportLevel));
}
if (has(visitors)) {
args.add("-visitors");
args.add(CollectionUtils.join(",", visitors));
}
if (has(omitVisitors)) {
args.add("-omitVisitors");
args.add(CollectionUtils.join(",", omitVisitors));
}
if (has(excludeFilter)) {
args.add("-exclude");
args.add(excludeFilter.getPath());
}
if (has(includeFilter)) {
args.add("-include");
args.add(includeFilter.getPath());
}
if (has(excludeBugsFilter)) {
args.add("-excludeBugs");
args.add(excludeBugsFilter.getPath());
}
if (has(extraArgs)) {
args.addAll(extraArgs);
}
for (File classDir : classesDirs.getFiles()) {
// FindBugs cannot handle missing directories
if (classDir.exists()) {
args.add(classDir.getAbsolutePath());
}
}
return new FindBugsSpec(args, maxHeapSize, debugEnabled, jvmArgs == null ? Collections.<String>emptyList() : jvmArgs);
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class TransformArtifactsAction method apply.
@Override
public List<File> apply(File file, File outputDir) {
ArtifactTransform artifactTransform = instantiator.newInstance(implementationClass, parameters.isolate());
artifactTransform.setOutputDirectory(outputDir);
List<File> outputs = artifactTransform.transform(file);
if (outputs == null) {
throw new InvalidUserDataException("Transform returned null result.");
}
String inputFilePrefix = file.getPath() + File.separator;
String outputDirPrefix = outputDir.getPath() + File.separator;
for (File output : outputs) {
if (!output.exists()) {
throw new InvalidUserDataException("Transform output file " + output.getPath() + " does not exist.");
}
if (output.equals(file) || output.equals(outputDir)) {
continue;
}
if (output.getPath().startsWith(outputDirPrefix)) {
continue;
}
if (output.getPath().startsWith(inputFilePrefix)) {
continue;
}
throw new InvalidUserDataException("Transform output file " + output.getPath() + " is not a child of the transform's input file or output directory.");
}
return outputs;
}
Aggregations