Package org.apache.tools.ant

Examples of org.apache.tools.ant.Project


      return;
    } else if ((destDir == DEFAULT_DESTDIR) || !destDir.canWrite()) {
      String s = "unable to copy resources to destDir: " + destDir;
      throw new BuildException(s);
    }
    final Project project = getProject();
    if (copyInjars) { // XXXX remove as unused since 1.1.1
      if (null != inpath) {
        log("copyInjars does not support inpath.\n", Project.MSG_WARN);
      }
      String taskName = getTaskName() + " - unzip";
View Full Code Here


    if (((null == tmpOutjar) || !tmpOutjar.canRead())
        || (!copyInjars && (null == sourceRootCopyFilter) && (null == inpathDirCopyFilter))) {
      return;
    }
    Zip zip = new Zip();
    Project project = getProject();
    zip.setProject(project);
    zip.setTaskName(getTaskName() + " - zip");
    zip.setDestFile(outjar);
    ZipFileSet zipfileset = new ZipFileSet();
    zipfileset.setProject(project);
View Full Code Here

     *
     *@exception  IOException  Description of Exception
     */
    @Override
    public void setUp() throws Exception {
        Project project = new Project();

        IndexTask task = new IndexTask();
        FileSet fs = new FileSet();
        fs.setProject(project);
        fs.setDir(new File(docsDir));
View Full Code Here

                // If this class does not exist, then we are not running Java 1.4
            }
            if (lessThan14)
                Thread.currentThread().setContextClassLoader(Launcher.class.getClassLoader());

            Project project = new Project();

            // Set the project's class loader
            project.setCoreLoader(Launcher.class.getClassLoader());

            // Initialize the project. Note that we don't invoke the
            // Project.init() method directly as this will cause all of
            // the myriad of Task subclasses to load which is a big
            // performance hit. Instead, we load only the
            // Launcher.SUPPORTED_ANT_TASKS and Launcher.SUPPORTED_ANT_TYPES
            // into the project that the Launcher supports.
            for (int i = 0; i < Launcher.SUPPORTED_ANT_TASKS.length; i++) {
                // The even numbered elements should be the task name
                String taskName = (String)Launcher.SUPPORTED_ANT_TASKS[i];
                // The odd numbered elements should be the task class
                Class taskClass = (Class)Launcher.SUPPORTED_ANT_TASKS[++i];
                project.addTaskDefinition(taskName, taskClass);
            }
            for (int i = 0; i < Launcher.SUPPORTED_ANT_TYPES.length; i++) {
                // The even numbered elements should be the type name
                String typeName = (String)Launcher.SUPPORTED_ANT_TYPES[i];
                // The odd numbered elements should be the type class
                Class typeClass = (Class)Launcher.SUPPORTED_ANT_TYPES[++i];
                project.addDataTypeDefinition(typeName, typeClass);
            }

            // Add all system properties as project properties
            project.setSystemProperties();

            // Parse the arguments
            int currentArg = 0;

            // Set default XML file
            File launchFile = new File(Launcher.getBootstrapDir(), Launcher.DEFAULT_XML_FILE_NAME);

            // Get standard launcher arguments
            for ( ; currentArg < args.length; currentArg++) {
                // If we find a "-" argument or an argument without a
                // leading "-", there are no more standard launcher arguments
                if ("-".equals(args[currentArg])) {
                    currentArg++;
                    break;
                } else if (args[currentArg].length() > 0 && !"-".equals(args[currentArg].substring(0, 1))) {
                    break;
                } else if ("-help".equals(args[currentArg])) {
                    throw new IllegalArgumentException();
                } else if ("-launchfile".equals(args[currentArg])) {
                    if (currentArg + 1 < args.length){
                        String fileArg = args[++currentArg];
                        launchFile = new File(fileArg);
                        if (!launchFile.isAbsolute())
                            launchFile = new File(Launcher.getBootstrapDir(), fileArg);
                    } else {
                        throw new IllegalArgumentException(args[currentArg] + " " + Launcher.getLocalizedString("missing.arg"));
                    }
                } else if ("-executablename".equals(args[currentArg])) {
                    if (currentArg + 1 < args.length)
                        System.setProperty(ChildMain.EXECUTABLE_PROP_NAME, args[++currentArg]);
                    else
                        throw new IllegalArgumentException(args[currentArg] + " " + Launcher.getLocalizedString("missing.arg"));
                } else if ("-verbose".equals(args[currentArg])) {
                    Launcher.setVerbose(true);
                } else {
                    throw new IllegalArgumentException(args[currentArg] + " " + Launcher.getLocalizedString("invalid.arg"));
                }
            }

            // Get target
            String target = null;
            if (currentArg < args.length)
                target = args[currentArg++];
            else
                throw new IllegalArgumentException(Launcher.getLocalizedString("missing.target"));

            // Get user properties
            for ( ; currentArg < args.length; currentArg++) {
                // If we don't find any more "-" or "-D" arguments, there are no
                // more user properties
                if ("-".equals(args[currentArg])) {
                    currentArg++;
                    break;
                } else if (args[currentArg].length() <= 2 || !"-D".equals(args[currentArg].substring(0, 2))) {
                    break;
                }
                int delimiter = args[currentArg].indexOf('=', 2);
                String key = null;
                String value = null;
                if (delimiter >= 2) {
                    key = args[currentArg].substring(2, delimiter);
                    value = args[currentArg].substring(delimiter + 1);
                } else {
                    // Unfortunately, MS-DOS batch scripts will split an
                    // "-Dname=value" argument into "-Dname" and "value"
                    // arguments. So, we need to assume that the next
                    // argument is the property value unless it appears
                    // to be a different type of argument.
                    key = args[currentArg].substring(2);
                    if (currentArg + 1 < args.length &&
                        !"-D".equals(args[currentArg + 1].substring(0, 2)))
                    {
                        value = args[++currentArg];
                    } else {
                        value = "";
                    }
                }
                project.setUserProperty(key, value);
            }

            // Treat all remaining arguments as application arguments
            String[] appArgs = new String[args.length - currentArg];
            for (int i = 0; i < appArgs.length; i++) {
                appArgs[i] = args[i + currentArg];
                project.setUserProperty(LaunchTask.ARG_PROP_NAME + Integer.toString(i), appArgs[i]);
            }

            // Set standard Ant user properties
            project.setUserProperty("ant.version", Main.getAntVersion());
            project.setUserProperty("ant.file", launchFile.getCanonicalPath());
            project.setUserProperty("ant.java.version", System.getProperty("java.specification.version"));

            // Set the buildfile
            ProjectHelper.configureProject(project, launchFile);

            // Check that the target exists
            if (!project.getTargets().containsKey(target))
                throw new IllegalArgumentException(target + " " + Launcher.getLocalizedString("invalid.target"));

            // Execute the target
            try {
                runtime.addShutdownHook(shutdownHook);
            } catch (NoSuchMethodError nsme) {
                // Early JVMs do not support this method
            }
            project.executeTarget(target);

        } catch (Throwable t) {
            // Log any errors
            returnValue = 1;
            String message = t.getMessage();
View Full Code Here

        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 ).
             *
             * 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());
        }
