HeliumBundleFactory { public synchronized File buildPackage(HeliumPackage pkg, boolean rebuild, boolean recopyLocalModule) throws IOException { if (pkg == null) { return null; } String[] moduleNameVersion = getNpmModuleNameAndVersion(pkg); if (moduleNameVersion == null) { logger.warn("Can't get module name and version of package " + pkg.getName()); return null; } String pkgName = pkg.getName(); File bundleDir = getHeliumPackageDirectory(pkgName); File bundleCache = getHeliumPackageBundleCache(pkgName); if (!rebuild && bundleCache.exists() && !bundleCache.isDirectory()) { return bundleCache; } try { installNodeAndNpm(); } catch (TaskRunnerException e) { throw new IOException(e); } if (!heliumLocalRepoDirectory.exists() || !heliumLocalRepoDirectory.isDirectory()) { FileUtils.deleteQuietly(heliumLocalRepoDirectory); FileUtils.forceMkdir(heliumLocalRepoDirectory); } FrontendPluginFactory fpf = new FrontendPluginFactory( bundleDir, nodeInstallationDirectory); String templateWebpackConfig = Resources.toString( Resources.getResource("helium/webpack.config.js"), Charsets.UTF_8); String templatePackageJson = Resources.toString( Resources.getResource("helium/" + PACKAGE_JSON), Charsets.UTF_8); String mainFileName = null; try { mainFileName = downloadPackage(pkg, moduleNameVersion, bundleDir, templateWebpackConfig, templatePackageJson, fpf); } catch (TaskRunnerException e) { throw new IOException(e); } prepareSource(pkg, moduleNameVersion, mainFileName); copyFrameworkModulesToInstallPath(recopyLocalModule); installNodeModules(fpf); File heliumBundle = bundleHeliumPackage(fpf, bundleDir); bundleCache.delete(); FileUtils.moveFile(heliumBundle, bundleCache); return bundleCache; } @Inject  HeliumBundleFactory(ZeppelinConfiguration conf); void buildAllPackages(List<HeliumPackage> pkgs); synchronized File buildPackage(HeliumPackage pkg,
                                        boolean rebuild,
                                        boolean recopyLocalModule);  }
@Test public void bundlePackage() throws IOException, TaskRunnerException { HeliumPackage pkg = new HeliumPackage( HeliumType.VISUALIZATION, "zeppelin-bubblechart", "zeppelin-bubblechart", "zeppelin-bubblechart@0.0.3", "", null, "license", "icon"); File bundle = hbf.buildPackage(pkg, true, true); assertTrue(bundle.isFile()); long lastModified = bundle.lastModified(); bundle = hbf.buildPackage(pkg, false, true); assertEquals(lastModified, bundle.lastModified()); }
@Test public void bundleLocalPackage() throws IOException, TaskRunnerException { URL res = Resources.getResource("helium/webpack.config.js"); String resDir = new File(res.getFile()).getParent(); String localPkg = resDir + "/../../../src/test/resources/helium/vis1"; HeliumPackage pkg = new HeliumPackage( HeliumType.VISUALIZATION, "vis1", "vis1", localPkg, "", null, "license", "fa fa-coffee"); File bundle = hbf.buildPackage(pkg, true, true); assertTrue(bundle.isFile()); }
@Test public void switchVersion() throws IOException, TaskRunnerException { URL res = Resources.getResource("helium/webpack.config.js"); String resDir = new File(res.getFile()).getParent(); HeliumPackage pkgV1 = new HeliumPackage( HeliumType.VISUALIZATION, "zeppelin-bubblechart", "zeppelin-bubblechart", "zeppelin-bubblechart@0.0.3", "", null, "license", "icon"); HeliumPackage pkgV2 = new HeliumPackage( HeliumType.VISUALIZATION, "zeppelin-bubblechart", "zeppelin-bubblechart", "zeppelin-bubblechart@0.0.1", "", null, "license", "icon"); List<HeliumPackage> pkgsV1 = new LinkedList<>(); pkgsV1.add(pkgV1); List<HeliumPackage> pkgsV2 = new LinkedList<>(); pkgsV2.add(pkgV2); File bundle1 = hbf.buildPackage(pkgV1, true, true); File bundle2 = hbf.buildPackage(pkgV2, true, true); assertNotSame(bundle1.lastModified(), bundle2.lastModified()); }