Skip to content

Commit 1ce61f2

Browse files
committed
Add command print
Signed-off-by: Adam Wisniewski <awisniew@us.ibm.com>
1 parent 0c0c3e3 commit 1ce61f2

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/CommandBuilder.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.File;
1616
import java.nio.file.Path;
1717
import java.nio.file.Paths;
18+
1819
import org.eclipse.osgi.util.NLS;
1920

2021
import io.openliberty.tools.eclipse.logging.Trace;
@@ -52,28 +53,28 @@ private CommandBuilder(String projectPath, String pathEnv, boolean isMaven) {
5253
*
5354
* @throws CommandNotFoundException
5455
*/
55-
public static String getMavenCommandLine(String projectPath, String cmdArgs, String pathEnv, boolean printCmd)
56+
public static String getMavenCommandLine(String projectPath, String cmdArgs, String pathEnv)
5657
throws CommandBuilder.CommandNotFoundException {
5758
if (Trace.isEnabled()) {
5859
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { projectPath, cmdArgs });
5960
}
6061
CommandBuilder builder = new CommandBuilder(projectPath, pathEnv, true);
6162
String cmd = builder.getCommand();
62-
String cmdLine = builder.getCommandLineFromArgs(cmd, cmdArgs, printCmd);
63+
String cmdLine = builder.getCommandLineFromArgs(cmd, cmdArgs);
6364
if (Trace.isEnabled()) {
6465
Trace.getTracer().traceExit(Trace.TRACE_TOOLS, cmdLine);
6566
}
6667
return cmdLine;
6768
}
6869

