geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r659604 - in /geronimo/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-core/src/main/java/org/apache/geronimo/gshell/application/ gshell-core/src/main/java/org/apache/geronimo/gshell/settings/ gshell-model/src/...
Date Fri, 23 May 2008 17:45:10 GMT
Author: jdillon
Date: Fri May 23 10:45:09 2008
New Revision: 659604

URL: http://svn.apache.org/viewvc?rev=659604&view=rev
Log:
Simplify the model a bit wrt collections, accessor methods will never return null
Tidy up locators, which will act like builders

Modified:
    geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/ApplicationLocator.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/DefaultSettingsManager.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/SettingsLocator.java
    geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/application/Application.java
    geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/common/DependencyGroup.java
    geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/layout/GroupNode.java
    geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java
    geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/settings/Settings.java
    geronimo/gshell/trunk/gshell-model/src/test/java/org/apache/geronimo/gshell/model/application/ApplicationMarshallerTest.java
    geronimo/gshell/trunk/gshell-model/src/test/resources/org/apache/geronimo/gshell/model/application/application1.xml

Modified: geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
(original)
+++ geronimo/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
Fri May 23 10:45:09 2008
@@ -254,13 +254,11 @@
             builder.setIo(io);
 
             // Find our settings descriptor
-            SettingsLocator settingsLocator = new SettingsLocator();
-            Settings settings = settingsLocator.locate();
+            Settings settings = new SettingsLocator().locate();
             builder.setSettings(settings);
 
             // Find our application descriptor
-            ApplicationLocator applicationLocator = new ApplicationLocator();
-            Application application = applicationLocator.locate();
+            Application application = new ApplicationLocator().locate();
             builder.setApplication(application);
 
             // Build the shell instance

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/ApplicationLocator.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/ApplicationLocator.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/ApplicationLocator.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/ApplicationLocator.java
Fri May 23 10:45:09 2008
@@ -41,6 +41,10 @@
     // FIXME: Need to make this more robust, allow a file override/hint look in META-INF/gshell,
etc.
     //
 
+    //
+    // TODO: Use builder pattern to add additonal bits to help location
+    //
+    
     public Application locate() throws Exception {
         log.debug("Locating");
 

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/application/DefaultApplicationManager.java
Fri May 23 10:45:09 2008
@@ -150,12 +150,8 @@
         }
 
         // Setup remote repositories
-        List<RemoteRepository> remoteRepositories = application.remoteRepositories();
-
-        if (remoteRepositories != null) {
-            for (RemoteRepository repo : remoteRepositories) {
-                artifactManager.addRemoteRepository(repo.getId(), repo.getLocationUri());
-            }
+        for (RemoteRepository repo : application.remoteRepositories()) {
+            artifactManager.addRemoteRepository(repo.getId(), repo.getLocationUri());
         }
     }
 
@@ -207,7 +203,7 @@
         Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
         List<Dependency> dependencies = application.dependencies(true); // include
groups
 
