Skip to content

Commit

Permalink
Add support for build type (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck authored Dec 18, 2024
1 parent 0584d27 commit c8fecd1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import com.redhat.red.build.koji.KojiClientException;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveQuery;
import com.redhat.red.build.koji.model.xmlrpc.KojiBtype;
import com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiBuildState;
import com.redhat.red.build.koji.model.xmlrpc.KojiIdOrName;
Expand Down Expand Up @@ -416,7 +417,7 @@ private void handleRPMs(Collection<Entry<Checksum, Collection<String>>> rpmEntri
if (cacheManager != null) {
KojiBuild cachedBuild = buildCache.put(id, build);

if (cachedBuild != null && !cachedBuild.getBuildInfo().getTypeNames().contains("rpm")) {
if (cachedBuild != null && !cachedBuild.getBuildInfo().getTypeNames().contains(KojiBtype.rpm)) {
LOGGER.warn("Build id {} was already cached, but this should never happen", red(id));
}
}
Expand Down
27 changes: 23 additions & 4 deletions core/src/main/java/org/jboss/pnc/build/finder/koji/KojiBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiBtype;
import com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiBuildRequest;
import com.redhat.red.build.koji.model.xmlrpc.KojiRpmInfo;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class KojiBuild {

private List<KojiTagInfo> tags;

private transient List<String> types;
private transient List<KojiBtype> types;

private List<KojiRpmInfo> remoteRpms;

Expand All @@ -82,7 +83,7 @@ public KojiBuild(
List<KojiLocalArchive> archives,
List<KojiArchiveInfo> remoteArchives,
List<KojiTagInfo> tags,
List<String> types,
List<KojiBtype> types,
List<KojiRpmInfo> remoteRpms) {
this.buildInfo = buildInfo;
this.taskInfo = taskInfo;
Expand Down Expand Up @@ -156,15 +157,33 @@ public void setTags(List<KojiTagInfo> tags) {
this.tags = tags;
}

public List<String> getTypes() {
/**
* Gets the types.
*
* @return the types
* @deprecated Use {@link KojiBuildInfo#getTypeNames()}
*/
@Deprecated(since = "2.7.0", forRemoval = true)
public List<KojiBtype> getTypes() {
if (types == null && buildInfo != null && buildInfo.getTypeNames() != null) {
types = buildInfo.getTypeNames();
}

return types;
}

public void setTypes(List<String> types) {
/**
* Sets the types.
*
* @param types the types to set
* @deprecated Use {@link KojiBuildInfo#setTypeNames(List)}.
*/
@Deprecated(since = "2.7.0", forRemoval = true)
public void setTypes(List<KojiBtype> types) {
if (buildInfo != null) {
buildInfo.setTypeNames(types);
}

this.types = types;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiBtype;
import com.redhat.red.build.koji.model.xmlrpc.KojiRpmInfo;

public class KojiLocalArchive {
Expand Down Expand Up @@ -69,16 +70,16 @@ public static boolean isMissingBuildTypeInfo(KojiArchiveInfo archive) {
return false;
}

String archiveBuildType = archive.getBuildType();
KojiBtype archiveBuildType = archive.getBuildType();

if (archiveBuildType == null) {
return false;
}

return switch (archiveBuildType) {
case "image" -> archive.getArch() == null;
case "maven" -> archive.getGroupId() == null;
case "win" -> archive.getPlatforms() == null;
case maven -> archive.getGroupId() == null;
case win -> archive.getPlatforms() == null;
case image -> archive.getArch() == null;
default -> false;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static com.redhat.red.build.koji.model.json.KojiJsonConstants.BUILD_SYSTEM;
import static com.redhat.red.build.koji.model.json.KojiJsonConstants.EXTERNAL_BUILD_ID;
import static com.redhat.red.build.koji.model.xmlrpc.KojiBtype.maven;
import static com.redhat.red.build.koji.model.xmlrpc.KojiBtype.npm;
import static org.apache.commons.lang3.ArrayUtils.EMPTY_STRING_ARRAY;
import static org.jboss.pnc.api.constants.Attributes.BREW_TAG_PREFIX;
import static org.jboss.pnc.api.constants.Attributes.BUILD_BREW_NAME;
Expand All @@ -40,10 +42,9 @@
import org.jboss.pnc.dto.ArtifactRef;
import org.jboss.pnc.dto.Build;
import org.jboss.pnc.enums.BuildType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiBtype;
import com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo;
import com.redhat.red.build.koji.model.xmlrpc.KojiBuildState;
import com.redhat.red.build.koji.model.xmlrpc.KojiChecksumType;
Expand All @@ -52,8 +53,6 @@
import com.redhat.red.build.koji.model.xmlrpc.KojiTaskRequest;

public final class PncUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(PncUtils.class);

public static final String EXTERNAL_ARCHIVE_ID = "external_archive_id";

public static final String EXTERNAL_BREW_BUILD_ID = "external_brew_build_id";
Expand All @@ -68,6 +67,8 @@ public final class PncUtils {

public static final String EXTERNAL_VERSION_ID = "external_version_id";

public static final String EXTERNAL_BUILD_TYPE = "external_build_type";

public static final String GRADLE = "gradle";

public static final String MAVEN = "maven";
Expand Down Expand Up @@ -201,8 +202,6 @@ public static KojiBuild pncBuildToKojiBuild(PncBuild pncBuild) {
KojiBuild kojiBuild = new KojiBuild();
Build build = pncBuild.getBuild();

setKojiBuildType(pncBuild, kojiBuild);

KojiBuildInfo buildInfo = new KojiBuildInfo();
setMavenBuildInfoFromBuildRecord(pncBuild, buildInfo);

Expand All @@ -227,7 +226,7 @@ public static KojiBuild pncBuildToKojiBuild(PncBuild pncBuild) {
+ build.getScmRepository().getInternalUrl()
+ (build.getScmRevision() != null ? "#" + build.getScmRevision() : ""));

Map<String, Object> extra = new HashMap<>(8, 1.0f);
Map<String, Object> extra = new HashMap<>(9, 1.0f);

extra.put(BUILD_SYSTEM, PNC);
extra.put(EXTERNAL_BUILD_ID, build.getId());
Expand Down Expand Up @@ -275,32 +274,45 @@ public static KojiBuild pncBuildToKojiBuild(PncBuild pncBuild) {
kojiBuild.setTaskRequest(taskRequest);
});

addPncBuildTypeToExtra(pncBuild.getBuild().getBuildConfigRevision().getBuildType(), extra);
buildInfo.setExtra(extra);
buildInfo.setTypeNames(List.of(getBuildType(pncBuild)));

kojiBuild.setBuildInfo(buildInfo);

return kojiBuild;
}

private static void setKojiBuildType(PncBuild pncBuild, KojiBuild kojiBuild) {
switch (pncBuild.getBuild().getBuildConfigRevision().getBuildType()) {
private static void addPncBuildTypeToExtra(BuildType buildType, Map<String, Object> extra) {
switch (buildType) {
case NPM:
kojiBuild.setTypes(Collections.singletonList(NPM));
extra.put(EXTERNAL_BUILD_TYPE, NPM);
break;
case GRADLE:
kojiBuild.setTypes(Collections.singletonList(GRADLE));
extra.put(EXTERNAL_BUILD_TYPE, GRADLE);
break;
case SBT:
kojiBuild.setTypes(Collections.singletonList(SBT));
extra.put(EXTERNAL_BUILD_TYPE, SBT);
break;
case MVN:
extra.put(EXTERNAL_BUILD_TYPE, MAVEN);
break;
default:
kojiBuild.setTypes(Collections.singletonList(MAVEN));
extra.put(EXTERNAL_BUILD_TYPE, UNKNOWN);
}
}

public static KojiArchiveInfo artifactToKojiArchiveInfo(PncBuild pncbuild, ArtifactRef artifact) {
Build build = pncbuild.getBuild();
private static KojiBtype getBuildType(PncBuild pncBuild) {
BuildType buildType = pncBuild.getBuild().getBuildConfigRevision().getBuildType();

return switch (buildType) {
case MVN, GRADLE, SBT -> maven;
case NPM -> npm;
};
}

public static KojiArchiveInfo artifactToKojiArchiveInfo(PncBuild pncBuild, ArtifactRef artifact) {
Build build = pncBuild.getBuild();
KojiArchiveInfo archiveInfo = new KojiArchiveInfo();

try {
Expand All @@ -315,14 +327,17 @@ public static KojiArchiveInfo artifactToKojiArchiveInfo(PncBuild pncbuild, Artif
archiveInfo.setArchiveId(-1);
}

Map<String, Object> extra = new HashMap<>(2, 1.0f);
Map<String, Object> extra = new HashMap<>(3, 1.0f);
extra.put(EXTERNAL_BUILD_ID, build.getId());
extra.put(EXTERNAL_ARCHIVE_ID, artifact.getId());
BuildType buildType = pncBuild.getBuild().getBuildConfigRevision().getBuildType();
addPncBuildTypeToExtra(buildType, extra);
archiveInfo.setExtra(extra);

archiveInfo.setArch("noarch");
archiveInfo.setFilename(artifact.getFilename());

archiveInfo.setBuildType(getBuildType(pncbuild));
archiveInfo.setBuildType(getBuildType(pncBuild));
archiveInfo.setChecksumType(KojiChecksumType.md5);
archiveInfo.setChecksum(artifact.getMd5());

Expand All @@ -332,7 +347,7 @@ public static KojiArchiveInfo artifactToKojiArchiveInfo(PncBuild pncbuild, Artif
archiveInfo.setSize(-1);
}

switch (pncbuild.getBuild().getBuildConfigRevision().getBuildType()) {
switch (buildType) {
case NPM:
// How do we set ArtifactInfo for NPM builds?
break;
Expand All @@ -354,17 +369,6 @@ public static KojiArchiveInfo artifactToKojiArchiveInfo(PncBuild pncbuild, Artif
return archiveInfo;
}

private static String getBuildType(PncBuild pncBuild) {
BuildType buildType = pncBuild.getBuild().getBuildConfigRevision().getBuildType();

return switch (buildType) {
case MVN -> MAVEN;
case GRADLE -> GRADLE;
case NPM -> NPM;
case SBT -> SBT;
};
}

public static void fixNullVersion(KojiBuild kojibuild, KojiArchiveInfo archiveInfo) {
KojiBuildInfo buildInfo = kojibuild.getBuildInfo();
String buildVersion = buildInfo.getVersion();
Expand Down
11 changes: 6 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<version.com.j2html>1.6.0</version.com.j2html>
<version.com.mycila>4.6</version.com.mycila>
<version.com.puppycrawl.tools>10.21.0</version.com.puppycrawl.tools>
<version.com.redhat.red.build.kojiji>2.20</version.com.redhat.red.build.kojiji>
<version.com.redhat.red.build.kojiji>2.21</version.com.redhat.red.build.kojiji>
<version.commons-codec>1.17.1</version.commons-codec>
<version.commons-io>2.18.0</version.commons-io>
<version.commons-validator>1.9.0</version.commons-validator>
Expand Down Expand Up @@ -145,7 +145,8 @@
<version.org.jboss.byteman>4.0.23</version.org.jboss.byteman>
<version.org.jboss.logging>3.6.1.Final</version.org.jboss.logging>
<version.org.jboss.logmanager>3.1.1.Final</version.org.jboss.logmanager>
<version.org.jboss.pnc>3.0.4</version.org.jboss.pnc>
<version.org.jboss.pnc.pnc>3.0.4</version.org.jboss.pnc.pnc>
<version.org.jboss.pnc.pnc-api>3.0.6-SNAPSHOT</version.org.jboss.pnc.pnc-api>
<version.org.jeasy>5.0.0</version.org.jeasy>
<version.org.jetbrains.kotlin>1.6.21</version.org.jetbrains.kotlin>
<version.org.json.json>20200518</version.org.json.json>
Expand Down Expand Up @@ -387,7 +388,7 @@
<dependency>
<groupId>org.jboss.pnc</groupId>
<artifactId>dto</artifactId>
<version>${version.org.jboss.pnc}</version>
<version>${version.org.jboss.pnc.pnc}</version>
<classifier>patch-builders${jakarta}</classifier>
<exclusions>
<exclusion>
Expand All @@ -400,12 +401,12 @@
<dependency>
<groupId>org.jboss.pnc</groupId>
<artifactId>pnc-api</artifactId>
<version>${version.org.jboss.pnc}</version>
<version>${version.org.jboss.pnc.pnc-api}</version>
</dependency>
<dependency>
<groupId>org.jboss.pnc</groupId>
<artifactId>rest-client${jakarta}</artifactId>
<version>${version.org.jboss.pnc}</version>
<version>${version.org.jboss.pnc.pnc}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.pnc.dto</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jboss.pnc.build.finder.report;

import static com.redhat.red.build.koji.model.xmlrpc.KojiBtype.maven;
import static j2html.TagCreator.attrs;
import static j2html.TagCreator.caption;
import static j2html.TagCreator.each;
Expand Down Expand Up @@ -48,7 +49,9 @@ public GAVReport(File outputDirectory, Collection<KojiBuild> builds) {
setOutputDirectory(outputDirectory);
this.gavs = builds.stream()
.filter(BuildFinderUtils::isNotBuildZero)
.filter(build -> build.getTypes() != null && build.getTypes().contains("maven"))
.filter(
build -> build.getBuildInfo() != null && build.getBuildInfo().getTypeNames() != null
&& build.getBuildInfo().getTypeNames().contains(maven))
.flatMap(build -> build.getArchives().stream())
.map(
localArchive -> localArchive.getArchive().getGroupId() + ":"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.redhat.red.build.koji.model.json.KojiJsonConstants.EXTERNAL_BUILD_URL;
import static com.redhat.red.build.koji.model.json.KojiJsonConstants.GROUP_ID;
import static com.redhat.red.build.koji.model.json.KojiJsonConstants.VERSION;
import static com.redhat.red.build.koji.model.xmlrpc.KojiBtype.maven;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.contentOf;
Expand Down Expand Up @@ -67,7 +68,7 @@ static void setupBuilds(@TempDir File folder) throws IOException {

builds = Collections.unmodifiableList(buildList);

assertThat(buildList).hasSameSizeAs(buildMap.entrySet());
assertThat(builds).hasSameSizeAs(buildMap.entrySet());

testLoad(folder);
}
Expand Down Expand Up @@ -130,7 +131,7 @@ void testBuilds3() {
KojiBuild build = builds.get(3);
assertThat(build.isMaven()).isTrue();
assertThat(build.isImport()).isFalse();
assertThat(build.getTypes()).containsExactly("maven");
assertThat(build.getBuildInfo().getTypeNames()).containsExactly(maven);
assertThat(build.getSource()).get(as(STRING))
.isEqualTo("svn+http://svn.apache.org/repos/asf/commons/proper/beanutils/tags/BEANUTILS_1_9_2#1598386");
assertThat(build.getScmSourcesZip()).get().extracting("filename", as(STRING)).endsWith("-scm-sources.zip");
Expand Down

0 comments on commit c8fecd1

Please sign in to comment.