69-
public static String getGradleCommandLine(String projectPath, String cmdArgs, String pathEnv, boolean printCmd)
70+
public static String getGradleCommandLine(String projectPath, String cmdArgs, String pathEnv)
7071
throws CommandBuilder.CommandNotFoundException {
7172
if (Trace.isEnabled()) {
7273
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, new Object[] { projectPath, cmdArgs });
7374
}
7475
CommandBuilder builder = new CommandBuilder(projectPath, pathEnv, false);
7576
String cmd = builder.getCommand();
76-
String cmdLine = builder.getCommandLineFromArgs(cmd, cmdArgs, printCmd);
77+
String cmdLine = builder.getCommandLineFromArgs(cmd, cmdArgs);
7778
if (Trace.isEnabled()) {
7879
Trace.getTracer().traceExit(Trace.TRACE_TOOLS, cmdLine);
7980
}
@@ -150,14 +151,15 @@ private String getCommandFromPreferences() throws IllegalStateException {
150151
String installLocPref = getInstallLocationPreferenceString();
151152
if (installLocPref == null || installLocPref.isBlank() || installLocPref.isEmpty()) {
152153
if (Trace.isEnabled()) {
153-
Trace.getTracer().trace(Trace.TRACE_TOOLS, "The mvn/gradle preference path: " + installLocPref + " was null, blank, or empty");
154+
Trace.getTracer().trace(Trace.TRACE_TOOLS,
155+
"The mvn/gradle preference path: " + installLocPref + " was null, blank, or empty");
154156
}
155157
return null;
156-
}
157-
158+
}
159+
158160
File tempCmdFile = new File(installLocPref + File.separator + "bin" + File.separator + getExecBaseName());
159161
String cmdPathStr = tempCmdFile.getPath();
160-
162+
161163
if (tempCmdFile.exists()) {
162164
if (Trace.isEnabled()) {
163165
Trace.getTracer().trace(Trace.TRACE_TOOLS, "Found mvn/gradle from preference at path: " + cmdPathStr);
@@ -202,20 +204,10 @@ private String getCommandFromPathEnvVar() throws IllegalStateException {
202204
return foundCmd;
203205
}
204206

205-
private String getCommandLineFromArgs(String cmd, String cmdArgs, boolean printCmd) {
207+
private String getCommandLineFromArgs(String cmd, String cmdArgs) {
206208
// Put it all together.
207209
StringBuilder sb = new StringBuilder();
208210
if (cmd != null) {
209-
if (printCmd) {
210-
if (Utils.isWindows()) {
211-
sb.append("/c ");
212-
sb.append("echo && ");
213-
sb.append("echo Liberty Tools running command: " + cmd + " " + cmdArgs);
214-
sb.append(" from directory: " + projectPath + " && ");
215-
} else {
216-
sb.append(" -x ");
217-
}
218-
}
219211
sb.append(cmd).append(" ").append(cmdArgs);
220212
}
221213

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void start(IProject iProject, String parms, String javaHomePath, ILaunch
184184

185185
if (Trace.isEnabled()) {
186186
Trace.getTracer().trace(Trace.TRACE_TOOLS, "The start request was already issued on project " + projectName
187-
+ ". No-op. ProjectTabController: " + processController);
187+
+ ". No-op. ProcessController: " + processController);
188188
}
189189
ErrorHandler.processErrorMessage(NLS.bind(Messages.start_already_issued, projectName), true);
190190
return;
@@ -220,9 +220,9 @@ public void start(IProject iProject, String parms, String javaHomePath, ILaunch
220220
BuildType buildType = project.getBuildType();
221221
if (buildType == Project.BuildType.MAVEN) {
222222
cmd = CommandBuilder.getMavenCommandLine(projectPath, "io.openliberty.tools:liberty-maven-plugin:dev " + startParms,
223-
pathEnv, false);
223+
pathEnv);
224224
} else if (buildType == Project.BuildType.GRADLE) {
225-
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyDev " + startParms, pathEnv, false);
225+
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyDev " + startParms, pathEnv);
226226
} else {
227227
throw new Exception("Unexpected project build type: " + buildType + ". Project " + projectName
228228
+ "does not appear to be a Maven or Gradle built project.");
@@ -284,10 +284,10 @@ public void startInContainer(IProject iProject, String parms, String javaHomePat
284284
if (processController.isProcessStarted(projectName)) {
285285

286286
if (Trace.isEnabled()) {
287-
Trace.getTracer().trace(Trace.TRACE_TOOLS, "The start request was already issued on project " + projectName
288-
+ ". No-op. ProjectTabController: " + processController);
287+
Trace.getTracer().trace(Trace.TRACE_TOOLS, "The start in container request was already issued on project " + projectName
288+
+ ". No-op. ProcessController: " + processController);
289289
}
290-
ErrorHandler.processErrorMessage(NLS.bind(Messages.start_already_issued, projectName), true);
290+
ErrorHandler.processErrorMessage(NLS.bind(Messages.start_container_already_issued, projectName), true);
291291
return;
292292
}
293293

@@ -321,9 +321,9 @@ public void startInContainer(IProject iProject, String parms, String javaHomePat
321321
BuildType buildType = project.getBuildType();
322322
if (buildType == Project.BuildType.MAVEN) {
323323
cmd = CommandBuilder.getMavenCommandLine(projectPath, "io.openliberty.tools:liberty-maven-plugin:devc " + startParms,
324-
pathEnv, true);
324+
pathEnv);
325325
} else if (buildType == Project.BuildType.GRADLE) {
326-
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyDevc " + startParms, pathEnv, true);
326+
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyDevc " + startParms, pathEnv);
327327
} else {
328328
throw new Exception("Unexpected project build type: " + buildType + ". Project " + projectName
329329
+ "does not appear to be a Maven or Gradle built project.");
@@ -716,7 +716,7 @@ public void startDevMode(String cmd, String projectName, String projectPath, Str
716716
envs.add("MAVEN_CONFIG=--log-file " + logFileName);
717717
}
718718

719-
Process process = processController.runProcess(projectName, projectPath, cmd, envs);
719+
Process process = processController.runProcess(projectName, projectPath, cmd, envs, true);
720720

721721
DebugPlugin.newProcess(launch, process, projectName);
722722
}
@@ -768,10 +768,10 @@ private void issueLPStopCommand(String projectName) {
768768
String buildTypeName;
769769
BuildType buildType = project.getBuildType();
770770
if (buildType == Project.BuildType.MAVEN) {
771-
cmd = CommandBuilder.getMavenCommandLine(projectPath, "io.openliberty.tools:liberty-maven-plugin:stop", pathEnv, false);
771+
cmd = CommandBuilder.getMavenCommandLine(projectPath, "io.openliberty.tools:liberty-maven-plugin:stop", pathEnv);
772772
buildTypeName = "Maven";
773773
} else if (buildType == Project.BuildType.GRADLE) {
774-
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyStop", pathEnv, false);
774+
cmd = CommandBuilder.getGradleCommandLine(projectPath, "libertyStop", pathEnv);
775775
buildTypeName = "Gradle";
776776
} else {
777777
throw new Exception("Unexpected project build type: " + buildType + ". Project " + projectName

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/process/ProcessController.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.io.PrintWriter;
18-
import java.util.Arrays;
18+
import java.util.ArrayList;
1919
import java.util.List;
2020
import java.util.Map;
2121
import java.util.concurrent.ConcurrentHashMap;
2222

2323
import io.openliberty.tools.eclipse.logging.Trace;
24+
import io.openliberty.tools.eclipse.utils.Utils;
2425

2526
/**
2627
* Manages the set up running dev mode processes.
@@ -62,11 +63,37 @@ public static ProcessController getInstance() {
6263
*
6364
* @throws IOException
6465
*/
65-
public Process runProcess(String projectName, String projectPath, String command, List<String> envs) throws IOException {
66+
public Process runProcess(String projectName, String projectPath, String command, List<String> envs, boolean printCmd)
67+
throws IOException {
68+
69+
List<String> commandList = new ArrayList<String>();
70+
71+
// Add exec statements and print commands
72+
if (Utils.isWindows()) {
73+
commandList.add("cmd.exe");
74+
commandList.add("/c");
75+
if (printCmd) {
76+
StringBuilder sb = new StringBuilder();
77+
sb.append("echo && ");
78+
sb.append("echo Liberty Tools running command: " + command);
79+
sb.append(" from directory: " + projectPath + " && ");
80+
sb.append(command);
81+
command = sb.toString();
82+
}
83+
84+
} else {
85+
commandList.add("/bin/sh");
86+
if (printCmd) {
87+
commandList.add("-xc");
88+
} else {
89+
commandList.add("-c");
90+
}
91+
}
92+
93+
commandList.add(command);
94+
95+
ProcessBuilder builder = new ProcessBuilder(commandList);
6696

67-
List<String> commandList = Arrays.asList(command.split(" "));
68-
ProcessBuilder builder = new ProcessBuilder();
69-
builder.command(commandList);
7097
builder.directory(new File(projectPath));
7198

7299
// Add environment variables

0 commit comments

Comments
 (0)