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

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

Introduction

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

Prototype

@Override
    public String getLocation() 

Source Link

Usage

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

License:Open Source License

public Model getRawModel(FileModelSource fileModelSource, EventHandler handler) {
    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setModelResolver(this);
    request.setModelSource(fileModelSource);
    Model model;/*w w w .ja v a 2 s  .  com*/
    try {
        ModelBuildingResult result = modelBuilder.build(request);
        model = result.getRawModel();
    } catch (ModelBuildingException | IllegalArgumentException e) {
        // IllegalArg can be thrown if the parent POM cannot be resolved.
        handler.handle(Event.error("Unable to resolve raw Maven model from " + fileModelSource.getLocation()
                + ": " + e.getMessage()));
        return null;
    }
    return model;
}

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.
 *//*from   w  w w .j a  va2s  .  com*/
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")));
    }
}