Java Code Examples for org.gradle.api.InvalidUserDataException

The following examples show how to use org.gradle.api.InvalidUserDataException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: pushfish-android   Author: PushFish   File: DefaultMavenPublication.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #2
Source Project: pushfish-android   Author: PushFish   File: AbstractProjectSpec.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T extends ProjectIdentifier> T selectProject(ProjectRegistry<? extends T> registry) {
    checkPreconditions(registry);
    List<T> matches = new ArrayList<T>();
    for (T project : registry.getAllProjects()) {
        if (select(project)) {
            matches.add(project);
        }
    }
    if (matches.isEmpty()) {
        throw new InvalidUserDataException(formatNoMatchesMessage());
    }
    if (matches.size() != 1) {
        throw new InvalidUserDataException(formatMultipleMatchesMessage(matches));
    }
    return matches.get(0);
}
 
Example #3
Source Project: pushfish-android   Author: PushFish   File: ValidatingTaskExecuter.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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.executed(new TaskValidationException(errorMessage, causes));
        return;
    }
    executer.execute(task, state, context);
}
 
Example #4
private <T extends Named> Set<T> chooseElements(Class<T> type, Set<? extends T> candidates, final Set<String> names) {
    if (names.isEmpty()) {
        return new LinkedHashSet<T>(candidates);
    }

    Set<String> unusedNames = new HashSet<String>(names);
    Set<T> chosen = new LinkedHashSet<T>();
    for (T candidate : candidates) {
        if (unusedNames.remove(candidate.getName())) {
            chosen.add(candidate);
        }
    }

    if (!unusedNames.isEmpty()) {
        throw new InvalidUserDataException(String.format("Invalid %s: '%s'", type.getSimpleName(), unusedNames.iterator().next()));
    }

    return chosen;
}
 
Example #5
Source Project: pushfish-android   Author: PushFish   File: TaskFactory.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private TaskInternal createTaskObject(ProjectInternal project, final Class<? extends TaskInternal> type, String name, boolean generateGetters) {
    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 TaskInternal> generatedType;
    if (generateGetters) {
        generatedType = generator.generate(type);
    } else {
        generatedType = type;
    }

    return AbstractTask.injectIntoNewInstance(project, name, new Callable<TaskInternal>() {
        public TaskInternal 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());
            }
        }
    });
}
 
Example #6
Source Project: pushfish-android   Author: PushFish   File: ModuleVersionSelectorParsers.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ModuleVersionSelector parseType(CharSequence notation) {
    ParsedModuleStringNotation parsed;
    try {
        parsed = new ParsedModuleStringNotation(notation.toString(), 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'");
    }
    return newSelector(parsed.getGroup(), parsed.getName(), parsed.getVersion());
}
 
Example #7
protected <T extends Named> Set<T> chooseElements(Class<T> type, Set<? extends T> candidates, Set<String> names) {
    if (names.isEmpty()) {
        return new LinkedHashSet<T>(candidates);
    }

    Set<String> unusedNames = new HashSet<String>(names);
    Set<T> chosen = new LinkedHashSet<T>();
    for (T candidate : candidates) {
        if (unusedNames.remove(candidate.getName())) {
            chosen.add(candidate);
        }
    }

    if (!unusedNames.isEmpty()) {
        throw new InvalidUserDataException(String.format("Invalid %s: '%s'", type.getSimpleName(), unusedNames.iterator().next()));
    }

    return chosen;
}
 
Example #8
Source Project: pushfish-android   Author: PushFish   File: DaemonForkOptions.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #9
Source Project: pushfish-android   Author: PushFish   File: TimeUnitsParser.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example #10
Source Project: pushfish-android   Author: PushFish   File: DaemonForkOptions.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #11
Source Project: pushfish-android   Author: PushFish   File: FilterChain.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example #12
Source Project: pushfish-android   Author: PushFish   File: TimeUnitsParser.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example #13
Source Project: web3j-gradle-plugin   Author: web3j   File: Web3jPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private File buildSourceDir(final Web3jExtension extension, final SourceSet sourceSet) {

        if (extension.getGeneratedFilesBaseDir().isEmpty()) {
            throw new InvalidUserDataException("Generated web3j package cannot be empty");
        }

        return new File(extension.getGeneratedFilesBaseDir() + "/" + sourceSet.getName() + "/java");
    }
 
Example #14
Source Project: pushfish-android   Author: PushFish   File: DefaultClientModule.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultClientModule(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;
}
 
Example #15
Source Project: pushfish-android   Author: PushFish   File: TaskFactory.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public TaskInternal createTask(Map<String, ?> args) {
    Map<String, Object> actualArgs = new HashMap<String, Object>(args);
    checkTaskArgsAndCreateDefaultValues(actualArgs);

    String name = actualArgs.get(Task.TASK_NAME).toString();
    if (!GUtil.isTrue(name)) {
        throw new InvalidUserDataException("The task name must be provided.");
    }

    Class<? extends TaskInternal> type = (Class) actualArgs.get(Task.TASK_TYPE);
    Boolean generateSubclass = Boolean.valueOf(actualArgs.get(GENERATE_SUBCLASS).toString());
    TaskInternal task = createTaskObject(project, type, name, generateSubclass);

    Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
    if (dependsOnTasks != null) {
        task.dependsOn(dependsOnTasks);
    }
    Object description = actualArgs.get(Task.TASK_DESCRIPTION);
    if (description != null) {
        task.setDescription(description.toString());
    }
    Object group = actualArgs.get(Task.TASK_GROUP);
    if (group != null) {
        task.setGroup(group.toString());
    }
    Object action = actualArgs.get(Task.TASK_ACTION);
    if (action instanceof Action) {
        Action<? super Task> taskAction = (Action<? super Task>) action;
        task.doFirst(taskAction);
    } else if (action != null) {
        Closure closure = (Closure) action;
        task.doFirst(closure);
    }

    return task;
}
 
Example #16
Source Project: pushfish-android   Author: PushFish   File: FindBugsSpecBuilder.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #17
Source Project: pushfish-android   Author: PushFish   File: FindBugsSpecBuilder.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #18
Source Project: pushfish-android   Author: PushFish   File: AbstractFileResolver.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void validate(File file, PathValidation validation) {
    switch (validation) {
        case NONE:
            break;
        case EXISTS:
            if (!file.exists()) {
                throw new InvalidUserDataException(String.format("File '%s' does not exist.", file));
            }
            break;
        case FILE:
            if (!file.exists()) {
                throw new InvalidUserDataException(String.format("File '%s' does not exist.", file));
            }
            if (!file.isFile()) {
                throw new InvalidUserDataException(String.format("File '%s' is not a file.", file));
            }
            break;
        case DIRECTORY:
            if (!file.exists()) {
                throw new InvalidUserDataException(String.format("Directory '%s' does not exist.", file));
            }
            if (!file.isDirectory()) {
                throw new InvalidUserDataException(String.format("Directory '%s' is not a directory.", file));
            }
            break;
    }
}
 
Example #19
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();
}
 
