incubator-easyant-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1389112 - in /incubator/easyant/core/trunk/src/main/java/org/apache/easyant: core/EasyAntEngine.java core/ant/ProjectUtils.java tasks/SubModule.java
Date Sun, 23 Sep 2012 18:42:47 GMT
Author: jlboudart
Date: Sun Sep 23 18:42:47 2012
New Revision: 1389112

URL: http://svn.apache.org/viewvc?rev=1389112&view=rev
Log:
Fix issues with submodules logger, and extensionPoints

Modified:
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
    incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java?rev=1389112&r1=1389111&r2=1389112&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
Sun Sep 23 18:42:47 2012
@@ -27,7 +27,6 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Enumeration;
-import java.util.Hashtable;
 import java.util.Properties;
 
 import org.apache.easyant.core.ant.ProjectUtils;
@@ -48,15 +47,12 @@ import org.apache.tools.ant.BuildListene
 import org.apache.tools.ant.BuildLogger;
 import org.apache.tools.ant.DemuxInputStream;
 import org.apache.tools.ant.DemuxOutputStream;
-import org.apache.tools.ant.ExtensionPoint;
 import org.apache.tools.ant.Location;
 import org.apache.tools.ant.MagicNames;
 import org.apache.tools.ant.Main;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
-import org.apache.tools.ant.ProjectHelper.OnMissingExtensionPoint;
 import org.apache.tools.ant.PropertyHelper;
-import org.apache.tools.ant.Target;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.input.DefaultInputHandler;
 import org.apache.tools.ant.input.InputHandler;
@@ -459,7 +455,7 @@ public class EasyAntEngine {
         }
 
         // FIXME:resolve extensionOf attributes this should be exposed by Apache Ant
