Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #10 from blackducksoftware/gav-extractor
Browse files Browse the repository at this point in the history
added functionality to extract gavs from filepaths to jars contained …
  • Loading branch information
jessie-anderson committed Sep 22, 2016
2 parents 8dda602 + 5f89059 commit 054fb11
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>build-tool-common</artifactId>
<version>2.0.8-SNAPSHOT</version>
<version>2.0.8</version>

<name>Build Tool Common</name>
<description>Manage a Build Info with artifact and dependencies</description>
Expand Down
@@ -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);
}
}

0 comments on commit 054fb11

Please sign in to comment.