Java tutorial
/* * Copyright (c) 2012 Amol S Deshmukh http://www.github.com/adeshmukh * * 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. */ package com.github.adeshmukh.pom2fs; import static java.lang.System.err; import static java.lang.System.out; import java.io.InputStream; import org.kohsuke.args4j.CmdLineParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.adeshmukh.xml2fs.Xml2fs; import com.github.adeshmukh.xml2fs.Xml2fsModule; import com.google.common.io.Closeables; import com.google.inject.Guice; import com.google.inject.Injector; /** * @author adeshmukh * Command line launcher for the pom2fs tool. */ public class Main { private static final Logger log = LoggerFactory.getLogger(Main.class); private static final CmdLineOptions cli = new CmdLineOptions(); private static final CmdLineParser clip = new CmdLineParser(cli); /** * @param args */ public static void main(String[] args) throws Exception { InputStream is = null; try { clip.parseArgument(args); if (cli.showUsage()) { clip.printUsage(out); } else { Injector injector = Guice.createInjector(new Xml2fsModule(cli.getOutputDir()), new PomExtractorModule()); Xml2fs xml2fs = injector.getInstance(Xml2fs.class); xml2fs.run(cli.getInputStream()); } } catch (Exception e) { handleError(e); } finally { Closeables.closeQuietly(is); } } private static void handleError(Exception e) { log.error("", e); System.err.println(e.getMessage()); clip.printUsage(err); } }