Search in sources :

Example 1 with Path

use of org.gradle.util.Path in project gradle by gradle.

the class DefaultConfiguration method createCopy.

private DefaultConfiguration createCopy(Set<Dependency> dependencies, boolean recursive) {
    DetachedConfigurationsProvider configurationsProvider = new DetachedConfigurationsProvider();
    String newName = name + "Copy";
    Path newIdentityPath = identityPath.getParent().child(newName);
    Path newPath = path.getParent().child(newName);
    Factory<ResolutionStrategyInternal> childResolutionStrategy = resolutionStrategy != null ? Factories.constant(resolutionStrategy.copy()) : resolutionStrategyFactory;
    DefaultConfiguration copiedConfiguration = instantiator.newInstance(DefaultConfiguration.class, newIdentityPath, newPath, newName, configurationsProvider, resolver, listenerManager, metaDataProvider, childResolutionStrategy, projectAccessListener, projectFinder, configurationComponentMetaDataBuilder, fileCollectionFactory, componentIdentifierFactory, buildOperationExecutor, instantiator, artifactNotationParser, attributesFactory, moduleIdentifierFactory);
    configurationsProvider.setTheOnlyConfiguration(copiedConfiguration);
    // state, cachedResolvedConfiguration, and extendsFrom intentionally not copied - must re-resolve copy
    // copying extendsFrom could mess up dependencies when copy was re-resolved
    copiedConfiguration.visible = visible;
    copiedConfiguration.transitive = transitive;
    copiedConfiguration.description = description;
    copiedConfiguration.defaultDependencyActions = defaultDependencyActions;
    copiedConfiguration.canBeConsumed = canBeConsumed;
    copiedConfiguration.canBeResolved = canBeResolved;
    copiedConfiguration.getArtifacts().addAll(getAllArtifacts());
    if (!configurationAttributes.isEmpty()) {
        for (Attribute<?> attribute : configurationAttributes.keySet()) {
            Object value = configurationAttributes.getAttribute(attribute);
            copiedConfiguration.getAttributes().attribute(Cast.<Attribute<Object>>uncheckedCast(attribute), value);
        }
    }
    // todo An ExcludeRule is a value object but we don't enforce immutability for DefaultExcludeRule as strong as we
    // should (we expose the Map). We should provide a better API for ExcludeRule (I don't want to use unmodifiable Map).
    // As soon as DefaultExcludeRule is truly immutable, we don't need to create a new instance of DefaultExcludeRule.
    Set<Configuration> excludeRuleSources = new LinkedHashSet<Configuration>();
    excludeRuleSources.add(this);
    if (recursive) {
        excludeRuleSources.addAll(getHierarchy());
    }
    for (Configuration excludeRuleSource : excludeRuleSources) {
        for (ExcludeRule excludeRule : excludeRuleSource.getExcludeRules()) {
            copiedConfiguration.excludeRules.add(new DefaultExcludeRule(excludeRule.getGroup(), excludeRule.getModule()));
        }
    }
    DomainObjectSet<Dependency> copiedDependencies = copiedConfiguration.getDependencies();
    for (Dependency dependency : dependencies) {
        copiedDependencies.add(dependency.copy());
    }
    return copiedConfiguration;
}
Also used : Path(org.gradle.util.Path) LinkedHashSet(java.util.LinkedHashSet) ResolvedProjectConfiguration(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) TaskDependency(org.gradle.api.tasks.TaskDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AbstractTaskDependency(org.gradle.api.internal.tasks.AbstractTaskDependency) Dependency(org.gradle.api.artifacts.Dependency) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) ExcludeRule(org.gradle.api.artifacts.ExcludeRule) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule)

Example 2 with Path

use of org.gradle.util.Path in project gradle by gradle.

the class BuildSourceBuilder method buildGradleLauncher.

private GradleLauncher buildGradleLauncher(StartParameter startParameter) {
    StartParameter startParameterArg = startParameter.newInstance();
    startParameterArg.setProjectProperties(startParameter.getProjectProperties());
    startParameterArg.setSearchUpwards(false);
    startParameterArg.setProfile(startParameter.isProfile());
    GradleLauncher gradleLauncher = nestedBuildFactory.nestedInstance(startParameterArg);
    GradleInternal build = gradleLauncher.getGradle();
    if (build.getParent().findIdentityPath() == null) {
        // When nested inside a nested build, we need to synthesize a path for this build, as the root project is not yet known for the parent build
        // Use the directory structure to do this. This means that the buildSrc build and its containing build may end up with different paths
        Path path = build.getParent().getParent().getIdentityPath().child(startParameter.getCurrentDir().getParentFile().getName()).child(startParameter.getCurrentDir().getName());
        build.setIdentityPath(path);
    }
    return gradleLauncher;
}
Also used : Path(org.gradle.util.Path) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) StartParameter(org.gradle.StartParameter) GradleLauncher(org.gradle.initialization.GradleLauncher) GradleInternal(org.gradle.api.internal.GradleInternal)

Example 3 with Path

use of org.gradle.util.Path in project gradle by gradle.

the class DefaultGroupTaskReportModel method build.

public void build(TaskReportModel model) {
    Comparator<String> keyComparator = GUtil.last(GUtil.last(STRING_COMPARATOR, OTHER_GROUP), DEFAULT_GROUP);
    Comparator<TaskDetails> taskComparator = new Comparator<TaskDetails>() {

        public int compare(TaskDetails task1, TaskDetails task2) {
            int diff = STRING_COMPARATOR.compare(task1.getPath().getName(), task2.getPath().getName());
            if (diff != 0) {
                return diff;
            }
            Path parent1 = task1.getPath().getParent();
            Path parent2 = task2.getPath().getParent();
            if (parent1 == null && parent2 != null) {
                return -1;
            }
            if (parent1 != null && parent2 == null) {
                return 1;
            }
            if (parent1 == null) {
                return 0;
            }
            return parent1.compareTo(parent2);
        }
    };
    groups = TreeMultimap.create(keyComparator, taskComparator);
    for (String group : model.getGroups()) {
        groups.putAll(group, model.getTasksForGroup(group));
    }
    String otherGroupName = findOtherGroup(groups.keySet());
    if (otherGroupName != null && groups.keySet().contains(DEFAULT_GROUP)) {
        groups.putAll(otherGroupName, groups.removeAll(DEFAULT_GROUP));
    }
    if (groups.keySet().contains(DEFAULT_GROUP) && groups.keySet().size() > 1) {
        groups.putAll(OTHER_GROUP, groups.removeAll(DEFAULT_GROUP));
    }
}
Also used : Path(org.gradle.util.Path) Comparator(java.util.Comparator)

Aggregations

Path (org.gradle.util.Path)3 Comparator (java.util.Comparator)1 LinkedHashSet (java.util.LinkedHashSet)1 StartParameter (org.gradle.StartParameter)1 Configuration (org.gradle.api.artifacts.Configuration)1 Dependency (org.gradle.api.artifacts.Dependency)1 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)1 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)1 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)1 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)1 AbstractTaskDependency (org.gradle.api.internal.tasks.AbstractTaskDependency)1 TaskDependency (org.gradle.api.tasks.TaskDependency)1 GradleLauncher (org.gradle.initialization.GradleLauncher)1 ClassPath (org.gradle.internal.classpath.ClassPath)1 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)1