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