Пример #1
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...");
    }
  }
Пример #2
0
  @Test
  public void installContainerWithDownload() throws Exception {
    Project project = initializeJavaProject();

    MavenCoreFacet coreFacet = project.getFacet(MavenCoreFacet.class);

    List<Profile> profiles = coreFacet.getPOM().getProfiles();
    for (Profile profile : profiles) {
      System.out.println(profile.getId());
    }
    assertThat(profiles.size(), is(0));

    queueInputLines("JBOSS_AS_MANAGED_4.2.X", "", "19", "10", "", "", "", "", "y", "");
    getShell().execute("arquillian setup");

    assertThat(coreFacet.getPOM().getProfiles().size(), is(1));
    Profile profile = coreFacet.getPOM().getProfiles().get(0);

    assertThat(
        profile.getDependencies(),
        hasItems(
            new DependencyMatcher("arquillian-jbossas-managed-4.2"),
            new DependencyMatcher("jboss-server-manager"),
            new DependencyMatcher("dom4j"),
            new DependencyMatcher("jbossall-client")));

    assertThat(profile.getBuild().getPlugins().size(), is(1));
    assertThat(
        profile.getBuild().getPlugins().get(0).getArtifactId(), is("maven-dependency-plugin"));
  }
Пример #3
0
  @Test
  public void testJacocoCommands() throws Exception {

    Project project = initializeJavaProject();
    Dependency junitDep = new Dependency();
    junitDep.setArtifactId("junit");
    junitDep.setGroupId("junit");
    junitDep.setVersion("4.10");
    junitDep.setScope("test");
    MavenCoreFacet facet = project.getFacet(MavenCoreFacet.class);
    Model pom = facet.getPOM();
    pom.addDependency(junitDep);
    facet.setPOM(pom);

    queueInputLines("");
    // create some simple classes
    getShell().execute("java new-class --package com.test \"public class A {}\"");
    getShell().execute("java new-field \"private int numberA=1;\"");
    getShell().execute("java new-method  \"public int getNumberA(){return numberA;}\"");

    getShell().execute("java new-class --package com.test \"public class B {}\"");
    getShell().execute("java new-field \"private int numberB=2;\"");
    getShell().execute("java new-method  \"public int getNumberB(){return numberB;}\"");

    // create and copy test class
    getShell()
        .execute(
            "java new-class --package com.test \"package com.test; import org.junit.Test;import static org.junit.Assert.*; public class ABTest {}\"");
    getShell()
        .execute(
            "java new-method  \"@Test public void testClasses(){A a = new A();B b = new B();assertEquals(3,a.getNumberA()+b.getNumberB());}\"");
    getShell().execute("cd " + project.getProjectRoot().getFullyQualifiedName());
    getShell().execute("cp src/main/java/com/test/ABTest.java src/test/java/");
    getShell().execute("rm -rf src/main/java/com/test/ABTest.java");

    // run jacoco plugin commands
    getShell().execute("jacoco setup");
    getShell().execute("jacoco run-tests --package com.test");
    queueInputLines("N");
    getShell().execute("jacoco create-report");

    assertTrue(
        "Missing jacoco.exec file!",
        project.getProjectRoot().getChildDirectory("target").getChild("jacoco.exec").exists());
    assertTrue(
        "Missing index.html report file!",
        project
            .getProjectRoot()
            .getChildDirectory("target")
            .getChildDirectory("site")
            .getChildDirectory("jacoco")
            .getChild("index.html")
            .exists());
  }
Пример #4
0
  @Command("set-artifactid")
  public void setArtifactId(
      final PipeOut out,
      @Option(description = "the new artifactId; for example: \"forge-shell\"")
          final String artifactId) {
    Assert.notNull(artifactId, "GroupId must not be empty");

    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

    Model pom = mvn.getPOM();
    pom.setArtifactId(artifactId);
    mvn.setPOM(pom);
    out.println("Set artifactId [ " + artifactId + " ]");
  }
Пример #5
0
  @Command("set-groupid")
  public void setGroupId(
      final PipeOut out,
      @Option(description = "the new groupId; for example: \"org.jboss.forge\"")
          final String groupId) {
    Assert.notNull(groupId, "GroupId must not be empty");

    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

    Model pom = mvn.getPOM();
    pom.setGroupId(groupId);
    mvn.setPOM(pom);
    out.println("Set groupId [ " + groupId + " ]");
  }