Example #20
Source Project: pushfish-android   Author: PushFish   File: DefaultArtifactPom.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #21
Source Project: pushfish-android   Author: PushFish   File: DefaultArtifactPom.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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.");
    }
}
 
Example #22
Source Project: pushfish-android   Author: PushFish   File: DefaultArtifactPomContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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); 
        }
    }
}
 
Example #23
Source Project: pushfish-android   Author: PushFish   File: ProjectPathProjectSpec.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void checkPreconditions(ProjectRegistry<?> registry) {
    // TODO(radimk): pattern for path?
    if (Strings.isNullOrEmpty(projectPath)) {
        throw new InvalidUserDataException("Project path must not be empty.");
    }
}
 
Example #24
Source Project: pushfish-android   Author: PushFish   File: PublishToMavenRepository.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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()
                )
        );
    }
}
 
Example #25
Source Project: pushfish-android   Author: PushFish   File: DefaultIvyPublication.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;

    configurations.maybeCreate("default");

    for (Usage usage : this.component.getUsages()) {
        String conf = usage.getName();
        configurations.maybeCreate(conf);
        configurations.getByName("default").extend(conf);

        for (PublishArtifact publishArtifact : usage.getArtifacts()) {
            artifact(publishArtifact).setConf(conf);
        }

        for (ModuleDependency dependency : usage.getDependencies()) {
            // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id.
            String confMapping = String.format("%s->%s", conf, dependency.getConfiguration());
            if (dependency instanceof ProjectDependency) {
                addProjectDependency((ProjectDependency) dependency, confMapping);
            } else {
                addModuleDependency(dependency, confMapping);
            }
        }
    }
}
 
Example #26
Source Project: pushfish-android   Author: PushFish   File: Groovydoc.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #27
Source Project: pushfish-android   Author: PushFish   File: DefaultIvyArtifactRepository.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private IvyResolver createResolver(Set<String> schemes) {
    if (schemes.isEmpty()) {
        throw new InvalidUserDataException("You must specify a base url or at least one artifact pattern for an Ivy repository.");
    }
    if (!WrapUtil.toSet("http", "https", "file").containsAll(schemes)) {
        throw new InvalidUserDataException("You may only specify 'file', 'http' and 'https' urls for an Ivy repository.");
    }
    if (WrapUtil.toSet("http", "https").containsAll(schemes)) {
        return createResolver(transportFactory.createHttpTransport(getName(), getCredentials()));
    }
    if (WrapUtil.toSet("file").containsAll(schemes)) {
        return createResolver(transportFactory.createFileTransport(getName()));
    }
    throw new InvalidUserDataException("You cannot mix file and http(s) urls for a single Ivy repository. Please declare 2 separate repositories.");
}
 
Example #28
Source Project: pushfish-android   Author: PushFish   File: DefaultArtifactPom.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #29
Source Project: pushfish-android   Author: PushFish   File: DefaultResolvedDependency.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<ResolvedArtifact> getParentArtifacts(ResolvedDependency parent) {
    if (!parents.contains(parent)) {
        throw new InvalidUserDataException("Provided dependency (" + parent + ") must be a parent of: " + this);
    }
    Set<ResolvedArtifact> artifacts = parentArtifacts.get(parent);
    return artifacts == null ? Collections.<ResolvedArtifact>emptySet() : artifacts;
}
 
Example #30
Source Project: pushfish-android   Author: PushFish   File: DefaultResolvedDependency.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<ResolvedArtifact> getParentArtifacts(ResolvedDependency parent) {
    if (!parents.contains(parent)) {
        throw new InvalidUserDataException("Provided dependency (" + parent + ") must be a parent of: " + this);
    }
    Set<ResolvedArtifact> artifacts = parentArtifacts.get(parent);
    return artifacts == null ? Collections.<ResolvedArtifact>emptySet() : artifacts;
}