Search in sources :

Example 1 with HeadlessTargetPlatformInstallLocationProvider

use of org.eclipse.n4js.external.HeadlessTargetPlatformInstallLocationProvider in project n4js by eclipse.

the class N4jscBase method cloneGitRepositoryAndInstallNpmPackages.

/**
 * depends on the checks done in {@link #checkTargetPlatformConfigurations}
 */
private void cloneGitRepositoryAndInstallNpmPackages() throws ExitCodeException {
    checkState(installLocationProvider instanceof HeadlessTargetPlatformInstallLocationProvider);
    HeadlessTargetPlatformInstallLocationProvider locationProvider = (HeadlessTargetPlatformInstallLocationProvider) installLocationProvider;
    if (installMissingDependencies) {
        try {
            // pull n4jsd to install location
            java.net.URI gitRepositoryLocation = locationProvider.getTargetPlatformLocalGitRepositoryLocation();
            Path localClonePath = new File(gitRepositoryLocation).toPath();
            hardReset(gitLocationProvider.getGitLocation().getRepositoryRemoteURL(), localClonePath, gitLocationProvider.getGitLocation().getRemoteBranch(), true);
            pull(localClonePath);
            // generate n4tp file for NpmManager to use
            PackageJson packageJson = TargetPlatformFactory.createN4Default();
            java.net.URI platformLocation = locationProvider.getTargetPlatformInstallLocation();
            File packageJsonFile = new File(new File(platformLocation), PackageJson.PACKAGE_JSON);
            try {
                if (!packageJsonFile.exists()) {
                    packageJsonFile.createNewFile();
                }
                try (PrintWriter pw = new PrintWriter(packageJsonFile)) {
                    pw.write(packageJson.toString());
                    pw.flush();
                    locationProvider.setTargetPlatformFileLocation(packageJsonFile.toURI());
                }
            } catch (IOException e) {
                throw new ExitCodeException(EXITCODE_CONFIGURATION_ERROR, "Error while consuming target platform file.", e);
            }
        } catch (Exception e) {
            locationProvider.setTargetPlatformFileLocation(null);
            locationProvider.setTargetPlatformInstallLocation(null);
            if (e instanceof ExitCodeException)
                throw e;
            Throwables.propagateIfPossible(e);
        }
    }
}
Also used : Path(java.nio.file.Path) HeadlessTargetPlatformInstallLocationProvider(org.eclipse.n4js.external.HeadlessTargetPlatformInstallLocationProvider) IOException(java.io.IOException) PackageJson(org.eclipse.n4js.external.libraries.PackageJson) File(java.io.File) N4JSCompileException(org.eclipse.n4js.generator.headless.N4JSCompileException) CmdLineException(org.kohsuke.args4j.CmdLineException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 2 with HeadlessTargetPlatformInstallLocationProvider

use of org.eclipse.n4js.external.HeadlessTargetPlatformInstallLocationProvider in project n4js by eclipse.

the class N4jscBase method checkTargetPlatformConfigurations.

/**
 * Checks state of target platform location is valid. If needed temp location is used. Valid location is saved in
 * {@link TargetPlatformInstallLocationProvider}
 *
 * @throws ExitCodeException
 *             if configuration is inconsistent or cannot be fixed.
 */
private void checkTargetPlatformConfigurations() throws ExitCodeException {
    HeadlessTargetPlatformInstallLocationProvider locationProvider = (HeadlessTargetPlatformInstallLocationProvider) installLocationProvider;
    if (targetPlatformInstallLocation != null) {
        if (!targetPlatformInstallLocation.exists()) {
            try {
                checkState(targetPlatformInstallLocation.mkdirs());
            } catch (Exception e) {
                throw new ExitCodeException(EXITCODE_CONFIGURATION_ERROR, "Target platform install location cannot be created at: " + targetPlatformInstallLocation + ".", e);
            }
        } else {
            if (!targetPlatformInstallLocation.isDirectory()) {
                throw new ExitCodeException(EXITCODE_CONFIGURATION_ERROR, "Target platform install location does not point to a directory at: " + targetPlatformInstallLocation + ".");
            }
            if (!targetPlatformInstallLocation.canWrite()) {
                throw new ExitCodeException(EXITCODE_CONFIGURATION_ERROR, "Target platform install location cannot be accessed at: " + targetPlatformInstallLocation + ".");
            }
            if (clean) {
                try {
                    FileDeleter.delete(targetPlatformInstallLocation);
                } catch (Exception e) {
                    throw new ExitCodeException(EXITCODE_CONFIGURATION_ERROR, "Existing target platform install location cannot be cleared at: " + targetPlatformInstallLocation + ".", e);
                }
                try {
                    checkState(targetPlatformInstallLocation.mkdirs());
                } catch (Exception e) {
                    throw new ExitCodeException(EXITCODE_CONFIGURATION_ERROR, "Target platform install location cannot be created at: " + targetPlatformInstallLocation + ".", e);
                }
            }
        }
        locationProvider.setTargetPlatformInstallLocation(targetPlatformInstallLocation.toURI());
    } else {
        // create temp location
        final Path tempRoot = createTempDirectory("hlcTmpDepsLocation_" + System.currentTimeMillis());
        targetPlatformInstallLocation = tempRoot.toFile();
        locationProvider.setTargetPlatformInstallLocation(tempRoot.toUri());
    }
}
Also used : Path(java.nio.file.Path) HeadlessTargetPlatformInstallLocationProvider(org.eclipse.n4js.external.HeadlessTargetPlatformInstallLocationProvider) N4JSCompileException(org.eclipse.n4js.generator.headless.N4JSCompileException) CmdLineException(org.kohsuke.args4j.CmdLineException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HeadlessTargetPlatformInstallLocationProvider (org.eclipse.n4js.external.HeadlessTargetPlatformInstallLocationProvider)2 N4JSCompileException (org.eclipse.n4js.generator.headless.N4JSCompileException)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 PackageJson (org.eclipse.n4js.external.libraries.PackageJson)1