KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antmod > conf > AntmodPropertiesTask


1 package org.antmod.conf;
2
3 import java.io.File JavaDoc;
4 import java.util.Date JavaDoc;
5 import java.util.Enumeration JavaDoc;
6
7 import org.antmod.buildplugin.BuildPluginFactory;
8 import org.antmod.descriptor.DescriptorStoreFactory;
9 import org.antmod.descriptor.ReleaseDescriptor;
10 import org.antmod.util.Os;
11 import org.apache.tools.ant.BuildException;
12 import org.apache.tools.ant.Task;
13
14 /**
15  * Allows access to the antmod properties from within Ant build files,
16  * by loading the antmod configuration properties into the current Ant project
17  * as normal properties.
18  *
19  * @author Klaas Waslander
20  */

21 public final class AntmodPropertiesTask extends Task {
22
23     /**
24      * Executes the antmod properties task, loading the antmod configuration
25      * as properties into the current Ant project.
26      */

27     public void execute() throws BuildException {
28         try {
29             // first load regular antmod configuration
30
AntmodProperties.loadIntoAnt(getProject());
31             
32             // set the plugin home directory properties
33
BuildPluginFactory.loadPluginHomesIntoAnt(getProject());
34
35             // check if current release is known, and if so load its properties LAST, to override everything else
36
String JavaDoc currentReleaseName = getProject().getProperty("antmod.release");
37             if (currentReleaseName != null) {
38                 ReleaseDescriptor currentRelease = DescriptorStoreFactory.getConfiguredDescriptorStore().getReleaseDescriptor(currentReleaseName);
39                 if (currentRelease != null) {
40                     // load properties of release into ant project, overriding existing ones (hehe)
41
Enumeration JavaDoc propNames = currentRelease.getProperties().propertyNames();
42                     String JavaDoc propName;
43                     while (propNames.hasMoreElements()) {
44                         propName = (String JavaDoc)propNames.nextElement();
45                         getProject().setProperty(propName, getProject().replaceProperties(currentRelease.getProperties().getProperty(propName)));
46                     }
47                     
48                     // register release-specific ant properties, such as mainmodule...
49
currentRelease.registerReleaseAttributesInto(getProject());
50                 }
51             }
52         } catch (IllegalArgumentException JavaDoc iae) {
53             throw new BuildException(iae);
54         }
55         
56         // make the timestamp of antmod.jar available as a property
57
getProject().setProperty("antmod.version.timestamp", new Date JavaDoc(new File JavaDoc(Os.getEnvironmentVariable("ANTMOD_HOME"), "lib" + File.separator + "antmod.jar").lastModified()).toString());
58     }
59
60 }
61
Popular Tags