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

com.buschmais.jqassistant.scm.maven.configuration.source.AbstractObjectValueConfigSource Maven / Gradle / Ivy

Go to download

jQAssistant plugin for Apache Maven to integrate jQAssistant into a Maven based project.

There is a newer version: 2.5.0
Show newest version
package com.buschmais.jqassistant.scm.maven.configuration.source;

import java.util.*;

import io.smallrye.config.common.AbstractConfigSource;
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;

/**
 * Abstract config source wrapping a Maven object providing properties values which are extracted using a {@link PrefixedObjectValueSource}.
 *
 * @param 
 *     The type of the Maven object.
 */
class AbstractObjectValueConfigSource extends AbstractConfigSource {

    private final PrefixedObjectValueSource valueSource;
    private final Set propertyNames;

    private final Map properties = new HashMap<>();

    AbstractObjectValueConfigSource(String name, T valueObject, String prefix, Collection propertyNames) {
        super(name, DEFAULT_ORDINAL);
        this.valueSource = new PrefixedObjectValueSource(prefix, valueObject);
        this.propertyNames = new HashSet<>(propertyNames);
    }

    @Override
    public final Set getPropertyNames() {
        return propertyNames;
    }

    @Override
    public String getValue(String property) {
        return properties.computeIfAbsent(property, key -> {
            Object value = valueSource.getValue(key);
            return value != null ?
                value.toString()
                    .replace("\\", "\\\\") :
                null;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy