com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException Java Examples

The following examples show how to use com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
private synchronized File bundleHeliumPackage(FrontendPluginFactory fpf,
                                             File bundleDir) throws IOException {
  try {
    out.reset();
    logger.info("Bundling helium packages");
    yarnCommand(fpf, "run bundle");
    logger.info("Bundled helium packages");
  } catch (TaskRunnerException e) {
    throw new IOException(new String(out.toByteArray()));
  }

  String bundleStdoutResult = new String(out.toByteArray());
  File heliumBundle = new File(bundleDir, HELIUM_BUNDLE);
  if (!heliumBundle.isFile()) {
    throw new IOException(
            "Can't create bundle: \n" + bundleStdoutResult);
  }

  WebpackResult result = getWebpackResultFromOutput(bundleStdoutResult);
  if (result.errors.length > 0) {
    FileUtils.deleteQuietly(heliumBundle);
    throw new IOException(result.errors[0]);
  }

  return heliumBundle;
}
 
Example #2
Source File: HeliumTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testSaveLoadConf() throws IOException, URISyntaxException, TaskRunnerException {
  // given
  File heliumConf = new File(tmpDir, "helium.conf");
  Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(),
      null, null, null, null);
  assertFalse(heliumConf.exists());

  // when
  helium.saveConfig();

  // then
  assertTrue(heliumConf.exists());

  // then load without exception
  Helium heliumRestored = new Helium(
      heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null, null);
}
 
Example #3
Source File: HeliumBundleFactoryTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
public void bundleErrorPropagation() 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/vis2";

  HeliumPackage pkg =
      new HeliumPackage(
          HeliumType.VISUALIZATION,
          "vis2",
          "vis2",
          localPkg,
          "",
          null,
          "license",
          "fa fa-coffee");
  File bundle = null;
  try {
    bundle = hbf.buildPackage(pkg, true, true);
    // should throw exception
    assertTrue(false);
  } catch (IOException e) {
    assertTrue(e.getMessage().contains("error in the package"));
  }
  assertNull(bundle);
}
 
Example #4
Source File: HeliumBundleFactoryTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: HeliumBundleFactoryTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void downloadPackage() throws TaskRunnerException {
  HeliumPackage pkg =
      new HeliumPackage(
          HeliumType.VISUALIZATION,
          "lodash",
          "lodash",
          "[email protected]",
          "",
          null,
          "license",
          "icon");
  hbf.install(pkg);
  System.out.println(new File(nodeInstallationDir, "/node_modules/lodash"));
  assertTrue(new File(nodeInstallationDir, "/node_modules/lodash").isDirectory());
}
 
Example #6
Source File: HeliumBundleFactoryTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void bundlePackage() throws IOException, TaskRunnerException {
  HeliumPackage pkg =
      new HeliumPackage(
          HeliumType.VISUALIZATION,
          "zeppelin-bubblechart",
          "zeppelin-bubblechart",
          "[email protected]",
          "",
          null,
          "license",
          "icon");
  File bundle = hbf.buildPackage(pkg, true, true);
  assertTrue(bundle.isFile());
  long lastModified = bundle.lastModified();

  // buildBundle again and check if it served from cache
  bundle = hbf.buildPackage(pkg, false, true);
  assertEquals(lastModified, bundle.lastModified());
}
 
Example #7
Source File: NPM.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the NPM registry location.
 *
 * @param node           the node manager
 * @param log            the logger
 * @param npmRegistryUrl the registry url
 */
public static void configureRegistry(NodeManager node, Log log, String npmRegistryUrl) {
    try {
        node.factory().getNpmRunner(node.proxy()).execute("config set registry " + npmRegistryUrl);
    } catch (TaskRunnerException e) {
        log.error("Error during the configuration of NPM registry with the url " + npmRegistryUrl + " - check log", e);
    }
}
 
