/*-------------------------------------------------------------------------- * Copyright 2008 utgenome.org * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *--------------------------------------------------------------------------*/ //-------------------------------------- // utgb-shell Project // // Repair.java // Since: Feb 1, 2008 // // $URL$ // $Author$ //-------------------------------------- package org.utgenome.shell; import java.io.File; import java.io.StringWriter; import org.utgenome.config.TrackConfiguration; import org.utgenome.config.UTGBConfig; import org.utgenome.shell.Create.ScaffoldFileFilter; import org.xerial.lens.Lens; import org.xerial.silk.SilkWriter; import org.xerial.util.log.Logger; import org.xerial.util.opt.Argument; import org.xerial.util.opt.Option; public class Repair extends UTGBShellCommand { private static Logger _logger = Logger.getLogger(Repair.class); @Option(symbol = "p", longName = "package", varName = "PACKAGE_NAME", description = "specify the java package name. e.g. org.yourdomain.track") private String packageName = null; @Option(symbol = "g", longName = "group", varName = "GROUP_NAME", description = "specify the maven group name of this project. default = org.utgenome.track") private String group = "org.utgenome.track"; @Option(symbol = "f", longName = "file", varName = "FILENAME", description = "repair specified file only") private String repairTargetFile = null; private ScaffoldFileFilter scaffoldFilter = new Create.CreateAllScaffoldFileFilter(); @Argument(index = 0) private String projectName = null; public Repair() { } @Override public void execute(String[] args) throws Exception { if (repairTargetFile != null) { scaffoldFilter = new Create.ScaffoldFileFilter() { public boolean accept(String pathname) { return pathname.equals(repairTargetFile); } }; } if (!isInProjectRoot()) { // no configuration file is found File prevConfigXML = getObsolteConfigurationFile(); if (prevConfigXML.exists()) { TrackConfiguration oldConfig = Lens.loadXML(TrackConfiguration.class, prevConfigXML.toURL()); UTGBConfig config = oldConfig.convert(); String silk = toSilk(config); // TODO implementation throw new UTGBShellException("needs migration"); } } try { UTGBConfig config = loadUTGBConfig(); Create.createScaffold(config.projectName, config.javaPackage, config.group, "./", scaffoldFilter); } catch (UTGBShellException e) { _logger.info(String.format("No %s file found or the config file is collapsed", getConfigFile())); // create from scratch if (projectName == null) throw new UTGBShellException("please specify your package name with -p option and the project name as a command line argument."); if (packageName == null) packageName = projectName; Create.createScaffold(projectName, packageName, group, "./", scaffoldFilter); } } public static String toSilk(UTGBConfig config) { StringWriter buf = new StringWriter(); SilkWriter w = new SilkWriter(buf); return null; } @Override public String name() { return "repair"; } public String getOneLinerDescription() { return "repair or restore template files"; } }