Skip to content

Commit 3a2aa7e

Browse files
ctruedenclaude
andcommitted
scijava-cli: run the same commands without a display
One component where SciJava Common had three packages (console, main, run): scijava "Gaussian Blur" --sigma 2.5 --edges Wrap scijava blur.groovy --sigma=2.5 scijava --list filters scijava --help "Gaussian Blur" A command is named the way a person names it -- menu path, label, or the tail of a class name -- matched forgivingly about case, spacing and a trailing ellipsis. An exact label beats a partial one, so "Brightness" still reaches Brightness... although Brightness/Contrast... exists; where two answer equally it lists them instead of guessing. `--option value` pairs are the inputs, arriving as strings that scijava-convert3 turns into whatever the parameters declared -- the same path a script header and a text field take, which is why the command line needed no conversion code of its own. --help and --list read the same metadata the menus and dialogs read; nothing describes a command twice. There is no canRunHeadless(). SciJava Common needed it because harvesting was tangled with the UI; here the harvester is one preprocessor among several and this runner installs none. A command that cannot get an input it needs is declined, with a reason, through the mechanism a dismissed dialog already uses. Not ported: ConsoleService and ConsoleArgument, whose pluggable-argument mechanism earns its place when a component actually needs to add an argument -- until then a forty-line parser does. MainService has no equivalent either: main is a method. Also fixes a hang in the JavaFX binding, found when this machine had no DISPLAY today. FxThread.start() treated IllegalStateException as "somebody else started the toolkit", but JavaFX throws the same exception for "startup called twice" -- so after a failed first start, the second call declared success and every runLater afterwards waited on a latch nothing would count down. The build did not fail; it hung, which is worse. A failure is now remembered and rethrown, and the startup wait is bounded. The wait for *work* deliberately keeps no timeout: a modal dialog lives inside it for as long as the user takes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NShAz21gbEHnGzhVnC47cb
1 parent 1d8efbd commit 3a2aa7e

11 files changed

Lines changed: 1318 additions & 12 deletions

File tree

‎docs/migration-plan.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,41 @@ widgets and watching its callbacks fire.
969969
which is honest but shows an empty chooser. It is a one-line change in
970970
either direction and wants a look at real dialogs before being made.
971971

972+
### The command line
973+
974+
**`scijava-cli`** (`org.scijava.cli`) is built: one component where SciJava
975+
Common had three packages (`console`, `main`, `run`).
976+
977+
```
978+
scijava "Gaussian Blur" --sigma 2.5 --edges Wrap
979+
scijava blur.groovy --sigma=2.5
980+
scijava --list filters
981+
scijava --help "Gaussian Blur"
982+
```
983+
984+
- **A command is named the way a person would name it** - by menu path, by
985+
label, by the tail of its class name - and matching is forgiving about case,
986+
spacing and a trailing ellipsis. An exact label beats a partial one, so
987+
"Brightness" still reaches `Brightness...` although
988+
`Brightness/Contrast...` exists; where two answer equally, it lists them
989+
rather than guessing.
990+
- **`--option value` pairs are the inputs**, and they arrive as strings that
991+
`scijava-convert3` turns into whatever the parameters declared. That is the
992+
same path a script header and a text field take, which is why the command
993+
line needed no conversion code of its own.
994+
- **There is no `canRunHeadless()`.** SciJava Common needed it because
995+
harvesting was tangled with the UI; here the harvester is one preprocessor
996+
among several and this runner simply does not install one. A command that
997+
cannot get an input it needs is declined, with a reason, through the
998+
mechanism a dismissed dialog already uses.
999+
- **`--help` reads the same metadata the menus and dialogs read**: labels,
1000+
types, choices, which inputs are optional. Nothing describes a command
1001+
twice.
1002+
- **Not ported**: `ConsoleService` and `ConsoleArgument`, the pluggable
1003+
argument mechanism. It earns its place when a component actually needs to
1004+
add an argument, and until then a parser of some forty lines does. `MainService`
1005+
has no equivalent either - `main` is a method.
1006+
9721007
### Phase 4 — UI and desktop
9731008

9741009
- **`scijava-harvest`** (`org.scijava.harvest`): the model behind a parameter

