@Test
  @Ignore("FORGE-894")
  public void testDependencyResolution() throws FileNotFoundException, FacetNotFoundException {
    Project project = projectFactory.createTempProject();
    project.getRoot().reify(DirectoryResource.class).deleteOnExit();

    MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
    metadataFacet.setProjectName("testproject");
    metadataFacet.setProjectVersion("1.0.0-SNAPSHOT");
    metadataFacet.setProjectGroupName("com.acme.testproject");

    configurator.setupComplexAddonProject(project, Collections.<AddonId>emptyList());

    Resource<?> projectRoot = project.getRoot();

    Assert.assertTrue("SPI module is missing", projectRoot.getChild("spi").exists());
    Assert.assertTrue("TESTS module is missing", projectRoot.getChild("tests").exists());

    Project spiProject = projectFactory.findProject(projectRoot.getChild("spi"));
    Project testsProject = projectFactory.findProject(projectRoot.getChild("tests"));

    Dependency spiDependency =
        DependencyBuilder.create(spiProject.getFacet(MetadataFacet.class).getOutputDependency())
            .setClassifier(FORGE_ADDON_CLASSIFIER);
    Assert.assertNotNull(
        "SPI module is not present in the TESTS module",
        testsProject.getFacet(DependencyFacet.class).getEffectiveDependency(spiDependency));
    Assert.assertEquals(
        "compile",
        testsProject
            .getFacet(DependencyFacet.class)
            .getEffectiveDependency(spiDependency)
            .getScopeType());
  }
  public static void main(String[] args) throws Exception {
    Furnace furnace = startFurnace();
    try {
      AddonRegistry addonRegistry = furnace.getAddonRegistry();
      ProjectFactory projectFactory = addonRegistry.getServices(ProjectFactory.class).get();
      ResourceFactory resourceFactory = addonRegistry.getServices(ResourceFactory.class).get();

      // Create a temporary directory as an example
      File underlyingResource = OperatingSystemUtils.getTempDirectory();

      Resource<File> projectDir = resourceFactory.create(underlyingResource);

      // This could return more than one provider, but since the maven addon is the only one
      // deployed, this is ok
      ProjectProvider projectProvider = addonRegistry.getServices(ProjectProvider.class).get();

      // Creating WAR project
      JavaWebProjectType javaWebProjectType =
          addonRegistry.getServices(JavaWebProjectType.class).get();
      Project project =
          projectFactory.createProject(
              projectDir, projectProvider, javaWebProjectType.getRequiredFacets());

      // Changing metadata
      MetadataFacet facet = project.getFacet(MetadataFacet.class);
      facet.setProjectName("my-demo-project");
      facet.setProjectVersion("1.0.0-SNAPSHOT");
      facet.setTopLevelPackage("com.mycompany.project");

      System.out.println("### Project Created in: " + project);
    } finally {
      furnace.stop();
    }
  }
  @Test
  public void testContainsProject() {
    Project project = projectFactory.createTempProject();
    Assert.assertNotNull(project);
    Resource<?> projectRoot = project.getRoot();
    Assert.assertTrue(projectFactory.containsProject(projectRoot, projectRoot));
    Assert.assertTrue(projectFactory.containsProject(projectRoot, projectRoot.getChild("src")));

    projectRoot.delete(true);

    Assert.assertFalse(projectFactory.containsProject(projectRoot, projectRoot));
  }
