рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ рдореИрдВ рдЬрд╛рд╡рд╛ рдореЗрдВ рд╕реАрдПрд▓рдЖрдИ рдЕрдиреБрдкреНрд░рдпреЛрдЧреЛрдВ рдХреЗ рдирд┐рд░реНрдорд╛рдг рдХреЗ рддрд░реАрдХреЛрдВ рдореЗрдВ рд╕реЗ рдПрдХ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдмрд╛рдд рдХрд░рдирд╛ рдЪрд╛рд╣рддрд╛ рд╣реВрдВред
рджрд░рдЕрд╕рд▓, рдРрд╕реЗ рдЕрдиреБрдкреНрд░рдпреЛрдЧреЛрдВ рдХреА рдмрд╣реБрдд рдЖрд╡рд╢реНрдпрдХрддрд╛ рдЧрд╛рдпрдм рдирд╣реАрдВ рд╣реБрдИ рд╣реИ - рдЗрд╕рд▓рд┐рдП, рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП, рдореЗрд░реЗ рдорд╛рдорд▓реЗ рдореЗрдВ рдпрд╣ рд╕рд░реНрд╡рд░ рдкрдХреНрд╖ рдХреЗ рдХрд╛рд░реНрдпрд╛рддреНрдордХ рдФрд░ рд▓реЛрдб рдкрд░реАрдХреНрд╖рдг рдХреЗ рд▓рд┐рдП рдПрдХ рдЖрд╡реЗрджрди рдерд╛ред рдмреЗрд╢рдХ, JUnits рдХреЗ рд╕реЗрдЯ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдЖрд╡рд╢реНрдпрдХ рдкрд░реАрдХреНрд╖рдг рдХрд░рдиреЗ рдХреЗ рд╡рд┐рдХрд▓реНрдк рдереЗ, рд▓реЗрдХрд┐рди рд╣рдо рд╕рдордп рдореЗрдВ рдмрд╣реБрдд рд╕реАрдорд┐рдд рдереЗ рдФрд░ рдПрдХ рд╕рдорд╛рдзрд╛рди рдкреНрд░рд╛рдкреНрдд рдХрд░рдирд╛ рдЪрд╛рд╣рддреЗ рдереЗ, рдЬрд┐рд╕реЗ рдкрд░реАрдХреНрд╖рдг рд╡рд┐рднрд╛рдЧ рд╕реЗ рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рдирд╣реАрдВ рдереАред рдЗрд╕рдХреЗ рдЕрд▓рд╛рд╡рд╛, рдмрд╛рдЗрдирд░реА рдкреНрд░реЛрдЯреЛрдХреЙрд▓ рдЬрд┐рд╕рдХреЗ рджреНрд╡рд╛рд░рд╛ рдХреНрд▓рд╛рдЗрдВрдЯ рдФрд░ рд╕рд░реНрд╡рд░ рдиреЗ рдмрд╛рддрдЪреАрдд рдХреА рдереА, рд╡рд╣ рд╕реНрдкрд╖реНрдЯ рд░реВрдк рд╕реЗ рдирд┐рд░реНрджрд┐рд╖реНрдЯ рдерд╛ред
рд╡рд┐рдЪрд╛рд░
рдЗрд╕ рдмрд╛рд░ рдореИрдВ рд╡рд╛рд╕реНрддрд╡ рдореЗрдВ рдПрдХ CLI рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдХреЗ рд▓рд┐рдП рддреБрдЪреНрдЫ рдЪреАрдЬреЗрдВ рдмрдирд╛рдиреЗ рдореЗрдВ рдкрд╣рд┐рдпрд╛ рдХреЛ рдлрд┐рд░ рд╕реЗ рдордЬрдмреВрдд рдирд╣реАрдВ рдХрд░рдирд╛ рдЪрд╛рд╣рддрд╛ рд╣реВрдВ - рдЗрдирдкреБрдЯ рд▓рд╛рдЗрди рдХреЛ рдкрд╛рд░реНрд╕ рдХрд░рдирд╛, рдХрдорд╛рдВрдб рдФрд░ рддрд░реНрдХреЛрдВ рдХреЛ рдЙрдЬрд╛рдЧрд░ рдХрд░рдирд╛, рддрд░реНрдХреЛрдВ рдХреЛ рдорд╛рдиреНрдп рдХрд░рдирд╛, рдХрдорд╛рдВрдб рдирд┐рд╖реНрдкрд╛рджрд┐рдд рдХрд░рдирд╛, рдкреНрд░реЙрдореНрдкреНрдЯ рдФрд░ рдЗрд╕реА рддрд░рд╣ рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд░рдирд╛ред
рддреИрдпрд╛рд░ рдШрдЯрдХреЛрдВ рдХреА рддрд▓рд╛рд╢ рдХрд░рдиреЗ рдХрд╛ рдирд┐рд░реНрдгрдп рд▓рд┐рдпрд╛ рдЧрдпрд╛ред
Habr├й рдкрд░ рдЗрддрдиреА рджреЗрд░ рдкрд╣рд▓реЗ
рдХреЙрдордиреНрд╕-рдХреНрд▓реА рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдПрдХ рд▓реЗрдЦ рдирд╣реАрдВ рдерд╛ред рдореБрдЭреЗ рдЗрд╕рдХреА 'рд▓рдХрдбрд╝реА' рдПрдкреАрдЖрдИ рдХреА рд╡рдЬрд╣ рд╕реЗ рдХреЙрдордиреНрд╕-рдХреНрд▓реА рдЦреБрдж рдкрд╕рдВрдж рдирд╣реАрдВ рдереА, рд▓реЗрдХрд┐рди рд▓реЗрдЦ рдкрд░ рдЯрд┐рдкреНрдкрдгрд┐рдпреЛрдВ рд╕реЗ рд╣реА рдореБрдЭреЗ
JCommander рд╕рд╣рд┐рдд рдХрдИ рд╡рд┐рдХрд▓реНрдкреЛрдВ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдкрддрд╛ рдЪрд▓рд╛ред
рдпрд╣ рд╡рд╣ рдерд╛ рдЬрд┐рд╕рдиреЗ рдзреНрдпрд╛рди рдЖрдХрд░реНрд╖рд┐рдд рдХрд┐рдпрд╛, рдХреНрдпреЛрдВрдХрд┐:
- рдЯреАрдо рдкреИрдЯрд░реНрди рдХреЗ рд▓рд┐рдП рдкреНрд░рд╛рдХреГрддрд┐рдХ рд╕рдорд░реНрдерди;
- рдПрдиреЛрдЯреЗрд╢рди рдХреЗ рдЖрдзрд╛рд░ рдкрд░, рдХреЙрд▓ рдкреИрд░рд╛рдореАрдЯрд░ рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░рдиреЗ рдХрд╛ рдПрдХ рд╕реБрд╡рд┐рдзрд╛рдЬрдирдХ рддрд░реАрдХрд╛;
- рдЙрдкрд▓рдмреНрдз рдЯреАрдореЛрдВ рдХреЗ рд▓рд┐рдП рд╕реНрд╡рдЪрд╛рд▓рд┐рдд рдорджрдж рдкреАрдврд╝реА;
- рдЕрдЪреНрдЫрд╛ рдкреНрд░рд▓реЗрдЦрди
- рдореБрдлреНрдд рдореЗрдВред
рдЪреВрдВрдХрд┐ рд╕рд░реНрд╡рд░ рдХрд╛ рд╣рд┐рд╕реНрд╕рд╛
Google Guice рдлреНрд░реЗрдорд╡рд░реНрдХ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдмрдирд╛рдпрд╛ рдЧрдпрд╛ рдерд╛, рдЗрд╕рд▓рд┐рдП рдЙрд╕ рдкрд░ CLI рдХреНрд▓рд╛рдЗрдВрдЯ рдХрд╛ рдирд┐рд░реНрдорд╛рдг рдХрд░рдирд╛ рдЙрдЪрд┐рдд рдерд╛, рдЦрд╛рд╕рдХрд░ рдЬрдм рд╕реЗ рд╕рд░реНрд╡рд░ рдФрд░ рдХреНрд▓рд╛рдЗрдВрдЯ рдореЗрдВ рдХреБрдЫ рд╕рд╛рдорд╛рдиреНрдп рдирд┐рд░реНрднрд░рддрд╛ рдФрд░ рдШрдЯрдХ рдереЗред
рдЗрд╕рдХрд╛ рдХреНрдпрд╛ рдЖрдпрд╛?
рдХрдХреНрд╖рд╛ рдЪрд╛рд░реНрдЯ:

