com.github.aschet.spdx.licensecompat.graph.io.LicenseVertexProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spdx-license-compat Show documentation
Show all versions of spdx-license-compat Show documentation
A license compatibility graph implementation for SPDX license identifiers.
The newest version!
/**
* Copyright 2017 Thomas Ascher
* SPDX-License-Identifier: LGPL-3.0+
*/
package com.github.aschet.spdx.licensecompat.graph.io;
import java.util.Map;
import org.jgrapht.ext.VertexProvider;
import org.spdx.rdfparser.license.LicenseInfoFactory;
import org.spdx.spdxspreadsheet.InvalidLicenseStringException;
import com.github.aschet.spdx.licensecompat.graph.LicenseVertex;
import com.github.aschet.spdx.licensecompat.utils.Utils;
/**
* Part of {@link LicenseCompatGraphImporter} to create the correct vertex type.
*
* @author Thomas Ascher
*/
final class LicenseVertexProvider implements VertexProvider {
@Override
public LicenseVertex buildVertex(final String label, final Map attributes) {
final LicenseVertex vertex = new LicenseVertex();
final String licenseID = attributes.get("label");
try {
vertex.setLicenses(LicenseInfoFactory.parseSPDXLicenseString(licenseID));
} catch (final InvalidLicenseStringException e) {
vertex.setLicenses(Utils.createExtractedLicenseInfo(licenseID));
}
return vertex;
}
}