Author: xavier
Date: Thu Nov 29 08:39:15 2007
New Revision: 599508
URL: http://svn.apache.org/viewvc?rev=599508&view=rev
Log:
IMPROVEMENT: Only display unique circular dependencies during Resolve (IVY-653)
Added:
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/AbstractLogCircularDependencyStrategy.java
(with props)
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
(with props)
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
(with props)
Modified:
incubator/ivy/core/trunk/CHANGES.txt
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java
incubator/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java
incubator/ivy/core/trunk/test/java/org/apache/ivy/util/MockMessageLogger.java
Modified: incubator/ivy/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?rev=599508&r1=599507&r2=599508&view=diff
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Thu Nov 29 08:39:15 2007
@@ -73,6 +73,7 @@
- FIX: ivy:settings and ivy:retrieve with explicit id causes unwarranted
DEPRECATED warning (thanks to Jacob Grydholt Jensen)
+- IMPROVEMENT: Only display unique circular dependencies during Resolve
(IVY-653)
- IMPROVEMENT: Adding option 'cp', which makes it possible for main to be
loaded from file (IVY-543) (thanks to Tjeerd Verhagen)
- IMPROVEMENT: BasicURLHandler should use method=head for getURLInfo (IVY-611)
(thanks to Jim Bonanno)
- IMPROVEMENT: artifactproperty should not overwrite the existing properties
(IVY-587)
Added:
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/AbstractLogCircularDependencyStrategy.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/AbstractLogCircularDependencyStrategy.java?rev=599508&view=auto
==============================================================================
---
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/AbstractLogCircularDependencyStrategy.java
(added)
+++
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/AbstractLogCircularDependencyStrategy.java
Thu Nov 29 08:39:15 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.circular;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.apache.ivy.core.IvyContext;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.resolve.ResolveData;
+
+public abstract class AbstractLogCircularDependencyStrategy
+ extends AbstractCircularDependencyStrategy {
+
+ protected AbstractLogCircularDependencyStrategy(String name) {
+ super(name);
+ }
+
+ private Collection/*<String>*/ circularDependencies = new HashSet();
+
+ public void handleCircularDependency(ModuleRevisionId[] mrids) {
+ String circularDependencyId = getCircularDependencyId(mrids);
+ if (!circularDependencies.contains(circularDependencyId)) {
+ circularDependencies.add(circularDependencyId);
+ logCircularDependency(mrids);
+ }
+ }
+
+ protected abstract void logCircularDependency(ModuleRevisionId[] mrids);
+
+ protected String getCircularDependencyId(ModuleRevisionId[] mrids) {
+ String contextPrefix = "";
+ ResolveData data = IvyContext.getContext().getResolveData();
+ if (data != null) {
+ contextPrefix = data.getOptions().getResolveId() + " ";
+ }
+ return contextPrefix + Arrays.asList(mrids);
+ }
+
+}
Propchange:
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/AbstractLogCircularDependencyStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java?rev=599508&r1=599507&r2=599508&view=diff
==============================================================================
---
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java
(original)
+++
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java
Thu Nov 29 08:39:15 2007
@@ -20,21 +20,23 @@
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.util.Message;
-public final class IgnoreCircularDependencyStrategy extends
AbstractCircularDependencyStrategy {
+public final class IgnoreCircularDependencyStrategy extends
AbstractLogCircularDependencyStrategy {
private static final CircularDependencyStrategy INSTANCE =
- new IgnoreCircularDependencyStrategy();
+ new IgnoreCircularDependencyStrategy();
public static CircularDependencyStrategy getInstance() {
return INSTANCE;
}
private IgnoreCircularDependencyStrategy() {
- super("ignore");
+ super("warn");
}
- public void handleCircularDependency(ModuleRevisionId[] mrids) {
- Message.verbose("circular dependency found: "
- + CircularDependencyHelper.formatMessage(mrids));
+ protected void logCircularDependency(ModuleRevisionId[] mrids) {
+ Message.verbose("circular dependency found: "
+ + CircularDependencyHelper.formatMessage(mrids));
}
+
}
+
Modified:
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java?rev=599508&r1=599507&r2=599508&view=diff
==============================================================================
---
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java
(original)
+++
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java
Thu Nov 29 08:39:15 2007
@@ -20,7 +20,7 @@
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.util.Message;
-public final class WarnCircularDependencyStrategy extends
AbstractCircularDependencyStrategy {
+public final class WarnCircularDependencyStrategy extends
AbstractLogCircularDependencyStrategy {
private static final CircularDependencyStrategy INSTANCE = new
WarnCircularDependencyStrategy();
@@ -32,7 +32,9 @@
super("warn");
}
- public void handleCircularDependency(ModuleRevisionId[] mrids) {
- Message.warn("circular dependency found: " +
CircularDependencyHelper.formatMessage(mrids));
+ protected void logCircularDependency(ModuleRevisionId[] mrids) {
+ Message.warn("circular dependency found: "
+ + CircularDependencyHelper.formatMessage(mrids));
}
+
}
Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java?rev=599508&r1=599507&r2=599508&view=diff
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java (original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java Thu Nov
29 08:39:15 2007
@@ -76,4 +76,17 @@
}
return c;
}
+
+ /**
+ * Returns an array of [EMAIL PROTECTED] ModuleRevisionId} corresponding
to the given comma separated list of
+ * their text representation.
+ *
+ * @param mrids
+ * the text representation of the [EMAIL PROTECTED]
ModuleRevisionId}
+ * @return an array of [EMAIL PROTECTED] ModuleRevisionId}
+ */
+ public static ModuleRevisionId[] parseMridsToArray(String mrids) {
+ Collection parsedMrids = parseMrids(mrids);
+ return (ModuleRevisionId[]) parsedMrids.toArray(new
ModuleRevisionId[parsedMrids.size()]);
+ }
}
Added:
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java?rev=599508&view=auto
==============================================================================
---
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
(added)
+++
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
Thu Nov 29 08:39:15 2007
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.circular;
+
+import junit.framework.TestCase;
+
+import org.apache.ivy.TestHelper;
+import org.apache.ivy.core.IvyContext;
+import org.apache.ivy.util.MockMessageLogger;
+
+public class IgnoreCircularDependencyStrategyTest extends TestCase {
+ private CircularDependencyStrategy strategy;
+ private MockMessageLogger mockMessageImpl;
+
+ protected void setUp() throws Exception {
+ strategy = IgnoreCircularDependencyStrategy.getInstance();
+
+ mockMessageImpl = new MockMessageLogger();
+
IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
+ }
+
+ public void testLog() throws Exception {
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.0,
#B;1.0"));
+
+ mockMessageImpl.assertLogVerboseContains("circular dependency found:
#A;1.0->#B;1.0");
+ }
+
+ public void testRemoveDuplicates() throws Exception {
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
+ // should only log the circular dependency once
+ assertEquals(1, mockMessageImpl.getLogs().size());
+ }
+}
Propchange:
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java?rev=599508&view=auto
==============================================================================
---
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
(added)
+++
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
Thu Nov 29 08:39:15 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.plugins.circular;
+
+import junit.framework.TestCase;
+
+import org.apache.ivy.TestHelper;
+import org.apache.ivy.core.IvyContext;
+import org.apache.ivy.core.event.EventManager;
+import org.apache.ivy.core.resolve.ResolveData;
+import org.apache.ivy.core.resolve.ResolveEngine;
+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.MockMessageLogger;
+
+public class WarnCircularDependencyStrategyTest extends TestCase {
+ private CircularDependencyStrategy strategy;
+ private MockMessageLogger mockMessageImpl;
+
+ protected void setUp() throws Exception {
+ strategy = WarnCircularDependencyStrategy.getInstance();
+
+ resetLogger();
+ }
+
+ private void resetLogger() {
+ mockMessageImpl = new MockMessageLogger();
+
IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
+ }
+
+ public void testLog() throws Exception {
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.0,
#B;1.0"));
+
+ mockMessageImpl.assertLogWarningContains("circular dependency found:
#A;1.0->#B;1.0");
+ }
+
+ public void testRemoveDuplicates() throws Exception {
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
+ // should only log the circular dependency once
+ assertEquals(1, mockMessageImpl.getLogs().size());
+ }
+
+ public void testRemoveDuplicates2() throws Exception {
+ setResolveContext("1");
+ resetLogger();
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
+ // should only log the circular dependency once
+ assertEquals(1, mockMessageImpl.getLogs().size());
+
+ setResolveContext("2");
+ resetLogger();
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+ // should log the message
+ assertEquals(1, mockMessageImpl.getLogs().size());
+
+
strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1,
#B;1.0"));
+
+ // should not log the message again
+ assertEquals(1, mockMessageImpl.getLogs().size());
+ }
+
+ private void setResolveContext(String resolveId) {
+ IvySettings settings = new IvySettings();
+ IvyContext.getContext().setResolveData(
+ new ResolveData(
+ new ResolveEngine(settings, new EventManager(), new
SortEngine(settings)),
+ new ResolveOptions().setResolveId(resolveId)));
+ }
+}
Propchange:
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/ivy/core/trunk/test/java/org/apache/ivy/util/MockMessageLogger.java
URL:
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/util/MockMessageLogger.java?rev=599508&r1=599507&r2=599508&view=diff
==============================================================================
---
incubator/ivy/core/trunk/test/java/org/apache/ivy/util/MockMessageLogger.java
(original)
+++
incubator/ivy/core/trunk/test/java/org/apache/ivy/util/MockMessageLogger.java
Thu Nov 29 08:39:15 2007
@@ -84,6 +84,10 @@
}
+
+ public void assertLogVerboseContains(String message) {
+ assertLogContains(Message.MSG_VERBOSE + " " + message);
+ }
public void assertLogInfoContains(String message) {
assertLogContains(Message.MSG_INFO + " " + message);
}