diff --git a/README.md b/README.md index a9d7a5a..d473983 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,44 @@ This is a command line interface (CLI) to easily create [CST projects](https://c ## Installation -### Install from source +Download the deb (Debian/Ubuntu) or rpm package from the latest release, install it on your machine and add the executable to your `PATH` variable +```shell +echo 'export PATH="$PATH:/opt/cst-cli/bin"' +source ~/.bashrc +``` + + +**DEB package** +```shell +sudo apt install ./cst_cli_x.x.deb +OR +sudo dpkg -i ./cst_cli_x.x.deb +``` + +**RPM package** +```shell +sudo rpm -r ./cst_cli_v_x.x.rpm +``` + + + +### Local compile + +To compile and package the CLI locally is necessary to have [Docker](https://docs.docker.com/desktop/) install on your machine. 1. Clone this repository into a local folder ```shell git clone https://github.com/brgsil/CST-CLI.git ``` -2. Go into the repository directory and run the package task +2. Go into the repository directory and run the package script ```shell cd CST-CLI - ./gradlew jpackage - ``` -3. Install deb package - ```shell - apt install ./build/cst_cli-package/cscli_0.1-1_amd64.deb + ./package.sh ``` +3. Install deb or rpm package from `build/cst_cli` folder 4. Update `PATH` variable to include executable ```shell - echo 'export PATH="$PATH:/opt/cscli/bin"' >> ~/.bashrc + echo 'export PATH="$PATH:/opt/cst-cli/bin"' >> ~/.bashrc source ~/.bashrc ``` @@ -29,5 +49,7 @@ This is a command line interface (CLI) to easily create [CST projects](https://c To create a new example CST project run the command: ```shell -cst init -f test.yaml +mkdir TestProject +cd TestProject +cst init -f ../test.yaml ``` diff --git a/build.gradle b/build.gradle index cd57736..c6f2563 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,7 @@ jlink { } jpackage { //installerType = 'exe' - outputDir = 'cst_cli-package' + outputDir = 'cst_cli' imageName = 'cst' } //launcher {jvmArgs = ['--add-opens cscli/br.unicamp.cst.commands=ALL-UNNAMED']} diff --git a/package.sh b/package.sh index bfbdd97..05ba162 100755 --- a/package.sh +++ b/package.sh @@ -14,6 +14,6 @@ docker exec cst-package apt install rpm fakeroot binutils -y docker exec cst-package ./gradlew jpackage -docker exec cst-package chown -R $(id -u):$(id -g) build/ +docker exec -w /app cst-package chown -R $(id -u):$(id -g) build/ docker stop cst-package diff --git a/settings.gradle b/settings.gradle index 2b35362..cb45ff8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'cscli' \ No newline at end of file +rootProject.name = 'cst_cli' \ No newline at end of file diff --git a/src/main/java/br/unicamp/cst/cli/Main.java b/src/main/java/br/unicamp/cst/cli/Main.java index ca68b4c..277d5dc 100644 --- a/src/main/java/br/unicamp/cst/cli/Main.java +++ b/src/main/java/br/unicamp/cst/cli/Main.java @@ -9,7 +9,7 @@ @Command(name = "cst", synopsisSubcommandLabel = "COMMAND", mixinStandardHelpOptions = true, - version = "cst_cli 0.1", + version = "Beta Version 0.1", subcommands = { CSTInit.class, CSTSave.class, diff --git a/src/main/java/br/unicamp/cst/cli/commands/CSTInit.java b/src/main/java/br/unicamp/cst/cli/commands/CSTInit.java index 1c39e10..84d96da 100644 --- a/src/main/java/br/unicamp/cst/cli/commands/CSTInit.java +++ b/src/main/java/br/unicamp/cst/cli/commands/CSTInit.java @@ -25,7 +25,7 @@ import java.util.concurrent.Callable; import java.util.stream.Collectors; -@Command(name = "init", description = "Initialize a new CST project") +@Command(name = "init", description = "Initialize a new CST project", mixinStandardHelpOptions = true) public class CSTInit implements Callable { public static String TAB = " "; public static String PARSER_ERROR = "Error parsing config file"; @@ -64,25 +64,28 @@ public Integer call() throws Exception { private void checkCurrDir() { File[] existingFiles = new File(System.getProperty("user.dir")).listFiles(); - if (!(existingFiles.length == 0)){ - CommandLine.Model.OptionSpec overwriteOpt = spec.findOption("--overwrite"); - if (!spec.commandLine().getParseResult().hasMatchedOption(overwriteOpt)){ - String warning = Ansi.AUTO.string("@|bold,red WARNING:|@ @|red This directory is not empty.|@\n" - + "Options to resolve conflict are:\n" - + " (1) Overwrite all files\n" - + " (2) Add only different files\n" - + "Enter selection (default: 2) "); - System.out.print(warning); - Scanner input = new Scanner(System.in); - String inputName = input.nextLine(); - String ans = "2"; - if (!inputName.isBlank()) - ans = inputName; - overwrite = ans.equals("1"); + if (!(existingFiles.length == 0)) { + // Ignore configuration file + if (!Arrays.stream(existingFiles).allMatch(f -> f.getName().contains(".yaml"))) { + CommandLine.Model.OptionSpec overwriteOpt = spec.findOption("--overwrite"); + if (!spec.commandLine().getParseResult().hasMatchedOption(overwriteOpt)) { + String warning = Ansi.AUTO.string("@|bold,red WARNING:|@ @|red This directory is not empty.|@\n" + + "Options to resolve conflict are:\n" + + " (1) Overwrite all files\n" + + " (2) Add only different files\n" + + "Enter selection (default: 2) "); + System.out.print(warning); + Scanner input = new Scanner(System.in); + String inputName = input.nextLine(); + String ans = "2"; + if (!inputName.isBlank()) + ans = inputName; + overwrite = ans.equals("1"); + return; + } } - } else { - overwrite = true; } + overwrite = true; } private void getRequiredParams() { @@ -260,8 +263,13 @@ private static String mergeCode(String newCode, String currCode) { private void getAgentConfig() throws IOException { String configInfo = ""; - if (config != null) + if (config != null) { + if (!config.exists()) { + System.out.println("Configuration file do not exists!"); + System.exit(1); + } configInfo = Files.lines(config.toPath()).collect(Collectors.joining("\n")); + } if (configInfo.isBlank()) { agentConfig = new AgentConfig(); } else { diff --git a/src/main/java/br/unicamp/cst/cli/commands/CSTSave.java b/src/main/java/br/unicamp/cst/cli/commands/CSTSave.java index a2b9ed4..98059a9 100644 --- a/src/main/java/br/unicamp/cst/cli/commands/CSTSave.java +++ b/src/main/java/br/unicamp/cst/cli/commands/CSTSave.java @@ -20,7 +20,7 @@ public Integer call() throws Exception{ AgentConfig agentConfig = ConfigParser.parseProjectToConfig(); if (output == null) { - //System.out.println(agentConfig.toYaml()); + System.out.println(agentConfig.toYaml()); } else { FileWriter writer = new FileWriter(output); writer.write(agentConfig.toYaml()); diff --git a/src/main/java/br/unicamp/cst/cli/data/AgentConfig.java b/src/main/java/br/unicamp/cst/cli/data/AgentConfig.java index 8f9874a..5f3406d 100644 --- a/src/main/java/br/unicamp/cst/cli/data/AgentConfig.java +++ b/src/main/java/br/unicamp/cst/cli/data/AgentConfig.java @@ -167,7 +167,7 @@ else if (memory.getType().equals(CONTAINER_TYPE)) { } } - templateInstance = templateInstance.replace("{{rootPackage}}", packageName); + templateInstance = templateInstance.replace("{{rootPackage}}", packageName == null ? "" : packageName); templateInstance = templateInstance.replace("{{codeletsImport}}", codeletsImport.toString()); templateInstance = templateInstance.replace("{{codeletGroups}}", codeletGroups.toString()); templateInstance = templateInstance.replace("{{memoryGroups}}", memoryGroups.toString()); diff --git a/src/main/java/br/unicamp/cst/cli/data/CodeletConfig.java b/src/main/java/br/unicamp/cst/cli/data/CodeletConfig.java index cfd05a9..860bfaf 100644 --- a/src/main/java/br/unicamp/cst/cli/data/CodeletConfig.java +++ b/src/main/java/br/unicamp/cst/cli/data/CodeletConfig.java @@ -131,4 +131,8 @@ public String toString() { ", broadcast=" + broadcast + '}'; } + + public String getPackage() { + return ".codelets." + group.toLowerCase() + "." + name; + } } diff --git a/src/main/java/br/unicamp/cst/cli/data/ConfigParser.java b/src/main/java/br/unicamp/cst/cli/data/ConfigParser.java index 79fc967..5343247 100644 --- a/src/main/java/br/unicamp/cst/cli/data/ConfigParser.java +++ b/src/main/java/br/unicamp/cst/cli/data/ConfigParser.java @@ -63,7 +63,7 @@ public static AgentConfig parseProjectToConfig() { //agentConstructor.accept(new VariableCollector(MEMORY_CONTAINER_TYPE), memoryContainers); AgentConfig testConfig = new AgentConfig(); agentConstructor.accept(new AgentConfigCollector(), testConfig); - System.out.println(testConfig); + //System.out.println(testConfig); return testConfig; /* @@ -224,7 +224,7 @@ public void visit(VariableDeclarator vd, AgentConfig agentConfig){ MemoryConfig memoryConfig = agentConfig.findMemoryOrCreate(vd.getNameAsString()); memoryConfig.setType(MemoryConfig.OBJECT_TYPE); } else if (vd.getTypeAsString().equals(MEMORY_CONTAINER_TYPE)) { - System.out.println(vd.toString()); + //System.out.println(vd.toString()); MemoryConfig memoryConfig = agentConfig.findMemoryOrCreate(vd.getNameAsString()); memoryConfig.setType(MemoryConfig.CONTAINER_TYPE); } else if (vd.getTypeAsString().equals(MEMORY_BASE_TYPE)) {