org.gradle.api.InvalidUserDataException Java Examples

The following examples show how to use org.gradle.api.InvalidUserDataException. 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 File: DaemonForkOptions.java    From pushfish-android with 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 #2
Source File: AbstractProjectSpec.java    From pushfish-android with 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 File: DefaultMavenPublication.java    From pushfish-android with 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 #4
Source File: TimeUnitsParser.java    From pushfish-android with 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 #5
Source File: ValidatingTaskExecuter.java    From pushfish-android with 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 #6
Source File: AbstractTargetedProjectNativeComponent.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #7
Source File: FilterChain.java    From pushfish-android with 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 #8
Source File: DaemonForkOptions.java    From pushfish-android with 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 File: AbstractTargetedNativeComponentSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #10
Source File: TaskFactory.java    From pushfish-android with 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 #11
Source File: TimeUnitsParser.java    From pushfish-android with 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 #12
Source File: ModuleVersionSelectorParsers.java    From pushfish-android with 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 #13
Source File: DefaultPluginRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin<?>> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example #14
Source File: DefaultClientModule.java    From pushfish-android with 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 File: AbstractProjectSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #16
Source File: DefaultFileOperations.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public File mkdir(Object path) {
    File dir = fileResolver.resolve(path);
    if (dir.isFile()) {
        throw new InvalidUserDataException(String.format("Can't create directory. The path=%s points to an existing file.", path));
    }
    GFileUtils.mkdirs(dir);
    return dir;
}
 
Example #17
Source File: DefaultConf2ScopeMappingContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #18
Source File: Copy.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CopyAction createCopyAction() {
    File destinationDir = getDestinationDir();
    if (destinationDir == null) {
        throw new InvalidUserDataException("No copy destination directory has been specified, use 'into' to specify a target directory.");
    }
    return new FileCopyAction(getServices().get(FileLookup.class).getFileResolver(destinationDir));
}
 
Example #19
Source File: DefaultMavenArtifactRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected MavenResolver createRealResolver() {
    URI rootUri = getUrl();
    if (rootUri == null) {
        throw new InvalidUserDataException("You must specify a URL for a Maven repository.");
    }

    MavenResolver resolver = new MavenResolver(getName(), rootUri, getTransport(rootUri.getScheme()),
            locallyAvailableResourceFinder, resolverStrategy);
    for (URI repoUrl : getArtifactUrls()) {
        resolver.addArtifactLocation(repoUrl, null);
    }
    return resolver;
}
 
Example #20
Source File: DefaultReportContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
    return report;
}
 
Example #21
Source File: JUnitTestClassExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, true, applicationClassLoader);
    Request request = Request.aClass(testClass);
    if (options.hasCategoryConfiguration()) {
        Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
            public Class<?> transform(final String original) {
                try {
                    return applicationClassLoader.loadClass(original);
                } catch (ClassNotFoundException e) {
                    throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
                }
            }
        };
        request = request.filterWith(new CategoryFilter(
                CollectionUtils.collect(options.getIncludeCategories(), transformer),
                CollectionUtils.collect(options.getExcludeCategories(), transformer)
        ));
    }

    if (!options.getIncludedTests().isEmpty()) {
        request = request.filterWith(new MethodNameFilter(options.getIncludedTests()));
    }

    Runner runner = request.getRunner();
    //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class.
    //Will be fixed with adding class filters
    if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) {
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
}
 
Example #22
Source File: AbstractFileResolver.java    From pushfish-android with 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 #23
Source File: Sync.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CopyAction createCopyAction() {
    File destinationDir = getDestinationDir();
    if (destinationDir == null) {
        throw new InvalidUserDataException("No copy destination directory has been specified, use 'into' to specify a target directory.");
    }
    return new SyncCopyActionDecorator(destinationDir, new FileCopyAction(getFileLookup().getFileResolver(destinationDir)));
}
 
Example #24
Source File: DependencyStringNotationParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ParsedModuleStringNotation splitModuleFromExtension(String notation) {
    Matcher matcher = EXTENSION_SPLITTER.matcher(notation);
    boolean hasArtifactType = matcher.matches();
    if (hasArtifactType && !ClientModule.class.isAssignableFrom(wantedType)) {
        if (matcher.groupCount() != 2) {
            throw new InvalidUserDataException("The dependency notation " + notation + " is invalid");
        }
        return new ParsedModuleStringNotation(matcher.group(1), matcher.group(2));
    }
    return new ParsedModuleStringNotation(notation, null);
}
 
Example #25
Source File: Copy.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CopyAction createCopyAction() {
    File destinationDir = getDestinationDir();
    if (destinationDir == null) {
        throw new InvalidUserDataException("No copy destination directory has been specified, use 'into' to specify a target directory.");
    }
    return new FileCopyAction(getFileLookup().getFileResolver(destinationDir));
}
 
Example #26
Source File: DefaultIvyModuleDescriptorSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void extraInfo(String namespace, String elementName, String value) {
    if (elementName == null) {
        throw new InvalidUserDataException("Cannot add an extra info element with null element name");
    }
    if (namespace == null) {
        throw new InvalidUserDataException("Cannot add an extra info element with null namespace");
    }
    extraInfo.add(namespace, elementName, value);
}
 
Example #27
Source File: GenerateIvyDescriptor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static IvyModuleDescriptorSpecInternal toIvyModuleDescriptorInternal(IvyModuleDescriptorSpec ivyModuleDescriptorSpec) {
    if (ivyModuleDescriptorSpec == null) {
        return null;
    } else if (ivyModuleDescriptorSpec instanceof IvyModuleDescriptorSpecInternal) {
        return (IvyModuleDescriptorSpecInternal) ivyModuleDescriptorSpec;
    } else {
        throw new InvalidUserDataException(
                String.format(
                        "ivyModuleDescriptor implementations must implement the '%s' interface, implementation '%s' does not",
                        IvyModuleDescriptorSpecInternal.class.getName(),
                        ivyModuleDescriptorSpec.getClass().getName()
                )
        );
    }
}
 
Example #28
Source File: PublishToIvyRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
public void publish() {
    IvyPublicationInternal publicationInternal = getPublicationInternal();
    if (publicationInternal == null) {
        throw new InvalidUserDataException("The 'publication' property is required");
    }

    IvyArtifactRepository repository = getRepository();
    if (repository == null) {
        throw new InvalidUserDataException("The 'repository' property is required");
    }

    doPublish(publicationInternal, repository);
}
 
Example #29
Source File: DefaultLibraryResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Class<? extends NativeLibraryBinary> getTypeForLinkage(String linkage) {
    if ("static".equals(linkage)) {
        return StaticLibraryBinary.class;
    }
    if ("shared".equals(linkage) || linkage == null) {
        return SharedLibraryBinary.class;
    }
    throw new InvalidUserDataException("Not a valid linkage: " + linkage);
}
 
Example #30
Source File: Sync.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CopyAction createCopyAction() {
    File destinationDir = getDestinationDir();
    if (destinationDir == null) {
        throw new InvalidUserDataException("No copy destination directory has been specified, use 'into' to specify a target directory.");
    }
    return new SyncCopyActionDecorator(destinationDir, new FileCopyAction(getServices().get(FileLookup.class).getFileResolver(destinationDir)));
}