View Full Code Here

            String name = null;
            String depends = "";
            String extensionPoint = null;
            OnMissingExtensionPoint extensionPointMissing = null;

            Project project = context.getProject();
            Target target = "target".equals(tag)
                ? new Target() : new ExtensionPoint();
            target.setProject(project);
            target.setLocation(new Location(context.getLocator()));
            context.addTarget(target);

            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("name")) {
                    name = value;
                    if ("".equals(name)) {
                        throw new BuildException("name attribute must " + "not be empty");
                    }
                } else if (key.equals("depends")) {
                    depends = value;
                } else if (key.equals("if")) {
                    target.setIf(value);
                } else if (key.equals("unless")) {
                    target.setUnless(value);
                } else if (key.equals("id")) {
                    if (value != null && !value.equals("")) {
                        context.getProject().addReference(value, target);
                    }
                } else if (key.equals("description")) {
                    target.setDescription(value);
                } else if (key.equals("extensionOf")) {
                    extensionPoint = value;
                } else if (key.equals("onMissingExtensionPoint")) {
                    try {
                        extensionPointMissing = OnMissingExtensionPoint.valueOf(value);
                    } catch (IllegalArgumentException e) {
                        throw new BuildException("Invalid onMissingExtensionPoint " + value);
                    }
                } else {
                    throw new SAXParseException("Unexpected attribute \"" + key + "\"", context
                                                .getLocator());
                }
            }

            if (name == null) {
                throw new SAXParseException("target element appears without a name attribute",
                                            context.getLocator());
            }

            String prefix = null;
            boolean isInIncludeMode =
                context.isIgnoringProjectTag() && isInIncludeMode();
            String sep = getCurrentPrefixSeparator();

            if (isInIncludeMode) {
                prefix = getTargetPrefix(context);
                if (prefix == null) {
                    throw new BuildException("can't include build file "
                                             + context.getBuildFileURL()
                                             + ", no as attribute has been given"
                                             + " and the project tag doesn't"
                                             + " specify a name attribute");
                }
                name = prefix + sep + name;
            }

            // Check if this target is in the current build file
            if (context.getCurrentTargets().get(name) != null) {
                throw new BuildException("Duplicate target '" + name + "'",
                                         target.getLocation());
            }
            Hashtable<String, Target> projectTargets = project.getTargets();
            boolean   usedTarget = false;
            // If the name has not already been defined define it
            if (projectTargets.containsKey(name)) {
                project.log("Already defined in main or a previous import, ignore " + name,
                            Project.MSG_VERBOSE);
            } else {
                target.setName(name);
                context.getCurrentTargets().put(name, target);
                project.addOrReplaceTarget(name, target);
                usedTarget = true;
            }

            if (depends.length() > 0) {
                if (!isInIncludeMode) {
                    target.setDepends(depends);
                } else {
                    for (String string : Target.parseDepends(depends, name, "depends")) {
                        target.addDependency(prefix + sep + string);
                   }
                }
            }
            if (!isInIncludeMode && context.isIgnoringProjectTag()
                && (prefix = getTargetPrefix(context)) != null) {
                // In an imported file (and not completely
                // ignoring the project tag or having a preconfigured prefix)
                String newName = prefix + sep + name;
                Target newTarget = target;
                if (usedTarget) {
                    newTarget = "target".equals(tag)
                            ? new Target(target) : new ExtensionPoint(target);
                }
                newTarget.setName(newName);
                context.getCurrentTargets().put(newName, newTarget);
                project.addOrReplaceTarget(newName, newTarget);
            }
            if (extensionPointMissing != null && extensionPoint == null) {
                throw new BuildException("onMissingExtensionPoint attribute cannot " +
                                         "be specified unless extensionOf is specified",
                                         target.getLocation());
View Full Code Here

    }

    private Project project;

    public void setUp() {
        project = new Project();
        project.setBasedir(".");
        project.setProperty("build.sysclasspath", "ignore");
    }
View Full Code Here

    protected Project getProject() {
       
        if( project!=null ) return project;
       
        // Initializing project
        project = new Project();
        logger = new JasperAntLogger();
        logger.setOutputPrintStream(System.out);
        logger.setErrorPrintStream(System.err);
        logger.setMessageOutputLevel(Project.MSG_INFO);
        project.addBuildListener( logger);
View Full Code Here

    public PatternSetTest(String name) {
        super(name);
    }

    public void setUp() {
        project = new Project();
        project.setBasedir(".");
    }
View Full Code Here

    public AbstractFileSetTest(String name) {
        super(name);
    }

    public void setUp() {
        project = new Project();
        project.setBasedir(".");
    }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.Project

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.