|
Cobertura example source code file (CommandLineBuilder.java)
The Cobertura CommandLineBuilder.java source code
/*
* Cobertura - http://cobertura.sourceforge.net/
*
* Copyright (C) 2005 Grzegorz Lukasik
*
* Note: This file is dual licensed under the GPL and the Apache
* Source License (so that it can be used from both the main
* Cobertura classes and the ant tasks).
*
* Cobertura is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* Cobertura is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cobertura; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
package net.sourceforge.cobertura.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
/**
* Helper class for storing long command lines inside temporary file.
* <p>
* Typical usage:
*
* <pre>
* builder = new CommandLineBuilder();
* builder.addArg("--someoption");
* builder.addArg("optionValue");
* ...
* builder.saveArgs();
* doSomething(builder.getCommandLineFile());
* builder.dispose();
* </pre>
*
* It will save options in <code>builder.getCommandLineFile(). Options
* will be stored one in a line. To retrieve options from file helper method can
* be used (see documentation):
*
* <pre>
* String[] args = CommandLineBuilder.preprocessCommandLineArguments(args);
* </pre>
*
* </p>
*
* <p>
* NOTICE: No protection against line separators in arguments, should be OK for
* Cobertura needs.
* </p>
* <p>
* NOTICE: This class depends on local machine settings (line separator, default
* encoding). If arguments are saved on different machine than they are loaded,
* results are unspecified. No problem in Cobertura.
* </p>
*
* @author Grzegorz Lukasik
*/
public class CommandLineBuilder {
private static final Logger logger = Logger
.getLogger(CommandLineBuilder.class);
private static final String LINESEP = System.getProperty("line.separator");
// File that will be used to store arguments
private File commandLineFile = null;
// Writer that will be used to write arguments to the file
private FileWriter commandLineWriter = null;
/**
* Creates a new instance of the builder. Instances of this class should not
* be reused to create many command lines.
*
* @throws IOException
* if problems with creating temporary file for storing command
* line occur
*/
public CommandLineBuilder() throws IOException {
commandLineFile = File.createTempFile("cobertura.", ".cmdline");
commandLineFile.deleteOnExit();
commandLineWriter = new FileWriter(commandLineFile);
}
/**
* Adds command line argument. Each argument can be thought as a single cell
* in array passed to main method. This method should not be used after
* arguments were saved.
*
* @param arg command line argument to save
* @throws IOException
* if problems with temporary file occur
* @throws NullPointerException
* if <code>arg is
Other Cobertura examples (source code examples)Here is a short list of links related to this Cobertura CommandLineBuilder.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.