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);
}
}
}
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());
}
}
Aggregations