-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional logging for launcher (#25)
* Adding logging for exceptions in config access and commands via launcher ConfigHelper - new class - defining two static delegate methods for accessing a string config property, with logging for exceptions during config access LaunchHelper - new class - defining a createJob method. This method provides a central implementation for calls that were implemented in both BundleGemRunShortcut and LaunchConfigurationDelegate, both creating a runnable Job spec for the DebugPlugin. - the createJob method will log instead of throwing CoreException, if the process launcher is cancelled during createJob or if the external process exits with a non-zero exit status. ReadaptDebugDelegate - moving two constants to the class scope - using ConfigHelper - using LogHelper to log any exception when launching readapt - updating the launch method signature, logging instead of throwing CoreException BundleGemRunShortcut - using LaunchHelper RubyRunDelegate - using ConfigHelper, LaunchHelper LogHelper - creating a constant for the bundle symbolic name - creating two generic 'log' methods, here used within the 'info', 'error', and additional 'cancelled' methods - adding an 'error' method accepting only a string arg - adding a 'cancelled' method accepting only a string arg This changeset updates previous plugin behaviors. For processes initialized via BundleGemRunShortcut or LaunchConfigurationDelegate, a logging message will be created only on the following events: - exception during process launch - cancellation during process launch - non-zero process exit * Updating patch branch - declaring LOGNAME as a final string * Updating config calls, logging in ReadaptDebugDelegate ReadaptDebugDelegate - Using the getConfigString default value in all calls to getConfigString - joining elements of READAPT_STDIO for log string
- Loading branch information
Showing
6 changed files
with
129 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...largraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/utils/ConfigHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.pyvesb.eclipse_solargraph.utils; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.debug.core.ILaunchConfiguration; | ||
|
||
public class ConfigHelper { | ||
|
||
public static String getConfigString(ILaunchConfiguration configuration, String name) { | ||
return getConfigString(configuration, name, ""); | ||
} | ||
|
||
public static String getConfigString(ILaunchConfiguration configuration, String name, String defaultValue) { | ||
try { | ||
return configuration.getAttribute(name, defaultValue); | ||
} catch (CoreException e) { | ||
LogHelper.error("Unable to access configuration attribute: " + name, e); | ||
return null; | ||
} | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...largraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/utils/LaunchHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.github.pyvesb.eclipse_solargraph.utils; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.core.runtime.jobs.Job; | ||
import org.eclipse.debug.core.DebugPlugin; | ||
import org.eclipse.debug.core.ILaunch; | ||
|
||
public class LaunchHelper { | ||
|
||
|
||
public static Job createJob(ILaunch launch, String command, String workingDirectory) { | ||
return createJob(launch, command, new File(workingDirectory)); | ||
} | ||
|
||
public static Job createJob(ILaunch launch, String command, File workingDirectory) { | ||
String[] absolutePlatformCommand = CommandHelper.getAbsolutePlatformCommand(command); | ||
return Job.create("Running " + command, r -> { | ||
try { | ||
Process process = DebugPlugin.exec(absolutePlatformCommand, workingDirectory); | ||
if (process == null) { | ||
LogHelper.cancelled("Command cancelled: " + command); | ||
return; | ||
} | ||
CompletableFuture<Process> future = process.onExit(); | ||
// initialize a process completion future to log any non-zero process exit | ||
future.defaultExecutor().execute(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
if (process.isAlive()) { | ||
process.waitFor(); | ||
} | ||
} catch (InterruptedException e) { | ||
LogHelper.cancelled("Process monitor interrupted: " + command); | ||
return; | ||
} | ||
int exc = process.exitValue(); | ||
if (exc != 0) { | ||
String msg = String.format("Process exited non-zero (%d): %s ", exc, command); | ||
LogHelper.error(msg); | ||
} | ||
} | ||
|
||
}); | ||
DebugPlugin.newProcess(launch, process, command); | ||
} catch (CoreException e) { | ||
// CoreException from exec | ||
LogHelper.log(Status.ERROR, "Exception when launching process: " + command, e); | ||
return; | ||
} | ||
}); | ||
} | ||
|
||
};; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters