Search in sources :

Example 1 with ProcessResult

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);
}
Also used : ProcessResult(org.eclipse.n4js.utils.process.ProcessResult)

Example 2 with ProcessResult

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;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Version(org.eclipse.n4js.utils.Version) ProcessResult(org.eclipse.n4js.utils.process.ProcessResult) File(java.io.File)

Example 3 with ProcessResult

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;
}
Also used : RunConfiguration(org.eclipse.n4js.runner.RunConfiguration) ProcessResult(org.eclipse.n4js.utils.process.ProcessResult)

Example 4 with ProcessResult

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)"));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ProcessResult(org.eclipse.n4js.utils.process.ProcessResult) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 5 with ProcessResult

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
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProcessResult(org.eclipse.n4js.utils.process.ProcessResult) Test(org.junit.Test) AbstractBuilderParticipantTest(org.eclipse.n4js.tests.builder.AbstractBuilderParticipantTest)

Aggregations

ProcessResult (org.eclipse.n4js.utils.process.ProcessResult)15 Test (org.junit.Test)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 AbstractBuilderParticipantTest (org.eclipse.n4js.tests.builder.AbstractBuilderParticipantTest)8 File (java.io.File)3 Version (org.eclipse.n4js.utils.Version)3 RunConfiguration (org.eclipse.n4js.runner.RunConfiguration)2 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1