ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r600418 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/ src/java/org/apache/ivy/util/ test/java/org/apache/ivy/plugins/circular/
Date Mon, 03 Dec 2007 01:57:39 GMT
Author: xavier
Date: Sun Dec  2 17:57:37 2007
New Revision: 600418

URL: http://svn.apache.org/viewvc?rev=600418&view=rev
Log:
fix settings initialization issue, related to the changes made for IVY-639. Default settings
were loaded when no there was no Ivy in context, which was actually happening pretty often
in the ant tasks since the Ivy instance was only attached when calling an Ivy method. Now
all IvyTasks push an IvyContext with the configured Ivy instance attached, and pop it at the
end.
I've also reviewed the default message logger use, now MessageLoggerEngine actually use it
as currently defined (and not as defined at logger engine init) at the time it needs it. This
allow easier configuration of the default logger with the Message.setDefaultLogger() method,
which actually propagates to all logger engines on which a default logger has not been specificied.

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConvertPom.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyExtractFromSources.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/Message.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/MessageLoggerEngine.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java Sun Dec  2 17:57:37
2007
@@ -109,8 +109,8 @@
         if (defaultInstanceObj != null
                 && defaultInstanceObj.getClass().getClassLoader() != IvyAntSettings.class
                         .getClassLoader()) {
-            Message.warn("ivy.instance reference an ivy:settings defined in an other classloader.
 "
-                     + "An new default one will be used in this project.");
+            project.log("ivy.instance reference an ivy:settings defined in an other classloader.
 "
+                     + "An new default one will be used in this project.", Project.MSG_WARN);
             defaultInstanceObj = null;
         }
         if (defaultInstanceObj != null && !(defaultInstanceObj instanceof IvyAntSettings))
{
@@ -119,8 +119,8 @@
                     + " an not an IvyAntSettings.  Please don't use this reference id ()");
         }
         if (defaultInstanceObj == null) {
-            Message.info("No ivy:settings found for the default reference 'ivy.instance'.
 " 
-                    + "A default instance will be used");
+            project.log("No ivy:settings found for the default reference 'ivy.instance'.
 " 
+                    + "A default instance will be used", Project.MSG_INFO);
             IvyAntSettings defaultInstance = new IvyAntSettings();
             defaultInstance.setProject(project);
             defaultInstance.registerAsDefault();
@@ -269,7 +269,7 @@
         URL url = IvySettings.getDefaultPropertiesURL();
         // this is copy of loadURL code from ant Property task (not available in 1.5.1)
         Properties props = new Properties();
-        Message.verbose("Loading " + url);
+        verbose("Loading " + url);
         try {
             InputStream is = url.openStream();
             try {
@@ -294,7 +294,7 @@
         String settingsFileName = variableContainer.getVariable("ivy.conf.file");
         if (settingsFileName != null 
                 && !settingsFileName.equals(variableContainer.getVariable("ivy.settings.file")))
{
-            Message.deprecated("'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead");
+            info("DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead");
         } else {
             settingsFileName = variableContainer.getVariable("ivy.settings.file");
         }
@@ -306,22 +306,34 @@
         };
         for (int i = 0; i < settingsLocations.length; i++) {
             file = settingsLocations[i];
-            Message.verbose("searching settings file: trying " + file);
+            verbose("searching settings file: trying " + file);
             if (file.exists()) {
                 break;
             }
         }
         if (!file.exists()) {
             if (Boolean.valueOf(getProject().getProperty("ivy.14.compatible")).booleanValue())
{
-                Message.info("no settings file found, using Ivy 1.4 default...");
+                info("no settings file found, using Ivy 1.4 default...");
                 file = null;
                 url = IvySettings.getDefault14SettingsURL();
             } else {
-                Message.info("no settings file found, using default...");
+                info("no settings file found, using default...");
                 file = null;
                 url = IvySettings.getDefaultSettingsURL();
             }
         }
+    }
+
+    private void verbose(String msg) {
+        log(msg, Project.MSG_VERBOSE);
+    }
+
+    private void info(String msg) {
+        log(msg, Project.MSG_INFO);
+    }
+
+    private void warn(String msg) {
+        log(msg, Project.MSG_WARN);
     }
 
     private void configureURLHandler() {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java Sun Dec  2 17:57:37 2007
@@ -21,9 +21,11 @@
 import java.net.MalformedURLException;
 import java.util.Properties;
 
+import org.apache.ivy.Ivy;
 import org.apache.ivy.ant.IvyAntSettings.Credentials;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.Property;
 
 /**
@@ -31,11 +33,11 @@
  * 
  * @deprecated Use the IvyAntSettings instead.
  */
-public class IvyConfigure extends IvyTask {
+public class IvyConfigure extends Task {
 
     private IvyAntSettings antSettings = new IvyAntSettings();
 
-    public void doExecute() throws BuildException {
+    public void execute() throws BuildException {
         log("ivy:configure is deprecated, please use the data type ivy:settings instead",
             Project.MSG_WARN);
         // ivyConfigure used to export properties in the ant script.
@@ -90,6 +92,10 @@
 
     public void setUsername(String userName) {
         antSettings.setUsername(userName);
+    }
+
+    public Ivy getIvyInstance() {
+        return antSettings.getConfiguredIvyInstance();
     }
 
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConvertPom.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConvertPom.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConvertPom.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConvertPom.java Sun Dec  2 17:57:37
2007
@@ -61,7 +61,7 @@
                 throw new BuildException("destination ivy file is required for convertpom
task");
             }
             ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(
-                new IvySettings(), pomFile.toURL(), false);
+                getSettings(), pomFile.toURL(), false);
             PomModuleDescriptorParser.getInstance().toIvyFile(pomFile.toURL().openStream(),
                 new URLResource(pomFile.toURL()), getIvyFile(), md);
         } catch (MalformedURLException e) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyExtractFromSources.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyExtractFromSources.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyExtractFromSources.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyExtractFromSources.java Sun Dec  2 17:57:37
2007
@@ -35,6 +35,7 @@
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
 import org.apache.tools.ant.filters.LineContainsRegExp;
 import org.apache.tools.ant.filters.TokenFilter;
 import org.apache.tools.ant.taskdefs.Concat;
@@ -45,7 +46,7 @@
 /**
  * Extracts imports from a set of java sources and generate corresponding ivy file
  */
-public class IvyExtractFromSources extends IvyTask {
+public class IvyExtractFromSources extends Task {
     public static class Ignore {
         private String packageName;
 
@@ -126,7 +127,7 @@
         concat.addFileset(fileSet);
     }
 
-    public void doExecute() throws BuildException {
+    public void execute() throws BuildException {
         configureConcat();
         Writer out = new StringWriter();
         concat.setWriter(out);

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java Sun Dec  2 17:57:37 2007
@@ -92,7 +92,7 @@
                 throw new BuildException("destination pom file is required for makepom task");
             }
             ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(
-                new IvySettings(), ivyFile.toURL(), false);
+                getSettings(), ivyFile.toURL(), false);
             PomModuleDescriptorWriter.write(md, 
                 mappings.isEmpty() 
                     ? PomModuleDescriptorWriter.DEFAULT_MAPPING

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java Sun Dec  2 17:57:37 2007
@@ -249,7 +249,9 @@
      * Called when task starts its execution.
      */
     protected void prepareTask() {
-        // push current project on the stack in context
+        // push current project and Ivy on the stack in context
+        IvyContext.pushNewCopyContext();
+        IvyContext.getContext().setIvy(getIvyInstance());
         IvyContext.getContext().push(ANT_PROJECT_CONTEXT_KEY, getProject());
     }
 
@@ -261,6 +263,7 @@
         if (!IvyContext.getContext().pop(ANT_PROJECT_CONTEXT_KEY, getProject())) {
             Message.error("ANT project poped from stack not equals current !. Ignoring");
         }
+        IvyContext.popContext();
     }
 
     /**

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java Sun Dec  2 17:57:37 2007
@@ -31,6 +31,7 @@
 import org.apache.ivy.core.resolve.ResolveData;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.circular.CircularDependencyStrategy;
+import org.apache.ivy.util.Message;
 import org.apache.ivy.util.MessageLogger;
 
 /**
@@ -346,7 +347,20 @@
 
 
     public MessageLogger getMessageLogger() {
-        return getIvy().getLoggerEngine();
+        // calling getIvy() instead of peekIvy() is not possible here: it will initialize
a default
+        // Ivy instance, with default settings, but settings themselves may log messages
and lead to
+        // a call to this method. So we use the current Ivy instance if any, or the default
Ivy
+        // instance, or the default MessageLogger.
+        Ivy ivy = peekIvy();
+        if (ivy == null) {
+            if (defaultIvy == null) {
+                return Message.getDefaultLogger();
+            } else {
+                return defaultIvy.getLoggerEngine();
+            }
+        } else {
+            return ivy.getLoggerEngine();
+        }
     }
 
     public EventManager getEventManager() {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/Message.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/Message.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/Message.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/Message.java Sun Dec  2 17:57:37 2007
@@ -54,11 +54,20 @@
 
     private static MessageLogger defaultLogger = new DefaultMessageLogger(Message.MSG_INFO);
 
+    /**
+     * Returns the current default logger.
+     * @return the current default logger; is never <code>null</code>.
+     */
     public static MessageLogger getDefaultLogger() {
         return defaultLogger;
     }
 
+    /**
+     * Change the default logger used when no other logger is currently configured
+     * @param logger the new default logger, must not be <code>null</code>
+     */
     public static void setDefaultLogger(MessageLogger logger) {
+        Checks.checkNotNull(logger, "logger");
         defaultLogger = logger;
     }
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/MessageLoggerEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/MessageLoggerEngine.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/MessageLoggerEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/MessageLoggerEngine.java Sun Dec  2 17:57:37
2007
@@ -36,7 +36,7 @@
 public class MessageLoggerEngine implements MessageLogger {
     private final Stack/*<MessageLogger>*/ loggerStack = new Stack();
     
-    private MessageLogger defaultLogger = Message.getDefaultLogger();
+    private MessageLogger defaultLogger = null;
 
     private List problems = new ArrayList();
 
@@ -87,11 +87,17 @@
      */
     private MessageLogger peekLogger() {
         if (loggerStack.isEmpty()) {
-            return defaultLogger;
+            return getDefaultLogger();
         }
         return (MessageLogger) loggerStack.peek();
     }
 
+    private MessageLogger getDefaultLogger() {
+        // we don't store the logger returned by Message.getDefaultLogger() to always stay
in sync
+        // as long as our default logger has not been set explicitly with setDefaultLogger()
+        return defaultLogger == null ? Message.getDefaultLogger() : defaultLogger;
+    }
+
     // consolidated methods
     public void warn(String msg) {
         peekLogger().warn(msg);
@@ -123,7 +129,7 @@
     }
     
     public void clearProblems() {
-        defaultLogger.clearProblems();
+        getDefaultLogger().clearProblems();
         for (Iterator iter = loggerStack.iterator(); iter.hasNext();) {
             MessageLogger l = (MessageLogger) iter.next();
             l.clearProblems();
@@ -134,7 +140,7 @@
     }
 
     public void setShowProgress(boolean progress) {
-        defaultLogger.setShowProgress(progress);
+        getDefaultLogger().setShowProgress(progress);
         // updates all loggers in the stack
         for (Iterator iter = loggerStack.iterator(); iter.hasNext();) {
             MessageLogger l = (MessageLogger) iter.next();
@@ -144,7 +150,7 @@
     
     public boolean isShowProgress() {
         // testing the default logger is enough, all loggers should be in sync
-        return defaultLogger.isShowProgress();
+        return getDefaultLogger().isShowProgress();
     }
 
     // delegation methods

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
Sun Dec  2 17:57:37 2007
@@ -20,7 +20,7 @@
 import junit.framework.TestCase;
 
 import org.apache.ivy.TestHelper;
-import org.apache.ivy.core.IvyContext;
+import org.apache.ivy.util.Message;
 import org.apache.ivy.util.MockMessageLogger;
 
 public class IgnoreCircularDependencyStrategyTest extends TestCase {
@@ -31,7 +31,7 @@
         strategy = IgnoreCircularDependencyStrategy.getInstance();
         
         mockMessageImpl = new MockMessageLogger();
-        IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
+        Message.setDefaultLogger(mockMessageImpl);
     }
     
     public void testLog() throws Exception {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java?rev=600418&r1=600417&r2=600418&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
Sun Dec  2 17:57:37 2007
@@ -27,6 +27,7 @@
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.core.sort.SortEngine;
+import org.apache.ivy.util.Message;
 import org.apache.ivy.util.MockMessageLogger;
 
 public class WarnCircularDependencyStrategyTest extends TestCase {
@@ -41,7 +42,7 @@
 
     private void resetLogger() {
         mockMessageImpl = new MockMessageLogger();
-        IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
+        Message.setDefaultLogger(mockMessageImpl);
     }
     
     public void testLog() throws Exception {



Mime
View raw message