2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.aai.schemagen;
24 import freemarker.template.TemplateException;
25 import org.onap.aai.schemagen.swagger.GenerateSwagger;
26 import org.onap.aai.setup.SchemaVersion;
27 import org.onap.aai.setup.SchemaVersions;
28 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
31 import java.io.IOException;
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.ListIterator;
36 public class AutoGenerateHtml {
38 private static final String AAI_GENERATE_VERSION = "aai.generate.version";
39 public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
40 //if the program is run from aai-common, use this directory as default"
41 public static final String ALT_SCHEMA_DIR = "aai-schema";
42 //used to check to see if program is run from aai-schema-gen
43 public static final String DEFAULT_RUN_DIR = "aai-schema-gen";
45 public static void main(String[] args) throws IOException, TemplateException {
46 String savedProperty = System.getProperty(AAI_GENERATE_VERSION);
48 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
50 "org.onap.aai.schemagen"
54 SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
56 List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
57 Collections.sort(versionsToGen);
58 Collections.reverse(versionsToGen);
59 ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
61 if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
62 schemaDir = ALT_SCHEMA_DIR;
65 schemaDir = DEFAULT_SCHEMA_DIR;
67 String release = System.getProperty("aai.release", "onap");
68 while (versionIterator.hasNext()) {
69 System.setProperty(AAI_GENERATE_VERSION, versionIterator.next().toString());
70 String yamlFile = schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_" + System.getProperty(AAI_GENERATE_VERSION)+ ".yaml";
71 File swaggerYamlFile = new File(yamlFile);
72 if(swaggerYamlFile.exists()) {
73 GenerateSwagger.schemaVersions = schemaVersions;
74 GenerateSwagger.main(args);
77 System.setProperty(AAI_GENERATE_VERSION, savedProperty);