Skip to content

Commit

Permalink
Skip node,npm install and bundle when no helium package is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Leemoonsoo committed Mar 15, 2017
1 parent bfa812a commit e8f0686
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Expand Up @@ -51,6 +51,7 @@ public class HeliumVisualizationFactory {
private File tabledataModulePath;
private File visualizationModulePath;
private Gson gson;
private boolean nodeAndNpmInstalled = false;

String bundleCacheKey = "";
File currentBundle;
Expand All @@ -75,11 +76,12 @@ public HeliumVisualizationFactory(File moduleDownloadPath) throws TaskRunnerExce

currentBundle = new File(workingDirectory, "vis.bundle.cache.js");
gson = new Gson();
installNodeAndNpm();
configureLogger();
}

private void installNodeAndNpm() {
void installNodeAndNpm() {
if (nodeAndNpmInstalled) {
return;
}
try {
NPMInstaller npmInstaller = frontEndPluginFactory.getNPMInstaller(getProxyConfig());
npmInstaller.setNpmVersion(NPM_VERSION);
Expand All @@ -88,6 +90,8 @@ private void installNodeAndNpm() {
NodeInstaller nodeInstaller = frontEndPluginFactory.getNodeInstaller(getProxyConfig());
nodeInstaller.setNodeVersion(NODE_VERSION);
nodeInstaller.install();
configureLogger();
nodeAndNpmInstalled = true;
} catch (InstallationException e) {
logger.error(e.getMessage(), e);
}
Expand All @@ -104,6 +108,19 @@ public File bundle(List<HeliumPackage> pkgs) throws IOException {

public synchronized File bundle(List<HeliumPackage> pkgs, boolean forceRefresh)
throws IOException {
if (pkgs == null || pkgs.size() == 0) {
// when no package is selected, simply return an empty file instead of try bundle package
synchronized (this) {
currentBundle.getParentFile().mkdirs();
currentBundle.delete();
currentBundle.createNewFile();
bundleCacheKey = "";
return currentBundle;
}
}

installNodeAndNpm();

// package.json
URL pkgUrl = Resources.getResource("helium/package.json");
String pkgJson = Resources.toString(pkgUrl, Charsets.UTF_8);
Expand Down Expand Up @@ -341,7 +358,7 @@ private String[] getNpmModuleNameAndVersion(HeliumPackage pkg) {
}
}

public synchronized void install(HeliumPackage pkg) throws TaskRunnerException {
synchronized void install(HeliumPackage pkg) throws TaskRunnerException {
String commandForNpmInstallArtifact =
String.format("install %s --fetch-retries=%d --fetch-retry-factor=%d " +
"--fetch-retry-mintimeout=%d", pkg.getArtifact(),
Expand All @@ -354,8 +371,8 @@ private void npmCommand(String args) throws TaskRunnerException {
}

private void npmCommand(String args, Map<String, String> env) throws TaskRunnerException {
installNodeAndNpm();
NpmRunner npm = frontEndPluginFactory.getNpmRunner(getProxyConfig(), DEFAULT_NPM_REGISTRY_URL);

npm.execute(args, env);
}

Expand Down
Expand Up @@ -58,6 +58,11 @@ public void tearDown() throws IOException {

@Test
public void testInstallNpm() throws InstallationException {
assertFalse(new File(tmpDir, "vis/node/npm").isFile());
assertFalse(new File(tmpDir, "vis/node/node").isFile());

hvf.installNodeAndNpm();

assertTrue(new File(tmpDir, "vis/node/npm").isFile());
assertTrue(new File(tmpDir, "vis/node/node").isFile());
}
Expand Down

0 comments on commit e8f0686

Please sign in to comment.