Search in sources :

Example 21 with InvalidUserDataException

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

the class AbstractLazyModuleComponentResolveMetadata method addVariantsByRule.

private Optional<ImmutableList<? extends ConfigurationMetadata>> addVariantsByRule(Optional<ImmutableList<? extends ConfigurationMetadata>> variants) {
    if (variantMetadataRules.getAdditionalVariants().isEmpty()) {
        return variants;
    }
    Map<String, ConfigurationMetadata> variantsByName = variants.or(ImmutableList.of()).stream().collect(Collectors.toMap(ConfigurationMetadata::getName, Function.identity()));
    ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<>();
    if (variants.isPresent()) {
        builder.addAll(variants.get());
    }
    for (AdditionalVariant additionalVariant : variantMetadataRules.getAdditionalVariants()) {
        String baseName = additionalVariant.getBase();
        ConfigurationMetadata base = null;
        if (baseName != null) {
            if (variants.isPresent()) {
                base = variantsByName.get(baseName);
                if (!additionalVariant.isLenient() && !(base instanceof ModuleConfigurationMetadata)) {
                    throw new InvalidUserDataException("Variant '" + baseName + "' not defined in module " + getId().getDisplayName());
                }
            } else {
                base = getConfiguration(baseName);
                if (!additionalVariant.isLenient() && !(base instanceof ModuleConfigurationMetadata)) {
                    throw new InvalidUserDataException("Configuration '" + baseName + "' not defined in module " + getId().getDisplayName());
                }
            }
        }
        if (baseName == null || base instanceof ModuleConfigurationMetadata) {
            ConfigurationMetadata configurationMetadata = new LazyRuleAwareWithBaseConfigurationMetadata(additionalVariant.getName(), (ModuleConfigurationMetadata) base, getId(), getAttributes(), variantMetadataRules, constructVariantExcludes(base), false);
            builder.add(configurationMetadata);
        }
    }
    return Optional.of(builder.build());
}
Also used : ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata) ImmutableList(com.google.common.collect.ImmutableList) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata)

Example 22 with InvalidUserDataException

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

the class LazyToRealisedModuleComponentResolveMetadataHelper method addVariantsFromRules.

