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