Skip to content

Commit

Permalink
Update assets, poms, add blank api template
Browse files Browse the repository at this point in the history
  • Loading branch information
mloukili committed Mar 6, 2018
1 parent e8d71cf commit e43a056
Show file tree
Hide file tree
Showing 59 changed files with 931 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private static void start () throws Exception {

Software = Json.load (new File (Home, "update.json"));

upgrade ();
if (!Json.isNullOrEmpty (Software)) {
upgrade ();
}

Scl =
new PackageClassLoader (
Expand Down Expand Up @@ -188,7 +190,7 @@ private static boolean download () {

System.out.println ("\n Newer version found " + newVersion);

System.out.println ("\n Download software version [" + newVersion + "]");
System.out.println ("\n Download [" + newVersion + "]");

GetRequest downloadRequest = new GetRequest (HttpUtils.createEndpoint (new URI ( uDownload )));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class CliUtils {

public static final String VersionPrefix = "bn.version-";
public static final String VersionPrefix = "bnb.cli.version-";

public static File fVersion (File home) {
File [] files = home.listFiles (new FileFilter () {
Expand Down Expand Up @@ -52,8 +52,17 @@ public static int iVersion (File home) {
return 0;
}
String [] aVersion = Lang.split (sVersion, Lang.DOT);
int patch = 0;
if (aVersion.length >= 3) {
String sPatch = aVersion [2];
int indexOfDash = sPatch.indexOf (Lang.DASH);
if (indexOfDash >= 0) {
sPatch = sPatch.substring (0, indexOfDash);
}
patch = Integer.valueOf (sPatch);
}
try {
return (Integer.valueOf (aVersion [0]) * 100) + (Integer.valueOf (aVersion [1]) * 10) + Integer.valueOf (aVersion [2]);
return (Integer.valueOf (aVersion [0]) * 100) + (Integer.valueOf (aVersion [1]) * 10) + patch;
} catch (Exception ex) {
return 0;
}
Expand Down
30 changes: 26 additions & 4 deletions cli/bluenimble-cli-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
Expand All @@ -44,14 +44,36 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version> 2.5 </version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/com/bluenimble/platform/cli/impls/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/com/bluenimble/platform/cli/impls/</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>main/</exclude>
</excludes>
<archive>
<manifestEntries>
<Built-By>BlueNimble Team</Built-By>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public CommandResult execute (Tool tool, Map<String, CommandOption> options)

tool.saveVariable (varName, varName.equals (Tool.ParaPhraseVar) ? tool.getParaphrase (false) : value);



} catch (Exception e) {
throw new CommandExecutionException (e.getMessage (), e);
}
Expand Down
4 changes: 3 additions & 1 deletion cli/bluenimble-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
todir="../../build/${project.artifactId}-${project.version}/boot" />
<move file="../../build/${project.artifactId}-${project.version}/lib/javax.persistence-api-2.2.jar"
todir="../../build/${project.artifactId}-${project.version}/build-libs" />


<touch file="../../build/${project.artifactId}-${project.version}/bnb.cli.version-${project.version}" />

</target>
</configuration>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public interface DefaultVars {
String CacheProvider = "cache.provider";
String QueryAll = "q.all";
String QueryCount = "q.count";
String TemplateFunctions= "templates.functions";
String TemplateServices = "templates.services";
String TemplateApi = "templates.api";
String Paraphrase = "paraphrase";
Expand Down Expand Up @@ -175,7 +174,7 @@ public BlueNimble (File home) throws InstallI18nException, ToolStartupException
Map<String, Object> vars = (Map<String, Object>)getContext (Tool.ROOT_CTX).get (ToolContext.VARS);
if (!vars.containsKey (Tool.ParaPhraseVar)) {
try {
setParaphrase ("serverless", true);
processCommand ("set paraphrase serverless");
} catch (Exception e) {
System.out.println ("ERROR: Can't set default paraphrase. Cause: " + e.getMessage ());
}
Expand All @@ -184,7 +183,7 @@ public BlueNimble (File home) throws InstallI18nException, ToolStartupException
loadKeys (this);

try {
new KeysMonitor (2000).start (BlueNimble.this);
new KeysMonitor (1000).start (BlueNimble.this);
} catch (Exception e) {
System.out.println ("ERROR: Can't start monitors. Cause: " + e.getMessage ());
}
Expand Down Expand Up @@ -520,10 +519,10 @@ private void loadVariables () {
oVars.set (DefaultVars.QueryCount, new JsonObject ().set ("where", new JsonObject ()).set ("select", new JsonArray ().set (null, "count(1)")));
}
if (!oVars.containsKey (DefaultVars.TemplateServices)) {
oVars.set (DefaultVars.TemplateServices, "default");
oVars.set (DefaultVars.TemplateServices, "blank/javascript");
}
if (!oVars.containsKey (DefaultVars.TemplateApi)) {
oVars.set (DefaultVars.TemplateApi, "default");
oVars.set (DefaultVars.TemplateApi, "blank/javascript");
}
if (oVars.containsKey (DefaultVars.Paraphrase)) {
try {
Expand All @@ -539,6 +538,7 @@ private void loadVariables () {
for (Object key : oVars.keySet ()) {
vars.put (String.valueOf (key), oVars.get (key));
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.bluenimble.platform.cli.command.impls.PrefixedCommand;
import com.bluenimble.platform.icli.mgm.BlueNimble;
import com.bluenimble.platform.icli.mgm.commands.dev.impls.CreateApiHandler;
import com.bluenimble.platform.icli.mgm.commands.dev.impls.CreateFunctionHandler;
import com.bluenimble.platform.icli.mgm.commands.dev.impls.CreateServiceHandler;

public class CreateCommand extends PrefixedCommand {
Expand All @@ -35,14 +34,12 @@ public class CreateCommand extends PrefixedCommand {
interface Subject {
String Api = "api";
String Service = "service";
String Function = "function";
}

public CreateCommand () {
super ("create", "create 'function', 'api' or 'service'. Ex. create function finance/makePayment. create api contacts. create service /users");
addHandler (Subject.Api, new CreateApiHandler ());
addHandler (Subject.Service, new CreateServiceHandler ());
addHandler (Subject.Function, new CreateFunctionHandler ());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CreateApiHandler implements CommandHandler {

private static final long serialVersionUID = 7185236990672693349L;

private static final String DefaultTemplate = "default";
private static final String DefaultTemplate = "blank/javascript";
private static final String Namespace = "namespace";

private static final CommandHandler SecureApiHandler = new SecureApiHandler ();
Expand Down Expand Up @@ -112,14 +112,29 @@ public CommandResult execute (Tool tool, String... args) throws CommandExecution
}
oApis.set (namespace, sApiFolder);

boolean secure = true;

try {
JsonObject apiSpec = Json.load (new File (apiFolder, "api.json"));

JsonObject codeGen = Json.getObject (apiSpec, "_codegen_");

secure = Json.getBoolean (codeGen, "secure", true);

if (codeGen != null) {
apiSpec.remove ("_codegen_");
Json.store (apiSpec, new File (apiFolder, "api.json"));
}

BlueNimble.saveConfig ();
tool.printer ().content ("Api '" + namespace + "' created! path: $ws/ " + sApiFolder, Json.load (new File (apiFolder, "api.json")).toString (2));
tool.printer ().content ("Api '" + namespace + "' created! path: $ws/ " + sApiFolder, apiSpec.toString (2));
} catch (Exception e) {
throw new CommandExecutionException (e.getMessage (), e);
}

SecureApiHandler.execute (tool, new String [] { namespace, "token+cookie", Lang.STAR });
if (secure) {
SecureApiHandler.execute (tool, new String [] { namespace, "token+signature", Lang.STAR });
}

return new DefaultCommandResult (CommandResult.OK, null);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public CommandResult execute (Tool tool, String... args) throws CommandExecution

File resourcesFolder = new File (apiFolder, "resources");
File servicesFolder = new File (resourcesFolder, "services");
File scriptsFolder = new File (resourcesFolder, "scripts");
File functionsFolder = new File (resourcesFolder, "functions");

CodeGenUtils.writeService ((AbstractTool)tool, verb, model, servicesFolder, scriptsFolder);
CodeGenUtils.writeService ((AbstractTool)tool, verb, model, servicesFolder, functionsFolder);

return new DefaultCommandResult (CommandResult.OK, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;

import com.bluenimble.platform.Lang;
import com.bluenimble.platform.icli.mgm.BlueNimble;
import com.bluenimble.platform.icli.mgm.CliSpec;

Expand Down Expand Up @@ -56,6 +57,7 @@ public void onFileCreate (File file) {
}
try {
BlueNimble.loadKeys (bluenimble, file);
BlueNimble.useKeys (file.getName ().substring (0, file.getName ().lastIndexOf (Lang.DOT)));
} catch (Exception e) {
bluenimble.printer ().error (e.getMessage ());
}
Expand All @@ -67,6 +69,7 @@ public void onFileChange (File file) {
}
try {
BlueNimble.loadKeys (bluenimble, file);
BlueNimble.useKeys (file.getName ().substring (0, file.getName ().lastIndexOf (Lang.DOT)));
} catch (Exception e) {
bluenimble.printer ().error (e.getMessage ());
}
Expand Down
Loading

0 comments on commit e43a056

Please sign in to comment.