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());
}
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();
}
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);
}
}
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);
}
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));
}
}
Aggregations