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;
23 import java.io.BufferedReader;
24 import java.io.BufferedWriter;
26 import java.io.FileNotFoundException;
27 import java.io.FileReader;
28 import java.io.FileWriter;
29 import java.io.IOException;
30 import java.io.PrintWriter;
31 import java.util.ArrayList;
32 import java.util.List;
35 private static ArrayList<String> lines = new ArrayList<String>();
36 private static String line = null;
38 public static void fixSingleQuotes(File f) throws IOException {
39 File translateFile = f;
41 FileReader fr = new FileReader(translateFile);
42 BufferedReader br = new BufferedReader(fr);
43 while((line = br.readLine()) != null) {
44 // lines.add(ensureNoSingleQuotes(line));
45 if(line.contains("'")) {
46 line = line.replace("'", "");
48 if(line.contains("\"\"") && (line.contains("m") || line.contains("M"))) {
49 line = line.replaceAll("\"\"", "\"");
56 FileWriter fw = new FileWriter(translateFile);
57 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
58 for(String s: lines) {
67 lines = new ArrayList<String>();
68 } catch (FileNotFoundException e) {
69 throw new RuntimeException(e);
74 * Remove single quotes from a line from a blueprint
76 private static String ensureNoSingleQuotes(String line) {
77 // TODO: Should probably use regex instead
78 // REVIEW: The condition under which to remove the single quotes
79 if ((line.contains("concat") || line.contains("default: ")) && line.contains("'")) {
80 return line.replace("'", "");
87 * Takes in an entire blueprint (YAML) in a string buffer and post processes it to apply
88 * "fixes" like removing unwanted single quotes.
90 public static String applyFixes(String bp) {
91 List<String> lines = new ArrayList<String>();
93 String[] linesPre = bp.split("\n");
94 System.out.println(String.format("To post-processing #lines: %d", linesPre.length));
96 for (String line : linesPre) {
97 lines.add(ensureNoSingleQuotes(line));
100 return String.join("\n", lines);