private Path executeWindupAgainstAppUntilRule(
      final String inputDir,
      final GraphContext grCtx,
      final Class<MavenizeRuleProvider> ruleToRunUpTo)
      throws IOException, IllegalAccessException, InstantiationException {
    Assume.assumeTrue("Exists: " + inputDir, new File(inputDir).exists());

    final Path outputPath =
        Paths.get(FileUtils.getTempDirectory().toString(), "Windup-Mavenization-output");
    FileUtils.deleteDirectory(outputPath.toFile());
    Files.createDirectories(outputPath);

    grCtx.getGraph().getBaseGraph().commit();

    // Configure Windup core
    final WindupConfiguration processorConfig = new WindupConfiguration();
    processorConfig.setRuleProviderFilter(new RuleProviderWithDependenciesPredicate(ruleToRunUpTo));
    processorConfig.setGraphContext(grCtx);
    processorConfig.addInputPath(Paths.get(inputDir));
    processorConfig.setOutputDirectory(outputPath);
    processorConfig.setOptionValue(ScanPackagesOption.NAME, Collections.singletonList(""));
    processorConfig.setOptionValue(SourceModeOption.NAME, false);
    processorConfig.setOptionValue(MavenizeOption.NAME, true);

    processor.execute(processorConfig);

    return outputPath;
  }
  @Test
  public void testNestedCondition() throws IOException {
    try (GraphContext context = factory.create()) {
      ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class);
      pm.setName("Main Project");
      FileModel inputPath = context.getFramed().addVertex(null, FileModel.class);
      inputPath.setFilePath("src/test/resources/");

      Path outputPath =
          Paths.get(
              FileUtils.getTempDirectory().toString(), "windup_" + UUID.randomUUID().toString());
      FileUtils.deleteDirectory(outputPath.toFile());
      Files.createDirectories(outputPath);

      inputPath.setProjectModel(pm);
      pm.setRootFileModel(inputPath);

      WindupConfiguration windupConfiguration =
          new WindupConfiguration()
              .setRuleProviderFilter(
                  new NotPredicate(
                      new RuleProviderPhasePredicate(
                          MigrationRulesPhase.class, ReportGenerationPhase.class)))
              .setGraphContext(context);
      windupConfiguration.setInputPath(Paths.get(inputPath.getFilePath()));
      windupConfiguration.setOutputDirectory(outputPath);
      processor.execute(windupConfiguration);

      GraphService<ClassificationModel> classificationService =
          new GraphService<>(context, ClassificationModel.class);

      Assert.assertEquals(1, provider.getXmlFileMatches().size());
      List<ClassificationModel> classifications = Iterators.asList(classificationService.findAll());
      for (ClassificationModel model : classifications) {
        String classification = model.getClassification();
        String classificationString = classification.toString();
        Assert.assertEquals("Spring File", classificationString);
      }
      Assert.assertEquals(1, classifications.size());
      Iterator<FileModel> iterator = classifications.get(0).getFileModels().iterator();
      Assert.assertNotNull(iterator.next());
      Assert.assertNotNull(iterator.next());
      Assert.assertFalse(iterator.hasNext());
    }
  }
  @Test
  public void testMetadataFound() throws Exception {
    String inputPath = "src/test/resources/NonNamespacedMavenDiscoveryTest";
    final Path outputPath = getDefaultPath();
    FileUtils.deleteDirectory(outputPath.toFile());
    Files.createDirectories(outputPath);
    try (GraphContext context = factory.create(outputPath)) {
      final WindupConfiguration processorConfig = new WindupConfiguration();
      processorConfig.setOptionValue(SourceModeOption.NAME, true);

      Predicate<RuleProvider> ruleFilter =
          new AndPredicate(new RuleProviderWithDependenciesPredicate(MigrationRulesPhase.class));

      processorConfig.setRuleProviderFilter(ruleFilter);
      processorConfig.setGraphContext(context);
      processorConfig.addInputPath(Paths.get(inputPath));
      processorConfig.setOutputDirectory(outputPath);
      processorConfig.setOptionValue(ScanPackagesOption.NAME, Collections.singletonList(""));

      processor.execute(processorConfig);

      ProjectModel project =
          WindupConfigurationService.getConfigurationModel(context)
              .getInputPaths()
              .iterator()
              .next()
              .getProjectModel();
      Assert.assertTrue("Maven Project Expected", project instanceof MavenProjectModel);

      MavenProjectModel mavenProject = (MavenProjectModel) project;
      Assert.assertEquals("testgroupid", mavenProject.getGroupId());
      Assert.assertEquals("testartifactid", mavenProject.getArtifactId());
      Assert.assertEquals("testname", mavenProject.getName());
      Assert.assertEquals("1.0.0.testversion", mavenProject.getVersion());
      Assert.assertEquals("testdescription", mavenProject.getDescription());

      Assert.assertEquals(1, Iterables.size(mavenProject.getDependencies()));
      ProjectDependencyModel dependency = mavenProject.getDependencies().iterator().next();

      Assert.assertEquals(
          "testdependency-groupid",
          ((MavenProjectModel) dependency.getProjectModel()).getGroupId());
      Assert.assertEquals(
          "testdependency-artifactid",
          ((MavenProjectModel) dependency.getProjectModel()).getArtifactId());
      Assert.assertEquals("1.4", dependency.getProjectModel().getVersion());
    }
  }
