示例#1
0
  @Override
  public boolean install() {
    DependencyFacet deps = project.getFacet(DependencyFacet.class);

    List<Dependency> versions =
        deps.resolveAvailableVersions("org.jboss.forge:forge-shell-api:[,]");
    Dependency version =
        shell.promptChoiceTyped("Install which version of the Forge API?", versions);
    deps.setProperty("forge.api.version", version.getVersion());
    DependencyBuilder apiDep =
        DependencyBuilder.create("org.jboss.forge:forge-shell-api:${forge.api.version}")
            .setScopeType(ScopeType.PROVIDED);
    DependencyBuilder testDep =
        DependencyBuilder.create("org.jboss.forge:forge-test-harness:${forge.api.version}")
            .setScopeType(ScopeType.TEST);
    DependencyBuilder testShellDep =
        DependencyBuilder.create("org.jboss.forge:forge-shell:${forge.api.version}")
            .setScopeType(ScopeType.TEST);

    installer.install(project, apiDep);
    installer.install(project, testDep);
    installer.install(project, testShellDep);
    return true;
  }
示例#2
0
  @Command("set-parent")
  public void setParent(
      @Option(
              name = "parentId",
              description =
                  "dependency identifier of parent, ex: \"org.jboss.forge:forge-parent:1.0.0\"",
              required = false)
          final Dependency gav,
      @Option(
              name = "parentRelativePath",
              description =
                  "relative location from the current project to the parent project root folder",
              type = PromptType.FILE_PATH,
              required = false)
          final String relativePath,
      @Option(
              name = "parentProjectRoot",
              description = "absolute location of a project to use as this project's direct parent",
              required = false)
          final Resource<?> path,
      final PipeOut out) {
    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);
    Parent parent = null;
    if (gav != null) {
      Assert.notNull(
          gav.getArtifactId(), "ArtifactId must not be null [" + gav.toCoordinates() + "]");
      Assert.notNull(gav.getGroupId(), "GroupId must not be null [" + gav.toCoordinates() + "]");
      Assert.notNull(gav.getVersion(), "Version must not be null [" + gav.toCoordinates() + "]");

      parent = new Parent();
      parent.setArtifactId(gav.getArtifactId());
      parent.setGroupId(gav.getGroupId());
      parent.setVersion(gav.getVersion());

      if (relativePath != null) {
        parent.setRelativePath(relativePath);
      }

      Model pom = mvn.getPOM();
      pom.setParent(parent);
      mvn.setPOM(pom);
    } else if ((path != null) && factory.containsProject(path.reify(DirectoryResource.class))) {
      Project parentProject = factory.findProject(path.reify(DirectoryResource.class));
      MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);

      parent = new Parent();
      parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
      parent.setGroupId(parentCore.getMavenProject().getGroupId());
      parent.setVersion(parentCore.getMavenProject().getVersion());

      if (relativePath != null) {
        parent.setRelativePath(relativePath);
      }

      Model pom = mvn.getPOM();
      pom.setParent(parent);
      mvn.setPOM(pom);
    } else if (relativePath != null) {
      PathspecParser parser =
          new PathspecParser(resources, shell.getCurrentProject().getProjectRoot(), relativePath);
      List<Resource<?>> resolvedResources = parser.resolve();
      if (!resolvedResources.isEmpty()
          && factory.containsProject(resolvedResources.get(0).reify(DirectoryResource.class))) {
        Project parentProject =
            factory.findProject(resolvedResources.get(0).reify(DirectoryResource.class));
        MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);

        parent = new Parent();
        parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
        parent.setGroupId(parentCore.getMavenProject().getGroupId());
        parent.setVersion(parentCore.getMavenProject().getVersion());
        parent.setRelativePath(relativePath);

        Model pom = mvn.getPOM();
        pom.setParent(parent);
        mvn.setPOM(pom);
      } else {
        out.print(ShellColor.RED, "***ERROR***");
        out.println(" relative path did not resolve to a Project [" + relativePath + "]");
      }
    } else {
      out.print(ShellColor.RED, "***ERROR***");
      out.println(" you must specify a path to or dependency id of the parent project.");
    }

    if (parent != null) {
      String parentId =
          parent.getGroupId()
              + ":"
              + parent.getArtifactId()
              + ":"
              + parent.getVersion()
              + " ("
              + (parent.getRelativePath() == null ? " " : parent.getRelativePath() + ")");

      out.println("Set parent [ " + parentId + " ]");
    }
  }