Skip to content

Commit

Permalink
Merge pull request #684 from kyonRay/release-3.0.1
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
kyonRay authored Sep 23, 2022
2 parents 65efac8 + 1e66b5f commit 0e7c33b
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 109 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ dependencies {
//compile 'org.fisco-bcos:solcJ:0.5.2.1'
compile 'org.fisco-bcos:solcJ:0.8.11.1'

compile('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.0.0')
compile('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.0.1-SNAPSHOT')
compile('org.fisco-bcos:evm-static-analysis:1.0.0-rc3')
compile('commons-cli:commons-cli:1.3.1')
compile('org.jline:jline:3.12.0')
compile('commons-cli:commons-cli:1.5.0')
compile('org.jline:jline:3.21.0')
compile('io.bretty:console-table-builder:1.2')
compile('com.github.jsqlparser:jsqlparser:2.0')
compile('com.github.jsqlparser:jsqlparser:4.5')
compile('org.fisco-bcos.code-generator:bcos-code-generator:1.0.0') {
exclude group: "org.fisco-bcos.java-sdk"
exclude group: "org.slf4j"
}
testCompile('com.github.stefanbirkner:system-rules:1.18.0')
testCompile('junit:junit:4.13.1')
testCompile('com.github.stefanbirkner:system-rules:1.19.0')
testCompile('junit:junit:4.13.2')
}

