Example usage for org.apache.maven.model.building FileModelSource FileModelSource

List of usage examples for org.apache.maven.model.building FileModelSource FileModelSource

Introduction

In this page you can find the example usage for org.apache.maven.model.building FileModelSource FileModelSource.

Prototype

public FileModelSource(File pomFile) 

Source Link

Document

Creates a new model source backed by the specified file.

Usage

From source file:com.bennavetta.util.tycho.maven.RepoModelResolver.java

License:Apache License

@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());
}

From source file:com.github.nethad.clustermeister.provisioning.dependencymanager.SimpleModelResolver.java

License:Apache License

@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
        throws UnresolvableModelException {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);

    try {/*from  w w w  .j  a v a  2  s .c  o  m*/
        ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
        pomArtifact = system.resolveArtifact(session, request).getArtifact();
    } catch (ArtifactResolutionException ex) {
        throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
    }

    File pomFile = pomArtifact.getFile();

    return new FileModelSource(pomFile);
}

From source file:com.google.devtools.build.workspace.maven.Resolver.java

License:Open Source License

/**
 * Given a local path to a Maven project, this attempts to find the transitive dependencies of
 * the project./*from  ww  w.  j  a v a2s .  c  o  m*/
 * @param projectPath The path to search for Maven projects.
 */
public String resolvePomDependencies(String projectPath) {
    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.
    resolveEffectiveModel(pomSource, Sets.<String>newHashSet(), null);
    return pom.getAbsolutePath();
}

From source file:com.google.devtools.build.workspace.maven.Resolver.java

License:Open Source License

/**
 * Find the POM files for a given pom's parent(s) and submodules.
 *//* w w w . j av a2 s. c  o m*/
private void resolveSourceLocations(FileModelSource fileModelSource) {
    Model model = modelResolver.getRawModel(fileModelSource, handler);
    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) {
            handler.handle(Event.error(
                    "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")));
    }
}

From source file:com.redhat.rcm.version.mgr.VersionManager.java

License:Open Source License

private synchronized ModelBuildingRequest newModelBuildingRequest(final File pom,
        final VersionManagerSession session) {
    if (baseMbr == null) {
        final DefaultModelBuildingRequest mbr = new DefaultModelBuildingRequest();
        mbr.setSystemProperties(System.getProperties());
        mbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        mbr.setProcessPlugins(false);/*ww  w . ja v  a  2  s  .c o m*/
        mbr.setLocationTracking(true);

        this.baseMbr = mbr;
    }

    final DefaultModelBuildingRequest req = new DefaultModelBuildingRequest(baseMbr);
    req.setModelSource(new FileModelSource(pom));

    final VManModelResolver resolver = new VManModelResolver(session, pom, artifactResolver,
            remoteRepositoryManager);

    req.setModelResolver(resolver);

    return req;
}

From source file:io.tesla.aether.guice.DefaultModelResolver.java

License:Open Source License

public ModelSource resolveModel(String groupId, String artifactId, String version)
        throws UnresolvableModelException {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);

    try {/*  w w w. jav  a  2  s .c  o  m*/
        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);
}

From source file:io.tesla.maven.bridge.support.ModelBuildingRequestBuilder.java

License:Open Source License

public ModelBuildingRequestBuilder pom(final File pom) {
    setModelSource(new FileModelSource(pom));
    return this;
}

From source file:org.apache.archiva.metadata.repository.storage.maven2.RepositoryModelResolver.java

License:Apache License

@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
        throws UnresolvableModelException {
    String filename = artifactId + "-" + version + ".pom";
    // TODO: we need to convert 1.0-20091120.112233-1 type paths to baseVersion for the below call - add a test

    File model = pathTranslator.toFile(basedir, groupId, artifactId, version, filename);

    if (!model.exists()) {
        /**/*from  www  .  j  av  a2 s .  c  om*/
         *
         */
        // is a SNAPSHOT ? so we can try to find locally before asking remote repositories.
        if (StringUtils.contains(version, VersionUtil.SNAPSHOT)) {
            File localSnapshotModel = findTimeStampedSnapshotPom(groupId, artifactId, version,
                    model.getParent());
            if (localSnapshotModel != null) {
                return new FileModelSource(localSnapshotModel);
            }

        }

        for (RemoteRepository remoteRepository : remoteRepositories) {
            try {
                boolean success = getModelFromProxy(remoteRepository, groupId, artifactId, version, filename);
                if (success && model.exists()) {
                    log.info("Model '{}' successfully retrieved from remote repository '{}'",
                            model.getAbsolutePath(), remoteRepository.getId());
                    break;
                }
            } catch (ResourceDoesNotExistException e) {
                log.info(
                        "An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}",
                        model.getAbsolutePath(), remoteRepository.getId(), e.getMessage());
            } catch (Exception e) {
                log.warn(
                        "An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}",
                        model.getAbsolutePath(), remoteRepository.getId(), e.getMessage());

                continue;
            }
        }
    }

    return new FileModelSource(model);
}

From source file:org.codehaus.mojo.flatten.model.resolution.FlattenModelResolver.java

License:Apache License

/**
 * {@inheritDoc}//from  w  w w .j  ava2s . c  o  m
 */
public ModelSource resolveModel(String groupId, String artifactId, String version) {

    Artifact pomArtifact = this.artifactFactory.createProjectArtifact(groupId, artifactId, version);
    pomArtifact = this.localRepository.find(pomArtifact);

    File pomFile = pomArtifact.getFile();

    return new FileModelSource(pomFile);
}

From source file:org.codehaus.mojo.flatten.model.resolution.FlattenModelResolver.java

License:Apache License

/**
 * 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)/*from  w ww  .j  a va 2  s  . c o m*/
 */
public ModelSource resolveModel(Parent parent) {
    Artifact pomArtifact = this.artifactFactory.createProjectArtifact(parent.getGroupId(),
            parent.getArtifactId(), parent.getVersion());
    pomArtifact = this.localRepository.find(pomArtifact);

    File pomFile = pomArtifact.getFile();

    return new FileModelSource(pomFile);
}