From 7c5d49a3dc8f55149e800767405cbb46cfc8b4ac Mon Sep 17 00:00:00 2001 From: Jessie Anderson Date: Thu, 22 Sep 2016 11:08:59 -0400 Subject: [PATCH 1/2] added functionality to extract gavs from filepaths to jars contained in local maven/gradle libs --- pom.xml | 7 ++- .../build/utils/FilePathGavExtractor.java | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/blackducksoftware/integration/build/utils/FilePathGavExtractor.java diff --git a/pom.xml b/pom.xml index 69c2487..2200c17 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ build-tool-common - 2.0.8-SNAPSHOT + 2.0.8 Build Tool Common Manage a Build Info with artifact and dependencies @@ -43,6 +43,11 @@ commons-io 2.4 + + org.eclipse.jdt + core + 3.3.0-v_771 + org.slf4j slf4j-api diff --git a/src/main/java/com/blackducksoftware/integration/build/utils/FilePathGavExtractor.java b/src/main/java/com/blackducksoftware/integration/build/utils/FilePathGavExtractor.java new file mode 100644 index 0000000..92c394d --- /dev/null +++ b/src/main/java/com/blackducksoftware/integration/build/utils/FilePathGavExtractor.java @@ -0,0 +1,47 @@ +package com.blackducksoftware.integration.build.utils; + +import java.io.File; +import java.util.Arrays; + +public class FilePathGavExtractor { + + private static String makeMessage(final String groupId, final String artifactId, final String version) { + final StringBuilder sb = new StringBuilder(); + sb.append("group: "); + sb.append(groupId); + sb.append(", "); + sb.append("artifact: "); + sb.append(artifactId); + sb.append(", "); + sb.append("version: "); + sb.append(version); + return sb.toString(); + } + + public static String getMavenPathGav(final String jarPath, final String localMavenRepoPath) { + final String[] filePathSegments = jarPath.split(File.separator); + final String[] m2RepoSegments = localMavenRepoPath.split(File.separator); + final String[] groupIdSegments = Arrays.copyOfRange(filePathSegments, m2RepoSegments.length, + filePathSegments.length - 3); + final StringBuilder groupIdBuilder = new StringBuilder(); + for (int i = 0; i < groupIdSegments.length; i++) { + groupIdBuilder.append(groupIdSegments[i]); + if (i < groupIdSegments.length - 1) { + groupIdBuilder.append("."); + } + } + final String groupId = groupIdBuilder.toString(); + final String artifactId = filePathSegments[filePathSegments.length - 3]; + final String version = filePathSegments[filePathSegments.length - 2]; + return makeMessage(groupId, artifactId, version); + + } + + public static String getGradlePathGav(final String filePath) { + final String[] filePathSegments = filePath.split(File.separator); + final String groupId = filePathSegments[filePathSegments.length - 5]; + final String artifactId = filePathSegments[filePathSegments.length - 4]; + final String version = filePathSegments[filePathSegments.length - 3]; + return makeMessage(groupId, artifactId, version); + } +} From 5f89059ef107c226bc0fb9ab262a367168f1b75a Mon Sep 17 00:00:00 2001 From: Jessie Anderson Date: Thu, 22 Sep 2016 11:11:22 -0400 Subject: [PATCH 2/2] removed eclipse dependency --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2200c17..a4cf023 100644 --- a/pom.xml +++ b/pom.xml @@ -43,11 +43,6 @@ commons-io 2.4 - - org.eclipse.jdt - core - 3.3.0-v_771 - org.slf4j slf4j-api