use of org.eclipse.n4js.utils.process.ProcessResult in project n4js by eclipse.
the class ProcessExecutionCommandStatus method execute.
/**
* Executes command given by the supplier and returns {@link IStatus} of the execution Provided message will be used
* to create error status if command execution fails.
*/
public IStatus execute(Supplier<ProcessExecutionCommand> commandSupplier, final String msg) {
final ProcessResult per = commandSupplier.get().execute();
if (per.isOK())
return OK_STATUS;
final Throwable cause = per.toThrowable(msg);
if (null != cause)
return statusHelper.createError(cause.getMessage(), cause);
return statusHelper.createError(per.toString(), cause);
}
use of org.eclipse.n4js.utils.process.ProcessResult in project n4js by eclipse.
the class BinariesValidator method validate.
/**
* Validates the availability, accessibility and version of the given binary. Returns with a status representing the
* outcome of the validation process.
*
* @param binary
* the binary to validate.
* @return a status representing the outcome of the validation process.
*/
public IStatus validate(final Binary binary) {
IStatus simpleValidation = validateBinaryFile(binary);
if (!simpleValidation.isOK())
return simpleValidation;
final File file = new File(binary.getBinaryAbsolutePath());
if (!file.canExecute()) {
return error(binary, "Cannot execute '" + binary.getLabel() + "' binary at: " + file + ".");
}
final ProcessResult result = commandFactory.checkBinaryVersionCommand(binary).execute();
if (!result.isOK()) {
return error(binary, "Expected exit code 0 when checking version of '" + binary.getLabel() + "' got " + result.getExitCode() + "' instead.\n" + result.getStdErr());
}
if (LOGGER.isDebugEnabled()) {
final String stdErrString = result.getStdErr();
if (!stdErrString.isEmpty())
LOGGER.debug(stdErrString);
}
final String stdOutString = result.getStdOut();
final Version currentVersion = Version.createFromString(stdOutString.trim());
if (!Version.isValid(currentVersion)) {
return error(binary, "Cannot find current version of '" + binary.getLabel() + "' binary. Output was: " + stdOutString);
} else {
final Version minimumVersion = binary.getMinimumVersion();
if (0 < minimumVersion.compareTo(currentVersion)) {
return error(binary, "The required minimum version of '" + binary.getLabel() + "' is '" + minimumVersion + "'. Currently configured version is '" + currentVersion + "'.");
}
return OK_STATUS;
}
}
use of org.eclipse.n4js.utils.process.ProcessResult in project n4js by eclipse.
the class TestReactExternalLibraryPluginTest method runClient.
private ProcessResult runClient() {
final String pathToModuleToRun = getResourceName(PA, CLIENT_MODULE);
final org.eclipse.emf.common.util.URI moduleToRun = createPlatformResourceURI(pathToModuleToRun, true);
final RunConfiguration config = runnerFrontEnd.createConfiguration(ID, null, moduleToRun);
final Process process = runnerFrontEndUI.runInUI(config);
final ProcessResult result = processExecutor.execute(process, "", OutputRedirection.REDIRECT);
assertTrue("Expected 0 error code for the process. Was: " + result.getExitCode() + "\nError message: " + result.getStdErr(), result.isOK());
return result;
}
use of org.eclipse.n4js.utils.process.ProcessResult in project n4js by eclipse.
the class TestReactExternalLibraryPluginTest method testInstallReactNpmThenRun.
/**
* Imports {@value #PA} project, checks for validation errors, installs {@code React npm} package, checks that
* errors are gone. Then verify that running React/JSX code is successful.
*/
// @Test
public void testInstallReactNpmThenRun() throws Exception {
final File projectsRoot = new File(getResourceUri(PROBANDS, WORKSPACE_LOC));
ProjectTestsUtils.importProject(projectsRoot, PA);
waitForAutoBuild();
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PA);
assertTrue(PA + " project is not accessible.", project.isAccessible());
final IFile clientModule = project.getFile(getResourceName(SRC_FOLDER, PA + "." + N4JSGlobals.N4JSX_FILE_EXTENSION));
assertTrue(clientModule + " client module is not accessible.", clientModule.isAccessible());
final IFile manifest = project.getFile(getResourceName(N4MF_MANIFEST));
assertTrue(manifest + " client module is not accessible.", manifest.isAccessible());
assertMarkers("Expected exactly 5 errors in client module.", clientModule, 5);
assertMarkers("Expected exactly one error in manifest.", manifest, 1);
npmManager.installDependency(PACKAGE_REACT, new NullProgressMonitor());
IResourcesSetupUtil.fullBuild();
waitForAutoBuild();
assertMarkers("Expected exactly zero errors in manifest.", manifest, 0);
assertMarkers("Expected exactly no errors in client module.", clientModule, 0);
final ProcessResult result = runClient();
assertTrue("Unexpected output after running the client module: " + result.getStdOut(), result.getStdOut().contains("Symbol(react.element)"));
}
use of org.eclipse.n4js.utils.process.ProcessResult in project n4js by eclipse.
the class RunExternalLibrariesPluginTest method runClientWithAllClosedWorkspaceProjects.
/**
*/
@Test
public void runClientWithAllClosedWorkspaceProjects() throws CoreException {
for (final String libProjectName : LIB_PROJECT_IDS) {
getProjectByName(libProjectName).close(new NullProgressMonitor());
waitForAutoBuildCheckIndexRigid();
}
final ProcessResult result = runClient();
// @formatter:off
assertEquals("Unexpected output after running the client module: " + result, "External A<init>" + NL + "External B<init>" + NL + "External C<init>" + NL + "External D<init>" + NL, result.getStdOut());
// @formatter:on
}
Aggregations