Author: xavier
Date: Tue Nov 13 15:38:55 2007
New Revision: 594716
URL: http://svn.apache.org/viewvc?rev=594716&view=rev
Log:
fix unit test failures due to recent modification on IvyContext handling
(IVY-639)
Modified:
incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntBuildTrigger.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntCallTrigger.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java
incubator/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
Modified:
incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntBuildTrigger.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntBuildTrigger.java?rev=594716&r1=594715&r2=594716&view=diff
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntBuildTrigger.java
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntBuildTrigger.java
Tue Nov 13 15:38:55 2007
@@ -70,7 +70,7 @@
Message.verbose("target build file already built, skipping: "
+ f);
} else {
Ant ant = new Ant();
- Project project = (Project) IvyContext.getContext().peek(
+ Project project = (Project) IvyContext.peekInContextStack(
IvyTask.ANT_PROJECT_CONTEXT_KEY);
if (project == null) {
project = new Project();
Modified:
incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntCallTrigger.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntCallTrigger.java?rev=594716&r1=594715&r2=594716&view=diff
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntCallTrigger.java
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/AntCallTrigger.java
Tue Nov 13 15:38:55 2007
@@ -59,7 +59,7 @@
private String prefix;
public void progress(IvyEvent event) {
- Project project = (Project)
IvyContext.getContext().peek(IvyTask.ANT_PROJECT_CONTEXT_KEY);
+ Project project = (Project)
IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
if (project == null) {
Message.info("ant call trigger can only be used from an ant build.
Ignoring.");
return;
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java?rev=594716&r1=594715&r2=594716&view=diff
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/IvyContext.java Tue
Nov 13 15:38:55 2007
@@ -31,6 +31,7 @@
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.circular.CircularDependencyStrategy;
import org.apache.ivy.util.MessageLogger;
+import org.apache.tools.ant.Project;
/**
* This class represents an execution context of an Ivy action. It contains
several getters to
@@ -101,6 +102,32 @@
getCurrentStack().pop();
}
+
+ /**
+ * Reads the first object from the list saved under given key in the first
context from the
+ * context stack in which this key is defined. If value under key in any
of the contexts form
+ * the stack represents non List object then a RuntimeException is thrown.
+ * <p>
+ * This methods does a similar job to [EMAIL PROTECTED] #peek(String)},
except that it considers the whole
+ * context stack and not only one instance.
+ * </p>
+ *
+ * @param key
+ * context key for the string
+ * @return top object from the list (index 0) of the first context in the
stack containing this
+ * key or null if no key or list empty in all contexts from the
context stack
+ * @see #peek(String)
+ */
+ public static Object peekInContextStack(String key) {
+ Object value = null;
+ Stack contextStack = getCurrentStack();
+ for (int i = contextStack.size() - 1; i >= 0 && value == null; i--) {
+ IvyContext ctx = (IvyContext) contextStack.get(i);
+ value = ctx.peek(key);
+ }
+ return value;
+ }
+
/**
* Returns the current ivy instance.
* <p>
@@ -202,6 +229,7 @@
}
}
}
+
/**
* Removes and returns first object from the list saved under given key in
the context. If value
Modified:
incubator/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=594716&r1=594715&r2=594716&view=diff
==============================================================================
---
incubator/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
(original)
+++
incubator/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
Tue Nov 13 15:38:55 2007
@@ -32,6 +32,7 @@
import org.apache.ivy.Ivy;
import org.apache.ivy.TestHelper;
+import org.apache.ivy.core.IvyContext;
import org.apache.ivy.core.cache.ArtifactOrigin;
import org.apache.ivy.core.cache.CacheManager;
import org.apache.ivy.core.module.descriptor.Artifact;
@@ -94,34 +95,39 @@
public void testResolveWithRetainingArtifactName() throws Exception {
-
settings.setCacheArtifactPattern(ivy.substitute("[module]/[originalname].[ext]"));
- ResolveReport report = ivy.resolve(new
File("test/repositories/2/mod15.2/ivy-1.1.xml")
- .toURL(), getResolveOptions(new String[] {"default"}));
- assertNotNull(report);
-
- ArtifactDownloadReport[] dReports =
report.getConfigurationReport("default")
- .getDownloadReports(ModuleRevisionId.newInstance("org15",
"mod15.1", "1.1"));
- assertNotNull(dReports);
- assertEquals("number of downloaded artifacts not correct", 1,
dReports.length);
+ ivy.pushContext();
+ try {
+
settings.setCacheArtifactPattern(ivy.substitute("[module]/[originalname].[ext]"));
+ ResolveReport report = ivy.resolve(new
File("test/repositories/2/mod15.2/ivy-1.1.xml")
+ .toURL(), getResolveOptions(new String[] {"default"}));
+ assertNotNull(report);
+
+ ArtifactDownloadReport[] dReports =
report.getConfigurationReport("default")
+ .getDownloadReports(ModuleRevisionId.newInstance("org15",
"mod15.1", "1.1"));
+ assertNotNull(dReports);
+ assertEquals("number of downloaded artifacts not correct", 1,
dReports.length);
- Artifact artifact = dReports[0].getArtifact();
- assertNotNull(artifact);
+ Artifact artifact = dReports[0].getArtifact();
+ assertNotNull(artifact);
- String cachePath = cacheManager.getArchivePathInCache(artifact);
- assertTrue("artifact name has not been retained: " + cachePath,
cachePath
+ String cachePath = cacheManager.getArchivePathInCache(artifact);
+ assertTrue("artifact name has not been retained: " + cachePath,
cachePath
.endsWith("library.jar"));
- dReports = report.getConfigurationReport("default").getDownloadReports(
- ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
- assertNotNull(dReports);
- assertEquals("number of downloaded artifacts not correct", 1,
dReports.length);
+ dReports =
report.getConfigurationReport("default").getDownloadReports(
+ ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
+ assertNotNull(dReports);
+ assertEquals("number of downloaded artifacts not correct", 1,
dReports.length);
- artifact = dReports[0].getArtifact();
- assertNotNull(artifact);
+ artifact = dReports[0].getArtifact();
+ assertNotNull(artifact);
- cachePath = cacheManager.getArchivePathInCache(artifact);
- assertTrue("artifact name has not been retained: " + cachePath,
cachePath
+ cachePath = cacheManager.getArchivePathInCache(artifact);
+ assertTrue("artifact name has not been retained: " + cachePath,
cachePath
.endsWith("mod14.1-1.1.jar"));
+ } finally {
+ ivy.popContext();
+ }
}
public void testArtifactOrigin() throws Exception {