Search in sources :

Example 1 with InvalidUserCodeException

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

the class DefaultComponentMetadataHandler method processRule.

private void processRule(SpecRuleAction<? super ComponentMetadataDetails> specRuleAction, ModuleComponentResolveMetadata metadata, final ComponentMetadataDetails details) {
    if (!specRuleAction.getSpec().isSatisfiedBy(details)) {
        return;
    }
    final List<Object> inputs = Lists.newArrayList();
    final RuleAction<? super ComponentMetadataDetails> action = specRuleAction.getAction();
    for (Class<?> inputType : action.getInputTypes()) {
        if (inputType == IvyModuleDescriptor.class) {
            // Ignore the rule if it expects Ivy metadata and this isn't an Ivy module
            if (!(metadata instanceof IvyModuleResolveMetadata)) {
                return;
            }
            IvyModuleResolveMetadata ivyMetadata = (IvyModuleResolveMetadata) metadata;
            inputs.add(new DefaultIvyModuleDescriptor(ivyMetadata.getExtraAttributes(), ivyMetadata.getBranch(), ivyMetadata.getStatus()));
            continue;
        }
        // We've already validated the inputs: should never get here.
        throw new IllegalStateException();
    }
    try {
        synchronized (this) {
            action.execute(details, inputs);
        }
    } catch (Exception e) {
        throw new InvalidUserCodeException(String.format("There was an error while evaluating a component metadata rule for %s.", details.getId()), e);
    }
}
Also used : DefaultIvyModuleDescriptor(org.gradle.api.internal.artifacts.ivyservice.DefaultIvyModuleDescriptor) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) IvyModuleResolveMetadata(org.gradle.internal.component.external.model.IvyModuleResolveMetadata) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException)

Example 2 with InvalidUserCodeException

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

the class PlayDistributionPlugin method createDistributionContentTasks.

@Mutate
void createDistributionContentTasks(ModelMap<Task> tasks, @Path("buildDir") final File buildDir, @Path("distributions") final PlayDistributionContainer distributions, final PlayPluginConfigurations configurations) {
    for (final PlayDistribution distribution : distributions.withType(PlayDistribution.class)) {
        final PlayApplicationBinarySpec binary = distribution.getBinary();
        if (binary == null) {
            throw new InvalidUserCodeException(String.format("Play Distribution '%s' does not have a configured Play binary.", distribution.getName()));
        }
        final File distJarDir = new File(buildDir, "distributionJars/" + distribution.getName());
        final String jarTaskName = "create" + StringUtils.capitalize(distribution.getName()) + "DistributionJar";
        tasks.create(jarTaskName, Jar.class, new Action<Jar>() {

            @Override
            public void execute(Jar jar) {
                jar.setDescription("Assembles an application jar suitable for deployment for the " + binary + ".");
                jar.dependsOn(binary.getTasks().withType(Jar.class));
                jar.from(jar.getProject().zipTree(binary.getJarFile()));
                jar.setDestinationDir(distJarDir);
                jar.setArchiveName(binary.getJarFile().getName());
                Map<String, Object> classpath = Maps.newHashMap();
                classpath.put("Class-Path", new PlayManifestClasspath(configurations.getPlayRun(), binary.getAssetsJarFile()));
                jar.getManifest().attributes(classpath);
            }
        });
        final Task distributionJar = tasks.get(jarTaskName);
        final File scriptsDir = new File(buildDir, "scripts/" + distribution.getName());
        String createStartScriptsTaskName = "create" + StringUtils.capitalize(distribution.getName() + "StartScripts");
        tasks.create(createStartScriptsTaskName, CreateStartScripts.class, new Action<CreateStartScripts>() {

            @Override
            public void execute(CreateStartScripts createStartScripts) {
                createStartScripts.setDescription("Creates OS specific scripts to run the " + binary + ".");
                createStartScripts.setClasspath(distributionJar.getOutputs().getFiles());
                createStartScripts.setMainClassName(getMainClass(distribution));
                createStartScripts.setApplicationName(distribution.getName());
                createStartScripts.setOutputDir(scriptsDir);
            }
        });
        Task createStartScripts = tasks.get(createStartScriptsTaskName);
        CopySpecInternal distSpec = (CopySpecInternal) distribution.getContents();
        CopySpec libSpec = distSpec.addChild().into("lib");
        libSpec.from(distributionJar);
        libSpec.from(binary.getAssetsJarFile());
        libSpec.from(configurations.getPlayRun().getAllArtifacts());
        libSpec.eachFile(new PrefixArtifactFileNames(configurations.getPlayRun()));
        CopySpec binSpec = distSpec.addChild().into("bin");
        binSpec.from(createStartScripts);
        binSpec.setFileMode(0755);
        CopySpec confSpec = distSpec.addChild().into("conf");
        confSpec.from("conf").exclude("routes");
        distSpec.from("README");
    }
}
Also used : CopySpec(org.gradle.api.file.CopySpec) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) Task(org.gradle.api.Task) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) PlayDistribution(org.gradle.play.distribution.PlayDistribution) DefaultPlayDistribution(org.gradle.play.internal.distribution.DefaultPlayDistribution) PlayApplicationBinarySpec(org.gradle.play.PlayApplicationBinarySpec) CreateStartScripts(org.gradle.api.tasks.application.CreateStartScripts) Jar(org.gradle.jvm.tasks.Jar) CopySpecInternal(org.gradle.api.internal.file.copy.CopySpecInternal) File(java.io.File) Map(java.util.Map) ModelMap(org.gradle.model.ModelMap) Mutate(org.gradle.model.Mutate)

