private String assertDocFile(String relativeName) throws Exception { File src = docFile(relativeName); Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", src.getAbsolutePath()); compiler.assertCompile(); return compiler.processor.getDoc(src.getName()); }
void failCompile() { JavaCompiler.CompilationTask task = createTask(sources, diagnostics); if (task.call()) { throw new AssertionError("Was expecting compilation to fail"); } }
@Test public void testDocFileNotFound() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", new File(new File("."), "does_not_exists").getAbsolutePath()); compiler.failCompile(); }
private String assertDoc(String pkg) throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), pkg); compiler.assertCompile(); return compiler.processor.getDoc(pkg); }
@Test public void testGen() throws Exception { AtomicInteger count = new AtomicInteger(); AbstractProcessor proc = new AbstractProcessor() { @Override public Set<String> getSupportedAnnotationTypes() { return Collections.singleton("*"); } @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (count.getAndIncrement() == 0) { try { Filer filer = processingEnv.getFiler(); Element elt = processingEnv.getElementUtils().getTypeElement("gen.GeneratedClass"); JavaFileObject src = filer.createSourceFile("io.vertx.test.gen.GeneratedClass", elt); try (Writer writer = src.openWriter()) { writer.append("package io.vertx.test.gen;\npublic class GeneratedClass {\n}"); } } catch (Exception e) { e.printStackTrace(); } } return true; } }; Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.gen"); compiler.addProcessor(proc); compiler.assertCompile(); assertEquals(3, count.get()); }
private Map<String, String> failDoc(String pkg) throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), pkg); compiler.failCompile(); return compiler.processor.failures; }
Files.walkFileTree(fromPath, visitor); assertTrue(sources.size() > 0); return new Compiler<>(sources, classOutput, processor);
@Test public void testNestedBlocks() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.nested"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.nested"); assertThat(content, containsString("[source,java]")); assertThat(content, containsString("----")); assertThat(content, not(containsString("\\----"))); assertThat(content, containsString("System.out.println(\"Hello\");")); }
@Test public void testOutputInterpolation() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", new File(dir, "$lang").getAbsolutePath()); compiler.setOption("docgen.extension", ".ad.txt"); compiler.assertCompile(); File file = new File(new File(dir, "java"), pkg + ".ad.txt"); assertTrue(file.exists()); assertTrue(file.isFile()); } } }
@Test public void testDocFileNotFile() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", new File(".").getAbsolutePath()); compiler.failCompile(); }
private String assertDocWithCustomGenerator(String pkg) throws Exception { Compiler<CustomTestGenProcessor> compiler = buildCompiler(new CustomTestGenProcessor(), pkg); compiler.assertCompile(); return compiler.processor.getDoc(pkg); }
void assertCompile() { JavaCompiler.CompilationTask task = createTask(sources, diagnostics); if (!task.call()) { StringWriter buffer = new StringWriter(); buffer.append("Could not compile").append(":\n"); for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) { buffer.append(diagnostic.toString()).append("\n"); } throw new AssertionError(buffer.toString()); } }
@Test public void testExtension() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.setOption("docgen.extension", ".ad.txt"); compiler.assertCompile(); File file = new File(dir, pkg + ".ad.txt"); assertTrue(file.exists()); assertTrue(file.isFile()); } }
@Test public void testDocFileWithLinkToUnresolvableType() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", docFile("docs/linktounresolvabletype.adoc").getAbsolutePath()); compiler.failCompile(); }
@Test public void testMissingPostProcessor() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.missing"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.missing"); // String processed = compiler.processor.applyPostProcessors(content); assertThat(content, containsString("This should be included.")); assertThat(content, containsString("[missing]")); assertThat(content, containsString("----")); }
@Test public void testLinkGenerationWithAnnotation() throws Exception { String pkg = "io.vertx.test.linktomethod"; Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File file = new File(dir, pkg + ".adoc"); List<String> lines = Files.readAllLines(file.toPath()); for (String line : lines) { // The :: is used when the annotated type is used. assertFalse(line.contains("::")); } }
@Test public void testResolveLinkWithSourceAndClass() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.linkresolution.resolvable"); compiler.assertCompile(); File dependency = compiler.classOutput; File metaInf = new File(dependency, "META-INF"); compiler.fileManager.getLocation(StandardLocation.CLASS_PATH).forEach(files::add); compiler.fileManager.setLocation(StandardLocation.CLASS_PATH, files); compiler.assertCompile(); String s = compiler.processor.getDoc("io.vertx.test.linkresolution.resolving"); assertEquals("`link:type[ResolvableType]`", s);
@Test public void testGeneration() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File file = new File(dir, pkg + ".adoc"); assertTrue(file.exists()); assertTrue(file.isFile()); } }
@Test public void testCodeBlocks() throws Exception { // Code blocks must not be touched by pre-processors. Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.code"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.code"); assertThat(content, containsString("[source,java]")); assertThat(content, containsString("[source]")); assertThat(content, containsString("----")); assertThat(content, containsString("System.out.println(\"Hello\");")); assertThat(content, containsString(" System.out.println(\"Bye\");")); }
@Test public void testFileName() throws Exception { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), "io.vertx.test.filename"); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File f1 = new File(dir, "index.adoc"); assertTrue(f1.exists()); assertTrue(f1.isFile()); File f2 = new File(dir, "sub" + File.separator + "index.adoc"); assertTrue(f2.exists()); assertTrue(f2.isFile()); assertEquals("sub/index.adoc", new String(Files.readAllBytes(f1.toPath()))); }