Example #8
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
void installNodeAndNpm() throws TaskRunnerException {
  if (nodeAndNpmInstalled) {
    return;
  }
  try {
    NodeInstaller nodeInstaller = frontEndPluginFactory
            .getNodeInstaller(getProxyConfig(isSecure(defaultNodeInstallerUrl)));
    nodeInstaller.setNodeVersion(NODE_VERSION);
    nodeInstaller.setNodeDownloadRoot(defaultNodeInstallerUrl);
    nodeInstaller.install();

    NPMInstaller npmInstaller = frontEndPluginFactory
            .getNPMInstaller(getProxyConfig(isSecure(defaultNpmInstallerUrl)));
    npmInstaller.setNpmVersion(NPM_VERSION);
    npmInstaller.setNpmDownloadRoot(defaultNpmInstallerUrl + "/" + NPM_PACKAGE_NAME + "/-/");
    npmInstaller.install();

    YarnInstaller yarnInstaller = frontEndPluginFactory
            .getYarnInstaller(getProxyConfig(isSecure(defaultYarnInstallerUrl)));
    yarnInstaller.setYarnVersion(YARN_VERSION);
    yarnInstaller.setYarnDownloadRoot(defaultYarnInstallerUrl);
    yarnInstaller.install();
    yarnCacheDir.mkdirs();
    String yarnCacheDirPath = yarnCacheDir.getAbsolutePath();
    yarnCommand(frontEndPluginFactory, "config set cache-folder " + yarnCacheDirPath);

    configureLogger();
    nodeAndNpmInstalled = true;
  } catch (InstallationException e) {
    logger.error(e.getMessage(), e);
  }
}
 
Example #9
Source File: NpxMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    File packageJson = new File(workingDirectory, "package.json");
    if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
        ProxyConfig proxyConfig = getProxyConfig();
        factory.getNpxRunner(proxyConfig, getRegistryUrl()).execute(arguments, environmentVariables);
    } else {
        getLog().info("Skipping npm install as package.json unchanged");
    }
}
 
Example #10
Source File: YarnMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    File packageJson = new File(this.workingDirectory, "package.json");
    if (this.buildContext == null || this.buildContext.hasDelta(packageJson)
        || !this.buildContext.isIncremental()) {
        ProxyConfig proxyConfig = getProxyConfig();
        factory.getYarnRunner(proxyConfig, getRegistryUrl()).execute(this.arguments,
            this.environmentVariables);
    } else {
        getLog().info("Skipping yarn install as package.json unchanged");
    }
}
 
Example #11
Source File: NpmMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    File packageJson = new File(workingDirectory, "package.json");
    if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
        ProxyConfig proxyConfig = getProxyConfig();
        factory.getNpmRunner(proxyConfig, getRegistryUrl()).execute(arguments, environmentVariables);
    } else {
        getLog().info("Skipping npm install as package.json unchanged");
    }
}
 
Example #12
Source File: GulpMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    if (shouldExecute()) {
        factory.getGulpRunner().execute(arguments, environmentVariables);

        if (outputdir != null) {
            getLog().info("Refreshing files after gulp: " + outputdir);
            buildContext.refresh(outputdir);
        }
    } else {
        getLog().info("Skipping gulp as no modified files in " + srcdir);
    }
}
 
Example #13
Source File: GruntMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    if (shouldExecute()) {
        factory.getGruntRunner().execute(arguments, environmentVariables);

        if (outputdir != null) {
            getLog().info("Refreshing files after grunt: " + outputdir);
            buildContext.refresh(outputdir);
        }
    } else {
        getLog().info("Skipping grunt as no modified files in " + srcdir);
    }
}
 
Example #14
Source File: WebpackMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    if (shouldExecute()) {
        factory.getWebpackRunner().execute(arguments, environmentVariables);

        if (outputdir != null) {
            getLog().info("Refreshing files after webpack: " + outputdir);
            buildContext.refresh(outputdir);
        }
    } else {
        getLog().info("Skipping webpack as no modified files in " + srcdir);
    }
}
 
Example #15
Source File: EmberMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    if (shouldExecute()) {
        factory.getEmberRunner().execute(arguments, environmentVariables);

        if (outputdir != null) {
            getLog().info("Refreshing files after ember: " + outputdir);
            buildContext.refresh(outputdir);
        }
    } else {
        getLog().info("Skipping ember as no modified files in " + srcdir);
    }
}
 
Example #16
Source File: HeliumBundleFactoryTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@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",
          "[email protected]",
          "",
          null,
          "license",
          "icon");

  HeliumPackage pkgV2 =
      new HeliumPackage(
          HeliumType.VISUALIZATION,
          "zeppelin-bubblechart",
          "zeppelin-bubblechart",
          "[email protected]",
          "",
          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());
}
 
