Search in sources :

Example 6 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class OsgiServiceLocatorTest method installAsDefaultImplementation.

@Test
public void installAsDefaultImplementation() {
    ServiceLocator.setImplementation(OsgiServiceLocator.class);
    ServiceLocator instance = ServiceLocator.getInstance();
    assertNotNull(instance);
    assertEquals(OsgiServiceLocator.class, instance.getClass());
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) Test(org.junit.Test)

Example 7 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator 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 8 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class ServiceLocatorTest method setupServiceLocatorWithMockMarkupLanguage.

protected void setupServiceLocatorWithMockMarkupLanguage(boolean metaInf) {
    try {
        ClassLoader classLoader = mock(ClassLoader.class);
        Collection<URL> resources = Collections.singletonList(new URL("file:" + MockMarkupLanguage.class.getName()));
        Enumeration<Object> empty = Collections.enumeration(Collections.emptyList());
        doReturn(empty).when(classLoader).getResources(any(String.class));
        doReturn(metaInf ? Collections.enumeration(resources) : empty).when(classLoader).getResources(eq("META-INF/services/" + MarkupLanguage.class.getName()));
        doReturn(!metaInf ? Collections.enumeration(resources) : empty).when(classLoader).getResources(eq("services/" + MarkupLanguage.class.getName()));
        doReturn(MockMarkupLanguage.class).when(classLoader).loadClass(MockMarkupLanguage.class.getName());
        locator = new ServiceLocator(classLoader) {

            @Override
            protected List<String> readServiceClassNames(URL url) {
                return super.readServiceClassNames(new ByteArrayInputStream(MockMarkupLanguage.class.getName().getBytes(Charsets.UTF_8)));
            }
        };
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) URL(java.net.URL) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Example 9 with ServiceLocator

use of org.eclipse.mylyn.wikitext.util.ServiceLocator in project mylyn.docs by eclipse.

the class ServiceLocatorTest method setupServiceLocatorWithMockMarkupLanguageProvider.

protected void setupServiceLocatorWithMockMarkupLanguageProvider(boolean metaInf) {
    try {
        ClassLoader classLoader = mock(ClassLoader.class);
        Collection<URL> resources = Collections.singletonList(new URL("file:" + MockMarkupLanguageProvider.class.getName()));
        Enumeration<Object> empty = Collections.enumeration(Collections.emptyList());
        doReturn(empty).when(classLoader).getResources(any(String.class));
        doReturn(metaInf ? Collections.enumeration(resources) : empty).when(classLoader).getResources(eq("META-INF/services/" + MarkupLanguageProvider.class.getName()));
        doReturn(!metaInf ? Collections.enumeration(resources) : empty).when(classLoader).getResources(eq("services/" + MarkupLanguageProvider.class.getName()));
        doReturn(MockMarkupLanguageProvider.class).when(classLoader).loadClass(MockMarkupLanguageProvider.class.getName());
        locator = new ServiceLocator(classLoader) {

            @Override
            protected List<String> readServiceClassNames(URL url) {
                return super.readServiceClassNames(new ByteArrayInputStream(MockMarkupLanguageProvider.class.getName().getBytes(Charsets.UTF_8)));
            }
        };
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MockMarkupLanguageProvider(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguageProvider) URL(java.net.URL) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) MarkupLanguageProvider(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageProvider) MockMarkupLanguageProvider(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguageProvider)

Aggregations

ServiceLocator (org.eclipse.mylyn.wikitext.util.ServiceLocator)9 Test (org.junit.Test)6 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 List (java.util.List)3 MockMarkupLanguage (org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage)3 ExpectedException (org.junit.rules.ExpectedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MockMarkupLanguageProvider (org.eclipse.mylyn.internal.wikitext.MockMarkupLanguageProvider)1 OsgiServiceLocator (org.eclipse.mylyn.wikitext.core.osgi.OsgiServiceLocator)1 Visitor (org.eclipse.mylyn.wikitext.maven.internal.SourceFileTraversal.Visitor)1 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)1 MarkupLanguageProvider (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageProvider)1