Search in sources :

Example 11 with InvalidUserDataException

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);
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) TaskAction(org.gradle.api.tasks.TaskAction)

Example 12 with InvalidUserDataException

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());
            }
        }
    }));
}
Also used : Task(org.gradle.api.Task) AbstractTask(org.gradle.api.internal.AbstractTask) DefaultTask(org.gradle.api.DefaultTask) ObjectInstantiationException(org.gradle.api.reflect.ObjectInstantiationException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DefaultTask(org.gradle.api.DefaultTask) Callable(java.util.concurrent.Callable) TaskInstantiationException(org.gradle.api.tasks.TaskInstantiationException)

Example 13 with InvalidUserDataException

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);
}
Also used : Action(org.gradle.api.Action) Closure(groovy.lang.Closure) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskInternal(org.gradle.api.internal.TaskInternal) DynamicObject(org.gradle.internal.metaobject.DynamicObject)

Example 14 with InvalidUserDataException

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);
}
Also used : FindBugsReportsImpl(org.gradle.api.plugins.quality.internal.FindBugsReportsImpl) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArrayList(java.util.ArrayList) CustomizableHtmlReportImpl(org.gradle.api.reporting.internal.CustomizableHtmlReportImpl) File(java.io.File)

Example 15 with InvalidUserDataException

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;
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArtifactTransform(org.gradle.api.artifacts.transform.ArtifactTransform) File(java.io.File)

Aggregations

InvalidUserDataException (org.gradle.api.InvalidUserDataException)61 File (java.io.File)18 Task (org.gradle.api.Task)6 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Action (org.gradle.api.Action)5 TaskAction (org.gradle.api.tasks.TaskAction)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 DefaultTask (org.gradle.api.DefaultTask)4 ImmutableList (com.google.common.collect.ImmutableList)3 Closure (groovy.lang.Closure)3 Map (java.util.Map)3 MavenArtifactRepository (org.gradle.api.artifacts.repositories.MavenArtifactRepository)3 TaskInternal (org.gradle.api.internal.TaskInternal)3 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)3 DirectorySensitivity (org.gradle.internal.fingerprint.DirectorySensitivity)3 LineEndingSensitivity (org.gradle.internal.fingerprint.LineEndingSensitivity)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Nullable (javax.annotation.Nullable)2