Skip to content

Commit da6fe26

Browse files
committed
version 3.0, updated mvn plugins, syntax changes.
1 parent 8a03232 commit da6fe26

302 files changed

Lines changed: 6276 additions & 6186 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aesh/pom.xml

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
<parent>
2525
<groupId>org.aesh</groupId>
2626
<artifactId>aesh-all</artifactId>
27-
<version>3.0-dev</version>
27+
<version>3.0</version>
2828
</parent>
2929
<modelVersion>4.0.0</modelVersion>
3030

3131
<groupId>org.aesh</groupId>
3232
<artifactId>aesh</artifactId>
3333
<packaging>jar</packaging>
34-
<version>3.0-dev</version>
34+
<version>3.0</version>
3535
<name>Æsh</name>
3636
<description>Æsh (Another Extendable SHell)</description>
3737
<scm>
@@ -105,39 +105,6 @@
105105
</execution>
106106
</executions>
107107
</plugin>
108-
<plugin>
109-
<groupId>org.apache.maven.plugins</groupId>
110-
<artifactId>maven-source-plugin</artifactId>
111-
<executions>
112-
<execution>
113-
<id>attach-sources</id>
114-
<phase>verify</phase>
115-
<goals>
116-
<goal>jar-no-fork</goal>
117-
</goals>
118-
</execution>
119-
</executions>
120-
</plugin>
121-
<plugin>
122-
<groupId>org.apache.maven.plugins</groupId>
123-
<artifactId>maven-checkstyle-plugin</artifactId>
124-
<executions>
125-
<execution>
126-
<id>validate</id>
127-
<phase>validate</phase>
128-
<configuration>
129-
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
130-
<consoleOutput>true</consoleOutput>
131-
<failsOnError>true</failsOnError>
132-
<useFile/>
133-
<includeTestSourceDirectory>true</includeTestSourceDirectory>
134-
</configuration>
135-
<goals>
136-
<goal>check</goal>
137-
</goals>
138-
</execution>
139-
</executions>
140-
</plugin>
141108
</plugins>
142109
</build>
143110

aesh/src/main/java/org/aesh/AeshConsoleRunner.java

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* JBoss, Home of Professional Open Source
33
* Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors
4-
* as indicated by the @authors tag. All rights reserved.
4+
* as indicated by the @authors tag
55
* See the copyright.txt in the distribution for a
66
* full listing of individual contributors.
77
*
@@ -19,6 +19,8 @@
1919
*/
2020
package org.aesh;
2121

22+
import java.io.IOException;
23+
2224
import org.aesh.command.Command;
2325
import org.aesh.command.CommandDefinition;
2426
import org.aesh.command.CommandResult;
@@ -28,16 +30,14 @@
2830
import org.aesh.command.registry.CommandRegistryException;
2931
import org.aesh.command.settings.Settings;
3032
import org.aesh.command.settings.SettingsBuilder;
31-
import org.aesh.readline.Prompt;
3233
import org.aesh.console.ReadlineConsole;
34+
import org.aesh.readline.Prompt;
3335
import org.aesh.terminal.Connection;
3436

