com.metaeffekt.artifact.extractors.configuration.AbstractExtractorConfiguration Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2021-2024 the original author or authors.
*
* 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 com.metaeffekt.artifact.extractors.configuration;
import com.metaeffekt.artifact.analysis.utils.FileUtils;
import com.metaeffekt.artifact.analysis.utils.StringUtils;
import org.metaeffekt.core.inventory.processor.model.Artifact;
import org.metaeffekt.core.inventory.processor.model.Inventory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
public abstract class AbstractExtractorConfiguration extends ExtractorConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(AbstractExtractorConfiguration.class);
private final String id;
private final File resultInventoryFile;
protected AbstractExtractorConfiguration(String id, File resultInventoryFile) {
this.id = id;
this.resultInventoryFile = resultInventoryFile;
}
public String getId() {
return id;
}
public File getResultInventoryFile() {
return resultInventoryFile;
}
protected void addToInventory(Inventory sourceInventory, Inventory aggregatedInventory) {
for (Artifact artifact : sourceInventory.getArtifacts()) {
final Artifact referenceArtifact;
if (!StringUtils.isEmpty(artifact.getChecksum())) {
referenceArtifact = aggregatedInventory.findArtifactByIdAndChecksum(artifact.getId(), artifact.getChecksum());
} else {
referenceArtifact = aggregatedInventory.findArtifact(artifact.getId());
}
if (referenceArtifact != null) {
// at the moment we do nothing; we may want to validate attributes and add projects.
// FIXME: compare columns; check for deviations; eg. architecture; think of a policy
for (String attribute : artifact.getAttributes()) {
if (referenceArtifact.get(attribute) == null) {
referenceArtifact.set(attribute, artifact.get(attribute));
}
}
} else {
// the artifact is not contained in the aggregated inventory yet; we add it
aggregatedInventory.getArtifacts().add(artifact);
}
}
// copy all AssetMetaData
aggregatedInventory.getAssetMetaData().addAll(sourceInventory.getAssetMetaData());
}
/**
* This method is invoked for the implementation to contribute the information from the analysisDir into the
* aggregatedInventory.
*
* @param targetDir The target directory.
* @param aggregatedInventory The inventory to contribute the information towards.
* @throws IOException If the information cannot be contributed.
*/
public abstract void contribute(File targetDir, Inventory aggregatedInventory) throws IOException;
protected File exist(File file) {
if (file.exists()) return file;
return null;
}
@Override
public void validate() {
FileUtils.validateExists(getResultInventoryFile());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy