コード例 #1
0
  private MavenExecutionResult doExecute(
      @NotNull final File file,
      @NotNull final List<String> activeProfiles,
      @NotNull final List<String> inactiveProfiles,
      @NotNull final List<String> goals,
      @NotNull final List<String> selectedProjects,
      boolean alsoMake,
      boolean alsoMakeDependents)
      throws RemoteException {
    MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, goals);

    if (!selectedProjects.isEmpty()) {
      request.setRecursive(true);
      request.setSelectedProjects(selectedProjects);
      if (alsoMake && alsoMakeDependents) {
        request.setMakeBehavior(ReactorManager.MAKE_BOTH_MODE);
      } else if (alsoMake) {
        request.setMakeBehavior(ReactorManager.MAKE_MODE);
      } else if (alsoMakeDependents) {
        request.setMakeBehavior(ReactorManager.MAKE_DEPENDENTS_MODE);
      }
    }

    Maven maven = getComponent(Maven.class);
    org.apache.maven.execution.MavenExecutionResult executionResult = maven.execute(request);

    return new MavenExecutionResult(
        executionResult.getProject(), filterExceptions(executionResult.getExceptions()));
  }
コード例 #2
0
ファイル: MavenCli.java プロジェクト: sonatype/maven-demo
  private int execute(CliRequest cliRequest) {
    MavenExecutionResult result = maven.execute(cliRequest.request);

    if (result.hasExceptions()) {
      ExceptionHandler handler = new DefaultExceptionHandler();

      Map<String, String> references = new LinkedHashMap<String, String>();

      MavenProject project = null;

      for (Throwable exception : result.getExceptions()) {
        ExceptionSummary summary = handler.handleException(exception);

        logSummary(summary, references, "", cliRequest.showErrors);

        if (project == null && exception instanceof LifecycleExecutionException) {
          project = ((LifecycleExecutionException) exception).getProject();
        }
      }

      logger.error("");

      if (!cliRequest.showErrors) {
        logger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
      }
      if (!logger.isDebugEnabled()) {
        logger.error("Re-run Maven using the -X switch to enable full debug logging.");
      }

      if (!references.isEmpty()) {
        logger.error("");
        logger.error(
            "For more information about the errors and possible solutions"
                + ", please read the following articles:");

        for (Map.Entry<String, String> entry : references.entrySet()) {
          logger.error(entry.getValue() + " " + entry.getKey());
        }
      }

      if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
        logger.error("");
        logger.error("After correcting the problems, you can resume the build with the command");
        logger.error("  mvn <goals> -rf :" + project.getArtifactId());
      }

      if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(
          cliRequest.request.getReactorFailureBehavior())) {
        logger.info("Build failures were ignored.");

        return 0;
      } else {
        return 1;
      }
    } else {
      return 0;
    }
  }
  @Override
  public void run(PlexusContainer plexusContainer) throws Exception {
    Settings settings = mavenSettingsBuilder.buildSettings();

    File localRepository = new File(settings.getLocalRepository());
    ArtifactRepository artifactRepository =
        new DefaultArtifactRepository(
            "local", localRepository.toURI().toASCIIString(), artifactRepositoryLayout);

    ProfileManager profileManager =
        new DefaultProfileManager(plexusContainer, settings, System.getProperties());

    Method method =
        maven.getClass().getDeclaredMethod("resolveParameters", Settings.class, Properties.class);
    method.setAccessible(true);
    method.invoke(maven, settings, new Properties());

    MavenProject mavenProject =
        mavenProjectBuilder.build(
            new File("c:\\workspace\\AppercutScanner\\pom.xml"),
            artifactRepository,
            profileManager);

    plexusContainer.getLogger().info(mavenProject.toString());

    DependencyNode rootNode =
        dependencyTreeBuilder.buildDependencyTree(
            mavenProject,
            artifactRepository,
            artifactFactory,
            artifactMetadataSource,
            null,
            artifactCollector);

    plexusContainer.getLogger().info("rootNode:\n" + rootNode);
  }
コード例 #4
0
ファイル: MavenSystemImpl.java プロジェクト: sammyt/mvnsh
    private int doExecute(final MavenExecutionRequest request) throws Exception {
      assert request != null;
      assert config != null;

      if (config.isDebug() || config.isShowVersion()) {
        CLIReportingUtils.showVersion(config.getStreams().out);
      }

      //
      // TODO: i18n all of this
      //

      if (request.isShowErrors()) {
        logger.info("Error stack-traces are turned on.");
      }
      if (MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals(request.getGlobalChecksumPolicy())) {
        logger.info("Disabling strict checksum verification on all artifact downloads.");
      } else if (MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals(
          request.getGlobalChecksumPolicy())) {
        logger.info("Enabling strict checksum verification on all artifact downloads.");
      }

      if (log.isDebugEnabled()) {
        log.debug("Executing request: {}", Yarn.render(request, Yarn.Style.MULTI));
      }

      MavenExecutionResult result;
      Maven maven = container.lookup(Maven.class);
      try {
        result = maven.execute(request);
      } finally {
        container.release(maven);
      }

      if (!result.hasExceptions()) {
        return 0;
      }
      // else process exceptions

      ExceptionHandler handler = new DefaultExceptionHandler();
      Map<String, String> references = new LinkedHashMap<String, String>();
      MavenProject project = null;

      for (Throwable exception : result.getExceptions()) {
        ExceptionSummary summary = handler.handleException(exception);

        logSummary(summary, references, "", request.isShowErrors());

        if (project == null && exception instanceof LifecycleExecutionException) {
          project = ((LifecycleExecutionException) exception).getProject();
        }
      }

      logger.error("");

      if (!request.isShowErrors()) {
        logger.error("To see the full stack-trace of the errors, re-run Maven with the -e switch.");
      }
      if (!logger.isDebugEnabled()) {
        logger.error("Re-run Maven using the -X switch to enable full debug logging.");
      }

      if (!references.isEmpty()) {
        logger.error("");
        logger.error(
            "For more information about the errors and possible solutions, please read the following articles:");

        for (Map.Entry<String, String> entry : references.entrySet()) {
          logger.error(entry.getValue() + " " + entry.getKey());
        }
      }

      if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
        logger.error("");
        logger.error("After correcting the problems, you can resume the build with the command");
        logger.error("  mvn <goals> -rf :" + project.getArtifactId());
      }

      if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(request.getReactorFailureBehavior())) {
        logger.info("Build failures were ignored.");
        return 0;
      } else {
        return 1;
      }
    }
コード例 #5
0
  public void execute() throws MojoExecutionException, MojoFailureException {
    // set up derived paths
    forgeDir = new File(outputDir, "forge");
    jarsDir = new File(forgeDir, "mcp/jars");

    // check whether the artifact is already installed
    if (reinstall) {
      getLog().info("reinstall flag set; skipping availability check");
    } else {
      getLog().info("attempting to resolve Forge artifacts");

      if (null != resolveApiArtifact() && null != resolveToolsArtifact()) {
        getLog().info("artifacts are available; skipping installation");
        return;
      } else {
        getLog().info("artifacts not available; continuing installation");
      }
    }

    if (!noExtract) downloadAndExtract();

    if (!forgeDir.isDirectory())
      throw new MojoFailureException("distribution did not extract to the excpected directory");

    // run the install script
    if (!noInstall) {
      getLog().info("running install script");
      try {
        final PythonLauncher launcher = new PythonLauncher(getLog(), forgeDir);

        final int result = launcher.execute(new File(forgeDir, "install.py"));

        if (0 != result) {
          throw new MojoFailureException("install script returned " + result);
        }
      } catch (IOException caught) {
        throw new MojoFailureException("error calling install script", caught);
      }
    }

    // load Minecraft's POM
    final Model minecraft = loadModelFromResouce("minecraft.pom");
    minecraft.setVersion(getMinecraftVersion());

    // figure out Minecraft's dependencies
    {
      getLog().info("detecting Minecraft dependencies");
      final Artifact lwjgl =
          locator.findVersion(new File(jarsDir, "bin/lwjgl.jar"), "org.lwjgl.lwjgl", "lwjgl");

      final Artifact lwjgl_util =
          new DefaultArtifact("org.lwjgl.lwjgl", "lwjgl_util", "jar", lwjgl.getVersion());

      // don't include jinput.jar
      // it's a transitive dependency from LWJGL

      getLog().info("resolving Minecraft dependencies");
      for (Artifact target : new Artifact[] {lwjgl, lwjgl_util}) {
        getLog().info("    " + target);

        final Artifact resolved = resolveRemoteArtifact(target);
        if (null == resolved)
          throw new MojoFailureException("unable to resolve artifact " + target);

        minecraft.addDependency(artifactToDependency(resolved));
      }
    }

    // install Minecraft JAR
    installJar(minecraft, new File(jarsDir, "bin/minecraft.jar"));

    // figure out Forge's dependencies
    // using a Map of coordinates => artifact for deduplication
    // can't use a Set, Artifact#equals() doesn't behave
    final Map<String, Dependency> forgeDeps = new HashMap<String, Dependency>();
    for (File file : (new File(forgeDir, "mcp/lib")).listFiles()) {
      final Artifact artifact = locator.locate(file);
      if (null == artifact)
        throw new MojoFailureException("no artifact found for dependency " + file.getName());

      forgeDeps.put(artifact.toString(), artifactToDependency(artifact));
    }

    // add Minecraft client to Forge dependencies
    {
      final Artifact artifact =
          new DefaultArtifact("net.minecraft", "minecraft", "jar", getMinecraftVersion());
      forgeDeps.put(artifact.toString(), artifactToDependency(artifact));
    }

    // extract the Forge POM
    final File pom = new File(forgeDir, "pom.xml");
    {
      final Model model = loadModelFromResouce("mcforge.pom");
      model.setVersion(getApiDependency().getVersion());
      model.setDependencies(new ArrayList<Dependency>(forgeDeps.values()));
      writeModelToFile(model, pom);
    }

    // execute a build from the Forge POM
    getLog().info("executing POM to package and install artifacts");
    try {
      final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
      requestPopulator.populateDefaults(request);

      request.setPom(pom);
      request.setGoals(Collections.singletonList("install"));

      final MavenExecutionResult result = maven.execute(request);

      // check for startup exceptions
      if (result.hasExceptions())
        throw new MojoFailureException(
            "failed to package and install artifacts", result.getExceptions().get(0));

      // check for build failure
      final BuildSummary summary = result.getBuildSummary(result.getProject());
      if (summary instanceof BuildFailure) {
        throw new MojoFailureException(
            "failed to package and install artifacts", ((BuildFailure) summary).getCause());
      }
    } catch (MojoFailureException caught) {
      throw caught;
    } catch (Exception caught) {
      throw new MojoFailureException("failed to package and install artifacts", caught);
    }
  }