ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r821836 - /ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java
Date Mon, 05 Oct 2009 15:21:42 GMT
Author: bodewig
Date: Mon Oct  5 15:21:41 2009
New Revision: 821836

URL: http://svn.apache.org/viewvc?rev=821836&view=rev
Log:
better deal with null projects

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java?rev=821836&r1=821835&r2=821836&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java Mon Oct  5 15:21:41 2009
@@ -378,15 +378,22 @@
      * @return the project's property helper.
      */
     public static synchronized PropertyHelper getPropertyHelper(Project project) {
-        PropertyHelper helper
-                = (PropertyHelper) project.getReference(MagicNames.REFID_PROPERTY_HELPER);
+        PropertyHelper helper = null;
+        if (project != null) {
+            helper = (PropertyHelper) project.getReference(MagicNames
+                                                           .REFID_PROPERTY_HELPER);
+        }
         if (helper != null) {
             return helper;
         }
+
         helper = new PropertyHelper();
         helper.setProject(project);
 
-        project.addReference(MagicNames.REFID_PROPERTY_HELPER, helper);
+        if (project != null) {
+            project.addReference(MagicNames.REFID_PROPERTY_HELPER, helper);
+        }
+
         return helper;
     }
 
@@ -461,7 +468,7 @@
             }
         }
         // Experimental/Testing, will be removed
-        if (name.startsWith("toString:")) {
+        if (project != null && name.startsWith("toString:")) {
             name = name.substring("toString:".length());
             Object v = project.getReference(name);
             return (v == null) ? null : v.toString();
@@ -619,18 +626,19 @@
         synchronized (this) {
             // user (CLI) properties take precedence
             if (userProperties.containsKey(name)) {
-                if (verbose) {
-                    project.log("Override ignored for user property \"" + name + "\"",
-                            Project.MSG_VERBOSE);
+                if (project != null && verbose) {
+                    project.log("Override ignored for user property \""
+                                + name + "\"", Project.MSG_VERBOSE);
                 }
                 return false;
             }
-            if (verbose) {
+            if (project != null && verbose) {
                 if (properties.containsKey(name)) {
-                    project.log("Overriding previous definition of property \"" + name +
"\"",
-                            Project.MSG_VERBOSE);
+                    project.log("Overriding previous definition of property \""
+                                + name + "\"", Project.MSG_VERBOSE);
                 }
-                project.log("Setting project property: " + name + " -> " + value, Project.MSG_DEBUG);
+                project.log("Setting project property: " + name + " -> "
+                            + value, Project.MSG_DEBUG);
             }
             if (name != null && value != null) {
                 properties.put(name, value);
@@ -679,11 +687,15 @@
             }
         }
         synchronized (this) {
-            if (properties.containsKey(name)) {
-                project.log("Override ignored for property \"" + name + "\"", Project.MSG_VERBOSE);
+            if (project != null && properties.containsKey(name)) {
+                project.log("Override ignored for property \"" + name
+                            + "\"", Project.MSG_VERBOSE);
                 return;
             }
-            project.log("Setting project property: " + name + " -> " + value, Project.MSG_DEBUG);
+            if (project != null) {
+                project.log("Setting project property: " + name
+                            + " -> " + value, Project.MSG_DEBUG);
+            }
             if (name != null && value != null) {
                 properties.put(name, value);
             }
@@ -720,7 +732,10 @@
      *              Must not be <code>null</code>.
      */
     public void setUserProperty(String name, Object value) {
-        project.log("Setting ro project property: " + name + " -> " + value, Project.MSG_DEBUG);
+        if (project != null) {
+            project.log("Setting ro project property: "
+                        + name + " -> " + value, Project.MSG_DEBUG);
+        }
         synchronized (this) {
             userProperties.put(name, value);
             properties.put(name, value);
@@ -761,7 +776,10 @@
      *              Must not be <code>null</code>.
      */
     public void setInheritedProperty(String name, Object value) {
-        project.log("Setting ro project property: " + name + " -> " + value, Project.MSG_DEBUG);
+        if (project != null) {
+            project.log("Setting ro project property: " + name + " -> "
+                        + value, Project.MSG_DEBUG);
+        }
 
         synchronized (this) {
             inheritedProperties.put(name, value);



Mime
View raw message