org.apache.maven.model.building.ModelSource Java Examples
The following examples show how to use
org.apache.maven.model.building.ModelSource.
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: Resolver.java From migration-tooling with Apache License 2.0 | 6 votes |
/** Resolves an artifact as a root of a dependency graph. */ public void resolveArtifact(String artifactCoord) { Artifact artifact; ModelSource modelSource; try { artifact = ArtifactBuilder.fromCoords(artifactCoord); modelSource = modelResolver.resolveModel(artifact); } catch (UnresolvableModelException | InvalidArtifactCoordinateException e) { logger.warning(e.getMessage()); return; } Rule rule = new Rule(artifact); rule.setRepository(modelSource.getLocation()); rule.setSha1(downloadSha1(rule)); deps.put(rule.name(), rule); // add the artifact rule to the workspace Model model = modelResolver.getEffectiveModel(modelSource); if (model != null) { traverseDeps(model, Sets.newHashSet(), Sets.newHashSet(), rule); } }
Example #2
Source File: SimpleModelResolver.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException { Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version); try { ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null); pomArtifact = system.resolveArtifact(session, request).getArtifact(); } catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) { throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex); } File pomFile = pomArtifact.getFile(); return new FileModelSource(pomFile); }
Example #3
Source File: FlattenModelResolver.java From flatten-maven-plugin with Apache License 2.0 | 6 votes |
/** * Resolves the POM for the specified parent. * * @param parent the parent coordinates to resolve, must not be {@code null} * @return The source of the requested POM, never {@code null} * @since Apache-Maven-3.2.2 (MNG-5639) */ public ModelSource resolveModel( Parent parent ) throws UnresolvableModelException { String groupId = parent.getGroupId(); String artifactId = parent.getArtifactId(); String version = parent.getVersion(); // resolve version range (if present) if ( isRestrictedVersionRange( version, groupId, artifactId ) ) { version = resolveParentVersionRange( groupId, artifactId, version ); } return resolveModel( groupId, artifactId, version ); }
Example #4
Source File: RepositoryModelResolver.java From archiva with Apache License 2.0 | 6 votes |
public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException { try { Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "", "pom", dependency.getVersion()); VersionRangeRequest versionRangeRequest = new VersionRangeRequest(artifact, null, null); VersionRangeResult versionRangeResult = this.versionRangeResolver.resolveVersionRange(this.session, versionRangeRequest); if (versionRangeResult.getHighestVersion() == null) { throw new UnresolvableModelException(String.format("No versions matched the requested dependency version range '%s'", dependency.getVersion()), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); } else if (versionRangeResult.getVersionConstraint() != null && versionRangeResult.getVersionConstraint().getRange() != null && versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null) { throw new UnresolvableModelException(String.format("The requested dependency version range '%s' does not specify an upper bound", dependency.getVersion()), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); } else { dependency.setVersion(versionRangeResult.getHighestVersion().toString()); return this.resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); } } catch (VersionRangeResolutionException var5) { throw new UnresolvableModelException(var5.getMessage(), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), var5); } }
Example #5
Source File: MavenModelResolver.java From furnace with Eclipse Public License 1.0 | 6 votes |
@Override public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException { Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version); try { final ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null); pomArtifact = system.resolveArtifact(session, request).getArtifact(); } catch (ArtifactResolutionException e) { throw new UnresolvableModelException("Failed to resolve POM for " + groupId + ":" + artifactId + ":" + version + " due to " + e.getMessage(), groupId, artifactId, version, e); } final File pomFile = pomArtifact.getFile(); return new FileModelSource(pomFile); }
Example #6
Source File: RepositoryModelResolver.java From repairnator with MIT License | 5 votes |
@Override public ModelSource resolveModel(String groupId, String artifactId, String versionId) throws UnresolvableModelException { File pom = getLocalFile(groupId, artifactId, versionId); if (!pom.exists()) { try { download(pom); } catch (IOException e) { throw new UnresolvableModelException("Could not download POM", groupId, artifactId, versionId, e); } } return new FileModelSource(pom); }
Example #7
Source File: FlattenModelResolver.java From flatten-maven-plugin with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public ModelSource resolveModel( String groupId, String artifactId, String version ) { File pomFile = reactorModelPool.find( groupId, artifactId, version ); if ( pomFile == null ) { Artifact pomArtifact = this.artifactFactory.createProjectArtifact( groupId, artifactId, version ); pomArtifact = this.localRepository.find( pomArtifact ); pomFile = pomArtifact.getFile(); } return new FileModelSource( pomFile ); }
Example #8
Source File: Resolver.java From migration-tooling with Apache License 2.0 | 4 votes |
private void addDependency( Dependency dependency, Model model, Set<String> topLevelScopes, Set<String> exclusions, @Nullable Rule parent) { String scope = dependency.getScope(); // DependencyManagement dependencies don't have scope. if (scope != null) { if (parent == null) { // Top-level scopes get pulled in based on the user-provided scopes. if (!topLevelScopes.contains(scope)) { return; } } else { // TODO (bazel-devel): Relabel the scope of transitive dependencies so that they match how // maven relabels them as described here: // https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html if (!INHERITED_SCOPES.contains(scope)) { return; } } } if (dependency.isOptional()) { return; } if (exclusions.contains(unversionedCoordinate(dependency))) { return; } try { Rule artifactRule = new Rule(ArtifactBuilder.fromMavenDependency(dependency, versionResolver)); HashSet<String> localDepExclusions = Sets.newHashSet(exclusions); dependency .getExclusions() .forEach(exclusion -> localDepExclusions.add(unversionedCoordinate(exclusion))); boolean isNewDependency = addArtifact(artifactRule, model.toString()); if (isNewDependency) { ModelSource depModelSource = modelResolver.resolveModel( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); if (depModelSource != null) { artifactRule.setRepository(depModelSource.getLocation()); artifactRule.setSha1(downloadSha1(artifactRule)); Model depModel = modelResolver.getEffectiveModel(depModelSource); if (depModel != null) { traverseDeps(depModel, topLevelScopes, localDepExclusions, artifactRule); } } else { logger.warning("Could not get a model for " + dependency); } } if (parent == null) { addArtifact(artifactRule, TOP_LEVEL_ARTIFACT); } else { parent.addDependency(artifactRule); parent.getDependencies().addAll(artifactRule.getDependencies()); } } catch (UnresolvableModelException | InvalidArtifactCoordinateException e) { logger.warning( "Could not resolve dependency " + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() + ": " + e.getMessage()); } }
Example #9
Source File: NBRepositoryModelResolver.java From netbeans with Apache License 2.0 | 4 votes |
@Override public ModelSource resolveModel(Parent parent) throws UnresolvableModelException { return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); }
Example #10
Source File: NBRepositoryModelResolver.java From netbeans with Apache License 2.0 | 4 votes |
@Override public ModelSource resolveModel(Dependency dpndnc) throws UnresolvableModelException { return resolveModel(dpndnc.getGroupId(), dpndnc.getArtifactId(), dpndnc.getVersion()); }
Example #11
Source File: SimpleModelResolver.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ModelSource resolveModel(Parent parent) throws UnresolvableModelException { return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); }
Example #12
Source File: SimpleModelResolver.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException { return resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); }
Example #13
Source File: RepositoryModelResolver.java From repairnator with MIT License | 4 votes |
@Override public ModelSource resolveModel(Parent parent) throws UnresolvableModelException { return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); }
Example #14
Source File: FlattenModelResolver.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
public ModelSource resolveModel( Dependency dependency ) throws UnresolvableModelException { return resolveModel( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() ); }
Example #15
Source File: MavenModelResolver.java From furnace with Eclipse Public License 1.0 | 4 votes |
public ModelSource resolveModel(Parent parent) throws UnresolvableModelException { // FIXME: Support version range. See DefaultModelResolver return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); }
Example #16
Source File: MavenModelResolver.java From furnace with Eclipse Public License 1.0 | 4 votes |
@Override public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException { return resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); }