/** * Creates a fresh object instance of the specified classname. * * <p>This uses the userDefinedLoader to load the specified class, * and then makes an instance using the default no-argument constructor.</p> * * @param className the full qualified class name to load. * @param userDefinedLoader the classloader to use. * @return The fresh object instance * @throws BuildException when loading or instantiation failed. */ public static Object newInstance(String className, ClassLoader userDefinedLoader) { return newInstance(className, userDefinedLoader, Object.class); }
/** * Create an instance of a matcher from a classname. * * @param className a <code>String</code> value * @return a <code>RegexpMatcher</code> value * @exception BuildException if an error occurs */ protected RegexpMatcher createInstance(String className) throws BuildException { return ClasspathUtils.newInstance(className, RegexpMatcherFactory.class.getClassLoader(), RegexpMatcher.class); }
/** * Tries to resolve the given classname into a javah adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of JavahAdapter. */ private static JavahAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : JavahAdapterFactory.class.getClassLoader(), JavahAdapter.class); } }
/** * Wrapper over RegexpMatcherFactory.createInstance that ensures that * we are dealing with a Regexp implementation. * @param classname the name of the class to use. * @return the instance. * @throws BuildException if there is a problem. * @since 1.3 * * @see RegexpMatcherFactory#createInstance(String) */ protected Regexp createRegexpInstance(String classname) throws BuildException { return ClasspathUtils.newInstance(classname, RegexpFactory.class.getClassLoader(), Regexp.class); }
/** * Tries to resolve the given classname into a compiler adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of CompilerAdapter. */ private static CompilerAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : CompilerAdapterFactory.class.getClassLoader(), CompilerAdapter.class); }
/** * Tries to resolve the given classname into a rmic adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of RmicAdapter. */ private static RmicAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : RmicAdapterFactory.class.getClassLoader(), RmicAdapter.class); } }
/** * Tries to resolve the given classname into a native2ascii adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of Native2AsciiAdapter. */ private static Native2AsciiAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : Native2AsciiAdapterFactory.class.getClassLoader(), Native2AsciiAdapter.class); }
/** * Helper method obtaining a fresh instance of the class specified * in the @classname and using the specified classpath. * * @return the fresh instantiated object. */ public Object newInstance() { return ClasspathUtils.newInstance(this.className, getClassLoader()); }
/** * Adds the listeners specified in the command line arguments, * along with the default listener, to the specified project. * * @param project The project to add listeners to. * Must not be <code>null</code>. */ protected void addBuildListeners(final Project project) { // Add the default listener project.addBuildListener(createLogger()); final int count = listeners.size(); for (int i = 0; i < count; i++) { final String className = listeners.elementAt(i); final BuildListener listener = ClasspathUtils.newInstance(className, Main.class.getClassLoader(), BuildListener.class); project.setProjectReference(listener); project.addBuildListener(listener); } }
/** * Creates the InputHandler and adds it to the project. * * @param project the project instance. * * @exception BuildException if a specified InputHandler * implementation could not be loaded. */ private void addInputHandler(final Project project) throws BuildException { InputHandler handler = null; if (inputHandlerClassname == null) { handler = new DefaultInputHandler(); } else { handler = ClasspathUtils.newInstance( inputHandlerClassname, Main.class.getClassLoader(), InputHandler.class); project.setProjectReference(handler); } project.setInputHandler(handler); }
private InputHandler getInputHandler() { if (type != null) { return type.getInputHandler(); } if (refid != null) { try { return (InputHandler) (getProject().getReference(refid)); } catch (final ClassCastException e) { throw new BuildException( refid + " does not denote an InputHandler", e); } } if (classname != null) { return ClasspathUtils.newInstance(classname, createLoader(), InputHandler.class); } throw new BuildException( "Must specify refid, classname or type"); } }
instance = ClasspathUtils.newInstance(classname, loader); } catch (BuildException e) { instance = ClasspathUtils.newInstance(classname, ScriptDef.class.getClassLoader());
} else if (loggerClassname != null) { try { logger = ClasspathUtils.newInstance( loggerClassname, Main.class.getClassLoader(), BuildLogger.class);
Class.forName("javax.mail.internet.MimeMessage"); mailer = ClasspathUtils.newInstance( "org.apache.tools.ant.taskdefs.email.MimeMailer", EmailTask.class.getClassLoader(), Mailer.class); || (AUTO.equals(encoding) && !autoFound)) { try { mailer = ClasspathUtils.newInstance( "org.apache.tools.ant.taskdefs.email.UUMailer", EmailTask.class.getClassLoader(), Mailer.class);
Mailer mailer = null; try { mailer = ClasspathUtils.newInstance( "org.apache.tools.ant.taskdefs.email.MimeMailer", MailLogger.class.getClassLoader(), Mailer.class);
private Task newModelMergerTask() { ClassLoader cl = MergeSourceModelsTask.class.getClassLoader(); Task mergeTask = (Task) ClasspathUtils.newInstance(MODEL_MERGER_TASK, cl); try { setProperty(mergeTask, "project", getProject()); } catch (Exception err) { throw new BuildException("error setting up PostProcessTask", err); } return mergeTask; }
private BuildLogger newLogger(String loggerClassName) { try { return (BuildLogger) ClasspathUtils.newInstance(loggerClassName, Aardvark.class.getClassLoader(), BuildLogger.class); } catch (BuildException e) { logErr("The specified logger class " + loggerClassName + " could not be used because " + e.getMessage()); throw e; } }
/** * Adds the listeners specified in the command line arguments, along with * the default listener, to the specified project. * * @param project The project to add listeners to. Must not be * <code>null</code>. */ @Override protected void addBuildListeners(final Project project) { // Add the default listener project.addBuildListener(createLogger()); final int count = listeners.size(); for (int i = 0; i < count; i++) { final String className = listeners.elementAt(i); final BuildListener listener = ClasspathUtils.newInstance(className, Main.class.getClassLoader(), BuildListener.class); project.setProjectReference(listener); project.addBuildListener(listener); } }
/** * Creates the InputHandler and adds it to the project. * * @param project the project instance. * * @exception BuildException if a specified InputHandler implementation * could not be loaded. */ private void addInputHandler(final Project project) throws BuildException { InputHandler handler; if (inputHandlerClassname == null) { handler = new DefaultInputHandler(); } else { handler = ClasspathUtils.newInstance(inputHandlerClassname, Main.class.getClassLoader(), InputHandler.class); project.setProjectReference(handler); } project.setInputHandler(handler); }
/** * Creates the default build logger for sending build events to the ant log. * * @return the logger instance for this build. */ private BuildLogger createLogger() { BuildLogger logger; if (loggerClassname != null) { try { logger = ClasspathUtils.newInstance(loggerClassname, Main.class.getClassLoader(), BuildLogger.class); } catch (final BuildException e) { printErrorMessage("The specified logger class " + loggerClassname + " could not be used because " + e.getMessage()); throw new RuntimeException(); } } else { logger = new DefaultLogger(); ((DefaultLogger) logger).useColor(useColor); } logger.setMessageOutputLevel(msgOutputLevel); logger.setOutputPrintStream(out); logger.setErrorPrintStream(err); logger.setEmacsMode(emacsMode); return logger; }