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()));
  }
Esempio n. 2
0
  @Override
  public void addMarkers(IResource pomResource, String type, MavenExecutionResult result) {
    SourceLocation defaultSourceLocation = new SourceLocation(1, 0, 0);
    List<MavenProblemInfo> allProblems = new ArrayList<MavenProblemInfo>();

    allProblems.addAll(
        toMavenProblemInfos(pomResource, defaultSourceLocation, result.getExceptions()));

    MavenProject mavenProject = result.getProject();
    DependencyResolutionResult resolutionResult = result.getDependencyResolutionResult();
    if (resolutionResult != null) {
      allProblems.addAll(
          toMavenProblemInfos(
              pomResource, defaultSourceLocation, resolutionResult.getCollectionErrors()));
      for (org.eclipse.aether.graph.Dependency dependency :
          resolutionResult.getUnresolvedDependencies()) {
        List<Exception> exceptions = resolutionResult.getResolutionErrors(dependency);
        if (exceptions != null && exceptions.size() > 0) {
          SourceLocation sourceLocation =
              SourceLocationHelper.findLocation(mavenProject, dependency);
          allProblems.addAll(toMavenProblemInfos(pomResource, sourceLocation, exceptions));
        }
      }
    }

    if (mavenProject != null) {
      addMissingArtifactProblemInfos(mavenProject, defaultSourceLocation, allProblems);
    }

    addErrorMarkers(pomResource, type, allProblems);
  }
  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);
    }
  }