You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by gs...@apache.org on 2007/06/20 19:53:16 UTC

svn commit: r549214 - in /incubator/ivy/core/trunk: src/java/org/apache/ivy/ src/java/org/apache/ivy/core/sort/ test/java/org/apache/ivy/core/sort/

Author: gscokart
Date: Wed Jun 20 12:53:16 2007
New Revision: 549214

URL: http://svn.apache.org/viewvc?view=rev&rev=549214
Log:
refactor to remove settings dependency (second aproach)

Added:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java   (with props)
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngineSettings.java   (with props)
Modified:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngine.java
    incubator/ivy/core/trunk/test/java/org/apache/ivy/core/sort/SortTest.java

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java?view=diff&rev=549214&r1=549213&r2=549214
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java Wed Jun 20 12:53:16 2007
@@ -51,7 +51,6 @@
 import org.apache.ivy.core.search.SearchEngine;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.core.sort.NonMatchingVersionReporter;
-import org.apache.ivy.core.sort.SilentNonMatchingVersionReporter;
 import org.apache.ivy.core.sort.SortEngine;
 import org.apache.ivy.plugins.matcher.PatternMatcher;
 import org.apache.ivy.plugins.repository.TransferEvent;
@@ -159,8 +158,7 @@
             eventManager = new EventManager();
         }
         if (sortEngine == null) {
-            sortEngine = new SortEngine();
-            //Settings element are injected in the getSortEngine method. 
+            sortEngine = new SortEngine(settings);
         }
         if (searchEngine == null) {
             searchEngine = new SearchEngine(settings);
@@ -565,8 +563,6 @@
     }
 
     public SortEngine getSortEngine() {
-        sortEngine.setCircularDependencyStrategy(settings.getCircularDependencyStrategy());
-        sortEngine.setVersionMatcher(settings.getVersionMatcher());
         return sortEngine;
     }
 

Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java?view=auto&rev=549214
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java Wed Jun 20 12:53:16 2007
@@ -0,0 +1,46 @@
+/*
+ *  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.core.sort;
+
+import org.apache.ivy.plugins.circular.CircularDependencyStrategy;
+import org.apache.ivy.plugins.version.VersionMatcher;
+
+public class SimpleSortEngineSettings implements SortEngineSettings {
+
+    private CircularDependencyStrategy circularStrategy;
+    
+    private VersionMatcher versionMatcher;
+    
+    public CircularDependencyStrategy getCircularDependencyStrategy() {
+        return circularStrategy;
+    }
+
+    public VersionMatcher getVersionMatcher() {
+        return versionMatcher;
+    }
+
+    
+    public void setCircularDependencyStrategy(CircularDependencyStrategy strategy) {
+        circularStrategy = strategy;
+    }
+
+    public void setVersionMatcher(VersionMatcher matcher) {
+        versionMatcher = matcher;
+    }
+
+}

Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SimpleSortEngineSettings.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngine.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngine.java?view=diff&rev=549214&r1=549213&r2=549214
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngine.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngine.java Wed Jun 20 12:53:16 2007
@@ -32,22 +32,16 @@
 
 public class SortEngine {
 
-    private CircularDependencyStrategy circularStrategy;
+    private SortEngineSettings settings;
 
-    private VersionMatcher versionMatcher;
-
-    public SortEngine() {
+    public SortEngine(SortEngineSettings settings) {
+        if (settings == null) {
+            throw new NullPointerException("SortEngine.settings can not be null");
+        }
+        this.settings = settings;
     }
 
     
-    public void setCircularDependencyStrategy(CircularDependencyStrategy circularStrategy) {
-        this.circularStrategy = circularStrategy;
-    }
-
-    public void setVersionMatcher(VersionMatcher versionMatcher) {
-        this.versionMatcher = versionMatcher;
-    }
-
 
     public List sortNodes(Collection nodes) throws CircularDependencyException {
         /*
@@ -74,8 +68,9 @@
         }
         List list = sortModuleDescriptors(dependenciesMap.keySet(),
             new SilentNonMatchingVersionReporter());
-        List ret = new ArrayList((int) (list.size() * 1.3 + nulls.size())); // attempt to adjust the
-        // size to avoid too much list resizing
+        final double adjustFactor = 1.3;
+        List ret = new ArrayList((int) (list.size() * adjustFactor + nulls.size()));
+        // attempt to adjust the size to avoid too much list resizing
         for (int i = 0; i < list.size(); i++) {
             ModuleDescriptor md = (ModuleDescriptor) list.get(i);
             List n = (List) dependenciesMap.get(md);
@@ -103,9 +98,22 @@
     public List sortModuleDescriptors(Collection moduleDescriptors,
             NonMatchingVersionReporter nonMatchingVersionReporter)
             throws CircularDependencyException {
+        if (nonMatchingVersionReporter == null) {
+            throw new NullPointerException("nonMatchingVersionReporter can not be null");
+        }
         ModuleDescriptorSorter sorter = new ModuleDescriptorSorter(moduleDescriptors,
-                versionMatcher, nonMatchingVersionReporter, circularStrategy);
+                getVersionMatcher(), nonMatchingVersionReporter, getCircularStrategy());
         return sorter.sortModuleDescriptors();
+    }
+
+
+
+    protected CircularDependencyStrategy getCircularStrategy() {
+        return settings.getCircularDependencyStrategy();
+    }
+
+    protected VersionMatcher getVersionMatcher() {
+        return settings.getVersionMatcher();
     }
 
 }

Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngineSettings.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngineSettings.java?view=auto&rev=549214
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngineSettings.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngineSettings.java Wed Jun 20 12:53:16 2007
@@ -0,0 +1,31 @@
+/*
+ *  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.core.sort;
+
+import org.apache.ivy.plugins.circular.CircularDependencyStrategy;
+import org.apache.ivy.plugins.version.VersionMatcher;
+
+/**
+ * The settings/collaborators used by the SortEngine.
+ */
+public interface SortEngineSettings {
+
+    public CircularDependencyStrategy getCircularDependencyStrategy();
+    
+    public VersionMatcher getVersionMatcher();
+}

Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/sort/SortEngineSettings.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/core/sort/SortTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/core/sort/SortTest.java?view=diff&rev=549214&r1=549213&r2=549214
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/core/sort/SortTest.java (original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/core/sort/SortTest.java Wed Jun 20 12:53:16 2007
@@ -49,6 +49,8 @@
     private DefaultModuleDescriptor md4;
 
     private SortEngine sortEngine;
+    
+    private SimpleSortEngineSettings settings; 
 
     private SilentNonMatchingVersionReporter nonMatchReporter;
 
@@ -65,9 +67,11 @@
         md3 = createModuleDescriptorToSort("md3", "rev3");
         md4 = createModuleDescriptorToSort("md4", "rev4");
 
-        sortEngine = new SortEngine();
-        sortEngine.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance());
-        sortEngine.setVersionMatcher(new ExactVersionMatcher());
+        settings = new SimpleSortEngineSettings();
+        settings.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance());
+        settings.setVersionMatcher(new ExactVersionMatcher());
+        
+        sortEngine = new SortEngine(settings);
         
         nonMatchReporter = new SilentNonMatchingVersionReporter();
     }
