io.fabric8.maven.enricher.standard.ProjectEnricher Maven / Gradle / Ivy
/*
* Copyright 2016 Red Hat, Inc.
*
* Red Hat licenses this file to you 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 io.fabric8.maven.enricher.standard;
import java.util.HashMap;
import java.util.Map;
import io.fabric8.kubernetes.api.builder.TypedVisitor;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.maven.core.util.MapUtil;
import io.fabric8.maven.enricher.api.BaseEnricher;
import io.fabric8.maven.enricher.api.EnricherContext;
import io.fabric8.maven.enricher.api.Kind;
import org.apache.maven.project.MavenProject;
/**
* Add project labels to any object.
* For selectors, the 'version' part is removed.
*
* The following labels are added:
*
* - version
* - project
* - group
* - provider (is set to fabric8)
*
*
* @author roland
* @since 01/04/16
*/
public class ProjectEnricher extends BaseEnricher {
public ProjectEnricher(EnricherContext buildContext) {
super(buildContext, "fmp-project");
}
@Override
public Map getSelector(Kind kind) {
return createLabels(kind == Kind.SERVICE || (kind.isController() && !kind.isPodController()));
}
@Override
public void adapt(KubernetesListBuilder builder) {
// Add to all objects in the builder
builder.accept(new TypedVisitor() {
@Override
public void visit(ObjectMetaBuilder element) {
Map labels = element.getLabels();
MapUtil.mergeIfAbsent(labels, createLabels());
}
});
}
private Map createLabels() {
return createLabels(false);
}
private Map createLabels(boolean withoutVersion) {
MavenProject project = getProject();
Map ret = new HashMap<>();
ret.put("project", project.getArtifactId());
ret.put("group", project.getGroupId());
ret.put("provider", "fabric8");
if (!withoutVersion) {
ret.put("version", project.getVersion());
}
return ret;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy