/** * Executes the task. * * <p>Builds a command line to execute cleartool and then calls Exec's run method to execute the * command line. * * @throws BuildException if the command fails and failonerr is set to true */ public void execute() throws BuildException { Commandline commandLine = new Commandline(); Project aProj = getProject(); int result = 0; // Default the viewpath to basedir if it is not specified if (getViewPath() == null) { setViewPath(aProj.getBaseDir().getPath()); } // build the command line from what we got the format is // cleartool lock [options...] // as specified in the CLEARTOOL.EXE help commandLine.setExecutable(getClearToolCommand()); commandLine.createArgument().setValue(COMMAND_UNLOCK); // Check the command line options checkOptions(commandLine); // For debugging // System.out.println(commandLine.toString()); if (!getFailOnErr()) { getProject().log("Ignoring any errors that occur for: " + getOpType(), Project.MSG_VERBOSE); } result = run(commandLine); if (Execute.isFailure(result) && getFailOnErr()) { String msg = "Failed executing: " + commandLine.toString(); throw new BuildException(msg, getLocation()); } }
/** * Executes the task. * * <p>Builds a command line to execute cleartool and then calls Exec's run method to execute the * command line. */ public void execute() throws BuildException { Commandline commandLine = new Commandline(); Project aProj = getProject(); int result = 0; // Check for required attributes if (getTypeName() == null) { throw new BuildException("Required attribute TypeName not specified"); } // Default the viewpath to basedir if it is not specified if (getViewPath() == null) { setViewPath(aProj.getBaseDir().getPath()); } // build the command line from what we got. the format is // cleartool mklabel [options...] [viewpath ...] // as specified in the CLEARTOOL help commandLine.setExecutable(getClearToolCommand()); commandLine.createArgument().setValue(COMMAND_MKLABEL); checkOptions(commandLine); result = run(commandLine); if (Execute.isFailure(result)) { String msg = "Failed executing: " + commandLine.toString(); throw new BuildException(msg, location); } }
/** * Do the compile with the specified arguments. * * @param args - arguments to pass to process on command line */ protected void compile(String[] args) { String[] commandArray = null; File tmpFile = null; try { String myos = System.getProperty("os.name"); // Windows has a 32k limit on total arg size, so // create a temporary file to store all the arguments // There have been reports that 300 files could be compiled // so 250 is a conservative approach if (myos.toLowerCase().indexOf("windows") >= 0 && args.length > 250) { PrintWriter out = null; try { String tempFileName = "jikes" + (new Random(System.currentTimeMillis())).nextLong(); tmpFile = new File(tempFileName); out = new PrintWriter(new FileWriter(tmpFile)); for (int i = 0; i < args.length; i++) { out.println(args[i]); } out.flush(); commandArray = new String[] {command, "@" + tmpFile.getAbsolutePath()}; } catch (IOException e) { throw new BuildException("Error creating temporary file", e); } finally { if (out != null) { try { out.close(); } catch (Throwable t) { // ignore } } } } else { commandArray = new String[args.length + 1]; commandArray[0] = command; System.arraycopy(args, 0, commandArray, 1, args.length); } // We assume, that everything jikes writes goes to // standard output, not to standard error. The option // -Xstdout that is given to Jikes in Javac.doJikesCompile() // should guarantee this. At least I hope so. :) try { Execute exe = new Execute(jop); exe.setAntRun(project); exe.setWorkingDirectory(project.getBaseDir()); exe.setCommandline(commandArray); exe.execute(); } catch (IOException e) { throw new BuildException("Error running Jikes compiler", e); } } finally { if (tmpFile != null) { tmpFile.delete(); } } }
@Override public void execute() throws BuildException { try { Project project = getProject(); UpgradeTableBuilderInvoker.invoke(project.getBaseDir(), _upgradeTableBuilderArgs); } catch (Exception e) { throw new BuildException(e); } }
/** * Converts a string to a URL. If it doesn't form a valid URL as is, it will be treated as a file * and converted to a file: URL. Relative file paths will be interpreted, relative to the Ant * project basedir, and converted to absolute form. * * @param src a URL or a file path * @param project Ant Project for relative file paths * @return URL-equivalent of src * @throws MalformedURLException */ public static URL createURL(String src, Project project) throws MalformedURLException { URL srcURL; try { srcURL = new URL(src); } catch (MalformedURLException e) { File srcFile = new File(src); if (!srcFile.isAbsolute()) srcFile = new File(project.getBaseDir(), src); srcURL = srcFile.toURI().toURL(); } return srcURL; }
/** * transformation * * @throws BuildException exception if something goes wrong with the transformation. */ public void transform() throws BuildException { checkOptions(); Project project = task.getProject(); TempFile tempFileTask = new TempFile(); tempFileTask.bindToOwner(task); XSLTProcess xsltTask = new XSLTProcess(); xsltTask.bindToOwner(task); xsltTask.setXslResource(getStylesheet()); // acrobatic cast. xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile()); File outputFile = null; if (format.equals(FRAMES)) { String tempFileProperty = getClass().getName() + String.valueOf(counter++); File tmp = FILE_UTILS.resolveFile(project.getBaseDir(), project.getProperty("java.io.tmpdir")); tempFileTask.setDestDir(tmp); tempFileTask.setProperty(tempFileProperty); tempFileTask.execute(); outputFile = new File(project.getProperty(tempFileProperty)); } else { outputFile = new File(toDir, "junit-noframes.html"); } xsltTask.setOut(outputFile); for (Iterator i = params.iterator(); i.hasNext(); ) { XSLTProcess.Param param = (XSLTProcess.Param) i.next(); XSLTProcess.Param newParam = xsltTask.createParam(); newParam.setProject(task.getProject()); newParam.setName(param.getName()); newParam.setExpression(param.getExpression()); } XSLTProcess.Param paramx = xsltTask.createParam(); paramx.setProject(task.getProject()); paramx.setName("output.dir"); paramx.setExpression(toDir.getAbsolutePath()); final long t0 = System.currentTimeMillis(); try { xsltTask.execute(); } catch (Exception e) { throw new BuildException("Errors while applying transformations: " + e.getMessage(), e); } final long dt = System.currentTimeMillis() - t0; task.log("Transform time: " + dt + "ms"); if (format.equals(FRAMES)) { Delete delete = new Delete(); delete.bindToOwner(task); delete.setFile(outputFile); delete.execute(); } }
public boolean execute(Project project, long contentLength, InputStream content) throws Throwable { Ant ant = (Ant) project.createTask("ant"); File baseDir = project.getBaseDir(); if (dir != null) baseDir = new File(dir); ant.setDir(baseDir); ant.setInheritAll(inheritall); ant.setInheritRefs(interitrefs); if (target != null) ant.setTarget(target); if (antFile != null) ant.setAntfile(antFile); Enumeration e = properties.elements(); PropertyContainer pc = null; Property p = null; while (e.hasMoreElements()) { pc = (PropertyContainer) e.nextElement(); p = ant.createProperty(); p.setName(pc.getName()); p.setValue(pc.getValue()); } e = references.elements(); ReferenceContainer rc = null; Ant.Reference ref = null; while (e.hasMoreElements()) { rc = (ReferenceContainer) e.nextElement(); ref = new Ant.Reference(); ref.setRefId(rc.getRefId()); ref.setToRefid(rc.getToRefId()); ant.addReference(ref); } ant.execute(); return false; }
/** Resolve a filename with Project's help - if we know one that is. */ private static File resolveFile(Project project, String relativeName) { return FileUtils.getFileUtils() .resolveFile((project == null) ? null : project.getBaseDir(), relativeName); }
/** * Configures this Selector. Does this work only once per Selector object. * * <p>Because some problems while configuring from <custom>Selector the configuration is done in * the following order: * * <ol> * <li>collect the configuration data * <li>wait for the first isSelected() call * <li>set the default values * <li>set values for name pattern '*': update, cache, algorithm, comparator * <li>set values for name pattern '*.*: cache.cachefile, ... * </ol> * * <p>This configuration algorithm is needed because you don't know the order of arriving * config-data. E.g. if you first set the <i>cache.cachefilename</i> and after that the * <i>cache</i> itself, the default value for cachefilename is used, because setting the cache * implies creating a new Cache instance - with its defaults. */ public void configure() { // // ----- The "Singleton" ----- // if (isConfigured) { return; } isConfigured = true; // // ----- Set default values ----- // Project p = getProject(); String filename = "cache.properties"; File cachefile = null; if (p != null) { // normal use inside Ant cachefile = new File(p.getBaseDir(), filename); // set self as a BuildListener to delay cachefile saves getProject().addBuildListener(this); } else { // no reference to project - e.g. during normal JUnit tests cachefile = new File(filename); setDelayUpdate(false); } Cache defaultCache = new PropertiesfileCache(cachefile); Algorithm defaultAlgorithm = new DigestAlgorithm(); Comparator<? super String> defaultComparator = new EqualComparator(); // // ----- Set the main attributes, pattern '*' ----- // for (Parameter parameter : configParameter) { if (parameter.getName().indexOf(".") > 0) { // this is a *.* parameter for later use specialParameter.add(parameter); } else { useParameter(parameter); } } configParameter = new Vector<Parameter>(); // specify the algorithm classname if (algoName != null) { // use Algorithm defined via name if ("hashvalue".equals(algoName.getValue())) { algorithm = new HashvalueAlgorithm(); } else if ("digest".equals(algoName.getValue())) { algorithm = new DigestAlgorithm(); } else if ("checksum".equals(algoName.getValue())) { algorithm = new ChecksumAlgorithm(); } } else { if (algorithmClass != null) { // use Algorithm specified by classname algorithm = (Algorithm) loadClass(algorithmClass, "is not an Algorithm.", Algorithm.class); } else { // nothing specified - use default algorithm = defaultAlgorithm; } } // specify the cache classname if (cacheName != null) { // use Cache defined via name if ("propertyfile".equals(cacheName.getValue())) { cache = new PropertiesfileCache(); } } else { if (cacheClass != null) { // use Cache specified by classname cache = (Cache) loadClass(cacheClass, "is not a Cache.", Cache.class); } else { // nothing specified - use default cache = defaultCache; } } // specify the comparator classname if (compName != null) { // use Algorithm defined via name if ("equal".equals(compName.getValue())) { comparator = new EqualComparator(); } else if ("rule".equals(compName.getValue())) { // TODO there is a problem with the constructor for the RBC. // you have to provide the rules in the constructors - no setters // available. throw new BuildException("RuleBasedCollator not yet supported."); // Have to think about lazy initialization here... JHM // comparator = new java.text.RuleBasedCollator(); } } else { if (comparatorClass != null) { // use Algorithm specified by classname @SuppressWarnings("unchecked") Comparator<? super String> localComparator = loadClass(comparatorClass, "is not a Comparator.", Comparator.class); comparator = localComparator; } else { // nothing specified - use default comparator = defaultComparator; } } // // ----- Set the special attributes, pattern '*.*' ----- // for (Iterator<Parameter> itSpecial = specialParameter.iterator(); itSpecial.hasNext(); ) { Parameter par = itSpecial.next(); useParameter(par); } specialParameter = new Vector<Parameter>(); }