Search in sources :

Example 36 with InvalidUserDataException

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

the class DefaultCopySpec method filesNotMatching.

public CopySpec filesNotMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) {
    if (!patterns.iterator().hasNext()) {
        throw new InvalidUserDataException("must provide at least one pattern to not 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(Specs.<RelativePath>negate(unionMatcher), action));
}
Also used : RelativePath(org.gradle.api.file.RelativePath) 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 37 with InvalidUserDataException

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

the class JettyRun method validateConfiguration.

public void validateConfiguration() {
    // check the location of the static content/jsps etc
    try {
        if ((getWebAppSourceDirectory() == null) || !getWebAppSourceDirectory().exists()) {
            throw new InvalidUserDataException("Webapp source directory " + (getWebAppSourceDirectory() == null ? "null" : getWebAppSourceDirectory().getCanonicalPath()) + " does not exist");
        } else {
            LOGGER.info("Webapp source directory = " + getWebAppSourceDirectory().getCanonicalPath());
        }
    } catch (IOException e) {
        throw new InvalidUserDataException("Webapp source directory does not exist", e);
    }
    // check reload mechanic
    if (!"automatic".equalsIgnoreCase(reload) && !"manual".equalsIgnoreCase(reload)) {
        throw new InvalidUserDataException("invalid reload mechanic specified, must be 'automatic' or 'manual'");
    } else {
        LOGGER.info("Reload Mechanic: " + reload);
    }
    // get the web.xml file if one has been provided, otherwise assume it is in the webapp src directory
    if (getWebXml() == null) {
        setWebXml(new File(new File(getWebAppSourceDirectory(), "WEB-INF"), "web.xml"));
    }
    LOGGER.info("web.xml file = " + getWebXml());
    //check if a jetty-env.xml location has been provided, if so, it must exist
    if (getJettyEnvXml() != null) {
        setJettyEnvXmlFile(jettyEnvXml);
        try {
            if (!getJettyEnvXmlFile().exists()) {
                throw new InvalidUserDataException("jetty-env.xml file does not exist at location " + jettyEnvXml);
            } else {
                LOGGER.info(" jetty-env.xml = " + getJettyEnvXmlFile().getCanonicalPath());
            }
        } catch (IOException e) {
            throw new InvalidUserDataException("jetty-env.xml does not exist");
        }
    }
    setExtraScanTargets(new ArrayList<File>());
    if (scanTargets != null) {
        for (File scanTarget : scanTargets) {
            LOGGER.info("Added extra scan target:" + scanTarget);
            getExtraScanTargets().add(scanTarget);
        }
    }
    if (scanTargetPatterns != null) {
        for (ScanTargetPattern scanTargetPattern : scanTargetPatterns) {
            ConfigurableFileTree files = getProject().fileTree(scanTargetPattern.getDirectory());
            files.include(scanTargetPattern.getIncludes());
            files.exclude(scanTargetPattern.getExcludes());
            Set<File> currentTargets = getExtraScanTargets();
            if (currentTargets != null && !currentTargets.isEmpty()) {
                currentTargets.addAll(files.getFiles());
            } else {
                setExtraScanTargets(files.getFiles());
            }
        }
    }
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree) IOException(java.io.IOException) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile)

Example 38 with InvalidUserDataException

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

the class TaskFactory method validateArgs.

private void validateArgs(Map<String, Object> args) {
    if (!validTaskArguments.containsAll(args.keySet())) {
        Map unknownArguments = new HashMap<String, Object>(args);
        unknownArguments.keySet().removeAll(validTaskArguments);
        throw new InvalidUserDataException(String.format("Could not create task '%s': Unknown argument(s) in task definition: %s", args.get(Task.TASK_NAME), unknownArguments.keySet()));
    }
}
Also used : HashMap(java.util.HashMap) InvalidUserDataException(org.gradle.api.InvalidUserDataException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 39 with InvalidUserDataException

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

the class LazyPublishArtifact method getFile.

@Override
public File getFile() {
    if (file == null) {
        Object value = provider.get();
        if (value instanceof FileSystemLocation) {
            FileSystemLocation location = (FileSystemLocation) value;
            file = location.getAsFile();
        } else if (value instanceof File) {
            file = (File) value;
        } else {
            throw new InvalidUserDataException(String.format("Cannot convert provided value (%s) to a file.", value));
        }
    }
    return file;
}
Also used : FileSystemLocation(org.gradle.api.file.FileSystemLocation) InvalidUserDataException(org.gradle.api.InvalidUserDataException) File(java.io.File)

Example 40 with InvalidUserDataException

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

the class GetInputPropertiesVisitor method getPropertyValuesFactory.

public Factory<Map<String, Object>> getPropertyValuesFactory() {
    return new Factory<Map<String, Object>>() {

        @Override
        public Map<String, Object> create() {
            Map<String, Object> result = new HashMap<String, Object>();
            for (TaskInputPropertySpec inputProperty : inputProperties) {
                String propertyName = inputProperty.getPropertyName();
                try {
                    Object value = prepareValue(inputProperty.getValue());
                    result.put(propertyName, value);
                } catch (Exception ex) {
                    throw new InvalidUserDataException(String.format("Error while evaluating property '%s' of %s", propertyName, beanName), ex);
                }
            }
            return result;
        }
    };
}
Also used : HashMap(java.util.HashMap) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskInputPropertySpec(org.gradle.api.internal.tasks.TaskInputPropertySpec) Factory(org.gradle.internal.Factory) GString(groovy.lang.GString) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

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