Пример #1
0
 @Override
 public void addPlugin(MavenPlugin plugin) {
   MavenCoreFacet mavenCoreFacet = project.getFacet(MavenCoreFacet.class);
   Model pom = mavenCoreFacet.getPOM();
   pom.getBuild().addPlugin(new MavenPluginAdapter(plugin));
   mavenCoreFacet.setPOM(pom);
 }
Пример #2
0
  @Command("remove-parent")
  public void removeParent(final PipeOut out) {
    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

    Model pom = mvn.getPOM();
    Parent parent = pom.getParent();

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

      if (shell.promptBoolean(
          "Are you sure you want to remove all parent information from this project? [ "
              + parentId
              + "]",
          false)) {
        out.println("Removed parent [ " + parentId + " ]");
        pom.setParent(null);
        mvn.setPOM(pom);
      } else {
        out.println("Aborted...");
      }
    } else {
      out.println("Nothing to remove...");
    }
  }
Пример #3
0
 @Override
 public void removePlugin(Dependency dependency) {
   MavenCoreFacet mavenCoreFacet = project.getFacet(MavenCoreFacet.class);
   List<Plugin> pomPlugins = mavenCoreFacet.getPOM().getBuild().getPlugins();
   for (Plugin pomPlugin : pomPlugins) {
     if (pomPlugin.getGroupId().equals(dependency.getGroupId())
         && pomPlugin.getArtifactId().equals(dependency.getArtifactId())) {
       Model pom = mavenCoreFacet.getPOM();
       pom.getBuild().removePlugin(pomPlugin);
       mavenCoreFacet.setPOM(pom);
     }
   }
 }
Пример #4
0
  @Override
  public List<MavenPlugin> listConfiguredPlugins() {
    MavenCoreFacet mavenCoreFacet = project.getFacet(MavenCoreFacet.class);
    List<Plugin> pomPlugins = mavenCoreFacet.getPOM().getBuild().getPlugins();
    List<MavenPlugin> plugins = new ArrayList<MavenPlugin>();

    for (Plugin plugin : pomPlugins) {
      MavenPluginAdapter adapter = new MavenPluginAdapter(plugin);
      MavenPluginBuilder pluginBuilder =
          MavenPluginBuilder.create()
              .setDependency(
                  DependencyBuilder.create()
                      .setGroupId(plugin.getGroupId())
                      .setArtifactId(plugin.getArtifactId())
                      .setVersion(plugin.getVersion()))
              .setConfiguration(adapter.getConfig());

      plugins.add(pluginBuilder);
    }

    return plugins;
  }
Пример #5
0
  @Command("set-parent")
  public void setParent(
      @Option(
              name = "parentId",
              description =
                  "dependency identifier of parent, ex: \"org.jboss.seam.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 + " ]");
    }
  }