All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.maven.plugins.qstools.config.Rules Maven / Gradle / Ivy

Go to download

This a Maven Plugin that helps JBoss Developer quickstarts maintenance. You can use it to verify if your project/quickstart follow the JBoss Developer Guidelines. It will run all JBoss Developer Guideline checkers and generate a report that provides information about any violations that your project/quickstarts has.

There is a newer version: 1.4.1.Final
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
 * contributors by the @authors tag. See the copyright.txt in the 
 * distribution for a full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,  
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.maven.plugins.qstools.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.jboss.maven.plugins.qstools.QSChecker;

/**
 * @author Rafael Benevides
 * 
 */
public class Rules {

    private List configurations;

    public Rules(List configurations) {
        this.configurations = configurations;
    }

    @SuppressWarnings("unchecked")
    public boolean isCheckerIgnored(QSChecker checker) {
        List ignoredCheckers = (List) getConfig("ignored-checkers");
        return ignoredCheckers.contains(checker.getClass().getSimpleName());
    }

    @SuppressWarnings("unchecked")
    public List getIgnoredUnusedProperties() {
        return (List) getConfig("ignored-unused-properties");
    }

    public String getExcludes() {
        Object excludes = getConfig("excludes");
        return excludes.toString().replace('[', ' ').replace(']', ' ');
    }

    public String getCheckerSpecificExcludes(QSChecker module) {
        Object moduleExclude = getConfig("excludes-" + module.getClass().getSimpleName());
        return moduleExclude == null ? "" : moduleExclude.toString().replace('[', ' ').replace(']', ' ');
    }

    public String getExpectedCompilerSource() {
        return (String) getConfig("expected-compiler-source");
    }

    public String getHeaderLocation() {
        return (String) getConfig("header-file");
    }

    public String getGroupId() {
        return (String) getConfig("groupid");
    }

    public String getArtifactIdPrefix() {
        return (String) getConfig("artifactid-prefix");
    }

    public String getPomNamePattern() {
        return (String) getConfig("pom-name-pattern");
    }

    public String getPomNamePatternForSubmodule() {
        return (String) getConfig("pom-name-pattern-submodule");
    }

    @SuppressWarnings("unchecked")
    public Map getFinalNamePatterns() {
        List packagingAsList = (List) getConfig("final-name-patterns");
        Map p = new HashMap();
        for (Object o : packagingAsList) {
            p.putAll((Map) o);
        }
        return p;
    }

    @SuppressWarnings("unchecked")
    public Properties getExpectedBomVersion() {
        List propertiesAsList = (List) getConfig("expected-bom-versions");
        Properties p = new Properties();
        for (Object o : propertiesAsList) {
            p.putAll((Map) o);
        }
        return p;
    }

    @SuppressWarnings("unchecked")
    public Properties getPropertiesNames() {
        List propertiesAsList = (List) getConfig("property-names");
        Properties p = new Properties();
        for (Object o : propertiesAsList) {
            p.putAll((Map) o);
        }
        return p;
    }

    @SuppressWarnings("unchecked")
    public List getPomOrder() {
        List pomOrder = (List) getConfig("pom-order");
        List list = new ArrayList();
        for (String o : pomOrder) {
            list.add(o);
        }
        return list;
    }

    @SuppressWarnings("unchecked")
    public List getIgnoredModules() {
        List modules = (List) getConfig("ignored-modules");
        List list = new ArrayList();
        for (String o : modules) {
            list.add(o);
        }
        return list;
    }

    @SuppressWarnings("unchecked")
    public Map getReadmeMetadatas() {
        List metadatas = (List) getConfig("readme-metadatas");
        Map map = new HashMap();
        for (Object o : metadatas) {
            map.putAll((Map) o);
        }
        return map;
    }

    @SuppressWarnings("unchecked")
    public Object getConfig(String configValue) {
        Object value = null;
        // Get the overwritten non-null value
        for (Object config : configurations) {
            Object foundValue = ((Map) config).get(configValue);
            if (foundValue != null) {
                value = foundValue;
            }
        }
        return value;
    }

    @SuppressWarnings("unchecked")
    public Properties getProjectBomsMigration() {
        List propertiesAsList = (List) getConfig("project-boms-migration");
        Properties p = new Properties();
        for (Object o : propertiesAsList) {
            p.putAll((Map) o);
        }
        return p;
    }

}