Example 3 with InvalidUserCodeException

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

the class DefaultConfigurationPublications method capability.

@Override
public void capability(Object notation) {
    if (canCreate) {
        Capability descriptor = capabilityNotationParser.parseNotation(notation);
        if (capabilities == null) {
            // it's rare that a component would declare more than 1 capability
            capabilities = Lists.newArrayListWithExpectedSize(1);
        }
        capabilities.add(descriptor);
    } else {
        throw new InvalidUserCodeException("Cannot declare capability '" + notation + "' after dependency " + displayName + " has been resolved");
    }
}
Also used : Capability(org.gradle.api.capabilities.Capability) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException)

Example 4 with InvalidUserCodeException

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

the class DefaultComponentSelectionRules method createSpecRuleActionFromId.

private SpecRuleAction<? super ComponentSelection> createSpecRuleActionFromId(Object id, RuleAction<? super ComponentSelection> ruleAction) {
    final ModuleIdentifier moduleIdentifier;
    try {
        moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id);
    } catch (UnsupportedNotationException e) {
        throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e);
    }
    Spec<ComponentSelection> spec = new ComponentSelectionMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<>(ruleAction, spec);
}
Also used : InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection)

Example 5 with InvalidUserCodeException

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

the class DefaultDependencyResolutionManagement method repoMutationDisallowedOnProject.

private void repoMutationDisallowedOnProject(ArtifactRepository artifactRepository) {
    UserCodeApplicationContext.Application current = context.current();
    DisplayName displayName = current == null ? null : current.getDisplayName();
    if (displayName == null) {
        displayName = UNKNOWN_CODE;
    }
    String message = "Build was configured to prefer settings repositories over project repositories but repository '" + artifactRepository.getName() + "' was added by " + displayName;
    switch(getConfiguredRepositoriesMode()) {
        case FAIL_ON_PROJECT_REPOS:
            throw new InvalidUserCodeException(message);
        case PREFER_SETTINGS:
            LOGGER.warn(message);
            break;
    }
}
Also used : InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) UserCodeApplicationContext(org.gradle.configuration.internal.UserCodeApplicationContext) DisplayName(org.gradle.internal.DisplayName)

Aggregations

InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)12 UnsupportedNotationException (org.gradle.internal.typeconversion.UnsupportedNotationException)4 Action (org.gradle.api.Action)3 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)3 File (java.io.File)2 Task (org.gradle.api.Task)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 VariantVersionMappingStrategy (org.gradle.api.publish.VariantVersionMappingStrategy)2 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 BiFunction (java.util.function.BiFunction)1 Inject (javax.inject.Inject)1 InvokerHelper (org.codehaus.groovy.runtime.InvokerHelper)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Transformer (org.gradle.api.Transformer)1 ArtifactView (org.gradle.api.artifacts.ArtifactView)1