Refactor packages and artifactIds to prepare for official migration to spring-projects repo.

Remove usage of component scan in favor of auto-conf

Fixes #61
This commit is contained in:
Eric Bottard
2017-08-03 18:06:28 +02:00
parent 5fd1f716d9
commit 6497df181d
91 changed files with 488 additions and 264 deletions

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.shell.Shell;
import org.springframework.shell.jline.JLineShell;
import org.springframework.shell.result.ResultHandlerConfig;
/**
* Main entry point for the application.
*
* <p>Creates the application context and start the REPL.</p>
*
* @author Eric Bottard
*/
@SpringBootApplication
public class SpringShellSample {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(SpringShellSample.class);
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples.jcommander;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.Parameter;
/**
* An example straight from the JCommander documentation.
*
* @author Eric Bottard
* @author Cédric Beust
*/
public class Args {
@Parameter
private List<String> parameters = new ArrayList<>();
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
private Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
private String groups;
@Parameter(names = "-debug", description = "Debug mode")
private boolean debug = false;
@Override
public String toString() {
return "Args{" +
"parameters=" + parameters +
", verbose=" + verbose +
", groups='" + groups + '\'' +
", debug=" + debug +
'}';
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples.jcommander;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
/**
* A class with JCommander commands.
*
* @author Eric Bottard
*/
@ShellComponent
public class JCommanderCommands {
@ShellMethod(help = "bind parameters to JCommander POJO")
public String jcommander(@ShellOption(optOut = true) Args args) {
return "You said " + args;
}
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples.legacy;
/**
* Created by ericbottard on 09/12/15.
*/
public enum ArtifactType {
source, processor, sink, task
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples.legacy;
import java.lang.reflect.Method;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
/**
* A sample of legacy Shell 1 commands that can be run thanks to the legacy adapter.
*
* @author Eric Bottard
*/
@Component
public class LegacyCommands implements CommandMarker {
public static final Method REGISTER_METHOD = ReflectionUtils.findMethod(LegacyCommands.class, "register", String.class, ArtifactType.class, String.class, boolean.class);
public static final Method SUM_METHOD = ReflectionUtils.findMethod(LegacyCommands.class, "sum", int.class, int.class);
@CliCommand(value = "register module", help = "Register a new module")
public String register(
@CliOption(mandatory = true,
key = {"", "name"},
help = "the name for the registered module")
String name,
@CliOption(mandatory = true,
key = {"type"},
help = "the type for the registered module")
ArtifactType type,
@CliOption(mandatory = false,
key = {"coordinates", "coords"},
help = "coordinates to the module archive")
String coordinates,
@CliOption(key = "force",
help = "force update if module already exists (only if not in use)",
specifiedDefaultValue = "true",
unspecifiedDefaultValue = "false")
boolean force) {
return String.format(("Successfully registered module '%s:%s'"), type, name);
}
@CliCommand(value = "sum", help = "adds two numbers")
public int sum(
@CliOption(key = "v1", unspecifiedDefaultValue = "38") int a,
@CliOption(key = "v2", specifiedDefaultValue = "42") int b) {
return a + b;
}
@CliCommand(value = "sum2", help = "adds two numbers")
public int sum2(
@CliOption(key = "v1", unspecifiedDefaultValue = "38") int a,
@CliOption(key = "v2", specifiedDefaultValue = "42", mandatory = true) int b,
@CliOption(key = "v3", mandatory = false) int c) {
return a + b + c;
}
@CliCommand(value = "legacy-echo", help = "Echoes a message")
public String legacyEcho(@CliOption(key = "", mandatory = true) String message) {
return message;
}
@CliCommand(value = "optional-echo", help = "Echoes an optional message")
public String optionalEcho(@CliOption(key = "", mandatory = false) String message) {
return message;
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.samples.standard;
import java.lang.annotation.ElementType;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.core.MethodParameter;
import org.springframework.shell.CompletionContext;
import org.springframework.shell.CompletionProposal;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
import org.springframework.shell.standard.ValueProviderSupport;
import org.springframework.stereotype.Component;
/**
* Example commands for the Shell 2 Standard resolver.
*
* @author Eric Bottard
*/
@ShellComponent("")
public class Commands {
@ShellMethod(help = "a command whose name looks the same as another one", value = "help me out")
public void helpMeOut() {
System.out.println("You can go");
}
@ShellMethod(help = "it's cool")
public String foo(String bar) {
return bar;
}
@ShellMethod(help = "it's cool with a prefix", prefix = "-")
public String fooPrefix(String bar) {
return bar;
}
@ShellMethod(help = "Shows support for boolean parameters, with arity=0")
public void shutdown(@ShellOption(arity = 0) boolean force) {
System.out.println("You passed " + force);
}
@ShellMethod(help = "test completion of special values")
public void quote(@ShellOption(valueProvider = FunnyValuesProvider.class) String text) {
System.out.println("You said " + text);
}
@ShellMethod(help = "add stuff")
public int add(int ahbahdisdonc, int b, int c) {
return ahbahdisdonc + b + c;
}
@ShellMethod(help = "Fails with an exception")
public void fail(ElementType elementType) {
throw new IllegalArgumentException("You said " + elementType);
}
@ShellMethod(help = "add array numbers")
public double addDoubles(@ShellOption(arity = 3) double[] numbers) {
return Arrays.stream(numbers).sum();
}
}
/**
* A {@link org.springframework.shell.standard.ValueProvider} that emits values with special characters
* (quotes, escapes, <em>etc.</em>)
*
* @author Eric Bottard
*/
@Component
class FunnyValuesProvider extends ValueProviderSupport {
private final static String[] VALUES = new String[] {
"hello world",
"I'm quoting \"The Daily Mail\"",
"10 \\ 3 = 3"
};
@Override
public List<CompletionProposal> complete(MethodParameter parameter, CompletionContext completionContext, String[] hints) {
return Arrays.stream(VALUES).map(CompletionProposal::new).collect(Collectors.toList());
}
}