Skip to content

Commit

Permalink
Merge pull request #85 from sabre1041/windows
Browse files Browse the repository at this point in the history
Windows support
  • Loading branch information
bserdar authored Jul 30, 2019
2 parents 3bf31f2 + e3eee2b commit 06f490e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jcliff-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export CLASSPATH=$(echo "${JCLIFF_HOME}"/target/jcliff-*.jar)
export JCLIFF_RULES_DIR=${JCLIFF_RULES_DIR:-'./src/main/resources'}
export JCLIFF_DEPS_DIR=${JCLIFF_DEPS_DIR:-'./target/dependency/'}

./src/main/bash/jcliff ${@}
./src/main/scripts/jcliff ${@}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<sources>
<source>
<destination>jcliff</destination>
<location>src/main/bash/jcliff</location>
<location>src/main/scripts/jcliff</location>
</source>
</sources>
</mapping>
Expand Down
3 changes: 2 additions & 1 deletion src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/bash</directory>
<directory>${project.basedir}/src/main/scripts</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>jcliff</include>
<include>jcliff.bat</include>
</includes>
</fileSet>
<fileSet>
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/com/redhat/jcliff/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
*/
package com.redhat.jcliff;

import java.io.InputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.InputStreamReader;

import java.util.List;
import java.util.ArrayList;
Expand All @@ -37,6 +35,7 @@ public class Cli {
private final String password;
private final String timeout;
private final Ctx ctx;
private final Boolean isWindows;

public Cli(String cli,
String controller,
Expand All @@ -50,6 +49,7 @@ public Cli(String cli,
this.password=password;
this.timeout=timeout;
this.ctx=ctx;
this.isWindows=isWindows();
}

public String run(String command) {
Expand Down Expand Up @@ -89,7 +89,6 @@ private static int runAndWait(String[] args,long timeout) throws Exception {
Exec x=new Exec(args);
x.start();
x.join(timeout);

if(x.isAlive())
throw new RuntimeException ("Timeout while waiting for child process to complete");
if(x.exception!=null)
Expand Down Expand Up @@ -148,6 +147,7 @@ public String run(String[] command,long execTimeout) {
writer.write('\n');
}
writer.flush();
writer.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -162,12 +162,24 @@ public String run(String[] command,long execTimeout) {
for(String x:cmdArray)
buf.append(x).append(' ');
FileWriter scw=new FileWriter(scriptFile);
scw.write(buf.toString()+">"+outFile.getAbsolutePath()+" 2>"+errFile.getAbsolutePath());
buf.append(">"+outFile.getAbsolutePath());
buf.append(" ");
buf.append("2>"+errFile.getAbsolutePath());
scw.flush();
scw.write(buf.toString());
scw.close();
ctx.log("Script file:"+scriptFile.getAbsolutePath()+" "+scriptFile.exists());
ctx.log("In file:"+tempFile.getAbsolutePath()+" "+tempFile.exists());

int returnCode=runAndWait(new String[] {"/bin/sh",scriptFile.getAbsolutePath()},execTimeout);
String[] runAndWaitArgs = null;

if(isWindows) {
runAndWaitArgs = new String[]{"cmd.exe", "/c", buf.toString()};
} else {
runAndWaitArgs = new String[] {"/bin/sh","-c", buf.toString()};
}

int returnCode=runAndWait(runAndWaitArgs, execTimeout);



Expand Down Expand Up @@ -205,4 +217,8 @@ private String read(File f) throws Exception {
r.close();
return buf.toString().trim();
}

private Boolean isWindows() {
return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
}
}
File renamed without changes.
60 changes: 60 additions & 0 deletions src/main/scripts/jcliff.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@echo off

setlocal EnableDelayedExpansion

set NOPAUSE=true

if "%JBOSS_HOME%" == "" (
echo No JBOSS_HOME provided. Aborting...
EXIT /b 1
)

if "%JCLIFF_HOME%" == "" (
echo No JCLIFF_HOME provided. Aborting...
EXIT /b 1
)

if not exist "%JCLIFF_HOME%" (
echo Provided JCLIFF_HOME does not exist: %JCLIFF_HOME%
EXIT /b 2
)

set JBOSS_CONTROLLER=%JBOSS_CONTROLLER_HOST%:%JBOSS_CONTROLLER_PORT%

set CONTROLLER=

if not "%JBOSS_CONTROLLER%" == ":" (
set CONTROLLER=--controller=%JBOSS_CONTROLLER%
)

set JBOSS_CLI_TIMEOUT=30000


if "%JCLIFF_RULES_DIR%" == "" (
set JCLIFF_RULES_DIR=%JCLIFF_HOME%\rules
)

if not "%JAVA_HOME%" == "" (
set JAVA=%JAVA_HOME%\bin\java.exe
) else (
For /F "Tokens=*" %%I in ('where java') Do Set JAVA=%%I
)

if not exist "%JAVA%" (
echo Invalid path to Java executable: %JAVA%
EXIT /b 3
)


if "%JCLIFF_DEPS_DIR%" == "" (
set JCLIFF_DEPS_DIR=%JCLIFF_HOME%
)

set CLASSPATH=
for /R %JCLIFF_HOME% %%a in (*.jar) do (
set CLASSPATH=%%a;!CLASSPATH!
)

set CLASSPATH=!CLASSPATH!

call "%JAVA%" -classpath "!CLASSPATH!" com.redhat.jcliff.Main --cli="%JBOSS_HOME%\bin\jboss-cli.bat" %CONTROLLER% --timeout="%JBOSS_CLI_TIMEOUT%" --ruledir="%JCLIFF_RULES_DIR%" %*

0 comments on commit 06f490e

Please sign in to comment.