Пример #6
0
  @Command("set-version")
  public void setVersion(
      final PipeOut out,
      @Option(description = "the new version; for example: \"1.0.0.Final\"") final String version) {
    Assert.notNull(version, "GroupId must not be empty");

    MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

    Model pom = mvn.getPOM();
    pom.setVersion(version);
    mvn.setPOM(pom);

    out.println("Set version [ " + version + " ]");
  }
  @Override
  public boolean install() {
    if (!this.isInstalled()) {
      for (DirectoryResource folder : this.getSourceFolders()) {
        folder.mkdirs();
      }

      // FIXME WOW this needs to be simplified somehow...
      MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class);
      Model pom = maven.getPOM();
      Build build = pom.getBuild();
      if (build == null) {
        build = new Build();
      }
      List<Plugin> plugins = build.getPlugins();
      Plugin javaSourcePlugin = null;
      for (Plugin plugin : plugins) {
        if ("org.apache.maven.plugins".equals(plugin.getGroupId())
            && "maven-compiler-plugin".equals(plugin.getArtifactId())) {
          javaSourcePlugin = plugin;
        }
      }

      if (javaSourcePlugin == null) {
        javaSourcePlugin = new Plugin();
        // FIXME this should find the most recent version using DependencyResolver
        javaSourcePlugin.setGroupId("org.apache.maven.plugins");
        javaSourcePlugin.setArtifactId("maven-compiler-plugin");
        javaSourcePlugin.setVersion("2.3.2");

        try {
          Xpp3Dom dom =
              Xpp3DomBuilder.build(
                  new ByteArrayInputStream(
                      "<configuration><source>1.6</source><target>1.6</target></configuration>"
                          .getBytes()),
                  "UTF-8");

          javaSourcePlugin.setConfiguration(dom);
        } catch (Exception e) {
          throw new ProjectModelException(e);
        }
      }

      build.addPlugin(javaSourcePlugin);
      pom.setBuild(build);
      maven.setPOM(pom);
    }
    return true;
  }
Пример #8
0
  @Test
  public void testSetupCommand() throws Exception {
    Project project = initializeJavaProject();
    getShell().execute("jacoco setup");
    MavenCoreFacet facet = project.getFacet(MavenCoreFacet.class);
    Model pom = facet.getPOM();
    Profile jacocoProfile = pom.getProfiles().get(0);
    assertEquals("jacoco", jacocoProfile.getId());

    Plugin jacocoPlugin = jacocoProfile.getBuild().getPlugins().get(0);
    assertEquals("jacoco-maven-plugin", jacocoPlugin.getArtifactId());

    PluginExecution exec = jacocoPlugin.getExecutions().get(0);
    assertEquals("prepare-agent", exec.getGoals().get(0));
  }
Пример #9
0
 @Override
 public DirectoryResource getTestResourceFolder() {
   MavenCoreFacet mavenFacet = project.getFacet(MavenCoreFacet.class);
   Build build = mavenFacet.getPOM().getBuild();
   final String resFolderName;
   if (build != null
       && !build.getTestResources().isEmpty()
       && build.getTestResources().get(0).getDirectory() != null) {
     resFolderName = build.getTestResources().get(0).getDirectory();
   } else {
     resFolderName = "src" + File.separator + "test" + File.separator + "resources";
   }
   DirectoryResource projectRoot = project.getProjectRoot();
   return projectRoot.getChildDirectory(resFolderName);
 }
Пример #10
0
  private void installContainer(String container, List<DependencyMatcher> dependencies)
      throws Exception {
    Project project = initializeJavaProject();

    MavenCoreFacet coreFacet = project.getFacet(MavenCoreFacet.class);

    List<Profile> profiles = coreFacet.getPOM().getProfiles();
    for (Profile profile : profiles) {
      System.out.println(profile.getId());
    }
    assertThat(profiles.size(), is(0));

    queueInputLines(
        container, "19", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
        "");
    getShell().execute("arquillian setup");

    assertThat(coreFacet.getPOM().getProfiles().size(), is(1));
    Profile profile = coreFacet.getPOM().getProfiles().get(0);

    for (DependencyMatcher dependency : dependencies) {
      assertThat(profile.getDependencies(), hasItem(dependency));
    }
  }
Пример #11
0
  @Test
  public void configureContainer() throws Exception {
    Project project = initializeJavaProject();

    MavenCoreFacet coreFacet = project.getFacet(MavenCoreFacet.class);

    List<Profile> profiles = coreFacet.getPOM().getProfiles();
    for (Profile profile : profiles) {
      System.out.println(profile.getId());
    }
    assertThat(profiles.size(), is(0));

    queueInputLines("JBOSS_AS_MANAGED_6.X", "", "19", "10", "", "", "", "8", "");
    getShell().execute("arquillian setup");

    queueInputLines("JBOSS_AS_MANAGED_6.X", "2", "8000");
    getShell().execute("arquillian configure-container");

    ResourceFacet facet = project.getFacet(ResourceFacet.class);
    FileResource<?> arquillianXML = facet.getTestResource("arquillian.xml");

    assertThat(arquillianXML, is(notNullValue()));
    assertThat(arquillianXML.exists(), is(true));
  }
  @Command
  public void custom(
      PipeOut out,
      @Option(name = "artifact", required = true) String artifact,
      @Option(name = "group", required = true) String group,
      @Option(name = "version", required = true) String version) {
    final MavenCoreFacet mvnFacet = project.getFacet(MavenCoreFacet.class);

    Model pom = mvnFacet.getPOM();

    org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();

    plugin.setGroupId(group);
    plugin.setArtifactId(artifact);
    plugin.setVersion(version);

    if (pom.getBuild().getPlugins().contains(plugin)) {
      return;
    }

    pom.getBuild().getPlugins().add(plugin);

    mvnFacet.setPOM(pom);
  }
Пример #13
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 + " ]");
    }
  }
Пример #14
0
 @Override
 public boolean isInstalled() {
   MavenCoreFacet mavenFacet = project.getFacet(MavenCoreFacet.class);
   return getSourceFolder().exists() && (mavenFacet != null) && mavenFacet.isInstalled();
 }