Example #17
Source File: HeliumBundleFactoryTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InstallationException, TaskRunnerException, IOException {
  zeppelinHomePath = System.getProperty(ConfVars.ZEPPELIN_HOME.getVarName());
  System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), "../");

  ZeppelinConfiguration conf = ZeppelinConfiguration.create();
  nodeInstallationDir =
      new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO), HELIUM_LOCAL_REPO);
  hbf = new HeliumBundleFactory(conf);
  hbf.installNodeAndNpm();
  hbf.copyFrameworkModulesToInstallPath(true);
}
 
Example #18
Source File: HeliumTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testRefresh() throws IOException, URISyntaxException, TaskRunnerException {
  File heliumConf = new File(tmpDir, "helium.conf");
  Helium helium = new Helium(
      heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null, null);
  HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
  helium.addRegistry(registry1);

  // when
  registry1.add(new HeliumPackage(
      HeliumType.APPLICATION,
      "name1",
      "desc1",
      "artifact1",
      "className1",
      new String[][]{},
      "",
      ""));

  // then
  assertEquals(1, helium.getAllPackageInfo().size());

  // when
  registry1.add(new HeliumPackage(
      HeliumType.APPLICATION,
      "name2",
      "desc2",
      "artifact2",
      "className2",
      new String[][]{},
      "",
      ""));

  // then
  assertEquals(2, helium.getAllPackageInfo(true, null).size());
}
 
Example #19
Source File: HeliumTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreRegistryInstances() throws IOException, URISyntaxException, TaskRunnerException {
  File heliumConf = new File(tmpDir, "helium.conf");
  Helium helium = new Helium(
      heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null, null);
  HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
  HeliumTestRegistry registry2 = new HeliumTestRegistry("r2", "r2");
  helium.addRegistry(registry1);
  helium.addRegistry(registry2);

  // when
  registry1.add(new HeliumPackage(
      HeliumType.APPLICATION,
      "name1",
      "desc1",
      "artifact1",
      "className1",
      new String[][]{},
      "",
      ""));

  registry2.add(new HeliumPackage(
      HeliumType.APPLICATION,
      "name2",
      "desc2",
      "artifact2",
      "className2",
      new String[][]{},
      "",
      ""));

  // then
  assertEquals(2, helium.getAllPackageInfo().size());
}
 
Example #20
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
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(),
              FETCH_RETRY_COUNT, FETCH_RETRY_FACTOR_COUNT, FETCH_RETRY_MIN_TIMEOUT);
  npmCommand(commandForNpmInstallArtifact);
}
 
Example #21
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private synchronized void installNodeModules(FrontendPluginFactory fpf) throws IOException {
  try {
    out.reset();
    String commandForNpmInstall =
            String.format("install --fetch-retries=%d --fetch-retry-factor=%d " +
                            "--fetch-retry-mintimeout=%d",
                    FETCH_RETRY_COUNT, FETCH_RETRY_FACTOR_COUNT, FETCH_RETRY_MIN_TIMEOUT);
    logger.info("Installing required node modules");
    yarnCommand(fpf, commandForNpmInstall);
    logger.info("Installed required node modules");
  } catch (TaskRunnerException e) {
    throw new IOException(e);
  }
}
 
Example #22
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private void yarnCommand(FrontendPluginFactory fpf,
                         String args, Map<String, String> env) throws TaskRunnerException {
  YarnRunner yarn = fpf.getYarnRunner(
          getProxyConfig(isSecure(defaultNpmInstallerUrl)), defaultNpmInstallerUrl);
  yarn.execute(args, env);
}
 
Example #23
Source File: BowerMojo.java    From frontend-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
protected synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    ProxyConfig proxyConfig = getProxyConfig();
    factory.getBowerRunner(proxyConfig).execute(arguments, environmentVariables);
}
 
Example #24
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private void yarnCommand(FrontendPluginFactory fpf, String args) throws TaskRunnerException {
  yarnCommand(fpf, args, new HashMap<String, String>());
}
 
Example #25
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private void npmCommand(FrontendPluginFactory fpf, String args) throws TaskRunnerException {
  npmCommand(args, new HashMap<String, String>());
}
 