Exemple #4
0
 @Before
 public void setup() throws Exception {
   project = projectFactory.createTempProject();
   commandController =
       testHarness.createCommandController(GitSetupCommand.class, project.getRoot());
   commandController.initialize();
 }
  @Before
  public void setup() throws Exception {
    AddonRegistry addonRegistry =
        SimpleContainer.getFurnace(getClass().getClassLoader()).getAddonRegistry();
    this.projectFactory = addonRegistry.getServices(ProjectFactory.class).get();
    this.testHarness = addonRegistry.getServices(UITestHarness.class).get();
    project = projectFactory.createTempProject();
    CommandController gitSetupCommandTester =
        testHarness.createCommandController(GitSetupCommand.class, project.getRoot());
    gitSetupCommandTester.initialize();
    gitSetupCommandTester.execute();

    CommandController gitIgnoreSetupTester =
        testHarness.createCommandController(GitIgnoreSetupCommand.class, project.getRoot());
    gitIgnoreSetupTester.initialize();
    gitIgnoreSetupTester.setValueFor("templateRepoDir", getCloneDir());
    gitIgnoreSetupTester.execute();

    Resource<?> cloneDir = getCloneDir();
    boolean templateFound = false;
    for (Resource<?> resource : cloneDir.listResources()) {
      if (resource.getName().endsWith(".gitignore")) {
        templateFound = true;
        break;
      }
    }
    assertTrue(templateFound);
  }
  @Test
  public void testCreateEnum() throws Exception {
    Project project = projectFactory.createTempProject();
    facetFactory.install(project, JavaSourceFacet.class);
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    JavaEnumSource javaEnum =
        Roaster.parse(
            JavaEnumSource.class, "package org.jboss.forge.test; public enum CreditCardType{}");
    facet.saveJavaSource(javaEnum);

    JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
    Assert.assertNotNull(javaResource);
    Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaEnum.class)));

    CommandController controller =
        testHarness.createCommandController(JavaAddEnumConstantCommand.class, javaResource);
    controller.initialize();
    controller.setValueFor("named", "VISA");
    Assert.assertTrue(controller.isValid());
    Assert.assertTrue(controller.canExecute());
    Result result = controller.execute();
    Assert.assertThat(result, is(not(instanceOf(Failed.class))));

    javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
    JavaEnumSource enumClass = javaResource.getJavaType();
    List<EnumConstantSource> enumConstants = enumClass.getEnumConstants();
    Assert.assertEquals(1, enumConstants.size());

    Assert.assertEquals("VISA", enumConstants.get(0).getName());
  }
  @Test
  public void testAddDependencyWithDifferentScopeThenManaged() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      installer.installManaged(project, DEPENDENCY);

      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));

      try (CommandController command =
          testHarness.createCommandController(AddDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", COORDINATES + ":test");
        command.execute();
      }
      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));

      Dependency dependency =
          project
              .getFacet(DependencyFacet.class)
              .getDirectDependency(DependencyBuilder.create(COORDINATES));
      Assert.assertEquals("test", dependency.getScopeType());
    } finally {
      project.getRoot().delete(true);
    }
  }
  @Test
  public void testHasManagedDependencyReturnFailureOnSomeFound() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      installer.installManaged(project, DEPENDENCY);

      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));

      try (CommandController command =
          testHarness.createCommandController(
              HasManagedDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", Arrays.asList(COORDINATES, COORDINATES2));
        Result result = command.execute();
        Assert.assertTrue(result instanceof Failed);
      }
    } finally {
      project.getRoot().delete(true);
    }
  }
  @Test
  public void testContainsProjectWithBuildSystem() {
    ProjectProvider buildSystem = buildSystems.get();
    try {
      Project project = projectFactory.createTempProject(buildSystem);
      Assert.assertNotNull(project);
      Resource<?> projectRoot = project.getRoot();
      Assert.assertTrue(projectFactory.containsProject(projectRoot, projectRoot, buildSystem));
      Assert.assertTrue(
          projectFactory.containsProject(projectRoot, projectRoot.getChild("src"), buildSystem));

      projectRoot.delete(true);
      Assert.assertFalse(projectFactory.containsProject(projectRoot, projectRoot, buildSystem));
    } finally {
      buildSystems.release(buildSystem);
    }
  }
 @Test
 public void testProjectListener() throws Exception {
   final AtomicBoolean projectSet = new AtomicBoolean(false);
   ListenerRegistration<ProjectListener> registration =
       projectFactory.addProjectListener(
           new ProjectListener() {
             @Override
             public void projectCreated(Project project) {
               projectSet.set(true);
             }
           });
   Assert.assertNotNull("Should not have returned a null listener registration", registration);
   Project project = projectFactory.createTempProject();
   registration.removeListener();
   Assert.assertNotNull(project);
   Assert.assertTrue("Listener was not called", projectSet.get());
 }
 @Test
 public void testCreateTempProjectWithFacets() {
   Project project =
       projectFactory.createTempProject(
           Arrays.<Class<? extends ProjectFacet>>asList(WebResourcesFacet.class));
   Assert.assertNotNull(project);
   Assert.assertTrue(project.hasFacet(WebResourcesFacet.class));
 }
 @Test
 public void testCreateTempProjectWithBuildSystem() throws Exception {
   ProjectProvider buildSystem = buildSystems.get();
   try {
     Project project = projectFactory.createTempProject(buildSystem);
     Assert.assertNotNull(project);
   } finally {
     buildSystems.release(buildSystem);
   }
 }
