Java 类org.apache.maven.model.building.ModelSource 实例源码
项目:migration-tooling
文件:Resolver.java
/** 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);
}
}
项目:gate-core
文件:SimpleModelResolver.java
@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);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:DependencyManagementBomTransformation.java
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
throws UnresolvableModelException {
Map<String, String> dependency = new HashMap<String, String>();
dependency.put("group", groupId);
dependency.put("module", artifactId);
dependency.put("version", version);
dependency.put("type", "pom");
try {
return new UrlModelSource(
Grape.getInstance().resolve(null, dependency)[0].toURL());
}
catch (MalformedURLException e) {
throw new UnresolvableModelException(e.getMessage(), groupId, artifactId,
version);
}
}
项目:spring-boot-concourse
文件:DependencyManagementBomTransformation.java
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
throws UnresolvableModelException {
Map<String, String> dependency = new HashMap<String, String>();
dependency.put("group", groupId);
dependency.put("module", artifactId);
dependency.put("version", version);
dependency.put("type", "pom");
try {
return new UrlModelSource(
Grape.getInstance().resolve(null, dependency)[0].toURL());
}
catch (MalformedURLException e) {
throw new UnresolvableModelException(e.getMessage(), groupId, artifactId,
version);
}
}
项目:contestparser
文件:DependencyManagementBomTransformation.java
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
throws UnresolvableModelException {
Map<String, String> dependency = new HashMap<String, String>();
dependency.put("group", groupId);
dependency.put("module", artifactId);
dependency.put("version", version);
dependency.put("type", "pom");
try {
return new UrlModelSource(
Grape.getInstance().resolve(null, dependency)[0].toURL());
}
catch (MalformedURLException e) {
throw new UnresolvableModelException(e.getMessage(), groupId, artifactId,
version);
}
}
项目:mvn-fluid-cd
文件:JenkinsDefaultMaven.java
private List<MavenProject> getProjectsForMavenReactor( MavenSession session )
throws ProjectBuildingException
{
MavenExecutionRequest request = session.getRequest();
request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() );
List<MavenProject> projects = new ArrayList<MavenProject>();
// We have no POM file.
//
if ( request.getPom() == null )
{
ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
MavenProject project =
projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
project.setExecutionRoot( true );
projects.add( project );
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}
项目:furnace
文件:MavenModelResolver.java
@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);
}
项目:oceano
文件:DefaultModelResolver.java
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, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e );
}
File pomFile = pomArtifact.getFile();
return new FileModelSource( pomFile );
}
项目:oceano
文件:DefaultMaven.java
private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
throws ProjectBuildingException
{
List<MavenProject> projects = new ArrayList<MavenProject>();
// We have no POM file.
//
if ( request.getPom() == null )
{
ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
MavenProject project =
projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
project.setExecutionRoot( true );
projects.add( project );
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}
项目:redhat-repository-validator
文件:LocalRepositoryModelResolver.java
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException {
LocalRepository localRepo = repositorySystemSession.getLocalRepository();
File localRepoDir = localRepo.getBasedir();
StringBuilder pomPath = new StringBuilder();
pomPath.append(groupId.replace('.', File.separatorChar));
pomPath.append(File.separatorChar);
pomPath.append(artifactId);
pomPath.append(File.separatorChar);
pomPath.append(version);
pomPath.append(File.separatorChar);
pomPath.append(artifactId);
pomPath.append('-');
pomPath.append(version);
pomPath.append(".pom");
File pomFile = new File(localRepoDir, pomPath.toString());
if (pomFile.exists()) {
return new FileModelSource(pomFile);
} else {
throw new UnresolvableModelException("POM does not exist in local repository: " + pomFile, groupId, artifactId, version);
}
}
项目:forge-furnace
文件:MavenModelResolver.java
@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);
}
项目:flatten-maven-plugin
文件:FlattenModelResolver.java
/**
* {@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 );
}
项目:flatten-maven-plugin
文件:FlattenModelResolver.java
/**
* 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 {
Dependency parentDependency = new Dependency();
parentDependency.setGroupId(parent.getGroupId());
parentDependency.setArtifactId(parent.getArtifactId());
parentDependency.setVersion(parent.getVersion());
parentDependency.setClassifier("");
parentDependency.setType("pom");
Artifact parentArtifact = null;
try
{
Iterable<ArtifactResult> artifactResults = depencencyResolver.resolveDependencies(
projectBuildingRequest, singleton(parentDependency), null, null );
Iterator<ArtifactResult> iterator = artifactResults.iterator();
if (iterator.hasNext()) {
parentArtifact = iterator.next().getArtifact();
}
} catch (DependencyResolverException e) {
throw new UnresolvableModelException( e.getMessage(), parent.getGroupId(), parent.getArtifactId(),
parent.getVersion(), e );
}
return resolveModel( parentArtifact.getGroupId(), parentArtifact.getArtifactId(), parentArtifact.getVersion() );
}
项目:oceano
文件:DefaultMavenProjectBuilder.java
/**
* This is used for pom-less execution like running archetype:generate. I am taking out the profile handling and the
* interpolation of the base directory until we spec this out properly.
*/
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration )
throws ProjectBuildingException
{
ProjectBuildingRequest request = injectSession( toRequest( configuration ) );
request.setProcessPlugins( false );
request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
ModelSource modelSource = new UrlModelSource( getClass().getResource( "standalone.xml" ) );
MavenProject project = projectBuilder.build( modelSource, request ).getProject();
project.setExecutionRoot( true );
return project;
}
项目:oceano
文件:ProjectModelResolver.java
public ModelSource resolveModel( String groupId, String artifactId, String version )
throws UnresolvableModelException
{
File pomFile = null;
if ( modelPool != null )
{
pomFile = modelPool.get( groupId, artifactId, version );
}
if ( pomFile == null )
{
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
try
{
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e );
}
pomFile = pomArtifact.getFile();
}
return new FileModelSource( pomFile );
}
项目:oceano
文件:DefaultProjectBuilder.java
private ModelSource createStubModelSource( Artifact artifact )
{
StringBuilder buffer = new StringBuilder( 1024 );
buffer.append( "<?xml version='1.0'?>" );
buffer.append( "<project>" );
buffer.append( "<modelVersion>4.0.0</modelVersion>" );
buffer.append( "<groupId>" ).append( artifact.getGroupId() ).append( "</groupId>" );
buffer.append( "<artifactId>" ).append( artifact.getArtifactId() ).append( "</artifactId>" );
buffer.append( "<version>" ).append( artifact.getBaseVersion() ).append( "</version>" );
buffer.append( "<packaging>" ).append( artifact.getType() ).append( "</packaging>" );
buffer.append( "</project>" );
return new StringModelSource( buffer, artifact.getId() );
}
项目:incubator-netbeans
文件:NBRepositoryModelResolver.java
@Override
public ModelSource resolveModel(Parent parent) throws UnresolvableModelException {
return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
}
项目:migration-tooling
文件:Resolver.java
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());
}
}
项目:gate-core
文件:SimpleModelResolver.java
@Override
public ModelSource resolveModel(Parent parent)
throws UnresolvableModelException {
return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
}
项目:flatten-maven-plugin
文件:FlattenModelResolver.java
public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException {
return resolveModel( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() );
}
项目:tycho-gen
文件:RepoModelResolver.java
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException
{
Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version);
return new FileModelSource(Maven.getMetadata(system, session, artifact).getFile());
}
项目:furnace
文件:MavenModelResolver.java
public ModelSource resolveModel(Parent parent)
throws UnresolvableModelException
{
// FIXME: Support version range. See DefaultModelResolver
return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
}
项目:oceano
文件:DefaultProjectBuilder.java
public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request )
throws ProjectBuildingException
{
return build( null, modelSource, new InternalConfig( request, null ) );
}
项目:oceano
文件:ProjectBuilder.java
/**
* Builds a project descriptor for the specified model source.
*
* @param modelSource The source of the model to built the project descriptor from, must not be {@code null}.
* @param request The project building request that holds further parameters, must not be {@code null}.
* @return The result of the project building, never {@code null}.
* @throws ProjectBuildingException If the project descriptor could not be successfully built.
*/
ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request )
throws ProjectBuildingException;
项目:oceano
文件:ModelResolver.java
/**
* Tries to resolve the POM for the specified coordinates.
*
* @param groupId The group identifier of the POM, must not be {@code null}.
* @param artifactId The artifact identifier of the POM, must not be {@code null}.
* @param version The version of the POM, must not be {@code null}.
* @return The source of the requested POM, never {@code null}.
* @throws UnresolvableModelException If the POM could not be resolved from any configured repository.
*/
ModelSource resolveModel( String groupId, String artifactId, String version )
throws UnresolvableModelException;