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 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()); } }
@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()); } }