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

The following examples show how to use com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory. 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: InstallNodeAndYarnMojo.java    From frontend-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(FrontendPluginFactory factory) throws InstallationException {
    ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter);
    Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter);
    if (null != server) {
        factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot)
            .setNodeVersion(this.nodeVersion).setPassword(server.getPassword())
            .setUserName(server.getUsername()).install();
        factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot)
            .setYarnVersion(this.yarnVersion).setUserName(server.getUsername())
            .setPassword(server.getPassword()).install();
    } else {
        factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot)
            .setNodeVersion(this.nodeVersion).install();
        factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot)
            .setYarnVersion(this.yarnVersion).install();
    }
}
 
Example #3
Source File: HeliumBundleFactory.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Inject
public HeliumBundleFactory(ZeppelinConfiguration conf) {
  this.heliumLocalRepoDirectory =
      new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO), HELIUM_LOCAL_REPO);
  this.heliumBundleDirectory = new File(heliumLocalRepoDirectory, HELIUM_BUNDLES_DIR);
  this.heliumLocalModuleDirectory = new File(heliumLocalRepoDirectory, HELIUM_LOCAL_MODULE_DIR);
  this.yarnCacheDir = new File(heliumLocalRepoDirectory, YARN_CACHE_DIR);
  this.defaultNodeInstallerUrl = conf.getHeliumNodeInstallerUrl();
  this.defaultNpmInstallerUrl = conf.getHeliumNpmInstallerUrl();
  this.defaultYarnInstallerUrl = conf.getHeliumYarnInstallerUrl();
  this.nodeInstallationDirectory = this.heliumLocalRepoDirectory;

  this.frontEndPluginFactory =
      new FrontendPluginFactory(heliumLocalRepoDirectory, nodeInstallationDirectory);

  this.gson = new Gson();

  File zeppelinWebPath = new File(conf.getRelativeDir("zeppelin-web"));
  if (!zeppelinWebPath.isDirectory()) {
    this.tabledataModulePath =
        new File(conf.getRelativeDir("lib/node_modules/zeppelin-tabledata"));
    this.visualizationModulePath = new File(conf.getRelativeDir("lib/node_modules/zeppelin-vis"));
    this.spellModulePath = new File(conf.getRelativeDir("lib/node_modules/zeppelin-spell"));
  } else {
    this.tabledataModulePath = new File(conf.getRelativeDir("zeppelin-web/src/app/tabledata"));
    this.visualizationModulePath =
        new File(conf.getRelativeDir("zeppelin-web/src/app/visualization"));
    this.spellModulePath = new File(conf.getRelativeDir("zeppelin-web/src/app/spell"));
  }
}
 
Example #4
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 #5
Source File: NodeManager.java    From wisdom with Apache License 2.0 5 votes vote down vote up
public NodeManager(Log log, File nodeDirectory, AbstractWisdomMojo mojo) {
    this.factory = new FrontendPluginFactory(mojo.basedir, nodeDirectory);
    this.npmInstallationFactory = new FrontendPluginFactory(nodeDirectory, nodeDirectory);
    this.nodeDirectory = nodeDirectory;
    this.mojo = mojo;
    if (!nodeDirectory.exists()) {
        nodeDirectory.mkdirs();
    }
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: InstallNodeAndNpmMojo.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(FrontendPluginFactory factory) throws InstallationException {
    ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter);
    String nodeDownloadRoot = getNodeDownloadRoot();
    String npmDownloadRoot = getNpmDownloadRoot();
    Server server = MojoUtils.decryptServer(serverId, session, decrypter);
    if (null != server) {
        factory.getNodeInstaller(proxyConfig)
            .setNodeVersion(nodeVersion)
            .setNodeDownloadRoot(nodeDownloadRoot)
            .setNpmVersion(npmVersion)
            .setUserName(server.getUsername())
            .setPassword(server.getPassword())
            .install();
        factory.getNPMInstaller(proxyConfig)
            .setNodeVersion(nodeVersion)
            .setNpmVersion(npmVersion)
            .setNpmDownloadRoot(npmDownloadRoot)
            .setUserName(server.getUsername())
            .setPassword(server.getPassword())
            .install();
    } else {
        factory.getNodeInstaller(proxyConfig)
            .setNodeVersion(nodeVersion)
            .setNodeDownloadRoot(nodeDownloadRoot)
            .setNpmVersion(npmVersion)
            .install();
        factory.getNPMInstaller(proxyConfig)
            .setNodeVersion(this.nodeVersion)
            .setNpmVersion(this.npmVersion)
            .setNpmDownloadRoot(npmDownloadRoot)
            .install();
    }
}
 
Example #12
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 #13
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 #14
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;
}
 
Example #15
Source File: NodeManager.java    From wisdom with Apache License 2.0 4 votes vote down vote up
/**
 * @return the factory used for NPM execution.
 */
public FrontendPluginFactory factory() {
    return factory;
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
Source File: NodeManager.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * @return the factory used for NPM installation. This factory sets the working directory to the node installation
 * directory in order to install the NPM in a known location (installation occurs locally, not globally).
 */
public FrontendPluginFactory factoryForNPMInstallation() {
    return npmInstallationFactory;
}
 
Example #23
Source File: AbstractFrontendMojo.java    From frontend-maven-plugin with Apache License 2.0 votes vote down vote up
protected abstract void execute(FrontendPluginFactory factory) throws FrontendException;