com.buschmais.jqassistant.scm.maven.configuration.source.AbstractObjectValueConfigSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jqassistant-maven-plugin Show documentation
Show all versions of jqassistant-maven-plugin Show documentation
jQAssistant plugin for Apache Maven to integrate jQAssistant
into a Maven based project.
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;
});
}
}