List of usage examples for org.apache.maven.project.validation ModelValidationResult getMessageCount
public int getMessageCount()
From source file:lu.softec.maven.mavenizer.mavenfile.internal.DefaultMavenFileFactory.java
License:Open Source License
/** * Validate coordinates of a {@link MavenFile} using the {@link ModelValidator} * * @param file {@link MavenFile} to be validated * @throws InvalidMavenCoordinatesException when validation fails *///w w w . ja v a 2 s. co m private void validateArtifactInformation(MavenFile file) throws InvalidMavenCoordinatesException { Model model = file.getMinimalModel(); ModelValidationResult result = modelValidator.validate(model); if (result.getMessageCount() > 0) { throw new InvalidMavenCoordinatesException( "Coordinates are incomplete or not valid:\n" + result.render(" ")); } }
From source file:net.md_5.specialsource.mavenplugin.InstallRemappedFileMojo.java
License:Apache License
/** * Validates the user-supplied artifact information. * * @throws MojoExecutionException If any artifact coordinate is invalid. *//* w w w . j a v a2 s. co m*/ private void validateArtifactInformation() throws MojoExecutionException { Model model = generateModel(); ModelValidationResult result = modelValidator.validate(model); if (result.getMessageCount() > 0) { throw new MojoExecutionException( "The artifact information is incomplete or not valid:\n" + result.render(" ")); } }
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 {/* ww w . java2 s . c o 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; }