From 4c0ed330c19bf7c12e314dd2b48ce4f9489578c5 Mon Sep 17 00:00:00 2001 From: David Walluck Date: Thu, 5 Sep 2024 09:17:46 -0400 Subject: [PATCH] Fix Raw use of parameterized class and use constants for build type --- .../model/FinderResultCreator.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jboss/pnc/deliverablesanalyzer/model/FinderResultCreator.java b/src/main/java/org/jboss/pnc/deliverablesanalyzer/model/FinderResultCreator.java index cd75dc87..599d209f 100644 --- a/src/main/java/org/jboss/pnc/deliverablesanalyzer/model/FinderResultCreator.java +++ b/src/main/java/org/jboss/pnc/deliverablesanalyzer/model/FinderResultCreator.java @@ -15,7 +15,12 @@ */ package org.jboss.pnc.deliverablesanalyzer.model; +import static org.jboss.pnc.api.deliverablesanalyzer.dto.Artifact.ArtifactBuilder; import static org.jboss.pnc.build.finder.core.BuildFinderUtils.isBuildIdZero; +import static org.jboss.pnc.build.finder.pnc.client.PncUtils.GRADLE; +import static org.jboss.pnc.build.finder.pnc.client.PncUtils.MAVEN; +import static org.jboss.pnc.build.finder.pnc.client.PncUtils.NPM; +import static org.jboss.pnc.build.finder.pnc.client.PncUtils.SBT; import java.net.URL; import java.util.ArrayList; @@ -38,7 +43,9 @@ import org.jboss.pnc.api.deliverablesanalyzer.dto.FinderResult; import org.jboss.pnc.api.deliverablesanalyzer.dto.LicenseInfo; import org.jboss.pnc.api.deliverablesanalyzer.dto.MavenArtifact; +import org.jboss.pnc.api.deliverablesanalyzer.dto.MavenArtifact.MavenArtifactBuilder; import org.jboss.pnc.api.deliverablesanalyzer.dto.NPMArtifact; +import org.jboss.pnc.api.deliverablesanalyzer.dto.NPMArtifact.NPMArtifactBuilder; import org.jboss.pnc.api.enums.LicenseSource; import org.jboss.pnc.build.finder.core.BuildSystem; import org.jboss.pnc.build.finder.core.BuildSystemInteger; @@ -65,7 +72,7 @@ public static FinderResult createFinderResult(String id, URL url, Map builder, KojiLocalArchive localArchive) { Set licenses = Optional.ofNullable(localArchive.getLicenses()) .orElse(Collections.emptySet()) .stream() @@ -111,7 +118,7 @@ private static LicenseInfo toDTO(org.jboss.pnc.build.finder.core.LicenseInfo lic return licenseBuilder.build(); } - private static void setCommonArtifactFields(Artifact.ArtifactBuilder builder, KojiLocalArchive archive) { + private static void setCommonArtifactFields(ArtifactBuilder builder, KojiLocalArchive archive) { KojiArchiveInfo archiveInfo = archive.getArchive(); long size = archiveInfo.getSize(); @@ -134,7 +141,7 @@ private static void setCommonArtifactFields(Artifact.ArtifactBuilder builder, Ko } } - private static MavenArtifact.MavenArtifactBuilder createMavenArtifact(KojiArchiveInfo archiveInfo) { + private static MavenArtifactBuilder createMavenArtifact(KojiArchiveInfo archiveInfo) { return MavenArtifact.builder() .groupId(archiveInfo.getGroupId()) .artifactId(archiveInfo.getArtifactId()) @@ -143,7 +150,7 @@ private static MavenArtifact.MavenArtifactBuilder createMavenArtifact(KojiArchiv .classifier(archiveInfo.getClassifier()); } - private static NPMArtifact.NPMArtifactBuilder createNpmArtifact(KojiArchiveInfo archiveInfo) { + private static NPMArtifactBuilder createNpmArtifact(KojiArchiveInfo archiveInfo) { return NPMArtifact.builder().name(archiveInfo.getArtifactId()).version(archiveInfo.getVersion()); } @@ -226,17 +233,21 @@ private static Build createBuild( private static Artifact createArtifact(KojiLocalArchive localArchive, BuildSystem buildSystem, boolean imported) { KojiArchiveInfo archiveInfo = localArchive.getArchive(); - - Artifact.ArtifactBuilder builder; - if ("maven".equals(archiveInfo.getBuildType()) || "gradle".equals(archiveInfo.getBuildType()) - || "sbt".equals(archiveInfo.getBuildType())) { - builder = createMavenArtifact(archiveInfo); - } else if ("npm".equals(archiveInfo.getBuildType())) { - builder = createNpmArtifact(archiveInfo); - } else { - throw new BadRequestException( - "Archive " + archiveInfo.getArtifactId() + " had unhandled artifact type: " - + archiveInfo.getBuildType()); + String buildType = archiveInfo.getBuildType(); + ArtifactBuilder builder; + + switch (buildType) { + case GRADLE: + case MAVEN: + case SBT: + builder = createMavenArtifact(archiveInfo); + break; + case NPM: + builder = createNpmArtifact(archiveInfo); + break; + default: + throw new BadRequestException( + "Archive " + archiveInfo.getArtifactId() + " had unhandled artifact type: " + buildType); } switch (buildSystem) {