35-
import java.io.IOException;
36-
3737
/**
3838
* Use the AeshConsoleRunner when you want to easily create an interactive CLI application.
3939
*
40-
* @author <a href="mailto:stalep@gmail.com">Ståle Pedersen</a>
40+
* @author Aesh team
4141
*/
4242
public class AeshConsoleRunner {
4343
private AeshCommandRegistryBuilder<CommandInvocation> registryBuilder;
@@ -54,7 +54,7 @@ public static AeshConsoleRunner builder() {
5454
}
5555

5656
public AeshConsoleRunner commands(Class<? extends Command>... commands) {
57-
if(commands != null) {
57+
if (commands != null) {
5858
ensureRegistryBuilderInitialized();
5959
try {
6060
registryBuilder.commands(commands);
@@ -66,7 +66,7 @@ public AeshConsoleRunner commands(Class<? extends Command>... commands) {
6666
}
6767

6868
public AeshConsoleRunner command(Class<? extends Command> command) {
69-
if(command != null) {
69+
if (command != null) {
7070
ensureRegistryBuilderInitialized();
7171
try {
7272
registryBuilder.command(command);
@@ -78,24 +78,24 @@ public AeshConsoleRunner command(Class<? extends Command> command) {
7878
}
7979

8080
public AeshConsoleRunner commandRegistryBuilder(AeshCommandRegistryBuilder<CommandInvocation> commandRegistryBuilder) {
81-
if(registryBuilder != null) {
81+
if (registryBuilder != null) {
8282
throw new RuntimeException("Cannot set CommandRegistryBuilder after it has been initialized. " +
8383
"CommandRegistryBuilder must be set before adding any commands.");
8484
}
85-
if(commandRegistryBuilder != null) {
85+
if (commandRegistryBuilder != null) {
8686
this.registryBuilder = commandRegistryBuilder;
8787
}
8888
return this;
8989
}
9090

9191
private void ensureRegistryBuilderInitialized() {
92-
if(registryBuilder == null) {
92+
if (registryBuilder == null) {
9393
registryBuilder = AeshCommandRegistryBuilder.builder();
9494
}
9595
}
9696

9797
public AeshConsoleRunner settings(Settings settings) {
98-
if(settings != null)
98+
if (settings != null)
9999
this.settings = settings;
100100
return this;
101101
}
@@ -106,17 +106,17 @@ public AeshConsoleRunner connection(Connection connection) {
106106
}
107107

108108
public AeshConsoleRunner prompt(String prompt) {
109-
if(prompt != null)
109+
if (prompt != null)
110110
this.prompt = new Prompt(prompt);
111-
if(console != null && console.running())
111+
if (console != null && console.running())
112112
console.setPrompt(this.prompt);
113113
return this;
114114
}
115115

116116
public AeshConsoleRunner prompt(Prompt prompt) {
117-
if(prompt != null)
117+
if (prompt != null)
118118
this.prompt = prompt;
119-
if(console != null && console.running())
119+
if (console != null && console.running())
120120
console.setPrompt(this.prompt);
121121
return this;
122122
}
@@ -132,29 +132,28 @@ public AeshConsoleRunner addExitCommand() {
132132
}
133133

134134
public void start() {
135-
if(console == null) {
135+
if (console == null) {
136136
init();
137-
if(prompt != null)
137+
if (prompt != null)
138138
console.setPrompt(prompt);
139139
try {
140140
console.start();
141-
}
142-
catch (IOException e) {
143-
throw new RuntimeException("Exception while starting the console: "+e.getMessage());
141+
} catch (IOException e) {
142+
throw new RuntimeException("Exception while starting the console: " + e.getMessage());
144143
}
145144
}
146145
}
147146

148147
public void stop() {
149-
if(console != null && console.running())
148+
if (console != null && console.running())
150149
console.stop();
151150
}
152151

153152
@SuppressWarnings("unchecked")
154153
private void init() {
155154
// Build the command registry from the builder
156155
CommandRegistry<CommandInvocation> builtRegistry = null;
157-
if(registryBuilder != null) {
156+
if (registryBuilder != null) {
158157
try {
159158
builtRegistry = registryBuilder.create();
160159
} catch (Exception e) {
@@ -163,58 +162,58 @@ private void init() {
163162
}
164163

165164
// Check if both builder and settings.commandRegistry have commands
166-
if(builtRegistry != null && !builtRegistry.getAllCommandNames().isEmpty() &&
165+
if (builtRegistry != null && !builtRegistry.getAllCommandNames().isEmpty() &&
167166
settings != null && settings.commandRegistry() != null &&
168167
!settings.commandRegistry().getAllCommandNames().isEmpty()) {
169-
throw new RuntimeException("Cannot define commands in both AeshConsoleRunner (via command() or commandRegistryBuilder()) " +
170-
"and Settings.commandRegistry(). Please use only one method to specify commands.");
168+
throw new RuntimeException(
169+
"Cannot define commands in both AeshConsoleRunner (via command() or commandRegistryBuilder()) " +
170+
"and Settings.commandRegistry(). Please use only one method to specify commands.");
171171
}
172172

173173
// Determine which registry to use
174174
CommandRegistry<CommandInvocation> finalRegistry = null;
175-
if(builtRegistry != null && !builtRegistry.getAllCommandNames().isEmpty()) {
175+
if (builtRegistry != null && !builtRegistry.getAllCommandNames().isEmpty()) {
176176
finalRegistry = builtRegistry;
177-
} else if(settings != null && settings.commandRegistry() != null &&
177+
} else if (settings != null && settings.commandRegistry() != null &&
178178
!settings.commandRegistry().getAllCommandNames().isEmpty()) {
179179
finalRegistry = settings.commandRegistry();
180180
}
181181

182182
// Validate that we have at least one command
183-
if(finalRegistry == null || finalRegistry.getAllCommandNames().isEmpty()) {
183+
if (finalRegistry == null || finalRegistry.getAllCommandNames().isEmpty()) {
184184
throw new RuntimeException("No commands added, nothing to run");
185185
}
186186

187187
try {
188-
if(settings == null) {
188+
if (settings == null) {
189189
settings = SettingsBuilder.builder()
190-
.commandRegistry(finalRegistry)
191-
.enableAlias(false)
192-
.enableExport(false)
193-
.enableMan(false)
194-
.persistHistory(false)
195-
.connection(connection)
196-
.build();
190+
.commandRegistry(finalRegistry)
191+
.enableAlias(false)
192+
.enableExport(false)
193+
.enableMan(false)
194+
.persistHistory(false)
195+
.connection(connection)
196+
.build();
197197
}
198198
// User added their own settings object, but we need to add or replace the registry
199-
else if(settings.commandRegistry() == null ||
199+
else if (settings.commandRegistry() == null ||
200200
settings.commandRegistry().getAllCommandNames().isEmpty()) {
201201
SettingsBuilder settingsBuilder = new SettingsBuilder(settings)
202-
.commandRegistry(finalRegistry);
202+
.commandRegistry(finalRegistry);
203203

204-
if(connection != null)
204+
if (connection != null)
205205
settingsBuilder.connection(connection);
206206

207207
settings = settingsBuilder.build();
208208
}
209209

210210
console = new ReadlineConsole(settings);
211-
}
212-
catch (Exception e) {
211+
} catch (Exception e) {
213212
throw new RuntimeException("Error when initializing console: " + e.getMessage(), e);
214213
}
215214
}
216215

217-
@CommandDefinition(name = "exit", description = "exit the program", aliases = {"quit"})
216+
@CommandDefinition(name = "exit", description = "exit the program", aliases = { "quit" })
218217
public static class ExitCommand implements Command {
219218
@Override
220219
public CommandResult execute(CommandInvocation commandInvocation) {

aesh/src/main/java/org/aesh/AeshRuntimeRunner.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* JBoss, Home of Professional Open Source
33
* Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors
4-
* as indicated by the @authors tag. All rights reserved.
4+
* as indicated by the @authors tag
55
* See the copyright.txt in the distribution for a
66
* full listing of individual contributors.
77
*
@@ -35,15 +35,14 @@
3535
import org.aesh.command.validator.CommandValidatorException;
3636
import org.aesh.command.validator.OptionValidatorException;
3737
import org.aesh.console.ShellImpl;
38-
import org.aesh.terminal.tty.TerminalConnection;
3938
import org.aesh.terminal.Connection;
39+
import org.aesh.terminal.tty.TerminalConnection;
4040

4141
/**
42-
* @author <a href="mailto:stalep@gmail.com">Ståle Pedersen</a>
42+
* @author Aesh team
4343
*/
4444
public class AeshRuntimeRunner {
4545

46-
4746
private CommandRuntime runtime;
4847

4948
AeshCommandRegistryBuilder registryBuilder = AeshCommandRegistryBuilder.builder();
@@ -61,7 +60,7 @@ public static AeshRuntimeRunner builder() {
6160
public AeshRuntimeRunner command(Class<? extends Command> command) {
6261
try {
6362
registryBuilder.command(command);
64-
} catch (CommandRegistryException e) {
63+
} catch (CommandRegistryException e) {
6564
throw new RuntimeException("Exception while building command: " + e.getMessage());
6665
}
6766
return this;
@@ -70,7 +69,7 @@ public AeshRuntimeRunner command(Class<? extends Command> command) {
7069
public AeshRuntimeRunner command(Command commandInstance) {
7170
try {
7271
registryBuilder.command(commandInstance);
73-
} catch (CommandRegistryException e) {
72+
} catch (CommandRegistryException e) {
7473
throw new RuntimeException("Exception while building command: " + e.getMessage());
7574
}
7675
return this;
@@ -100,16 +99,15 @@ public CommandResult execute() {
10099
throw new RuntimeException("Command needs to be added");
101100
try {
102101

103-
104102
if (runtime == null) {
105-
AeshCommandRuntimeBuilder runtimeBuilder = AeshCommandRuntimeBuilder.builder();
106-
if(interactive) {
107-
connection = new TerminalConnection();
108-
connection.openNonBlocking();
109-
runtimeBuilder.shell(new ShellImpl(connection));
110-
}
103+
AeshCommandRuntimeBuilder runtimeBuilder = AeshCommandRuntimeBuilder.builder();
104+
if (interactive) {
105+
connection = new TerminalConnection();
106+
connection.openNonBlocking();
107+
runtimeBuilder.shell(new ShellImpl(connection));
108+
}
111109

112-
runtime = runtimeBuilder.commandRegistry(commandRegistry).build();
110+
runtime = runtimeBuilder.commandRegistry(commandRegistry).build();
113111

114112
}
115113

@@ -146,7 +144,7 @@ else if (commandNames.size() > 1)
146144
} catch (InterruptedException | IOException e) {
147145
System.err.println(e.getMessage());
148146
}
149-
if(connection != null)
147+
if (connection != null)
150148
connection.close();
151149

152150
return result;

0 commit comments

Comments
 (0)