org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact Java Examples

The following examples show how to use org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact. 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: GradleArtifactResolvingHelper.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
private Set<ResolvedDependency> doResolve(final Collection<ArtifactSpec> deps) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration();
    final DependencySet dependencySet = config.getDependencies();

    deps.stream()
            .forEach(spec -> {
                if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
                    dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
                } else {
                    final DefaultExternalModuleDependency d =
                            new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
                    final DefaultDependencyArtifact da =
                            new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
                    d.addArtifact(da);
                    d.getExcludeRules().add(new DefaultExcludeRule());
                    dependencySet.add(d);
                }
            });

    return config.getResolvedConfiguration().getFirstLevelModuleDependencies();
}
 
Example #2
Source File: GradleArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
private Set<ResolvedDependency> doResolve(final Collection<ArtifactSpec> deps) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration();
    final DependencySet dependencySet = config.getDependencies();

    deps.forEach(spec -> {
        final DefaultExternalModuleDependency d =
                new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
        final DefaultDependencyArtifact da =
                new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
        d.addArtifact(da);
        d.getExcludeRules().add(new DefaultExcludeRule());
        dependencySet.add(d);
    });

    return config.getResolvedConfiguration().getFirstLevelModuleDependencies();
}
 
Example #3
Source File: ModuleFactoryHelper.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void addExplicitArtifactsIfDefined(ExternalDependency moduleDependency, String artifactType, String classifier) {
    String actualArtifactType = artifactType;
    if (actualArtifactType == null) {
        if (classifier != null) {
            actualArtifactType = DependencyArtifact.DEFAULT_TYPE;
        }
    } else {
        moduleDependency.setTransitive(false);
    }
    if (actualArtifactType != null) {
        moduleDependency.addArtifact(new DefaultDependencyArtifact(moduleDependency.getName(),
                actualArtifactType, actualArtifactType, classifier, null));
    }
}
 
Example #4
Source File: ModuleFactoryHelper.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void addExplicitArtifactsIfDefined(ExternalDependency moduleDependency, String artifactType, String classifier) {
    String actualArtifactType = artifactType;
    if (actualArtifactType == null) {
        if (classifier != null) {
            actualArtifactType = DependencyArtifact.DEFAULT_TYPE;
        }
    } else {
        moduleDependency.setTransitive(false);
    }
    if (actualArtifactType != null) {
        moduleDependency.addArtifact(new DefaultDependencyArtifact(moduleDependency.getName(),
                actualArtifactType, actualArtifactType, classifier, null));
    }
}
 
Example #5
Source File: AppModelGradleResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Path resolve(AppArtifact appArtifact) throws AppModelResolverException {
    if (!appArtifact.isResolved()) {

        final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
        dep.setExtension(appArtifact.getType());
        dep.setType(appArtifact.getType());
        dep.setName(appArtifact.getArtifactId());

        final DefaultExternalModuleDependency gradleDep = new DefaultExternalModuleDependency(appArtifact.getGroupId(),
                appArtifact.getArtifactId(), appArtifact.getVersion(), null);
        gradleDep.addArtifact(dep);

        final Configuration detachedConfig = project.getConfigurations().detachedConfiguration(gradleDep);

        final ResolvedConfiguration rc = detachedConfig.getResolvedConfiguration();
        Set<ResolvedArtifact> resolvedArtifacts = rc.getResolvedArtifacts();
        for (ResolvedArtifact a : resolvedArtifacts) {
            if (appArtifact.getArtifactId().equals(a.getName())
                    && appArtifact.getType().equals(a.getType())
                    && appArtifact.getGroupId().equals(a.getModuleVersion().getId().getGroup())) {
                appArtifact.setPath(a.getFile().toPath());
            }
        }

        if (!appArtifact.isResolved()) {
            throw new AppModelResolverException("Failed to resolve " + appArtifact);
        }

    }
    return appArtifact.getPath();
}
 
