Search in sources :

Example 1 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class JettyStop method stop.

@TaskAction
public void stop() {
    if (getStopPort() == null) {
        throw new InvalidUserDataException("Please specify a valid port");
    }
    if (getStopKey() == null) {
        throw new InvalidUserDataException("Please specify a valid stopKey");
    }
    ProgressLogger progressLogger = getServices().get(ProgressLoggerFactory.class).newOperation(JettyStop.class).start("Stop Jetty server", "Stopping Jetty");
    try {
        Socket s = new Socket(InetAddress.getByName("127.0.0.1"), getStopPort());
        s.setSoLinger(false, 0);
        OutputStream out = s.getOutputStream();
        out.write((getStopKey() + "\r\nstop\r\n").getBytes());
        out.flush();
        s.close();
    } catch (ConnectException e) {
        LOGGER.info("Jetty not running!");
    } catch (Exception e) {
        LOGGER.error("Exception during stopping", e);
    } finally {
        progressLogger.completed();
    }
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) OutputStream(java.io.OutputStream) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) Socket(java.net.Socket) ConnectException(java.net.ConnectException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ConnectException(java.net.ConnectException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class TaskFactory method createTask.

public TaskInternal createTask(Map<String, ?> args) {
    Map<String, Object> actualArgs = new HashMap<String, Object>(args);
    checkTaskArgsAndCreateDefaultValues(actualArgs);
    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 = (Class) actualArgs.get(Task.TASK_TYPE);
    TaskInternal task = create(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 = (Action<? super Task>) action;
        task.doFirst(taskAction);
    } else if (action != null) {
        Closure closure = (Closure) action;
        task.doFirst(closure);
    }
    return task;
}
Also used : Action(org.gradle.api.Action) AbstractTask(org.gradle.api.internal.AbstractTask) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) Closure(groovy.lang.Closure) HashMap(java.util.HashMap) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskInternal(org.gradle.api.internal.TaskInternal)

Example 3 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class ArtifactTransformBackedTransformer method apply.

@Override
public List<File> apply(File file, File outputDir) {
    ArtifactTransform artifactTransform = create();
    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)

Example 4 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class DefaultCopySpec method filesMatching.

public CopySpec filesMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) {
    if (!patterns.iterator().hasNext()) {
        throw new InvalidUserDataException("must provide at least one pattern to match");
    }
    List<Spec> matchers = new ArrayList<Spec>();
    for (String pattern : patterns) {
        matchers.add(PatternMatcherFactory.getPatternMatcher(true, isCaseSensitive(), pattern));
    }
    Spec unionMatcher = Specs.union(matchers.toArray(new Spec[matchers.size()]));
    return eachFile(new MatchingCopyAction(unionMatcher, action));
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArrayList(java.util.ArrayList) CopySpec(org.gradle.api.file.CopySpec) CopyProcessingSpec(org.gradle.api.file.CopyProcessingSpec) Spec(org.gradle.api.specs.Spec)

Example 5 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class DefaultSourceDirectorySet method doGetSrcDirTrees.

private Set<DirectoryTree> doGetSrcDirTrees() {
    Set<DirectoryTree> result = new LinkedHashSet<DirectoryTree>();
    for (Object path : source) {
        if (path instanceof SourceDirectorySet) {
            SourceDirectorySet nested = (SourceDirectorySet) path;
            result.addAll(nested.getSrcDirTrees());
        } else {
            for (File srcDir : fileResolver.resolveFiles(path)) {
                if (srcDir.exists() && !srcDir.isDirectory()) {
                    throw new InvalidUserDataException(String.format("Source directory '%s' is not a directory.", srcDir));
                }
                result.add(directoryFileTreeFactory.create(srcDir, patterns));
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DirectoryTree(org.gradle.api.file.DirectoryTree) InvalidUserDataException(org.gradle.api.InvalidUserDataException) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) 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