diff --git a/components/micro-gateway-cli/pom.xml b/components/micro-gateway-cli/pom.xml index 2a341ad991..e7786c8c59 100644 --- a/components/micro-gateway-cli/pom.xml +++ b/components/micro-gateway-cli/pom.xml @@ -66,6 +66,10 @@ com.moandjiezana.toml toml4j + + org.everit.json + org.everit.json.schema + diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java index 5520769e7e..aadfd77ec3 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java @@ -29,12 +29,14 @@ import org.wso2.apimgt.gateway.cli.codegen.ThrottlePolicyGenerator; import org.wso2.apimgt.gateway.cli.config.TOMLConfigParser; import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants; -import org.wso2.apimgt.gateway.cli.exception.*; +import org.wso2.apimgt.gateway.cli.exception.CLIInternalException; +import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException; +import org.wso2.apimgt.gateway.cli.exception.ConfigParserException; import org.wso2.apimgt.gateway.cli.model.config.Config; import org.wso2.apimgt.gateway.cli.model.config.ContainerConfig; import org.wso2.apimgt.gateway.cli.model.config.Etcd; import org.wso2.apimgt.gateway.cli.utils.GatewayCmdUtils; -import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionUtils; +import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionBuilder; import org.wso2.apimgt.gateway.cli.utils.ToolkitLibExtractionUtils; import java.io.File; @@ -83,7 +85,7 @@ public void execute() { } String projectName = GatewayCmdUtils.getSingleArgument(mainArgs); - projectName = projectName.replaceAll("[\\/\\\\]", ""); + projectName = projectName.replaceAll("[/\\\\]", ""); File projectLocation = new File(GatewayCmdUtils.getProjectDirectoryPath(projectName)); if (!projectLocation.exists()) { @@ -115,10 +117,9 @@ public void execute() { etcd.setEtcdEnabled(GatewayCmdUtils.getEtcdEnabled(projectName)); GatewayCmdUtils.setEtcd(etcd); - MgwDefinitionUtils.configureMgwDefinition(projectName); + MgwDefinitionBuilder.build(projectName); CodeGenerator codeGenerator = new CodeGenerator(); ThrottlePolicyGenerator policyGenerator = new ThrottlePolicyGenerator(); - boolean changesDetected; policyGenerator.generate(GatewayCmdUtils.getProjectGenSrcDirectoryPath(projectName) + File.separator + GatewayCliConstants.POLICY_DIR, projectName); @@ -128,7 +129,7 @@ public void execute() { //to indicate the api information which is not used in the code generation process, but included in //definition.yaml - MgwDefinitionUtils.FindNotUsedAPIInformation(); + MgwDefinitionBuilder.FindUnusedAPIInformation(); //Initializing the ballerina project and creating .bal folder. InitHandler.initialize(Paths.get(GatewayCmdUtils.getProjectGenDirectoryPath(projectName)), null, new ArrayList<>(), null); diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/Main.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/Main.java index 5fcd102385..9a16cc8e96 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/Main.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/Main.java @@ -40,11 +40,10 @@ public class Main { private static final String JC_EXPECTED_A_VALUE_AFTER_PARAMETER_PREFIX = "Expected a value after parameter"; private static final String INTERNAL_ERROR_MESSAGE = "Internal error occurred while executing command."; private static final String MICRO_GW = "micro-gw: "; + private static final Logger logger = LoggerFactory.getLogger(Main.class); private static PrintStream outStream = System.err; - private static final Logger logger = LoggerFactory.getLogger(Main.class); - public static void main(String... args) { try { Optional optionalInvokedCmd = getInvokedCmd(args); @@ -105,37 +104,10 @@ private static Optional getInvokedCmd(String... args) { cmdParser.addCommand(GatewayCliCommands.IMPORT, importCmd); importCmd.setParentCmdParser(cmdParser); -// AddAPICmd addAPICmd = new AddAPICmd(); -// cmdParser.addCommand(GatewayCliCommands.ADD_API, addAPICmd); -// addAPICmd.setParentCmdParser(cmdParser); -// -// AddRouteCmd addRouteCmd = new AddRouteCmd(); -// cmdParser.addCommand(GatewayCliCommands.ADD_ROUTE, addRouteCmd); -// addRouteCmd.setParentCmdParser(cmdParser); -// -// ListAPIsCmd listAPIsCmd = new ListAPIsCmd(); -// cmdParser.addCommand(GatewayCliCommands.LIST_APIS, listAPIsCmd); -// listAPIsCmd.setParentCmdParser(cmdParser); -// -// ListResourcesCmd listResourcesCmd = new ListResourcesCmd(); -// cmdParser.addCommand(GatewayCliCommands.LIST_RESOURCES, listResourcesCmd); -// listResourcesCmd.setParentCmdParser(cmdParser); -// -// DescResourceCmd descResourceCmd = new DescResourceCmd(); -// cmdParser.addCommand(GatewayCliCommands.DESC_RESOURCE, descResourceCmd); -// descResourceCmd.setParentCmdParser(cmdParser); -// -// FunctionCmd functionCmd = new FunctionCmd(); -// cmdParser.addCommand(GatewayCliCommands.FUNCTION,functionCmd); -// functionCmd.setParentCmdParser(cmdParser); - SetProjectCmd setProjectCmd = new SetProjectCmd(); cmdParser.addCommand(GatewayCliCommands.SET, setProjectCmd); setProjectCmd.setParentCmdParser(cmdParser); - -// UpdateRouteCmd updateRouteCmd = new UpdateRouteCmd(); -// cmdParser.addCommand(GatewayCliCommands.UPDATE_ROUTE, updateRouteCmd); -// updateRouteCmd.setParentCmdParser(cmdParser); + Map commanderMap; String parsedCmdName; if (args.length != 0) { diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/codegen/CodeGenerator.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/codegen/CodeGenerator.java index 88c063d830..94f20036fb 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/codegen/CodeGenerator.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/codegen/CodeGenerator.java @@ -130,7 +130,7 @@ public void generate(String projectName, boolean overwrite) Files.walk(Paths.get(openApiPath)).filter( path -> path.getFileName().toString().endsWith(".json")) .forEach( path -> { ExtendedAPI api = OpenAPICodegenUtils.generateAPIFromOpenAPIDef(path.toString()); - String basepath = MgwDefinitionUtils.getBasePath(api.getName(), api.getVersion()); + String basepath = MgwDefinitionBuilder.getBasePath(api.getName(), api.getVersion()); api.setContext(basepath); BallerinaService definitionContext; OpenAPICodegenUtils.setAdditionalConfigsDevFirst(api); diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/constants/GatewayCliConstants.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/constants/GatewayCliConstants.java index ec4c402afc..b4b43da918 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/constants/GatewayCliConstants.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/constants/GatewayCliConstants.java @@ -18,10 +18,10 @@ package org.wso2.apimgt.gateway.cli.constants; import java.io.File; -import java.util.Collections; -import java.util.regex.Pattern; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.regex.Pattern; public class GatewayCliConstants { public static final String PROJECT_CONF_DIR = "conf"; @@ -115,4 +115,5 @@ public class GatewayCliConstants { public static final String API_METADATA_FILE = "api-metadata.yaml"; public static final String API_SWAGGER = "swagger.json"; public static final String PROJECT_FILE_NAME = ".PROJECT"; + public static final String DEFINITION_SCHEMA_FILE = "definition-schema.json"; } \ No newline at end of file diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwAPIDefinition.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/APIDefinition.java similarity index 93% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwAPIDefinition.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/APIDefinition.java index 01f0ad16b1..4980a1a715 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwAPIDefinition.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/APIDefinition.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.apimgt.gateway.cli.model.mgwdefinition; +package org.wso2.apimgt.gateway.cli.model.definition; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -26,14 +26,14 @@ * This class represents the DTO for Single API in Microgateway Definition. */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class MgwAPIDefinition { +public class APIDefinition { private String title; private String version; private EndpointListRouteDTO prodEpList; private EndpointListRouteDTO sandEpList; private String requestInterceptor; private String responseInterceptor; - private MgwPathsDefinition pathsDefinition; + private PathsDefinition pathsDefinition; private String security; //todo: bring enum private APICorsConfigurationDTO corsConfiguration; //to identify whether it has been used @@ -94,11 +94,11 @@ public void setCorsConfiguration(APICorsConfigurationDTO corsConfiguration) { } @JsonProperty("resources") - public MgwPathsDefinition getPathsDefinition() { + public PathsDefinition getPathsDefinition() { return pathsDefinition; } - public void setPathsDefinition(MgwPathsDefinition pathsDefinition) { + public void setPathsDefinition(PathsDefinition pathsDefinition) { this.pathsDefinition = pathsDefinition; } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwAPIsDefinition.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/APIDefinitions.java similarity index 79% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwAPIsDefinition.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/APIDefinitions.java index 598617930e..849362f7d5 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwAPIsDefinition.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/APIDefinitions.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.apimgt.gateway.cli.model.mgwdefinition; +package org.wso2.apimgt.gateway.cli.model.definition; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; @@ -27,11 +27,11 @@ * This class represents the DTO for multiple APIs in Microgateway Definition. */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class MgwAPIsDefinition { - private Map apis = new LinkedHashMap<>(); +public class APIDefinitions { + private Map apis = new LinkedHashMap<>(); @JsonAnySetter - public void setApis(String key, MgwAPIDefinition api) { + public void setApis(String key, APIDefinition api) { apis.put(key, api); } @@ -40,16 +40,16 @@ public void setApis(String key, MgwAPIDefinition api) { * * @return map with (basepath, api information object) */ - public Map getApisMap(){ + public Map getApisMap() { return apis; } - public MgwAPIDefinition getApiFromBasepath(String basepath) { + public APIDefinition getApiFromBasepath(String basepath) { return apis.get(basepath); } public String getBasepathFromAPI(String apiName, String apiVersion) { - for (Map.Entry apiEntry : apis.entrySet()) { + for (Map.Entry apiEntry : apis.entrySet()) { if (apiEntry.getValue().getTitle().equals(apiName) && apiEntry.getValue().getVersion().equals(apiVersion)) { //because if this method is called, it means that API information is utilized. apiEntry.getValue().setIsDefinitionUsed(true); diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwRootDefinition.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/DefinitionConfig.java similarity index 80% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwRootDefinition.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/DefinitionConfig.java index d636cf88dd..1d115e7972 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwRootDefinition.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/DefinitionConfig.java @@ -15,22 +15,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.apimgt.gateway.cli.model.mgwdefinition; +package org.wso2.apimgt.gateway.cli.model.definition; import com.fasterxml.jackson.annotation.JsonProperty; /** * This class represents the DTO for root in Microgateway Definition. */ -public class MgwRootDefinition { - private MgwAPIsDefinition apis; - +public class DefinitionConfig { @JsonProperty("apis") - public MgwAPIsDefinition getApis() { + private APIDefinitions apis; + + public APIDefinitions getApis() { return apis; } - public void setApis(MgwAPIsDefinition apis) { + public void setApis(APIDefinitions apis) { this.apis = apis; } } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwEndpointListDefinition.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/EndpointListDefinition.java similarity index 96% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwEndpointListDefinition.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/EndpointListDefinition.java index a0490dd7ab..594cee899e 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwEndpointListDefinition.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/EndpointListDefinition.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.apimgt.gateway.cli.model.mgwdefinition; +package org.wso2.apimgt.gateway.cli.model.definition; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -26,7 +26,7 @@ * This class represents the DTO for Single Path in API in Microgateway Definition. */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class MgwEndpointListDefinition { +public class EndpointListDefinition { private EndpointListRouteDTO prodEndpointList; private EndpointListRouteDTO sandEndpointList; private String requestInterceptor; diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwPathsDefinition.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/PathsDefinition.java similarity index 77% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwPathsDefinition.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/PathsDefinition.java index d6f95b7736..3fb6f2f403 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwPathsDefinition.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/PathsDefinition.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.apimgt.gateway.cli.model.mgwdefinition; +package org.wso2.apimgt.gateway.cli.model.definition; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; @@ -27,15 +27,15 @@ * This class represents the DTO for all the paths in API in Microgateway Definition. */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class MgwPathsDefinition { - private Map resources = new LinkedHashMap<>(); +public class PathsDefinition { + private Map resources = new LinkedHashMap<>(); @JsonAnySetter - public void setResources(String key, MgwResourceDefinition path) { + public void setResources(String key, ResourceDefinition path) { resources.put(key, path); } - public MgwResourceDefinition getMgwResource(String path) { + public ResourceDefinition getMgwResource(String path) { return resources.get(path); } } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwResourceDefinition.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/ResourceDefinition.java similarity index 69% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwResourceDefinition.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/ResourceDefinition.java index dae2f48634..8fc61a562c 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/mgwdefinition/MgwResourceDefinition.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/definition/ResourceDefinition.java @@ -15,23 +15,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.apimgt.gateway.cli.model.mgwdefinition; +package org.wso2.apimgt.gateway.cli.model.definition; import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonProperty; import java.util.LinkedHashMap; import java.util.Map; -public class MgwResourceDefinition { - private Map operations = new LinkedHashMap<>(); +public class ResourceDefinition { + private Map operations = new LinkedHashMap<>(); @JsonAnySetter - public void setEndpoints(String key, MgwEndpointListDefinition endpoint) { + public void setEndpoints(String key, EndpointListDefinition endpoint) { operations.put(key, endpoint); } - public MgwEndpointListDefinition getEndpointListDefinition(String resourceName) { + public EndpointListDefinition getEndpointListDefinition(String resourceName) { return operations.get(resourceName); } } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java index 906b440165..357600411e 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/model/template/service/BallerinaService.java @@ -32,7 +32,7 @@ import org.wso2.apimgt.gateway.cli.utils.CodegenUtils; import org.wso2.apimgt.gateway.cli.utils.GatewayCmdUtils; import org.wso2.apimgt.gateway.cli.model.config.Etcd; -import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionUtils; +import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionBuilder; import java.util.AbstractMap; import java.util.LinkedHashSet; @@ -167,36 +167,36 @@ private void setPaths(OpenAPI openAPI) throws BallerinaServiceGenException { operation.getValue().setOperationId(operationId); //if it is the developer first approach if (isDevFirst) { - String basePath = MgwDefinitionUtils.getBasePath(openAPI.getInfo().getTitle(), + String basePath = MgwDefinitionBuilder.getBasePath(openAPI.getInfo().getTitle(), openAPI.getInfo().getVersion()); //to add resource level endpoint configuration - MgwEndpointConfigDTO epConfig = MgwDefinitionUtils.getResourceEpConfigForCodegen(basePath, + MgwEndpointConfigDTO epConfig = MgwDefinitionBuilder.getResourceEpConfigForCodegen(basePath, path.getKey(), operation.getKey()); if (epConfig != null) { operation.getValue().setEpConfigDTO(epConfig); } //todo: need to validate the existence of those functions //to add request interceptor - String requestInterceptor = MgwDefinitionUtils.getRequestInterceptor(basePath, path.getKey(), + String requestInterceptor = MgwDefinitionBuilder.getRequestInterceptor(basePath, path.getKey(), operation.getKey()); if (requestInterceptor != null) { operation.getValue().setRequestInterceptor(requestInterceptor); } //to add response interceptor - String responseInterceptor = MgwDefinitionUtils.getResponseInterceptor(basePath, path.getKey(), + String responseInterceptor = MgwDefinitionBuilder.getResponseInterceptor(basePath, path.getKey(), operation.getKey()); if (responseInterceptor != null) { operation.getValue().setResponseInterceptor(responseInterceptor); } //to add throttle policy - String throttle_policy = MgwDefinitionUtils.getThrottlePolicy(basePath, path.getKey(), + String throttle_policy = MgwDefinitionBuilder.getThrottlePolicy(basePath, path.getKey(), operation.getKey()); if (throttle_policy != null) { operation.getValue().setResourceTier(throttle_policy); } //to add API level request interceptor - String apiRequestInterceptor = MgwDefinitionUtils.getApiRequestInterceptor(basePath); + String apiRequestInterceptor = MgwDefinitionBuilder.getApiRequestInterceptor(basePath); if (apiRequestInterceptor != null) { //if user specify the same interceptor function in both api level and resource level ignore // api level interceptor @@ -206,7 +206,7 @@ private void setPaths(OpenAPI openAPI) throws BallerinaServiceGenException { } //to add API level response interceptor - String apiResponseInterceptor = MgwDefinitionUtils.getApiResponseInterceptor(basePath); + String apiResponseInterceptor = MgwDefinitionBuilder.getApiResponseInterceptor(basePath); if (apiResponseInterceptor != null) { operation.getValue().setApiResponseInterceptor(apiResponseInterceptor); } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java index bdd209b982..cefcb257af 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java @@ -39,14 +39,14 @@ import org.wso2.apimgt.gateway.cli.model.rest.ext.ExtendedAPI; import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.PrintStream; @@ -678,8 +678,7 @@ public static String getDeploymentConfigLocation(String projectName) { * @return path to the given project in the current working directory */ public static String getProjectDirectoryPath(String projectName) { - // TODO: do we need to change this? - return new File(projectName).getAbsolutePath(); + return getUserDir() + File.separator + projectName; } /** diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionBuilder.java similarity index 82% rename from components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionUtils.java rename to components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionBuilder.java index 26515d95cc..2c7b62160a 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionUtils.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/MgwDefinitionBuilder.java @@ -17,19 +17,18 @@ */ package org.wso2.apimgt.gateway.cli.utils; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants; import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException; +import org.wso2.apimgt.gateway.cli.model.definition.DefinitionConfig; import org.wso2.apimgt.gateway.cli.model.mgwcodegen.MgwEndpointConfigDTO; -import org.wso2.apimgt.gateway.cli.model.mgwdefinition.MgwRootDefinition; import org.wso2.apimgt.gateway.cli.model.rest.APICorsConfigurationDTO; import org.wso2.apimgt.gateway.cli.model.route.EndpointListRouteDTO; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -40,26 +39,40 @@ /** - * This class includes the Util functions related to operations on MgwDefinition. + * Represents the microgateway definitions file. + *

+ * Implementation contains the methods required to build a valid definition object model + * from a definition file. + *

*/ -public class MgwDefinitionUtils { - - private static final ObjectMapper OBJECT_MAPPER_YAML = new ObjectMapper(new YAMLFactory()); - private static final Logger LOGGER = LoggerFactory.getLogger(MgwDefinitionUtils.class); - private static MgwRootDefinition rootDefinition; +public class MgwDefinitionBuilder { + private static DefinitionConfig definitionConfig; private static String projectName; + private static final Logger LOGGER = LoggerFactory.getLogger(MgwDefinitionBuilder.class); private static Map requestInterceptorMap = new HashMap<>(); private static Map responseInterceptorMap = new HashMap<>(); - public static void configureMgwDefinition(String project) { + /** + * Builds the {@link DefinitionConfig} object model for {@link GatewayCliConstants#PROJECT_DEFINITION_FILE}. + * Before parsing the yaml file to {@link DefinitionConfig}, validation will be performed on + * the the input project definition file. + * + * @param project microgateway project name + */ + public static void build(String project) { projectName = project; + String definitionPath = GatewayCmdUtils.getProjectMgwDefinitionFilePath(project); + File definitionFile = new File(definitionPath); + try { - String definitionFilePath = GatewayCmdUtils.getProjectMgwDefinitionFilePath(project); - rootDefinition = OBJECT_MAPPER_YAML.readValue(new File(definitionFilePath), MgwRootDefinition.class); + InputStream isSchema = MgwDefinitionBuilder.class.getClassLoader() + .getResourceAsStream(GatewayCliConstants.DEFINITION_SCHEMA_FILE); + definitionConfig = YamlValidator.parse(definitionFile, isSchema, DefinitionConfig.class); } catch (IOException e) { throw new CLIRuntimeException("Error while reading the " + GatewayCliConstants.PROJECT_DEFINITION_FILE + ".", e); } + try { //update the interceptor map setInterceptors(); @@ -77,37 +90,38 @@ public static void configureMgwDefinition(String project) { * @return basePath */ public static String getBasePath(String apiName, String apiVersion) { - String basePath = rootDefinition.getApis().getBasepathFromAPI(apiName, apiVersion); + String basePath = definitionConfig.getApis().getBasepathFromAPI(apiName, apiVersion); if (basePath == null) { throw new CLIRuntimeException("Error: The API '" + apiName + "' and version '" + apiVersion + "' is not " + "found in the " + GatewayCliConstants.PROJECT_DEFINITION_FILE + "."); } + return basePath; } public static EndpointListRouteDTO getProdEndpointList(String basePath) { - return rootDefinition.getApis().getApiFromBasepath(basePath).getProdEpList(); + return definitionConfig.getApis().getApiFromBasepath(basePath).getProdEpList(); } public static EndpointListRouteDTO getSandEndpointList(String basePath) { - return rootDefinition.getApis().getApiFromBasepath(basePath).getProdEpList(); + return definitionConfig.getApis().getApiFromBasepath(basePath).getProdEpList(); } public static String getSecurity(String basePath) { - return rootDefinition.getApis().getApiFromBasepath(basePath).getSecurity(); + return definitionConfig.getApis().getApiFromBasepath(basePath).getSecurity(); } public static APICorsConfigurationDTO getCorsConfiguration(String basePath) { - return rootDefinition.getApis().getApiFromBasepath(basePath).getCorsConfiguration(); + return definitionConfig.getApis().getApiFromBasepath(basePath).getCorsConfiguration(); } public static MgwEndpointConfigDTO getResourceEpConfigForCodegen(String basePath, String path, String operation) { if (!isResourceAvailable(basePath, path, operation)) { return null; } - EndpointListRouteDTO prodList = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition(). + EndpointListRouteDTO prodList = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition(). getMgwResource(path).getEndpointListDefinition(operation).getProdEndpointList(); - EndpointListRouteDTO sandList = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition(). + EndpointListRouteDTO sandList = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition(). getMgwResource(path).getEndpointListDefinition(operation).getSandEndpointList(); return RouteUtils.convertToMgwServiceMap(prodList, sandList); } @@ -124,9 +138,10 @@ public static String getRequestInterceptor(String basePath, String path, String if (!isResourceAvailable(basePath, path, operation)) { return null; } - String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path). + String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path). getEndpointListDefinition(operation).getRequestInterceptor(); validateInterceptorAvailability(requestInterceptorMap, interceptor, basePath, path, operation); + return interceptor; } @@ -142,9 +157,10 @@ public static String getResponseInterceptor(String basePath, String path, String if (!isResourceAvailable(basePath, path, operation)) { return null; } - String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path). + String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path). getEndpointListDefinition(operation).getResponseInterceptor(); validateInterceptorAvailability(responseInterceptorMap, interceptor, basePath, path, operation); + return interceptor; } @@ -152,7 +168,7 @@ public static String getThrottlePolicy(String basePath, String path, String oper if (!isResourceAvailable(basePath, path, operation)) { return null; } - return rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path). + return definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path). getEndpointListDefinition(operation).getThrottlePolicy(); } @@ -165,13 +181,13 @@ public static String getThrottlePolicy(String basePath, String path, String oper * @return true if the resource is available */ private static boolean isResourceAvailable(String basePath, String path, String operation) { - if (rootDefinition.getApis().getApiFromBasepath(basePath) == null) { + if (definitionConfig.getApis().getApiFromBasepath(basePath) == null) { return false; } - if (rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path) == null) { + if (definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path) == null) { return false; } - return rootDefinition.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path) + return definitionConfig.getApis().getApiFromBasepath(basePath).getPathsDefinition().getMgwResource(path) .getEndpointListDefinition(operation) != null; } @@ -182,7 +198,7 @@ private static boolean isResourceAvailable(String basePath, String path, String * @return API response request function name */ public static String getApiRequestInterceptor(String basePath) { - String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getRequestInterceptor(); + String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getRequestInterceptor(); validateInterceptorAvailability(requestInterceptorMap, interceptor, basePath, null, null); return interceptor; } @@ -194,7 +210,7 @@ public static String getApiRequestInterceptor(String basePath) { * @return API response interceptor function name */ public static String getApiResponseInterceptor(String basePath) { - String interceptor = rootDefinition.getApis().getApiFromBasepath(basePath).getResponseInterceptor(); + String interceptor = definitionConfig.getApis().getApiFromBasepath(basePath).getResponseInterceptor(); validateInterceptorAvailability(responseInterceptorMap, interceptor, basePath, null, null); return interceptor; } @@ -230,8 +246,8 @@ private static void validateInterceptorAvailability(Map intercep /** * To find out the api information which is not used for code generation but included in the definitions.yaml */ - public static void FindNotUsedAPIInformation() { - rootDefinition.getApis().getApisMap().forEach((k, v) -> { + public static void FindUnusedAPIInformation() { + definitionConfig.getApis().getApisMap().forEach((k, v) -> { if (!v.getIsDefinitionUsed()) { String msg = "API '" + v.getTitle() + "' version: '" + v.getVersion() + "' is not used but " + "added to the " + GatewayCliConstants.PROJECT_DEFINITION_FILE + "."; @@ -340,3 +356,4 @@ private static void findResponseInterceptors(String balSrcCode, String intercept findInterceptors(balSrcCode, interceptorFilePath, false, responseInterceptorMap); } } + diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java index 946f5f8b3f..171532f898 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/OpenAPICodegenUtils.java @@ -295,19 +295,19 @@ public static String readJson(String filePath) { * @param api API object */ public static void setAdditionalConfigsDevFirst(ExtendedAPI api) { - String basePath = MgwDefinitionUtils.getBasePath(api.getName(), api.getVersion()); + String basePath = MgwDefinitionBuilder.getBasePath(api.getName(), api.getVersion()); MgwEndpointConfigDTO mgwEndpointConfigDTO = - RouteUtils.convertToMgwServiceMap(MgwDefinitionUtils.getProdEndpointList(basePath), - MgwDefinitionUtils.getSandEndpointList(basePath)); + RouteUtils.convertToMgwServiceMap(MgwDefinitionBuilder.getProdEndpointList(basePath), + MgwDefinitionBuilder.getSandEndpointList(basePath)); api.setEndpointConfigRepresentation(mgwEndpointConfigDTO); // 0th element represents the specific basepath api.setSpecificBasepath(basePath); - String security = MgwDefinitionUtils.getSecurity(basePath); + String security = MgwDefinitionBuilder.getSecurity(basePath); if(security == null){ security = "oauth2"; } api.setApiSecurity(security); - api.setCorsConfiguration(MgwDefinitionUtils.getCorsConfiguration(basePath)); + api.setCorsConfiguration(MgwDefinitionBuilder.getCorsConfiguration(basePath)); } public static void setAdditionalConfig(ExtendedAPI api){ diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java index 7b1d5cbe5e..a4d284d2e1 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/ToolkitLibExtractionUtils.java @@ -18,7 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.wso2.apimgt.gateway.cli.cmd.InitCmd; import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants; import org.wso2.apimgt.gateway.cli.exception.CLIInternalException; @@ -31,7 +30,7 @@ * This class represents the utility functions required for library packages extraction */ public class ToolkitLibExtractionUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(InitCmd.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ToolkitLibExtractionUtils.class); /** * Extracts the platform and runtime and copy related jars and balos to extracted runtime and platform. diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/YamlValidator.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/YamlValidator.java new file mode 100644 index 0000000000..d308b31cb4 --- /dev/null +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/YamlValidator.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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 org.wso2.apimgt.gateway.cli.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import org.everit.json.schema.Schema; +import org.everit.json.schema.ValidationException; +import org.everit.json.schema.loader.SchemaLoader; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * This class provides required functionality to validate a given + * yaml file with a given Json Schema + */ +public class YamlValidator { + private static final Logger logger = LoggerFactory.getLogger(YamlValidator.class); + + /** + * Parse the yaml {@code file} to required DTO {@code type} using jackson library. + * Before parsing the input file, schema validation will be done to validate the file syntax. + * + * @param file yaml file to be parsed + * @param isSchema json schema definition to be used for schema validation + * @param type Jackson object model to parse the yaml content + * @param Jackson object model to parse the yaml content + * @return Parsed yaml file as a DTO + * @throws IOException when failed to read input files + */ + public static T parse(File file, InputStream isSchema, Class type) throws IOException { + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + JsonNode jsonNode = mapper.readTree(file); + + if (jsonNode == null) { + throw new IOException("Input file is invalid or empty"); + } + + JSONObject rawSchema = new JSONObject(new JSONTokener(isSchema)); + Schema schema = SchemaLoader.load(rawSchema); + logger.debug("Loaded json schema"); + + try { + schema.validate(new JSONObject(jsonNode.toString())); + } catch (ValidationException e) { + handleValidationException(e, file.getName()); + } + + return mapper.readValue(file, type); + } + + private static void handleValidationException(ValidationException ex, String fileName) { + StringBuilder msgBuilder = new StringBuilder(); + List allMsg = ex.getAllMessages(); + + for (String msg : allMsg) { + msgBuilder.append('\n' + msg); + } + throw new CLIRuntimeException("Invalid file: " + fileName + '\n' + msgBuilder.toString(), 1); + } + +} diff --git a/components/micro-gateway-cli/src/main/resources/definition-schema.json b/components/micro-gateway-cli/src/main/resources/definition-schema.json new file mode 100644 index 0000000000..722f7b4802 --- /dev/null +++ b/components/micro-gateway-cli/src/main/resources/definition-schema.json @@ -0,0 +1,114 @@ +{ + "$id": "https://raw.githubusercontent.com/wso2/product-microgateway/master/components/micro-gateway-cli/src/main/resources/definition-schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Definition", + "type": "object", + "properties": { + "apis": { + "type": "object", + "patternProperties": { + "\/.*": { + "type": "object", + "required": ["title", "version","security"], + "anyOf": [ + { + "required": ["production_endpoint"] + }, + { + "required": ["sandbox_endpoint"] + }, + { + "required": ["production_endpoint", "sandbox_endpoint"] + } + ], + "properties": { + "title": { + "type": "string" + }, + "version": { + "type": "string" + }, + "production_endpoint": { + "$ref": "#/definitions/endpoint" + }, + "sandbox_endpoint": { + "$ref": "#/definitions/endpoint" + }, + "security": { + "type": "string", + "enum": ["oauth", "basic"] + }, + "resources": { + "type": "object", + "patternProperties": { + "\/.*": { + "type": "object", + "patternProperties": { + "^[^\\d\\W]+$": { + "type": "object", + "anyOf": [ + { + "required": ["production_endpoint"] + }, + { + "required": ["sandbox_endpoint"] + }, + { + "required": ["production_endpoint", "sandbox_endpoint"] + } + ], + "properties": { + "production_endpoint": { + "$ref": "#/definitions/endpoint" + }, + "sandbox_endpoint": { + "$ref": "#/definitions/endpoint" + }, + "throttle_policy": { + "type": "string" + }, + "request_interceptor": { + "type": "string" + }, + "response_interceptor": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false, + "definitions": { + "endpoint": { + "type": "object", + "required": ["urls", "type"], + "additionalProperties": false, + "properties": { + "urls": { + "type": "array", + "items": { + "type": "string" + } + }, + "type": { + "type": "string", + "enum": [ + "http", + "failover", + "load_balance" + ] + } + } + } + } +} diff --git a/distribution/resources/bin/micro-gw b/distribution/resources/bin/micro-gw index 58a5c1154d..ea0f5ed1f1 100755 --- a/distribution/resources/bin/micro-gw +++ b/distribution/resources/bin/micro-gw @@ -30,8 +30,7 @@ # ----------------------------------------------------------------------------- #To update the CLI Class Path -updateCLIClassPath() -{ +function update_cli_classpath { CLI_CLASSPATH="" if [ -e "$BALLERINA_HOME/bre/lib/bootstrap/tools.jar" ]; then CLI_CLASSPATH="$JAVA_HOME/lib/tools.jar" @@ -79,8 +78,12 @@ updateCLIClassPath() cygwin=false os400=false case "`uname`" in -CYGWIN*) cygwin=true;; -OS400*) os400=true;; + CYGWIN*) + cygwin=true + ;; + OS400*) + os400=true + ;; esac # resolve links - $0 may be a softlink @@ -117,6 +120,12 @@ export PATH=$BALLERINA_HOME/bin:$PATH MICRO_GW_PROJECT_DIR=$(pwd) +# if JAVA_HOME is not set we're not happy +if [ -z "$JAVA_HOME" ]; then + echo "You must set the JAVA_HOME variable before running Micro-Gateway Tooling." + exit 1 +fi + # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin; then [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` @@ -165,12 +174,6 @@ if [ ! -x "$JAVACMD" ] ; then exit 1 fi -# if JAVA_HOME is not set we're not happy -if [ -z "$JAVA_HOME" ]; then - echo "You must set the JAVA_HOME variable before running Ballerina." - exit 1 -fi - # ----- Process the input command ---------------------------------------------- ALL_ARGS=() @@ -179,7 +182,7 @@ while [[ $# -gt 0 ]] do key="$1" case $key in - --java.debug|-java.debug|java.debug) + --java.debug) CMD="--java.debug" PORT="$2" shift # past java.debug argument @@ -236,7 +239,7 @@ if [ "$CMD" = "--java.debug" ]; then echo "Please start the remote debugging client to continue..." fi -updateCLIClassPath +update_cli_classpath # For Cygwin, switch paths to Windows format before running java if $cygwin; then @@ -283,7 +286,8 @@ if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_ BALLERINA_HOME=`cygpath --absolute --windows "$BALLERINA_HOME"` fi - updateCLIClassPath + + update_cli_classpath MICRO_GW_LABEL_PROJECT_DIR="$MICRO_GW_PROJECT_DIR/$CMD_PRO_NAME_VAL" pushd $MICRO_GW_LABEL_PROJECT_DIR/gen > /dev/null # clean the content of target folder diff --git a/distribution/resources/bin/micro-gw.bat b/distribution/resources/bin/micro-gw.bat index 3001421d3d..134b751604 100644 --- a/distribution/resources/bin/micro-gw.bat +++ b/distribution/resources/bin/micro-gw.bat @@ -44,9 +44,10 @@ REM If the current disk drive ie: `E:\` is different from the drive where this ( if %verbose%==T ( ECHO Switch to drive '%wsasDrive%' if current drive '%curDrive%' not equal to program drive '%wsasDrive%' ) if NOT "%curDrive%" == "%wsasDrive%" %wsasDrive%: +REM if MICROGW_HOME environment variable not set then set it if "%MICROGW_HOME%" == "" SET MICROGW_HOME=%PRGDIR%.. -REM set BALLERINA_HOME +REM set BALLERINA_HOME SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform if NOT EXIST %BALLERINA_HOME% SET BALLERINA_HOME="%MICROGW_HOME%\lib" @@ -85,15 +86,13 @@ REM of arguments (up to the command line limit, anyway). if ""%1""=="""" goto passToJar if ""%1""==""help"" goto passToJar if ""%1""==""build"" goto commandBuild - if ""%1""==""-java.debug"" goto commandDebug - if ""%1""==""java.debug"" goto commandDebug if ""%1""==""--java.debug"" goto commandDebug SHIFT goto setupArgs :usageInfo ECHO Missing command operand - ECHO "Usage: micro-gw [-v] ([ -l ] setup | build)" + ECHO "Use: micro-gw [--verbose] (init | import | build)" goto :end :commandBuild @@ -105,7 +104,7 @@ goto :end if [%project_name%] == [] ( goto :noName ) else ( goto :nameFound ) :noName - ECHO "Project name not provided please follow the command usage patterns given below" + ECHO "micro-gw: main parameters are required (""), Run 'micro-gw help' for usage." goto :usageInfo :nameFound @@ -121,33 +120,30 @@ goto :end if ERRORLEVEL 1 goto :end - :continueBuild - goto :passToJar - REM set ballerina home again as the platform is extracted at this point. - SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform - SET PATH=%PATH%;%BALLERINA_HOME%\bin\ - if %verbose%==T ECHO BALLERINA_HOME environment variable is set to %BALLERINA_HOME% - pushd "%MICRO_GW_PROJECT_DIR%" - if %verbose%==T ECHO current dir %CD% - SET TARGET_DIR="%MICRO_GW_PROJECT_DIR%\target" - :: /s : Removes the specified directory and all subdirectories including any files. Use /s to remove a tree. - :: /q : Runs rmdir in quiet mode. Deletes directories without confirmation. - if EXIST "%TARGET_DIR%" ( RMDIR "%TARGET_DIR%" /s /q ) - call ballerina build src -o %project_name:\=%.balx --experimental --siddhiruntime - popd - if %verbose%==T ECHO Ballerina build completed - - set %* = %* --compiled - - REM Check for a debug param by looping through the remaining args list - :checkDebug - SHIFT - if ""%1""=="""" goto passToJar - - if ""%1""==""-java.debug"" goto commandDebug - if ""%1""==""java.debug"" goto commandDebug - if ""%1""==""--java.debug"" goto commandDebug - goto checkDebug + :continueBuild + call :passToJar + REM set ballerina home again as the platform is extracted at this point. + SET BALLERINA_HOME=%MICROGW_HOME%\lib\platform + SET PATH=%PATH%;%BALLERINA_HOME%\bin\ + if %verbose%==T ECHO BALLERINA_HOME environment variable is set to %BALLERINA_HOME% + ECHO MICRO_GW_PROJECT_DIR: "%CURRENT_D%" + PUSHD "%CURRENT_D%" + PUSHD "%MICRO_GW_PROJECT_DIR%\gen" + if %verbose%==T ECHO current dir %CD% + SET TARGET_DIR="%MICRO_GW_PROJECT_DIR%\target" + if EXIST "%TARGET_DIR%" ( RMDIR "%TARGET_DIR%" /s /q ) + call ballerina build src -o %project_name:\=%.balx --offline --experimental --siddhiruntime + POPD + + if %verbose%==T ECHO Ballerina build completed + SET originalArgs=%originalArgs% --compiled + + REM Check for a debug param by looping through the remaining args list + :checkDebug + SHIFT + if ""%1""=="""" goto passToJar + if ""%1""==""--java.debug"" goto commandDebug + goto checkDebug goto :passToJar :commandDebug @@ -156,13 +152,13 @@ goto :passToJar SHIFT SET DEBUG_PORT=%1 if "%DEBUG_PORT%"=="" goto noDebugPort - if NOT "%JAVA_OPTS%"=="" ECHO Warning !!!. User specified JAVA_OPTS will be ignored, once you give the --debug option. + if NOT "%JAVA_OPTS%"=="" ECHO Warning !!!. User specified JAVA_OPTS will be ignored, once you give the --java.debug option. SET JAVA_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%DEBUG_PORT% ECHO Please start the remote debugging client to continue... goto passToJar :noDebugPort - ECHO Please specify the debug port after the java.debug option + ECHO Please specify the debug port after the --java.debug option goto end @@ -200,7 +196,7 @@ goto end -Dfile.encoding=UTF8 ^ -Dtemplates.dir.path="%MICROGW_HOME%"\resources\templates ^ -Dcli.home="%MICROGW_HOME%" ^ - -Dcurrent.dir=%CURRENT_D% + -Dcurrent.dir="%CD%" ^ -DVERBOSE_ENABLED=%verbose% if %verbose%==T ECHO JAVACMD = !JAVACMD! @@ -209,6 +205,7 @@ goto end CD %MICROGW_HOME% "%JAVA_HOME%\bin\java" %JAVACMD% org.wso2.apimgt.gateway.cli.cmd.Main %originalArgs% if "%ERRORLEVEL%"=="121" goto runJava + if ERRORLEVEL 1 goto :end :end goto endlocal diff --git a/distribution/src/main/assembly/bin.xml b/distribution/src/main/assembly/bin.xml index 263b5cf475..462c7566b6 100644 --- a/distribution/src/main/assembly/bin.xml +++ b/distribution/src/main/assembly/bin.xml @@ -140,6 +140,8 @@ org.wso2.am.microgw:org.wso2.micro.gateway.cli:jar com.moandjiezana.toml:toml4j:jar com.beust:jcommander:jar + org.everit.json:org.everit.json.schema:jar + org.json:json:jar diff --git a/pom.xml b/pom.xml index 887b4dd35f..cafa541d9a 100644 --- a/pom.xml +++ b/pom.xml @@ -312,6 +312,11 @@ broker-launcher ${broker.version} + + org.everit.json + org.everit.json.schema + ${json.schema.version} + @@ -423,6 +428,7 @@ scm-server 1.1.1 3.2.47 + 1.5.0