Example usage for org.apache.maven.model.building ModelBuildingRequest getSystemProperties

List of usage examples for org.apache.maven.model.building ModelBuildingRequest getSystemProperties

Introduction

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

Prototype

Properties getSystemProperties();

Source Link

Document

Gets the system properties to use for interpolation and profile activation.

Usage

From source file:com.doublefx.maven.utils.flexmojos.mavenValidator.FlexMojosCompatibleModelValidator.java

License:Apache License

private void validateEffectiveDependency(ModelProblemCollector problems, Dependency d, boolean management,
        String prefix, ModelBuildingRequest request) {
    this.validateId(prefix + "artifactId", problems, Severity.ERROR, d.getArtifactId(), d.getManagementKey(),
            d);/* w  w  w .  ja v a  2 s.c  o m*/
    this.validateId(prefix + "groupId", problems, Severity.ERROR, d.getGroupId(), d.getManagementKey(), d);
    if (!management) {
        this.validateStringNotEmpty(prefix + "type", problems, Severity.ERROR, d.getType(),
                d.getManagementKey(), d);
        this.validateStringNotEmpty(prefix + "version", problems, Severity.ERROR, d.getVersion(),
                d.getManagementKey(), d);
    }

    if ("system".equals(d.getScope())) {
        String systemPath = d.getSystemPath();
        if (StringUtils.isEmpty(systemPath)) {
            addViolation(problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(), "is missing.",
                    d);
        } else {
            File exclusion = new File(systemPath);
            if (!exclusion.isAbsolute()) {
                addViolation(problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(),
                        "must specify an absolute path but is " + systemPath, d);
            } else if (!exclusion.isFile()) {
                String msg = "refers to a non-existing file " + exclusion.getAbsolutePath();
                systemPath = systemPath.replace('/', File.separatorChar).replace('\\', File.separatorChar);
                String jdkHome = request.getSystemProperties().getProperty("java.home", "") + File.separator
                        + "..";
                if (systemPath.startsWith(jdkHome)) {
                    msg = msg + ". Please verify that you run Maven using a JDK and not just a JRE.";
                }

                addViolation(problems, Severity.WARNING, prefix + "systemPath", d.getManagementKey(), msg, d);
            }
        }
    } else if (StringUtils.isNotEmpty(d.getSystemPath())) {
        addViolation(problems, Severity.ERROR, prefix + "systemPath", d.getManagementKey(),
                "must be omitted. This field may only be specified for a dependency with system scope.", d);
    }

    if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {

        for (Exclusion exclusion1 : d.getExclusions()) {
            this.validateId(prefix + "exclusions.exclusion.groupId", problems, Severity.WARNING,
                    exclusion1.getGroupId(), d.getManagementKey(), exclusion1);
            this.validateId(prefix + "exclusions.exclusion.artifactId", problems, Severity.WARNING,
                    exclusion1.getArtifactId(), d.getManagementKey(), exclusion1);
        }
    }

}