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

The following examples show how to use org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency. 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: AppModelGradleResolver.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private Dependency processQuarkusDir(AppArtifact a, Path quarkusDir, AppModel.Builder appBuilder) {
    if (!Files.exists(quarkusDir)) {
        return null;
    }
    final Path quarkusDescr = quarkusDir.resolve(BootstrapConstants.DESCRIPTOR_FILE_NAME);
    if (!Files.exists(quarkusDescr)) {
        return null;
    }
    final Properties extProps = resolveDescriptor(quarkusDescr);
    if (extProps == null) {
        return null;
    }
    appBuilder.handleExtensionProperties(extProps, a.toString());
    String value = extProps.getProperty(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT);
    final String[] split = value.split(":");

    return new DefaultExternalModuleDependency(split[0], split[1], split[2], null);
}
 
Example #2
Source File: DependencyGroup.java    From atlas with Apache License 2.0 6 votes vote down vote up
private Set<String> getBundleDependencies(Configuration compileClasspath,
                                          Set<? extends DependencyResult> bundleDependencies, Set<String> awbs) {
    Set<String> bundleSets = new HashSet<>();
    for (DependencyResult dependencyResult : bundleDependencies) {
        bundleSets.add(dependencyResult.toString());
    }
    for (Dependency dependency : compileClasspath.getAllDependencies()) {
        if (dependency instanceof DefaultExternalModuleDependency) {
            DefaultExternalModuleDependency externalModuleDependency = (DefaultExternalModuleDependency)dependency;
            if (!((DefaultExternalModuleDependency)dependency).getArtifacts().isEmpty()) {
                if (StringUtils.equalsIgnoreCase("awb", ((DefaultExternalModuleDependency)dependency).getArtifacts()
                    .iterator().next().getType()) || awbs.contains(dependency.getGroup()+":"+dependency.getName())) {
                    bundleSets.add(
                        dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion());
                }
            }
        }
    }
    return bundleSets;
}
 
Example #3
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 #4
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 #5
Source File: ScalaRuntime.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Searches the specified class path for a 'scala-library' Jar, and returns a class path
 * containing a corresponding (same version) 'scala-compiler' Jar and its dependencies.
 *
 * <p>If the (deprecated) 'scalaTools' configuration is explicitly configured, no repository
 * is declared for the project, no 'scala-library' Jar is found on the specified class path,
 * or its version cannot be determined, a class path with the contents of the 'scalaTools'
 * configuration is returned.
 *
 * <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
 *
 * @param classpath a class path containing a 'scala-library' Jar
 * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies
 */
public FileCollection inferScalaClasspath(final Iterable<File> classpath) {
    // alternatively, we could return project.files(Runnable)
    // would differ in the following ways: 1. live (not sure if we want live here) 2. no autowiring (probably want autowiring here)
    return new LazilyInitializedFileCollection() {
        @Override
        public FileCollection createDelegate() {
            if (project.getRepositories().isEmpty()) {
                throw new GradleException(String.format("Cannot infer Scala class path because no repository is declared in %s", project));
            }

            File scalaLibraryJar = findScalaJar(classpath, "library");
            if (scalaLibraryJar == null) {
                throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. "
                        + "Does %s declare dependency to scala-library? Searched classpath: %s.", project, classpath));
            }

            String scalaVersion = getScalaVersion(scalaLibraryJar);
            if (scalaVersion == null) {
                throw new AssertionError(String.format("Unexpectedly failed to parse version of Scala Jar file: %s in %s", scalaLibraryJar, project));
            }

            return project.getConfigurations().detachedConfiguration(
                    new DefaultExternalModuleDependency("org.scala-lang", "scala-compiler", scalaVersion));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #6
Source File: DependencyNotationParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static NotationParser<Object, Dependency> parser(Instantiator instantiator, DefaultProjectDependencyFactory dependencyFactory, ClassPathRegistry classPathRegistry, FileLookup fileLookup) {
    return NotationParserBuilder
            .toType(Dependency.class)
            .fromCharSequence(new DependencyStringNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class))
            .parser(new DependencyMapNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class))
            .fromType(FileCollection.class, new DependencyFilesNotationParser(instantiator))
            .fromType(Project.class, new DependencyProjectNotationParser(dependencyFactory))
            .fromType(DependencyFactory.ClassPathNotation.class, new DependencyClassPathNotationParser(instantiator, classPathRegistry, fileLookup.getFileResolver()))
            .invalidNotationMessage("Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.")
            .toComposite();
}
 
Example #7
Source File: DependencyManagementBuildScopeServices.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
DependencyFactory createDependencyFactory(Instantiator instantiator,
                                          ProjectAccessListener projectAccessListener,
                                          StartParameter startParameter,
                                          ClassPathRegistry classPathRegistry,
                                          FileLookup fileLookup) {
    DefaultProjectDependencyFactory factory = new DefaultProjectDependencyFactory(
            projectAccessListener, instantiator, startParameter.isBuildProjectDependencies());

    ProjectDependencyFactory projectDependencyFactory = new ProjectDependencyFactory(factory);
    DependencyProjectNotationParser projParser = new DependencyProjectNotationParser(factory);

    NotationParser<Object, ? extends Dependency> moduleMapParser = new DependencyMapNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class);
    NotationParser<Object, ? extends Dependency> moduleStringParser = new DependencyStringNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class);
    NotationParser<Object, ? extends Dependency> selfResolvingDependencyFactory = new DependencyFilesNotationParser(instantiator);

    List<NotationParser<Object, ? extends Dependency>> notationParsers = Arrays.asList(
            moduleStringParser,
            moduleMapParser,
            selfResolvingDependencyFactory,
            projParser,
            new DependencyClassPathNotationParser(instantiator, classPathRegistry, fileLookup.getFileResolver()));

    return new DefaultDependencyFactory(
            new DependencyNotationParser(notationParsers),
            new ClientModuleNotationParserFactory(instantiator).create(),
            projectDependencyFactory);
}
 
