#1104 I18N effort for dubbo code base - dubbo-plugin
This commit is contained in:
parent
254aae56db
commit
d41e7225d0
|
|
@ -1,3 +1,19 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You 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.
|
||||
-->
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.SPI;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
@SPI
|
||||
public interface BaseCommand {
|
||||
String execute(CommandContext commandContext,String[] args);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class CommandContext {
|
||||
private String commandName;
|
||||
private String[] args;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class CommandContextFactory {
|
||||
public static CommandContext newInstance(String commandName){
|
||||
return new CommandContext(commandName);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,28 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public interface CommandExecutor {
|
||||
/**
|
||||
* <pre>
|
||||
* 执行一个命令,返回对应命令执行的结果
|
||||
* </pre>
|
||||
* Execute one command and return the execution result
|
||||
*
|
||||
* @param commandContext
|
||||
* 命令
|
||||
* @return
|
||||
* @param commandContext command context
|
||||
* @return command execution result
|
||||
* @throws NoSuchCommandException
|
||||
*/
|
||||
String execute(CommandContext commandContext) throws NoSuchCommandException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.CommandImpl;
|
||||
|
||||
import com.alibaba.dubbo.qos.command.BaseCommand;
|
||||
|
|
@ -10,10 +26,6 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
@Cmd(name = "help", summary = "help command", example = {
|
||||
"help",
|
||||
"help online"
|
||||
|
|
@ -62,7 +74,7 @@ public class Help implements BaseCommand {
|
|||
}
|
||||
|
||||
/*
|
||||
* 输出主帮助菜单
|
||||
* output main help
|
||||
*/
|
||||
private String mainHelp() {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.CommandImpl;
|
||||
|
||||
import com.alibaba.dubbo.config.model.ApplicationModel;
|
||||
|
|
@ -14,10 +30,6 @@ import com.alibaba.dubbo.registry.support.ProviderInvokerWrapper;
|
|||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/22
|
||||
*/
|
||||
@Cmd(name = "ls", summary = "ls service", example = {
|
||||
"ls"
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.CommandImpl;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||
|
|
@ -16,10 +32,6 @@ import com.alibaba.dubbo.registry.support.ProviderInvokerWrapper;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
@Cmd(name = "offline", summary = "offline dubbo", example = {
|
||||
"offline dubbo",
|
||||
"offline xx.xx.xxx.service"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.CommandImpl;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||
|
|
@ -16,10 +32,6 @@ import com.alibaba.dubbo.registry.support.ProviderInvokerWrapper;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
@Cmd(name = "online", summary = "online dubbo", example = {
|
||||
"online dubbo",
|
||||
"online xx.xx.xxx.service"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.CommandImpl;
|
||||
|
||||
import com.alibaba.dubbo.qos.command.BaseCommand;
|
||||
|
|
@ -5,10 +21,6 @@ import com.alibaba.dubbo.qos.command.CommandContext;
|
|||
import com.alibaba.dubbo.qos.command.annotation.Cmd;
|
||||
import com.alibaba.dubbo.qos.common.Constants;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
@Cmd(name = "quit",summary = "quit telnet console")
|
||||
public class Quit implements BaseCommand {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class DefaultCommandExecutor implements CommandExecutor {
|
||||
@Override
|
||||
public String execute(CommandContext commandContext) throws NoSuchCommandException {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class NoSuchCommandException extends Exception {
|
||||
public NoSuchCommandException(String msg) {
|
||||
super("NoSuchCommandException:" + msg);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
|
|
@ -6,37 +22,37 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 指令集
|
||||
* Command
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Cmd {
|
||||
|
||||
/**
|
||||
* 指定命令的名称<br/>
|
||||
* Command name
|
||||
*
|
||||
* @return 返回命令的名称
|
||||
* @return command name
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* 指定命令的解释
|
||||
* Command description
|
||||
*
|
||||
* @return 返回命令的解释
|
||||
* @return command description
|
||||
*/
|
||||
String summary();
|
||||
|
||||
/**
|
||||
* 例子
|
||||
* Command example
|
||||
*
|
||||
* @return 返回命令的例子
|
||||
* @return command example
|
||||
*/
|
||||
String[] example() default {};
|
||||
|
||||
/**
|
||||
* 排序,在help命令中
|
||||
* Command order in help
|
||||
*
|
||||
* @return 返回命令在目录中的排序
|
||||
* @return command order in help
|
||||
*/
|
||||
int sort() default 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.decoder;
|
||||
|
||||
import com.alibaba.dubbo.qos.command.CommandContext;
|
||||
|
|
@ -14,10 +30,6 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class HttpCommandDecoder {
|
||||
public static CommandContext decode(HttpRequest request) {
|
||||
CommandContext commandContext = null;
|
||||
|
|
@ -28,9 +40,7 @@ public class HttpCommandDecoder {
|
|||
if (array.length == 2) {
|
||||
String name = array[1];
|
||||
|
||||
// Get请求和Post请求分开处理
|
||||
// Get看url的Path
|
||||
// Post看请求正文
|
||||
// process GET request and POST request separately. Check url for GET, and check body for POST
|
||||
if (request.getMethod() == HttpMethod.GET) {
|
||||
if (queryStringDecoder.parameters().isEmpty()) {
|
||||
commandContext = CommandContextFactory.newInstance(name);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.decoder;
|
||||
|
||||
import com.alibaba.dubbo.qos.command.CommandContext;
|
||||
|
|
@ -5,10 +21,6 @@ import com.alibaba.dubbo.qos.command.CommandContextFactory;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class TelnetCommandDecoder {
|
||||
public static final CommandContext decode(String str) {
|
||||
CommandContext commandContext = null;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.command.util;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||
|
|
@ -7,10 +23,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
public class CommandHelper {
|
||||
public static boolean hasCommand(String commandName) {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,29 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.common;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public interface Constants {
|
||||
|
||||
int DEFAULT_PORT = 22222;
|
||||
// 通过-D参数指定port
|
||||
// system property for specifying qos port
|
||||
String QOS_PORT = "dubbo.qos.port";
|
||||
String BR_STR = "\r\n";
|
||||
String CLOSE = "close!";
|
||||
|
||||
// 通过-D参数指定当前qos是否能够拒绝外部ip的联入
|
||||
// system property for whether to accept foreign IP to connect or not
|
||||
String ACCEPT_FOREIGN_IP = "dubbo.qos.accept.foreign.ip";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.server;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
public class DubboLogo {
|
||||
public static String dubbo =
|
||||
" ████████▄ ███ █▄ ▀█████████▄ ▀█████████▄ ▄██████▄ \n" +
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.server;
|
||||
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
|
|
@ -5,7 +21,6 @@ import com.alibaba.dubbo.common.logger.LoggerFactory;
|
|||
import com.alibaba.dubbo.common.utils.ConfigUtils;
|
||||
import com.alibaba.dubbo.qos.common.Constants;
|
||||
import com.alibaba.dubbo.qos.server.handler.QosProcessHandler;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
|
|
@ -18,15 +33,12 @@ import io.netty.util.concurrent.DefaultThreadFactory;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 该Server监听指定的端口,能够提供telnet以及HTTP的访问
|
||||
*
|
||||
* 通过静态方法创建Server
|
||||
* 负责启动Server,绑定监听端口
|
||||
* 关闭Server
|
||||
* </pre>
|
||||
*
|
||||
* @author weipeng2k 2015年8月27日 上午11:29:27
|
||||
* A server serves for both telnet access and http access
|
||||
* <ul>
|
||||
* <li>static initialize server</li>
|
||||
* <li>start server and bind port</li>
|
||||
* <li>close server</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class Server {
|
||||
|
||||
|
|
@ -56,16 +68,14 @@ public class Server {
|
|||
private AtomicBoolean hasStarted = new AtomicBoolean();
|
||||
|
||||
/**
|
||||
* 设置telnet提供的welcome信息
|
||||
*
|
||||
* @param welcome
|
||||
* welcome message
|
||||
*/
|
||||
public void setWelcome(String welcome) {
|
||||
this.welcome = welcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动server,绑定端口
|
||||
* start server, bind port
|
||||
*/
|
||||
public void start() throws Throwable {
|
||||
if (!hasStarted.compareAndSet(false, true)) {
|
||||
|
|
@ -95,7 +105,7 @@ public class Server {
|
|||
}
|
||||
|
||||
/**
|
||||
* 关闭server
|
||||
* close server
|
||||
*/
|
||||
public void stop() {
|
||||
logger.info("qos-server stopped.");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.server.handler;
|
||||
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
|
|
@ -7,7 +23,6 @@ import com.alibaba.dubbo.qos.command.CommandExecutor;
|
|||
import com.alibaba.dubbo.qos.command.DefaultCommandExecutor;
|
||||
import com.alibaba.dubbo.qos.command.NoSuchCommandException;
|
||||
import com.alibaba.dubbo.qos.command.decoder.HttpCommandDecoder;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
|
@ -20,17 +35,15 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
|||
import io.netty.handler.codec.http.HttpVersion;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 根据传入的HttpRequest进行解析,分析uri以及参数
|
||||
*
|
||||
* 如果命令没有找到返回404
|
||||
* 如果执行失败500
|
||||
* 执行成功则返回内容200
|
||||
*
|
||||
* Http连接均在执行完毕之后断开
|
||||
* </pre>
|
||||
*
|
||||
* @author weipeng2k 2015年9月1日 下午5:13:56
|
||||
* Parse HttpRequest for uri and parameters
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>if command not found, return 404</li>
|
||||
* <li>if execution fails, return 500</li>
|
||||
* <li>if succeed, return 200</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* will disconnect after execution finishes
|
||||
*/
|
||||
public class HttpProcessHandler extends SimpleChannelInboundHandler<HttpRequest> {
|
||||
|
||||
|
|
@ -41,7 +54,8 @@ public class HttpProcessHandler extends SimpleChannelInboundHandler<HttpRequest>
|
|||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception {
|
||||
CommandContext commandContext = HttpCommandDecoder.decode(msg);
|
||||
if (commandContext == null) { // 如果命令无法构造返回404
|
||||
// return 404 when fail to construct command context
|
||||
if (commandContext == null) {
|
||||
log.warn("can not found commandContext url: " + msg.getUri());
|
||||
FullHttpResponse response = http_404();
|
||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,18 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.server.handler;
|
||||
|
||||
|
|
@ -15,12 +28,9 @@ import io.netty.channel.ChannelHandlerContext;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* @author weipeng2k 2015年9月6日 下午5:52:26
|
||||
*/
|
||||
public class LocalHostPermitHandler extends ChannelHandlerAdapter {
|
||||
|
||||
// true表示能够远端连接
|
||||
// true means to accept foreign IP
|
||||
private static boolean acceptForeignIp = Boolean.valueOf(ConfigUtils.getProperty(Constants.ACCEPT_FOREIGN_IP, "true"));
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.server.handler;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
|
@ -17,10 +33,6 @@ import io.netty.util.concurrent.ScheduledFuture;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author weipeng2k
|
||||
* @author qinliujie
|
||||
*/
|
||||
public class QosProcessHandler extends ByteToMessageDecoder {
|
||||
|
||||
private ScheduledFuture<?> welcomeFuture;
|
||||
|
|
@ -54,13 +66,13 @@ public class QosProcessHandler extends ByteToMessageDecoder {
|
|||
return;
|
||||
}
|
||||
|
||||
// 读入一个byte来猜协议
|
||||
// read one byte to guess protocol
|
||||
final int magic = in.getByte(in.readerIndex());
|
||||
|
||||
ChannelPipeline p = ctx.pipeline();
|
||||
p.addLast(new LocalHostPermitHandler());
|
||||
if (isHttp(magic)) {
|
||||
// HTTP协议不做welcome输出
|
||||
// no welcome output for http protocol
|
||||
if (welcomeFuture != null && welcomeFuture.isCancellable()) {
|
||||
welcomeFuture.cancel(false);
|
||||
}
|
||||
|
|
@ -77,9 +89,8 @@ public class QosProcessHandler extends ByteToMessageDecoder {
|
|||
p.remove(this);
|
||||
}
|
||||
}
|
||||
//Http 请求头 GET/POST,就酱紫 QWQ
|
||||
// G for GET, and P for POST
|
||||
private static boolean isHttp(int magic) {
|
||||
return magic == 'G' || magic == 'P';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.server.handler;
|
||||
|
||||
|
||||
|
|
@ -16,12 +32,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 接受telnet协议,其实就是用户提交的内容,使用\r\n结尾,当然已经被netty过滤了\r\n了。
|
||||
* 经过了StringDecoder相关的Decode过程
|
||||
* </pre>
|
||||
*
|
||||
* @author weipeng2k
|
||||
* Telnet process handler
|
||||
*/
|
||||
public class TelnetProcessHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,28 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.textui;
|
||||
|
||||
/**
|
||||
* 命令行控件<br/>
|
||||
* Created by oldmanpushcart@gmail.com on 15/5/7.
|
||||
* render component
|
||||
*/
|
||||
public interface TComponent {
|
||||
|
||||
/**
|
||||
* 渲染组件内容
|
||||
* render
|
||||
*/
|
||||
String rendering();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.textui;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -5,8 +21,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* KV排版控件
|
||||
* Created by oldmanpushcart@gmail.com on 15/5/9.
|
||||
* KV
|
||||
*/
|
||||
public class TKv implements TComponent {
|
||||
|
||||
|
|
@ -42,13 +57,6 @@ public class TKv implements TComponent {
|
|||
return filterEmptyLine(tTable.rendering());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 出现多余的空行的原因是,KVview在输出时,会补全空格到最长的长度。所以在"yyyyy”后面会多出来很多的空格。
|
||||
* 再经过TableView的固定列处理,多余的空格就会在一行里放不下,输出成两行(第二行前面是空格)
|
||||
*
|
||||
* @see https://github.com/oldmanpushcart/greys-anatomy/issues/82
|
||||
*/
|
||||
private String filterEmptyLine(String content) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
Scanner scanner = null;
|
||||
|
|
@ -57,7 +65,7 @@ public class TKv implements TComponent {
|
|||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line != null) {
|
||||
//清理一行后面多余的空格
|
||||
// remove extra space at line's end
|
||||
line = StringUtils.stripEnd(line, " ");
|
||||
if (line.isEmpty()) {
|
||||
line = " ";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.textui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -6,18 +22,17 @@ import java.util.List;
|
|||
import static org.apache.commons.lang3.StringUtils.repeat;
|
||||
|
||||
/**
|
||||
* 阶梯缩进控件
|
||||
* Created by oldmanpushcart@gmail.com on 15/5/8.
|
||||
* Ladder
|
||||
*/
|
||||
public class TLadder implements TComponent {
|
||||
|
||||
// 分隔符
|
||||
// separator
|
||||
private static final String LADDER_CHAR = "`-";
|
||||
|
||||
// 缩进符
|
||||
// tab
|
||||
private static final String STEP_CHAR = " ";
|
||||
|
||||
// 缩进长度
|
||||
// indent length
|
||||
private static final int INDENT_STEP = 2;
|
||||
|
||||
private final List<String> items = new ArrayList<String>();
|
||||
|
|
@ -29,14 +44,14 @@ public class TLadder implements TComponent {
|
|||
int deep = 0;
|
||||
for (String item : items) {
|
||||
|
||||
// 第一个条目不需要分隔符
|
||||
// no separator is required for the first item
|
||||
if (deep == 0) {
|
||||
ladderSB
|
||||
.append(item)
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
// 其他的需要添加分隔符
|
||||
// need separator for others
|
||||
else {
|
||||
ladderSB
|
||||
.append(repeat(STEP_CHAR, deep * INDENT_STEP))
|
||||
|
|
@ -52,10 +67,7 @@ public class TLadder implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 添加一个项目
|
||||
*
|
||||
* @param item 项目
|
||||
* @return this
|
||||
* add one item
|
||||
*/
|
||||
public TLadder addItem(String item) {
|
||||
items.add(item);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.textui;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -15,18 +31,17 @@ import static org.apache.commons.lang3.StringUtils.length;
|
|||
import static org.apache.commons.lang3.StringUtils.repeat;
|
||||
|
||||
/**
|
||||
* 表格组件
|
||||
* Created by oldmanpushcart@gmail.com on 15/5/7.
|
||||
* Table
|
||||
*/
|
||||
public class TTable implements TComponent {
|
||||
|
||||
// 各个列的定义
|
||||
// column definition
|
||||
private final ColumnDefine[] columnDefineArray;
|
||||
|
||||
// 边框
|
||||
// border
|
||||
private final Border border = new Border();
|
||||
|
||||
// 内边距
|
||||
// padding
|
||||
private int padding;
|
||||
|
||||
public TTable(ColumnDefine[] columnDefineArray) {
|
||||
|
|
@ -59,23 +74,23 @@ public class TTable implements TComponent {
|
|||
final boolean isFirstRow = rowIndex == 0;
|
||||
final boolean isLastRow = rowIndex == rowCount - 1;
|
||||
|
||||
// 打印首分隔行
|
||||
// print first separation line
|
||||
if (isFirstRow
|
||||
&& border.has(Border.BORDER_OUTER_TOP)) {
|
||||
tableSB.append(drawSeparationLine(widthCacheArray)).append("\n");
|
||||
}
|
||||
|
||||
// 打印内部分割行
|
||||
// print inner separation lines
|
||||
if (!isFirstRow
|
||||
&& border.has(Border.BORDER_INNER_H)) {
|
||||
tableSB.append(drawSeparationLine(widthCacheArray)).append("\n");
|
||||
}
|
||||
|
||||
// 绘一行
|
||||
// draw one line
|
||||
tableSB.append(drawRow(widthCacheArray, rowIndex));
|
||||
|
||||
|
||||
// 打印结尾分隔行
|
||||
// print ending separation line
|
||||
if (isLastRow
|
||||
&& border.has(Border.BORDER_OUTER_BOTTOM)) {
|
||||
tableSB.append(drawSeparationLine(widthCacheArray)).append("\n");
|
||||
|
|
@ -189,8 +204,8 @@ public class TTable implements TComponent {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取表格行数
|
||||
/**
|
||||
* get row count
|
||||
*/
|
||||
private int getRowCount() {
|
||||
int rowCount = 0;
|
||||
|
|
@ -200,8 +215,8 @@ public class TTable implements TComponent {
|
|||
return rowCount;
|
||||
}
|
||||
|
||||
/*
|
||||
* 定位最后一个列
|
||||
/**
|
||||
* position to last column
|
||||
*/
|
||||
private int indexLastCol(final int[] widthCacheArray) {
|
||||
for (int colIndex = widthCacheArray.length - 1; colIndex >= 0; colIndex--) {
|
||||
|
|
@ -214,8 +229,8 @@ public class TTable implements TComponent {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 打印分隔行
|
||||
/**
|
||||
* draw separation line
|
||||
*/
|
||||
private String drawSeparationLine(final int[] widthCacheArray) {
|
||||
final StringBuilder separationLineSB = new StringBuilder();
|
||||
|
|
@ -253,9 +268,7 @@ public class TTable implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 添加数据行
|
||||
*
|
||||
* @param columnDataArray 数据数组
|
||||
* Add a row
|
||||
*/
|
||||
public TTable addRow(Object... columnDataArray) {
|
||||
|
||||
|
|
@ -276,41 +289,41 @@ public class TTable implements TComponent {
|
|||
|
||||
|
||||
/**
|
||||
* 对齐方向
|
||||
* alignment
|
||||
*/
|
||||
public enum Align {
|
||||
|
||||
/**
|
||||
* 左对齐
|
||||
* left-alignment
|
||||
*/
|
||||
LEFT,
|
||||
|
||||
/**
|
||||
* 右对齐
|
||||
* right-alignment
|
||||
*/
|
||||
RIGHT,
|
||||
|
||||
/**
|
||||
* 居中对齐
|
||||
* middle-alignment
|
||||
*/
|
||||
MIDDLE
|
||||
}
|
||||
|
||||
/**
|
||||
* 列定义
|
||||
* column definition
|
||||
*/
|
||||
public static class ColumnDefine {
|
||||
|
||||
// 列宽度
|
||||
// column width
|
||||
private final int width;
|
||||
|
||||
// 是否自动宽度
|
||||
// whether to auto resize
|
||||
private final boolean isAutoResize;
|
||||
|
||||
// 对齐方式
|
||||
// alignment
|
||||
private final Align align;
|
||||
|
||||
// 数据行集合
|
||||
// data rows
|
||||
private final List<String> rows = new ArrayList<String>();
|
||||
|
||||
public ColumnDefine(int width, boolean isAutoResize, Align align) {
|
||||
|
|
@ -336,18 +349,18 @@ public class TTable implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取当前列的宽度
|
||||
* get current width
|
||||
*
|
||||
* @return 宽度
|
||||
* @return width
|
||||
*/
|
||||
public int getWidth() {
|
||||
|
||||
// 如果是固定宽度,则直接返回预设定的宽度
|
||||
// if not auto resize, return preset width
|
||||
if (!isAutoResize) {
|
||||
return width;
|
||||
}
|
||||
|
||||
// 如果是自动扩展宽度,则需要根据计算当前列的所有字符串最大可视宽度
|
||||
// if it's auto resize, then calculate the possible max width
|
||||
int maxWidth = 0;
|
||||
for (String data : rows) {
|
||||
maxWidth = max(width(data), maxWidth);
|
||||
|
|
@ -357,9 +370,9 @@ public class TTable implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取当前列的行数
|
||||
* get rows for the current column
|
||||
*
|
||||
* @return 当前列的行数
|
||||
* @return current column's rows
|
||||
*/
|
||||
public int getRowCount() {
|
||||
return rows.size();
|
||||
|
|
@ -368,9 +381,9 @@ public class TTable implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 设置内边距大小
|
||||
* set padding
|
||||
*
|
||||
* @param padding 内边距
|
||||
* @param padding padding
|
||||
*/
|
||||
public TTable padding(int padding) {
|
||||
this.padding = padding;
|
||||
|
|
@ -378,9 +391,9 @@ public class TTable implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取表格列总数
|
||||
* get column count
|
||||
*
|
||||
* @return 表格列总数
|
||||
* @return column count
|
||||
*/
|
||||
public int getColumnCount() {
|
||||
return columnDefineArray.length;
|
||||
|
|
@ -388,23 +401,22 @@ public class TTable implements TComponent {
|
|||
|
||||
|
||||
/**
|
||||
* 替换TAB制表符<br/>
|
||||
* 替换为4个空格
|
||||
* replace tab to four spaces
|
||||
*
|
||||
* @param string 原始字符串
|
||||
* @return 替换后的字符串
|
||||
* @param string the original string
|
||||
* @return the replaced string
|
||||
*/
|
||||
private static String replaceTab(String string) {
|
||||
return StringUtils.replace(string, "\t", " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个字符串的可视宽度<br/>
|
||||
* 什么叫一个字符串的可视宽度呢?很简单,因为字符串有换行行为,所以一个字符串的宽度不能简单的根据字符串的长度来判断<br/>
|
||||
* 例如:"abc\n1234",这个字符串的可视宽度为4
|
||||
* visible width for the given string.
|
||||
*
|
||||
* @param string 字符串
|
||||
* @return 字符串可视宽度
|
||||
* for example: "abc\n1234"'s width is 4.
|
||||
*
|
||||
* @param string the given string
|
||||
* @return visible width
|
||||
*/
|
||||
private static int width(String string) {
|
||||
int maxWidth = 0;
|
||||
|
|
@ -421,71 +433,71 @@ public class TTable implements TComponent {
|
|||
|
||||
/**
|
||||
* 获取表格边框设置
|
||||
* get border
|
||||
*
|
||||
* @return 表格边框
|
||||
* @return table border
|
||||
*/
|
||||
public Border getBorder() {
|
||||
return border;
|
||||
}
|
||||
|
||||
/**
|
||||
* 边框样式设置
|
||||
* border style
|
||||
*/
|
||||
public class Border {
|
||||
|
||||
private int borders = BORDER_OUTER | BORDER_INNER;
|
||||
|
||||
/**
|
||||
* 外部上边框
|
||||
* border outer top
|
||||
*/
|
||||
public static final int BORDER_OUTER_TOP = 1 << 0;
|
||||
|
||||
/**
|
||||
* 外部右边框
|
||||
* border outer right
|
||||
*/
|
||||
public static final int BORDER_OUTER_RIGHT = 1 << 1;
|
||||
|
||||
/**
|
||||
* 外部下边框
|
||||
* border outer bottom
|
||||
*/
|
||||
public static final int BORDER_OUTER_BOTTOM = 1 << 2;
|
||||
|
||||
/**
|
||||
* 外部左边框
|
||||
* border outer left
|
||||
*/
|
||||
public static final int BORDER_OUTER_LEFT = 1 << 3;
|
||||
|
||||
/**
|
||||
* 内边框:水平
|
||||
* inner border: horizon
|
||||
*/
|
||||
public static final int BORDER_INNER_H = 1 << 4;
|
||||
|
||||
/**
|
||||
* 内边框:垂直
|
||||
* inner border: vertical
|
||||
*/
|
||||
public static final int BORDER_INNER_V = 1 << 5;
|
||||
|
||||
/**
|
||||
* 外边框
|
||||
* outer border
|
||||
*/
|
||||
public static final int BORDER_OUTER = BORDER_OUTER_TOP | BORDER_OUTER_BOTTOM | BORDER_OUTER_LEFT | BORDER_OUTER_RIGHT;
|
||||
|
||||
/**
|
||||
* 内边框
|
||||
* inner border
|
||||
*/
|
||||
public static final int BORDER_INNER = BORDER_INNER_H | BORDER_INNER_V;
|
||||
|
||||
/**
|
||||
* 无边框
|
||||
* no border
|
||||
*/
|
||||
public static final int BORDER_NON = 0;
|
||||
|
||||
/**
|
||||
* 是否包含指定边框类型<br/>
|
||||
* 只要当前边框策略命中其中之一即认为命中
|
||||
* whether has one of the specified border styles
|
||||
*
|
||||
* @param borderArray 目标边框数组
|
||||
* @return 当前边框策略是否拥有指定的边框
|
||||
* @param borderArray border styles
|
||||
* @return whether has one of the specified border styles
|
||||
*/
|
||||
public boolean has(int... borderArray) {
|
||||
if (null == borderArray) {
|
||||
|
|
@ -500,18 +512,18 @@ public class TTable implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取表格边框设置
|
||||
* get border style
|
||||
*
|
||||
* @return 边框位
|
||||
* @return border style
|
||||
*/
|
||||
public int get() {
|
||||
return borders;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表格边框
|
||||
* set border style
|
||||
*
|
||||
* @param border 边框位
|
||||
* @param border border style
|
||||
* @return this
|
||||
*/
|
||||
public Border set(int border) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.textui;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -12,8 +28,7 @@ import static org.apache.commons.lang3.StringUtils.EMPTY;
|
|||
import static org.apache.commons.lang3.StringUtils.repeat;
|
||||
|
||||
/**
|
||||
* 树形控件
|
||||
* Created by oldmanpushcart@gmail.com on 15/5/26.
|
||||
* tree
|
||||
*/
|
||||
public class TTree implements TComponent {
|
||||
|
||||
|
|
@ -22,13 +37,13 @@ public class TTree implements TComponent {
|
|||
private static final String STEP_HAS_BOARD = "| ";
|
||||
private static final String STEP_EMPTY_BOARD = " ";
|
||||
|
||||
// 是否输出耗时
|
||||
// should output cost or not
|
||||
private final boolean isPrintCost;
|
||||
|
||||
// 根节点
|
||||
// tree node
|
||||
private final Node root;
|
||||
|
||||
// 当前节点
|
||||
// current node
|
||||
private Node current;
|
||||
|
||||
|
||||
|
|
@ -93,7 +108,7 @@ public class TTree implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 递归遍历
|
||||
* recursive visit
|
||||
*/
|
||||
private void recursive(int deep, boolean isLast, String prefix, Node node, Callback callback) {
|
||||
callback.callback(deep, isLast, prefix, node);
|
||||
|
|
@ -118,9 +133,9 @@ public class TTree implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 创建一个分支节点
|
||||
* create a branch node
|
||||
*
|
||||
* @param data 节点数据
|
||||
* @param data node data
|
||||
* @return this
|
||||
*/
|
||||
public TTree begin(Object data) {
|
||||
|
|
@ -149,7 +164,7 @@ public class TTree implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 结束一个分支节点
|
||||
* end a branch node
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
|
|
@ -164,37 +179,37 @@ public class TTree implements TComponent {
|
|||
|
||||
|
||||
/**
|
||||
* 树节点
|
||||
* tree node
|
||||
*/
|
||||
private static class Node {
|
||||
|
||||
/**
|
||||
* 父节点
|
||||
* parent node
|
||||
*/
|
||||
final Node parent;
|
||||
|
||||
/**
|
||||
* 节点数据
|
||||
* node data
|
||||
*/
|
||||
Object data;
|
||||
|
||||
/**
|
||||
* 子节点
|
||||
* child nodes
|
||||
*/
|
||||
final List<Node> children = new ArrayList<Node>();
|
||||
|
||||
/**
|
||||
* 开始时间戳
|
||||
* begin timestamp
|
||||
*/
|
||||
private long beginTimestamp;
|
||||
|
||||
/**
|
||||
* 结束时间戳
|
||||
* end timestamp
|
||||
*/
|
||||
private long endTimestamp;
|
||||
|
||||
/**
|
||||
* 构造树节点(根节点)
|
||||
* construct root node
|
||||
*/
|
||||
private Node(Object data) {
|
||||
this.parent = null;
|
||||
|
|
@ -202,10 +217,10 @@ public class TTree implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 构造树节点
|
||||
* construct a regular node
|
||||
*
|
||||
* @param parent 父节点
|
||||
* @param data 节点数据
|
||||
* @param parent parent node
|
||||
* @param data node data
|
||||
*/
|
||||
private Node(Node parent, Object data) {
|
||||
this.parent = parent;
|
||||
|
|
@ -214,7 +229,7 @@ public class TTree implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 是否根节点
|
||||
* is the current node the root node
|
||||
*
|
||||
* @return true / false
|
||||
*/
|
||||
|
|
@ -223,7 +238,7 @@ public class TTree implements TComponent {
|
|||
}
|
||||
|
||||
/**
|
||||
* 是否叶子节点
|
||||
* if the current node the leaf node
|
||||
*
|
||||
* @return true / false
|
||||
*/
|
||||
|
|
@ -245,7 +260,7 @@ public class TTree implements TComponent {
|
|||
|
||||
|
||||
/**
|
||||
* 遍历回调接口
|
||||
* callback interface for recursive visit
|
||||
*/
|
||||
private interface Callback {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/20
|
||||
*/
|
||||
public class StringSplitTest {
|
||||
@Test
|
||||
public void stringSplitTest(){
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.alibaba.dubbo.qos.textui;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author qinliujie
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class TKvTest {
|
||||
@Test
|
||||
public void outPutTest() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You 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.
|
||||
-->
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
|
|
|
|||
Loading…
Reference in New Issue