Example #26
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private void npmCommand(String args, Map<String, String> env) throws TaskRunnerException {
  NpmRunner npm = frontEndPluginFactory.getNpmRunner(
          getProxyConfig(isSecure(defaultNpmInstallerUrl)), defaultNpmInstallerUrl);
  npm.execute(args, env);
}
 
Example #27
Source File: JspmMojo.java    From frontend-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
protected synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    factory.getJspmRunner().execute(arguments, environmentVariables);
}
 
Example #28
Source File: KarmaRunMojo.java    From frontend-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
    factory.getKarmaRunner().execute("start " + karmaConfPath, environmentVariables);
}
 
Example #29
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private void npmCommand(String args) throws TaskRunnerException {
  npmCommand(args, new HashMap<String, String>());
}
 
Example #30
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
/**
 * @return main file name of this helium package (relative path)
 */
private String downloadPackage(HeliumPackage pkg, String[] nameAndVersion, File bundleDir,
                              String templateWebpackConfig, String templatePackageJson,
                              FrontendPluginFactory fpf) throws IOException, TaskRunnerException {
  if (bundleDir.exists()) {
    FileUtils.deleteQuietly(bundleDir);
  }
  FileUtils.forceMkdir(bundleDir);

  FileFilter copyFilter = new FileFilter() {
    @Override
    public boolean accept(File pathname) {
      String fileName = pathname.getName();
      if (fileName.startsWith(".") || fileName.startsWith("#") || fileName.startsWith("~")) {
        return false;
      } else {
        return true;
      }
    }
  };

  if (isLocalPackage(pkg)) {
    FileUtils.copyDirectory(
            new File(pkg.getArtifact()),
            bundleDir,
            copyFilter);
  } else {
    // if online package
    String version = nameAndVersion[1];
    File tgz = new File(heliumLocalRepoDirectory, pkg.getName() + "-" + version + ".tgz");
    tgz.delete();

    // wget, extract and move dir to `bundles/${pkg.getName()}`, and remove tgz
    npmCommand(fpf, "pack " + pkg.getArtifact());
    File extracted = new File(heliumBundleDirectory, "package");
    FileUtils.deleteDirectory(extracted);
    List<String> entries = unTgz(tgz, heliumBundleDirectory);
    for (String entry: entries) logger.debug("Extracted " + entry);
    tgz.delete();
    FileUtils.copyDirectory(extracted, bundleDir);
    FileUtils.deleteDirectory(extracted);
  }

  // 1. setup package.json
  File existingPackageJson = new File(bundleDir, "package.json");
  JsonReader reader = new JsonReader(new FileReader(existingPackageJson));
  Map<String, Object> packageJson = gson.fromJson(reader,
          new TypeToken<Map<String, Object>>(){}.getType());
  Map<String, String> existingDeps = (Map<String, String>) packageJson.get("dependencies");
  String mainFileName = (String) packageJson.get("main");

  StringBuilder dependencies = new StringBuilder();
  int index = 0;
  for (Map.Entry<String, String> e: existingDeps.entrySet()) {
    dependencies.append("    \"").append(e.getKey()).append("\": ");
    if (e.getKey().equals("zeppelin-vis") ||
        e.getKey().equals("zeppelin-tabledata") ||
        e.getKey().equals("zeppelin-spell")) {
      dependencies.append("\"file:../../" + HELIUM_LOCAL_MODULE_DIR + "/")
              .append(e.getKey()).append("\"");
    } else {
      dependencies.append("\"").append(e.getValue()).append("\"");
    }

    if (index < existingDeps.size() - 1) {
      dependencies.append(",\n");
    }
    index = index + 1;
  }

  FileUtils.deleteQuietly(new File(bundleDir, PACKAGE_JSON));
  templatePackageJson = templatePackageJson.replaceFirst("PACKAGE_NAME", pkg.getName());
  templatePackageJson = templatePackageJson.replaceFirst("MAIN_FILE", mainFileName);
  templatePackageJson = templatePackageJson.replaceFirst("DEPENDENCIES", dependencies.toString());
  FileUtils.write(new File(bundleDir, PACKAGE_JSON), templatePackageJson);

  // 2. setup webpack.config
  FileUtils.write(new File(bundleDir, "webpack.config.js"), templateWebpackConfig);

  return mainFileName;
}