-        if (dependencies != null && !dependencies.isEmpty()) {
+        if (!dependencies.isEmpty()) {
             log.debug("Application dependencies:");
 
             for (Dependency dep : dependencies) {

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/DefaultSettingsManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/DefaultSettingsManager.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/DefaultSettingsManager.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/DefaultSettingsManager.java
Fri May 23 10:45:09 2008
@@ -74,14 +74,11 @@
     private void configure(final Settings settings) throws Exception {
         assert settings != null;
 
-        List<RemoteRepository> remoteRepositories = settings.remoteRepositories();
-        
-        if (remoteRepositories != null) {
-            for (RemoteRepository repo : remoteRepositories) {
-                artifactManager.addRemoteRepository(repo.getId(), repo.getLocationUri());
-            }
+        // Setup remote repositories
+        for (RemoteRepository repo : settings.remoteRepositories()) {
+            artifactManager.addRemoteRepository(repo.getId(), repo.getLocationUri());
         }
-
+        
         // TODO: apply other artifact related settings (proxy, auth, whatever)
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/SettingsLocator.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/SettingsLocator.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/SettingsLocator.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/settings/SettingsLocator.java
Fri May 23 10:45:09 2008
@@ -39,6 +39,10 @@
     // FIXME: Need to make this more robust, allow a file override/hint look in META-INF/gshell,
user.home, etc.
     //
 
+    //
+    // TODO: Use builder pattern to add additonal bits to help location
+    //
+
     public Settings locate() throws Exception {
         log.debug("Locating");
 

Modified: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/application/Application.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/application/Application.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/application/Application.java
(original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/application/Application.java
Fri May 23 10:45:09 2008
@@ -127,35 +127,31 @@
     }
 
     public List<RemoteRepository> remoteRepositories() {
+        if (remoteRepositories == null) {
+            remoteRepositories = new ArrayList<RemoteRepository>();
+        }
+
         return remoteRepositories;
     }
 
-    //
-    // TODO: Consider making accessors of collection types return non-null always to simplify
usage (avoid needing that null check)
-    //
-
     public void add(final RemoteRepository repository) {
         assert repository != null;
 
-        if (remoteRepositories == null) {
-            remoteRepositories = new ArrayList<RemoteRepository>();
-        }
-
-        remoteRepositories.add(repository);
+        remoteRepositories().add(repository);
     }
 
     public List<DependencyGroup> dependencyGroups() {
+        if (dependencyGroups == null) {
+            dependencyGroups = new ArrayList<DependencyGroup>();
+        }
+
         return dependencyGroups;
     }
 
     public void add(final DependencyGroup group) {
         assert group != null;
 
-        if (dependencyGroups == null) {
-            dependencyGroups = new ArrayList<DependencyGroup>();
-        }
-
-        dependencyGroups.add(group);
+        dependencyGroups().add(group);
     }
 
     public List<Dependency> dependencies() {
@@ -163,28 +159,20 @@
     }
 
     public List<Dependency> dependencies(boolean includeGroups) {
-        if (!includeGroups) {
-            return dependencies;
+        if (dependencies == null) {
+            dependencies = new ArrayList<Dependency>();
         }
 
-        // Don't bother making a new list if we have nothing to populate it with
-        if (dependencies == null && dependencyGroups == null) {
-            return null;
+        if (!includeGroups) {
+            return dependencies;
         }
 
         List<Dependency> list = new ArrayList<Dependency>();
 
-        if (dependencies != null) {
-            list.addAll(dependencies);
-        }
-        
-        if (dependencyGroups != null) {
-            for (DependencyGroup group : dependencyGroups) {
-                List<Dependency> tmp = group.dependencies();
-                if (tmp != null) {
-                    list.addAll(tmp);
-                }
-            }
+        list.addAll(dependencies);
+
+        for (DependencyGroup group : dependencyGroups) {
+            list.addAll(group.dependencies());
         }
 
         return list;
@@ -193,11 +181,7 @@
     public void add(final Dependency dependency) {
         assert dependency != null;
 
-        if (dependencies == null) {
-            dependencies = new ArrayList<Dependency>();
-        }
-
-        dependencies.add(dependency);
+        dependencies().add(dependency);
     }
 
     public Branding getBranding() {

Modified: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/common/DependencyGroup.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/common/DependencyGroup.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/common/DependencyGroup.java
(original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/common/DependencyGroup.java
Fri May 23 10:45:09 2008
@@ -37,41 +37,35 @@
     @XStreamImplicit
     private List<Dependency> dependencies;
 
-    //
-    // TODO: Consider making accessors of collection types return non-null always to simplify
usage (avoid needing that null check)
-    //
-    
     public List<Dependency> dependencies() {
+        if (dependencies == null) {
+            dependencies = new ArrayList<Dependency>();
+        }
+
         return dependencies;
     }
     
     public void add(final Dependency dependency) {
         assert dependency != null;
 
-        if (dependencies == null) {
-            dependencies = new ArrayList<Dependency>();
-        }
-
-        dependencies.add(dependency);
+        dependencies().add(dependency);
     }
 
     public int size() {
-        return dependencies == null ? 0 : dependencies.size();
+        return dependencies().size();
     }
     
     public boolean isEmpty() {
-        return dependencies == null || dependencies.isEmpty();
+        return dependencies().isEmpty();
     }
 
     /**
      * Link children to their parent group when deserializing.
-     *
-     * @return  Model element instance.
      */
     @SuppressWarnings({"UnusedDeclaration"})
     private Object readResolve() {
         if (!isEmpty()) {
-            for (Dependency child : dependencies) {
+            for (Dependency child : dependencies()) {
                 child.setDependencyGroup(this);
             }
         }

Modified: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/layout/GroupNode.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/layout/GroupNode.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/layout/GroupNode.java
(original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/layout/GroupNode.java
Fri May 23 10:45:09 2008
@@ -24,6 +24,7 @@
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.LinkedHashSet;
 
 /**
  * A group of nodes.
@@ -34,7 +35,7 @@
 public class GroupNode
     extends Node
 {
-    protected Set<Node> nodes = new HashSet<Node>();
+    protected Set<Node> nodes;
 
     public GroupNode(final String name) {
         super(name);
@@ -45,13 +46,13 @@
 
         child.setParent(this);
 
-        nodes.add(child);
+        nodes().add(child);
     }
 
     public Node find(final String name) {
         assert name != null;
         
-        for (Node child : nodes) {
+        for (Node child : nodes()) {
             if (name.equals(child.getName())) {
                 return child;
             }
@@ -61,15 +62,19 @@
     }
 
     public Set<Node> nodes() {
-        return Collections.unmodifiableSet(nodes);
+        if (nodes == null) {
+            nodes = new LinkedHashSet<Node>();
+        }
+
+        return nodes;
     }
 
     public int size() {
-        return nodes.size();
+        return nodes().size();
     }
 
     public boolean isEmpty() {
-        return nodes == null || nodes.isEmpty();
+        return nodes().isEmpty();
     }
     
     /**
@@ -78,7 +83,7 @@
     @SuppressWarnings({"UnusedDeclaration"})
     private Object readResolve() {
         if (!isEmpty()) {
-            for (Node child : nodes) {
+            for (Node child : nodes()) {
                 child.setParent(this);
             }
         }

Modified: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java
(original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/plugin/Plugin.java
Fri May 23 10:45:09 2008
@@ -51,7 +51,7 @@
 
     private Properties properties;
     
-    private List<Dependency> dependencies = new ArrayList<Dependency>();
+    private List<Dependency> dependencies;
 
     private List<DependencyGroup> dependencyGroups = new ArrayList<DependencyGroup>();
 
@@ -91,35 +91,47 @@
         this.properties = properties;
     }
 
-    //
-    // TODO: Consider making accessors of collection types return non-null always to simplify
usage (avoid needing that null check)
-    //
-    
-    public List<Dependency> dependencies() {
-        return dependencies;
+    public List<DependencyGroup> dependencyGroups() {
+        if (dependencyGroups == null) {
+            dependencyGroups = new ArrayList<DependencyGroup>();
+        }
+
+        return dependencyGroups;
     }
 
-    public void add(final Dependency dependency) {
-        assert dependency != null;
+    public void add(final DependencyGroup group) {
+        assert group != null;
 
+        dependencyGroups().add(group);
+    }
+
+    public List<Dependency> dependencies() {
+        return dependencies(false);
+    }
+
+    public List<Dependency> dependencies(boolean includeGroups) {
         if (dependencies == null) {
             dependencies = new ArrayList<Dependency>();
         }
 
-        dependencies.add(dependency);
-    }
+        if (!includeGroups) {
+            return dependencies;
+        }
 
-    public List<DependencyGroup> dependencyGroups() {
-        return dependencyGroups;
-    }
+        List<Dependency> list = new ArrayList<Dependency>();
 
-    public void add(final DependencyGroup group) {
-        assert group != null;
+        list.addAll(dependencies);
 
-        if (dependencyGroups == null) {
-            dependencyGroups = new ArrayList<DependencyGroup>();
+        for (DependencyGroup group : dependencyGroups) {
+            list.addAll(group.dependencies());
         }
 
-        dependencyGroups.add(group);
+        return list;
+    }
+
+    public void add(final Dependency dependency) {
+        assert dependency != null;
+
+        dependencies().add(dependency);
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/settings/Settings.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/settings/Settings.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/settings/Settings.java
(original)
+++ geronimo/gshell/trunk/gshell-model/src/main/java/org/apache/geronimo/gshell/model/settings/Settings.java
Fri May 23 10:45:09 2008
@@ -46,10 +46,6 @@
 
     // TODO: Paths
 
-    //
-    // TODO: Consider making accessors of collection types return non-null always to simplify
usage (avoid needing that null check)
-    //
-    
     public Properties getProperties() {
         return properties;
     }
@@ -59,16 +55,16 @@
     }
 
     public List<RemoteRepository> remoteRepositories() {
+        if (remoteRepositories == null) {
+            remoteRepositories = new ArrayList<RemoteRepository>();
+        }
+
         return remoteRepositories;
     }
 
     public void add(final RemoteRepository repository) {
         assert repository != null;
 
-        if (remoteRepositories == null) {
-            remoteRepositories = new ArrayList<RemoteRepository>();
-        }
-
-        remoteRepositories.add(repository);
+        remoteRepositories().add(repository);
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-model/src/test/java/org/apache/geronimo/gshell/model/application/ApplicationMarshallerTest.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/test/java/org/apache/geronimo/gshell/model/application/ApplicationMarshallerTest.java?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/test/java/org/apache/geronimo/gshell/model/application/ApplicationMarshallerTest.java
(original)
+++ geronimo/gshell/trunk/gshell-model/src/test/java/org/apache/geronimo/gshell/model/application/ApplicationMarshallerTest.java
Fri May 23 10:45:09 2008
@@ -86,6 +86,8 @@
 
         Application root = marshaller.unmarshal(input);
 
+        root.dependencies(true);
+        
         System.out.println(root);
     }
 
@@ -94,6 +96,8 @@
 
         Application root = marshaller.unmarshal(url);
 
+        root.dependencies(true);
+
         System.out.println(root);
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-model/src/test/resources/org/apache/geronimo/gshell/model/application/application1.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-model/src/test/resources/org/apache/geronimo/gshell/model/application/application1.xml?rev=659604&r1=659603&r2=659604&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-model/src/test/resources/org/apache/geronimo/gshell/model/application/application1.xml
(original)
+++ geronimo/gshell/trunk/gshell-model/src/test/resources/org/apache/geronimo/gshell/model/application/application1.xml
Fri May 23 10:45:09 2008
@@ -41,6 +41,7 @@
         </remoteRepository>
     </remoteRepositories>
 
+    <!--
     <dependencies>
         <dependency>
             <groupId>a</groupId>
@@ -48,6 +49,7 @@
             <version>c</version>
         </dependency>
     </dependencies>
+    -->
 
     <dependencyGroups>
         <dependencyGroup>



Mime
View raw message