Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/update-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
cd url-updater
mvn -B -ntp -Dstyle.color=always install
mvn -B -ntp -Dstyle.color=always exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="../ide-urls"
mvn -B -ntp -Dstyle.color=always exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="../ide-urls PT-5H30M"
- name: Commit and push to ide-urls
run: |
cd ide-urls
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.devonfw.tools.ide.url;

import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.format.DateTimeParseException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -15,22 +18,41 @@ public class UpdateInitiator {
private static final Logger logger = LoggerFactory.getLogger(UpdateInitiator.class.getName());

/**
* @param args the command-line arguments. Has to have a single argument pointing to the {@code ide-urls} repository.
* @param args the command-line arguments. arg[0] points to the {@code ide-urls} repository. arg[1] defines a timeout
* for GitHub actions in Duration string format.
*/
public static void main(String[] args) {

if (args.length == 0) {
logger.error("Error: Missing path to repository as command line argument.");
logger.error("Usage: java UpdateInitiator <path_to_repository>");
logger.error("Error: Missing path to repository as well as missing timeout as command line arguments.");
logger.error("Usage: java UpdateInitiator <path_to_repository> <duration_string_format>");
System.exit(1);
}

String pathToRepo = args[0];
Instant expirationTime = null;

if (args.length < 2) {
logger.warn("Timeout was not set, setting timeout to infinite instead.");
} else {
try {
Duration duration = Duration.parse(args[1]);
expirationTime = Instant.now().plus(duration);
logger.info("Timeout was set to: {}.", expirationTime);
} catch (DateTimeParseException e) {
logger.error("Error: Provided timeout format is not valid.", e);
System.exit(1);
}
}

Path repoPath = Path.of(pathToRepo);

if (!repoPath.toFile().isDirectory()) {
logger.error("Error: Provided path is not a valid directory.");
System.exit(1);
}
UpdateManager updateManager = new UpdateManager(repoPath);

UpdateManager updateManager = new UpdateManager(repoPath, expirationTime);
updateManager.updateAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public abstract class AbstractUrlUpdater implements UrlUpdater {

private static final Logger logger = LoggerFactory.getLogger(AbstractUrlUpdater.class);

/** The {@link Instant} expiration time for the GitHub actions url-update job */
private Instant expirationTime;

/**
* @param expirationTime to set for the GitHub actions url-update job
*/
public void setExpirationTime(Instant expirationTime) {

this.expirationTime = expirationTime;
}

/**
* @return the name of the {@link UrlTool tool} handled by this updater.
*/
Expand Down Expand Up @@ -433,6 +444,25 @@ private void doUpdateStatusJson(boolean success, int statusCode, UrlVersion urlV
}
}

/**
* Checks if the timeout was expired.
*
* @return boolean true if timeout was expired, false if not
*/
public boolean isTimeoutExpired() {

if (this.expirationTime == null) {
return false;
}

if (Instant.now().isAfter(expirationTime)) {
logger.warn("Expiration time of timeout was reached, cancelling update process.");
return true;
}

return false;
}

/**
* Updates the tool's versions in the URL repository.
*
Expand All @@ -447,7 +477,13 @@ public void update(UrlRepository urlRepository) {
Set<String> versions = getVersions();
String toolWithEdition = getToolWithEdition();
logger.info("For tool {} we found the following versions : {}", toolWithEdition, versions);

for (String version : versions) {

if (isTimeoutExpired()) {
break;
}

if (edition.getChild(version) == null) {
try {
UrlVersion urlVersion = edition.getOrCreateChild(version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.devonfw.tools.ide.url.updater;

import java.nio.file.Path;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -53,6 +54,8 @@ public class UpdateManager {

private final UrlRepository urlRepository;

private final Instant expirationTime;

private final List<AbstractUrlUpdater> updaters = Arrays.asList(new AndroidStudioUrlUpdater(), new AwsUrlUpdater(),
new AzureUrlUpdater(), new CobigenUrlUpdater(), new DotNetUrlUpdater(),
new EclipseCppUrlUpdater(), new EclipseJavaUrlUpdater(), new GCloudUrlUpdater(), new GcViewerUrlUpdater(), new GhUrlUpdater(),
Expand All @@ -66,10 +69,12 @@ public class UpdateManager {
* The constructor.
*
* @param pathToRepository the {@link Path} to the {@code ide-urls} repository to update.
* @param expirationTime for GitHub actions url-update job
*/
public UpdateManager(Path pathToRepository) {
public UpdateManager(Path pathToRepository, Instant expirationTime) {

this.urlRepository = UrlRepository.load(pathToRepository);
this.expirationTime = expirationTime;
}

/**
Expand All @@ -79,6 +84,7 @@ public void updateAll() {

for (AbstractUrlUpdater updater : this.updaters) {
try {
updater.setExpirationTime(this.expirationTime);
updater.update(this.urlRepository);
} catch (Exception e) {
logger.error("Failed to update {}", updater.getToolWithEdition(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public void update(UrlRepository urlRepository) {

for (AndroidJsonItem item : items) {
String version = item.getVersion();

if (isTimeoutExpired()) {
break;
}

if (edition.getChild(version) == null) {
try {
UrlVersion urlVersion = edition.getOrCreateChild(version);
Expand Down