‎docs/migration.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ A **dropped** row is a successful outcome, not a gap.
134134
| `input`, `tool` | UI-agnostic facades on `scijava-events` (Phase 4) | planned |
135135
| `display` | overhauled, not ported (Phase 4) | open |
136136
| `platform`, `ui.dnd` | `scijava-desktop` modernization (Phase 4) | planned |
137-
| `console`, `main`, `run` | single CLI module (Phase 4) | planned |
138-
| `startup` | standalone module (Phase 4) | planned |
137+
| `console`, `main`, `run` | `org.scijava.cli`: one component where SciJava Common had three packages. `Cli.run(args)` finds a command by menu path, label or class name, binds `--option value` pairs as its inputs (converted by `scijava-convert3`, so a shell's strings reach typed parameters), runs it through the same `Runner` a dialog uses, and prints its outputs. `--list [text]` and `--help <command>` read the same metadata the menus do. `ConsoleService`/`ConsoleArgument` have no equivalent yet: the pluggable-argument mechanism earns its place when a component actually needs to add an argument. `CodeRunner`/`RunService` are subsumed - a script path is a command like any other. `MainService` has no equivalent: `main` is a method | ported |
138+
| `startup` | folded into the application layer rather than ported: `StartupService` is a registry of hooks, and the thing actually missing is the assembly - gather commands from the index, from scripts, from the legacy bridge - which the three demo shells and the CLI each do for themselves (Phase 4) | planned |
139139
| `welcome`, `download`, `text`, `options` | likely dropped | open |
140140
| `minimaven`, `test` | out of scope | dropped |

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<module>scijava-awt</module>
6161
<module>scijava-bridge</module>
6262
<module>scijava-compat</module>
63+
<module>scijava-cli</module>
6364
<module>scijava-collections</module>
6465
<module>scijava-command3</module>
6566
<module>scijava-common3</module>

‎scijava-cli/pom.xml‎

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.scijava</groupId>
7+
<artifactId>pom-scijava</artifactId>
8+
<version>44.0.0</version>
9+
<relativePath />
10+
</parent>
11+
12+
<artifactId>scijava-cli</artifactId>
13+
<!--
14+
NB: the major version tracks the incarnation, per the incubator README.
15+
The 1.x.y of the other components is a legacy of the first monoversioned
16+
release, not the intended scheme.
17+
-->
18+
<version>1.0.0-SNAPSHOT</version>
19+
20+
<name>SciJava CLI</name>
21+
<description>Running commands and scripts from a command line.</description>
22+
<url>https://github.com/scijava/scijava</url>
23+
<inceptionYear>2026</inceptionYear>
24+
<organization>
25+
<name>SciJava</name>
26+
<url>https://scijava.org/</url>
27+
</organization>
28+
<licenses>
29+
<license>
30+
<name>Simplified BSD License</name>
31+
<distribution>repo</distribution>
32+
</license>
33+
</licenses>
34+
35+
<developers>
36+
<developer>
37+
<id>ctrueden</id>
38+
<name>Curtis Rueden</name>
39+
<roles>
40+
<role>founder</role>
41+
<role>lead</role>
42+
<role>reviewer</role>
43+
<role>support</role>
44+
<role>maintainer</role>
45+
</roles>
46+
</developer>
47+
<developer>
48+
<id>gselzer</id>
49+
<name>Gabriel Selzer</name>
50+
<roles>
51+
<role>founder</role>
52+
<role>debugger</role>
53+
<role>reviewer</role>
54+
<role>support</role>
55+
</roles>
56+
</developer>
57+
</developers>
58+
<contributors>
59+
<contributor>
60+
<name>Johannes Schindelin</name>
61+
<properties><id>dscho</id></properties>
62+
</contributor>
63+
</contributors>
64+
65+
<mailingLists>
66+
<mailingList>
67+
<name>Image.sc Forum</name>
68+
<archive>https://forum.image.sc/tag/scijava</archive>
69+
</mailingList>
70+
</mailingLists>
71+
72+
<scm>
73+
<connection>scm:git:https://github.com/scijava/scijava</connection>
74+
<developerConnection>scm:git:git@github.com:scijava/scijava</developerConnection>
75+
<tag>HEAD</tag>
76+
<url>https://github.com/scijava/scijava</url>
77+
</scm>
78+
<issueManagement>
79+
<system>GitHub Issues</system>
80+
<url>https://github.com/scijava/scijava/issues</url>
81+
</issueManagement>
82+
<ciManagement>
83+
<system>GitHub Actions</system>
84+
<url>https://github.com/scijava/scijava/actions</url>
85+
</ciManagement>
86+
87+
<properties>
88+
<package-name>org.scijava.cli</package-name>
89+
90+
<license.licenseName>bsd_2</license.licenseName>
91+
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
92+
93+
<!-- Note: These versions must match across all component POMs! -->
94+
<scijava-command3.version>3.0.0-SNAPSHOT</scijava-command3.version>
95+
<scijava-common3.version>1.0.1-SNAPSHOT</scijava-common3.version>
96+
<scijava-context.version>1.0.0-SNAPSHOT</scijava-context.version>
97+
<scijava-discovery.version>1.0.1-SNAPSHOT</scijava-discovery.version>
98+
<scijava-index.version>1.0.0-SNAPSHOT</scijava-index.version>
99+
<scijava-script3.version>3.0.0-SNAPSHOT</scijava-script3.version>
100+
<scijava-convert3.version>3.0.0-SNAPSHOT</scijava-convert3.version>
101+
<scijava-execute.version>1.0.0-SNAPSHOT</scijava-execute.version>
102+
<scijava-priority.version>1.0.1-SNAPSHOT</scijava-priority.version>
103+
<scijava-struct.version>1.0.1-SNAPSHOT</scijava-struct.version>
104+
</properties>
105+
106+
<dependencies>
107+
<!--
108+
NB: commands come from wherever the caller found them - the annotation
109+
index, a scripts directory, the legacy bridge - so this component
110+
depends on the command layer and the script layer, and on no source of
111+
commands in particular.
112+
-->
113+
<dependency>
114+
<groupId>org.scijava</groupId>
115+
<artifactId>scijava-command3</artifactId>
116+
<version>${scijava-command3.version}</version>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.scijava</groupId>
120+
<artifactId>scijava-context</artifactId>
121+
<version>${scijava-context.version}</version>
122+
</dependency>
123+
<!--
124+
NB: pinned although no import here names it. Discovering commands goes
125+
through it, and an unpinned SciJava dependency resolves whatever is
126+
released rather than what is in this reactor.
127+
-->
128+
<dependency>
129+
<groupId>org.scijava</groupId>
130+
<artifactId>scijava-discovery</artifactId>
131+
<version>${scijava-discovery.version}</version>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.scijava</groupId>
135+
<artifactId>scijava-index</artifactId>
136+
<version>${scijava-index.version}</version>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.scijava</groupId>
140+
<artifactId>scijava-script3</artifactId>
141+
<version>${scijava-script3.version}</version>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.scijava</groupId>
145+
<artifactId>scijava-common3</artifactId>
146+
<version>${scijava-common3.version}</version>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.scijava</groupId>
150+
<artifactId>scijava-convert3</artifactId>
151+
<version>${scijava-convert3.version}</version>
152+
</dependency>
153+
<dependency>
154+
<groupId>org.scijava</groupId>
155+
<artifactId>scijava-execute</artifactId>
156+
<version>${scijava-execute.version}</version>
157+
</dependency>
158+
<dependency>
159+
<groupId>org.scijava</groupId>
160+
<artifactId>scijava-priority</artifactId>
161+
<version>${scijava-priority.version}</version>
162+
</dependency>
163+
<dependency>
164+
<groupId>org.scijava</groupId>
165+
<artifactId>scijava-struct</artifactId>
166+
<version>${scijava-struct.version}</version>
167+
</dependency>
168+
169+
<!-- Test scope dependencies -->
170+
<!--
171+
NB: a real engine, so that the tests exercise a language rather than a
172+
stand-in. Any JSR-223 engine on the classpath is discovered the same
173+
way; Groovy is simply the one Fiji users meet first.
174+
-->
175+
<dependency>
176+
<groupId>org.apache.groovy</groupId>
177+
<artifactId>groovy</artifactId>
178+
<scope>test</scope>
179+
</dependency>
180+
<dependency>
181+
<groupId>org.apache.groovy</groupId>
182+
<artifactId>groovy-jsr223</artifactId>
183+
<scope>test</scope>
184+
</dependency>
185+
<dependency>
186+
<groupId>org.junit.jupiter</groupId>
187+
<artifactId>junit-jupiter-api</artifactId>
188+
<scope>test</scope>
189+
</dependency>
190+
</dependencies>
191+
192+
<build>
193+
<plugins>
194+
<!-- NB: the annotation index, for the test commands. -->
195+
<plugin>
196+
<artifactId>maven-compiler-plugin</artifactId>
197+
<configuration>
198+
<annotationProcessorPaths>
199+
<path>
200+
<groupId>org.scijava</groupId>
201+
<artifactId>scijava-index</artifactId>
202+
<version>${scijava-index.version}</version>
203+
</path>
204+
</annotationProcessorPaths>
205+
</configuration>
206+
</plugin>
207+
<plugin>
208+
<artifactId>maven-enforcer-plugin</artifactId>
209+
<executions>
210+
<execution>
211+
<id>enforce-package-rules</id>
212+
<goals>
213+
<goal>enforce</goal>
214+
</goals>
215+
<phase>test</phase>
216+
<configuration>
217+
<rules>
218+
<NoPackageCyclesRule implementation="org.scijava.maven.plugin.enforcer.NoPackageCyclesRule" />
219+
<NoSubpackageDependenceRule implementation="org.scijava.maven.plugin.enforcer.NoSubpackageDependenceRule" />
220+
</rules>
221+
</configuration>
222+
</execution>
223+
</executions>
224+
</plugin>
225+
<plugin>
226+
<artifactId>maven-javadoc-plugin</artifactId>
227+
<configuration>
228+
<links>
229+
<link>https://javadoc.scijava.org/Java11/</link>
230+
</links>
231+
</configuration>
232+
</plugin>
233+
</plugins>
234+
</build>
235+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* #%L
3+
* Running commands and scripts from a command line.
4+
* %%
5+
* Copyright (C) 2026 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
module org.scijava.cli {
31+
32+
exports org.scijava.cli;
33+
34+
// NB: one opens, to the container alone. Nothing in this component's main
35+
// sources is a plugin, but its tests declare commands in this package, and
36+
// surefire patches them into this module -- so without it the container
37+
// cannot construct them. `opens` is not `exports`.
38+
opens org.scijava.cli to org.scijava.context;
39+
40+
requires transitive org.scijava.command3;
41+
requires transitive org.scijava.execute;
42+
requires transitive org.scijava.script3;
43+
requires org.scijava.common3;
44+
requires org.scijava.context;
45+
requires org.scijava.struct;
46+
47+
}

0 commit comments

Comments
 (0)