Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Therapi Discovery in ImageJ Ops2 #49

Merged
merged 3 commits into from
Jun 30, 2022

Conversation

gselzer
Copy link
Member

@gselzer gselzer commented Nov 15, 2021

This PR follows #48 as the second PR designed to purge SciJava Common 2 from the Incubator projects. It:

  • Refactors @Plugin definitions as @implNotes, consistent with the methodology described in Therapi-based Discovery #44.
  • Removes the vast majority of, if not all, @Plugin and Priority imports from the ImageJ Ops2 module.

@gselzer gselzer requested a review from ctrueden November 15, 2021 22:40
@gselzer gselzer force-pushed the imagej/imagej-ops2/plugin-purging branch 2 times, most recently from d963982 to 80d0e2c Compare November 16, 2021 19:20
@gselzer gselzer force-pushed the imagej/imagej-ops2/plugin-purging branch from 80d0e2c to 367d716 Compare November 16, 2021 20:26
@ctrueden ctrueden self-assigned this Nov 22, 2021
@gselzer gselzer force-pushed the imagej/imagej-ops2/plugin-purging branch from 367d716 to d9909fd Compare January 14, 2022 17:14
gselzer added 2 commits June 30, 2022 15:47
Using perl commands:

To get basic (type, name) plugins with some javadoc before

perl -0777 -i -pe 's/
\*\/\s*\@plugin\(\s*type\s*=\s*([^\.]*)[^n]*name\s*=\s*"\s*([^"]*)"\s*\)/
* \@implNote \L\1\E names="\2"\n *\//igs' **/*.java

To get basic (type, name, priority) plugins with some javadoc before

perl -0777 -i -pe 's/
\*\/\s*\@plugin\(\s*type\s*=\s*([^\.]*)[^n]*name\s*=\s*"\s*([^"]*)",\s*priority\s*=\s*([^,\s]*)\s*\)/
* \@implNote \L\1\E names="\2", priority="\3"\n *\//igs' **/*.java

To get basic (type, name, label, priority) plugins with some javadoc
before

