This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-feature-launcher-maven-plugin.git
commit b0c8fa05a17844d8a5289889282d3bb02e4ea421 Author: Robert Munteanu <[email protected]> AuthorDate: Thu Jun 25 16:18:23 2020 +0200 SLING-9526 - Allow launching feature model applications in external processes, non-blocking Configurable start timeouts. --- src/it/simple-it/pom.xml | 1 + .../java/org/apache/sling/maven/feature/launcher/Launch.java | 12 ++++++++++++ .../org/apache/sling/maven/feature/launcher/StartMojo.java | 5 ++--- .../org/apache/sling/maven/feature/launcher/LaunchTest.java | 10 ++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/it/simple-it/pom.xml b/src/it/simple-it/pom.xml index 50edf83..c99cc47 100644 --- a/src/it/simple-it/pom.xml +++ b/src/it/simple-it/pom.xml @@ -98,6 +98,7 @@ <org.osgi.service.http.port>${http.port}</org.osgi.service.http.port> </frameworkProperties> </launcherArguments> + <startTimeoutSeconds>180</startTimeoutSeconds> </launch> </launches> <toLaunch> diff --git a/src/main/java/org/apache/sling/maven/feature/launcher/Launch.java b/src/main/java/org/apache/sling/maven/feature/launcher/Launch.java index e691610..a801ad5 100644 --- a/src/main/java/org/apache/sling/maven/feature/launcher/Launch.java +++ b/src/main/java/org/apache/sling/maven/feature/launcher/Launch.java @@ -29,6 +29,7 @@ public class Launch { private String id; private Dependency feature; private LauncherArguments launcherArguments; + private int startTimeoutSeconds = 30; public String getId() { return id; @@ -53,6 +54,14 @@ public class Launch { public void setLauncherArguments(LauncherArguments launcherArguments) { this.launcherArguments = launcherArguments; } + + public int getStartTimeoutSeconds() { + return startTimeoutSeconds; + } + + public void setStartTimeoutSeconds(int startTimeoutSeconds) { + this.startTimeoutSeconds = startTimeoutSeconds; + } public void validate() { if ( id == null || id.trim().isEmpty() ) @@ -61,6 +70,9 @@ public class Launch { if ( !ID_PATTERN.matcher(id).matches() ) throw new IllegalArgumentException("Invalid id '" + id + "'. Allowed characters are digits, numbers, '-','_' and '.'."); + if ( startTimeoutSeconds < 0 ) + throwInvalid("startTimeout value '" + startTimeoutSeconds + "' is negative" ); + if ( feature == null ) throwInvalid("required field 'feature' is missing"); diff --git a/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java b/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java index 04e6a6a..d62789f 100644 --- a/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java +++ b/src/main/java/org/apache/sling/maven/feature/launcher/StartMojo.java @@ -163,11 +163,10 @@ public class StartMojo }; monitor.start(); getLog().info("Waiting for " + launch.getId() + " to start"); - // TODO - configurable timeouts - boolean started = latch.await(3, TimeUnit.MINUTES); + boolean started = latch.await(launch.getStartTimeoutSeconds(), TimeUnit.SECONDS); if ( !started ) { ProcessTracker.stop(process); - throw new MojoExecutionException("Launch " + launch.getId() + " failed to start in the allocated time."); + throw new MojoExecutionException("Launch " + launch.getId() + " failed to start in " + launch.getStartTimeoutSeconds() + " seconds."); } processes.startTracking(launch.getId(), process); diff --git a/src/test/java/org/apache/sling/maven/feature/launcher/LaunchTest.java b/src/test/java/org/apache/sling/maven/feature/launcher/LaunchTest.java index 4450b96..e512d13 100644 --- a/src/test/java/org/apache/sling/maven/feature/launcher/LaunchTest.java +++ b/src/test/java/org/apache/sling/maven/feature/launcher/LaunchTest.java @@ -82,4 +82,14 @@ public class LaunchTest { launch.validate(); } + @Test(expected = IllegalArgumentException.class) + public void invalidLaunch_negativeTimeout() { + + Launch launch = new Launch(); + launch.setId("feature"); + launch.setFeature(validDep); + launch.setStartTimeoutSeconds(-10); + launch.validate(); + } + }
