Skip to content

Commit

Permalink
Merge pull request #571 from bci-oss/allow-start-from-explorer
Browse files Browse the repository at this point in the history
Allow starting samm.exe from explorer/desktop
  • Loading branch information
atextor authored Apr 18, 2024
2 parents 0b47e95 + 34a2dc0 commit a6f47dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ jobs:
unset JAVA_TOOL_OPTIONS
mvn -B clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B verify -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
echo "start cmd /k samm.exe help" > tools/samm-cli/target/start-samm-cli.bat
shell: bash

- name: Upload Windows binary
Expand All @@ -205,7 +203,6 @@ jobs:
name: windows-artifacts
path: |
tools/samm-cli/target/samm.exe
tools/samm-cli/target/*.bat
tools/samm-cli/target/*.dll
tools/samm-cli/target/lib/
Expand Down Expand Up @@ -254,7 +251,7 @@ jobs:
- name: Prepare release
run: |
# Create Windows CLI zip
zip -9 -r samm-cli-${{ github.event.inputs.release_version }}-windows-x86_64.zip samm.exe *.bat *.dll
zip -9 -r samm-cli-${{ github.event.inputs.release_version }}-windows-x86_64.zip samm.exe *.dll
# Full release: Maven Central
# The (apparently) only way to retrieve the staging profile id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ alias samm='java -jar /location/to/samm-cli-{esmf-sdk-version}.jar'
. *For the Windows native executable:*
* *Download*: Download via above link or visit the repository of the Java SDK which contains the SAMM CLI at the Github https://github.com/eclipse-esmf/esmf-sdk/releases[releases page] and download executable file for Windows.
* *Extract*: extract it to a location of your choice.
* *Open* the provided `start-samm-cli.bat`: This will open a command prompt in this directory, where you can enter further `samm` commands.
* *Open* `samm.exe`: This will open a command prompt in this directory, where you can enter further `samm` commands.
* *Input*: Make sure to read the below documentation and provide model files in the correct xref:models-directory-structure[directory structure].

. *For the Linux native executable:*
Expand Down
27 changes: 21 additions & 6 deletions tools/samm-cli/src/main/java/org/eclipse/esmf/SammCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
*/
package org.eclipse.esmf;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.eclipse.esmf.aas.AasCommand;
import org.eclipse.esmf.aspect.AspectCommand;
import org.eclipse.esmf.substitution.IsWindows;

import org.fusesource.jansi.AnsiConsole;
import picocli.CommandLine;
Expand Down Expand Up @@ -87,6 +89,25 @@ int runWithExceptionHandler( final CommandLine.IExecutionExceptionHandler except
}

public static void main( final String[] argv ) {
// Check if the .exe was started on Windows without arguments: Most likely opened from Explorer or Desktop.
// If yes, open a command prompt to continue working instead.
if ( new IsWindows().getAsBoolean() && argv.length == 0 ) {
ProcessHandle.current().info().command().ifPresent( executable -> {
// Only spawn terminals for native executable
if ( !executable.endsWith( "java.exe" ) ) {
try {
final File exeFile = new File( executable );
final String directory = exeFile.getParent();
final String exeFileName = exeFile.getName();
Runtime.getRuntime().exec( "cmd /k cd /d \"" + directory + "\" & start cmd /k " + exeFileName + " help" );
System.exit( 0 );
} catch ( final Exception e ) {
// Ignore, continue as usual
}
}
} );
}

NativeImageHelpers.ensureRequiredEnvironment();

// The disabling color switch needs to be checked before PicoCLI initialization
Expand Down Expand Up @@ -147,10 +168,4 @@ public void run() {
System.out.println( commandLine.getHelp().fullSynopsis() );
System.out.println( format( "Run @|bold " + commandLine.getCommandName() + " help|@ for help." ) );
}

void testProgrammaticConfiguration() {
final CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.create();
spec.usageMessage().footer( "asdf" ).description( "asdf" );
spec.addOption( CommandLine.Model.OptionSpec.builder( "-c" ).type( int.class ).build() );
}
}

0 comments on commit a6f47dc

Please sign in to comment.