Example #6
Source File: ModuleFactoryHelper.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void addExplicitArtifactsIfDefined(ExternalDependency moduleDependency, String artifactType, String classifier) {
    String actualArtifactType = artifactType;
    if (actualArtifactType == null) {
        if (classifier != null) {
            actualArtifactType = DependencyArtifact.DEFAULT_TYPE;
        }
    } else {
        moduleDependency.setTransitive(false);
    }
    if (actualArtifactType != null) {
        moduleDependency.addArtifact(new DefaultDependencyArtifact(moduleDependency.getName(),
                actualArtifactType, actualArtifactType, classifier, null));
    }
}
 
Example #7
Source File: ModuleFactoryHelper.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void addExplicitArtifactsIfDefined(ExternalDependency moduleDependency, String artifactType, String classifier) {
    String actualArtifactType = artifactType;
    if (actualArtifactType == null) {
        if (classifier != null) {
            actualArtifactType = DependencyArtifact.DEFAULT_TYPE;
        }
    } else {
        moduleDependency.setTransitive(false);
    }
    if (actualArtifactType != null) {
        moduleDependency.addArtifact(new DefaultDependencyArtifact(moduleDependency.getName(),
                actualArtifactType, actualArtifactType, classifier, null));
    }
}
 
Example #8
Source File: GradleDependencyResolutionHelper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
/**
 * Resolve the given artifact specifications.
 *
 * @param project         the Gradle project reference.
 * @param specs           the specifications that need to be resolved.
 * @param transitive      should the artifacts be resolved transitively?
 * @param excludeDefaults should we skip resolving artifacts that belong to the Thorntail group?
 * @return collection of resolved artifact specifications.
 */
public static Set<ArtifactSpec> resolveArtifacts(Project project, Collection<ArtifactSpec> specs, boolean transitive,
                                                 boolean excludeDefaults) {
    if (project == null) {
        throw new IllegalArgumentException("Gradle project reference cannot be null.");
    }
    if (specs == null) {
        project.getLogger().warn("Artifact specification collection is null.");
        return Collections.emptySet();
    }

    // Early return if there is nothing to resolve.
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }

    final Configuration config = project.getConfigurations().detachedConfiguration().setTransitive(transitive);
    final DependencySet dependencySet = config.getDependencies();
    final Map<String, Project> projectGAVCoordinates = getAllProjects(project);
    final ProjectAccessListener listener = new DefaultProjectAccessListener();

    Set<ArtifactSpec> result = new HashSet<>();
    specs.forEach(s -> {
        // 1. Do we need to resolve this entry?
        final String specGAV = String.format(GROUP_ARTIFACT_VERSION_FORMAT, s.groupId(), s.artifactId(), s.version());
        boolean resolved = s.file != null;
        boolean projectEntry = projectGAVCoordinates.containsKey(specGAV);

        // 2. Should we skip this spec?
        if (excludeDefaults && FractionDescriptor.THORNTAIL_GROUP_ID.equals(s.groupId()) && !projectEntry) {
            return;
        }

        // 3. Should this entry be resolved?
        if (!resolved || transitive) {
            // a.) Does this entry represent a project dependency?
            if (projectGAVCoordinates.containsKey(specGAV)) {
                dependencySet.add(new DefaultProjectDependency((ProjectInternal) projectGAVCoordinates.get(specGAV), listener, false));
            } else {
                DefaultExternalModuleDependency d = new DefaultExternalModuleDependency(s.groupId(), s.artifactId(), s.version());
                DefaultDependencyArtifact da = new DefaultDependencyArtifact(s.artifactId(), s.type(), s.type(), s.classifier(), null);
                d.addArtifact(da);
                dependencySet.add(d);
            }
        } else {
            // 4. Nothing else to do, just add the spec to the result.
            result.add(s);
        }
    });

    // 5. Are there any specs that need resolution?
    if (!dependencySet.isEmpty()) {
        config.getResolvedConfiguration().getResolvedArtifacts().stream()
                .map(ra -> asDescriptor("compile", ra).toArtifactSpec())
                .forEach(result::add);
    }
    return result;
}