Skip to content

Commit

Permalink
Merge pull request #1 from CST-Group/beta_release
Browse files Browse the repository at this point in the history
Beta release
  • Loading branch information
brgsil authored Nov 11, 2024
2 parents a13bed2 + 2725d42 commit 0e73298
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 36 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,52 @@ 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
```

## Example

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
```
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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']}
Expand Down
2 changes: 1 addition & 1 deletion package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'cscli'
rootProject.name = 'cst_cli'
2 changes: 1 addition & 1 deletion src/main/java/br/unicamp/cst/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 27 additions & 19 deletions src/main/java/br/unicamp/cst/cli/commands/CSTInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> {
public static String TAB = " ";
public static String PARSER_ERROR = "Error parsing config file";
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/br/unicamp/cst/cli/commands/CSTSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/br/unicamp/cst/cli/data/AgentConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/br/unicamp/cst/cli/data/CodeletConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,8 @@ public String toString() {
", broadcast=" + broadcast +
'}';
}

public String getPackage() {
return ".codelets." + group.toLowerCase() + "." + name;
}
}
4 changes: 2 additions & 2 deletions src/main/java/br/unicamp/cst/cli/data/ConfigParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 0e73298

Please sign in to comment.