Search in sources :

Example 6 with FileArchive

use of org.revapi.simple.FileArchive in project revapi by revapi.

the class TextReporterTest method testCustomTemplate.

@Test
public void testCustomTemplate() throws Exception {
    Path tempFile = Files.createTempFile(new File(".").toPath(), "text-report-test", ".ftl");
    try {
        Files.copy(getClass().getResourceAsStream("/custom-template.ftl"), tempFile, StandardCopyOption.REPLACE_EXISTING);
        TextReporter reporter = new TextReporter();
        Revapi r = new Revapi(emptySet(), singleton(TextReporter.class), emptySet(), emptySet());
        AnalysisContext ctx = AnalysisContext.builder(r).withConfigurationFromJSON("{\"revapi\": {\"reporter\": {\"text\": {\"template\": \"" + tempFile.toString() + "\"}}}}").withOldAPI(API.of(new FileArchive(new File("old-dummy.archive"))).build()).withNewAPI(API.of(new FileArchive(new File("new-dummy.archive"))).build()).build();
        AnalysisContext reporterCtx = r.prepareAnalysis(ctx).getFirstConfigurationOrNull(TextReporter.class);
        reporter.initialize(reporterCtx);
        buildReports().forEach(reporter::report);
        StringWriter out = new StringWriter();
        PrintWriter wrt = new PrintWriter(out);
        reporter.setOutput(wrt);
        reporter.close();
        String expected = "old1 VS new1\nold2 VS new2\n";
        Assert.assertEquals(expected, out.toString());
    } finally {
        Files.delete(tempFile);
    }
}
Also used : Path(java.nio.file.Path) Revapi(org.revapi.Revapi) StringWriter(java.io.StringWriter) FileArchive(org.revapi.simple.FileArchive) AnalysisContext(org.revapi.AnalysisContext) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

FileArchive (org.revapi.simple.FileArchive)6 File (java.io.File)5 ArrayList (java.util.ArrayList)3 RepositoryException (org.eclipse.aether.RepositoryException)3 AnalysisContext (org.revapi.AnalysisContext)3 Revapi (org.revapi.Revapi)3 Getopt (gnu.getopt.Getopt)2 LongOpt (gnu.getopt.LongOpt)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 RepositorySystem (org.eclipse.aether.RepositorySystem)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 Test (org.junit.Test)2 ArtifactResolver (org.revapi.maven.utils.ArtifactResolver)2 ScopeDependencySelector (org.revapi.maven.utils.ScopeDependencySelector)2 ScopeDependencyTraverser (org.revapi.maven.utils.ScopeDependencyTraverser)2 FileInputStream (java.io.FileInputStream)1 Path (java.nio.file.Path)1