예제 #4
0
  @Test
  public void testJavaClassCondition()
      throws IOException, InstantiationException, IllegalAccessException {
    try (GraphContext context = factory.create(getDefaultPath())) {
      final String inputDir = "src/test/resources/org/jboss/windup/rules/java";

      final Path outputPath =
          Paths.get(
              FileUtils.getTempDirectory().toString(),
              "windup_" + RandomStringUtils.randomAlphanumeric(6));
      FileUtils.deleteDirectory(outputPath.toFile());
      Files.createDirectories(outputPath);

      // Fill the graph with test data.
      ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class);
      pm.setName("Main Project");

      // Create FileModel for $inputDir
      FileModel inputPathFrame = context.getFramed().addVertex(null, FileModel.class);
      inputPathFrame.setFilePath(inputDir);
      inputPathFrame.setProjectModel(pm);
      pm.addFileModel(inputPathFrame);

      // Set project.rootFileModel to inputPath
      pm.setRootFileModel(inputPathFrame);

      // Create FileModel for $inputDir/HintsClassificationsTest.java
      FileModel fileModel = context.getFramed().addVertex(null, FileModel.class);
      fileModel.setFilePath(inputDir + "/JavaHintsClassificationsTest.java");
      fileModel.setProjectModel(pm);
      pm.addFileModel(fileModel);

      // Create FileModel for $inputDir/JavaClassTest.java
      fileModel = context.getFramed().addVertex(null, FileModel.class);
      fileModel.setFilePath(inputDir + "/JavaClassTest.java");
      fileModel.setProjectModel(pm);
      pm.addFileModel(fileModel);

      context.getGraph().getBaseGraph().commit();

      final WindupConfiguration processorConfig =
          new WindupConfiguration().setOutputDirectory(outputPath);
      processorConfig.setRuleProviderFilter(
          new RuleProviderWithDependenciesPredicate(TestJavaClassTestRuleProvider.class));
      processorConfig
          .setGraphContext(context)
          .setRuleProviderFilter(
              new RuleProviderWithDependenciesPredicate(TestJavaClassTestRuleProvider.class));
      processorConfig.setInputPath(Paths.get(inputDir));
      processorConfig.setOutputDirectory(outputPath);
      processorConfig.setOptionValue(ScanPackagesOption.NAME, Collections.singletonList(""));

      processor.execute(processorConfig);

      GraphService<JavaTypeReferenceModel> typeRefService =
          new GraphService<>(context, JavaTypeReferenceModel.class);
      Iterable<JavaTypeReferenceModel> typeReferences = typeRefService.findAll();
      Assert.assertTrue(typeReferences.iterator().hasNext());

      Assert.assertEquals(3, provider.getFirstRuleMatchCount());
      Assert.assertEquals(1, provider.getSecondRuleMatchCount());
    }
  }