Java 类org.apache.maven.model.building.FileModelSource 实例源码

项目:migration-tooling    文件:Resolver.java   
/**
 * Given a local path to a Maven project, this attempts to find the transitive dependencies of the
 * project.
 *
 * @param projectPath The path to search for Maven projects.
 * @param scopes The scopes to look up dependencies in.
 */
public String resolvePomDependencies(String projectPath, Set<String> scopes) {
  DefaultModelProcessor processor = new DefaultModelProcessor();
  processor.setModelLocator(new DefaultModelLocator());
  processor.setModelReader(new DefaultModelReader());
  File pom = processor.locatePom(new File(projectPath));
  FileModelSource pomSource = new FileModelSource(pom);
  // First resolve the model source locations.
  resolveSourceLocations(pomSource);
  // Next, fully resolve the models.
  Model model = modelResolver.getEffectiveModel(pomSource);
  if (model != null) {
    traverseDeps(model, scopes, Sets.newHashSet(), null);
  }
  return pom.getAbsolutePath();
}
项目: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);
}
项目:meghanada-server    文件:POMParser.java   
@Override
public ModelSource2 resolveModel(
    final String groupId, final String artifactId, final String version)
    throws UnresolvableModelException {
  final Config config = Config.load();
  final String localRepository = config.getMavenLocalRepository();
  final String parent = ClassNameUtils.replace(groupId, ".", File.separator);
  final String path =
      Joiner.on(File.separator).join(localRepository, parent, artifactId, version);
  final String file = artifactId + '-' + version + ".pom";
  final File pom = new File(path, file);
  final boolean exists = pom.exists();

  if (!loaded.contains(pom)) {
    loaded.add(pom);
  }
  if (exists) {
    return new FileModelSource(pom);
  }
  return null;
}
项目:meghanada-server    文件:POMParser.java   
@Override
public ModelSource2 resolveModel(final Parent parent) throws UnresolvableModelException {
  final String groupId = parent.getGroupId();
  final String artifactId = parent.getArtifactId();
  final String version = parent.getVersion();
  final ModelSource2 model = resolveModel(groupId, artifactId, version);
  if (nonNull(model)) {
    return model;
  }
  String relativePath = parent.getRelativePath();

  if (nonNull(relativePath) && !relativePath.isEmpty()) {
    File pom = new File(this.projectRoot, relativePath);
    if (!relativePath.endsWith("pom.xml")) {
      pom = new File(relativePath, "pom.xml");
    }
    if (!loaded.contains(pom)) {
      loaded.add(pom);
    }
    if (pom.exists()) {
      return new FileModelSource(pom);
    }
  }
  return null;
}
项目: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 );
}
项目: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);

}
项目:migration-tooling    文件:Resolver.java   
/** Find the POM files for a given pom's parent(s) and submodules. */
private void resolveSourceLocations(FileModelSource fileModelSource) {
  Model model = modelResolver.getRawModel(fileModelSource);
  if (model == null) {
    return;
  }

  // Self.
  Parent parent = model.getParent();
  if (model.getGroupId() == null) {
    model.setGroupId(parent.getGroupId());
  }
  if (!modelResolver.putModelSource(model.getGroupId(), model.getArtifactId(), fileModelSource)) {
    return;
  }

  // Parent.
  File pomDirectory = new File(fileModelSource.getLocation()).getParentFile();
  if (parent != null && !parent.getArtifactId().equals(model.getArtifactId())) {
    File parentPom;
    try {
      parentPom = new File(pomDirectory, parent.getRelativePath()).getCanonicalFile();
    } catch (IOException e) {
      logger.warning(
          "Unable to get canonical path of " + pomDirectory + " and " + parent.getRelativePath());
      return;
    }
    if (parentPom.exists()) {
      resolveSourceLocations(new FileModelSource(parentPom));
    }
  }

  // Submodules.
  for (String module : model.getModules()) {
    resolveSourceLocations(new FileModelSource(new File(pomDirectory, module + "/pom.xml")));
  }
}
项目: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 );
}
项目: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 );
}
项目:redhat-repository-validator    文件:ValidatorSupport.java   
public ModelBuildingResult buildModel(File pomFile) {
    ModelBuildingResult result = null;

    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(modelBuildingRequestTemplate);
    request.setPomFile(pomFile);
    request.setModelSource(new FileModelSource(pomFile));
    try {
        result = modelBuilder.build(request);
    } catch (ModelBuildingException e) {
        result = null;
    }

    return result;
}
项目:redhat-repository-validator    文件:ModelValidator.java   
private void validate(ValidatorContext ctx, File pomFile) {
    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(modelBuildingRequestTemplate);
    request.setPomFile(pomFile);
    request.setModelSource(new FileModelSource(pomFile));
    request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
    try {
        modelBuilder.build(request);
    } catch (ModelBuildingException e) {
        ctx.addError(this, pomFile, e);
    }
}
项目: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());
}
项目:oceano    文件:DefaultProjectBuilder.java   
public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request )
    throws ProjectBuildingException
{
    return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null ) );
}
项目:oceano    文件:DefaultProjectBuilder.java   
public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, ProjectBuildingRequest request )
    throws ProjectBuildingException
{
    org.sonatype.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact );
    pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact );

    InternalConfig config = new InternalConfig( request, null );

    boolean localProject;

    try
    {
        ArtifactRequest pomRequest = new ArtifactRequest();
        pomRequest.setArtifact( pomArtifact );
        pomRequest.setRepositories( config.repositories );
        ArtifactResult pomResult = repoSystem.resolveArtifact( config.session, pomRequest );

        pomArtifact = pomResult.getArtifact();
        localProject = pomResult.getRepository() instanceof WorkspaceRepository;
    }
    catch ( org.sonatype.aether.resolution.ArtifactResolutionException e )
    {
        if ( e.getResults().get( 0 ).isMissing() && allowStubModel )
        {
            return build( null, createStubModelSource( artifact ), config );
        }
        throw new ProjectBuildingException( artifact.getId(),
                                            "Error resolving project artifact: " + e.getMessage(), e );
    }

    File pomFile = pomArtifact.getFile();

    if ( "pom".equals( artifact.getType() ) )
    {
        artifact.selectVersion( pomArtifact.getVersion() );
        artifact.setFile( pomFile );
        artifact.setResolved( true );
    }

    return build( localProject ? pomFile : null, new FileModelSource( pomFile ), config );
}