Example usage for org.apache.maven.project.validation ModelValidator validate

List of usage examples for org.apache.maven.project.validation ModelValidator validate

Introduction

In this page you can find the example usage for org.apache.maven.project.validation ModelValidator validate.

Prototype

ModelValidationResult validate(Model model);

Source Link

Usage

From source file:org.codehaus.mojo.stage2.MetadataMerger.java

License:Apache License

private Model fromPomFile(final File pom) throws IOException {
    final XmlStreamReader xmlReader = ReaderFactory.newXmlReader(pom);
    final Model model;
    try {//from   w  ww .j a v a 2 s.co  m
        model = new MavenXpp3Reader().read(xmlReader);
    } catch (XmlPullParserException e) {
        throw new IOException("Could not create model from " + pom, e);
    } finally {
        xmlReader.close();
    }
    final Parent parent = model.getParent();
    String groupId = model.getGroupId() == null ? parent.getGroupId() : model.getGroupId();
    String artifactId = model.getArtifactId();
    String version = model.getVersion() == null ? parent.getVersion() : model.getVersion();
    String packaging = model.getPackaging();
    final Model newModel = generateModel(groupId, artifactId, version, packaging);
    System.err.println("XXXXX" + newModel);
    ModelValidator validator = new DefaultModelValidator();
    System.err.println("YYYY" + validator);
    ModelValidationResult validationResult = validator.validate(newModel);
    if (validationResult.getMessageCount() > 0) {
        throw new IOException(validationResult.toString());
    }
    return newModel;
}