public static Map validate()

in src/main/java/org/apache/sling/provisioning/model/ModelUtility.java [164:258]


    public static Map<Traceable, String> validate(final Model model) {
        final Map<Traceable, String> errors = new HashMap<>();

        for(final Feature feature : model.getFeatures() ) {
            // validate feature
            if ( feature.getName() == null || feature.getName().isEmpty() ) {
                addError(errors, feature, "Name is required for a feature.");
            }
            // version should be a valid version
            if ( feature.getVersion() != null ) {
                try {
                    new Version(feature.getVersion());
                } catch ( final IllegalArgumentException iae) {
                    addError(errors, feature, "Version is not a valid version: " + feature.getVersion());
                }
            }
            for(final RunMode runMode : feature.getRunModes()) {
                boolean hasRemove = false;
                final String[] rm = runMode.getNames();
                if ( rm != null ) {
                    int hasSpecial = 0;
                    for(final String m : rm) {
                        if ( m.startsWith(":") ) {
                            if ( hasSpecial > 0 ) {
                                if ( hasSpecial == 1 ) {
                                    if ( ModelConstants.RUN_MODE_REMOVE.equals(m) && !hasRemove) {
                                        hasRemove = true;
                                        hasSpecial = 2;
                                    } else if ( hasRemove && !ModelConstants.RUN_MODE_REMOVE.equals(m) ) {
                                        hasSpecial = 2;
                                    } else {
                                        hasSpecial = 2;
                                        addError(errors, runMode, "Invalid modes " + Arrays.toString(rm));
                                        break;
                                    }
                                } else {
                                    hasSpecial++;
                                    addError(errors, runMode, "Invalid modes " + Arrays.toString(rm));
                                    break;
                                }

                            } else {
                                hasSpecial = 1;
                                hasRemove = ModelConstants.RUN_MODE_REMOVE.equals(m);
                            }
                        }
                    }
                }

                for(final ArtifactGroup sl : runMode.getArtifactGroups()) {
                    if ( sl.getStartLevel() < 0 ) {
                        addError(errors, sl, "Invalid start level " + sl.getStartLevel());
                    }
                    for(final Artifact a : sl) {
                        String error = null;
                        if ( a.getGroupId() == null || a.getGroupId().isEmpty() ) {
                            error = "groupId missing";
                        }
                        if ( a.getArtifactId() == null || a.getArtifactId().isEmpty() ) {
                            error = (error != null ? error + ", " : "") + "artifactId missing";
                        }
                        if ( a.getVersion() == null || a.getVersion().isEmpty() ) {
                            error = (error != null ? error + ", " : "") + "version missing";
                        }
                        if ( a.getType() == null || a.getType().isEmpty() ) {
                            error = (error != null ? error + ", " : "") + "type missing";
                        }
                        if (error != null) {
                            addError(errors, a, error);
                        }
                    }
                }

                for(final Configuration c : runMode.getConfigurations()) {
                    String error = null;
                    if ( c.getPid() == null || c.getPid().isEmpty() ) {
                        error = "pid missing";
                    }
                    if ( c.isSpecial() && c.getFactoryPid() != null ) {
                        error = (error != null ? error + ", " : "") + "factory pid not allowed for special configuration";
                    }
                    if ( c.getProperties().isEmpty() && !hasRemove ) {
                        error = (error != null ? error + ", " : "") + "configuration properties missing";
                    }
                    if (error != null) {
                        addError(errors, c, error);
                    }
                }
            }
        }
        if ( errors.isEmpty()) {
            return null;
        }
        return errors;
    }