Search in sources :

Example 1 with ModelValidationResult

use of org.apache.maven.project.validation.ModelValidationResult in project che by eclipse.

the class MavenServerImpl method validate.

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()));
        }
    }
}
Also used : InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) ModelValidationResult(org.apache.maven.project.validation.ModelValidationResult) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException)

Example 2 with ModelValidationResult

use of org.apache.maven.project.validation.ModelValidationResult in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method validate.

private void validate(@Nullable File file, @NotNull Collection<Exception> exceptions, @NotNull Collection<MavenProjectProblem> problems, @Nullable Collection<MavenId> unresolvedArtifacts) throws RemoteException {
    for (Throwable each : exceptions) {
        if (each == null)
            continue;
        Maven3ServerGlobals.getLogger().info(each);
        if (each instanceof IllegalStateException && each.getCause() != null) {
            each = each.getCause();
        }
        String path = file == null ? "" : file.getPath();
        if (path.isEmpty() && each instanceof ProjectBuildingException) {
            File pomFile = ((ProjectBuildingException) each).getPomFile();
            path = pomFile == null ? "" : pomFile.getPath();
        }
        if (each instanceof InvalidProjectModelException) {
            ModelValidationResult modelValidationResult = ((InvalidProjectModelException) each).getValidationResult();
            if (modelValidationResult != null) {
                for (Object eachValidationProblem : modelValidationResult.getMessages()) {
                    problems.add(MavenProjectProblem.createStructureProblem(path, (String) eachValidationProblem));
                }
            } else {
                problems.add(MavenProjectProblem.createStructureProblem(path, each.getCause().getMessage()));
            }
        } else if (each instanceof ProjectBuildingException) {
            String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage();
            problems.add(MavenProjectProblem.createStructureProblem(path, causeMessage));
        } else {
            problems.add(MavenProjectProblem.createStructureProblem(path, each.getMessage()));
        }
    }
    if (unresolvedArtifacts != null) {
        unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds());
    }
}
Also used : ModelValidationResult(org.apache.maven.project.validation.ModelValidationResult) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) File(java.io.File)

Example 3 with ModelValidationResult

use of org.apache.maven.project.validation.ModelValidationResult in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method validate.

private void validate(@Nullable File file, @NotNull Collection<Exception> exceptions, @NotNull Collection<MavenProjectProblem> problems, @Nullable Collection<MavenId> unresolvedArtifacts) throws RemoteException {
    for (Throwable each : exceptions) {
        if (each == null)
            continue;
        Maven3ServerGlobals.getLogger().info(each);
        if (each instanceof IllegalStateException && each.getCause() != null) {
            each = each.getCause();
        }
        String path = file == null ? "" : file.getPath();
        if (path.isEmpty() && each instanceof ProjectBuildingException) {
            File pomFile = ((ProjectBuildingException) each).getPomFile();
            path = pomFile == null ? "" : pomFile.getPath();
        }
        if (each instanceof InvalidProjectModelException) {
            ModelValidationResult modelValidationResult = ((InvalidProjectModelException) each).getValidationResult();
            if (modelValidationResult != null) {
                for (Object eachValidationProblem : modelValidationResult.getMessages()) {
                    problems.add(MavenProjectProblem.createStructureProblem(path, (String) eachValidationProblem));
                }
            } else {
                problems.add(MavenProjectProblem.createStructureProblem(path, each.getCause().getMessage()));
            }
        } else if (each instanceof ProjectBuildingException) {
            String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage();
            problems.add(MavenProjectProblem.createStructureProblem(path, causeMessage));
        } else if (each.getStackTrace().length > 0 && each.getClass().getPackage().getName().equals("groovy.lang")) {
            StackTraceElement traceElement = each.getStackTrace()[0];
            problems.add(MavenProjectProblem.createStructureProblem(traceElement.getFileName() + ":" + traceElement.getLineNumber(), each.getMessage()));
        } else {
            problems.add(MavenProjectProblem.createStructureProblem(path, each.getMessage()));
        }
    }
    if (unresolvedArtifacts != null) {
        unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds());
    }
}
Also used : ModelValidationResult(org.apache.maven.project.validation.ModelValidationResult) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) File(java.io.File)

Example 4 with ModelValidationResult

use of org.apache.maven.project.validation.ModelValidationResult in project maven-plugins by apache.

the class SignAndDeployFileMojo method validateArtifactInformation.

/**
     * Validates the user-supplied artifact information.
     * 
     * @throws MojoFailureException If any artifact coordinate is invalid.
     */
private void validateArtifactInformation() throws MojoFailureException {
    Model model = generateModel();
    ModelValidationResult result = modelValidator.validate(model);
    if (result.getMessageCount() > 0) {
        throw new MojoFailureException("The artifact information is incomplete or not valid:\n" + result.render("  "));
    }
}
Also used : ModelValidationResult(org.apache.maven.project.validation.ModelValidationResult) Model(org.apache.maven.model.Model) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

ModelValidationResult (org.apache.maven.project.validation.ModelValidationResult)4 File (java.io.File)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 Model (org.apache.maven.model.Model)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 InvalidProjectModelException (org.apache.maven.project.InvalidProjectModelException)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1