Skip to content

Commit 88a7aa1

Browse files
committed
Start of adding support for a Windows PowerShell platform 'windows-ps'
1 parent 974ee6c commit 88a7aa1

File tree

9 files changed

+305
-8
lines changed

9 files changed

+305
-8
lines changed

appassembler-maven-plugin/src/it/daemonScriptNameTest/verify.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ class CheckFolder {
3535
// Check the existence of the generated unix script
3636
def unixScriptFile = new File( fileBinFolder, "executable" );
3737
def windowsScriptFile = new File( fileBinFolder, "executable.bat" );
38+
def windowsPsScriptFile = new File( fileBinFolder, "executable.ps" );
3839

3940
if (unixScriptFile.exists()) {
4041
throw new FileNotFoundException("The file " + unixScriptFile + " does not exist.");
4142
}
4243
if (windowsScriptFile.exists()) {
4344
throw new FileNotFoundException("The file " + windowsScriptFile + " does not exist.");
4445
}
46+
if (windowsPsScriptFile.exists()) {
47+
throw new FileNotFoundException("The file " + windowsPsScriptFile + " does not exist.");
48+
}
4549
}
4650
}
4751

appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/daemon/script/DefaultScriptGenerator.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,19 @@ private InputStream getScriptTemplate( String platformName, Daemon daemon )
324324
}
325325
else
326326
{
327-
is = getClass().getResourceAsStream( platformName + "BinTemplate" );
327+
String scriptTemplatePrefix = platformName;
328+
while (true) {
329+
int idx = scriptTemplatePrefix.indexOf('-');
330+
if (idx == -1 || scriptTemplatePrefix.length() < 2) {
331+
break;
332+
}
333+
334+
scriptTemplatePrefix = ( scriptTemplatePrefix.substring( 0, idx )
335+
+ Character.toUpperCase( scriptTemplatePrefix.charAt( idx + 1 ) )
336+
+ scriptTemplatePrefix.substring( idx + 2 ) );
337+
}
338+
339+
is = getClass().getResourceAsStream( scriptTemplatePrefix + "BinTemplate" );
328340
if ( is == null )
329341
{
330342
throw new DaemonGeneratorException( "Unable to load internal template resource: " + platformName

appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/daemon/script/Platform.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public class Platform
6161
*/
6262
public static final String WINDOWS_NAME = "windows";
6363

64+
/**
65+
* Windows Powershell Platform name
66+
*/
67+
public static final String WINDOWS_PS_NAME = "windows-ps";
68+
6469
private static final Map<String, Platform> ALL_PLATFORMS;
6570

6671
private static final String DEFAULT_UNIX_BIN_FILE_EXTENSION = "";
@@ -73,15 +78,20 @@ public class Platform
7378

7479
private boolean isWindows;
7580

81+
private boolean isPowerShell;
82+
83+
private String commentPrefix;
84+
7685
// -----------------------------------------------------------------------
7786
// Static
7887
// -----------------------------------------------------------------------
7988

8089
static
8190
{
8291
ALL_PLATFORMS = new HashMap<String, Platform>();
83-
addPlatform( new Platform( UNIX_NAME, false, DEFAULT_UNIX_BIN_FILE_EXTENSION ) );
84-
addPlatform( new Platform( WINDOWS_NAME, true, DEFAULT_WINDOWS_BIN_FILE_EXTENSION ) );
92+
addPlatform( new Platform( UNIX_NAME, false, false, DEFAULT_UNIX_BIN_FILE_EXTENSION, "# " ) );
93+
addPlatform( new Platform( WINDOWS_NAME, true, false, DEFAULT_WINDOWS_BIN_FILE_EXTENSION, "@REM " ) );
94+
addPlatform( new Platform( WINDOWS_PS_NAME, true, true, ".ps1", "# " ) );
8595
}
8696

8797
private static Platform addPlatform( Platform platform )
@@ -193,13 +203,17 @@ public static Set<Platform> getPlatformSet( List<String> platformList, Set<Platf
193203
//
194204
// -----------------------------------------------------------------------
195205

196-
private Platform( String name, boolean isWindows, String binFileExtension )
206+
private Platform( String name, boolean isWindows, boolean isPowerShell, String binFileExtension, String commentPrefix )
197207
{
198208
this.name = name;
199209

200210
this.isWindows = isWindows;
201211

212+
this.isPowerShell = isPowerShell;
213+
202214
this.binFileExtension = binFileExtension;
215+
216+
this.commentPrefix = commentPrefix;
203217
}
204218

205219
// -----------------------------------------------------------------------
@@ -261,7 +275,7 @@ public String getPathSeparator()
261275
*/
262276
public String getCommentPrefix()
263277
{
264-
return isWindows ? "@REM " : "# ";
278+
return commentPrefix ;
265279
}
266280

267281
public String getNewLine()
@@ -467,9 +481,12 @@ public String getEnvSetup( Daemon daemon, String binFolder )
467481
{
468482
if ( isWindows )
469483
{
470-
String envScriptPath = "\"%BASEDIR%\\" + binFolder + "\\" + envSetupFileName + ".bat\"";
471-
472-
envSetup = "if exist " + envScriptPath + " call " + envScriptPath;
484+
if ( isPowerShell ) {
485+
envSetup = "$setupScript = $PSScriptRoot + \"\\" + envSetupFileName + ".ps1\"; if (Test-Path $setupScript ) { &$setupScript }";
486+
} else {
487+
String envScriptPath = "\"%BASEDIR%\\" + binFolder + "\\" + envSetupFileName + ".bat\"";
488+
envSetup = "if exist " + envScriptPath + " call " + envScriptPath;
489+
}
473490
}
474491
else
475492
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#LICENSE_HEADER#
2+
3+
$baseDir = split-path -parent split-path -parent $MyInvocation.MyCommand.Definition
4+
5+
#ENV_SETUP#
6+
7+
if (-not (Test-Path env:JAVACMD) -Or ( $env:JAVACMD -eq "" )) {
8+
$javaCmd=#JAVA_BINARY#
9+
} else {
10+
$javaCmd=$env:JAVACMD
11+
}
12+
13+
if (-not (Test-Path env:REPO) -Or ( $env:REPO -eq "" )) {
14+
$repo=$env:BASEDIR + "\" + #REPO#
15+
} else {
16+
$repo=$env:REPO
17+
}
18+
19+
$classPath=#CLASSPATH#
20+
21+
if ((Test-Path env:ENDORSED_DIR) -Or ( $env:ENDORSED_DIR -ne "")) {
22+
$classPath = $env:BASEDIR + "\" + $env:ENDORSED_DIR + "\*;" + $classPath;
23+
}
24+
25+
if ((Test-Path env:CLASSPATH_PREFIX) -Or ( $env:CLASSPATH_PREFIX -ne "")) {
26+
$classPath = $env:CLASSPATH_PREFIX + "";" + $classPath;
27+
}
28+
29+
iex $javaCmd $env:JAVA_OPTS #EXTRA_JVM_ARGUMENTS# -classpath $classPath -Dapp.name="#APP_NAME#" -Dapp.repo="$repo" -Dapp.home="$baseDir" -Dbasedir="$baseDir" #MAINCLASS# #APP_ARGUMENTS#$args
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright 2001-2006 The Apache Software Foundation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ----------------------------------------------------------------------------
16+
#
17+
# Copyright (c) 2001-2006 The Apache Software Foundation. All rights
18+
# reserved.
19+
20+
21+
$baseDir = split-path -parent split-path -parent $MyInvocation.MyCommand.Definition
22+
23+
$setupScript = $PSScriptRoot + "\setup.ps1"; if (Test-Path $setupScript ) { &$setupScript }
24+
25+
if (-not (Test-Path env:JAVACMD) -Or ( $env:JAVACMD -eq "" )) {
26+
$javaCmd=java
27+
} else {
28+
$javaCmd=$env:JAVACMD
29+
}
30+
31+
if (-not (Test-Path env:REPO) -Or ( $env:REPO -eq "" )) {
32+
$repo=$env:BASEDIR + "\" + repo
33+
} else {
34+
$repo=$env:REPO
35+
}
36+
37+
$classPath=
38+
39+
if ((Test-Path env:ENDORSED_DIR) -Or ( $env:ENDORSED_DIR -ne "")) {
40+
$classPath = $env:BASEDIR + "\" + $env:ENDORSED_DIR + "\*;" + $classPath;
41+
}
42+
43+
if ((Test-Path env:CLASSPATH_PREFIX) -Or ( $env:CLASSPATH_PREFIX -ne "")) {
44+
$classPath = $env:CLASSPATH_PREFIX + "";" + $classPath;
45+
}
46+
47+
iex $javaCmd $env:JAVA_OPTS Yo dude xyz="%BASEDIR%" -classpath $classPath -Dapp.name="basedir-test" -Dapp.repo="$repo" -Dapp.home="$baseDir" -Dbasedir="$baseDir" foo.Bar $args
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright 2001-2006 The Apache Software Foundation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ----------------------------------------------------------------------------
16+
#
17+
# Copyright (c) 2001-2006 The Apache Software Foundation. All rights
18+
# reserved.
19+
20+
21+
$baseDir = split-path -parent split-path -parent $MyInvocation.MyCommand.Definition
22+
23+
$setupScript = $PSScriptRoot + "\setup.ps1"; if (Test-Path $setupScript ) { &$setupScript }
24+
25+
if (-not (Test-Path env:JAVACMD) -Or ( $env:JAVACMD -eq "" )) {
26+
$javaCmd=java
27+
} else {
28+
$javaCmd=$env:JAVACMD
29+
}
30+
31+
if (-not (Test-Path env:REPO) -Or ( $env:REPO -eq "" )) {
32+
$repo=$env:BASEDIR + "\" + repo
33+
} else {
34+
$repo=$env:REPO
35+
}
36+
37+
$classPath=
38+
39+
if ((Test-Path env:ENDORSED_DIR) -Or ( $env:ENDORSED_DIR -ne "")) {
40+
$classPath = $env:BASEDIR + "\" + $env:ENDORSED_DIR + "\*;" + $classPath;
41+
}
42+
43+
if ((Test-Path env:CLASSPATH_PREFIX) -Or ( $env:CLASSPATH_PREFIX -ne "")) {
44+
$classPath = $env:CLASSPATH_PREFIX + "";" + $classPath;
45+
}
46+
47+
iex $javaCmd $env:JAVA_OPTS Yo dude xyz="%REPO%" -classpath $classPath -Dapp.name="repo-test" -Dapp.repo="$repo" -Dapp.home="$baseDir" -Dbasedir="$baseDir" foo.Bar $args
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright 2001-2006 The Apache Software Foundation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ----------------------------------------------------------------------------
16+
#
17+
# Copyright (c) 2001-2006 The Apache Software Foundation. All rights
18+
# reserved.
19+
20+
21+
$baseDir = split-path -parent split-path -parent $MyInvocation.MyCommand.Definition
22+
23+
$setupScript = $PSScriptRoot + "\setup.ps1"; if (Test-Path $setupScript ) { &$setupScript }
24+
25+
if (-not (Test-Path env:JAVACMD) -Or ( $env:JAVACMD -eq "" )) {
26+
$javaCmd=start /min javaw
27+
} else {
28+
$javaCmd=$env:JAVACMD
29+
}
30+
31+
if (-not (Test-Path env:REPO) -Or ( $env:REPO -eq "" )) {
32+
$repo=$env:BASEDIR + "\" + repo
33+
} else {
34+
$repo=$env:REPO
35+
}
36+
37+
$classPath=
38+
39+
if ((Test-Path env:ENDORSED_DIR) -Or ( $env:ENDORSED_DIR -ne "")) {
40+
$classPath = $env:BASEDIR + "\" + $env:ENDORSED_DIR + "\*;" + $classPath;
41+
}
42+
43+
if ((Test-Path env:CLASSPATH_PREFIX) -Or ( $env:CLASSPATH_PREFIX -ne "")) {
44+
$classPath = $env:CLASSPATH_PREFIX + "";" + $classPath;
45+
}
46+
47+
iex $javaCmd $env:JAVA_OPTS Yo dude -classpath $classPath -Dapp.name="test" -Dapp.repo="$repo" -Dapp.home="$baseDir" -Dbasedir="$baseDir" foo.Bar $args
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright 2001-2006 The Apache Software Foundation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ----------------------------------------------------------------------------
16+
#
17+
# Copyright (c) 2001-2006 The Apache Software Foundation. All rights
18+
# reserved.
19+
20+
21+
$baseDir = split-path -parent split-path -parent $MyInvocation.MyCommand.Definition
22+
23+
$setupScript = $PSScriptRoot + "\setup.ps1"; if (Test-Path $setupScript ) { &$setupScript }
24+
25+
if (-not (Test-Path env:JAVACMD) -Or ( $env:JAVACMD -eq "" )) {
26+
$javaCmd=java
27+
} else {
28+
$javaCmd=$env:JAVACMD
29+
}
30+
31+
if (-not (Test-Path env:REPO) -Or ( $env:REPO -eq "" )) {
32+
$repo=$env:BASEDIR + "\" + repo
33+
} else {
34+
$repo=$env:REPO
35+
}
36+
37+
$classPath=
38+
39+
if ((Test-Path env:ENDORSED_DIR) -Or ( $env:ENDORSED_DIR -ne "")) {
40+
$classPath = $env:BASEDIR + "\" + $env:ENDORSED_DIR + "\*;" + $classPath;
41+
}
42+
43+
if ((Test-Path env:CLASSPATH_PREFIX) -Or ( $env:CLASSPATH_PREFIX -ne "")) {
44+
$classPath = $env:CLASSPATH_PREFIX + "";" + $classPath;
45+
}
46+
47+
iex $javaCmd $env:JAVA_OPTS Yo dude -classpath $classPath -Dapp.name="test-endorsed-lib" -Dapp.repo="$repo" -Dapp.home="$baseDir" -Dbasedir="$baseDir" foo.Bar $args
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ----------------------------------------------------------------------------
2+
# Copyright 2001-2006 The Apache Software Foundation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ----------------------------------------------------------------------------
16+
#
17+
# Copyright (c) 2001-2006 The Apache Software Foundation. All rights
18+
# reserved.
19+
20+
21+
$baseDir = split-path -parent split-path -parent $MyInvocation.MyCommand.Definition
22+
23+
$setupScript = $PSScriptRoot + "\setup.ps1"; if (Test-Path $setupScript ) { &$setupScript }
24+
25+
if (-not (Test-Path env:JAVACMD) -Or ( $env:JAVACMD -eq "" )) {
26+
$javaCmd=java
27+
} else {
28+
$javaCmd=$env:JAVACMD
29+
}
30+
31+
if (-not (Test-Path env:REPO) -Or ( $env:REPO -eq "" )) {
32+
$repo=$env:BASEDIR + "\" + repo
33+
} else {
34+
$repo=$env:REPO
35+
}
36+
37+
$classPath=
38+
39+
if ((Test-Path env:ENDORSED_DIR) -Or ( $env:ENDORSED_DIR -ne "")) {
40+
$classPath = $env:BASEDIR + "\" + $env:ENDORSED_DIR + "\*;" + $classPath;
41+
}
42+
43+
if ((Test-Path env:CLASSPATH_PREFIX) -Or ( $env:CLASSPATH_PREFIX -ne "")) {
44+
$classPath = $env:CLASSPATH_PREFIX + "";" + $classPath;
45+
}
46+
47+
iex $javaCmd $env:JAVA_OPTS Yo dude -classpath $classPath -Dapp.name="test" -Dapp.repo="$repo" -Dapp.home="$baseDir" -Dbasedir="$baseDir" foo.Bar $args

0 commit comments

Comments
 (0)