/** tests basic operation of the parallel task */ public void testBasic() { // should get no output at all Project p = getProject(); p.setUserProperty("test.direct", DIRECT_MESSAGE); p.setUserProperty("test.delayed", DELAYED_MESSAGE); expectOutputAndError("testBasic", "", ""); String log = getLog(); assertEquals( "parallel tasks didn't output correct data", log, DIRECT_MESSAGE + DELAYED_MESSAGE); }
/** tests basic operation of the parallel task */ public void testThreadCount() { // should get no output at all Project p = getProject(); p.setUserProperty("test.direct", DIRECT_MESSAGE); p.setUserProperty("test.delayed", DELAYED_MESSAGE); expectOutputAndError("testThreadCount", "", ""); String log = getLog(); int pos = 0; while (pos > -1) { pos = countThreads(log, pos); } }
/** tests the failure of a task within a parallel construction */ public void testFail() { // should get no output at all Project p = getProject(); p.setUserProperty("test.failure", FAILURE_MESSAGE); p.setUserProperty("test.delayed", DELAYED_MESSAGE); expectBuildExceptionContaining("testFail", "fail task in one parallel branch", FAILURE_MESSAGE); }
public MonitoredBuild(File buildFile, String target) { myBuildFile = buildFile; this.target = target; project = new Project(); project = new Project(); project.init(); project.setUserProperty("ant.file", myBuildFile.getAbsolutePath()); ProjectHelper.configureProject(project, myBuildFile); }
/** * Sets the project's properties. May be called to set project-wide properties, or just before a * target call to \ set target-related properties only. * * @param _properties A map containing the properties' name/value couples * @param _overridable If set, the provided properties values may be overriden \ by the config * file's values * @throws Exception Exceptions are self-explanatory (read their Message) */ public void setProperties(Map _properties, boolean _overridable) throws Exception { // Test if the project exists if (project == null) throw new Exception( "Properties cannot be set because the project has not been initialized. Please call the 'init' method first !"); // Property hashmap is null if (_properties == null) throw new Exception("The provided property map is null."); // Loop through the property map Set propertyNames = _properties.keySet(); Iterator iter = propertyNames.iterator(); while (iter.hasNext()) { // Get the property's name and value String propertyName = (String) iter.next(); String propertyValue = (String) _properties.get(propertyName); if (propertyValue == null) continue; // Set the properties if (_overridable) project.setProperty(propertyName, propertyValue); else project.setUserProperty(propertyName, propertyValue); } }
/** * Attempt to build this entry. * * @param packagerResource packager metadata resource * @param properties a map of properties to pass to the child Ant build responsible for dependency * packaging * @throws IllegalStateException if this entry has already been built */ public synchronized void build(Resource packagerResource, Map properties) throws IOException { // Sanity check if (this.built) { throw new IllegalStateException("build in directory `" + this.dir + "' already completed"); } // Remove work directory if it exists (e.g. left over from last time) if (this.dir.exists()) { if (!cleanup()) { throw new IOException("can't remove directory `" + this.dir + "'"); } } // Create work directory if (!this.dir.mkdirs()) { throw new IOException("can't create directory `" + this.dir + "'"); } // Write out packager XML InputStream packagerXML = packagerResource.openStream(); saveFile("packager.xml", packagerXML); // Write packager XSLT saveFile("packager.xsl"); // Write packager XSD saveFile("packager-1.0.xsd"); // Write master Ant build file saveFile("build.xml"); // Execute the Ant build file Project project = new Project(); project.init(); project.setUserProperty("ant.file", new File(dir, "build.xml").getAbsolutePath()); ProjectHelper.configureProject(project, new File(dir, "build.xml")); project.setBaseDir(dir); // Configure logging verbosity BuildLogger logger = new DefaultLogger(); logger.setMessageOutputLevel( this.verbose ? Project.MSG_VERBOSE : this.quiet ? Project.MSG_WARN : Project.MSG_INFO); logger.setOutputPrintStream(System.out); logger.setErrorPrintStream(System.err); project.addBuildListener(logger); // Set properties project.setUserProperty( "ivy.packager.organisation", "" + this.mr.getModuleId().getOrganisation()); project.setUserProperty("ivy.packager.module", "" + this.mr.getModuleId().getName()); project.setUserProperty("ivy.packager.revision", "" + this.mr.getRevision()); project.setUserProperty("ivy.packager.branch", "" + this.mr.getBranch()); if (this.resourceCache != null) { project.setUserProperty( "ivy.packager.resourceCache", "" + this.resourceCache.getCanonicalPath()); } if (this.resourceURL != null) { project.setUserProperty("ivy.packager.resourceURL", "" + getResourceURL()); } if (this.validate) { project.setUserProperty("ivy.packager.validate", "true"); } project.setUserProperty("ivy.packager.restricted", "" + this.restricted); project.setUserProperty("ivy.packager.quiet", String.valueOf(quiet)); if (properties != null) { for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) { Entry entry = (Entry) it.next(); project.setUserProperty((String) entry.getKey(), (String) entry.getValue()); } } // Execute task Message.verbose("performing packager resolver build in " + this.dir); try { project.executeTarget("build"); this.built = true; } catch (BuildException e) { Message.verbose("packager resolver build failed: " + e); throw e; } }
/** Runs the given targets for the test project specified */ public Map run( File buildFile, List targets, Properties projectProperties, Properties pluginState) { Project project = new Project(); project.setCoreLoader(getClass().getClassLoader()); antListener = new AntRunner.AntListener(); project.addBuildListener( createLogger(projectProperties.getProperty("quokka.debugger.logLevel"))); project.addBuildListener(antListener); // project.setInputHandler(new DefaultInputHandler()); project.setInputHandler( new InputHandler() { public void handleInput(InputRequest request) throws BuildException { System.out.println(request.getPrompt()); try { String line = new BufferedReader(new InputStreamReader(System.in)).readLine(); request.setInput(line); } catch (IOException e) { e.printStackTrace(); } } }); project.setKeepGoingMode(false); // PrintStream err = System.err; // PrintStream out = System.out; // InputStream in = System.in; project.setDefaultInputStream(System.in); // System.setIn(new DemuxInputStream(project)); // System.setOut(new PrintStream(new DemuxOutputStream(project, false))); // System.setErr(new PrintStream(new DemuxOutputStream(project, true))); for (Iterator i = projectProperties.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); project.setUserProperty((String) entry.getKey(), (String) entry.getValue()); } Exception exception = null; try { project.fireBuildStarted(); project.init(); project.setUserProperty("ant.version", "1.7.0"); project.setUserProperty("ant.file", buildFile.getAbsolutePath()); // Remove hard dependency on core.main to allow integration tests to be // done within the core.main package. This is ok as AntRunner is loaded via the integration // test class loader. org.apache.tools.ant.ProjectHelper helper = (org.apache.tools.ant.ProjectHelper) getClass() .getClassLoader() .loadClass("ws.quokka.core.main.ant.ProjectHelper") .newInstance(); project.addReference("ant.projectHelper", helper); helper.parse(project, buildFile); // Add any plugin state PluginState state = (PluginState) project.getReference("quokka.pluginState"); for (Iterator i = pluginState.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); state.put((String) entry.getKey(), entry.getValue()); } Vector targetsVector = new Vector(); targetsVector.addAll(targets); // make sure that we have a target to execute if (targets.size() == 0) { if (project.getDefaultTarget() != null) { targetsVector.add(project.getDefaultTarget()); } } project.executeTargets(targetsVector); Map results = antListener.toMap(); results.put("antProperties", new HashMap(project.getProperties())); return results; } catch (Exception e) { exception = e; if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new BuildException(e); } } finally { // System.setOut(out); // System.setErr(err); // System.setIn(in); project.fireBuildFinished(exception); } }
/** * Initialisation routine called after handler creation with the element name and attributes. * The attributes which this handler can deal with are: <code>"default"</code>, <code>"name" * </code>, <code>"id"</code> and <code>"basedir"</code>. * * @param uri The namespace URI for this element. * @param tag Name of the element which caused this handler to be created. Should not be <code> * null</code>. Ignored in this implementation. * @param qname The qualified name for this element. * @param attrs Attributes of the element which caused this handler to be created. Must not be * <code>null</code>. * @param context The current context. * @exception SAXParseException if an unexpected attribute is encountered or if the <code> * "default"</code> attribute is missing. */ public void onStartElement( String uri, String tag, String qname, Attributes attrs, AntXMLContext context) throws SAXParseException { String baseDir = null; boolean nameAttributeSet = false; Project project = context.getProject(); // Set the location of the implicit target associated with the project tag context.getImplicitTarget().setLocation(new Location(context.getLocator())); /** * XXX I really don't like this - the XML processor is still too 'involved' in the processing. * A better solution (IMO) would be to create UE for Project and Target too, and then process * the tree and have Project/Target deal with its attributes ( similar with Description ). * * <p>If we eventually switch to ( or add support for ) DOM, things will work smoothly - UE * can be avoided almost completely ( it could still be created on demand, for backward * compatibility ) */ for (int i = 0; i < attrs.getLength(); i++) { String attrUri = attrs.getURI(i); if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) { continue; // Ignore attributes from unknown uris } String key = attrs.getLocalName(i); String value = attrs.getValue(i); if (key.equals("default")) { if (value != null && !value.equals("")) { if (!context.isIgnoringProjectTag()) { project.setDefault(value); } } } else if (key.equals("name")) { if (value != null) { context.setCurrentProjectName(value); nameAttributeSet = true; if (!context.isIgnoringProjectTag()) { project.setName(value); project.addReference(value, project); } else if (isInIncludeMode()) { if (!"".equals(value) && (getCurrentTargetPrefix() == null || getCurrentTargetPrefix().length() == 0)) { // help nested include tasks setCurrentTargetPrefix(value); } } } } else if (key.equals("id")) { if (value != null) { // What's the difference between id and name ? if (!context.isIgnoringProjectTag()) { project.addReference(value, project); } } } else if (key.equals("basedir")) { if (!context.isIgnoringProjectTag()) { baseDir = value; } } else { // XXX ignore attributes in a different NS ( maybe store them ? ) throw new SAXParseException( "Unexpected attribute \"" + attrs.getQName(i) + "\"", context.getLocator()); } } // XXX Move to Project ( so it is shared by all helpers ) String antFileProp = MagicNames.ANT_FILE + "." + context.getCurrentProjectName(); String dup = project.getProperty(antFileProp); String typeProp = MagicNames.ANT_FILE_TYPE + "." + context.getCurrentProjectName(); String dupType = project.getProperty(typeProp); if (dup != null && nameAttributeSet) { Object dupFile = null; Object contextFile = null; if (MagicNames.ANT_FILE_TYPE_URL.equals(dupType)) { try { dupFile = new URL(dup); } catch (java.net.MalformedURLException mue) { throw new BuildException( "failed to parse " + dup + " as URL while looking" + " at a duplicate project" + " name.", mue); } contextFile = context.getBuildFileURL(); } else { dupFile = new File(dup); contextFile = context.getBuildFile(); } if (context.isIgnoringProjectTag() && !dupFile.equals(contextFile)) { project.log( "Duplicated project name in import. Project " + context.getCurrentProjectName() + " defined first in " + dup + " and again in " + contextFile, Project.MSG_WARN); } } if (nameAttributeSet) { if (context.getBuildFile() != null) { project.setUserProperty(antFileProp, context.getBuildFile().toString()); project.setUserProperty(typeProp, MagicNames.ANT_FILE_TYPE_FILE); } else if (context.getBuildFileURL() != null) { project.setUserProperty(antFileProp, context.getBuildFileURL().toString()); project.setUserProperty(typeProp, MagicNames.ANT_FILE_TYPE_URL); } } if (context.isIgnoringProjectTag()) { // no further processing return; } // set explicitly before starting ? if (project.getProperty("basedir") != null) { project.setBasedir(project.getProperty("basedir")); } else { // Default for baseDir is the location of the build file. if (baseDir == null) { project.setBasedir(context.getBuildFileParent().getAbsolutePath()); } else { // check whether the user has specified an absolute path if ((new File(baseDir)).isAbsolute()) { project.setBasedir(baseDir); } else { project.setBaseDir(FILE_UTILS.resolveFile(context.getBuildFileParent(), baseDir)); } } } project.addTarget("", context.getImplicitTarget()); context.setCurrentTarget(context.getImplicitTarget()); }