Search in sources :

Example 1 with NameMatcher

use of org.gradle.util.internal.NameMatcher in project gradle by gradle.

the class ProjectFinderByTaskPath method findProject.

public ProjectInternal findProject(String projectPath, ProjectInternal startFrom) {
    if (projectPath.equals(Project.PATH_SEPARATOR)) {
        return startFrom.getRootProject();
    }
    Project current = startFrom;
    if (projectPath.startsWith(Project.PATH_SEPARATOR)) {
        current = current.getRootProject();
        projectPath = projectPath.substring(1);
    }
    for (String pattern : projectPath.split(Project.PATH_SEPARATOR)) {
        Map<String, Project> children = current.getChildProjects();
        NameMatcher matcher = new NameMatcher();
        Project child = matcher.find(pattern, children);
        if (child != null) {
            current = child;
            continue;
        }
        throw new ProjectLookupException(matcher.formatErrorMessage("project", current));
    }
    return (ProjectInternal) current;
}
Also used : Project(org.gradle.api.Project) NameMatcher(org.gradle.util.internal.NameMatcher) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 2 with NameMatcher

use of org.gradle.util.internal.NameMatcher in project gradle by gradle.

the class DefaultTaskSelector method getSelection.

private TaskSelection getSelection(String path, ProjectInternal project) {
    ResolvedTaskPath taskPath = taskPathResolver.resolvePath(path, project);
    ProjectInternal targetProject = taskPath.getProject();
    if (taskPath.isQualified()) {
        configurer.configure(targetProject);
    } else {
        configurer.configureHierarchy(targetProject);
    }
    TaskSelectionResult tasks = taskNameResolver.selectWithName(taskPath.getTaskName(), taskPath.getProject(), !taskPath.isQualified());
    if (tasks != null) {
        // An exact match
        return new TaskSelection(taskPath.getProject().getPath(), path, tasks);
    }
    Map<String, TaskSelectionResult> tasksByName = taskNameResolver.selectAll(taskPath.getProject(), !taskPath.isQualified());
    NameMatcher matcher = new NameMatcher();
    String actualName = matcher.find(taskPath.getTaskName(), tasksByName.keySet());
    if (actualName != null) {
        return new TaskSelection(taskPath.getProject().getPath(), taskPath.getPrefix() + actualName, tasksByName.get(actualName));
    }
    throw new TaskSelectionException(matcher.formatErrorMessage("task", taskPath.getProject()));
}
Also used : ResolvedTaskPath(org.gradle.execution.taskpath.ResolvedTaskPath) NameMatcher(org.gradle.util.internal.NameMatcher) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 3 with NameMatcher

use of org.gradle.util.internal.NameMatcher in project gradle by gradle.

the class ConfigurationFinder method find.

public static Configuration find(ConfigurationContainer configurations, String configurationName) {
    NameMatcher matcher = new NameMatcher();
    Configuration configuration = matcher.find(configurationName, configurations.getAsMap());
    if (configuration != null) {
        return configuration;
    }
    // if configuration with exact name is present return it
    configuration = configurations.findByName(configurationName);
    if (configuration != null) {
        return configuration;
    }
    throw new InvalidUserDataException(matcher.formatErrorMessage("configuration", configurations));
}
Also used : NameMatcher(org.gradle.util.internal.NameMatcher) Configuration(org.gradle.api.artifacts.Configuration) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Aggregations

NameMatcher (org.gradle.util.internal.NameMatcher)3 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Project (org.gradle.api.Project)1 Configuration (org.gradle.api.artifacts.Configuration)1 ResolvedTaskPath (org.gradle.execution.taskpath.ResolvedTaskPath)1