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=========================================================
23 package org.onap.aai.schemagen;
25 import freemarker.template.TemplateException;
28 import java.io.IOException;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.ListIterator;
33 import org.onap.aai.schemagen.swagger.GenerateSwagger;
34 import org.onap.aai.setup.SchemaVersion;
35 import org.onap.aai.setup.SchemaVersions;
36 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
38 public class AutoGenerateHtml {
40 private static final String AAI_GENERATE_VERSION = "aai.generate.version";
41 public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
42 // if the program is run from aai-common, use this directory as default"
43 public static final String ALT_SCHEMA_DIR = "aai-schema";
44 // used to check to see if program is run from aai-schema-gen
45 public static final String DEFAULT_RUN_DIR = "aai-schema-gen";
47 public static void main(String[] args) throws IOException, TemplateException {
48 String savedProperty = System.getProperty(AAI_GENERATE_VERSION);
50 AnnotationConfigApplicationContext ctx =
51 new AnnotationConfigApplicationContext("org.onap.aai.setup", "org.onap.aai.schemagen");
53 SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
55 List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
56 Collections.sort(versionsToGen);
57 Collections.reverse(versionsToGen);
58 ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
60 if (System.getProperty("user.dir") != null
61 && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
62 schemaDir = ALT_SCHEMA_DIR;
64 schemaDir = DEFAULT_SCHEMA_DIR;
66 String release = System.getProperty("aai.release", "onap");
67 while (versionIterator.hasNext()) {
68 System.setProperty(AAI_GENERATE_VERSION, versionIterator.next().toString());
70 schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_"
71 + System.getProperty(AAI_GENERATE_VERSION) + ".yaml";
72 File swaggerYamlFile = new File(yamlFile);
73 if (swaggerYamlFile.exists()) {
74 GenerateSwagger.schemaVersions = schemaVersions;
75 GenerateSwagger.main(args);
78 System.setProperty(AAI_GENERATE_VERSION, savedProperty);