@@ -148,7 +152,8 @@
                     nbOfCall);
                 String assertMsg = "incorrect cicular dependency invocation" 
                         + CircularDependencyHelper.formatMessage(mrids);
-                assertEquals(assertMsg, 3 , mrids.length);
+                final int expectedLength = 3;
+                assertEquals(assertMsg, expectedLength , mrids.length);
                 if (mrids[0].equals(md2.getModuleRevisionId())) {
                     assertEquals(assertMsg , md3.getModuleRevisionId() , mrids[1]);
                     assertEquals(assertMsg , md2.getModuleRevisionId() , mrids[2]);
@@ -165,7 +170,7 @@
             }
         }
         CircularDependencyReporterMock circularDepReportMock = new CircularDependencyReporterMock();
-        sortEngine.setCircularDependencyStrategy(circularDepReportMock);
+        settings.setCircularDependencyStrategy(circularDepReportMock);
 
         List toSort = Arrays.asList(new ModuleDescriptor[] {md4, md3, md2, md1});
         sortEngine.sortModuleDescriptors(toSort, nonMatchReporter);
@@ -183,7 +188,7 @@
         addDependency(md3, "md2", "latest.integration");
         addDependency(md4, "md3", "latest.integration");
 
-        sortEngine.setVersionMatcher(new LatestVersionMatcher());
+        settings.setVersionMatcher(new LatestVersionMatcher());
         
         DefaultModuleDescriptor[][] expectedOrder = new DefaultModuleDescriptor[][] {{md1, md2,
                 md3, md4}};