blob: e1020a164f9f00b33bc1091d4ede84fd4cbd5c09 [file] [log] [blame]
Bharat saraswal97459962016-02-20 21:57:16 +05301/*
Brian O'Connor0f7908b2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Bharat saraswal97459962016-02-20 21:57:16 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.utils.io.impl;
18
Bharat saraswal9fab16b2016-09-23 23:27:24 +053019import org.apache.commons.io.FileUtils;
20import org.onosproject.yangutils.translator.exception.TranslatorException;
21import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
22
Bharat saraswal715d3fc2016-05-17 19:59:16 +053023import java.io.BufferedReader;
Bharat saraswal97459962016-02-20 21:57:16 +053024import java.io.BufferedWriter;
25import java.io.File;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053026import java.io.FileReader;
Bharat saraswal97459962016-02-20 21:57:16 +053027import java.io.FileWriter;
28import java.io.IOException;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053029import java.util.ArrayList;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053030import java.util.Arrays;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053031import java.util.Iterator;
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +053032import java.util.LinkedList;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053033import java.util.List;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053034import java.util.Stack;
35import java.util.regex.Pattern;
Bharat saraswale304c252016-08-16 20:56:20 +053036
Gaurav Agrawal8a147522016-08-10 13:43:01 +053037import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053038import static org.onosproject.yangutils.utils.UtilConstants.COLON;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053039import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
Bharat saraswal84366c52016-03-23 19:40:35 +053040import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
Bharat saraswalc2d3be12016-06-16 00:29:12 +053041import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053042import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
Bharat saraswal84366c52016-03-23 19:40:35 +053043import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053044import static org.onosproject.yangutils.utils.UtilConstants.ONE;
Bharat saraswale3175d32016-08-31 17:50:11 +053045import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053046import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
Bharat saraswal84366c52016-03-23 19:40:35 +053047import static org.onosproject.yangutils.utils.UtilConstants.ORG;
48import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
Bharat saraswal715d3fc2016-05-17 19:59:16 +053049import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053050import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
51import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
52import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
53import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
54import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
55import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
56import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
57import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
58import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_DIGITS;
59import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
60import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
61import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053062import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
Bharat saraswal84366c52016-03-23 19:40:35 +053063import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
64import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053065import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
Bharat saraswal84366c52016-03-23 19:40:35 +053066import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053067import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
Gaurav Agrawal8a147522016-08-10 13:43:01 +053068import static org.onosproject.yangutils.utils.UtilConstants.UNUSED;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053069import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
Bharat saraswal8beac342016-08-04 02:00:03 +053070import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
Bharat saraswal84366c52016-03-23 19:40:35 +053071import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
72import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
Bharat saraswalc2d3be12016-06-16 00:29:12 +053073import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
Gaurav Agrawalbfce9342016-06-15 13:58:01 +053074import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +053075
Bharat saraswal97459962016-02-20 21:57:16 +053076/**
Bharat saraswal63f26fb2016-04-05 15:13:44 +053077 * Represents common utility functionalities for code generation.
Bharat saraswal97459962016-02-20 21:57:16 +053078 */
79public final class YangIoUtils {
80
Bharat saraswale3175d32016-08-31 17:50:11 +053081 private static final int LINE_SIZE = 118;
82 private static final int SUB_LINE_SIZE = 116;
Bharat saraswal9fab16b2016-09-23 23:27:24 +053083 private static final int SUB_SIZE = 60;
Bharat saraswal97459962016-02-20 21:57:16 +053084
85 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +053086 * Creates an instance of YANG io utils.
Bharat saraswal97459962016-02-20 21:57:16 +053087 */
88 private YangIoUtils() {
89 }
90
91 /**
92 * Creates the directory structure.
93 *
94 * @param path directory path
95 * @return directory structure
Bharat saraswal8beac342016-08-04 02:00:03 +053096 * @throws IOException when fails to do IO operations
Bharat saraswal97459962016-02-20 21:57:16 +053097 */
Bharat saraswal1edde622016-09-06 10:18:04 +053098 public static File createDirectories(String path)
99 throws IOException {
b.janani66b749c2016-02-24 12:23:03 +0530100 File generatedDir = new File(path);
Bharat saraswal8beac342016-08-04 02:00:03 +0530101 if (!generatedDir.exists()) {
102 boolean isGenerated = generatedDir.mkdirs();
103 if (!isGenerated) {
104 throw new IOException("failed to generated directory " + path);
105 }
106 }
Bharat saraswal97459962016-02-20 21:57:16 +0530107 return generatedDir;
108 }
109
110 /**
111 * Adds package info file for the created directory.
112 *
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530113 * @param path directory path
114 * @param classInfo class info for the package
115 * @param pack package of the directory
116 * @param isChildNode is it a child node
Vinod Kumar S08710982016-03-03 19:55:30 +0530117 * @throws IOException when fails to create package info file
Bharat saraswal97459962016-02-20 21:57:16 +0530118 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530119 public static void addPackageInfo(File path, String classInfo, String pack,
120 boolean isChildNode) throws IOException {
Bharat saraswal97459962016-02-20 21:57:16 +0530121
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530122 pack = parsePkg(pack);
Bharat saraswal97459962016-02-20 21:57:16 +0530123 try {
124
Bharat saraswal84366c52016-03-23 19:40:35 +0530125 File packageInfo = new File(path + SLASH + "package-info.java");
Bharat saraswal8beac342016-08-04 02:00:03 +0530126 if (!packageInfo.exists()) {
127 boolean isGenerated = packageInfo.createNewFile();
128 if (!isGenerated) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530129 throw new IOException("failed to generated package-info " +
130 path);
Bharat saraswal8beac342016-08-04 02:00:03 +0530131 }
132 }
Bharat saraswal84366c52016-03-23 19:40:35 +0530133 FileWriter fileWriter = new FileWriter(packageInfo);
134 BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
135
Bharat saraswal8beac342016-08-04 02:00:03 +0530136 bufferedWriter.write(getCopyrightHeader());
Vidyashree Ramab3670472016-08-06 15:49:56 +0530137 //TODO: get the compiler annotations and pass the info
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530138 bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode,
139 null));
140 String pkg = PACKAGE + SPACE + pack + SEMI_COLON;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530141 if (pkg.length() > LINE_SIZE) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530142 pkg = processModifications(pkg, LINE_SIZE);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530143 }
144 bufferedWriter.write(pkg);
b.janani66b749c2016-02-24 12:23:03 +0530145 bufferedWriter.close();
Bharat saraswal84366c52016-03-23 19:40:35 +0530146 fileWriter.close();
Bharat saraswal97459962016-02-20 21:57:16 +0530147 } catch (IOException e) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530148 throw new IOException("Exception occurred while creating package info" +
149 " file.");
Bharat saraswal97459962016-02-20 21:57:16 +0530150 }
151 }
152
153 /**
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530154 * Parses package and returns updated package.
155 *
156 * @param pack package needs to be updated
157 * @return updated package
158 */
159 public static String parsePkg(String pack) {
160
161 if (pack.contains(ORG)) {
162 String[] strArray = pack.split(ORG);
163 if (strArray.length >= 3) {
164 for (int i = 1; i < strArray.length; i++) {
165 if (i == 1) {
166 pack = ORG + strArray[1];
167 } else {
168 pack = pack + ORG + strArray[i];
169 }
170 }
171 } else {
172 pack = ORG + strArray[1];
173 }
174 }
175
176 return pack;
177 }
178
179 /**
Bharat saraswal97459962016-02-20 21:57:16 +0530180 * Cleans the generated directory if already exist in source folder.
181 *
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530182 * @param dir generated directory in previous build
Bharat saraswal84366c52016-03-23 19:40:35 +0530183 * @throws IOException when failed to delete directory
Bharat saraswal97459962016-02-20 21:57:16 +0530184 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530185 public static void deleteDirectory(String dir)
186 throws IOException {
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530187 File generatedDirectory = new File(dir);
Bharat saraswal97459962016-02-20 21:57:16 +0530188 if (generatedDirectory.exists()) {
Bharat saraswal97459962016-02-20 21:57:16 +0530189 try {
VinodKumarS-Huawei6266db32016-05-10 17:58:57 +0530190 FileUtils.deleteDirectory(generatedDirectory);
Bharat saraswal97459962016-02-20 21:57:16 +0530191 } catch (IOException e) {
Bharat saraswal250a7472016-05-12 13:16:57 +0530192 throw new IOException(
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530193 "Failed to delete the generated files in " +
194 generatedDirectory + " directory");
Bharat saraswal97459962016-02-20 21:57:16 +0530195 }
Bharat saraswal97459962016-02-20 21:57:16 +0530196 }
197 }
198
199 /**
Bharat saraswal250a7472016-05-12 13:16:57 +0530200 * Searches and deletes generated temporary directories.
201 *
202 * @param root root directory
203 * @throws IOException when fails to do IO operations.
204 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530205 public static void searchAndDeleteTempDir(String root)
206 throws IOException {
Bharat saraswal250a7472016-05-12 13:16:57 +0530207 List<File> store = new LinkedList<>();
208 Stack<String> stack = new Stack<>();
209 stack.push(root);
210
211 while (!stack.empty()) {
212 root = stack.pop();
213 File file = new File(root);
Bharat saraswal8beac342016-08-04 02:00:03 +0530214 File[] fileList = file.listFiles();
215 if (fileList == null || fileList.length == 0) {
Bharat saraswal250a7472016-05-12 13:16:57 +0530216 continue;
217 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530218 for (File current : fileList) {
Bharat saraswal250a7472016-05-12 13:16:57 +0530219 if (current.isDirectory()) {
220 stack.push(current.toString());
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530221 if (current.getName().endsWith(HYPHEN + TEMP)) {
Bharat saraswal250a7472016-05-12 13:16:57 +0530222 store.add(current);
223 }
224 }
225 }
226 }
227
228 for (File dir : store) {
Bharat saraswal4aaab4d2016-05-17 14:19:38 +0530229 FileUtils.deleteDirectory(dir);
Bharat saraswal250a7472016-05-12 13:16:57 +0530230 }
231 }
232
233 /**
Bharat saraswal022dae92016-03-04 20:08:09 +0530234 * Removes extra char from the string.
235 *
Bharat saraswald14cbe82016-07-14 13:26:18 +0530236 * @param valueString string to be trimmed
Bharat saraswal8beac342016-08-04 02:00:03 +0530237 * @param removalString extra chars
Bharat saraswal022dae92016-03-04 20:08:09 +0530238 * @return new string
239 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530240 public static String trimAtLast(String valueString, String...
241 removalString) {
Bharat saraswal022dae92016-03-04 20:08:09 +0530242 StringBuilder stringBuilder = new StringBuilder(valueString);
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530243 String midString;
244 int index;
245 for (String remove : removalString) {
246 midString = stringBuilder.toString();
247 index = midString.lastIndexOf(remove);
248 if (index != -1) {
249 stringBuilder.deleteCharAt(index);
250 }
Bharat saraswal022dae92016-03-04 20:08:09 +0530251 }
Bharat saraswald14cbe82016-07-14 13:26:18 +0530252 return stringBuilder.toString();
Bharat saraswal022dae92016-03-04 20:08:09 +0530253 }
254
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530255 /**
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530256 * Replaces the last occurrence of a string with a given string.
257 *
258 * @param valueString string under operation
259 * @param removalString string to be replaced
260 * @param replacingString string with which replacement is to be done
261 * @return new string
262 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530263 public static String replaceLast(String valueString, String removalString,
264 String replacingString) {
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530265 StringBuilder stringBuilder = new StringBuilder(valueString);
266 int index = valueString.lastIndexOf(removalString);
267 if (index != -1) {
268 stringBuilder.replace(index, index + 1, replacingString);
269 } else {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530270 stringBuilder.append(NEW_LINE + EIGHT_SPACE_INDENTATION + UNUSED +
271 OPEN_PARENTHESIS + ONE +
272 CLOSE_PARENTHESIS + SEMI_COLON);
Gaurav Agrawal8a147522016-08-10 13:43:01 +0530273 }
274 return stringBuilder.toString();
275
276 // TODO remove generation of ENUM if there is no leaf node.
277 }
278
279
280 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530281 * Returns the directory path of the package in canonical form.
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530282 *
283 * @param baseCodeGenPath base path where the generated files needs to be
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530284 * put
285 * @param pathOfJavaPkg java package of the file being generated
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530286 * @return absolute path of the package in canonical form
287 */
288 public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
289
290 if (pathOfJavaPkg.charAt(pathOfJavaPkg.length() - 1) == File.separatorChar) {
Bharat saraswal84366c52016-03-23 19:40:35 +0530291 pathOfJavaPkg = trimAtLast(pathOfJavaPkg, SLASH);
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530292 }
Bharat saraswal84366c52016-03-23 19:40:35 +0530293 String[] strArray = pathOfJavaPkg.split(SLASH);
294 if (strArray[0].equals(EMPTY_STRING)) {
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530295 return pathOfJavaPkg;
296 } else {
Bharat saraswal84366c52016-03-23 19:40:35 +0530297 return baseCodeGenPath + SLASH + pathOfJavaPkg;
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530298 }
299 }
300
301 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530302 * Returns the absolute path of the package in canonical form.
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530303 *
304 * @param baseCodeGenPath base path where the generated files needs to be
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530305 * put
306 * @param pathOfJavaPkg java package of the file being generated
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530307 * @return absolute path of the package in canonical form
308 */
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530309 public static String getAbsolutePackagePath(String baseCodeGenPath,
310 String pathOfJavaPkg) {
Vinod Kumar S9f26ae52016-03-23 15:30:27 +0530311 return baseCodeGenPath + pathOfJavaPkg;
312 }
313
314 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530315 * Merges the temp java files to main java files.
Bharat saraswal84366c52016-03-23 19:40:35 +0530316 *
317 * @param appendFile temp file
Gaurav Agrawalab7c4bd2016-05-17 18:06:38 +0530318 * @param srcFile main file
Bharat saraswal84366c52016-03-23 19:40:35 +0530319 * @throws IOException when fails to append contents
320 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530321 public static void mergeJavaFiles(File appendFile, File srcFile)
322 throws IOException {
Bharat saraswal84366c52016-03-23 19:40:35 +0530323 try {
324 appendFileContents(appendFile, srcFile);
325 } catch (IOException e) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530326 throw new IOException("Failed to merge " + appendFile + " in " +
327 srcFile);
Bharat saraswal84366c52016-03-23 19:40:35 +0530328 }
329 }
330
331 /**
Bharat saraswal63f26fb2016-04-05 15:13:44 +0530332 * Inserts data in the generated file.
Bharat saraswal84366c52016-03-23 19:40:35 +0530333 *
334 * @param file file in which need to be inserted
335 * @param data data which need to be inserted
336 * @throws IOException when fails to insert into file
337 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530338 public static void insertDataIntoJavaFile(File file, String data)
339 throws IOException {
Bharat saraswal84366c52016-03-23 19:40:35 +0530340 try {
341 updateFileHandle(file, data, false);
342 } catch (IOException e) {
343 throw new IOException("Failed to insert in " + file + "file");
344 }
345 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530346
347 /**
348 * Validates a line size in given file whether it is having more then 120 characters.
349 * If yes it will update and give a new file.
350 *
351 * @param dataFile file in which need to verify all lines.
352 * @return updated file
353 * @throws IOException when fails to do IO operations.
354 */
VinodKumarS-Huaweid81eccb2016-06-01 14:30:22 +0530355 public static File validateLineLength(File dataFile)
356 throws IOException {
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530357 FileReader fileReader = new FileReader(dataFile);
358 BufferedReader bufferReader = new BufferedReader(fileReader);
359 try {
360 StringBuilder stringBuilder = new StringBuilder();
361 String line = bufferReader.readLine();
362
363 while (line != null) {
364 if (line.length() > LINE_SIZE) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530365 line = processModifications(line, LINE_SIZE);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530366 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530367 stringBuilder.append(line);
368 stringBuilder.append(NEW_LINE);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530369 line = bufferReader.readLine();
370 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530371 FileWriter writer = new FileWriter(dataFile);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530372 writer.write(stringBuilder.toString());
373 writer.close();
Bharat saraswal8beac342016-08-04 02:00:03 +0530374 return dataFile;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530375 } finally {
376 fileReader.close();
377 bufferReader.close();
378 }
379 }
380
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530381 /**
382 * Resolves validation of line length by modifying the string.
383 *
384 * @param line current line string
385 * @param lineSize line size for change
386 * @return modified line string
387 */
388 private static String processModifications(String line, int lineSize) {
389 int period = getArrayLength(line, PERIOD);
390 int space = getArrayLength(line, SPACE);
391 if (period > space) {
392 return merge(getForPeriod(line), PERIOD, lineSize);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530393 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530394 return merge(getForSpace(line), SPACE, lineSize);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530395 }
396
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530397 /**
398 * Returns count of pattern in line.
399 *
400 * @param line line string
401 * @param pattern pattern followed in line
402 * @return count of pattern in line
403 */
404 private static int getArrayLength(String line, String pattern) {
405 String[] array = line.split(Pattern.quote(pattern));
406 int len = array.length;
407 if (pattern.equals(SPACE)) {
408 for (String str : array) {
409 if (str.equals(EMPTY_STRING)) {
410 len--;
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530411 }
Bharat saraswal5cd9e9c2016-05-26 23:48:38 +0530412 }
413 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530414 return len - 1;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530415 }
416
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530417 /**
418 * Returns array list of string in case of period.
419 *
420 * @param line line string
421 * @return array list of string in case of period
422 */
423 private static ArrayList<String> getForPeriod(String line) {
424 String[] array = line.split(Pattern.quote(PERIOD));
425 return getSplitArray(array, PERIOD);
426 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530427
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530428 /**
429 * Returns array list of string in case of space.
430 *
431 * @param line line string
432 * @return array list of string in case of space
433 */
434 private static ArrayList<String> getForSpace(String line) {
435 String[] array = line.split(SPACE);
436 return getSplitArray(array, SPACE);
437 }
438
439 /**
440 * Merges strings to form a new string.
441 *
442 * @param list list of strings
443 * @param pattern pattern
444 * @param lineSize line size
445 * @return merged string
446 */
447 private static String merge(ArrayList<String> list, String pattern, int lineSize) {
448 StringBuilder builder = new StringBuilder();
449 StringBuilder fine = new StringBuilder();
Bharat saraswal8beac342016-08-04 02:00:03 +0530450 String append;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530451 String pre;
452 String present = EMPTY_STRING;
453 //Add one blank string in list to handle border limit cases.
454 list.add(EMPTY_STRING);
455 Iterator<String> listIt = list.iterator();
456 ArrayList<String> arrayList = new ArrayList<>();
457 int length;
458 StringBuilder spaces = new StringBuilder();
459 while (listIt.hasNext()) {
460 pre = present;
461 present = listIt.next();
462 //check is present string is more than 80 char.
463 if (present.length() > SUB_SIZE) {
464 int period = getArrayLength(present, PERIOD);
465 int space = getArrayLength(present, SPACE);
466 if (period > space) {
467 // in such case present string should be resolved.
468 present = processModifications(present, SUB_SIZE);
469 builder.append(present);
Bharat saraswale3175d32016-08-31 17:50:11 +0530470 }
Bharat saraswale3175d32016-08-31 17:50:11 +0530471 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530472 length = builder.length();
473 //If length of builder is less than the given length then append
474 // it to builder.
475 if (length <= lineSize) {
476 //fill the space builder to provide proper indentation.
477 if (present.equals(EMPTY_STRING)) {
478 spaces.append(SPACE);
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530479 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530480 //append to builder
481 builder.append(present);
482 builder.append(pattern);
483 fine.append(pre);
484 //do not append pattern in case of empty strings.
485 if (!pre.equals(EMPTY_STRING)) {
486 fine.append(pattern);
487 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530488 } else {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530489 // now the length is more than given size so trim the pattern
490 // for the string and add it to list,
491 fine = getReplacedString(fine, pattern);
492 arrayList.add(fine.toString());
493 // clear all.
494 builder.delete(0, length);
495 fine.delete(0, fine.length());
496 // append indentation
497 if (pattern.contains(PERIOD)) {
498 append = NEW_LINE + spaces +
499 TWELVE_SPACE_INDENTATION +
500 PERIOD;
501 } else {
502 append = NEW_LINE + spaces + TWELVE_SPACE_INDENTATION;
503 }
504 // builder needs to move one step forward to fine builder so
505 // append present and pre strings to builder with pattern.
506 builder.append(append);
507 builder.append(pre);
508 builder.append(pattern);
509 builder.append(present);
510 builder.append(pattern);
511 fine.append(append);
512 fine.append(pre);
513 if (!pre.equals(EMPTY_STRING)) {
514 fine.append(pattern);
515 }
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530516 }
517 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530518
519 builder = getReplacedString(builder, pattern);
520
521 //need to remove extra string added from the builder.
522 if (builder.toString().lastIndexOf(pattern) == builder.length() - 1) {
523 builder = getReplacedString(builder, pattern);
524 }
525 arrayList.add(builder.toString());
526 fine.delete(0, fine.length());
527 for (String str : arrayList) {
528 fine.append(str);
529 }
530 //No need to append extra spaces.
531 if (pattern.equals(PERIOD)) {
532 return fine.toString();
533 }
534 return spaces + fine.toString();
535 }
536
537 /**
538 * Trims extra pattern strings for builder string.
539 *
540 * @param builder builder
541 * @param pattern pattern
542 * @return modified string
543 */
544 private static StringBuilder getReplacedString(StringBuilder builder, String
545 pattern) {
546 String temp = builder.toString();
547 temp = trimAtLast(temp, pattern);
548 int length = builder.length();
549 builder.delete(0, length);
550 builder.append(temp);
551 return builder;
552 }
553
554 /**
555 * Creates array list to process line string modification.
556 *
557 * @param array array of strings
558 * @param pattern pattern
559 * @return list to process line string modification
560 */
561 private static ArrayList<String> getSplitArray(String[] array, String pattern) {
562 ArrayList<String> newArray = new ArrayList<>();
563 int count = 0;
564 String temp;
565 for (String str : array) {
566 if (!str.contains(OPEN_CURLY_BRACKET)) {
567 if (str.length() > SUB_LINE_SIZE) {
568 count = getSplitString(str, newArray, count);
569 } else {
570 newArray.add(str);
571 count++;
572 }
573 } else {
574 if (newArray.isEmpty()) {
575 newArray.add(str);
576 } else {
577 temp = newArray.get(count - 1);
578 newArray.remove(count - 1);
579 newArray.add(count - 1, temp + pattern + str);
580 }
581 }
582 }
583
584 return newArray;
585 }
586
587 private static int getSplitString(String str,
588 ArrayList<String> newArray, int count) {
589 String[] array = str.split(SPACE);
590 for (String st : array) {
591 newArray.add(st + SPACE);
592 count++;
593 }
594 return count;
Bharat saraswal715d3fc2016-05-17 19:59:16 +0530595 }
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530596
597 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530598 * Returns the java Package from package path.
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530599 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530600 * @param packagePath package path
601 * @return java package
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530602 */
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530603 public static String getJavaPackageFromPackagePath(String packagePath) {
604 return packagePath.replace(SLASH, PERIOD);
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530605 }
606
607 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530608 * Returns the directory path corresponding to java package.
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530609 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530610 * @param packagePath package path
611 * @return java package
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530612 */
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530613 public static String getPackageDirPathFromJavaJPackage(String packagePath) {
614 return packagePath.replace(PERIOD, SLASH);
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530615 }
616
617 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530618 * Returns the YANG identifier name as java identifier with first letter
619 * in small.
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530620 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530621 * @param yangIdentifier identifier in YANG file.
622 * @return corresponding java identifier
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530623 */
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530624 public static String getSmallCase(String yangIdentifier) {
625 return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530626 }
627
628 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530629 * Returns the YANG identifier name as java identifier with first letter
630 * in capital.
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530631 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530632 * @param yangIdentifier identifier in YANG file
633 * @return corresponding java identifier
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530634 */
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530635 public static String getCapitalCase(String yangIdentifier) {
636 yangIdentifier = yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
637 return restrictConsecutiveCapitalCase(yangIdentifier);
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530638 }
639
640 /**
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530641 * Restricts consecutive capital cased string as a rule in camel case.
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530642 *
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530643 * @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
644 * @return string without consecutive capital case
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530645 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530646 private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530647
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530648 for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
649 if (k + 1 < consecCapitalCaseRemover.length()) {
650 if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
651 if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
652 consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
653 + consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
654 + consecCapitalCaseRemover.substring(k + 2);
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530655 }
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530656 }
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530657 }
658 }
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530659 return consecCapitalCaseRemover;
Bharat saraswalc2d3be12016-06-16 00:29:12 +0530660 }
661
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530662 /**
663 * Adds prefix, if the string begins with digit or is a java key word.
664 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530665 * @param camelCasePrefix string for adding prefix
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530666 * @param conflictResolver object of YANG to java naming conflict util
667 * @return prefixed camel case string
668 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530669 private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530670
671 String prefix = getPrefixForIdentifier(conflictResolver);
672 if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
673 camelCasePrefix = prefix + camelCasePrefix;
674 }
675 if (JAVA_KEY_WORDS.contains(camelCasePrefix)) {
676 camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase()
677 + camelCasePrefix.substring(1);
678 }
679 return camelCasePrefix;
680 }
681
682 /**
683 * Applies the rule that a string does not end with a capitalized letter and capitalizes
684 * the letter next to a number in an array.
685 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530686 * @param stringArray containing strings for camel case separation
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530687 * @param conflictResolver object of YANG to java naming conflict util
688 * @return camel case rule checked string
689 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530690 private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530691
692 String ruleChecker = stringArray[0].toLowerCase();
693 int i;
694 if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
695 i = 0;
696 ruleChecker = EMPTY_STRING;
697 } else {
698 i = 1;
699 }
700 for (; i < stringArray.length; i++) {
701 if (i + 1 == stringArray.length) {
702 if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
703 || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
704 ruleChecker = ruleChecker + stringArray[i].toLowerCase();
705 break;
706 }
707 }
708 if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
709 for (int j = 0; j < stringArray[i].length(); j++) {
710 char letterCheck = stringArray[i].charAt(j);
711 if (Character.isLetter(letterCheck)) {
712 stringArray[i] = stringArray[i].substring(0, j)
713 + stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
714 break;
715 }
716 }
717 ruleChecker = ruleChecker + stringArray[i];
718 } else {
719 ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
720 }
721 }
722 String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver);
723 return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
724 }
725
726 /**
727 * Resolves the conflict when input has upper case.
728 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530729 * @param stringArray containing strings for upper case conflict resolver
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530730 * @param conflictResolver object of YANG to java naming conflict util
731 * @return camel cased string
732 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530733 private static String upperCaseConflictResolver(String[] stringArray,
734 YangToJavaNamingConflictUtil conflictResolver) {
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530735
736 for (int l = 0; l < stringArray.length; l++) {
737 String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
738 for (int m = 0; m < upperCaseSplitArray.length; m++) {
739 if (upperCaseSplitArray[m].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
740 int check = m;
741 while (check + 1 < upperCaseSplitArray.length) {
742 if (upperCaseSplitArray[check + 1].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
743 upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
744 check = check + 1;
745 } else if (upperCaseSplitArray[check + 1]
746 .matches(REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES)) {
747 upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
748 break;
749 } else {
750 break;
751 }
752 }
753 }
754 }
755 StringBuilder strBuilder = new StringBuilder();
756 for (String element : upperCaseSplitArray) {
757 strBuilder.append(element);
758 }
759 stringArray[l] = strBuilder.toString();
760 }
Bharat saraswal8beac342016-08-04 02:00:03 +0530761 List<String> result = new ArrayList<>();
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530762 for (String element : stringArray) {
763 String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
764 for (String letter : capitalCaseSplitArray) {
765 String[] arrayForAddition = letter.split(REGEX_WITH_DIGITS);
766 List<String> list = Arrays.asList(arrayForAddition);
767 for (String str : list) {
768 if (str != null && !str.isEmpty()) {
769 result.add(str);
770 }
771 }
772 }
773 }
774 stringArray = result.toArray(new String[result.size()]);
775 return applyCamelCaseRule(stringArray, conflictResolver);
776 }
777
778 /**
779 * Returns the YANG identifier name as java identifier.
780 *
Bharat saraswalaf413b82016-07-14 15:18:20 +0530781 * @param yangIdentifier identifier in YANG file
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530782 * @param conflictResolver object of YANG to java naming conflict util
783 * @return corresponding java identifier
784 */
785 public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
786
787 if (conflictResolver != null) {
788 String replacementForHyphen = conflictResolver.getReplacementForHyphen();
789 String replacementForPeriod = conflictResolver.getReplacementForPeriod();
790 String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
791 if (replacementForPeriod != null) {
792 yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
Bharat saraswal1edde622016-09-06 10:18:04 +0530793 PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530794 }
795 if (replacementForUnderscore != null) {
796 yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
Bharat saraswal1edde622016-09-06 10:18:04 +0530797 UNDER_SCORE + replacementForUnderscore.toLowerCase() +
798 UNDER_SCORE);
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530799 }
800 if (replacementForHyphen != null) {
801 yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
Bharat saraswal1edde622016-09-06 10:18:04 +0530802 HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530803 }
804 }
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530805 yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLON);
806 String[] strArray = yangIdentifier.split(COLON);
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530807 if (strArray[0].isEmpty()) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530808 List<String> stringArrangement = new ArrayList<>();
809 stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530810 strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
811 }
812 return upperCaseConflictResolver(strArray, conflictResolver);
813 }
814
815 /**
816 * Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
817 *
818 * @param conflictResolver object of YANG to java naming conflict util
819 * @return prefix which needs to be added
820 */
821 public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {
822
823 String prefixForIdentifier = null;
824 if (conflictResolver != null) {
825 prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
826 }
827 if (prefixForIdentifier != null) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530828 prefixForIdentifier = prefixForIdentifier.replaceAll
829 (REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
830 String[] strArray = prefixForIdentifier.split(COLON);
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530831 try {
832 if (strArray[0].isEmpty()) {
Bharat saraswal8beac342016-08-04 02:00:03 +0530833 List<String> stringArrangement = new ArrayList<>();
834 stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
Gaurav Agrawalbfce9342016-06-15 13:58:01 +0530835 strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
836 }
837 prefixForIdentifier = strArray[0];
838 for (int j = 1; j < strArray.length; j++) {
839 prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() +
840 strArray[j].substring(1);
841 }
842 } catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
843 throw new TranslatorException("The given prefix in pom.xml is invalid.");
844 }
845 } else {
846 prefixForIdentifier = YANG_AUTO_PREFIX;
847 }
848 return prefixForIdentifier;
849 }
Bharat saraswal1edde622016-09-06 10:18:04 +0530850
851 /**
852 * Removes empty directory.
853 *
854 * @param path path to be checked
855 */
856 public static void removeEmptyDirectory(String path) {
857 int index;
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530858 while (path != null && !path.isEmpty()) {
Bharat saraswal1edde622016-09-06 10:18:04 +0530859 if (!removeDirectory(path)) {
860 break;
861 } else {
862 index = path.lastIndexOf(SLASH);
863 path = path.substring(0, index);
864 }
865 }
866 }
867
868 private static boolean removeDirectory(String path) {
869 File dir = new File(path);
870 boolean isDeleted = false;
871 if (dir.isDirectory()) {
872 File[] files = dir.listFiles();
873 if (files != null && files.length == 0) {
874 isDeleted = dir.delete();
875 } else if (files != null && files.length == 1) {
Bharat saraswal9fab16b2016-09-23 23:27:24 +0530876 if ("package-info.java".equals(files[0].getName())
Bharat saraswal1edde622016-09-06 10:18:04 +0530877 || files[0].getName().endsWith("-temp")) {
878 isDeleted = dir.delete();
879 }
880 }
881 }
882 return isDeleted;
883 }
Bharat saraswal97459962016-02-20 21:57:16 +0530884}