Coverage Summary for Class: MigrationTool (co.rsk.cli.config)

Class Class, % Method, % Line, %
MigrationTool 0% (0/1) 0% (0/2) 0% (0/14)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2018 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18 package co.rsk.cli.config; 19  20 import co.rsk.cli.CliArgs; 21  22 import java.io.IOException; 23 import java.nio.charset.StandardCharsets; 24 import java.nio.file.Files; 25 import java.nio.file.Path; 26 import java.nio.file.StandardOpenOption; 27  28 public class MigrationTool { 29  30  public static void main(String[] commandLineArgs) throws IOException { 31  CliArgs.Parser<Migrator.MigratorOptions, Migrator.MigratorFlags> parser = new CliArgs.Parser<>( 32  Migrator.MigratorOptions.class, 33  Migrator.MigratorFlags.class 34  ); 35  36  CliArgs<Migrator.MigratorOptions, Migrator.MigratorFlags> cliArgs = parser.parse(commandLineArgs); 37  38  MigratorConfiguration configuration = new MigratorConfiguration( 39  cliArgs.getOptions().get(Migrator.MigratorOptions.INPUT_FILE), 40  cliArgs.getOptions().get(Migrator.MigratorOptions.MIGRATION_FILE), 41  cliArgs.getOptions().get(Migrator.MigratorOptions.OUTPUT_FILE), 42  cliArgs.getFlags().contains(Migrator.MigratorFlags.REPLACE_IN_PLACE) 43  ); 44  45  Migrator migrator = new Migrator(configuration); 46  String migratedConfigOutput = migrator.migrateConfiguration(); 47  Path destination = configuration.getDestinationConfiguration(); 48  Files.write(destination, migratedConfigOutput.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 49  50  System.out.println("Configuration successfully migrated."); 51  System.out.printf("Source: %s\nDestination: %s\n", configuration.getSourceConfiguration(), destination); 52  } 53 }