configurations.all {
Expand Down
2 changes: 1 addition & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.0.0-rc2
v3.0.1
18 changes: 17 additions & 1 deletion src/main/java/console/command/JlineUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ public static LineReader getLineReader(Client client) throws IOException {
completers.add(
new ArgumentCompleter(
new StringsCompleter(command),
new ConsoleFilesCompleter(new File(ContractCompiler.SOLIDITY_PATH)),
new ConsoleFilesCompleter(
new File(ContractCompiler.SOLIDITY_PATH), false),
new StringsCompleterIgnoreCase()));
completers.add(
new ArgumentCompleter(
new StringsCompleter(command),
new StringsCompleter("-l"),
currentPathCompleter,
new ConsoleFilesCompleter(
new File(ContractCompiler.SOLIDITY_PATH), false),
new StringsCompleterIgnoreCase()));
}
// contract address and method completer
Expand Down Expand Up @@ -125,6 +134,13 @@ public static LineReader getLineReader(Client client) throws IOException {
new StringsCompleter(command),
new ConsoleFilesCompleter(
new File(ContractCompiler.LIQUID_PATH), true),
currentPathCompleter,
new StringsCompleterIgnoreCase()));
completers.add(
new ArgumentCompleter(
new StringsCompleter(command),
new StringsCompleter("-l"),
currentPathCompleter,
new ConsoleFilesCompleter(
new File(ContractCompiler.LIQUID_PATH), true),
currentPathCompleter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {

public static void setIsWasm(boolean wasm) {
isWasm = wasm;
DEPLOY.setMinParamLength(wasm ? 3 : 1);
DEPLOY.setMinParamLength(wasm ? 2 : 1);
}

public static final CommandInfo DEPLOY =
Expand Down
155 changes: 89 additions & 66 deletions src/main/java/console/command/completer/ConsoleFilesCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jline.builtins.Completers;
import org.jline.reader.Candidate;
import org.jline.reader.LineReader;
import org.jline.reader.ParsedLine;
import org.jline.terminal.Terminal;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import org.jline.utils.StyleResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,17 +23,18 @@ public class ConsoleFilesCompleter extends Completers.FilesCompleter {
private static final Logger logger = LoggerFactory.getLogger(ConsoleFilesCompleter.class);

public final String SOL_STR = ".sol";
public final String WASM_STR = ".wasm";
public final String ABI_STR = ".abi";
public final String TABLE_SOL = "Table.sol";
public final String KV_TABLE_SOL = "KVTable.sol";
private static final Set<String> EXCLUDE_SOL = new HashSet<>();
private Path contractPath;
private boolean solidityCompleter = true;
private boolean isWasm = false;

static {
EXCLUDE_SOL.add("Table.sol");
EXCLUDE_SOL.add("Crypto.sol");
}

public ConsoleFilesCompleter(File contractFile) {
super(new File("." + File.separator));
contractPath = contractFile.toPath();
this(contractFile.toPath());
}

public ConsoleFilesCompleter(File contractFile, boolean isWasm) {
Expand All @@ -45,7 +49,8 @@ public ConsoleFilesCompleter(Path contractPath) {
}

@Override
protected String getDisplay(Terminal terminal, Path p) {
protected String getDisplay(
Terminal terminal, Path p, StyleResolver resolver, String separator) {
String name = p.getFileName().toString();
// do not display .sol
if (name.endsWith(SOL_STR)) {
Expand All @@ -54,7 +59,7 @@ protected String getDisplay(Terminal terminal, Path p) {
if (Files.isDirectory(p)) {
AttributedStringBuilder sb = new AttributedStringBuilder();
sb.styled(AttributedStyle.BOLD.foreground(AttributedStyle.RED), name);
sb.append("/");
sb.append(separator);
name = sb.toAnsi(terminal);
} else if (Files.isSymbolicLink(p)) {
AttributedStringBuilder sb = new AttributedStringBuilder();
Expand All @@ -68,16 +73,16 @@ protected String getDisplay(Terminal terminal, Path p) {
@Override
public void complete(
LineReader reader, ParsedLine commandLine, final List<Candidate> candidates) {
assert commandLine != null;
assert candidates != null;
String buffer = commandLine.word().substring(0, commandLine.wordCursor());
complete(buffer, reader, commandLine, candidates, solidityCompleter);
// complete contract path
complete(buffer, reader, candidates, true);
// complete userDir
complete(buffer, reader, candidates, false);
}

public void complete(
String buffer,
LineReader reader,
ParsedLine commandLine,
final List<Candidate> candidates,
boolean completeSol) {
Path current;
Expand All @@ -93,74 +98,92 @@ public void complete(
current = getUserHome().getParent().resolve(curBuf.substring(1));
}
} else {
current = contractPath.resolve(curBuf);
current = completeSol ? contractPath.resolve(curBuf) : getUserDir().resolve(curBuf);
}
} else {
curBuf = "";
current = contractPath;
current = completeSol ? contractPath : getUserDir();
}

try (DirectoryStream<Path> directoryStream =
Files.newDirectoryStream(current, this::accept)) {
if (!Files.exists(current)) {
return;
}
directoryStream.forEach(
p -> {
if (!Files.exists(p)) {
return;
}
String value = curBuf + p.getFileName().toString();
// filter not sol file and Table.sol and KVTable.sol
if (TABLE_SOL.equals(value) || KV_TABLE_SOL.equals(value)) {
return;
}
if (isWasm) {
if (!Files.isDirectory(p)
&& !value.endsWith(WASM_STR)
&& !value.endsWith(ABI_STR)) {
return;
}
} else {
if (solidityCompleter
&& !Files.isDirectory(p)
&& !value.endsWith(SOL_STR)) {
return;
}
}
if (Files.isDirectory(p)) {
candidates.add(
new Candidate(
value
+ (reader.isSet(
LineReader.Option
.AUTO_PARAM_SLASH)
? sep
: ""),
getDisplay(reader.getTerminal(), p),
null,
null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH)
? sep
: null,
null,
false));
} else {
if (solidityCompleter && completeSol) {
value = value.substring(0, value.length() - SOL_STR.length());
}
candidates.add(
new Candidate(
value,
getDisplay(reader.getTerminal(), p),
null,
null,
null,
null,
true));
}
if (isWasm) filterDisplayLiquid(reader, candidates, curBuf, p);
else filterDisplaySolidity(reader, candidates, curBuf, p);
});
} catch (Exception e) {
logger.error(" message: {}, e: {}", e.getMessage(), e);
}
}

private void filterDisplaySolidity(
LineReader reader, List<Candidate> candidates, String curBuf, Path p) {
if (!Files.exists(p)) {
return;
}
String value = curBuf + p.getFileName().toString();
// filter sol interface file
if (EXCLUDE_SOL.contains(value)) {
return;
}

if (solidityCompleter && !Files.isDirectory(p) && !value.endsWith(SOL_STR)) {
return;
}

if (Files.isDirectory(p)) {
candidates.add(
new Candidate(
value
+ (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH)
? File.separator
: ""),
getDisplay(reader.getTerminal(), p, null, File.separator),
null,
null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH)
? File.separator
: null,
null,
false));
} else {
value = value.substring(0, value.length() - SOL_STR.length());
candidates.add(
new Candidate(
value,
getDisplay(reader.getTerminal(), p, null, File.separator),
null,
null,
null,
null,
true));
}
}

private void filterDisplayLiquid(
LineReader reader, List<Candidate> candidates, String curBuf, Path p) {
if (!Files.exists(p)) {
return;
}
String value = curBuf + p.getFileName().toString();
if (!Files.isDirectory(p)) {
return;
}
candidates.add(
new Candidate(
value
+ (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH)
? File.separator
: ""),
getDisplay(reader.getTerminal(), p, null, File.separator),
null,
null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? File.separator : null,
null,
false));
}
}
11 changes: 5 additions & 6 deletions src/main/java/console/command/model/HelpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public static void deployHelp(boolean isWasm) {
"* contractNameOrPath -- The name of a contract or the path of a contract (Default load contract from the \"contracts/solidity\" path when using contractName).");
System.out.println(
"* parameters -- Parameters will be passed to constructor when deploying the contract.");
System.out.println(
"* -l[Optional] -- deploy with link, link BFS path after deploy contract success.");
System.out.println(
"* --parallel-analysis/-p[Optional] -- parallel conflict analysis with the contract, default: no.");
} else {
Expand All @@ -231,8 +233,6 @@ public static void deployHelp(boolean isWasm) {
"* path -- The path of BFS where the contract will be located at, such as '/apps/liquid/YouContract/'.");
System.out.println(
"* parameters -- Parameters will be passed to constructor when deploying the contract.");
System.out.println(
"* --parallel-analysis/-p[Optional] -- parallel conflict analysis with the contract, default: no.");
}
}

Expand Down Expand Up @@ -415,14 +415,13 @@ public static void startHelp() {

public static void listAbiHelp(boolean isWasm) {
System.out.println("List functions and events info of the contract.");
System.out.println("Usage: listAbi [contractPath/contractName]");
System.out.println("Usage: listAbi [contractPath/contractName/contractAddress]");
if (isWasm) {
System.out.println(
"contractPath[Required] -- The BFS path of Liquid contract, this contract should be deployed in this console.");
System.out.println("contractAddress[Required] -- The BFS path of Liquid contract.");
return;
}
System.out.println(
"contractPath/contractName[Required] -- The name or the path of a contract, if a name is specified, the contract should in the default directory \"contracts/solidity\"");
"contractPath/Name/Address[Required] -- The name or address or the path of a contract, if a name is specified, the contract should in the default directory \"contracts/solidity\"");
}

public static void changeDirHelp() {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/console/common/ConsoleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,15 @@ public static File getSolFile(String solFileNameOrPath, boolean checkExist)
}
filePath = ConsoleUtils.removeSolSuffix(filePath);
filePath += SOL_SUFFIX;
/** Check that the file exists in the default directory first */
// check again path file exist: contracts/solidity/Asset + .sol
solFile = new File(filePath);
if (solFile.exists()) {
return solFile;
}

// Check that the file exists in the default directory first
solFile = new File(SOLIDITY_PATH + File.separator + filePath);
/** file not exist */
// file not exist
if (!solFile.exists() && checkExist) {
throw new ConsoleMessageException(solFileNameOrPath + " does not exist ");
}
Expand All @@ -531,9 +537,9 @@ public static String getLiquidFilePath(String liquidFileNameOrPath)
if (liquidFile.exists()) {
return liquidFile.getAbsolutePath();
}
/** Check that the file exists in the default directory first */
// Check that the file exists in the default directory first
liquidFile = new File(LIQUID_PATH + File.separator + liquidFileNameOrPath);
/** file not exist */
// file not exist
if (!liquidFile.exists()) {
throw new ConsoleMessageException(liquidFileNameOrPath + " does not exist ");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/console/common/ConsoleVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ConsoleVersion {

public static final String Version = "3.0.0";
public static final String Version = "3.0.1";

public static void main(String[] args) {
System.out.println("console version: " + Version);
Expand Down
Loading

0 comments on commit 0e7c33b

Please sign in to comment.