/** * Add any task validation needed to ensure internal code quality * @param task task * @param role role of the task */ private void validateTask(Task task, String role) { if (task != null && task.getProject() == null) { throw new BuildException("%s task is not bound to the project %s", role, task); } }
/** * Force the task to be reconfigured from its RuntimeConfigurable. */ public void reconfigure() { if (wrapper != null) { wrapper.reconfigure(getProject()); } }
/** * Construct a BuildEvent for a task level event. * The project and target associated with the event * are derived from the given task. * * @param task the task that emitted the event. * Must not be <code>null</code>. */ public BuildEvent(Task task) { super(task); this.project = task.getProject(); this.target = task.getOwningTarget(); this.task = task; }
/** * Handle an input request by this task. * * @param buffer the buffer into which data is to be read. * @param offset the offset into the buffer at which data is stored. * @param length the amount of data to read. * * @return the number of bytes read. * * @exception IOException if the data cannot be read. * @since Ant 1.6 */ protected int handleInput(byte[] buffer, int offset, int length) throws IOException { return getProject().defaultInput(buffer, offset, length); }
/** * Logs a message with the given priority. This delegates * the actual logging to the project. * * @param msg The message to be logged. Should not be <code>null</code>. * @param msgLevel The message priority at which this message is to * be logged. */ public void log(String msg, int msgLevel) { if (getProject() == null) { super.log(msg, msgLevel); } else { getProject().log(this, msg, msgLevel); } }
/** * Logs a message with the given priority. This delegates * the actual logging to the project. * * @param msg The message to be logged. Should not be <code>null</code>. * @param t The exception to be logged. May be <code>null</code>. * @param msgLevel The message priority at which this message is to * be logged. * @since 1.7 */ public void log(String msg, Throwable t, int msgLevel) { if (getProject() == null) { super.log(msg, msgLevel); } else { getProject().log(this, msg, t, msgLevel); } }
/** * Adds any classes the user specifies using <i>support</i> nested elements * to the <code>ejbFiles</code> Hashtable. * * @param ejbFiles Hashtable of EJB classes (and other) files that will be * added to the completed JAR file */ protected void addSupportClasses(Hashtable<String, File> ejbFiles) { // add in support classes if any Project project = task.getProject(); for (FileSet supportFileSet : config.supportFileSets) { File supportBaseDir = supportFileSet.getDir(project); DirectoryScanner supportScanner = supportFileSet.getDirectoryScanner(project); for (String supportFile : supportScanner.getIncludedFiles()) { ejbFiles.put(supportFile, new File(supportBaseDir, supportFile)); } } }
/** * Add the classpath for the user classes * * @return a Path instance to be configured by Ant. */ public Path createClasspath() { if (classpath == null) { classpath = new Path(task.getProject()); } return classpath.createPath(); }
/** * Configures this task - if it hasn't been done already. * If the task has been invalidated, it is replaced with an * UnknownElement task which uses the new definition in the project. * * @exception BuildException if the task cannot be configured. */ public void maybeConfigure() throws BuildException { if (invalid) { getReplacement(); } else if (wrapper != null) { wrapper.maybeConfigure(getProject()); } }
/** * Called to validate that the tool parameters have been configured. * @throws BuildException if there is an error. */ @Override public void validateConfigured() throws BuildException { super.validateConfigured(); if (ejbdeploy) { String home = getTask().getProject().getProperty("websphere.home"); if (home == null) { throw new BuildException( "The 'websphere.home' property must be set when 'ejbdeploy=true'"); } websphereHome = getTask().getProject().resolveFile(home); } }
/** * Get the classpath to the WebSphere classpaths. * @return the WebSphere classpath. */ public Path createWASClasspath() { if (wasClasspath == null) { wasClasspath = new Path(getTask().getProject()); } return wasClasspath.createPath(); }
/** * Get the classpath to the WebLogic classpaths. * @return the classpath to configure. */ public Path createWLClasspath() { if (wlClasspath == null) { wlClasspath = new Path(getTask().getProject()); } return wlClasspath.createPath(); }
/** * Based on the parameter passed in, this method creates the necessary * factory desired. * * The current mapping for compiler names are as follows: * <ul><li>jasper = jasper compiler (the default) * <li><i>a fully qualified classname</i> = the name of a jsp compiler * adapter * </ul> * * @param compilerType either the name of the desired compiler, or the * full classname of the compiler's adapter. * @param task a task to log through. * @return the compiler * @throws BuildException if the compiler type could not be resolved into * a compiler adapter. */ public static JspCompilerAdapter getCompiler(String compilerType, Task task) throws BuildException { return getCompiler(compilerType, task, // Memory-Leak in line below task.getProject().createClassLoader(null)); }
/** * Returns a Classloader object which parses the passed in generic EjbJar classpath. * The loader is used to dynamically load classes from javax.ejb.* and the classes * being added to the jar. * @return a classloader. */ protected ClassLoader getClassLoaderForBuild() { if (classpathLoader != null) { return classpathLoader; } Path combinedClasspath = getCombinedClasspath(); // only generate a new ClassLoader if we have a classpath if (combinedClasspath == null) { classpathLoader = getClass().getClassLoader(); } else { // Memory leak in line below classpathLoader = getTask().getProject().createClassLoader(combinedClasspath); } return classpathLoader; }
/** * Helper method invoked by isRebuildRequired to get a ClassLoader for a * Jar File passed to it. * * @param classjar java.io.File representing jar file to get classes from. * @return the classloader for the jarfile. * @throws IOException if there is a problem. */ protected ClassLoader getClassLoaderFromJar(File classjar) throws IOException { Path lookupPath = new Path(getTask().getProject()); lookupPath.setLocation(classjar); Path classpath = getCombinedClasspath(); if (classpath != null) { lookupPath.append(classpath); } return getTask().getProject().createClassLoader(lookupPath); } }
/** * Helper method invoked by isRebuildRequired to get a ClassLoader for a * Jar File passed to it. * * @param classjar java.io.File representing jar file to get classes from. * @return a classloader for the jar file. * @throws IOException if there is an error. */ protected ClassLoader getClassLoaderFromJar(File classjar) throws IOException { Path lookupPath = new Path(getTask().getProject()); lookupPath.setLocation(classjar); Path classpath = getCombinedClasspath(); if (classpath != null) { lookupPath.append(classpath); } return getTask().getProject().createClassLoader(lookupPath); } }
/** * Recursively adds an UnknownElement instance for each child * element of replacement. * * @since Ant 1.5.1 */ private void replaceChildren(RuntimeConfigurable wrapper, UnknownElement parentElement) { for (RuntimeConfigurable childWrapper : Collections.list(wrapper.getChildren())) { UnknownElement childElement = new UnknownElement(childWrapper.getElementTag()); parentElement.addChild(childElement); childElement.setProject(getProject()); childElement.setRuntimeConfigurableWrapper(childWrapper); childWrapper.setProxy(childElement); replaceChildren(childWrapper, childElement); } }
public AntBuilder(final Task parentTask) { this(parentTask.getProject(), parentTask.getOwningTarget()); // define "owning" task as wrapper to avoid having tasks added to the target // but it needs to be an UnknownElement and no access is available from // task to its original UnknownElement final UnknownElement ue = new UnknownElement(parentTask.getTaskName()); ue.setProject(parentTask.getProject()); ue.setTaskType(parentTask.getTaskType()); ue.setTaskName(parentTask.getTaskName()); ue.setLocation(parentTask.getLocation()); ue.setOwningTarget(parentTask.getOwningTarget()); ue.setRuntimeConfigurableWrapper(parentTask.getRuntimeConfigurableWrapper()); parentTask.getRuntimeConfigurableWrapper().setProxy(ue); antXmlContext.pushWrapper(parentTask.getRuntimeConfigurableWrapper()); }
/** * Bind a task to another; use this when configuring a newly created * task to do work on behalf of another. * Project, OwningTarget, TaskName, Location and Description are all copied * * Important: this method does not call {@link Task#init()}. * If you are creating a task to delegate work to, call {@link Task#init()} * to initialize it. * * @param owner owning target * @since Ant1.7 */ public final void bindToOwner(Task owner) { setProject(owner.getProject()); setOwningTarget(owner.getOwningTarget()); setTaskName(owner.getTaskName()); setDescription(owner.getDescription()); setLocation(owner.getLocation()); setTaskType(owner.getTaskType()); } }
/** * Creates an UnknownElement that can be used to replace this task. * Once this has been created once, it is cached and returned by * future calls. * * @return the UnknownElement instance for the new definition of this task. */ private UnknownElement getReplacement() { if (replacement == null) { replacement = new UnknownElement(taskType); replacement.setProject(getProject()); replacement.setTaskType(taskType); replacement.setTaskName(taskName); replacement.setLocation(getLocation()); replacement.setOwningTarget(target); replacement.setRuntimeConfigurableWrapper(wrapper); wrapper.setProxy(replacement); replaceChildren(wrapper, replacement); target.replaceChild(this, replacement); replacement.maybeConfigure(); } return replacement; }