private void validate(@NotNull File file, @NotNull Collection<Exception> exceptions, @NotNull Collection<MavenProjectProblem> problems, @Nullable Collection<MavenId> unresolvedArtifacts) throws RemoteException { for (Throwable each : exceptions) { Maven3ServerGlobals.getLogger().info(each); if (each instanceof IllegalStateException && each.getCause() != null) { each = each.getCause(); } if (each instanceof InvalidProjectModelException) { ModelValidationResult modelValidationResult = ((InvalidProjectModelException)each).getValidationResult(); if (modelValidationResult != null) { for (Object eachValidationProblem : modelValidationResult.getMessages()) { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), (String)eachValidationProblem)); } } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getCause().getMessage())); } } else if (each instanceof ProjectBuildingException) { String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage(); problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), causeMessage)); } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getMessage())); } } if (unresolvedArtifacts != null) { unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds()); } }
private void validate(File file, Collection<Exception> exceptions, Collection<MavenProjectProblem> problems, Collection<MavenId> unresolvedArtifacts) throws RemoteException { for (Exception each : exceptions) { Maven2ServerGlobals.getLogger().info(each); if (each instanceof InvalidProjectModelException) { ModelValidationResult modelValidationResult = ((InvalidProjectModelException)each).getValidationResult(); if (modelValidationResult != null) { for (Object eachValidationProblem : modelValidationResult.getMessages()) { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), (String)eachValidationProblem)); } } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getCause().getMessage())); } } else if (each instanceof ProjectBuildingException) { String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage(); problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), causeMessage)); } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getMessage())); } } unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds()); }
private void validate(File pom, List<Exception> exceptions, List<MavenProjectProblem> problems) throws RemoteException { for (Throwable exception : exceptions) { if (exception instanceof IllegalStateException && exception.getCause() != null) { exception = exception.getCause(); } if (exception instanceof InvalidProjectModelException) { ModelValidationResult validationResult = ((InvalidProjectModelException) exception).getValidationResult(); if (validationResult != null) { problems.addAll( validationResult .getMessages() .stream() .map(s -> MavenProjectProblem.newStructureProblem(pom.getPath(), s)) .collect(Collectors.toList())); } else { problems.add( MavenProjectProblem.newStructureProblem( pom.getPath(), exception.getCause().getMessage())); } } if (exception instanceof ProjectBuildingException) { String message = exception.getCause() == null ? exception.getMessage() : exception.getCause().getMessage(); problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), message)); } else { MavenServerContext.getLogger().info(exception); problems.add( MavenProjectProblem.newStructureProblem(pom.getPath(), exception.getMessage())); } } }
private void validate(File file, Collection<Exception> exceptions, Collection<MavenProjectProblem> problems, Collection<MavenId> unresolvedArtifacts) throws RemoteException { for (Exception each : exceptions) { Maven3ServerGlobals.getLogger().info(each); if (each instanceof InvalidProjectModelException) { ModelValidationResult modelValidationResult = ((InvalidProjectModelException)each).getValidationResult(); if (modelValidationResult != null) { for (Object eachValidationProblem : modelValidationResult.getMessages()) { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), (String)eachValidationProblem)); } } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getCause().getMessage())); } } else if (each instanceof ProjectBuildingException) { String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage(); problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), causeMessage)); } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getMessage())); } } unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds()); }
public InvalidProjectModelException( String projectId, String message, File pomFile, ModelValidationResult validationResult ) { super( projectId, message, pomFile ); this.validationResult = validationResult; }
/** * Validates the user-supplied artifact information. * * @throws MojoExecutionException If any artifact coordinate is invalid. */ 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( " " ) ); } }
public final ModelValidationResult getValidationResult() { return validationResult; }
/** * @param projectId * @param pomLocation absolute path of the pom file * @param message * @param validationResult * @deprecated use {@link File} constructor for pomLocation */ public InvalidProjectModelException( String projectId, String pomLocation, String message, ModelValidationResult validationResult ) { this( projectId, message, new File( pomLocation ), validationResult ); }