Skip to content
This repository was archived by the owner on Oct 26, 2026. It is now read-only.

Improve Discovery Framework for use in Ops API - #51

Merged
ctrueden merged 8 commits into
mainfrom
scijava/scijava-discovery/simplification
Jun 30, 2022
Merged

ctrueden merged 8 commits into
mainfrom
scijava/scijava-discovery/simplification

Conversation

@gselzer

@gselzer gselzer commented Nov 29, 2021 •

Copy link
Copy Markdown
Member

This PR greatly simplifies the Discoverer API, as well as adding some new functionality via static Discoverer methods. The highlights are listed below:

  • Discoverer.all(): Returns all Discoverers provided as Services, in addition to a Discoverer that is backed by ServiceLoader.
  • Discoverer.union(Iterable<Discoverer> itr): allows the combination of multiple Discoverers into one uber-Discoverer
  • Discoverer.onlyFor(Class<?>... classes): allows the usage of Discoverer for a subset of classes, very useful for backend implementation discovery (i.e. if you want to run an OpEnvironment with all known MatchingRoutines, but not all known Ops. Discoverer.except() provides the reverse.
    These methods allow for powerful syntax like
		Discoverer serviceLoading = Discoverer.using(ServiceLoader::load) //
				.onlyFor( //
						OpWrapper.class, //
						MatchingRoutine.class, //
						OpInfoGenerator.class, //
						InfoChainGenerator.class //
				);

This syntax is used in AbstractTestEnvironment to get all known OpWrappers, MatchingRoutines, OpInfoGenerators, and InfoChainGenerators, and nothing else. This allows extending tests to obtain all of these useful backend implementations while removing the burden of being slowed down by all known Ops.

The end goal of this PR was to make it easy for an OpEnvironment to take an Object and extract OpInfos from it. To this end, the method makeDiscoverable(Object... objects) was added to OpEnvironment.

TODO:

  • It seems that almost every incubator build, at least one random ImageJ Ops2 test fails due to a matching error. I haven't been able to replicate this issue with any particular test. Should this be a blocker to merging?

Closes scijava/scijava#80

@gselzer
gselzer force-pushed the scijava/scijava-discovery/simplification branch 5 times, most recently from 7d0a944 to 2cf3ff1 Compare December 3, 2021 17:25
@gselzer
gselzer force-pushed the scijava/scijava-discovery/simplification branch from 2cf3ff1 to 2d59829 Compare January 14, 2022 17:16
gselzer added 8 commits June 30, 2022 17:02
StaticDiscoverer has been simplified and renamed

TODO: For some reason, ConcatenateViewTest failed. WE should check that
out
This allows people to register all OpInfos "contained" in a class
through the syntax

ops.register(ops.infosFrom(<your class instance here>))

It's somewhat readable
TODO: Make sure we don't get two instances of OpInfos using this along
with the natural discovery of Ops.
@ctrueden
ctrueden force-pushed the scijava/scijava-discovery/simplification branch from 2d59829 to 0dca4e4 Compare June 30, 2022 22:02

@ctrueden ctrueden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with this as a big step forward! I like the transition from Discoverer as interface required for all types of discoveries, to Object as primary currency.

}
}
catch (IOException exc) {
} catch (IOException exc) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on with the curly braces here? Are we changing code styles?

@ctrueden
ctrueden merged commit acec388 into main Jun 30, 2022
@ctrueden
ctrueden deleted the scijava/scijava-discovery/simplification branch June 30, 2022 22:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add OpEnvironment API to Generate OpInfos from a Collection/Array of Classes

2 participants