Exemple #13
0
 @Test
 public void testConfigListInProject() throws Exception {
   Project project = projectFactory.createTempProject();
   Configuration projectConfig = project.getFacet(ConfigurationFacet.class).getConfiguration();
   addPropsToProjectConfig(projectConfig);
   test.getShell().setCurrentResource(project.getRoot());
   test.execute("config-list", 15, TimeUnit.SECONDS);
   assertThat(test.getStdOut(), containsString("key2=project: [projectValue2]"));
   assertThat(test.getStdOut(), containsString("key3=project: [projectValue3]"));
 }
Exemple #14
0
 @Test
 public void testConfigSetPropertyListInProject() throws Exception {
   Project project = projectFactory.createTempProject();
   test.getShell().setCurrentResource(project.getRoot());
   test.execute("config-set --key key2 --value projectValue2 --local", 15, TimeUnit.SECONDS);
   test.execute("config-set --key key3 --value projectValue3 --local", 15, TimeUnit.SECONDS);
   assertFalse(test.execute("config-list", 15, TimeUnit.SECONDS) instanceof Failed);
   assertThat(test.getStdOut(), containsString("key2=project: [projectValue2]"));
   assertThat(test.getStdOut(), containsString("key3=project: [projectValue3]"));
 }
Exemple #15
0
 @Override
 public Result execute(final UIExecutionContext context) throws Exception {
   JavaEESpecFacet chosen = javaEEVersion.getValue();
   if (facetFactory.install(getSelectedProject(context.getUIContext()), chosen)) {
     // This facet may activate other facets, so better invalidate the cache
     projectFactory.invalidateCaches();
     return Results.success("JavaEE " + chosen.getSpecVersion() + " has been installed.");
   }
   return Results.fail("Could not install JavaEE " + chosen.getSpecVersion());
 }
Exemple #16
0
  @Test
  public void testCatCommand() throws Exception {
    Project project = projectFactory.createTempProject();
    File target = new File(project.getRoot().getFullyQualifiedName(), "test.java");
    target.createNewFile();

    FileResource<?> source = project.getRoot().getChild(target.getName()).reify(FileResource.class);
    source.setContents("public void test() {}");

    shellTest.execute("cat " + source.getFullyQualifiedName(), 5, TimeUnit.SECONDS);
    Assert.assertThat(shellTest.getStdOut(), CoreMatchers.containsString("test()"));
  }
  @Test
  public void testFindProject() throws Exception {
    Project project = projectFactory.createTempProject();

    Assert.assertNotNull(project);
    Assert.assertNotNull(projectFactory.findProject(project.getRoot()));
    Assert.assertNull(
        projectFactory.findProject(
            project.getRoot(),
            new Predicate<Project>() {
              @Override
              public boolean accept(Project type) {
                return false;
              }
            }));

    Assert.assertNotNull(
        projectFactory.findProject(
            project.getRoot().reify(DirectoryResource.class).getChildDirectory("src/main/java")));

    project.getRoot().delete(true);
  }
 @Test
 public void testCreateTempProjectWithBuildSystemAndFacets() {
   ProjectProvider buildSystem = buildSystems.get();
   try {
     Project project =
         projectFactory.createTempProject(
             buildSystem, Arrays.<Class<? extends ProjectFacet>>asList(WebResourcesFacet.class));
     Assert.assertNotNull(project);
     Assert.assertTrue(project.hasFacet(WebResourcesFacet.class));
   } finally {
     buildSystems.release(buildSystem);
   }
 }
