Skip to content

Commit

Permalink
Merge pull request #181 from axonivy-market/develop
Browse files Browse the repository at this point in the history
MARP-1186 Create release 1.1.0
  • Loading branch information
nqhoan-axonivy authored Sep 30, 2024
2 parents 79b528d + 735fb43 commit 2b3eb96
Show file tree
Hide file tree
Showing 158 changed files with 5,832 additions and 2,612 deletions.
1 change: 1 addition & 0 deletions marketplace-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
data/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
Expand Down
687 changes: 687 additions & 0 deletions marketplace-service/.editorconfig

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions marketplace-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
data/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.axonivy.market;

import com.axonivy.market.service.ProductService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.boot.SpringApplication;
Expand All @@ -15,14 +16,11 @@
@EnableAsync
@EnableScheduling
@SpringBootApplication
@AllArgsConstructor
public class MarketplaceServiceApplication {

private final ProductService productService;

public MarketplaceServiceApplication(ProductService productService) {
this.productService = productService;
}

public static void main(String[] args) {
SpringApplication.run(MarketplaceServiceApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.axonivy.market.assembler;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import com.axonivy.market.constants.RequestMappingConstants;
import com.axonivy.market.controller.ProductDetailsController;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.util.ImageUtils;
import com.axonivy.market.util.VersionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.Optional;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Component
public class ProductDetailModelAssembler extends RepresentationModelAssemblerSupport<Product, ProductDetailModel> {
Expand Down Expand Up @@ -48,9 +47,9 @@ private ProductDetailModel createModel(Product product, String version, String r
String productId = Optional.of(product).map(Product::getId).orElse(StringUtils.EMPTY);

if (requestPath.equals(RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION)) {
String bestMatchVersion = VersionUtils.getBestMatchVersion(product.getReleasedVersions(), version);
Link link = linkTo(
methodOn(ProductDetailsController.class).findProductJsonContent(productId, bestMatchVersion)).withSelfRel();
methodOn(ProductDetailsController.class).findProductJsonContent(productId,
product.getBestMatchVersion())).withSelfRel();
model.setMetaProductJsonUrl(link.getHref());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.axonivy.market.github.model;
package com.axonivy.market.bo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.axonivy.market.github.model;
package com.axonivy.market.bo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -11,14 +11,15 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MavenArtifact implements Serializable {
public class Artifact implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String repoUrl;
Expand All @@ -30,4 +31,22 @@ public class MavenArtifact implements Serializable {
@Transient
private Boolean isProductArtifact;
private List<ArchivedArtifact> archivedArtifacts;
private boolean isInvalidArtifact;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Artifact that = (Artifact) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ public class LatestVersionComparator implements Comparator<String> {

@Override
public int compare(String v1, String v2) {
// Split by "."
String[] parts1 = v1.split("\\.");
String[] parts2 = v2.split("\\.");

// Compare up to the shorter length
int length = Math.min(parts1.length, parts2.length);
for (int i = 0; i < length; i++) {
try {
int num1 = Integer.parseInt(parts1[i]);
int num2 = Integer.parseInt(parts2[i]);
// Return difference for numeric parts
if (num1 != num2) {
return num2 - num1;
}
// Handle non-numeric parts (e.g., "m229")
} catch (NumberFormatException e) {
return parts2[i].replaceAll("\\D", "").compareTo(parts1[i].replaceAll("\\D", ""));
}
}

// Versions with more parts are considered larger
return parts2.length - parts1.length;
return MavenVersionComparator.compare(v2, v1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,112 +11,112 @@
import java.util.regex.Pattern;

import static com.axonivy.market.constants.CommonConstants.DASH_SEPARATOR;
import static com.axonivy.market.constants.MavenConstants.MAIN_VERSION_REGEX;
import static com.axonivy.market.constants.MavenConstants.SNAPSHOT_VERSION;
import static org.apache.commons.lang3.StringUtils.EMPTY;

public class MavenVersionComparator {

private static final String MAIN_VERSION_REGEX = "\\.";
private static final int GREATER_THAN = 1;
private static final int EQUAL = 0;
private static final int LESS_THAN = -1;
private static final int GREATER_THAN = 1;
private static final int EQUAL = 0;
private static final int LESS_THAN = -1;

private MavenVersionComparator() {
}
private MavenVersionComparator() {
}

public static GHTag findHighestTag(List<GHTag> ghTags) {
if (CollectionUtils.isEmpty(ghTags)) {
return null;
}
String highestVersion = findHighestMavenVersion(ghTags.stream().map(GHTag::getName).toList());
return ghTags.stream().filter(tag -> tag.getName().equals(highestVersion)).findAny().orElse(null);
public static GHTag findHighestTag(List<GHTag> ghTags) {
if (CollectionUtils.isEmpty(ghTags)) {
return null;
}
String highestVersion = findHighestMavenVersion(ghTags.stream().map(GHTag::getName).toList());
return ghTags.stream().filter(tag -> tag.getName().equals(highestVersion)).findAny().orElse(null);
}

public static String findHighestMavenVersion(List<String> versions) {
if (CollectionUtils.isEmpty(versions)) {
return null;
}

String highestVersion = versions.get(0);
for (var version : versions) {
if (compare(version, highestVersion) > EQUAL) {
highestVersion = version;
}
}
return highestVersion;
public static String findHighestMavenVersion(List<String> versions) {
if (CollectionUtils.isEmpty(versions)) {
return null;
}

private static int compare(String version, String otherVersion) {
version = stripLeadingChars(version);
otherVersion = stripLeadingChars(otherVersion);
String[] versionParts = createMainAndQualifierArray(version);
String[] otherVersionParts = createMainAndQualifierArray(otherVersion);

// Compare main version parts
int mainComparison = compareMainVersion(versionParts[0], otherVersionParts[0]);
if (mainComparison != EQUAL) {
return mainComparison;
}

// Compare qualifiers
String qualifier1 = getQualifierPart(versionParts);
String qualifier2 = getQualifierPart(otherVersionParts);
// Consider versions without a qualifier higher than those with qualifiers
if (qualifier1.isEmpty() && !qualifier2.isEmpty()) {
return GREATER_THAN;
}
if (!qualifier1.isEmpty() && qualifier2.isEmpty()) {
return LESS_THAN;
}
return compareQualifier(qualifier1, qualifier2);
String highestVersion = versions.get(0);
for (var version : versions) {
if (compare(version, highestVersion) > EQUAL) {
highestVersion = version;
}
}

private static String stripLeadingChars(String version) {
Pattern pattern = Pattern.compile(CommonConstants.DIGIT_REGEX);
Matcher matcher = pattern.matcher(version);
if (matcher.find()) {
return matcher.group(1);
}
return version;
return highestVersion;
}

public static int compare(String version, String otherVersion) {
version = stripLeadingChars(version);
otherVersion = stripLeadingChars(otherVersion);
String[] versionParts = createMainAndQualifierArray(version);
String[] otherVersionParts = createMainAndQualifierArray(otherVersion);

// Compare main version parts
int mainComparison = compareMainVersion(versionParts[0], otherVersionParts[0]);
if (mainComparison != EQUAL) {
return mainComparison;
}

private static int compareMainVersion(String mainVersion, String otherMainVersion) {
String[] parts1 = mainVersion.split(MAIN_VERSION_REGEX);
String[] parts2 = otherMainVersion.split(MAIN_VERSION_REGEX);

int length = Math.max(parts1.length, parts2.length);
for (int i = 0; i < length; i++) {
int num1 = parseToNumber(parts1, i);
int num2 = parseToNumber(parts2, i);
if (num1 != num2) {
return num1 - num2;
}
}
return EQUAL;
// Compare qualifiers
String qualifier1 = getQualifierPart(versionParts);
String qualifier2 = getQualifierPart(otherVersionParts);
// Consider versions without a qualifier higher than those with qualifiers
if (qualifier1.isEmpty() && !qualifier2.isEmpty()) {
return GREATER_THAN;
}

private static String getQualifierPart(String[] versionParts) {
return versionParts.length > 1 ? versionParts[1] : EMPTY;
if (!qualifier1.isEmpty() && qualifier2.isEmpty()) {
return LESS_THAN;
}

private static String[] createMainAndQualifierArray(String version) {
return StringUtils.defaultIfBlank(version, EMPTY).split(DASH_SEPARATOR, 2);
return compareQualifier(qualifier1, qualifier2);
}

private static String stripLeadingChars(String version) {
Pattern pattern = Pattern.compile(CommonConstants.DIGIT_REGEX);
Matcher matcher = pattern.matcher(version);
if (matcher.find()) {
return matcher.group(1);
}
return version;
}

private static int compareMainVersion(String mainVersion, String otherMainVersion) {
String[] parts1 = mainVersion.split(MAIN_VERSION_REGEX);
String[] parts2 = otherMainVersion.split(MAIN_VERSION_REGEX);

int length = Math.max(parts1.length, parts2.length);
for (int i = 0; i < length; i++) {
int num1 = parseToNumber(parts1, i);
int num2 = parseToNumber(parts2, i);
if (num1 != num2) {
return num1 - num2;
}
}
return EQUAL;
}

private static String getQualifierPart(String[] versionParts) {
return versionParts.length > 1 ? versionParts[1] : EMPTY;
}

private static int parseToNumber(String[] versionParts, int index) {
if (index < versionParts.length && NumberUtils.isDigits(versionParts[index])) {
return NumberUtils.toInt(versionParts[index]);
}
return 0;
private static String[] createMainAndQualifierArray(String version) {
return StringUtils.defaultIfBlank(version, EMPTY).split(DASH_SEPARATOR, 2);
}

private static int parseToNumber(String[] versionParts, int index) {
if (index < versionParts.length && NumberUtils.isDigits(versionParts[index])) {
return NumberUtils.toInt(versionParts[index]);
}
return 0;
}

private static int compareQualifier(String qualifier1, String qualifier2) {
if (SNAPSHOT_VERSION.equals(qualifier1) && !SNAPSHOT_VERSION.equals(qualifier2)) {
return LESS_THAN;
}
if (!SNAPSHOT_VERSION.equals(qualifier1) && SNAPSHOT_VERSION.equals(qualifier2)) {
return GREATER_THAN;
}
return qualifier1.compareTo(qualifier2);
private static int compareQualifier(String qualifier1, String qualifier2) {
if (SNAPSHOT_VERSION.equals(qualifier1) && !SNAPSHOT_VERSION.equals(qualifier2)) {
return LESS_THAN;
}
if (!SNAPSHOT_VERSION.equals(qualifier1) && SNAPSHOT_VERSION.equals(qualifier2)) {
return GREATER_THAN;
}
return qualifier1.compareTo(qualifier2);
}
}
Loading

0 comments on commit 2b3eb96

Please sign in to comment.