рдЖрд░реЗрдЦ рдореЗрдВ:
-
CLISupport - рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдХреЗ рдХрдВрд╕реЛрд▓ рдЗрдирдкреБрдЯ рдкрд░ рдирдЬрд╝рд░ рд░рдЦрддрд╛ рд╣реИ рдФрд░ JCommander рдХреЗ рд▓рд┐рдП рдЕрдкрдиреЗ рдкрд╛рд░реНрд╕рд┐рдВрдЧ рдХреЛ рджрд░реНрд╢рд╛рддрд╛ рд╣реИ;
-
CLIApplication - рдПрдХ рд╡рд┐рд╢рд┐рд╖реНрдЯ рдХреНрд░рдо рдореЗрдВ рдЕрдиреБрдкреНрд░рдпреЛрдЧ рдШрдЯрдХреЛрдВ рдХреЛ рд╢реБрд░реВ рдФрд░ рд░реЛрдХрддрд╛ рд╣реИ;
-
рдХрдорд╛рди - рдЕрдореВрд░реНрдд рд╡рд░реНрдЧ рдХрдорд╛рди, рдЕрдиреНрдп рд╕рднреА рдЯреАрдореЛрдВ рдХреЗ рд▓рд┐рдП рдЖрдзрд╛рд░ред рдореБрдЦреНрдп рд╡рд┐рдзрд┐ рдирд┐рд╖реНрдкрд╛рджрд┐рдд рд╣реИ;
-
рдХрдорд╛рдВрдбрдПрдХреНрд╕рдПрдХреНрд╕рдПрдХреНрд╕рдПрдХреНрд╕ - рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП рдХрдорд╛рдВрдб рдХрд╛ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди;
-
JCommanderProvider - com.google.inject.Provider рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХрд╛ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрдиред рдмрд╛рд╣рд░реА рдЕрдиреБрд░реЛрдзреЛрдВ (рдЗрдВрдЬреЗрдХреНрд╢рди) рдХреЗ рд╕рд╛рде JCommander рдХрд╛ рдПрдХ рдЙрджрд╛рд╣рд░рдг рдмрдирд╛рддрд╛ рд╣реИ;
-
CLIConfigurationModule - Guice рдореЗрдВ рдШрдЯрдХ рд╡рд┐рдиреНрдпрд╛рд╕рдХрд░реНрддрд╛, com.google.inject.AbstractModule рдХрд╛ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрдиред
рдХреЛрдб рдЙрджрд╛рд╣рд░рдг
CLIConfigurationModule рдПрдХ Guice рдХреЙрдиреНрдлрд╝рд┐рдЧрд░реЗрд╢рди рдореЙрдбреНрдпреВрд▓ рд╣реИ, рдХреЗрд╡рд▓ рдпрд╣ рдирд┐рд╖реНрдкрд╛рджрди рдХреЗ рд▓рд┐рдП рдЙрдкрд▓рдмреНрдз рд╕рднреА рдирд┐рд░реНрднрд░рддрд╛ рдФрд░ рдЖрджреЗрд╢реЛрдВ рдХрд╛ рд╡рд░реНрдгрди рдХрд░рддрд╛ рд╣реИред
public class CLIConfigurationModule extends AbstractModule {
protected void configure() {
AnsiConsole.systemInstall();
bind(PrimaryBusinessLogicService. class ).to(PrimaryBusinessLogicServiceImpl. class ).asEagerSingleton();
bind(SecondaryBusinessLogicService. class ).to(SecondaryBusinessLogicServiceImpl. class ).asEagerSingleton();
bind(CLISupport. class ).asEagerSingleton();
bind(CLIApplication. class ).asEagerSingleton();
bind(JCommander. class ).toProvider(JCommanderProvider. class );
bind(CommandClearScreen. class );
bind(CommandExit. class );
bind(CommandUsage. class );
bind(CommandPrimary. class );
bind(CommandSecondary. class );
}
@Provides
@Inject
public Collection<Command> provideAvailableCommands(Injector injector) {
Collection<Command> commands = new ArrayList <Command>();
commands.add(injector.getInstance(CommandClearScreen. class ));
commands.add(injector.getInstance(CommandExit. class ));
commands.add(injector.getInstance(CommandUsage. class ));
commands.add(injector.getInstance(CommandPrimary. class ));
commands.add(injector.getInstance(CommandSecondary. class ));
return commands;
}
}
* This source code was highlighted with Source Code Highlighter .
public class CLIConfigurationModule extends AbstractModule {
protected void configure() {
AnsiConsole.systemInstall();
bind(PrimaryBusinessLogicService. class ).to(PrimaryBusinessLogicServiceImpl. class ).asEagerSingleton();
bind(SecondaryBusinessLogicService. class ).to(SecondaryBusinessLogicServiceImpl. class ).asEagerSingleton();
bind(CLISupport. class ).asEagerSingleton();
bind(CLIApplication. class ).asEagerSingleton();
bind(JCommander. class ).toProvider(JCommanderProvider. class );
bind(CommandClearScreen. class );
bind(CommandExit. class );
bind(CommandUsage. class );
bind(CommandPrimary. class );
bind(CommandSecondary. class );
}
@Provides
@Inject
public Collection<Command> provideAvailableCommands(Injector injector) {
Collection<Command> commands = new ArrayList <Command>();
commands.add(injector.getInstance(CommandClearScreen. class ));
commands.add(injector.getInstance(CommandExit. class ));
commands.add(injector.getInstance(CommandUsage. class ));
commands.add(injector.getInstance(CommandPrimary. class ));
commands.add(injector.getInstance(CommandSecondary. class ));
return commands;
}
}
* This source code was highlighted with Source Code Highlighter .
public class CLIConfigurationModule extends AbstractModule {
protected void configure() {
AnsiConsole.systemInstall();
bind(PrimaryBusinessLogicService. class ).to(PrimaryBusinessLogicServiceImpl. class ).asEagerSingleton();
bind(SecondaryBusinessLogicService. class ).to(SecondaryBusinessLogicServiceImpl. class ).asEagerSingleton();
bind(CLISupport. class ).asEagerSingleton();
bind(CLIApplication. class ).asEagerSingleton();
bind(JCommander. class ).toProvider(JCommanderProvider. class );
bind(CommandClearScreen. class );
bind(CommandExit. class );
bind(CommandUsage. class );
bind(CommandPrimary. class );
bind(CommandSecondary. class );
}
@Provides
@Inject
public Collection<Command> provideAvailableCommands(Injector injector) {
Collection<Command> commands = new ArrayList <Command>();
commands.add(injector.getInstance(CommandClearScreen. class ));
commands.add(injector.getInstance(CommandExit. class ));
commands.add(injector.getInstance(CommandUsage. class ));
commands.add(injector.getInstance(CommandPrimary. class ));
commands.add(injector.getInstance(CommandSecondary. class ));
return commands;
}
}
* This source code was highlighted with Source Code Highlighter .
JCommanderProvider - рдЬрдм рд╡реЗ рдЗрдВрдЬреЗрдХреНрдЯ / рдкреБрдирдГ рдкреНрд░рд╛рдкреНрдд рдХрд░ рд░рд╣реЗ рд╣реИрдВ JCommander рдЙрджрд╛рд╣рд░рдг рдмрдирд╛рддрд╛ рд╣реИред CLIConfigurationModule рд╡рд░реНрдЧ рдореЗрдВ рдкреНрд░реЛрд╡рд╛рдЗрдб рдПрдиреЛрдЯреЗрд╢рди рджреНрд╡рд╛рд░рд╛ рдШреЛрд╖рд┐рдд рдЖрджреЗрд╢реЛрдВ рдХрд╛ рд╕рдВрдЧреНрд░рд╣ рд╣реЛ рдЬрд╛рддрд╛ рд╣реИред рдореБрдЦреНрдп рд╡рд┐рд╢реЗрд╖рддрд╛ рдпрд╣ рд╣реИ рдХрд┐ рдЕрдЧрд▓реЗ рдЖрджреЗрд╢ рдХреЛ рдкрд╛рд░реНрд╕ рдХрд░рдиреЗ рд╕реЗ рдкрд╣рд▓реЗ, рдЖрдкрдХреЛ JCommander рдХрд╛ рдПрдХ рдирдпрд╛ рдкреНрд░рд╛рд░рдВрднрд┐рдХ рдЙрджрд╛рд╣рд░рдг рдмрдирд╛рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ, рдХреНрдпреЛрдВрдХрд┐ рдкрд╛рд░реНрд╕ рдХрд░рдиреЗ рдХреЗ рдмрд╛рдж, рдпрд╣ рд░рд╛рдЬреНрдп рдХреЛ рдмрдЪрд╛рддрд╛ рд╣реИ рдФрд░ рдмрд╛рдж рдореЗрдВ рдкрд╛рд░реНрд╕рд┐рдВрдЧ рдХреЗ рджреМрд░рд╛рди рдпрд╣ рдиреБрдХрд╕рд╛рди рдкрд╣реБрдВрдЪрд╛ рд╕рдХрддрд╛ рд╣реИ рдФрд░ рдРрд╕рд╛ рдХрд░рддрд╛ рд╣реИред рдЗрд╕реАрд▓рд┐рдП рдЖрдк JCommander рдХреЛ Singleton / asEagerSingleton рдШреЛрд╖рд┐рдд рдирд╣реАрдВ рдХрд░ рд╕рдХрддреЗред
public class JCommanderProvider implements Provider<JCommander> {
@Inject
private Collection<Command> commands;
/**
* Constructs the new JCommander instance with all commands.
*
* @return
*/
public JCommander get () {
JCommander commander = new JCommander();
for (Command command : commands) {
addCommand(commander, command);
}
return commander;
}
private void addCommand(JCommander commander, Command command) {
commander.addCommand(command.getCommandName(), command, command.getAliases());
}
}
* This source code was highlighted with Source Code Highlighter .
public class JCommanderProvider implements Provider<JCommander> {
@Inject
private Collection<Command> commands;
/**
* Constructs the new JCommander instance with all commands.
*
* @return
*/
public JCommander get () {
JCommander commander = new JCommander();
for (Command command : commands) {
addCommand(commander, command);
}
return commander;
}
private void addCommand(JCommander commander, Command command) {
commander.addCommand(command.getCommandName(), command, command.getAliases());
}
}
* This source code was highlighted with Source Code Highlighter .
рдХрдорд╛рдВрдб рд╕рднреА рдХрдорд╛рдВрдб рдХреЗ рд▓рд┐рдП рдмреЗрд╕ рдХреНрд▓рд╛рд╕ рд╣реИред рдореБрдЦреНрдп рд╡рд┐рдзрд┐ рдирд┐рд╖реНрдкрд╛рджрд┐рдд рд╣реИред рдХрдорд╛рдВрдб рдХрд╛ рдирд╛рдо javax.inject.Name рдПрдиреЛрдЯреЗрд╢рди рдореЗрдВ рдЗрдВрдЧрд┐рдд рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ - рдореБрдЭреЗ рдпрд╣ рдПрдХ рдмрд╣реБрдд рд╣реА рд╕реБрдВрджрд░ рд╕рдорд╛рдзрд╛рди рдорд┐рд▓рд╛, рдХреНрдпреЛрдВрдХрд┐ javax.inject рдкрд░ рдирд┐рд░реНрднрд░рддрд╛ Guice рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╕рдордп рдкреНрд░рдХрдЯ рд╣реЛрддреА рд╣реИ, рдФрд░ рддрд╛рд░реНрдХрд┐рдХ рд░реВрдк рд╕реЗ рдпрд╣ рдПрдиреЛрдЯреЗрд╢рди рдмрд╣реБрдд рд╕рд╛рд░реНрдердХ рд╣реИред рдореБрдЦреНрдп рдирд╛рдо рдХреЗ рдЕрд▓рд╛рд╡рд╛, рдЙрдкрдирд╛рдо (рдЙрдкрдирд╛рдо) рдХреА рдПрдХ рд╕рд░рдгреА рдХреЛ рднреА рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИ - рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП, рдХрдорд╛рдВрдб 'рдирд┐рдХрд╛рд╕' рдореЗрдВ рдЙрдкрдирд╛рдо 'q' рдФрд░ 'x' рд╣реЛ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕рдХреЗ рдЕрд▓рд╛рд╡рд╛, GetCommandName рдФрд░ getAliases рдХреЗ рддрд░реАрдХреЛрдВ рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ JCommander рдореЗрдВ рдХрдорд╛рдВрдб рд░рдЬрд┐рд╕реНрдЯрд░ рдХрд░рддреЗ рд╕рдордп рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ (JCommanderProvider рдореЗрдВ addCommand рд╡рд┐рдзрд┐ рджреЗрдЦреЗрдВ)ред
public abstract class Command {
private static final String [] NO_ALIASES = new String []{};
protected Logger logger;
private String commandName;
protected Command() {
logger = LoggerFactory.getLogger(getClass());
commandName = getClass().getAnnotation(Named. class ). value ();
}
public String [] getAliases() {
return NO_ALIASES;
}
public final String getCommandName() {
return commandName;
}
public abstract void execute() throws ExecutionException;
}
* This source code was highlighted with Source Code Highlighter .
public abstract class Command {
private static final String [] NO_ALIASES = new String []{};
protected Logger logger;
private String commandName;
protected Command() {
logger = LoggerFactory.getLogger(getClass());
commandName = getClass().getAnnotation(Named. class ). value ();
}
public String [] getAliases() {
return NO_ALIASES;
}
public final String getCommandName() {
return commandName;
}
public abstract void execute() throws ExecutionException;
}
* This source code was highlighted with Source Code Highlighter .
public abstract class Command {
private static final String [] NO_ALIASES = new String []{};
protected Logger logger;
private String commandName;
protected Command() {
logger = LoggerFactory.getLogger(getClass());
commandName = getClass().getAnnotation(Named. class ). value ();
}
public String [] getAliases() {
return NO_ALIASES;
}
public final String getCommandName() {
return commandName;
}
public abstract void execute() throws ExecutionException;
}
* This source code was highlighted with Source Code Highlighter .
CommandPrimary рд╡реНрдпрд╡рд╕рд╛рдп рддрд░реНрдХ рд╕реЗрд╡рд╛ рдХреЙрд▓ рдХреЗ рд╕рд╛рде рдПрдХ рд╡рд╛рд╕реНрддрд╡рд┐рдХ рдЯреАрдо рдХрд╛ рдПрдХ рдЙрджрд╛рд╣рд░рдг рд╣реИред @ рдкрд╛рд░реЗрдореАрдЯрд░ рдПрдиреЛрдЯреЗрд╢рди рдореЗрдВ рдЬреЛ рд╕рдВрдХреЗрдд рджрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ, рд╡рд╣ рдЗрд╕ рдХрдорд╛рдВрдб рдХреЗ рд▓рд┐рдП рд╡рд┐рд╡рд░рдг рдЙрддреНрдкрдиреНрди рдХрд░рддреЗ рд╕рдордп рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ (рдХрдорд╛рдВрдб рдХрдорд╛рдВрдб рджреЗрдЦреЗрдВ)ред
@Parameters(commandDescription = "Execute the logic of primary service" )
@Named( "do-primary" )
public class CommandPrimary extends Command {
@Parameter(names = { "-verbose" , "-v" }, description = "Verbose mode" )
protected boolean verbose;
@Parameter(names = { "-id" }, description = "Entity ID" , required = true )
protected String id;
@Parameter(names = { "-count" , "-c" }, validateWith = PositiveInteger. class , description = "Entities count" , required = true )
protected long count;
private PrimaryBusinessLogicService primaryBusinessLogicService;
@Inject
public CommandPrimary(PrimaryBusinessLogicService primaryBusinessLogicService) {
this .primaryBusinessLogicService = primaryBusinessLogicService;
}
@Override
public String [] getAliases() {
return new String []{ "dp" , "primary" };
}
@Override
public void execute() throws ExecutionException {
try {
if (verbose) {
logger.info( String .format( "Executing primary business logic with parameters: [count=%d, id=%s]" , count, id));
}
primaryBusinessLogicService.executePrimaryBusinessLogic(count, id);
} catch (ServiceException e) {
throw new ExecutionException(e);
}
}
}
* This source code was highlighted with Source Code Highlighter .
@Parameters(commandDescription = "Execute the logic of primary service" )
@Named( "do-primary" )
public class CommandPrimary extends Command {
@Parameter(names = { "-verbose" , "-v" }, description = "Verbose mode" )
protected boolean verbose;
@Parameter(names = { "-id" }, description = "Entity ID" , required = true )
protected String id;
@Parameter(names = { "-count" , "-c" }, validateWith = PositiveInteger. class , description = "Entities count" , required = true )
protected long count;
private PrimaryBusinessLogicService primaryBusinessLogicService;
@Inject
public CommandPrimary(PrimaryBusinessLogicService primaryBusinessLogicService) {
this .primaryBusinessLogicService = primaryBusinessLogicService;
}
@Override
public String [] getAliases() {
return new String []{ "dp" , "primary" };
}
@Override
public void execute() throws ExecutionException {
try {
if (verbose) {
logger.info( String .format( "Executing primary business logic with parameters: [count=%d, id=%s]" , count, id));
}
primaryBusinessLogicService.executePrimaryBusinessLogic(count, id);
} catch (ServiceException e) {
throw new ExecutionException(e);
}
}
}
* This source code was highlighted with Source Code Highlighter .
@Parameters(commandDescription = "Execute the logic of primary service" )
@Named( "do-primary" )
public class CommandPrimary extends Command {
@Parameter(names = { "-verbose" , "-v" }, description = "Verbose mode" )
protected boolean verbose;
@Parameter(names = { "-id" }, description = "Entity ID" , required = true )
protected String id;
@Parameter(names = { "-count" , "-c" }, validateWith = PositiveInteger. class , description = "Entities count" , required = true )
protected long count;
private PrimaryBusinessLogicService primaryBusinessLogicService;
@Inject
public CommandPrimary(PrimaryBusinessLogicService primaryBusinessLogicService) {
this .primaryBusinessLogicService = primaryBusinessLogicService;
}
@Override
public String [] getAliases() {
return new String []{ "dp" , "primary" };
}
@Override
public void execute() throws ExecutionException {
try {
if (verbose) {
logger.info( String .format( "Executing primary business logic with parameters: [count=%d, id=%s]" , count, id));
}
primaryBusinessLogicService.executePrimaryBusinessLogic(count, id);
} catch (ServiceException e) {
throw new ExecutionException(e);
}
}
}
* This source code was highlighted with Source Code Highlighter .
рдкрд░рд┐рдпреЛрдЬрдирд╛ рдирд┐рд░реНрднрд░рддрд╛< properties >
< version.jcommander > 1.18 </ version.jcommander >
< version.jansi > 1.6 </ version.jansi >
< version.commons-io > 2.0.1 </ version.commons-io >
< version.jline > 0.9.94 </ version.jline >
< version.guice > 3.0 </ version.guice >
< version.logback > 0.9.29 </ version.logback >
< version.slf4j > 1.6.2 </ version.slf4j >
< version.commons-lang > 3.0.1 </ version.commons-lang >
< version.maven-compiler-plugin > 2.3.2 </ version.maven-compiler-plugin >
< version.maven-jar-plugin > 2.3.2 </ version.maven-jar-plugin >
< version.maven-surefire-plugin > 2.9 </ version.maven-surefire-plugin >
< version.onejar-maven-plugin > 1.4.4 </ version.onejar-maven-plugin >
< version.maven-assembly-plugin > 2.2.1 </ version.maven-assembly-plugin >
</ properties >
< dependencies >
<!-- Logging -->
< dependency >
< groupId > ch.qos.logback </ groupId >
< artifactId > logback-classic </ artifactId >
< version > ${version.logback} </ version >
</ dependency >
< dependency >
< groupId > ch.qos.logback </ groupId >
< artifactId > logback-core </ artifactId >
< version > ${version.logback} </ version >
</ dependency >
< dependency >
< groupId > org.slf4j </ groupId >
< artifactId > slf4j-api </ artifactId >
< version > ${version.slf4j} </ version >
</ dependency >
<!-- Google Stuff -->
< dependency >
< groupId > com.google.inject </ groupId >
< artifactId > guice </ artifactId >
< version > ${version.guice} </ version >
</ dependency >
<!--External Stuff-->
< dependency >
< groupId > commons-io </ groupId >
< artifactId > commons-io </ artifactId >
< version > ${version.commons-io} </ version >
</ dependency >
< dependency >
< groupId > org.fusesource.jansi </ groupId >
< artifactId > jansi </ artifactId >
< version > ${version.jansi} </ version >
</ dependency >
< dependency >
< groupId > com.beust </ groupId >
< artifactId > jcommander </ artifactId >
< version > ${version.jcommander} </ version >
</ dependency >
< dependency >
< groupId > jline </ groupId >
< artifactId > jline </ artifactId >
< version > ${version.jline} </ version >
</ dependency >
< dependency >
< groupId > org.apache.commons </ groupId >
< artifactId > commons-lang3 </ artifactId >
< version > ${version.commons-lang} </ version >
</ dependency >
</ dependencies >
* This source code was highlighted with Source Code Highlighter .
< properties >
< version.jcommander > 1.18 </ version.jcommander >
< version.jansi > 1.6 </ version.jansi >
< version.commons-io > 2.0.1 </ version.commons-io >
< version.jline > 0.9.94 </ version.jline >
< version.guice > 3.0 </ version.guice >
< version.logback > 0.9.29 </ version.logback >
< version.slf4j > 1.6.2 </ version.slf4j >
< version.commons-lang > 3.0.1 </ version.commons-lang >
< version.maven-compiler-plugin > 2.3.2 </ version.maven-compiler-plugin >
< version.maven-jar-plugin > 2.3.2 </ version.maven-jar-plugin >
< version.maven-surefire-plugin > 2.9 </ version.maven-surefire-plugin >
< version.onejar-maven-plugin > 1.4.4 </ version.onejar-maven-plugin >
< version.maven-assembly-plugin > 2.2.1 </ version.maven-assembly-plugin >
</ properties >
< dependencies >
<!-- Logging -->
< dependency >
< groupId > ch.qos.logback </ groupId >
< artifactId > logback-classic </ artifactId >
< version > ${version.logback} </ version >
</ dependency >
< dependency >
< groupId > ch.qos.logback </ groupId >
< artifactId > logback-core </ artifactId >
< version > ${version.logback} </ version >
</ dependency >
< dependency >
< groupId > org.slf4j </ groupId >
< artifactId > slf4j-api </ artifactId >
< version > ${version.slf4j} </ version >
</ dependency >
<!-- Google Stuff -->
< dependency >
< groupId > com.google.inject </ groupId >
< artifactId > guice </ artifactId >
< version > ${version.guice} </ version >
</ dependency >
<!--External Stuff-->
< dependency >
< groupId > commons-io </ groupId >
< artifactId > commons-io </ artifactId >
< version > ${version.commons-io} </ version >
</ dependency >
< dependency >
< groupId > org.fusesource.jansi </ groupId >
< artifactId > jansi </ artifactId >
< version > ${version.jansi} </ version >
</ dependency >
< dependency >
< groupId > com.beust </ groupId >
< artifactId > jcommander </ artifactId >
< version > ${version.jcommander} </ version >
</ dependency >
< dependency >
< groupId > jline </ groupId >
< artifactId > jline </ artifactId >
< version > ${version.jline} </ version >
</ dependency >
< dependency >
< groupId > org.apache.commons </ groupId >
< artifactId > commons-lang3 </ artifactId >
< version > ${version.commons-lang} </ version >
</ dependency >
</ dependencies >
* This source code was highlighted with Source Code Highlighter .
< properties >
< version.jcommander > 1.18 </ version.jcommander >
< version.jansi > 1.6 </ version.jansi >
< version.commons-io > 2.0.1 </ version.commons-io >
< version.jline > 0.9.94 </ version.jline >
< version.guice > 3.0 </ version.guice >
< version.logback > 0.9.29 </ version.logback >
< version.slf4j > 1.6.2 </ version.slf4j >
< version.commons-lang > 3.0.1 </ version.commons-lang >
< version.maven-compiler-plugin > 2.3.2 </ version.maven-compiler-plugin >
< version.maven-jar-plugin > 2.3.2 </ version.maven-jar-plugin >
< version.maven-surefire-plugin > 2.9 </ version.maven-surefire-plugin >
< version.onejar-maven-plugin > 1.4.4 </ version.onejar-maven-plugin >
< version.maven-assembly-plugin > 2.2.1 </ version.maven-assembly-plugin >
</ properties >
< dependencies >
<!-- Logging -->
< dependency >
< groupId > ch.qos.logback </ groupId >
< artifactId > logback-classic </ artifactId >
< version > ${version.logback} </ version >
</ dependency >
< dependency >
< groupId > ch.qos.logback </ groupId >
< artifactId > logback-core </ artifactId >
< version > ${version.logback} </ version >
</ dependency >
< dependency >
< groupId > org.slf4j </ groupId >
< artifactId > slf4j-api </ artifactId >
< version > ${version.slf4j} </ version >
</ dependency >
<!-- Google Stuff -->
< dependency >
< groupId > com.google.inject </ groupId >
< artifactId > guice </ artifactId >
< version > ${version.guice} </ version >
</ dependency >
<!--External Stuff-->
< dependency >
< groupId > commons-io </ groupId >
< artifactId > commons-io </ artifactId >
< version > ${version.commons-io} </ version >
</ dependency >
< dependency >
< groupId > org.fusesource.jansi </ groupId >
< artifactId > jansi </ artifactId >
< version > ${version.jansi} </ version >
</ dependency >
< dependency >
< groupId > com.beust </ groupId >
< artifactId > jcommander </ artifactId >
< version > ${version.jcommander} </ version >
</ dependency >
< dependency >
< groupId > jline </ groupId >
< artifactId > jline </ artifactId >
< version > ${version.jline} </ version >
</ dependency >
< dependency >
< groupId > org.apache.commons </ groupId >
< artifactId > commons-lang3 </ artifactId >
< version > ${version.commons-lang} </ version >
</ dependency >
</ dependencies >
* This source code was highlighted with Source Code Highlighter .
рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╕реНрдкрд╖реНрдЯреАрдХрд░рдг
jansi рдкреБрд╕реНрддрдХрд╛рд▓рдп рд╕реНрдерд▓ рд╣реИ ред рдкреБрд░рд╛рдиреЗ рд╕реНрдХреВрд▓ рдХреЗ рдЫрджреНрдо-рдЧреНрд░рд╛рдлрд┐рдХ рдЙрддреНрд╕рд╛рд╣реА рд▓реЛрдЧреЛрдВ рдХреЗ рд▓рд┐рдП, рдХрдВрд╕реЛрд▓ рдХреЛ рдЖрдЙрдЯрдкреБрдЯ рдореЗрдВ рд╡рд┐рд╡рд┐рдзрддрд╛ рд▓рд╛рдиреЗ рдФрд░ рдкрд░реАрдХреНрд╖рдХреЛрдВ рдХреЗ рдХрд╛рдо рдореЗрдВ рдереЛрдбрд╝реА рдЦреБрд╢реА рдЬреЛрдбрд╝рдиреЗ рдХреА рдЗрдЪреНрдЫрд╛ рдереАред рдХреБрдЫ рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ - рдПрдХ рд░рдВрдЧ рдирд┐рд╖реНрдХрд░реНрд╖ рдФрд░ рд╡рд┐рджрд╛рдИ рд╡рд╛рдХреНрдпрд╛рдВрд╢ 'рдЕрд▓рд╡рд┐рджрд╛!' рд╕рдлреЗрдж рд░рдВрдЧ рдореЗрдВ рдмрд╛рд╣рд░ рдирд┐рдХрд▓рдиреЗ рдкрд░ред рд╡рд┐рд╢реЗрд╖ рд░реВрдк рд╕реЗ рдЦрд╛рд▓реА рд╕рдордп рдХреА рдЫреЛрдЯреА рд░рд╛рд╢рд┐ рд╕реЗ рдЬреЛ рдкрд░рд┐рдпреЛрдЬрдирд╛ рдХреЗ рдЕрдВрдд рдореЗрдВ рджрд┐рдЦрд╛рдИ рджреАред
рд▓реЙрдЧрдмреИрдХ рдПрдХ рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╕рд╛рдЗрдЯ рд╣реИ ред рд▓реЙрдЧрд┐рдВрдЧ рдХреЗ рдЗрд╕ рд╡рд┐рд╢реЗрд╖ рдХрд╛рд░реНрдпрд╛рдиреНрд╡рдпрди рдХрд╛ рдЙрдкрдпреЛрдЧ рдЖрд╡рд╢реНрдпрдХ рдирд╣реАрдВ рд╣реИ, рд╣рд╛рд▓рд╛рдВрдХрд┐, рдпрд╣ рд▓реЙрдЧрдмреИрдХ рдХреЗ рдореБрдЦреНрдп рд╕рдХрд╛рд░рд╛рддреНрдордХ рдЧреБрдгреЛрдВ рдХреЛ рдзреНрдпрд╛рди рджреЗрдиреЗ рдпреЛрдЧреНрдп рд╣реИ - рдЙрдЪреНрдЪ рдкреНрд░рджрд░реНрд╢рди, рдордХреНрдЦреА рдкрд░ рдлрд┐рд░ рд╕реЗ рдкрдврд╝рдирд╛ рд╕реЗрдЯрд┐рдВрдЧреНрд╕, рдЬреЗрдПрдордПрдХреНрд╕ рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдХреЙрдиреНрдлрд╝рд┐рдЧрд░реЗрд╢рди, рдкреИрд░рд╛рдореАрдЯрд░ рдХреЗ рд▓рд┐рдП рд╕рдорд░реНрдерди рдФрд░ рд╢рд╛рдорд┐рд▓-рдПрд╕, рдФрд░ рдмрд╣реБрдд рдХреБрдЫред рд╕рд╛рдорд╛рдиреНрдп рддреМрд░ рдкрд░, рд▓реЙрдЧрдмреИрдХ рдПрдХ рдЕрд▓рдЧ рд▓реЗрдЦ рдХреЗ рд╣рдХрджрд╛рд░ рд╣реИрдВред
jline рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╕рд╛рдЗрдЯ рд╣реИ ред рдпрд╣ рдКрдкрд░ / рдиреАрдЪреЗ рдХреБрдВрдЬрд┐рдпреЛрдВ (рдиреАрдЪреЗ рджреЗрдЦреЗрдВ) рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реБрдП рдкрд╣рд▓реЗ рд╕реЗ рджрд░реНрдЬ рдЖрджреЗрд╢реЛрдВ рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдиреЗрд╡рд┐рдЧреЗрд╢рди рдХреА рд╕рдВрдЪрд╛рд▓рди рдХреА рд╕рдорд╕реНрдпрд╛ рдХреЛ рд╣рд▓ рдХрд░рддрд╛ рд╣реИ, рд╕рд╛рде рд╣реА рдХрдорд╛рдВрдб рдкреВрд░рд╛ рд╣реЛрдиреЗ рдХреА рдХрд╛рд░реНрдпрдХреНрд╖рдорддрд╛ (рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП, 'рдбреВ-рдкреА' рдФрд░ рдЯреИрдм рдХреБрдВрдЬреА рджрдмрд╛рдХрд░ рдкреНрд░рд╡реЗрд╢ рдХрд░рдиреЗ рдХреА рдХреЛрд╢рд┐рд╢ рдХрд░рддрд╛ рд╣реИ)ред рдЖрджрд░реНрд╢ рд░реВрдк рдореЗрдВ, рдЖрдк рди рдХреЗрд╡рд▓ рдЖрджреЗрд╢реЛрдВ рдХреЗ рдСрдЯреЛ-рд╕рдорд╛рдкрди рдХреЛ рд▓рд╛рдЧреВ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВ, рдмрд▓реНрдХрд┐ рдЙрдирдХреЗ рддрд░реНрдХ, рдЗрд╕рдХреЗ рдЕрд▓рд╛рд╡рд╛, рд╕рдВрджрд░реНрдн рдХреЗ рд╕рдВрджрд░реНрдн рдореЗрдВ рднреАред
рд╕рдорд╕реНрдпрд╛рдУрдВ
рд▓рд┐рдирдХреНрд╕ рдХреЗ рддрд╣рдд, рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛рдУрдВ рдиреЗ рдиреЛрдЯ рдХрд┐рдпрд╛ рдХрд┐ рдЕрдк / рдбрд╛рдЙрди рддреАрд░ рд╕рд╣реА рдврдВрдЧ рд╕реЗ рдХрд╛рдо рдирд╣реАрдВ рдХрд░рддреЗ рдереЗ - рдкрд╣рд▓реЗ рд╕реЗ рдХрд╛рдо рдХрд┐рдП рдЧрдП рдХрдорд╛рдВрдб рдХреА рд╕реВрдЪреА рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдиреЗрд╡рд┐рдЧреЗрдЯ рдХрд░рдиреЗ рдХреЗ рдмрдЬрд╛рдп, рдЕрддреБрд▓рдиреАрдп рдЫрджреНрдо-рдЕрдиреБрдХреНрд░рдо рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд┐рдП рдЧрдП рдереЗред рдЗрд╕ рд╕рдорд╕реНрдпрд╛ рдХреЗ рдХрд╛рд░рдг
рдЬреЗрд▓ рд▓рд╛рдЗрдмреНрд░реЗрд░реА рдХрд╛ рдЙрдкрдпреЛрдЧ рд╣реБрдЖред
рдЕрдиреНрдпрдерд╛, рд╕рдм рдХреБрдЫ рд╕реНрдкрд╖реНрдЯ рдФрд░ рд╕рд╛рдордВрдЬрд╕реНрдпрдкреВрд░реНрдг рд░реВрдк рд╕реЗ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИред
рд╕реНрд░реЛрдд рдХреЛрдб
рд▓реЗрдЦ рдХреЗ рд▓рд┐рдП рд╕рднреА рд╕реНрд░реЛрдд рдХреЛрдб
рдпрд╣рд╛рдВ рдЙрдкрд▓рдмреНрдз
рд╣реИрдВ ред
рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдХреЛ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдЖрдкрдХреЛ Maven рд╕рдВрд╕реНрдХрд░рдг 2.x рд╕реНрдерд╛рдкрд┐рдд рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ, рдЙрд╕рдХреЗ рдмрд╛рдж - 'mvan рдкреИрдХреЗрдЬ'ред
рдЕрд╕реЗрдВрдмрд▓реА рдХреЗ рдкрд░рд┐рдгрд╛рдорд╕реНрд╡рд░реВрдк, jcommander-guice-sample-XXX-client.tar.gz рдЖрд░реНрдХрд╛рдЗрд╡ рдмрдирд╛рдпрд╛ рдЬрд╛рдПрдЧрд╛ред рдЗрд╕реЗ рдЕрдирдкреИрдХ рдХрд┐рдпрд╛ рдЬрд╛рдирд╛ рдЪрд╛рд╣рд┐рдП рдФрд░ рдЕрдкрдиреЗ OS рдХреЗ рдЕрдиреБрд░реВрдк рд╢реЗрд▓ рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХреЛ рдЪрд▓рд╛рдирд╛ рдЪрд╛рд╣рд┐рдП - run.sh рдпрд╛ run.batред
рдкрд░рд┐рдгрд╛рдо рдХреБрдЫ рдЗрд╕ рддрд░рд╣ рджрд┐рдЦрддреЗ рд╣реИрдВ:

рдореБрдЭреЗ рдЙрдореНрдореАрдж рд╣реИ рдХрд┐ рд▓реЗрдЦ рдХрд┐рд╕реА рдХреЗ рд▓рд┐рдП рдЙрдкрдпреЛрдЧреА рд╣реЛрдЧрд╛ред
рдЖрдкрдХрд╛ рдзреНрдпрд╛рди рджреЗрдиреЗ рдХреЗ рд▓рд┐рдП рдЖрдк рд╕рднреА рдХрд╛ рдзрдиреНрдпрд╡рд╛рдж!