private void addManagedDependencies(DependencyResult result) { this.resolutionContext.addManagedDependencies(getDependencies(result)); }
public String getVersion(String artifactId, String defaultVersion) { String version = this.dependencyResolutionContext.getArtifactCoordinatesResolver() .getVersion(artifactId); if (version == null) { version = defaultVersion; } return version; }
public String getManagedVersion(String groupId, String artifactId) { Dependency dependency = getManagedDependency(groupId, artifactId); if (dependency == null) { dependency = this.managedDependencyByGroupAndArtifact .get(getIdentifier(groupId, artifactId)); } return (dependency != null) ? dependency.getArtifact().getVersion() : null; }
public static void install(GroovyClassLoader classLoader) { install(classLoader, new DependencyResolutionContext(), RepositoryConfigurationFactory .createDefaultRepositoryConfiguration()); }
this.loader = createLoader(configuration); DependencyResolutionContext resolutionContext = new DependencyResolutionContext(); resolutionContext.addDependencyManagement( new SpringBootDependenciesDependencyManagement());
private CollectRequest getCollectRequest(List<Dependency> dependencies) { CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, new ArrayList<>(this.repositories)); collectRequest .setManagedDependencies(this.resolutionContext.getManagedDependencies()); return collectRequest; }
private void updateDependencyResolutionContext( List<Map<String, String>> bomDependencies) { URI[] uris = Grape.getInstance().resolve(null, bomDependencies.toArray(new Map[0])); DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance(); for (URI uri : uris) { try { DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setModelResolver(new GrapeModelResolver()); request.setModelSource(new UrlModelSource(uri.toURL())); request.setSystemProperties(System.getProperties()); Model model = modelBuilder.build(request).getEffectiveModel(); this.resolutionContext.addDependencyManagement( new MavenModelDependencyManagement(model)); } catch (Exception ex) { throw new IllegalStateException("Failed to build model for '" + uri + "'. Is it a valid Maven bom?", ex); } } }
private Dependency getManagedDependency(String group, String artifact) { return this.managedDependencyByGroupAndArtifact .get(getIdentifier(group, artifact)); }
private Artifact createArtifact(Map<?, ?> dependencyMap) { String group = (String) dependencyMap.get("group"); String module = (String) dependencyMap.get("module"); String version = (String) dependencyMap.get("version"); if (version == null) { version = this.resolutionContext.getManagedVersion(group, module); } String classifier = (String) dependencyMap.get("classifier"); String type = determineType(dependencyMap); return new DefaultArtifact(group, module, classifier, type, version); }
private URLClassLoader populateClassloader(OptionSet options) throws MalformedURLException { DependencyResolutionContext resolutionContext = new DependencyResolutionContext(); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File("repository").toURI(), true)); boolean quiet = true; if (options.has(debugOption)) { System.setProperty("groovy.grape.report.downloads", "true"); quiet = false; } AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(null, repositoryConfiguration, resolutionContext, quiet); HashMap<String, Object> dependency = new HashMap<>(); dependency.put("group", "org.springframework.cloud.launcher"); dependency.put("module", "spring-cloud-launcher-deployer"); dependency.put("version", getVersion()); dependency.put("transitive", false); URI[] uris = grapeEngine.resolve(null, dependency); URLClassLoader loader = new URLClassLoader(new URL[] { uris[0].toURL() }, getClass().getClassLoader().getParent().getParent()); log.debug("resolved URIs " + Arrays.asList(loader.getURLs())); return loader; }
public void addManagedDependencies(List<Dependency> dependencies) { this.managedDependencies.addAll(dependencies); for (Dependency dependency : dependencies) { this.managedDependencyByGroupAndArtifact.put(getIdentifier(dependency), dependency); } }
public DefaultAetherGrapeEngine() { groovyClassLoader = getGroovyClassLoader(); grapeEngine = AetherGrapeEngineFactory.create(groovyClassLoader, RepositoryConfigurationFactory.createDefaultRepositoryConfiguration(), new DependencyResolutionContext()); }
private String getIdentifier(Dependency dependency) { return getIdentifier(dependency.getArtifact().getGroupId(), dependency.getArtifact().getArtifactId()); }
private void applyGroupAndVersion(AnnotationNode annotation, String module) { if (module != null) { setMember(annotation, "module", module); } else { Expression expression = annotation.getMembers().get("module"); module = (String) ((ConstantExpression) expression).getValue(); } if (annotation.getMember("group") == null) { setMember(annotation, "group", this.resolutionContext .getArtifactCoordinatesResolver().getGroupId(module)); } if (annotation.getMember("version") == null) { setMember(annotation, "version", this.resolutionContext .getArtifactCoordinatesResolver().getVersion(module)); } }
public void addDependencyManagement(DependencyManagement dependencyManagement) { for (org.springframework.boot.cli.compiler.dependencies.Dependency dependency : dependencyManagement .getDependencies()) { List<Exclusion> aetherExclusions = new ArrayList<>(); for (org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion exclusion : dependency .getExclusions()) { aetherExclusions.add(new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*")); } Dependency aetherDependency = new Dependency( new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "jar", dependency.getVersion()), JavaScopes.COMPILE, false, aetherExclusions); this.managedDependencies.add(0, aetherDependency); this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency), aetherDependency); } this.dependencyManagement = (this.dependencyManagement != null) ? new CompositeDependencyManagement(dependencyManagement, this.dependencyManagement) : dependencyManagement; this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver( this.dependencyManagement); }
/** * Add a single dependency with the specified classifier and type and, optionally, all * of its dependencies. The group ID and version of the dependency are resolved from * the module by using the customizer's {@link ArtifactCoordinatesResolver}. * @param module the module ID * @param classifier the classifier, may be {@code null} * @param type the type, may be {@code null} * @param transitive {@code true} if the transitive dependencies should also be added, * otherwise {@code false} * @return this {@link DependencyCustomizer} for continued use */ public DependencyCustomizer add(String module, String classifier, String type, boolean transitive) { if (canAdd()) { ArtifactCoordinatesResolver artifactCoordinatesResolver = this.dependencyResolutionContext .getArtifactCoordinatesResolver(); this.classNode.addAnnotation( createGrabAnnotation(artifactCoordinatesResolver.getGroupId(module), artifactCoordinatesResolver.getArtifactId(module), artifactCoordinatesResolver.getVersion(module), classifier, type, transitive)); } return this; }