Search in sources :

Example 1 with Visitor

use of org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor in project mylyn.docs by eclipse.

the class MarkupToEclipseHelpMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        ensureOutputFolderExists();
        ensureSourceFolderExists();
        ServiceLocator serviceLocator = ServiceLocator.getInstance(MarkupToEclipseHelpMojo.class.getClassLoader());
        Set<MarkupLanguage> markupLanguages = serviceLocator.getAllMarkupLanguages();
        if (markupLanguages.isEmpty()) {
            throw new MojoFailureException("No markup languages are available");
        }
        getLog().info(format("Generating Eclipse help content from sources: {0} -> {1}", sourceFolder, outputFolder));
        final FileToMarkupLanguage fileToMarkupLanguage = new FileToMarkupLanguage(markupLanguages);
        SourceFileTraversal fileTraversal = new SourceFileTraversal(sourceFolder);
        final AtomicInteger fileCount = new AtomicInteger();
        fileTraversal.traverse(new Visitor() {

            @Override
            public void accept(String relativePath, File sourceFile) {
                fileCount.incrementAndGet();
                process(sourceFile, relativePath, fileToMarkupLanguage.get(sourceFile));
            }
        });
        getLog().info(format("Processed {0} files", fileCount.get()));
    } catch (BuildFailureException e) {
        getLog().error(e.getMessage(), e);
        throw new MojoFailureException(e.getMessage(), e.getCause());
    }
}
Also used : Visitor(org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) File(java.io.File)

Example 2 with Visitor

use of org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor in project mylyn.docs by eclipse.

the class SourceFileTraversalTest method traverseRootMatch.

@Test
public void traverseRootMatch() {
    File file = mockFile("one.Test");
    SourceFileTraversal traversal = new SourceFileTraversal(mockFolder("test", file));
    Visitor visitor = mock(Visitor.class);
    traversal.traverse(visitor);
    verify(visitor).accept(eq(""), same(file));
    verifyNoMoreInteractions(visitor);
}
Also used : Visitor(org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor) SourceFileTraversal(org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal) File(java.io.File) Test(org.junit.Test)

Example 3 with Visitor

use of org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor in project mylyn.docs by eclipse.

the class SourceFileTraversalTest method traverseMatchWithPath.

@Test
public void traverseMatchWithPath() {
    File file = mockFile("one.Test");
    SourceFileTraversal traversal = new SourceFileTraversal(mockFolder("test", mockFolder("depth1", mockFolder("depth2", file))));
    Visitor visitor = mock(Visitor.class);
    traversal.traverse(visitor);
    verify(visitor).accept(eq("depth1" + File.separator + "depth2"), same(file));
    verifyNoMoreInteractions(visitor);
}
Also used : Visitor(org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor) SourceFileTraversal(org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)3 Visitor (org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor)3 SourceFileTraversal (org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal)2 Test (org.junit.Test)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)1 ServiceLocator (org.eclipse.mylyn.wikitext.util.ServiceLocator)1