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

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

Introduction

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

Prototype

DefaultModelProcessor

Source Link

Usage

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 w w w  .j a  va2 s .  c om
 * @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:org.springframework.boot.cli.compiler.dependencies.SpringBootDependenciesDependencyManagement.java

License:Apache License

private static Model readModel() {
    DefaultModelProcessor modelProcessor = new DefaultModelProcessor();
    modelProcessor.setModelLocator(new DefaultModelLocator());
    modelProcessor.setModelReader(new DefaultModelReader());

    try {// w w  w.j  a  va 2s . c  o m
        return modelProcessor.read(
                SpringBootDependenciesDependencyManagement.class.getResourceAsStream("effective-pom.xml"),
                null);
    } catch (IOException ex) {
        throw new IllegalStateException("Failed to build model from effective pom", ex);
    }
}

From source file:org.springframework.boot.loader.thin.PomLoader.java

License:Apache License

private static Model readModel(Resource resource) {
    DefaultModelProcessor modelProcessor = new DefaultModelProcessor();
    modelProcessor.setModelLocator(new DefaultModelLocator());
    modelProcessor.setModelReader(new DefaultModelReader());

    try {/*  w  ww  .j av a2s  . co m*/
        return modelProcessor.read(resource.getInputStream(), null);
    } catch (IOException ex) {
        throw new IllegalStateException("Failed to build model from effective pom", ex);
    }
}

From source file:org.vesalainen.test.pom.ModelFactory.java

private Model getModel(ModelSource modelSource, ModelResolver modelResolver) {
    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(false);//from w w w . j a va  2  s .  c  o  m
    req.setModelSource(modelSource);
    req.setModelResolver(modelResolver);
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);

    DefaultModelProcessor modelProcessor = new DefaultModelProcessor().setModelReader(new DefaultModelReader());
    DefaultSuperPomProvider superPomProvider = new DefaultSuperPomProvider().setModelProcessor(modelProcessor);
    DefaultPathTranslator pathTranslator = new DefaultPathTranslator();
    DefaultUrlNormalizer urlNormalizer = new DefaultUrlNormalizer();
    StringSearchModelInterpolator stringSearchModelInterpolator = (StringSearchModelInterpolator) new StringSearchModelInterpolator()
            .setPathTranslator(pathTranslator).setUrlNormalizer(urlNormalizer);
    DefaultModelUrlNormalizer modelUrlNormalizer = new DefaultModelUrlNormalizer()
            .setUrlNormalizer(urlNormalizer);
    DefaultModelPathTranslator modelPathTranslator = new DefaultModelPathTranslator()
            .setPathTranslator(pathTranslator);
    ModelBuilder builder = new DefaultModelBuilder()
            .setDependencyManagementImporter(new DefaultDependencyManagementImporter())
            .setDependencyManagementInjector(new DefaultDependencyManagementInjector())
            .setInheritanceAssembler(new DefaultInheritanceAssembler())
            .setModelNormalizer(new DefaultModelNormalizer()).setModelPathTranslator(modelPathTranslator)
            .setModelProcessor(modelProcessor).setModelUrlNormalizer(modelUrlNormalizer)
            .setModelValidator(new DefaultModelValidator())
            .setPluginConfigurationExpander(new DefaultPluginConfigurationExpander())
            .setPluginManagementInjector(new DefaultPluginManagementInjector())
            .setProfileInjector(new DefaultProfileInjector()).setProfileSelector(new DefaultProfileSelector())
            .setReportConfigurationExpander(new DefaultReportConfigurationExpander())
            .setReportingConverter(new DefaultReportingConverter()).setSuperPomProvider(superPomProvider)
            .setModelInterpolator(stringSearchModelInterpolator);
    try {
        return builder.build(req).getEffectiveModel();
    } catch (ModelBuildingException ex) {
        throw new RuntimeException(ex);
    }
}