1 /**============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 ================================================================================
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ============LICENSE_END=========================================================
21 package org.onap.blueprintgenerator.core;
25 import org.apache.commons.cli.BasicParser;
26 import org.apache.commons.cli.CommandLine;
27 import org.apache.commons.cli.Options;
28 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
29 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
33 @SuppressWarnings("deprecation")
34 public class BlueprintGenerator {
36 private static String componentSpecPath = "";
38 private static String bluePrintName = "";
40 private static String outputPath = "";
42 private static char bpType = 'o';
44 private static String importPath = "";
47 public static void main(String[] args) throws Exception {
54 //create the component Spec we are going to be working with
55 ComponentSpec cs = new ComponentSpec();
56 cs.createComponentSpecFromFile(componentSpecPath);
57 // if(bpType != 't') {
58 // cs.createComponentSpecFromFile(componentSpecPath);
60 // if(bpType == 't') {
61 // Self self = new Self();
62 // self.setName("blueprint_template");
63 // self.setDescription("A template yaml file for blueprints");
64 // self.setVersion("1.0.0");
65 // self.setComponent_type("template");
69 Blueprint bp = new Blueprint();
70 bp = bp.createBlueprint(cs, bluePrintName, bpType, importPath);
71 bp.blueprintToYaml(outputPath, bluePrintName, cs);
75 public static void printInstructions() {
76 System.out.println("OPTIONS:");
77 System.out.println("-i: The path to the JSON spec file (required)");
78 System.out.println("-n: Name of the blueprint (optional)");
79 System.out.println("-p: The path to the final blueprint (required)");
80 System.out.println("-t: The path to the yaml import file (optional)");
81 //System.out.println("-t: This flag will create a template of how a blueprint will look. No ComponentSpec is required if you add this flag (optional");
86 public static void parseInputs(String[] args) throws Exception {
87 //convert the arguments array to a string to make it easier
90 if(commands.length() == 0) {
94 commands = commands + " " + s;
97 //check if it has the required inputs
98 // if(commands.contains("-t")) {
100 // CommandLineParser parser = new BasicParser();
101 // Options options = new Options();
102 // options.addOption("p", "Path", true, "Path to the final blueprint");
103 // options.addOption("i", "Spec", true, "ComponentSpec import file");
104 // options.addOption("n", "name", true, "Name of the blueprint");
105 // options.addOption("t", "Template", false, "Create a bp tempalte");
106 // CommandLine commandLine = parser.parse(options, args);
107 // outputPath = commandLine.getOptionValue("p");
109 if(!commands.contains("-p") || !commands.contains("-i")) {
110 System.out.println("did not enter the required inputs");
113 BasicParser parser = new BasicParser();
114 Options options = new Options();
115 options.addOption("i", "Spec", true, "ComponentSpec import file");
116 options.addOption("p", "Path", true, "Path to the final blueprint");
117 options.addOption("n", "Name", true, "Name of the blueprint");
118 options.addOption("t", "imports", true, "Path to the import file");
120 CommandLine commandLine = parser.parse(options, args);
121 componentSpecPath = commandLine.getOptionValue("i");
122 outputPath = commandLine.getOptionValue("p");
123 if(!(commandLine.getOptionValue("n") == null)){
124 bluePrintName = commandLine.getOptionValue("n");
126 if(!(commandLine.getOptionValue("t") == null)) {
127 importPath = commandLine.getOptionValue("t");