Example #8
Source File: Utils.java    From Injector with Apache License 2.0 5 votes vote down vote up
public static Dependency createDependencyFrom(ResolvedArtifact resolvedArtifact) {
	ModuleVersionIdentifier identifier = resolvedArtifact.getModuleVersion().getId();
	return identifier.getGroup().isEmpty() ? new DefaultSelfResolvingDependency(
			resolvedArtifact.getId().getComponentIdentifier(),
			new DefaultFileCollectionFactory(new IdentityFileResolver(), null).fixed(resolvedArtifact.getFile())
	) : new DefaultExternalModuleDependency(
			identifier.getGroup(),
			identifier.getName(),
			identifier.getVersion());
}
 
Example #9
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 #10
Source File: ScalaRuntime.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Searches the specified class path for a 'scala-library' Jar, and returns a class path
 * containing a corresponding (same version) 'scala-compiler' Jar and its dependencies.
 *
 * <p>If the (deprecated) 'scalaTools' configuration is explicitly configured, no repository
 * is declared for the project, no 'scala-library' Jar is found on the specified class path,
 * or its version cannot be determined, a class path with the contents of the 'scalaTools'
 * configuration is returned.
 *
 * <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
 *
 * @param classpath a class path containing a 'scala-library' Jar
 * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies
 */
public FileCollection inferScalaClasspath(final Iterable<File> classpath) {
    // alternatively, we could return project.files(Runnable)
    // would differ in the following ways: 1. live (not sure if we want live here) 2. no autowiring (probably want autowiring here)
    return new LazilyInitializedFileCollection() {
        @Override
        public FileCollection createDelegate() {
            if (project.getRepositories().isEmpty()) {
                throw new GradleException(String.format("Cannot infer Scala class path because no repository is declared in %s", project));
            }

            File scalaLibraryJar = findScalaJar(classpath, "library");
            if (scalaLibraryJar == null) {
                throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. "
                        + "Does %s declare dependency to scala-library? Searched classpath: %s.", project, classpath));
            }

            String scalaVersion = getScalaVersion(scalaLibraryJar);
            if (scalaVersion == null) {
                throw new AssertionError(String.format("Unexpectedly failed to parse version of Scala Jar file: %s in %s", scalaLibraryJar, project));
            }

            return project.getConfigurations().detachedConfiguration(
                    new DefaultExternalModuleDependency("org.scala-lang", "scala-compiler", scalaVersion));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #11
Source File: DependencyNotationParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static NotationParser<Object, Dependency> parser(Instantiator instantiator, DefaultProjectDependencyFactory dependencyFactory, ClassPathRegistry classPathRegistry, FileLookup fileLookup) {
    return NotationParserBuilder
            .toType(Dependency.class)
            .fromCharSequence(new DependencyStringNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class))
            .parser(new DependencyMapNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class))
            .fromType(FileCollection.class, new DependencyFilesNotationParser(instantiator))
            .fromType(Project.class, new DependencyProjectNotationParser(dependencyFactory))
            .fromType(DependencyFactory.ClassPathNotation.class, new DependencyClassPathNotationParser(instantiator, classPathRegistry, fileLookup.getFileResolver()))
            .invalidNotationMessage("Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.")
            .toComposite();
}
 
Example #12
Source File: DependencyManagementBuildScopeServices.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
DependencyFactory createDependencyFactory(Instantiator instantiator,
                                          ProjectAccessListener projectAccessListener,
                                          StartParameter startParameter,
                                          ClassPathRegistry classPathRegistry,
                                          FileLookup fileLookup) {
    DefaultProjectDependencyFactory factory = new DefaultProjectDependencyFactory(
            projectAccessListener, instantiator, startParameter.isBuildProjectDependencies());

    ProjectDependencyFactory projectDependencyFactory = new ProjectDependencyFactory(factory);
    DependencyProjectNotationParser projParser = new DependencyProjectNotationParser(factory);

    NotationParser<Object, ? extends Dependency> moduleMapParser = new DependencyMapNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class);
    NotationParser<Object, ? extends Dependency> moduleStringParser = new DependencyStringNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class);
    NotationParser<Object, ? extends Dependency> selfResolvingDependencyFactory = new DependencyFilesNotationParser(instantiator);

    List<NotationParser<Object, ? extends Dependency>> notationParsers = Arrays.asList(
            moduleStringParser,
            moduleMapParser,
            selfResolvingDependencyFactory,
            projParser,
            new DependencyClassPathNotationParser(instantiator, classPathRegistry, fileLookup.getFileResolver()));

    return new DefaultDependencyFactory(
            new DependencyNotationParser(notationParsers),
            new ClientModuleNotationParserFactory(instantiator).create(),
            projectDependencyFactory);
}
 
Example #13
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;
}