From 10453cc42d275441683600c2dd51ba3dbac89f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Sat, 10 Sep 2016 23:11:25 +0200 Subject: [PATCH] [all] Add the "embedded" CLI option for the SREs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SREs may be embedded into another application. The CLI-Embedded entry in the SRE manifest enables to launch the SRE in embedded mode. This option will enable Janus to be embedded into the SARL product at run-time. Signed-off-by: Stéphane Galland --- .../SARLLaunchConfigurationDelegate.java | 4 ++ .../io/sarl/eclipse/runtime/SREConstants.java | 4 ++ .../eclipse/runtime/StandardSREInstall.java | 4 ++ .../io/sarl/maven/sre/AbstractSREMojo.java | 1 + .../io/sarl/maven/sre/CommandLineOptions.java | 24 +++++++++-- .../src/io/janusproject/Boot.java | 43 +++++++++---------- .../src/io/janusproject/Boot.properties | 1 + .../src/io/janusproject/Boot_fr.properties | 1 + .../eclipse/sre/JanusSREInstall.java | 1 + 9 files changed, 57 insertions(+), 26 deletions(-) diff --git a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/launching/runner/SARLLaunchConfigurationDelegate.java b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/launching/runner/SARLLaunchConfigurationDelegate.java index c52642bff1..c56386fb24 100644 --- a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/launching/runner/SARLLaunchConfigurationDelegate.java +++ b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/launching/runner/SARLLaunchConfigurationDelegate.java @@ -598,6 +598,10 @@ public String getProgramArguments(ILaunchConfiguration configuration) throws Cor assert cliOptions != null; String options = null; + if (this.accessor.isEmbeddedSRE(configuration)) { + options = join(options, cliOptions.get(SREConstants.MANIFEST_CLI_EMBEDDED)); + } + if (this.accessor.getShowLogoFlag(configuration)) { options = join(options, cliOptions.get(SREConstants.MANIFEST_CLI_SHOW_LOGO)); } else { diff --git a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/SREConstants.java b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/SREConstants.java index a88105bc7d..d9c9b04ded 100644 --- a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/SREConstants.java +++ b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/SREConstants.java @@ -100,6 +100,10 @@ public final class SREConstants { */ public static final String MANIFEST_CLI_NO_MORE_OPTION = "CLI-No-More-Option"; //$NON-NLS-1$ + /** Field name for CLI option for marking the SRE as embedded in another application.. + */ + public static final String MANIFEST_CLI_EMBEDDED = "CLI-Embedded"; //$NON-NLS-1$ + /** Attribute name of the SRE's library path (the jar file). */ public static final String XML_LIBRARY_PATH = "libraryPath"; //$NON-NLS-1$ diff --git a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/StandardSREInstall.java b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/StandardSREInstall.java index 965fabb85a..fbb9fe396d 100644 --- a/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/StandardSREInstall.java +++ b/eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/runtime/StandardSREInstall.java @@ -112,6 +112,8 @@ public class StandardSREInstall extends AbstractSREInstall { private String cliNoMoreOption; + private String cliEmbedded; + private String manifestMainClass; private String manifestName; @@ -275,6 +277,7 @@ protected void resolveDirtyFields(boolean forceSettings) { this.cliBootAgentContextID = sarlSection.getValue(SREConstants.MANIFEST_CLI_BOOT_AGENT_CONTEXT_ID); this.cliSreOffline = sarlSection.getValue(SREConstants.MANIFEST_CLI_SRE_OFFLINE); this.cliNoMoreOption = sarlSection.getValue(SREConstants.MANIFEST_CLI_NO_MORE_OPTION); + this.cliEmbedded = sarlSection.getValue(SREConstants.MANIFEST_CLI_EMBEDDED); // // Program arguments final String programArgs = Strings.nullToEmpty(sarlSection.getValue(SREConstants.MANIFEST_PROGRAM_ARGUMENTS)); @@ -535,6 +538,7 @@ public Map getAvailableCommandLineOptions() { putIfNotempty(options, SREConstants.MANIFEST_CLI_BOOT_AGENT_CONTEXT_ID, this.cliBootAgentContextID); putIfNotempty(options, SREConstants.MANIFEST_CLI_SRE_OFFLINE, this.cliSreOffline); putIfNotempty(options, SREConstants.MANIFEST_CLI_NO_MORE_OPTION, this.cliNoMoreOption); + putIfNotempty(options, SREConstants.MANIFEST_CLI_EMBEDDED, this.cliEmbedded); this.optionBuffer = new SoftReference<>(options); } return Collections.unmodifiableMap(options); diff --git a/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/AbstractSREMojo.java b/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/AbstractSREMojo.java index 979ed3c9b2..0522adf894 100644 --- a/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/AbstractSREMojo.java +++ b/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/AbstractSREMojo.java @@ -440,6 +440,7 @@ private void buildManifest(ManifestUpdater updater, String mainClass) { updater.addSREAttribute(SREConstants.MANIFEST_CLI_HIDE_INFO, cmd.getHideInfo()); updater.addSREAttribute(SREConstants.MANIFEST_CLI_SHOW_INFO, cmd.getShowInfo()); updater.addSREAttribute(SREConstants.MANIFEST_CLI_NO_MORE_OPTION, cmd.getNoMoreOption()); + updater.addSREAttribute(SREConstants.MANIFEST_CLI_EMBEDDED, cmd.getEmbedded()); updater.addSREAttribute(SREConstants.MANIFEST_VM_ARGUMENTS, getVmArguments()); updater.addSREAttribute(SREConstants.MANIFEST_PROGRAM_ARGUMENTS, getApplicationArguments()); } diff --git a/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/CommandLineOptions.java b/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/CommandLineOptions.java index dc405fe1d7..1a30be2575 100644 --- a/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/CommandLineOptions.java +++ b/maven/io.sarl.maven.sre/src/main/java/io/sarl/maven/sre/CommandLineOptions.java @@ -58,6 +58,9 @@ public class CommandLineOptions { @Parameter private String offline; + @Parameter + private String embedded; + @Parameter private String noMoreOption = "--"; //$NON-NLS-1$ @@ -78,7 +81,8 @@ public boolean equals(Object obj) { && Objects.equals(getDefaultContextId(), other.getDefaultContextId()) && Objects.equals(getRandomContextId(), other.getRandomContextId()) && Objects.equals(getBootAgentContextId(), other.getBootAgentContextId()) - && Objects.equals(getNoMoreOption(), other.getNoMoreOption()); + && Objects.equals(getNoMoreOption(), other.getNoMoreOption()) + && Objects.equals(getEmbedded(), other.getEmbedded()); } return false; } @@ -86,7 +90,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { return Objects.hash(this.bootAgentContextId, this.defaultContextId, this.hideInfo, this.hideLogo, - this.noMoreOption, this.offline, this.randomContextId, this.showInfo); + this.noMoreOption, this.offline, this.randomContextId, this.showInfo, this.embedded); } /** Replies the command line option for hiding the SRE logo. @@ -239,7 +243,6 @@ public String getNoMoreOption() { return this.noMoreOption; } - /** Change the command line option for indicates that no more option will be present on the rest of the command line. * * @param noMoreOptionCLIOption the command line option. @@ -248,6 +251,21 @@ public void setNoMoreOption(String noMoreOptionCLIOption) { this.noMoreOption = noMoreOptionCLIOption; } + /** Replies the command line option for indicating that the SRE is embedded in another application. + * + * @return the command line option. + */ + public String getEmbedded() { + return this.embedded; + } + + /** Change the command line option for indicating that the SRE is embedded in another application. + * + * @param embeddedCLIOption the command line option. + */ + public void setEmbedded(String embeddedCLIOption) { + this.embedded = embeddedCLIOption; + } /** Put the string representation of the properties of this object into the given buffer. * diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java index 9d3f32f760..a5fefda216 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java @@ -39,6 +39,7 @@ import com.google.inject.Module; import com.hazelcast.logging.LoggingService; import io.janusproject.kernel.Kernel; +import io.janusproject.services.executor.ChuckNorrisException; import io.janusproject.services.network.NetworkConfig; import io.janusproject.util.LoggerCreator; import org.apache.commons.cli.CommandLine; @@ -96,7 +97,7 @@ private Boot() { * @param args - the CLI arguments given to the program. * @return the arguments that are not recognized as CLI options. */ - @SuppressWarnings("checkstyle:cyclomaticcomplexity") + @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) public static String[] parseCommandLine(String[] args) { final CommandLineParser parser = new DefaultParser(); try { @@ -109,6 +110,7 @@ public static String[] parseCommandLine(String[] args) { } boolean noLogo = false; + boolean embedded = false; int verbose = LoggerCreator.toInt(JanusConfig.VERBOSE_LEVEL_VALUE); final Iterator