-        injectTargetIntoExtensionPoint(project, helper);
+        ProjectUtils.injectTargetIntoExtensionPoint(project, helper);
     }
 
     private void locateBuildModuleAndBuildFile(Project project) {
@@ -536,32 +532,6 @@ public class EasyAntEngine {
 
     }
 
-    private void injectTargetIntoExtensionPoint(Project project, ProjectHelper helper) {
-        for (Object extensionInfos : helper.getExtensionStack()) {
-            String[] extensionInfo = (String[]) extensionInfos;
-            String tgName = extensionInfo[0];
-            String name = extensionInfo[1];
-            OnMissingExtensionPoint missingBehaviour = OnMissingExtensionPoint.FAIL;
-            Hashtable<?, ?> projectTargets = project.getTargets();
-            if (!projectTargets.containsKey(tgName)) {
-                String message = "can't add target " + name + " to extension-point " + tgName
-                        + " because the extension-point is unknown.";
-                if (missingBehaviour == OnMissingExtensionPoint.FAIL) {
-                    throw new BuildException(message);
-                } else if (missingBehaviour == OnMissingExtensionPoint.WARN) {
-                    Target target = (Target) projectTargets.get(name);
-                    project.log(target, "Warning: " + message, Project.MSG_WARN);
-                }
-            } else {
-                Target t = (Target) projectTargets.get(tgName);
-                if (!(t instanceof ExtensionPoint)) {
-                    throw new BuildException("referenced target " + tgName + " is not an
extension-point");
-                }
-                t.addDependency(name);
-            }
-        }
-    }
-
     /**
      * this method run the build process
      * 

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java?rev=1389112&r1=1389111&r2=1389112&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
(original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/core/ant/ProjectUtils.java
Sun Sep 23 18:42:47 2012
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.PrintStream;
 import java.lang.reflect.Field;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -28,8 +29,11 @@ import org.apache.tools.ant.BuildExcepti
 import org.apache.tools.ant.BuildListener;
 import org.apache.tools.ant.BuildLogger;
 import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.ExtensionPoint;
 import org.apache.tools.ant.Location;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.ProjectHelper.OnMissingExtensionPoint;
 import org.apache.tools.ant.Target;
 
 /**
@@ -75,44 +79,31 @@ public class ProjectUtils {
         PrintStream err = System.err;
         int currentLogLevel = Project.MSG_INFO;
         project.log("removing current logger", Project.MSG_DEBUG);
-        // since BuildLogger doesn't offer any way to get the out / err print
+        // since DefaultLogger doesn't offer any way to get the out / err print
         // streams we should use reflection
         // TODO: we should find a better way to do this
         for (Iterator<?> i = project.getBuildListeners().iterator(); i.hasNext();)
{
             BuildListener l = (BuildListener) i.next();
-            if (l instanceof BuildLogger) {
-                Field fields[];
-                // case of classes extending DefaultLogger
-                if (l.getClass().getSuperclass() == DefaultLogger.class) {
-                    fields = l.getClass().getSuperclass().getDeclaredFields();
-                } else {
-                    fields = l.getClass().getDeclaredFields();
-                }
-
-                for (int j = 0; j < fields.length; j++) {
-                    try {
-                        if (fields[j].getType().equals(PrintStream.class) && fields[j].getName().equals("out"))
{
-                            fields[j].setAccessible(true);
-                            out = (PrintStream) fields[j].get(l);
-                            fields[j].setAccessible(false);
-                        }
-                        if (fields[j].getType().equals(PrintStream.class) && fields[j].getName().equals("err"))
{
-                            fields[j].setAccessible(true);
-                            err = (PrintStream) fields[j].get(l);
-                            fields[j].setAccessible(false);
-                        }
-                        if (fields[j].getName().equals("msgOutputLevel")) {
-                            fields[j].setAccessible(true);
-                            currentLogLevel = (Integer) fields[j].get(l);
-                            fields[j].setAccessible(false);
-                        }
-                    } catch (IllegalAccessException ex) {
-                        throw new BuildException(ex);
-                    }
+            if (l instanceof DefaultLogger) {
+                try {
+                    Field fieldOut = DefaultLogger.class.getDeclaredField("out");
+                    fieldOut.setAccessible(true);
+                    out = (PrintStream) fieldOut.get(l);
+                    Field fieldErr = DefaultLogger.class.getDeclaredField("err");
+                    fieldErr.setAccessible(true);
+                    err = (PrintStream) fieldErr.get(l);
+                    Field fieldMsgLevel = DefaultLogger.class.getDeclaredField("msgOutputLevel");
+                    fieldMsgLevel.setAccessible(true);
+                    currentLogLevel = (Integer) fieldMsgLevel.get(l);
+                } catch (IllegalAccessException ex) {
+                    throw new BuildException(ex);
+                } catch (SecurityException e) {
+                    throw new BuildException(e);
+                } catch (NoSuchFieldException e) {
+                    throw new BuildException(e);
                 }
+                project.removeBuildListener(l);
             }
-            project.removeBuildListener(l);
-
         }
         project.log("Initializing new logger " + logger.getClass().getName(), Project.MSG_DEBUG);
         logger.setOutputPrintStream(out);
@@ -169,4 +160,30 @@ public class ProjectUtils {
         return ret;
     }
 
+    public static void injectTargetIntoExtensionPoint(Project project, ProjectHelper helper)
{
+        for (Object extensionInfos : helper.getExtensionStack()) {
+            String[] extensionInfo = (String[]) extensionInfos;
+            String tgName = extensionInfo[0];
+            String name = extensionInfo[1];
+            OnMissingExtensionPoint missingBehaviour = OnMissingExtensionPoint.FAIL;
+            Hashtable<?, ?> projectTargets = project.getTargets();
+            if (!projectTargets.containsKey(tgName)) {
+                String message = "can't add target " + name + " to extension-point " + tgName
+                        + " because the extension-point is unknown.";
+                if (missingBehaviour == OnMissingExtensionPoint.FAIL) {
+                    throw new BuildException(message);
+                } else if (missingBehaviour == OnMissingExtensionPoint.WARN) {
+                    Target target = (Target) projectTargets.get(name);
+                    project.log(target, "Warning: " + message, Project.MSG_WARN);
+                }
+            } else {
+                Target t = (Target) projectTargets.get(tgName);
+                if (!(t instanceof ExtensionPoint)) {
+                    throw new BuildException("referenced target " + tgName + " is not an
extension-point");
+                }
+                t.addDependency(name);
+            }
+        }
+    }
+
 }

Modified: incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java
URL: http://svn.apache.org/viewvc/incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java?rev=1389112&r1=1389111&r2=1389112&view=diff
==============================================================================
--- incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java (original)
+++ incubator/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SubModule.java Sun
Sep 23 18:42:47 2012
@@ -191,10 +191,12 @@ public class SubModule extends Task {
             lm.setTaskName(EasyAntConstants.EASYANT_TASK_NAME);
             lm.setProject(subModule);
             lm.setOwningTarget(ProjectUtils.createTopLevelTarget());
-            lm.setLocation(new Location(mainscript.toString()));
+            lm.setLocation(new Location(mainscript.getAbsolutePath()));
             lm.setUseBuildRepository(useBuildRepository);
             lm.execute();
 
+            ProjectUtils.injectTargetIntoExtensionPoint(subModule, helper);
+
             filterTargets(subModule);
             printExecutingTargetMsg(subModule);
 
@@ -250,6 +252,8 @@ public class SubModule extends Task {
 
     private Project configureSubModule(File file, File directory) {
         Project subModule = getProject().createSubProject();
+
+        subModule.setJavaVersionProperty();
         for (int i = 0; i < getProject().getBuildListeners().size(); i++) {
             BuildListener buildListener = (BuildListener) getProject().getBuildListeners().elementAt(i);
             subModule.addBuildListener(buildListener);
@@ -555,8 +559,8 @@ public class SubModule extends Task {
      *             if a reference does not have a refid.
      */
     private void addReferences(Project subproject) throws BuildException {
-        Hashtable<String, Object> thisReferences = (Hashtable<String, Object>)
getProject().getReferences().clone();
-        Hashtable<String, Object> newReferences = (Hashtable<String, Object>)
subproject.getReferences();
+        Hashtable<?, ?> thisReferences = (Hashtable<?, ?>) getProject().getReferences().clone();
+        Hashtable<?, ?> newReferences = subproject.getReferences();
         Enumeration<?> e;
         for (Ant.Reference ref : references) {
             String refid = ref.getRefId();



Mime
View raw message