1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 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 17 import java.io.File 18 import java.nio.file.Files 19 mainnull20fun main(args: Array<String>) { 21 val showUsage = args.isEmpty() || when (args.singleOrNull()) { 22 "-h", "--help" -> true 23 else -> false 24 } 25 if (showUsage) { 26 usage() 27 return 28 } 29 30 val files = args.flatMap { 31 File(it).walk().filter { it.isFile && it.extension == "java" }.map { it.toPath() } 32 } 33 val persistences = parse(files) 34 for (persistence in persistences) { 35 val file = generate(persistence) 36 Files.newBufferedWriter(persistence.path).use { 37 it.write(FILE_HEADER) 38 file.writeTo(it) 39 } 40 } 41 } 42 usagenull43private fun usage() { 44 println("Usage: xmlpersistence <FILES>") 45 } 46