private static ImmutableList<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> addVariantsFromRules(ModuleComponentResolveMetadata componentMetadata, List<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> declaredVariants, VariantMetadataRules variantMetadataRules) {
    List<AdditionalVariant> additionalVariants = variantMetadataRules.getAdditionalVariants();
    if (additionalVariants.isEmpty()) {
        return ImmutableList.copyOf(declaredVariants);
    }
    ImmutableList.Builder<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> builder = new ImmutableList.Builder<>();
    builder.addAll(declaredVariants);
    Map<String, ComponentVariant> variantsByName = declaredVariants.stream().collect(Collectors.toMap(ComponentVariant::getName, Function.identity()));
    for (AdditionalVariant additionalVariant : additionalVariants) {
        String baseName = additionalVariant.getBase();
        ImmutableAttributes attributes;
        ImmutableCapabilities capabilities;
        ImmutableList<? extends ComponentVariant.Dependency> dependencies;
        ImmutableList<? extends ComponentVariant.DependencyConstraint> dependencyConstraints;
        ImmutableList<? extends ComponentVariant.File> files;
        ComponentVariant baseVariant = variantsByName.get(baseName);
        boolean isExternalVariant;
        if (baseVariant == null) {
            attributes = componentMetadata.getAttributes();
            capabilities = ImmutableCapabilities.EMPTY;
            dependencies = ImmutableList.of();
            dependencyConstraints = ImmutableList.of();
            files = ImmutableList.of();
            isExternalVariant = false;
        } else {
            attributes = (ImmutableAttributes) baseVariant.getAttributes();
            capabilities = (ImmutableCapabilities) baseVariant.getCapabilities();
            dependencies = baseVariant.getDependencies();
            dependencyConstraints = baseVariant.getDependencyConstraints();
            files = baseVariant.getFiles();
            isExternalVariant = baseVariant.isExternalVariant();
        }
        if (baseName == null || baseVariant != null) {
            AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl variant = applyRules(new AbstractMutableModuleComponentResolveMetadata.ImmutableVariantImpl(componentMetadata.getId(), additionalVariant.getName(), attributes, dependencies, dependencyConstraints, files, capabilities, isExternalVariant), variantMetadataRules, componentMetadata.getId());
            builder.add(variant);
        } else if (!additionalVariant.isLenient()) {
            throw new InvalidUserDataException("Variant '" + baseName + "' not defined in module " + componentMetadata.getId().getDisplayName());
        }
    }
    return builder.build();
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableList(com.google.common.collect.ImmutableList) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 23 with InvalidUserDataException

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

the class ZipFileTree method visit.

@Override
public void visit(FileVisitor visitor) {
    File zipFile = fileProvider.get();
    if (!zipFile.exists()) {
        throw new InvalidUserDataException(format("Cannot expand %s as it does not exist.", getDisplayName()));
    }
    if (!zipFile.isFile()) {
        throw new InvalidUserDataException(format("Cannot expand %s as it is not a file.", getDisplayName()));
    }
    AtomicBoolean stopFlag = new AtomicBoolean();
    File expandedDir = getExpandedDir();
    try (ZipFile zip = new ZipFile(zipFile)) {
        // The iteration order of zip.getEntries() is based on the hash of the zip entry. This isn't much use
        // to us. So, collect the entries in a map and iterate over them in alphabetical order.
        Iterator<ZipEntry> sortedEntries = entriesSortedByName(zip);
        while (!stopFlag.get() && sortedEntries.hasNext()) {
            ZipEntry entry = sortedEntries.next();
            DetailsImpl details = new DetailsImpl(zipFile, expandedDir, entry, zip, stopFlag, chmod);
            if (entry.isDirectory()) {
                visitor.visitDir(details);
            } else {
                visitor.visitFile(details);
            }
        }
    } catch (Exception e) {
        throw new GradleException(format("Could not expand %s.", getDisplayName()), e);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ZipFile(org.apache.tools.zip.ZipFile) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ZipEntry(org.apache.tools.zip.ZipEntry) GradleException(org.gradle.api.GradleException) ZipFile(org.apache.tools.zip.ZipFile) File(java.io.File) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 24 with InvalidUserDataException

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

the class BasicFileResolver method transform.

@Override
public File transform(String original) {
    if (original.startsWith("file:")) {
        try {
            return FileUtils.normalize(new File(new URI(original)));
        } catch (URISyntaxException e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
    }
    File file = new File(original);
    if (file.isAbsolute()) {
        return FileUtils.normalize(file);
    }
    if (URI_SCHEME.matcher(original).matches()) {
        throw new InvalidUserDataException(String.format("Cannot convert URL '%s' to a file.", original));
    }
    file = new File(baseDir, original);
    return FileUtils.normalize(file);
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

Example 25 with InvalidUserDataException

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

the class ComponentModuleMetadataContainer method detectCycles.

private static void detectCycles(Map<ModuleIdentifier, Replacement> replacements, ModuleIdentifier source, ModuleIdentifier target) {
    if (source.equals(target)) {
        throw new InvalidUserDataException(String.format("Cannot declare module replacement that replaces self: %s->%s", source, target));
    }
    ModuleIdentifier m = unwrap(replacements.get(target));
    if (m == null) {
        // target does not exist in the map, there's no cycle for sure
        return;
    }
    Set<ModuleIdentifier> visited = new LinkedHashSet<>();
    visited.add(source);
    visited.add(target);
    while (m != null) {
        if (!visited.add(m)) {
            // module was already visited, there is a cycle
            throw new InvalidUserDataException(format("Cannot declare module replacement %s->%s because it introduces a cycle: %s", source, target, Joiner.on("->").join(visited) + "->" + source));
        }
        m = unwrap(replacements.get(m));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

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