Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Raw use of parameterized class and use constants for build type #695

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -65,7 +72,7 @@ public static FinderResult createFinderResult(String id, URL url, Map<BuildSyste
.build();
}

private static void setLicenseInformation(Artifact.ArtifactBuilder builder, KojiLocalArchive localArchive) {
private static void setLicenseInformation(ArtifactBuilder<?, ?> builder, KojiLocalArchive localArchive) {
Set<LicenseInfo> licenses = Optional.ofNullable(localArchive.getLicenses())
.orElse(Collections.emptySet())
.stream()
Expand Down Expand Up @@ -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();

Expand All @@ -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())
Expand All @@ -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());
}

Expand Down Expand Up @@ -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) {
Expand Down