diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/GeneralInfo.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/GeneralInfo.java index 9429fd964..2b7dc0825 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/GeneralInfo.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/GeneralInfo.java @@ -1,5 +1,6 @@ package org.jfrog.build.extractor.scan; +import com.fasterxml.jackson.annotation.JsonInclude; import org.apache.commons.lang.StringUtils; import java.io.Serializable; @@ -7,17 +8,14 @@ /** * @author yahavi */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class GeneralInfo implements Serializable { private static final long serialVersionUID = 1L; private String componentId = ""; - private String name = ""; - private String path = ""; private String pkgType = ""; - private String groupId = ""; - private String artifactId = ""; - private String version = ""; + private String path = ""; private String sha1 = ""; @SuppressWarnings("WeakerAccess") @@ -25,39 +23,38 @@ public GeneralInfo() { } @SuppressWarnings("unused") - public GeneralInfo(String componentId, String name, String path, String pkgType) { + public GeneralInfo(String componentId, String path, String pkgType) { this.componentId = componentId; - this.name = name; this.path = path; this.pkgType = pkgType; } public String getGroupId() { - if (StringUtils.isNotBlank(groupId)) { - return groupId; + int colonMatches = StringUtils.countMatches(componentId, ":"); + if (colonMatches != 2) { + return ""; } - return isValid() ? componentId.substring(0, componentId.indexOf(":")) : ""; + return componentId.substring(0, componentId.indexOf(":")); } public String getArtifactId() { - if (StringUtils.isNotBlank(artifactId)) { - return artifactId; - } - if (!isValid()) { + int colonMatches = StringUtils.countMatches(componentId, ":"); + if (colonMatches < 1 || colonMatches > 2) { return ""; } int indexOfColon = componentId.indexOf(":"); - if (StringUtils.countMatches(componentId, ":") == 1) { + if (colonMatches == 1) { return componentId.substring(0, indexOfColon); } return componentId.substring(indexOfColon + 1, componentId.lastIndexOf(":")); } public String getVersion() { - if (StringUtils.isNotBlank(version)) { - return version; + int colonMatches = StringUtils.countMatches(componentId, ":"); + if (colonMatches < 1 || colonMatches > 2) { + return ""; } - return isValid() ? componentId.substring(componentId.lastIndexOf(":") + 1) : ""; + return componentId.substring(componentId.lastIndexOf(":") + 1); } @SuppressWarnings("unused") @@ -65,10 +62,6 @@ public String getComponentId() { return componentId; } - public String getName() { - return name; - } - public String getPath() { return path; } @@ -88,31 +81,11 @@ public GeneralInfo componentId(String componentId) { return this; } - public GeneralInfo name(String name) { - this.name = name; - return this; - } - public GeneralInfo path(String path) { this.path = path; return this; } - public GeneralInfo groupId(String groupId) { - this.groupId = groupId; - return this; - } - - public GeneralInfo artifactId(String artifactId) { - this.artifactId = artifactId; - return this; - } - - public GeneralInfo version(String version) { - this.version = version; - return this; - } - @SuppressWarnings("unused") public GeneralInfo pkgType(String pkgType) { this.pkgType = pkgType; @@ -123,9 +96,4 @@ public GeneralInfo sha1(String sha1) { this.sha1 = sha1; return this; } - - private boolean isValid() { - int colonCount = StringUtils.countMatches(componentId, ":"); - return colonCount == 1 || colonCount == 2; - } } \ No newline at end of file diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/Issue.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/Issue.java index 13fdbd26f..263774c36 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/Issue.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/Issue.java @@ -1,6 +1,7 @@ package org.jfrog.build.extractor.scan; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; import org.apache.commons.lang.StringUtils; import javax.annotation.Nonnull; @@ -10,26 +11,21 @@ /** * @author yahavi */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class Issue implements Comparable { - private String created; - private String description; - private String issueType = "N/A"; - private String provider; private Severity severity = Severity.Normal; - private String summary; - private String component = ""; private List fixedVersions; + private String component = ""; + private String description; + private String summary; public Issue() { } @SuppressWarnings("unused") - public Issue(String created, String description, String issueType, String provider, Severity severity, String summary, List fixedVersions) { - this.created = created; + public Issue(String description, Severity severity, String summary, List fixedVersions) { this.description = description; - this.issueType = issueType; - this.provider = provider; this.severity = severity; this.summary = summary; this.fixedVersions = fixedVersions; @@ -47,25 +43,11 @@ public void setComponent(String component) { this.component = component; } - public String getCreated() { - return created; - } - @SuppressWarnings("unused") public String getDescription() { return description; } - @SuppressWarnings("unused") - public String getIssueType() { - return issueType; - } - - @SuppressWarnings("unused") - public String getProvider() { - return provider; - } - @SuppressWarnings("unused") public String getSummary() { return summary; diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/License.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/License.java index af72088f9..c3ff394e4 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/License.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/scan/License.java @@ -1,6 +1,7 @@ package org.jfrog.build.extractor.scan; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; import org.apache.commons.lang.StringUtils; import java.util.ArrayList; @@ -10,13 +11,14 @@ /** * @author yahavi */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class License { - private static String UNKNOWN_LICENCE_FULL_NAME = "Unknown license"; + private static final String UNKNOWN_LICENCE_FULL_NAME = "Unknown license"; @SuppressWarnings("FieldCanBeLocal") - private static String UNKNOWN_LICENCE_NAME = "Unknown"; + private static final String UNKNOWN_LICENCE_NAME = "Unknown"; private List components = new ArrayList<>(); - private String fullName; - private String name; + private final String fullName; + private final String name; private List moreInfoUrl = new ArrayList<>(); private boolean violate; @@ -55,6 +57,7 @@ public boolean isViolate() { return violate; } + @SuppressWarnings("unused") public void setViolate(boolean violate) { this.violate = violate; } diff --git a/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/DependencyTreeTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/DependencyTreeTest.java index 052034b0f..3bd0569c3 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/DependencyTreeTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/DependencyTreeTest.java @@ -5,7 +5,10 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import static org.testng.Assert.*; import static org.testng.AssertJUnit.assertEquals; @@ -182,7 +185,7 @@ public void testFixedVersions() { * @return the random issue */ private Issue createIssue(Severity severity) { - return new Issue(generateUID(), generateUID(), generateUID(), generateUID(), severity, generateUID(), Lists.newArrayList()); + return new Issue(generateUID(), severity, generateUID(), Lists.newArrayList()); } /** diff --git a/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/GeneralInfoTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/GeneralInfoTest.java new file mode 100644 index 000000000..143f35fe2 --- /dev/null +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/scan/GeneralInfoTest.java @@ -0,0 +1,47 @@ +package org.jfrog.build.extractor.scan; + +import org.testng.annotations.Test; + +import static org.testng.Assert.*; + +/** + * @author yahavi + **/ +public class GeneralInfoTest { + + @Test + public void testEmptyComponentId() { + GeneralInfo generalInfo = new GeneralInfo().componentId(""); + assertEquals(generalInfo.getComponentId(), ""); + assertEquals(generalInfo.getGroupId(), ""); + assertEquals(generalInfo.getArtifactId(), ""); + assertEquals(generalInfo.getVersion(), ""); + } + + @Test + public void testNoColon() { + GeneralInfo generalInfo = new GeneralInfo().componentId("component"); + assertEquals(generalInfo.getComponentId(), "component"); + assertEquals(generalInfo.getGroupId(), ""); + assertEquals(generalInfo.getArtifactId(), ""); + assertEquals(generalInfo.getVersion(), ""); + } + + @Test + public void testArtifactVersion() { + GeneralInfo generalInfo = new GeneralInfo().componentId("artifact:1.2.3"); + assertEquals(generalInfo.getComponentId(), "artifact:1.2.3"); + assertEquals(generalInfo.getGroupId(), ""); + assertEquals(generalInfo.getArtifactId(), "artifact"); + assertEquals(generalInfo.getVersion(), "1.2.3"); + } + + @Test + public void testGroupArtifactVersion() { + GeneralInfo generalInfo = new GeneralInfo().componentId("group:artifact:1.2.3"); + assertEquals(generalInfo.getComponentId(), "group:artifact:1.2.3"); + assertEquals(generalInfo.getGroupId(), "group"); + assertEquals(generalInfo.getArtifactId(), "artifact"); + assertEquals(generalInfo.getVersion(), "1.2.3"); + } +}