Search in sources :

Example 1 with PluginIndex

use of org.scijava.plugin.PluginIndex in project imagej-omero by imagej.

the class ScriptGeneratorTest method testGenerateAll.

@Test
public void testGenerateAll() throws IOException {
    // create a context with a minimal command set
    final PluginIndex pluginIndex = new PluginIndex() {

        @Override
        public void discover() {
            super.discover();
            removeAll(getPlugins(Command.class));
            add(pluginInfo(FileNew.class));
            add(pluginInfo(FileOpen.class));
            add(pluginInfo(FileSave.class));
            add(pluginInfo(FileExit.class));
            add(pluginInfo(Lion.class));
            add(pluginInfo(Tiger.class));
            add(pluginInfo(Bear.class));
        }
    };
    final ArrayList<Class<? extends Service>> classes = new ArrayList<Class<? extends Service>>();
    classes.add(AppService.class);
    classes.add(CommandService.class);
    classes.add(MenuService.class);
    final Context context = new Context(classes, pluginIndex);
    final ScriptGenerator scriptGen = new ScriptGenerator(context);
    final File tempDir = TestUtils.createTemporaryDirectory("script-generator-");
    final File libDir = new File(tempDir, "lib");
    final File scriptsDir = new File(libDir, "scripts");
    assertTrue(scriptsDir.mkdirs());
    final int returnCode = scriptGen.generateAll(tempDir);
    context.dispose();
    assertEquals(0, returnCode);
    final File imagejDir = new File(scriptsDir, "imagej");
    assertTrue(imagejDir.isDirectory());
    final File fileDir = new File(imagejDir, "File");
    assertTrue(fileDir.isDirectory());
    final File animalsDir = new File(imagejDir, "\ufeffAnimals");
    assertTrue(animalsDir.isDirectory());
    assertTrue(new File(fileDir, "New.py").exists());
    assertTrue(new File(fileDir, "\ufeffOpen.py").exists());
    assertTrue(new File(fileDir, "\ufeff\ufeffSave.py").exists());
    assertTrue(new File(fileDir, "\ufeff\ufeff\ufeffExit.py").exists());
    assertTrue(new File(animalsDir, "Lion.py").exists());
    assertTrue(new File(animalsDir, "\ufeffTiger.py").exists());
    assertTrue(new File(animalsDir, "\ufeff\ufeffBear.py").exists());
    FileUtils.deleteRecursively(tempDir);
}
Also used : Context(org.scijava.Context) ArrayList(java.util.ArrayList) CommandService(org.scijava.command.CommandService) AppService(org.scijava.app.AppService) Service(org.scijava.service.Service) MenuService(org.scijava.menu.MenuService) PluginIndex(org.scijava.plugin.PluginIndex) Command(org.scijava.command.Command) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Context (org.scijava.Context)1 AppService (org.scijava.app.AppService)1 Command (org.scijava.command.Command)1 CommandService (org.scijava.command.CommandService)1 MenuService (org.scijava.menu.MenuService)1 PluginIndex (org.scijava.plugin.PluginIndex)1 Service (org.scijava.service.Service)1