-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
142 changed files
with
3,301 additions
and
761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
events {} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
|
||
server { | ||
listen 80; | ||
server_name marketplace; | ||
|
||
root /usr/share/nginx/html; | ||
index index.html; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.html; | ||
} | ||
|
||
location /marketplace-service { | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-NginX-Proxy true; | ||
proxy_pass http://service:8080/marketplace-service; | ||
proxy_ssl_session_reuse off; | ||
proxy_set_header Host $http_host; | ||
proxy_cache_bypass $http_upgrade; | ||
proxy_redirect off; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
marketplace-service/src/main/java/com/axonivy/market/comparator/MavenVersionComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.axonivy.market.comparator; | ||
|
||
import com.axonivy.market.constants.CommonConstants; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.math.NumberUtils; | ||
import org.kohsuke.github.GHTag; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static com.axonivy.market.constants.CommonConstants.DASH_SEPARATOR; | ||
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 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 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; | ||
} | ||
|
||
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); | ||
} | ||
|
||
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 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); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
marketplace-service/src/main/java/com/axonivy/market/config/AsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.axonivy.market.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
@Configuration | ||
public class AsyncConfig implements AsyncConfigurer { | ||
|
||
private static final String THREAD_NAME_PREFIX = "AC-Thread-"; | ||
|
||
@Override | ||
public Executor getAsyncExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(5); | ||
executor.setMaxPoolSize(10); | ||
executor.setQueueCapacity(25); | ||
executor.setThreadNamePrefix(THREAD_NAME_PREFIX); | ||
executor.initialize(); | ||
return executor; | ||
} | ||
} |
Oops, something went wrong.