Search in sources :

Example 1 with CmdLineParser

use of jargs.gnu.CmdLineParser in project bigbluebutton by bigbluebutton.

the class DeskshareMain method main.

public static void main(String[] args) {
    DeskshareMain dsMain = new DeskshareMain();
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option host = dsMain.addHelp(parser.addStringOption('s', "server"), serverHelpText);
    CmdLineParser.Option port = dsMain.addHelp(parser.addIntegerOption('p', "port"), "The port the application is listening");
    CmdLineParser.Option listenPort = dsMain.addHelp(parser.addIntegerOption('l', "listenPort"), "Port to listen for lifeline");
    CmdLineParser.Option room = dsMain.addHelp(parser.addStringOption('r', "room"), "Room");
    CmdLineParser.Option cWidth = dsMain.addHelp(parser.addIntegerOption('w', "captureWidth"), "Width of the screen capture");
    CmdLineParser.Option cHeight = dsMain.addHelp(parser.addIntegerOption('t', "captureHeight"), "Height of the screen capture");
    CmdLineParser.Option sWidth = dsMain.addHelp(parser.addIntegerOption('d', "scaleWidth"), "Scale capture width");
    CmdLineParser.Option sHeight = dsMain.addHelp(parser.addIntegerOption('g', "scaleHeight"), "Scale capture height");
    CmdLineParser.Option xCoord = dsMain.addHelp(parser.addIntegerOption('x', "x"), "Upper-left x coordinate of the screen capture");
    CmdLineParser.Option yCoord = dsMain.addHelp(parser.addIntegerOption('y', "y"), "Upper-left y coordinate of the screen capture");
    CmdLineParser.Option tryHttpTunnel = dsMain.addHelp(parser.addBooleanOption('n', "httptunnel"), "Http tunnel if direct connection fails");
    CmdLineParser.Option icon = dsMain.addHelp(parser.addStringOption('i', "icon"), "Path to system tray icon file");
    CmdLineParser.Option help = dsMain.addHelp(parser.addBooleanOption('h', "help"), "Show this help message");
    CmdLineParser.Option fullScreen = dsMain.addHelp(parser.addBooleanOption('f', "full-screen"), "Capture the full screen.");
    try {
        parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
        System.err.println(e.getMessage());
        dsMain.printUsage();
        System.exit(2);
    }
    if (Boolean.TRUE.equals(parser.getOptionValue(help))) {
        dsMain.printUsage();
        System.exit(0);
    }
    // Extract the values entered for the various options -- if the
    // options were not specified, the corresponding values will be
    // the default.
    Integer portValue = (Integer) parser.getOptionValue(port, new Integer(9123));
    Integer listenPortValue = (Integer) parser.getOptionValue(listenPort, new Integer(9125));
    Integer cWidthValue = (Integer) parser.getOptionValue(cWidth, new Integer(801));
    Integer cHeightValue = (Integer) parser.getOptionValue(cHeight, new Integer(601));
    Integer sWidthValue = (Integer) parser.getOptionValue(sWidth, new Integer(800));
    Integer sHeightValue = (Integer) parser.getOptionValue(sHeight, new Integer(600));
    Integer xValue = (Integer) parser.getOptionValue(xCoord, new Integer(0));
    Integer yValue = (Integer) parser.getOptionValue(yCoord, new Integer(0));
    Boolean tunnelValue = (Boolean) parser.getOptionValue(tryHttpTunnel, new Boolean(false));
    String iconValue = (String) parser.getOptionValue(icon, "");
    String url = null;
    String meetingId = null;
    String streamId = null;
    String serverUrl = null;
    Boolean captureFullScreen = false;
    String session = null;
    String codecOptions = null;
    boolean useH264 = true;
    if (args != null && args.length == 9) {
        System.out.println("Using passed args: length=[" + args.length + "]");
        url = args[0];
        serverUrl = args[1];
        meetingId = args[2];
        streamId = args[3];
        captureFullScreen = Boolean.parseBoolean(args[4]);
        useH264 = false;
        System.out.println("Using passed args: [" + url + "] meetingId=[" + meetingId + "] streamId=[" + streamId + "] captureFullScreen=" + captureFullScreen);
        codecOptions = args[5];
        session = args[6];
        useH264 = Boolean.parseBoolean(args[7]);
        String errorMessage = args[8];
        if (!errorMessage.equalsIgnoreCase("NO_ERRORS")) {
            dsMain.displayJavaWarning(errorMessage);
        } else {
            Image image = null;
            if (iconValue.isEmpty()) {
                try {
                    image = ImageIO.read(dsMain.getClass().getResourceAsStream("/images/bbb.gif"));
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                image = Toolkit.getDefaultToolkit().getImage("bbb.gif");
            }
            dsMain.displaySystemProperties();
            System.setProperty("org.bytedeco.javacpp.logger.debug", "true");
            System.out.println("org.bytedeco.javacpp.logger.debug : " + System.getProperty("org.bytedeco.javacpp.logger.debug"));
            client = new DeskshareClient.NewBuilder().host(serverUrl).port(portValue).meetingId(meetingId).streamId(streamId).captureWidth(cWidthValue).captureHeight(cHeightValue).scaleWidth(sWidthValue).scaleHeight(sHeightValue).quality(true).autoScale(0).codecOptions(codecOptions).x(xValue).y(yValue).fullScreen(captureFullScreen).withURL(url).httpTunnel(tunnelValue).trayIcon(image).enableTrayIconActions(true).useH264(useH264).build();
            client.addClientListener(dsMain);
            client.start();
            try {
                System.out.println("Waiting for trigger to Stop client.");
                ExitCode reason = dsMain.exitReasonQ.take();
                System.out.println("Stopping Java Web Start.");
                client.stop();
                System.exit(reason.getExitCode());
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                System.exit(500);
            }
        }
    } else {
        System.out.println("Using default args: [" + url + "] width=[" + cWidthValue + "] height=[" + cHeightValue + "]");
        System.out.println("args null =[" + (args == null) + "] args.length=[" + args.length + "]");
        dsMain.displayJavaWarning("Invalid number of arguments.");
    }
}
Also used : CmdLineParser(jargs.gnu.CmdLineParser) IOException(java.io.IOException) Image(java.awt.Image) Option(jargs.gnu.CmdLineParser.Option)

Example 2 with CmdLineParser

use of jargs.gnu.CmdLineParser in project bigbluebutton by bigbluebutton.

the class DeskshareMain method main.

public static void main(String[] args) {
    DeskshareMain dsMain = new DeskshareMain();
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option host = dsMain.addHelp(parser.addStringOption('s', "server"), serverHelpText);
    CmdLineParser.Option port = dsMain.addHelp(parser.addIntegerOption('p', "port"), "The port the application is listening");
    CmdLineParser.Option listenPort = dsMain.addHelp(parser.addIntegerOption('l', "listenPort"), "Port to listen for lifeline");
    CmdLineParser.Option room = dsMain.addHelp(parser.addStringOption('r', "room"), "Room");
    CmdLineParser.Option cWidth = dsMain.addHelp(parser.addIntegerOption('w', "captureWidth"), "Width of the screen capture");
    CmdLineParser.Option cHeight = dsMain.addHelp(parser.addIntegerOption('t', "captureHeight"), "Height of the screen capture");
    CmdLineParser.Option sWidth = dsMain.addHelp(parser.addIntegerOption('d', "scaleWidth"), "Scale capture width");
    CmdLineParser.Option sHeight = dsMain.addHelp(parser.addIntegerOption('g', "scaleHeight"), "Scale capture height");
    //    	CmdLineParser.Option quality = dsMain.addHelp(parser.addBooleanOption('q', "quality"),"Scale with better quality instead of speed");
    //    	CmdLineParser.Option aspectRatio = dsMain.addHelp(parser.addBooleanOption('a', "aspectRatio"),"Maintain aspect ratio when scaling");
    //    	CmdLineParser.Option autoScale = dsMain.addHelp(parser.addDoubleOption('a', "autoScale"),"Scale factor [0.5 to 0.8]. Override -d and -g options.");
    CmdLineParser.Option xCoord = dsMain.addHelp(parser.addIntegerOption('x', "x"), "Upper-left x coordinate of the screen capture");
    CmdLineParser.Option yCoord = dsMain.addHelp(parser.addIntegerOption('y', "y"), "Upper-left y coordinate of the screen capture");
    CmdLineParser.Option tryHttpTunnel = dsMain.addHelp(parser.addBooleanOption('n', "httptunnel"), "Http tunnel if direct connection fails");
    CmdLineParser.Option icon = dsMain.addHelp(parser.addStringOption('i', "icon"), "Path to system tray icon file");
    CmdLineParser.Option help = dsMain.addHelp(parser.addBooleanOption('h', "help"), "Show this help message");
    CmdLineParser.Option fullScreen = dsMain.addHelp(parser.addBooleanOption('f', "full-screen"), "Capture the full screen.");
    CmdLineParser.Option useSVC2 = dsMain.addHelp(parser.addBooleanOption('2', "useSVC2"), "Use Screen Video V2.");
    try {
        parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
        System.err.println(e.getMessage());
        dsMain.printUsage();
        System.exit(2);
    }
    if (Boolean.TRUE.equals(parser.getOptionValue(help))) {
        dsMain.printUsage();
        System.exit(0);
    }
    // Extract the values entered for the various options -- if the
    // options were not specified, the corresponding values will be
    // the default.
    String hostValue = (String) parser.getOptionValue(host, "localhost");
    Integer portValue = (Integer) parser.getOptionValue(port, new Integer(9123));
    Integer listenPortValue = (Integer) parser.getOptionValue(listenPort, new Integer(9125));
    String roomValue = (String) parser.getOptionValue(room, "85115");
    Integer cWidthValue = (Integer) parser.getOptionValue(cWidth, new Integer(800));
    Integer cHeightValue = (Integer) parser.getOptionValue(cHeight, new Integer(600));
    Integer sWidthValue = (Integer) parser.getOptionValue(sWidth, new Integer(800));
    Integer sHeightValue = (Integer) parser.getOptionValue(sHeight, new Integer(600));
    //        Boolean qualityValue = (Boolean)parser.getOptionValue(quality, new Boolean(false));
    //        Double autoScaleValue = (Double)parser.getOptionValue(autoScale, new Double(0));
    //        Double autoScaleValue = new Double(0);
    //        Boolean aspectValue = (Boolean)parser.getOptionValue(aspectRatio, new Boolean(false));
    Integer xValue = (Integer) parser.getOptionValue(xCoord, new Integer(0));
    Integer yValue = (Integer) parser.getOptionValue(yCoord, new Integer(0));
    Boolean tunnelValue = (Boolean) parser.getOptionValue(tryHttpTunnel, new Boolean(false));
    String iconValue = (String) parser.getOptionValue(icon, "bbb.gif");
    Boolean fullScreenValue = (Boolean) parser.getOptionValue(fullScreen, new Boolean(false));
    Boolean useSVC2Value = (Boolean) parser.getOptionValue(useSVC2, new Boolean(false));
    Image image = Toolkit.getDefaultToolkit().getImage(iconValue);
    lifeline = new LifeLine(listenPortValue.intValue(), dsMain);
    lifeline.listen();
    client = new DeskshareClient.NewBuilder().host(hostValue).port(portValue).room(roomValue).captureWidth(cWidthValue).captureHeight(cHeightValue).scaleWidth(sWidthValue).scaleHeight(sHeightValue).quality(true).autoScale(0).x(xValue).y(yValue).fullScreen(fullScreenValue).useSVC2(useSVC2Value).httpTunnel(tunnelValue).trayIcon(image).enableTrayIconActions(true).build();
    client.addClientListener(dsMain);
    client.start();
    try {
        System.out.println("Waiting for trigger to Stop client.");
        ExitCode reason = dsMain.exitReasonQ.take();
        System.out.println("Stopping client.");
        client.stop();
        lifeline.disconnect();
        System.exit(reason.getExitCode());
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(500);
    }
}
Also used : CmdLineParser(jargs.gnu.CmdLineParser) Image(java.awt.Image) Option(jargs.gnu.CmdLineParser.Option)

Example 3 with CmdLineParser

use of jargs.gnu.CmdLineParser in project hackpad by dropbox.

the class YUICompressor method main.

public static void main(String[] args) {
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option typeOpt = parser.addStringOption("type");
    CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
    CmdLineParser.Option nomungeOpt = parser.addBooleanOption("nomunge");
    CmdLineParser.Option linebreakOpt = parser.addStringOption("line-break");
    CmdLineParser.Option preserveSemiOpt = parser.addBooleanOption("preserve-semi");
    CmdLineParser.Option disableOptimizationsOpt = parser.addBooleanOption("disable-optimizations");
    CmdLineParser.Option helpOpt = parser.addBooleanOption('h', "help");
    CmdLineParser.Option charsetOpt = parser.addStringOption("charset");
    CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o', "output");
    Reader in = null;
    Writer out = null;
    try {
        parser.parse(args);
        Boolean help = (Boolean) parser.getOptionValue(helpOpt);
        if (help != null && help.booleanValue()) {
            usage();
            System.exit(0);
        }
        boolean verbose = parser.getOptionValue(verboseOpt) != null;
        String charset = (String) parser.getOptionValue(charsetOpt);
        if (charset == null || !Charset.isSupported(charset)) {
            charset = System.getProperty("file.encoding");
            if (charset == null) {
                charset = "UTF-8";
            }
            if (verbose) {
                System.err.println("\n[INFO] Using charset " + charset);
            }
        }
        String[] fileArgs = parser.getRemainingArgs();
        String type = (String) parser.getOptionValue(typeOpt);
        if (fileArgs.length == 0) {
            if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                usage();
                System.exit(1);
            }
            in = new InputStreamReader(System.in, charset);
        } else {
            if (type != null && !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                usage();
                System.exit(1);
            }
            String inputFilename = fileArgs[0];
            if (type == null) {
                int idx = inputFilename.lastIndexOf('.');
                if (idx >= 0 && idx < inputFilename.length() - 1) {
                    type = inputFilename.substring(idx + 1);
                }
            }
            if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                usage();
                System.exit(1);
            }
            in = new InputStreamReader(new FileInputStream(inputFilename), charset);
        }
        int linebreakpos = -1;
        String linebreakstr = (String) parser.getOptionValue(linebreakOpt);
        if (linebreakstr != null) {
            try {
                linebreakpos = Integer.parseInt(linebreakstr, 10);
            } catch (NumberFormatException e) {
                usage();
                System.exit(1);
            }
        }
        String outputFilename = (String) parser.getOptionValue(outputFilenameOpt);
        if (type.equalsIgnoreCase("js")) {
            try {
                JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {

                    public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
                        if (line < 0) {
                            System.err.println("\n[WARNING] " + message);
                        } else {
                            System.err.println("\n[WARNING] " + line + ':' + lineOffset + ':' + message);
                        }
                    }

                    public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
                        if (line < 0) {
                            System.err.println("\n[ERROR] " + message);
                        } else {
                            System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':' + message);
                        }
                    }

                    public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) {
                        error(message, sourceName, line, lineSource, lineOffset);
                        return new EvaluatorException(message);
                    }
                });
                // Close the input stream first, and then open the output stream,
                // in case the output file should override the input file.
                in.close();
                in = null;
                if (outputFilename == null) {
                    out = new OutputStreamWriter(System.out, charset);
                } else {
                    out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
                }
                boolean munge = parser.getOptionValue(nomungeOpt) == null;
                boolean preserveAllSemiColons = parser.getOptionValue(preserveSemiOpt) != null;
                boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;
                compressor.compress(out, linebreakpos, munge, verbose, preserveAllSemiColons, disableOptimizations);
            } catch (EvaluatorException e) {
                e.printStackTrace();
                // Return a special error code used specifically by the web front-end.
                System.exit(2);
            }
        } else if (type.equalsIgnoreCase("css")) {
            CssCompressor compressor = new CssCompressor(in);
            // Close the input stream first, and then open the output stream,
            // in case the output file should override the input file.
            in.close();
            in = null;
            if (outputFilename == null) {
                out = new OutputStreamWriter(System.out, charset);
            } else {
                out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
            }
            compressor.compress(out, linebreakpos);
        }
    } catch (CmdLineParser.OptionException e) {
        usage();
        System.exit(1);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : CmdLineParser(jargs.gnu.CmdLineParser) ErrorReporter(yuicompressor.org.mozilla.javascript.ErrorReporter) EvaluatorException(yuicompressor.org.mozilla.javascript.EvaluatorException)

Example 4 with CmdLineParser

use of jargs.gnu.CmdLineParser in project jforum2 by rafaelsteil.

the class LuceneCommandLineReindexer method parseCmdArgs.

private void parseCmdArgs(String[] args) {
    StringBuffer description = new StringBuffer(512);
    description.append("\n*** Going to reindex using the following options: \n");
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option recreateOption = parser.addBooleanOption("recreateIndex");
    CmdLineParser.Option typeOption = parser.addStringOption("type");
    CmdLineParser.Option pathOption = parser.addStringOption("path");
    CmdLineParser.Option firstPostIdOption = parser.addIntegerOption("firstPostId");
    CmdLineParser.Option lastPostIdOption = parser.addIntegerOption("lastPostId");
    CmdLineParser.Option fromDateOption = parser.addStringOption("fromDate");
    CmdLineParser.Option toDateOption = parser.addStringOption("toDate");
    CmdLineParser.Option avoidDuplicatedOption = parser.addBooleanOption("avoidDuplicatedRecords");
    try {
        parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
        System.out.println(e.getMessage());
        this.printUsage();
    }
    if (parser.getRemainingArgs().length > 0) {
        this.printUsage();
    }
    // Type
    String type = (String) parser.getOptionValue(typeOption);
    if (StringUtils.isEmpty(type) || (!type.equals("date") && !type.equals("message"))) {
        System.out.println("*** --type should be either date or message");
        this.printUsage();
    }
    description.append("\t-> Searching by ").append(type).append('\n');
    // Path
    this.path = (String) parser.getOptionValue(pathOption);
    if (StringUtils.isEmpty(this.path)) {
        System.out.println("*** --path is a required option. It should point to the root directory where JForum is installed");
        this.printUsage();
    }
    description.append("\t->App path: ").append(path).append('\n');
    // FirstPostId and LastPostId
    int firstPostId = ((Integer) parser.getOptionValue(firstPostIdOption, new Integer(0))).intValue();
    int lastPostId = ((Integer) parser.getOptionValue(lastPostIdOption, new Integer(0))).intValue();
    if ("message".equals(type)) {
        if (firstPostId == 0 || lastPostId == 0 || lastPostId <= firstPostId) {
            System.out.println("*** --firstPostId and --lastPostId are required fields when --type=message. " + "Also, --lastPostId should be greater than --firstPostId");
            this.printUsage();
        }
        description.append("\t-> From Post #").append(firstPostId).append(" to Post #").append(lastPostId).append('\n');
    }
    // FromDate and ToDate
    Date fromDate = null;
    Date toDate = null;
    if ("date".equals(type)) {
        fromDate = this.parseDate((String) parser.getOptionValue(fromDateOption));
        toDate = this.parseDate((String) parser.getOptionValue(toDateOption));
        if (fromDate == null || toDate == null) {
            System.out.println("*** --fromDate and --toDate are required fields when --type=date");
            this.printUsage();
        }
        description.append("\t-> From date ").append(fromDate).append(" to ").append(toDate).append('\n');
    }
    // Recreate
    this.recreate = ((Boolean) parser.getOptionValue(recreateOption, Boolean.FALSE)).booleanValue();
    description.append("\t->Recreate the index? ").append(this.recreate ? "Yes" : "No").append('\n');
    // AvoidDuplicatedRecords
    boolean avoidDuplicated = ((Boolean) parser.getOptionValue(avoidDuplicatedOption, Boolean.FALSE)).booleanValue();
    description.append("\t->Avoid duplicated records? ").append(avoidDuplicated ? "Yes" : "No").append('\n');
    this.reindexerArgs = new LuceneReindexArgs(fromDate, toDate, firstPostId, lastPostId, avoidDuplicated, "date".equals(type) ? LuceneReindexArgs.TYPE_DATE : LuceneReindexArgs.TYPE_MESSAGE);
    System.out.println(description);
}
Also used : CmdLineParser(jargs.gnu.CmdLineParser) LuceneReindexArgs(net.jforum.search.LuceneReindexArgs) Date(java.util.Date)

Example 5 with CmdLineParser

use of jargs.gnu.CmdLineParser in project yuicompressor by yui.

the class YUICompressor method main.

public static void main(String[] args) {
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option typeOpt = parser.addStringOption("type");
    CmdLineParser.Option versionOpt = parser.addBooleanOption('V', "version");
    CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
    CmdLineParser.Option nomungeOpt = parser.addBooleanOption("nomunge");
    CmdLineParser.Option linebreakOpt = parser.addStringOption("line-break");
    CmdLineParser.Option preserveSemiOpt = parser.addBooleanOption("preserve-semi");
    CmdLineParser.Option disableOptimizationsOpt = parser.addBooleanOption("disable-optimizations");
    CmdLineParser.Option helpOpt = parser.addBooleanOption('h', "help");
    CmdLineParser.Option charsetOpt = parser.addStringOption("charset");
    CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o', "output");
    CmdLineParser.Option mungemapFilenameOpt = parser.addStringOption('m', "mungemap");
    CmdLineParser.Option preserveUnknownHintsOpt = parser.addBooleanOption('p', "preservehints");
    Reader in = null;
    Writer out = null;
    Writer mungemap = null;
    try {
        parser.parse(args);
        Boolean help = (Boolean) parser.getOptionValue(helpOpt);
        if (help != null && help.booleanValue()) {
            usage();
            System.exit(0);
        }
        Boolean version = (Boolean) parser.getOptionValue(versionOpt);
        if (version != null && version.booleanValue()) {
            version();
            System.exit(0);
        }
        boolean verbose = parser.getOptionValue(verboseOpt) != null;
        String charset = (String) parser.getOptionValue(charsetOpt);
        if (charset == null || !Charset.isSupported(charset)) {
            // charset = System.getProperty("file.encoding");
            // if (charset == null) {
            // charset = "UTF-8";
            // }
            // UTF-8 seems to be a better choice than what the system is reporting
            charset = "UTF-8";
            if (verbose) {
                System.err.println("\n[INFO] Using charset " + charset);
            }
        }
        int linebreakpos = -1;
        String linebreakstr = (String) parser.getOptionValue(linebreakOpt);
        if (linebreakstr != null) {
            try {
                linebreakpos = Integer.parseInt(linebreakstr, 10);
            } catch (NumberFormatException e) {
                usage();
                System.exit(1);
            }
        }
        String typeOverride = (String) parser.getOptionValue(typeOpt);
        if (typeOverride != null && !typeOverride.equalsIgnoreCase("js") && !typeOverride.equalsIgnoreCase("css")) {
            usage();
            System.exit(1);
        }
        boolean munge = parser.getOptionValue(nomungeOpt) == null;
        boolean preserveAllSemiColons = parser.getOptionValue(preserveSemiOpt) != null;
        boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;
        boolean preserveUnknownHints = parser.getOptionValue(preserveUnknownHintsOpt) != null;
        String[] fileArgs = parser.getRemainingArgs();
        java.util.List files = java.util.Arrays.asList(fileArgs);
        if (files.isEmpty()) {
            if (typeOverride == null) {
                usage();
                System.exit(1);
            }
            files = new java.util.ArrayList();
            // read from stdin
            files.add("-");
        }
        String output = (String) parser.getOptionValue(outputFilenameOpt);
        String[] pattern;
        if (output == null) {
            pattern = new String[0];
        } else if (output.matches("(?i)^[a-z]\\:\\\\.*")) {
            // if output is with something like c:\ dont split it
            pattern = new String[] { output };
        } else {
            pattern = output.split(":");
        }
        try {
            String mungemapFilename = (String) parser.getOptionValue(mungemapFilenameOpt);
            if (mungemapFilename != null) {
                mungemap = new OutputStreamWriter(new FileOutputStream(mungemapFilename), charset);
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
        java.util.Iterator filenames = files.iterator();
        while (filenames.hasNext()) {
            String inputFilename = (String) filenames.next();
            String type = null;
            try {
                if (inputFilename.equals("-")) {
                    in = new InputStreamReader(System.in, charset);
                    type = typeOverride;
                } else {
                    if (typeOverride != null) {
                        type = typeOverride;
                    } else {
                        int idx = inputFilename.lastIndexOf('.');
                        if (idx >= 0 && idx < inputFilename.length() - 1) {
                            type = inputFilename.substring(idx + 1);
                        }
                    }
                    if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                        usage();
                        System.exit(1);
                    }
                    in = new InputStreamReader(new FileInputStream(inputFilename), charset);
                }
                String outputFilename = output;
                // if a substitution pattern was passed in
                if (pattern.length > 1 && files.size() > 0) {
                    outputFilename = inputFilename.replaceFirst(pattern[0], pattern[1]);
                }
                if (type.equalsIgnoreCase("js")) {
                    try {
                        final String localFilename = inputFilename;
                        JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {

                            public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
                                System.err.println("\n[WARNING] in " + localFilename);
                                if (line < 0) {
                                    System.err.println("  " + message);
                                } else {
                                    System.err.println("  " + line + ':' + lineOffset + ':' + message);
                                }
                            }

                            public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
                                System.err.println("[ERROR] in " + localFilename);
                                if (line < 0) {
                                    System.err.println("  " + message);
                                } else {
                                    System.err.println("  " + line + ':' + lineOffset + ':' + message);
                                }
                            }

                            public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) {
                                error(message, sourceName, line, lineSource, lineOffset);
                                return new EvaluatorException(message);
                            }
                        });
                        // Close the input stream first, and then open the output stream,
                        // in case the output file should override the input file.
                        in.close();
                        in = null;
                        if (outputFilename == null) {
                            out = new OutputStreamWriter(System.out, charset);
                        } else {
                            out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
                            if (mungemap != null) {
                                mungemap.write("\n\nFile: " + outputFilename + "\n\n");
                            }
                        }
                        compressor.compress(out, mungemap, linebreakpos, munge, verbose, preserveAllSemiColons, disableOptimizations, preserveUnknownHints);
                    } catch (EvaluatorException e) {
                        e.printStackTrace();
                        // Return a special error code used specifically by the web front-end.
                        System.exit(2);
                    }
                } else if (type.equalsIgnoreCase("css")) {
                    CssCompressor compressor = new CssCompressor(in);
                    // Close the input stream first, and then open the output stream,
                    // in case the output file should override the input file.
                    in.close();
                    in = null;
                    if (outputFilename == null) {
                        out = new OutputStreamWriter(System.out, charset);
                    } else {
                        out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
                    }
                    compressor.compress(out, linebreakpos);
                }
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (CmdLineParser.OptionException e) {
        usage();
        System.exit(1);
    } finally {
        if (mungemap != null) {
            try {
                mungemap.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : CmdLineParser(jargs.gnu.CmdLineParser) ErrorReporter(org.mozilla.javascript.ErrorReporter) EvaluatorException(org.mozilla.javascript.EvaluatorException)

Aggregations

CmdLineParser (jargs.gnu.CmdLineParser)5 Option (jargs.gnu.CmdLineParser.Option)2 Image (java.awt.Image)2 IOException (java.io.IOException)1 Date (java.util.Date)1 LuceneReindexArgs (net.jforum.search.LuceneReindexArgs)1 ErrorReporter (org.mozilla.javascript.ErrorReporter)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 ErrorReporter (yuicompressor.org.mozilla.javascript.ErrorReporter)1 EvaluatorException (yuicompressor.org.mozilla.javascript.EvaluatorException)1