Exemple #19
0
  @Test
  public void testCatColoredCommand() throws Exception {
    Project project = projectFactory.createTempProject();
    File target = new File(project.getRoot().getFullyQualifiedName(), "test.java");
    target.createNewFile();

    FileResource<?> source = project.getRoot().getChild(target.getName()).reify(FileResource.class);
    source.setContents("public void test() {}");

    shellTest.execute("cat " + source.getFullyQualifiedName() + " --color", 5, TimeUnit.SECONDS);
    // the string should be colors, so there are color codes between the statements
    Assert.assertThat(
        shellTest.getStdOut(), CoreMatchers.not(CoreMatchers.containsString("public void")));
  }
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    Result result = Results.success("Project named '" + named.getValue() + "' has been created.");
    DirectoryResource directory = targetLocation.getValue();
    DirectoryResource targetDir = directory.getChildDirectory(named.getValue());

    if (targetDir.mkdirs() || overwrite.getValue()) {
      ProjectType value = type.getValue();

      Project project = null;
      if (value != null) {
        project =
            projectFactory.createProject(
                targetDir, buildSystem.getValue(), value.getRequiredFacets());
      } else {
        project = projectFactory.createProject(targetDir, buildSystem.getValue());
      }

      if (project != null) {
        UIContext uiContext = context.getUIContext();
        MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
        metadataFacet.setProjectName(named.getValue());
        metadataFacet.setProjectVersion(version.getValue());
        metadataFacet.setTopLevelPackage(topLevelPackage.getValue());

        if (finalName.hasValue()) {
          PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);
          packagingFacet.setFinalName(finalName.getValue());
        }

        uiContext.setSelection(project.getRoot());
        uiContext.getAttributeMap().put(Project.class, project);
      } else result = Results.fail("Could not create project of type: [" + value + "]");
    } else result = Results.fail("Could not create target location: " + targetDir);

    return result;
  }
  @Test
  public void testRemoveManagedDependencies() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      installer.install(project, DEPENDENCY);
      installer.install(project, DEPENDENCY2);

      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));

      try (CommandController command =
          testHarness.createCommandController(
              RemoveManagedDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", Arrays.asList(DEPENDENCY, DEPENDENCY2));
        command.setValueFor("removeUnmanaged", "false");
        command.execute();
      }

      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));
    } finally {
      project.getRoot().delete(true);
    }
  }
  @Test
  public void testAddDependency() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));

      try (CommandController command =
          testHarness.createCommandController(AddDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", COORDINATES);
        command.execute();
      }

      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));
    } finally {
      project.getRoot().delete(true);
    }
  }
 @Test
 public void testProjectListenerExportedService() {
   Project project = projectFactory.createTempProject();
   Assert.assertNotNull(project);
   Assert.assertSame(project, MockProjectListener.project);
 }
 @Test
 public void testCreateTempProject() {
   Project project = projectFactory.createTempProject();
   Assert.assertNotNull(project);
   Assert.assertFalse(project.hasFacet(WebResourcesFacet.class));
 }
