Search in sources :

Example 56 with InvalidUserDataException

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

the class ResolveChangesStep method createIncrementalInputProperties.

private static IncrementalInputProperties createIncrementalInputProperties(UnitOfWork work) {
    UnitOfWork.InputChangeTrackingStrategy inputChangeTrackingStrategy = work.getInputChangeTrackingStrategy();
    switch(inputChangeTrackingStrategy) {
        case NONE:
            return IncrementalInputProperties.NONE;
        // noinspection deprecation
        case ALL_PARAMETERS:
            // When using IncrementalTaskInputs, keep the old behaviour of all file inputs being incremental
            return IncrementalInputProperties.ALL;
        case INCREMENTAL_PARAMETERS:
            ImmutableBiMap.Builder<String, Object> builder = ImmutableBiMap.builder();
            InputVisitor visitor = new InputVisitor() {

                @Override
                public void visitInputFileProperty(String propertyName, InputPropertyType type, FileValueSupplier valueSupplier) {
                    if (type.isIncremental()) {
                        Object value = valueSupplier.getValue();
                        if (value == null) {
                            throw new InvalidUserDataException("Must specify a value for incremental input property '" + propertyName + "'.");
                        }
                        builder.put(propertyName, value);
                    }
                }
            };
            work.visitIdentityInputs(visitor);
            work.visitRegularInputs(visitor);
            return new DefaultIncrementalInputProperties(builder.build());
        default:
            throw new AssertionError("Unknown InputChangeTrackingStrategy: " + inputChangeTrackingStrategy);
    }
}
Also used : UnitOfWork(org.gradle.internal.execution.UnitOfWork) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) InputPropertyType(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputPropertyType) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DefaultIncrementalInputProperties(org.gradle.internal.execution.history.changes.DefaultIncrementalInputProperties) InputVisitor(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputVisitor) FileValueSupplier(org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier)

Example 57 with InvalidUserDataException

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

the class DefaultFileOperations method mkdir.

@Override
public File mkdir(Object path) {
    File dir = fileResolver.resolve(path);
    if (dir.isFile()) {
        throw new InvalidUserDataException(String.format("Can't create directory. The path=%s points to an existing file.", path));
    }
    GFileUtils.mkdirs(dir);
    return dir;
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 58 with InvalidUserDataException

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

the class DefaultSourceDirectorySet method getSourceTrees.

protected Set<DirectoryFileTree> getSourceTrees() {
    Set<DirectoryFileTree> result = new LinkedHashSet<>();
    for (Object path : source) {
        if (path instanceof DefaultSourceDirectorySet) {
            DefaultSourceDirectorySet nested = (DefaultSourceDirectorySet) path;
            result.addAll(nested.getSourceTrees());
        } else {
            for (File srcDir : fileCollectionFactory.resolving(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) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) File(java.io.File)

Example 59 with InvalidUserDataException

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

the class DefaultCatalogProblemBuilder method maybeThrowError.

public static void maybeThrowError(String error, List<VersionCatalogProblem> problems) {
    if (!problems.isEmpty()) {
        TreeFormatter formatter = new TreeFormatter();
        formatter.node(error);
        formatter.startChildren();
        for (VersionCatalogProblem problem : problems) {
            problem.reportInto(formatter);
        }
        formatter.endChildren();
        throw new InvalidUserDataException(formatter.toString());
    }
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 60 with InvalidUserDataException

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

the class DefaultTaskContainer method findByPath.

@Override
public Task findByPath(String path) {
    if (Strings.isNullOrEmpty(path)) {
        throw new InvalidUserDataException("A path must be specified!");
    }
    if (!path.contains(Project.PATH_SEPARATOR)) {
        return findByName(path);
    }
    String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR);
    ProjectInternal project = this.project.findProject(Strings.isNullOrEmpty(projectPath) ? Project.PATH_SEPARATOR : projectPath);
    if (project == null) {
        return null;
    }
    project.getOwner().ensureTasksDiscovered();
    return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR));
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

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