Search in sources :

Example 41 with InvalidUserDataException

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

the class AnnotationProcessorPathFactory method getProcessorPathFromCompilerArguments.

private FileCollection getProcessorPathFromCompilerArguments(final CompileOptions compileOptions) {
    final FileCollection annotationProcessorPath = compileOptions.getAnnotationProcessorPath();
    List<String> compilerArgs = compileOptions.getAllCompilerArgs();
    int pos = compilerArgs.indexOf("-processorpath");
    if (pos < 0) {
        return null;
    }
    if (pos == compilerArgs.size() - 1) {
        throw new InvalidUserDataException("No path provided for compiler argument -processorpath in requested compiler args: " + Joiner.on(" ").join(compilerArgs));
    }
    final String processorpath = compilerArgs.get(pos + 1);
    if (annotationProcessorPath == null) {
        return fileCollectionFactory.fixed("annotation processor path", extractProcessorPath(processorpath));
    }
    return fileCollectionFactory.create(new AbstractTaskDependency() {

        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            context.add(annotationProcessorPath);
        }
    }, new MinimalFileSet() {

        @Override
        public Set<File> getFiles() {
            if (!annotationProcessorPath.isEmpty()) {
                return annotationProcessorPath.getFiles();
            }
            return extractProcessorPath(processorpath);
        }

        @Override
        public final String getDisplayName() {
            return "annotation processor path";
        }
    });
}
Also used : AbstractTaskDependency(org.gradle.api.internal.tasks.AbstractTaskDependency) MinimalFileSet(org.gradle.api.internal.file.collections.MinimalFileSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) FileCollection(org.gradle.api.file.FileCollection) MinimalFileSet(org.gradle.api.internal.file.collections.MinimalFileSet)

Example 42 with InvalidUserDataException

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

the class DefaultIvyPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    configurations.maybeCreate("default");
    Set<PublishArtifact> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        Usage usage = usageContext.getUsage();
        String conf = mapUsage(usage);
        configurations.maybeCreate(conf);
        configurations.getByName("default").extend(conf);
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            if (!seenArtifacts.contains(publishArtifact)) {
                seenArtifacts.add(publishArtifact);
                artifact(publishArtifact).setConf(conf);
            }
        }
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id.
                String confMapping = String.format("%s->%s", conf, dependency.getTargetConfiguration() == null ? Dependency.DEFAULT_CONFIGURATION : dependency.getTargetConfiguration());
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, confMapping);
                } else {
                    addExternalDependency((ExternalDependency) dependency, confMapping);
                }
            }
        }
    }
}
Also used : Usage(org.gradle.api.attributes.Usage) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) UsageContext(org.gradle.api.internal.component.UsageContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 43 with InvalidUserDataException

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

the class DefaultMavenPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    Set<ArtifactKey> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    Set<DependencyConstraint> seenConstraints = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            ArtifactKey key = new ArtifactKey(publishArtifact.getFile(), publishArtifact.getClassifier(), publishArtifact.getExtension());
            if (seenArtifacts.add(key)) {
                artifact(publishArtifact);
            }
        }
        Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext.getUsage());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, dependencies);
                } else {
                    addModuleDependency(dependency, dependencies);
                }
            }
        }
        Set<MavenDependency> dependencyConstraints = dependencyConstraintsFor(usageContext.getUsage());
        for (DependencyConstraint dependency : usageContext.getDependencyConstraints()) {
            if (seenConstraints.add(dependency) && !dependency.getVersionConstraint().getPreferredVersion().isEmpty()) {
                addDependencyConstraint(dependency, dependencyConstraints);
            }
        }
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) UsageContext(org.gradle.api.internal.component.UsageContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultMavenDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency) MavenDependency(org.gradle.api.publish.maven.MavenDependency)

Example 44 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project spring-boot by spring-projects.

the class InteractiveUpgradeResolver method alignedVersionOption.

private VersionOption alignedVersionOption(Library library, Map<String, Library> libraries) {
    VersionAlignment versionAlignment = library.getVersion().getVersionAlignment();
    Library alignmentLibrary = libraries.get(versionAlignment.getLibraryName());
    DependencyVersions dependencyVersions = alignmentLibrary.getDependencyVersions();
    if (dependencyVersions == null) {
        throw new InvalidUserDataException("Cannot align with library '" + versionAlignment.getLibraryName() + "' as it does not define any dependency versions");
    }
    if (!dependencyVersions.available()) {
        return null;
    }
    Set<String> versions = new HashSet<>();
    for (Group group : library.getGroups()) {
        for (Module module : group.getModules()) {
            String version = dependencyVersions.getVersion(group.getId(), module.getName());
            if (version != null) {
                versions.add(version);
            }
        }
    }
    if (versions.isEmpty()) {
        throw new InvalidUserDataException("Cannot align with library '" + versionAlignment.getLibraryName() + "' as its dependency versions do not include any of this library's modules");
    }
    if (versions.size() > 1) {
        throw new InvalidUserDataException("Cannot align with library '" + versionAlignment.getLibraryName() + "' as it uses multiple different versions of this library's modules");
    }
    DependencyVersion version = DependencyVersion.parse(versions.iterator().next());
    return library.getVersion().getVersion().equals(version) ? null : new AlignedVersionOption(version, alignmentLibrary);
}
Also used : Group(org.springframework.boot.build.bom.Library.Group) DependencyVersions(org.springframework.boot.build.bom.Library.DependencyVersions) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DependencyVersion(org.springframework.boot.build.bom.bomr.version.DependencyVersion) Library(org.springframework.boot.build.bom.Library) VersionAlignment(org.springframework.boot.build.bom.Library.VersionAlignment) Module(org.springframework.boot.build.bom.Library.Module) HashSet(java.util.HashSet)

Example 45 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project spring-boot by spring-projects.

the class UpgradeBom method createGitHub.

private GitHub createGitHub() {
    Properties bomrProperties = new Properties();
    try (Reader reader = new FileReader(new File(System.getProperty("user.home"), ".bomr.properties"))) {
        bomrProperties.load(reader);
        String username = bomrProperties.getProperty("bomr.github.username");
        String password = bomrProperties.getProperty("bomr.github.password");
        return GitHub.withCredentials(username, password);
    } catch (IOException ex) {
        throw new InvalidUserDataException("Failed to load .bomr.properties from user home", ex);
    }
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties) 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