perl -0777 -i -pe 's/
\*\/\s*\@plugin\(\s*type\s*=\s*([^\.]*)[^n]*name\s*=\s*"\s*([^"]*)",\s*label\s*=\s*"([^"]*)"\s*,\s*priority\s*=\s*([^,\s]*)\s*\)/
      * \@implNote \L\1\E names="\2", label="\3", priority="\4"\n
      *\//igs' **/*.java

To get basic (type, name, label) plugins with some javadoc
before

perl -0777 -i -pe 's/
\*\/\s*\@plugin\(\s*type\s*=\s*([^\.]*)[^n]*name\s*=\s*"\s*([^"]*)",\s*label\s*=\s*"([^"]*)"\s*\)/
    * \@implNote \L\1\E names="\2", label="\3"\n *\//igs' **/*.java

To get basic (type, name) plugins with no javadoc
before

perl -0777 -i -pe
's/\@plugin\(\s*type\s*=\s*([^\.]*)[^n]*name\s*=\s*"\s*([^"]*)"\s*\)/\/**\n
* \@implNote \L\1\E names="\2"\n *\//igs' **/*.java

To get basic (type, name, priority) plugins with no javadoc
before

perl -0777 -i -pe
's/\@plugin\(\s*type\s*=\s*([^\.]*)[^n]*name\s*=\s*"\s*([^"]*)",\s*priority\s*=\s*([^,\s]*)\s*\)/\/**\n
* \@implNote \L\1\E names="\2", priority="\3"\n *\//igs' **/*.java

After using these commands, remaining Ops were converted manually

We then need to convert the double quotes in the created implNotes into
single quotes. We do this with the following commands:

perl -0777 -i -pe "s/ \@implnote op names=\"([^\"]*)\"/\@implNote op
names='\1'/igs" **/*.java

perl -0777 -i -pe "s/\*(\s*)\@implNote op(.*'.*'),
     priority=\"([^\"]*)\"/\* \@implNote op\2, priority='\3'/igs"
     **/*.java

perl -0777 -i -pe "s/\*(\s*)\@implNote op(.*'.*'), label=\"([^\"]*)\"/\*
\@implNote op\2, label='\3'/igs" **/*.java

perl -0777 -i -pe "s/\*(\s*)\@implNote op(.*'.*'),
     priority=\"([^\"]*)\"/\* \@implNote op\2, priority='\3'/igs"
     **/*.java

Again, after running these command, remaining implNotes were fixed

Then, we convert the SciJava Priority enums to numbers (as SciJava
    Discovery Therapi doesn't support Priority (yet)):

sed -i -e "s/'Priority.VERY_HIGH'/'10000.'/g" **/*.java
sed -i -e "s/'Priority.HIGH'/'100.'/g" **/*.java
sed -i -e "s/'Priority.LOW'/'100.'/g" **/*.java
First, the parameters were converted to custom taglets (manually, sob).

Then the following perl commands were used to convert OpField
annotations into implNotes:

perl -0777 -i -pe
"s/(\s*)\*\/(\s*)\@OpField\(\s*names\s*=\s*\"([^\"]*)\"\s*,\s*params\s*=\s*\"[^\"]*\"\s*,\s*priority\s*=\s*([^\)]*)\)/\1*
\@implNote op names='\3', priority='\4'\1*\/\2\@FlopField/igs" **/*.java

perl -0777 -i -pe
"s/(\s*)\*\/(\s*)\@OpField\(\s*names\s*=\s*\"([^\"]*)\"\s*,\s*params\s*=\s*\"[^\"]*\"[^\)]*\)/\1*
\@implNote op names='\3'\1*\/\2\@FlopField/igs" **/*.java

Then I realized I had left my @FlopField indicator string in, yielding
the usage of the sed command:

sed -i -e '/@FlopField/d' **/*.java

Now I continue:

perl -0777 -i -pe
"s/(\s*)\*\/(\s*)\@OpField\(\s*names\s*=\s*\"([^\"]*)\"[^\)]*\)/\1*
\@implNote op names='\3'\1*\//igs" **/*.java

Of course, there are some with @SuppressWarnings annotations *sigh*

perl -0777 -i -pe
"s/(\s*)\*\/(\s*)\@OpField\(\s*names\s*=\s*\"([^\"]*)\"[^\)]*\)/\1*
\@implNote op names='\3'\1*\//igs" **/*.java

Continuing on:

perl -0777 -i -pe "s/([\t
]*)\@OpField\(\s*names\s*=\s*\"([^\"]*)\"\s*,\s*priority\s*=\s*([^\)]*)\s*\)/\1\/**\n\1
* \@implNote op names='\2', priority='\3'\n\1 *\//igs" **/*.java

perl -0777 -i -pe "s/([\t
]*)\@OpField\(\s*names\s*=\s*\"([^\"]*)\"[^\)]*\)/\1\/**\n\1 *
\@implNote op names='\2'\n\1 *\//igs" **/*.java

Finally, we rename the priorities to their decimal value. See last
commmit for method
@ctrueden ctrueden force-pushed the imagej/imagej-ops2/plugin-purging branch from d9909fd to a910289 Compare June 30, 2022 21:36
And fix a couple of warnings.

Co-authored-by: Curtis Rueden <[email protected]>
@ctrueden ctrueden force-pushed the imagej/imagej-ops2/plugin-purging branch from a910289 to 8a62ad7 Compare June 30, 2022 21:39
Copy link
Member

@ctrueden ctrueden left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you for documenting the perl commands used. That could conceivably come in handy later (or at least educate someone on how to do this sort of work).

I squashed your import cleaning commits, and did my own import cleaning pass, since there were still many unused ones left.

I will note that I got some nondeterministic test failures on my system, where ops or their dependencies sometimes could not be matched. I am inclined to blame Eclipse, even though I tried to have the projects closed in Eclipse any time I ran tests from the command line. Anyway, the last couple of rounds of testing built successfully for me, so I'm going to move ahead with this.

@ctrueden ctrueden merged commit c893de5 into main Jun 30, 2022
@ctrueden ctrueden deleted the imagej/imagej-ops2/plugin-purging branch June 30, 2022 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants