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

org.wildfly.glow.LayerMapping Maven / Gradle / Ivy

The newest version!
/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2023 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * 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.wildfly.glow;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 *
 * @author jdenise
 */
public class LayerMapping {
    public enum RULE {
        ADD_ON,
        ADD_ON_REQUIRED_DEPENDENCIES_FOUND,
        ADD_ON_ALWAYS_INCLUDED,
        ALWAYS_INCLUDED,
        ANNOTATION,
        BASE_LAYER,
        BRING_DATASOURCE,
        EXPECTED_FILE,
        EXPLICIT,
        JAVA_TYPE,
        NOT_EXPECTED_FILE,
        PROFILE_INCLUDED,
        PROFILE_EXCLUDED,
        PROPERTIES_FILE,
        XML_PATH
    }
    private final Map> constantPoolClassInfos = new HashMap<>();
    private final Map> annotations = new HashMap<>();
    private final Map activeProfilesLayers = new HashMap<>();
    private final Map> allProfilesLayers = new HashMap<>();
    private Layer defaultBaseLayer;

    private final Set layersIncludedIfAllDeps = new TreeSet<>();
    private final Map> layersIncludedIfSomeDeps = new HashMap<>();

    private final Set metadataOnly = new TreeSet<>();
    private final Map> addOnFamilyMembers = new TreeMap<>();
    private final Map addOns = new HashMap<>();
    private final Map> fixedByAddons = new HashMap<>();
    private final Map addOnsCardinalityInFamily = new HashMap<>();
    private final Map addOnsCardinalityInDefaultFamily = new HashMap<>();

    private final Map noConfigurationConditions = new HashMap<>();
    private final Map hiddenConditions = new HashMap<>();
    /**
     * @return the constantPoolClassInfos
     */
    public Map> getConstantPoolClassInfos() {
        return constantPoolClassInfos;
    }

    /**
     * @return the annotations
     */
    public Map> getAnnotations() {
        return annotations;
    }

    /**
     * @return the activeProfilesLayers
     */
    public Map getActiveProfilesLayers() {
        return activeProfilesLayers;
    }

    /**
     * @return the allProfilesLayers
     */
    public Map> getAllProfilesLayers() {
        return allProfilesLayers;
    }

    /**
     * @return the defaultBaseLayer
     */
    public Layer getDefaultBaseLayer() {
        return defaultBaseLayer;
    }

    /**
     * @param defaultBaseLayer the defaultBaseLayer to set
     */
    public void setDefaultBaseLayer(Layer defaultBaseLayer) {
        this.defaultBaseLayer = defaultBaseLayer;
    }

    /**
     * @return the layersIncludedIfAllDeps
     */
    public Set getLayersIncludedIfAllDeps() {
        return layersIncludedIfAllDeps;
    }

    /**
     * @return the layersIncludedIfSomeDeps
     */
    public Map> getLayersIncludedIfSomeDeps() {
        return layersIncludedIfSomeDeps;
    }

    /**
     * @return the metadataOnly
     */
    public Set getMetadataOnly() {
        return metadataOnly;
    }

    /**
     * @return the addOnFamilyMembers
     */
    public Map> getAddOnFamilyMembers() {
        return addOnFamilyMembers;
    }

    /**
     * @return the addOns
     */
    public Map getAddOns() {
        return addOns;
    }

    /**
     * @return the fixedByAddons
     */
    public Map> getFixedByAddons() {
        return fixedByAddons;
    }

    /**
     * @return the addOnsCardinalityInFamily
     */
    public Map getAddOnsCardinalityInFamily() {
        return addOnsCardinalityInFamily;
    }

    /**
     * @return the addOnsCardinalityInDefaultFamily
     */
    public Map getAddOnsCardinalityInDefaultFamily() {
        return addOnsCardinalityInDefaultFamily;
    }

    /**
     * @return the noConfigurationConditions
     */
    public Map getNoConfigurationConditions() {
        return noConfigurationConditions;
    }

    /**
     * @return the hiddenConditions
     */
    public Map getHiddenConditions() {
        return hiddenConditions;
    }

    public static String cleanupKey(String key) {
        if (key.startsWith(LayerMetadata.HIDDEN_IF)) {
            key = key.substring(key.indexOf(LayerMetadata.HIDDEN_IF) + LayerMetadata.HIDDEN_IF.length() + 1, key.length());
        } else {
            if (key.startsWith(LayerMetadata.NO_CONFIGURATION_IF)) {
                key = key.substring(key.indexOf(LayerMetadata.NO_CONFIGURATION_IF) + LayerMetadata.NO_CONFIGURATION_IF.length() + 1, key.length());
            }
        }
        return key;
    }

    public static boolean isCondition(String k) {
        return k.startsWith(LayerMetadata.HIDDEN_IF) || k.startsWith(LayerMetadata.NO_CONFIGURATION_IF);
    }

    public static void addRule(RULE rule, Set layers, String c) {
        for (Layer ll : layers) {
            Set set = ll.getMatchingRules().computeIfAbsent(rule, (value) -> new HashSet<>());
            if (c != null) {
                set.add(c);
            }
        }
    }

    public static void addRule(RULE rule, Layer l, String c) {
        Set set = l.getMatchingRules().computeIfAbsent(rule, (value) -> new HashSet<>());
        if (c != null) {
            set.add(c);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy