Skip to content

Commit 49cd928

Browse files
gselzerctrueden
authored andcommitted
Create SciJava Discovery Plugin
1 parent 897c14b commit 49cd928

14 files changed

Lines changed: 217 additions & 4 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<module>imagej/imagej-ops2</module>
4949
<module>imagej/imagej-testutil</module>
5050
<module>scijava/scijava-discovery</module>
51+
<module>scijava/scijava-discovery-plugin</module>
5152
<module>scijava/scijava-discovery-therapi</module>
5253
<module>scijava/scijava-function</module>
5354
<module>scijava/scijava-log2</module>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.apt_generated/
2+
/.apt_generated_tests/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2016 - 2019, SciJava Ops developers.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
POSSIBILITY OF SUCH DAMAGE.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SciJava Discovery Plugin: A Discoverer implementation backed by SciJava Common's `PluginService`
2+
3+
This module provides the `PluginBasedDiscoverer`, a `Discoverer` implementation that uses [SciJava Common](https://github.com/scijava/scijava-common)'s annotation processor to create `Discovery` objects. `Plugin` `Class`es are wrapped into `Discovery` objects, and are returned via `PluginBasedDiscoverer.implsOfType()`. Please check out SciJava Common for instructions on developing `Plugin`s.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.scijava</groupId>
9+
<artifactId>scijava-incubator</artifactId>
10+
<version>0-SNAPSHOT</version>
11+
<relativePath>../..</relativePath>
12+
</parent>
13+
14+
<artifactId>scijava-discovery-plugin</artifactId>
15+
16+
<name>SciJava Discovery Plugin</name>
17+
<description>SciJava Discovery Plugin: A Discovery implementation backed by SciJava Common's PluginService</description>
18+
<url>https://github.com/scijava/scijava</url>
19+
<inceptionYear>2021</inceptionYear>
20+
<organization>
21+
<name>SciJava</name>
22+
<url>https://scijava.org/</url>
23+
</organization>
24+
<licenses>
25+
<license>
26+
<name>Simplified BSD License</name>
27+
<distribution>repo</distribution>
28+
</license>
29+
</licenses>
30+
31+
<developers>
32+
<developer>
33+
<id>ctrueden</id>
34+
<name>Curtis Rueden</name>
35+
<url>https://imagej.net/User:Rueden</url>
36+
<roles>
37+
<role>founder</role>
38+
<role>reviewer</role>
39+
<role>support</role>
40+
<role>maintainer</role>
41+
</roles>
42+
</developer>
43+
<developer>
44+
<id>gselzer</id>
45+
<name>Gabriel Selzer</name>
46+
<roles>
47+
<role>founder</role>
48+
<role>lead</role>
49+
<role>developer</role>
50+
<role>debugger</role>
51+
<role>reviewer</role>
52+
<role>support</role>
53+
</roles>
54+
</developer>
55+
</developers>
56+
<contributors>
57+
<contributor>
58+
<name>None</name>
59+
</contributor>
60+
</contributors>
61+
62+
<mailingLists>
63+
<mailingList>
64+
<name>Image.sc Forum</name>
65+
<archive>https://forum.image.sc/tags/scijava-discovery-plugin</archive>
66+
</mailingList>
67+
</mailingLists>
68+
69+
<scm>
70+
<connection>scm:git:git://github.com/scijava/incubator</connection>
71+
<developerConnection>scm:git:git@github.com:scijava/incubator</developerConnection>
72+
<tag>HEAD</tag>
73+
<url>https://github.com/scijava/incubator</url>
74+
</scm>
75+
<issueManagement>
76+
<system>GitHub Issues</system>
77+
<url>https://github.com/scijava/scijava/issues</url>
78+
</issueManagement>
79+
<ciManagement>
80+
<system>Travis CI</system>
81+
<url>https://travis-ci.com/scijava/incubator</url>
82+
</ciManagement>
83+
84+
<properties>
85+
<package-name>org.scijava.discovery.plugin</package-name>
86+
87+
<license.licenseName>bsd_2</license.licenseName>
88+
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
89+
<scijava-discovery-plugin.allowedDuplicateClasses>
90+
${scijava.allowedDuplicateClasses}
91+
</scijava-discovery-plugin.allowedDuplicateClasses>
92+
<allowedDuplicateClasses>${scijava-discovery-plugin.allowedDuplicateClasses}</allowedDuplicateClasses>
93+
<therapi.packages></therapi.packages>
94+
</properties>
95+
<dependencies>
96+
<dependency>
97+
<groupId>org.scijava</groupId>
98+
<artifactId>scijava-common</artifactId>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.scijava</groupId>
102+
<artifactId>scijava-discovery</artifactId>
103+
<version>${project.version}</version>
104+
</dependency>
105+
<!-- Test scope dependencies -->
106+
<dependency>
107+
<groupId>junit</groupId>
108+
<artifactId>junit</artifactId>
109+
<scope>test</scope>
110+
</dependency>
111+
</dependencies>
112+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module org.scijava.discovery.plugin {
2+
3+
exports org.scijava.discovery.plugin;
4+
opens org.scijava.discovery.plugin to org.scijava;
5+
6+
requires org.scijava.discovery;
7+
requires transitive org.scijava;
8+
}

scijava/scijava-ops-engine/src/main/java/org/scijava/ops/engine/impl/PluginBasedDiscoverer.java renamed to scijava/scijava-discovery-plugin/src/main/java/org/scijava/discovery/plugin/PluginBasedDiscoverer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.scijava.ops.engine.impl;
1+
package org.scijava.discovery.plugin;
22

33
import java.util.List;
44
import java.util.Objects;
@@ -17,8 +17,8 @@ public class PluginBasedDiscoverer implements Discoverer {
1717

1818
private final PluginService p;
1919

20-
public PluginBasedDiscoverer(Context ctx) {
21-
p = ctx.getService(PluginService.class);
20+
public PluginBasedDiscoverer(PluginService p) {
21+
this.p = p;
2222
}
2323

2424
@Override
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
package org.scijava.discovery.plugin;
3+
4+
import java.util.List;
5+
6+
import org.junit.Assert;
7+
import org.junit.AfterClass;
8+
import org.junit.BeforeClass;
9+
import org.junit.Test;
10+
import org.scijava.Context;
11+
import org.scijava.discovery.Discoverer;
12+
import org.scijava.plugin.PluginService;
13+
14+
public class PluginDiscovererTest {
15+
16+
private static Context ctx;
17+
private static PluginService plugins;
18+
19+
@BeforeClass
20+
public static void setUp() {
21+
ctx = new Context(PluginService.class);
22+
plugins = ctx.getService(PluginService.class);
23+
}
24+
25+
@AfterClass
26+
public static void tearDown() throws Exception {
27+
ctx.close();
28+
plugins = null;
29+
}
30+
31+
@Test
32+
public void testPluginDiscovery() {
33+
Discoverer d = new PluginBasedDiscoverer(plugins);
34+
List<Class<TestPlugin>> implsOfType = d.implsOfType(TestPlugin.class);
35+
Assert.assertTrue(implsOfType.contains(TestPluginImpl.class));
36+
}
37+
38+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.scijava.discovery.plugin;
2+
3+
import org.scijava.plugin.SciJavaPlugin;
4+
5+
public interface TestPlugin extends SciJavaPlugin {
6+
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.scijava.discovery.plugin;
2+
3+
import org.scijava.plugin.Plugin;
4+
5+
@Plugin(type = TestPlugin.class)
6+
public class TestPluginImpl implements TestPlugin {
7+
8+
}

0 commit comments

Comments
 (0)