Handling the scenario when we can't relativize the source path.
@@ -31,6 +31,8 @@ import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId;
@@ -38,8 +40,12 @@ import com.blackducksoftware.integration.hub.detect.model.BomToolType;
@Component
public class BomCodeLocationNameFactory extends CodeLocationNameFactory {
+ private final Logger logger = LoggerFactory.getLogger(BomCodeLocationNameFactory.class);
+
public String createCodeLocationName(final String detectSourcePath, final String sourcePath, final ExternalId externalId, final BomToolType bomToolType, final String prefix, final String suffix) {
//path piece
+ String relativePiece = sourcePath;
+ try {
final Path actualSourcePath = new File(sourcePath).toPath();
final Path detectPath = new File(detectSourcePath).toPath();
final Path detectParentPath = detectPath.getParent();
@@ -48,8 +54,11 @@ public class BomCodeLocationNameFactory extends CodeLocationNameFactory {
for (int i = 0; i < relativePath.getNameCount(); i++) {
relativePieces.add(relativePath.getName(i).toFile().getName());
}
- final String relativePiece = relativePieces.stream().collect(Collectors.joining("/"));
-
+ relativePiece = relativePieces.stream().collect(Collectors.joining("/"));
+ } catch (final Exception e) {
+ logger.info("Unable to relativize path, full source path will be used: " + sourcePath);
+ logger.debug("The reason relativize failed: ", e);
+ }
//external id piece
final List<String> pieces = Arrays.asList(externalId.getExternalIdPieces());
final String externalIdPiece = pieces.stream().collect(Collectors.joining("/"));