Exemple #25
0
 public Project refreshProject(Project project) {
   return projectFactory.findProject(project.getRoot(), mavenBuildSystem);
 }
  @Test
  public void testComplexAddonProject() throws FileNotFoundException, FacetNotFoundException {
    Project project = projectFactory.createTempProject();
    project.getRoot().reify(DirectoryResource.class).deleteOnExit();

    MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
    metadataFacet.setProjectName("testproject");
    metadataFacet.setProjectVersion("1.0.0-SNAPSHOT");
    metadataFacet.setProjectGroupName("com.acme.testproject");

    Version furnaceVersion = furnace.getVersion();
    configurator.setupComplexAddonProject(project, Collections.<AddonId>emptyList());
    Assert.assertTrue(project.hasFacet(AddonParentFacet.class));
    Assert.assertTrue(project.hasFacet(JavaCompilerFacet.class));
    Assert.assertFalse(project.hasFacet(JavaSourceFacet.class));
    Assert.assertFalse(project.hasFacet(CDIFacet.class));
    Assert.assertFalse(project.hasFacet(ResourcesFacet.class));
    Resource<?> projectRoot = project.getRoot();

    Assert.assertTrue("ADDON module is missing", projectRoot.getChild("addon").exists());
    Assert.assertTrue("API module is missing", projectRoot.getChild("api").exists());
    Assert.assertTrue("IMPL module is missing", projectRoot.getChild("impl").exists());
    Assert.assertTrue("SPI module is missing", projectRoot.getChild("spi").exists());
    Assert.assertTrue("TESTS module is missing", projectRoot.getChild("tests").exists());

    Project addonProject = projectFactory.findProject(projectRoot.getChild("addon"));
    Project apiProject = projectFactory.findProject(projectRoot.getChild("api"));
    Project implProject = projectFactory.findProject(projectRoot.getChild("impl"));
    Project spiProject = projectFactory.findProject(projectRoot.getChild("spi"));
    Project testsProject = projectFactory.findProject(projectRoot.getChild("tests"));

    Assert.assertTrue(project.hasFacet(ForgeBOMFacet.class));

    Assert.assertFalse(addonProject.hasFacet(ForgeBOMFacet.class));
    Assert.assertFalse(addonProject.hasFacet(JavaCompilerFacet.class));
    Assert.assertTrue(addonProject.hasFacet(JavaSourceFacet.class));
    Assert.assertTrue(addonProject.hasFacet(ResourcesFacet.class));
    Assert.assertFalse(addonProject.hasFacet(CDIFacet.class));

    Assert.assertFalse(apiProject.hasFacet(ForgeBOMFacet.class));
    Assert.assertFalse(apiProject.hasFacet(JavaCompilerFacet.class));
    Assert.assertTrue(apiProject.hasFacet(JavaSourceFacet.class));
    Assert.assertTrue(apiProject.hasFacet(ResourcesFacet.class));
    Assert.assertTrue(apiProject.hasFacet(CDIFacet_1_1.class));

    Assert.assertFalse(implProject.hasFacet(ForgeBOMFacet.class));
    Assert.assertFalse(implProject.hasFacet(JavaCompilerFacet.class));
    Assert.assertTrue(implProject.hasFacet(JavaSourceFacet.class));
    Assert.assertTrue(implProject.hasFacet(ResourcesFacet.class));
    Assert.assertTrue(implProject.hasFacet(CDIFacet_1_1.class));

    Assert.assertFalse(spiProject.hasFacet(ForgeBOMFacet.class));
    Assert.assertFalse(spiProject.hasFacet(JavaCompilerFacet.class));
    Assert.assertTrue(spiProject.hasFacet(JavaSourceFacet.class));
    Assert.assertTrue(spiProject.hasFacet(ResourcesFacet.class));
    Assert.assertTrue(spiProject.hasFacet(FurnaceAPIFacet.class));
    Assert.assertFalse(spiProject.hasFacet(CDIFacet_1_1.class));

    Assert.assertFalse(testsProject.hasFacet(ForgeBOMFacet.class));
    Assert.assertFalse(testsProject.hasFacet(JavaCompilerFacet.class));
    Assert.assertTrue(testsProject.hasFacet(JavaSourceFacet.class));
    Assert.assertTrue(testsProject.hasFacet(ResourcesFacet.class));
    Assert.assertFalse(testsProject.hasFacet(CDIFacet_1_1.class));

    Dependency addonDependency =
        DependencyBuilder.create(addonProject.getFacet(MetadataFacet.class).getOutputDependency())
            .setClassifier(FORGE_ADDON_CLASSIFIER);
    Dependency apiDependency = apiProject.getFacet(MetadataFacet.class).getOutputDependency();
    Dependency implDependency = implProject.getFacet(MetadataFacet.class).getOutputDependency();
    Dependency spiDependency =
        DependencyBuilder.create(spiProject.getFacet(MetadataFacet.class).getOutputDependency())
            .setClassifier(FORGE_ADDON_CLASSIFIER);

    /*
     * Verify parent project
     */
    Assert.assertNull(project.getFacet(MavenFacet.class).getModel().getParent());

    Assert.assertFalse(project.getRoot().getChild("src").exists());
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertFalse(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(
                DependencyBuilder.create(
                        addonProject.getFacet(MetadataFacet.class).getOutputDependency())
                    .setClassifier(FORGE_ADDON_CLASSIFIER)));
    Assert.assertTrue(
        project.getFacet(DependencyFacet.class).hasDirectManagedDependency(apiDependency));
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(
                implProject.getFacet(MetadataFacet.class).getOutputDependency()));

    Assert.assertTrue(
        project.getFacet(DependencyFacet.class).hasDirectManagedDependency(spiDependency));

    /*
     * Verify impl/ sub-module
     */

    Assert.assertEquals(
        ".." + File.separator + "pom.xml",
        implProject.getFacet(MavenFacet.class).getModel().getParent().getRelativePath());
    Assert.assertTrue(implProject.hasFacet(DefaultFurnaceContainerAPIFacet.class));
    Assert.assertTrue(
        implProject
            .getFacet(JavaSourceFacet.class)
            .getJavaResource("com.acme.testproject.package-info.java")
            .exists());

    Assert.assertTrue(
        implProject.getFacet(DependencyFacet.class).hasDirectDependency(apiDependency));
    Assert.assertFalse(
        implProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(apiDependency));
    Assert.assertTrue(
        implProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(apiDependency));
    Assert.assertEquals(
        "provided",
        implProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(apiDependency)
            .getScopeType());

    Assert.assertTrue(
        implProject.getFacet(DependencyFacet.class).hasDirectDependency(spiDependency));
    Assert.assertFalse(
        implProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(spiDependency));
    Assert.assertTrue(
        implProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(spiDependency));
    Assert.assertEquals(
        "provided",
        implProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(spiDependency)
            .getScopeType());

    // Assert.assertTrue(implProject.getFacet(DependencyFacet.class).getManagedDependencies().isEmpty());
    Assert.assertTrue(
        implProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertFalse(
        implProject
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertTrue(
        implProject
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertFalse(
        implProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));
    Assert.assertTrue(implProject.hasFacet(AddonImplFacet.class));
    Assert.assertFalse(implProject.hasFacet(FurnacePluginFacet.class));

    /*
     * Verify api/ sub-module
     */
    Assert.assertEquals(
        ".." + File.separator + "pom.xml",
        apiProject.getFacet(MavenFacet.class).getModel().getParent().getRelativePath());
    Assert.assertTrue(apiProject.hasFacet(DefaultFurnaceContainerAPIFacet.class));
    Assert.assertTrue(
        apiProject
            .getFacet(JavaSourceFacet.class)
            .getJavaResource("com.acme.testproject.package-info.java")
            .exists());

    Assert.assertTrue(
        apiProject.getFacet(DependencyFacet.class).hasDirectDependency(spiDependency));
    Assert.assertFalse(
        apiProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(spiDependency));
    Assert.assertTrue(
        apiProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(spiDependency));
    Assert.assertEquals(
        "provided",
        apiProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(spiDependency)
            .getScopeType());

    // Assert.assertTrue(apiProject.getFacet(DependencyFacet.class).getManagedDependencies().isEmpty());
    Assert.assertTrue(
        apiProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertFalse(
        apiProject
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertTrue(
        apiProject
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertFalse(
        apiProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));
    Assert.assertTrue(apiProject.hasFacet(AddonAPIFacet.class));
    Assert.assertFalse(apiProject.hasFacet(FurnacePluginFacet.class));

    /*
     * Verify spi/ sub-module2.0.0.Final
     */
    Assert.assertEquals(
        ".." + File.separator + "pom.xml",
        spiProject.getFacet(MavenFacet.class).getModel().getParent().getRelativePath());
    Assert.assertTrue(
        spiProject
            .getFacet(JavaSourceFacet.class)
            .getJavaResource("com.acme.testproject.package-info.java")
            .exists());

    // Assert.assertTrue(spiProject.getFacet(DependencyFacet.class).getManagedDependencies().isEmpty());
    Assert.assertTrue(
        spiProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(FurnaceAPIFacet.FURNACE_API_DEPENDENCY));
    Assert.assertFalse(
        spiProject
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(FurnaceAPIFacet.FURNACE_API_DEPENDENCY));
    Assert.assertTrue(
        spiProject
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(FurnaceAPIFacet.FURNACE_API_DEPENDENCY));
    Assert.assertFalse(
        spiProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));
    Assert.assertFalse(spiProject.hasFacet(DefaultFurnaceContainerFacet.class));
    Assert.assertFalse(spiProject.hasFacet(DefaultFurnaceContainerAPIFacet.class));
    Assert.assertFalse(spiProject.hasFacet(CDIFacet_1_1.class));
    Assert.assertTrue(spiProject.hasFacet(AddonSPIFacet.class));
    Assert.assertTrue(spiProject.hasFacet(FurnacePluginFacet.class));

    /*
     * Verify addon/ sub-module
     */
    Assert.assertEquals(
        ".." + File.separator + "pom.xml",
        addonProject.getFacet(MavenFacet.class).getModel().getParent().getRelativePath());
    Assert.assertTrue(
        addonProject
            .getFacet(JavaSourceFacet.class)
            .getJavaResource("com.acme.testproject.package-info.java")
            .exists());

    Assert.assertTrue(
        addonProject.getFacet(DependencyFacet.class).hasDirectDependency(apiDependency));
    Assert.assertFalse(
        addonProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(apiDependency));
    Assert.assertTrue(
        addonProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(apiDependency));
    Assert.assertNull(
        addonProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(apiDependency)
            .getScopeType());
    Assert.assertFalse(
        addonProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(apiDependency)
            .isOptional());

    Assert.assertTrue(
        addonProject.getFacet(DependencyFacet.class).hasDirectDependency(implDependency));
    Assert.assertFalse(
        addonProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(implDependency));
    Assert.assertTrue(
        addonProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(implDependency));
    Assert.assertEquals(
        "runtime",
        addonProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(implDependency)
            .getScopeType());
    Assert.assertTrue(
        addonProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(implDependency)
            .isOptional());

    Assert.assertTrue(
        addonProject.getFacet(DependencyFacet.class).hasDirectDependency(spiDependency));
    Assert.assertFalse(
        addonProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(spiDependency));
    Assert.assertTrue(
        addonProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(spiDependency));
    Assert.assertNull(
        addonProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(spiDependency)
            .getScopeType());
    Assert.assertEquals(
        "compile",
        addonProject
            .getFacet(DependencyFacet.class)
            .getEffectiveDependency(spiDependency)
            .getScopeType());
    Assert.assertFalse(
        addonProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(spiDependency)
            .isOptional());

    // Assert.assertTrue(addonProject.getFacet(DependencyFacet.class).getManagedDependencies().isEmpty());
    Assert.assertTrue(
        addonProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertFalse(
        addonProject
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertTrue(
        addonProject
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(
                DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertFalse(
        addonProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));

    Assert.assertTrue(addonProject.hasFacet(FurnacePluginFacet.class));

    /*
     * Verify tests/ sub-module
     */

    Assert.assertEquals(
        ".." + File.separator + "pom.xml",
        testsProject.getFacet(MavenFacet.class).getModel().getParent().getRelativePath());

    Assert.assertTrue(
        testsProject.getFacet(DependencyFacet.class).hasDirectDependency(addonDependency));
    Assert.assertFalse(
        testsProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(addonDependency));
    Assert.assertTrue(
        testsProject
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(addonDependency));
    Assert.assertNull(
        testsProject
            .getFacet(DependencyFacet.class)
            .getDirectDependency(addonDependency)
            .getScopeType());
    Assert.assertNotNull(
        "ADDON module is not present in the TESTS module",
        testsProject.getFacet(DependencyFacet.class).getEffectiveDependency(addonDependency));
    Assert.assertEquals(
        "compile",
        testsProject
            .getFacet(DependencyFacet.class)
            .getEffectiveDependency(addonDependency)
            .getScopeType());

    Assert.assertFalse(
        testsProject.getFacet(DependencyFacet.class).hasDirectDependency(spiDependency));
    Assert.assertFalse(
        testsProject.getFacet(DependencyFacet.class).hasDirectManagedDependency(spiDependency));
    Assert.assertTrue(
        testsProject.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(spiDependency));

    // Assert.assertTrue(testsProject.getFacet(DependencyFacet.class).getManagedDependencies().isEmpty());
    Assert.assertTrue(
        testsProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertFalse(
        testsProject
            .getFacet(DependencyFacet.class)
            .hasDirectManagedDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertTrue(
        testsProject
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(
                DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertEquals(
        furnaceVersion.toString(),
        testsProject
            .getFacet(DependencyFacet.class)
            .getEffectiveDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY)
            .getCoordinate()
            .getVersion());
    Assert.assertFalse(
        testsProject
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));

    Assert.assertTrue(project.getRoot().getChild("README.asciidoc").exists());
    project.getRoot().delete(true);
    project.getRoot().reify(DirectoryResource.class).deleteOnExit();
  }
Exemple #27
0
 /**
  * Creates a project installing the required facets from {@link
  * JavaProjectType#getRequiredFacets()}
  */
 public Project createJavaLibraryProject() {
   return projectFactory.createTempProject(mavenBuildSystem, javaProjectType.getRequiredFacets());
 }
  @Test
  public void testSimpleAddonProject() throws FileNotFoundException, FacetNotFoundException {
    Project project = projectFactory.createTempProject();
    project.getRoot().reify(DirectoryResource.class).deleteOnExit();
    MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
    metadataFacet.setProjectName("testproject");
    metadataFacet.setProjectVersion("1.0.0-SNAPSHOT");
    metadataFacet.setProjectGroupName("com.acme.testproject");

    Version furnaceVersion = furnace.getVersion();
    configurator.setupSimpleAddonProject(project, Collections.<AddonId>emptyList());

    Assert.assertTrue(project.hasFacet(ForgeBOMFacet.class));
    Assert.assertTrue(project.hasFacet(DefaultFurnaceContainerFacet.class));
    Assert.assertTrue(project.hasFacet(FurnacePluginFacet.class));
    Assert.assertTrue(project.hasFacet(AddonTestFacet.class));
    Assert.assertTrue(project.hasFacet(JavaSourceFacet.class));
    Assert.assertTrue(project.hasFacet(JavaCompilerFacet.class));
    Assert.assertTrue(project.hasFacet(CDIFacet.class));
    Assert.assertTrue(project.hasFacet(CDIFacet_1_1.class));

    Assert.assertFalse(project.getFacet(DependencyFacet.class).getManagedDependencies().isEmpty());
    Assert.assertTrue(
        project
            .getFacet(JavaSourceFacet.class)
            .getJavaResource("com.acme.testproject.package-info.java")
            .exists());

    /** Verify test harness dependencies */
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(AddonTestFacet.FURNACE_TEST_ADAPTER_DEPENDENCY));
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(AddonTestFacet.FURNACE_TEST_HARNESS_DEPENDENCY));
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(AddonTestFacet.FURNACE_TEST_ADAPTER_DEPENDENCY));
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(AddonTestFacet.FURNACE_TEST_HARNESS_DEPENDENCY));
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveDependency(DependencyBuilder.create("junit:junit").setScopeType("test")));

    /** Verify container dependencies */
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertNull(
        project
            .getFacet(DependencyFacet.class)
            .getDirectDependency(DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY)
            .getCoordinate()
            .getVersion());
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveManagedDependency(
                DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY));
    Assert.assertNotNull(
        project
            .getFacet(DependencyFacet.class)
            .getEffectiveManagedDependency(
                DefaultFurnaceContainerFacet.FURNACE_CONTAINER_DEPENDENCY)
            .getCoordinate()
            .getVersion());
    Assert.assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertEquals(
        furnaceVersion.toString(),
        project
            .getFacet(DependencyFacet.class)
            .getEffectiveDependency(
                DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY)
            .getCoordinate()
            .getVersion());
    Assert.assertFalse(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DefaultFurnaceContainerAPIFacet.FURNACE_CONTAINER_API_DEPENDENCY));
    Assert.assertFalse(
        project
            .getFacet(DependencyFacet.class)
            .hasDirectDependency(DependencyBuilder.create("javax.annotation:jsr250-api:1.0")));

    Assert.assertTrue(project.getRoot().getChild("README.asciidoc").exists());
    project.getRoot().delete(true);
  }