@TaskAction public void publish() { final MavenPublicationInternal publication = getPublicationInternal(); if (publication == null) { throw new InvalidUserDataException("The 'publication' property is required"); } new PublishOperation(publication, "mavenLocal") { @Override protected void publish() throws Exception { MavenPublisher localPublisher = new MavenLocalPublisher(getLoggingManagerFactory(), getMavenRepositoryLocator()); MavenPublisher staticLockingPublisher = new StaticLockingMavenPublisher(localPublisher); MavenPublisher validatingPublisher = new ValidatingMavenPublisher(staticLockingPublisher); validatingPublisher.publish(publication.asNormalisedPublication(), null); } }.run(); }
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; for (Usage usage : this.component.getUsages()) { // TODO Need a smarter way to map usage to artifact classifier for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact); } // TODO Need a smarter way to map usage to scope for (ModuleDependency dependency : usage.getDependencies()) { if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency); } else { addModuleDependency(dependency); } } } }
private static void detectCycles(Map<ModuleIdentifier, ModuleIdentifier> 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 = 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<ModuleIdentifier>(); 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 = replacements.get(m); } }
public void convert(String notation, NotationConvertResult<? super ModuleVersionSelector> result) throws TypeConversionException { ParsedModuleStringNotation parsed; try { parsed = new ParsedModuleStringNotation(notation, null); } catch (IllegalDependencyNotation e) { throw new InvalidUserDataException( "Invalid format: '" + notation + "'. The correct notation is a 3-part group:name:version notation, " + "e.g: 'org.gradle:gradle-core:1.0'"); } if (parsed.getGroup() == null || parsed.getName() == null || parsed.getVersion() == null) { throw new InvalidUserDataException( "Invalid format: '" + notation + "'. Group, name and version cannot be empty. Correct example: " + "'org.gradle:gradle-core:1.0'"); } result.converted(newSelector(parsed.getGroup(), parsed.getName(), parsed.getVersion())); }
public void convert(String notation, NotationConvertResult<? super ComponentSelector> result) throws TypeConversionException { ParsedModuleStringNotation parsed; try { parsed = new ParsedModuleStringNotation(notation, null); } catch (IllegalDependencyNotation e) { throw new InvalidUserDataException( "Invalid format: '" + notation + "'. The correct notation is a 3-part group:name:version notation, " + "e.g: 'org.gradle:gradle-core:1.0'"); } if (parsed.getGroup() == null || parsed.getName() == null || parsed.getVersion() == null) { throw new InvalidUserDataException( "Invalid format: '" + notation + "'. Group, name and version cannot be empty. Correct example: " + "'org.gradle:gradle-core:1.0'"); } result.converted(newSelector(parsed.getGroup(), parsed.getName(), parsed.getVersion())); }
public void add(final Class<? extends FilterReader> filterType, final Map<String, ?> properties) { transformers.add(new Transformer<Reader, Reader>() { public Reader transform(Reader original) { try { Constructor<? extends FilterReader> constructor = filterType.getConstructor(Reader.class); FilterReader result = constructor.newInstance(original); if (properties != null) { ConfigureUtil.configureByMap(properties, result); } return result; } catch (Throwable th) { throw new InvalidUserDataException("Error - Invalid filter specification for " + filterType.getName(), th); } } }); }
private void validateParentMutation(MutationType type) { // Strategy changes in a parent configuration do not affect this configuration, or any of its children, in any way if (type == MutationType.STRATEGY) { return; } if (resolvedState == ARTIFACTS_RESOLVED) { throw new InvalidUserDataException(String.format("Cannot change %s of parent of %s after it has been resolved", type, getDisplayName())); } else if (resolvedState == GRAPH_RESOLVED) { if (type == MutationType.DEPENDENCIES) { throw new InvalidUserDataException(String.format("Cannot change %s of parent of %s after task dependencies have been resolved", type, getDisplayName())); } } markAsModifiedAndNotifyChildren(type); }
public void validateMutation(MutationType type) { if (resolvedState == ARTIFACTS_RESOLVED) { // The public result for the configuration has been calculated. // It is an error to change anything that would change the dependencies or artifacts throw new InvalidUserDataException(String.format("Cannot change %s of %s after it has been resolved.", type, getDisplayName())); } else if (resolvedState == GRAPH_RESOLVED) { // The task dependencies for the configuration have been calculated using Configuration.getBuildDependencies(). throw new InvalidUserDataException(String.format("Cannot change %s of %s after task dependencies have been resolved", type, getDisplayName())); } else if (observedState == GRAPH_RESOLVED || observedState == ARTIFACTS_RESOLVED) { // The configuration has been used in a resolution, and it is an error for build logic to change any dependencies, // exclude rules or parent configurations (values that will affect the resolved graph). if (type != MutationType.STRATEGY) { String extraMessage = insideBeforeResolve ? " Use 'defaultDependencies' instead of 'beforeResolve' to specify default dependencies for a configuration." : ""; throw new InvalidUserDataException(String.format("Cannot change %s of %s after it has been included in dependency resolution.%s", type, getDisplayName(), extraMessage)); } } markAsModifiedAndNotifyChildren(type); }
private Set<DirectoryTree> doGetSrcDirTrees() { Set<DirectoryTree> result = new LinkedHashSet<DirectoryTree>(); for (Object path : source) { if (path instanceof SourceDirectorySet) { SourceDirectorySet nested = (SourceDirectorySet) path; result.addAll(nested.getSrcDirTrees()); } else { for (File srcDir : fileResolver.resolveFiles(path)) { if (srcDir.exists() && !srcDir.isDirectory()) { throw new InvalidUserDataException(String.format("Source directory '%s' is not a directory.", srcDir)); } result.add(directoryFileTreeFactory.create(srcDir, patterns)); } } } return result; }
private int getHeapSizeMb(String heapSize) { if (heapSize == null) { return -1; // unspecified } String normalized = heapSize.trim().toLowerCase(); try { if (normalized.endsWith("m")) { return Integer.parseInt(normalized.substring(0, normalized.length() - 1)); } if (normalized.endsWith("g")) { return Integer.parseInt(normalized.substring(0, normalized.length() - 1)) * 1024; } } catch (NumberFormatException e) { throw new InvalidUserDataException("Cannot parse heap size: " + heapSize, e); } throw new InvalidUserDataException("Cannot parse heap size: " + heapSize); }
public NormalizedTimeUnit parseNotation(CharSequence notation, int value) { String candidate = notation.toString().toUpperCase(); //jdk5 does not have days, hours or minutes, normalizing to millis if (candidate.equals("DAYS")) { return millis(value * 24 * 60 * 60 * 1000); } else if (candidate.equals("HOURS")) { return millis(value * 60 * 60 * 1000); } else if (candidate.equals("MINUTES")) { return millis(value * 60 * 1000); } try { return new NormalizedTimeUnit(value, TimeUnit.valueOf(candidate)); } catch (Exception e) { throw new InvalidUserDataException("Unable to parse provided TimeUnit: " + notation, e); } }
public Set<Task> getTasksByName(final String name, boolean recursive) { if (!isTrue(name)) { throw new InvalidUserDataException("Name is not specified!"); } final Set<Task> foundTasks = new HashSet<Task>(); Action<Project> action = new Action<Project>() { public void execute(Project project) { // Don't force evaluation of rules here, let the task container do what it needs to ((ProjectInternal) project).evaluate(); Task task = project.getTasks().findByName(name); if (task != null) { foundTasks.add(task); } } }; if (recursive) { allprojects(action); } else { action.execute(this); } return foundTasks; }
@Override public <S extends TaskInternal> S create(String name, final Class<S> type) { if (!Task.class.isAssignableFrom(type)) { throw new InvalidUserDataException(String.format( "Cannot create task of type '%s' as it does not implement the Task interface.", type.getSimpleName())); } final Class<? extends Task> generatedType; if (type.isAssignableFrom(DefaultTask.class)) { generatedType = generator.generate(DefaultTask.class); } else { generatedType = generator.generate(type); } return type.cast(AbstractTask.injectIntoNewInstance(project, name, type, new Callable<Task>() { public Task call() throws Exception { try { return instantiator.newInstance(generatedType); } catch (ObjectInstantiationException e) { throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()), e.getCause()); } } })); }
public Task findByPath(String path) { if (!GUtil.isTrue(path)) { throw new InvalidUserDataException("A path must be specified!"); } if (!path.contains(Project.PATH_SEPARATOR)) { return findByName(path); } String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR); ProjectInternal project = this.project.findProject(!GUtil.isTrue(projectPath) ? Project.PATH_SEPARATOR : projectPath); if (project == null) { return null; } projectAccessListener.beforeRequestingTaskByPath(project); return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR)); }
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) { List<String> messages = new ArrayList<String>(); for (TaskValidator validator : task.getValidators()) { validator.validate(task, messages); } if (!messages.isEmpty()) { List<InvalidUserDataException> causes = new ArrayList<InvalidUserDataException>(); messages = messages.subList(0, Math.min(5, messages.size())); for (String message : messages) { causes.add(new InvalidUserDataException(message)); } String errorMessage; if (messages.size() == 1) { errorMessage = String.format("A problem was found with the configuration of %s.", task); } else { errorMessage = String.format("Some problems were found with the configuration of %s.", task); } state.setOutcome(new TaskValidationException(errorMessage, causes)); return; } executer.execute(task, state, context); }
protected PgpSignatory readProperties(Project project, String prefix, String name, boolean required) { ArrayList<Object> values = new ArrayList<Object>(); for (String property : PROPERTIES) { String qualifiedProperty = (String)getQualifiedPropertyName(prefix, property); if (project.hasProperty(qualifiedProperty)) { values.add( project.property(qualifiedProperty)); } else { if (required) { throw new InvalidUserDataException("property \'" + qualifiedProperty + "\' could not be found on project and is needed for signing"); } else { return null; } } } String keyId = values.get(0).toString(); File keyRing = project.file(values.get(1).toString()); String password = values.get(2).toString(); return createSignatory(name, keyId, keyRing, password); }
protected <N extends T> N add(Class<N> clazz, Object... constructionArgs) { N report = getInstantiator().newInstance(clazz, constructionArgs); if (report.getName().equals("enabled")) { throw new InvalidUserDataException("Reports that are part of a ReportContainer cannot be named 'enabled'"); } getStore().add(report); index(); return report; }
public AbstractExternalModuleDependency(String group, String name, String version, String configuration) { super(configuration); if (name == null) { throw new InvalidUserDataException("Name must not be null!"); } this.group = group; this.name = name; this.version = version; }
@Override public void exports(String value) { validatePackageName(value); if (!exports.add(value)) { throw new InvalidUserDataException( format("Invalid public API specification: package '%s' has already been exported", value)); } }
private void validatePackageName(String value) { try { JvmPackageName.of(value); } catch (IllegalArgumentException cause) { throw new InvalidUserDataException( format("Invalid public API specification: %s", cause.getMessage()), cause); } }
@Override public void setContentCharset(String contentCharset) { if (contentCharset == null) { throw new InvalidUserDataException("contentCharset must not be null"); } if (!Charset.isSupported(contentCharset)) { throw new InvalidUserDataException(String.format("Charset for contentCharset '%s' is not supported by your JVM", contentCharset)); } this.contentCharset = contentCharset; }
public <S extends T> S create(String name, Class<S> type) { @SuppressWarnings("unchecked") NamedDomainObjectFactory<S> factory = (NamedDomainObjectFactory<S>) factories.get(type); if (factory == null) { throw new InvalidUserDataException( String.format("Cannot create a %s because this type is not known to %s. Known types are: %s", type.getSimpleName(), displayName, getSupportedTypeNames()), new NoFactoryRegisteredForTypeException()); } return factory.create(name); }
private <T extends Platform> T resolveFromContainer(Class<T> type, PlatformRequirement platformRequirement) { final String target = platformRequirement.getPlatformName(); NamedDomainObjectSet<T> allWithType = platforms.withType(type); T matching = CollectionUtils.findFirst(allWithType, new Spec<T>() { public boolean isSatisfiedBy(T element) { return element.getName().equals(target); } }); if (matching == null) { throw new InvalidUserDataException(String.format("Invalid %s: %s", type.getSimpleName(), target)); } return matching; }
public void setReportFormat(String reportFormat) { if (REPORT_FORMATS.contains(reportFormat)) { this.reportFormat = reportFormat; } else { throw new InvalidUserDataException("'" + reportFormat + "' is not a valid codenarc report format"); } }
public <T extends ProjectIdentifier> T selectProject(ProjectRegistry<? extends T> registry) { checkPreconditions(registry); List<T> matches = new ArrayList<T>(); select(registry, matches); if (matches.isEmpty()) { throw new InvalidUserDataException(formatNoMatchesMessage()); } if (matches.size() != 1) { throw new InvalidUserDataException(formatMultipleMatchesMessage(matches)); } return matches.get(0); }
public T create(String name, Action<? super T> configureAction) throws InvalidUserDataException { assertCanAdd(name); T object = doCreate(name); add(object); configureAction.execute(object); return object; }
public FindBugsSpecBuilder withEffort(String effort) { if (effort != null && !VALID_EFFORTS.contains(effort)) { throw new InvalidUserDataException("Invalid value for FindBugs 'effort' property: " + effort); } this.effort = effort; return this; }
public FindBugsSpecBuilder withReportLevel(String reportLevel) { if (reportLevel != null && !VALID_REPORT_LEVELS.contains(reportLevel)) { throw new InvalidUserDataException("Invalid value for FindBugs 'reportLevel' property: " + reportLevel); } this.reportLevel = reportLevel; return this; }
public FindBugsSpecBuilder withExcludeFilter(File excludeFilter) { if (excludeFilter != null && !excludeFilter.canRead()) { String errorStr = String.format("Cannot read file specified for FindBugs 'excludeFilter' property: %s", excludeFilter); throw new InvalidUserDataException(errorStr); } this.excludeFilter = excludeFilter; return this; }
public FindBugsSpecBuilder withIncludeFilter(File includeFilter) { if (includeFilter != null && !includeFilter.canRead()) { String errorStr = String.format("Cannot read file specified for FindBugs 'includeFilter' property: %s", includeFilter); throw new InvalidUserDataException(errorStr); } this.includeFilter = includeFilter; return this; }
public Conf2ScopeMapping getMapping(Collection<Configuration> configurations) { Set<Conf2ScopeMapping> result = getMappingsWithHighestPriority(configurations); if (result.size() > 1) { throw new InvalidUserDataException( "The configuration to scope mapping is not unique. The following configurations " + "have the same priority: " + result); } return result.size() == 0 ? null : result.iterator().next(); }
public void addArtifact(Artifact artifact, File src) { throwExceptionIfArtifactOrSrcIsNull(artifact, src); PublishArtifact publishArtifact = new MavenArtifact(artifact, src); ArtifactKey artifactKey = new ArtifactKey(publishArtifact); if (this.artifacts.containsKey(artifactKey)) { throw new InvalidUserDataException(String.format("A POM cannot have multiple artifacts with the same type and classifier. Already have %s, trying to add %s.", this.artifacts.get( artifactKey), publishArtifact)); } if (publishArtifact.getClassifier() != null) { addArtifact(publishArtifact); assignArtifactValuesToPom(artifact, pom, false); return; } if (this.artifact != null) { // Choose the 'main' artifact based on its type. if (!PACKAGING_TYPES.contains(artifact.getType())) { addArtifact(publishArtifact); return; } if (PACKAGING_TYPES.contains(this.artifact.getType())) { throw new InvalidUserDataException("A POM can not have multiple main artifacts. " + "Already have " + this.artifact + ", trying to add " + publishArtifact); } addArtifact(this.artifact); } this.artifact = publishArtifact; this.artifacts.put(artifactKey, publishArtifact); assignArtifactValuesToPom(artifact, pom, true); }
private void throwExceptionIfArtifactOrSrcIsNull(Artifact artifact, File src) { if (artifact == null) { throw new InvalidUserDataException("Artifact must not be null."); } if (src == null) { throw new InvalidUserDataException("Src file must not be null."); } }
public void addArtifact(Artifact artifact, File src) { if (artifact == null || src == null) { throw new InvalidUserDataException("Artifact or source file must not be null!"); } for (PomFilter activePomFilter : pomFilterContainer.getActivePomFilters()) { if (activePomFilter.getFilter().accept(artifact, src)) { if (artifactPoms.get(activePomFilter.getName()) == null) { artifactPoms.put(activePomFilter.getName(), artifactPomFactory.createArtifactPom(activePomFilter.getPomTemplate())); } artifactPoms.get(activePomFilter.getName()).addArtifact(artifact, src); } } }
public MavenPom addFilter(String name, PublishFilter publishFilter) { if (name == null || publishFilter == null) { throw new InvalidUserDataException("Name and Filter must not be null."); } MavenPom pom = mavenPomFactory.create(); pomFilters.put(name, new DefaultPomFilter(name, pom, publishFilter)); return pom; }
@TaskAction public void publish() { MavenPublicationInternal publicationInternal = getPublicationInternal(); if (publicationInternal == null) { throw new InvalidUserDataException("The 'publication' property is required"); } MavenArtifactRepository repository = getRepository(); if (repository == null) { throw new InvalidUserDataException("The 'repository' property is required"); } doPublish(publicationInternal, repository); }
private static MavenPublicationInternal toPublicationInternal(MavenPublication publication) { if (publication == null) { return null; } else if (publication instanceof MavenPublicationInternal) { return (MavenPublicationInternal) publication; } else { throw new InvalidUserDataException( String.format( "publication objects must implement the '%s' interface, implementation '%s' does not", MavenPublicationInternal.class.getName(), publication.getClass().getName() ) ); } }
@Override protected void checkPreconditions(ProjectRegistry<?> registry) { if (!dir.exists()) { throw new InvalidUserDataException(String.format("Project directory '%s' does not exist.", dir)); } if (!dir.isDirectory()) { throw new InvalidUserDataException(String.format("Project directory '%s' is not a directory.", dir)); } }
/** * Constructs a {@code Link}. * * @param url Base URL of external site * @param packages list of package prefixes */ public Link(String url, String... packages) { throwExceptionIfNull(url, "Url must not be null"); if (packages.length == 0) { throw new InvalidUserDataException("You must specify at least one package!"); } for (String aPackage : packages) { throwExceptionIfNull(aPackage, "A package must not be null"); } this.packages = Arrays.asList(packages); this.url = url; }
/** * Generates the signature files. */ @TaskAction public void generate() { if (getSignatory() == null) { throw new InvalidUserDataException("Cannot perform signing task \'" + getPath() + "\' because it has no configured signatory"); } for (Signature signature : signatures) { signature.generate(); } }