Re: Update of properties (patches)

Dan Tihelka <[email protected]>
Newsgroups gmane.comp.java.cruise-control.user
Message-ID <[email protected]>
Hallo Jeffrey,

I'm sending the next set of patches (while XMLConfigManager.java.patch1 
includes the part sent in the previous patch ...). I did not included 
FileResolver class, as it has not been changed since.

Still, the patches do not change the function of CruiseControl (tetst are 
passed up to the fail I sent earlier ...), and they should be well formatted 
('checktyle' passed :-))

What do you think about them? May I continue, or are there issues I missed? If 
it is correct, would it be possible to commit them into SVN, to be easier for 
me to create patches in future?

There is not much work to do - just to implement the passing of FileResolver 
into plugins (see ProjectXMLHelper.configurePlugin()), and to change 
DefaultPropertiesPlugin to accept and use the resolver. And maybe some tests, 
but I'm not sure, if they are necessary in this case ... Just tell.

And yes - what to you think about the reflection vs. interface idea? Which way 
should I continue?


Best regards,
Dan T.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

_______________________________________________
Cruisecontrol-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cruisecontrol-user
CruiseControlConfig.java.patch1 (text/x-diff, 3.6 KB)
Index: main/src/net/sourceforge/cruisecontrol/CruiseControlConfig.java
===================================================================
--- main/src/net/sourceforge/cruisecontrol/CruiseControlConfig.java	(revision 4347)
+++ main/src/net/sourceforge/cruisecontrol/CruiseControlConfig.java	(working copy)
@@ -48,6 +48,7 @@
 import java.util.TreeMap;
 
 import net.sourceforge.cruisecontrol.config.DashboardConfigurationPlugin;
+import net.sourceforge.cruisecontrol.config.FileResolver;
 import net.sourceforge.cruisecontrol.config.IncludeProjectsPlugin;
 import net.sourceforge.cruisecontrol.config.PluginPlugin;
 import net.sourceforge.cruisecontrol.config.PropertiesPlugin;
@@ -95,6 +96,7 @@
     private final Map<String, PluginRegistry> projectPluginRegistries = new TreeMap<String, PluginRegistry>();
 
     private final XmlResolver xmlResolver;
+    private final FileResolver fileResolver;
 
     private SystemPlugin system;
 
@@ -114,20 +116,22 @@
     private final Set<String> customPropertiesPlugins = new HashSet<String>();
 
     public CruiseControlConfig(Element ccElement) throws CruiseControlException {
-        this(ccElement, null, null);
+        this(ccElement, null, null, null);
     }
 
     public CruiseControlConfig(Element ccElement, CruiseControlController controller) throws CruiseControlException {
-        this(ccElement, null, controller);
+        this(ccElement, null, null, controller);
     }
 
-    public CruiseControlConfig(Element ccElement, XmlResolver xmlResolver) throws CruiseControlException {
-        this(ccElement, xmlResolver, null);
+    public CruiseControlConfig(Element ccElement, XmlResolver xmlResolver, FileResolver fileResolver) 
+            throws CruiseControlException {
+        this(ccElement, xmlResolver, fileResolver, null);
     }
 
-    public CruiseControlConfig(Element ccElement, XmlResolver xmlResolver, CruiseControlController controller)
-            throws CruiseControlException {
+    public CruiseControlConfig(Element ccElement, XmlResolver xmlResolver, FileResolver fileResolver, 
+            CruiseControlController controller) throws CruiseControlException {
         this.xmlResolver = xmlResolver;
+        this.fileResolver = fileResolver;
         this.controller = controller;
         parse(ccElement);
     }
@@ -180,6 +184,7 @@
     private CruiseControlConfig(Element includedElement, CruiseControlConfig parent) throws CruiseControlException {
         this.controller = parent.controller;
         xmlResolver = parent.xmlResolver;
+        fileResolver = parent.fileResolver;
         rootPlugins = PluginRegistry.createRegistry(parent.rootPlugins);
         rootProperties = new HashMap<String, String>(parent.rootProperties);
         templatePluginProperties = new HashMap<String, List>(parent.templatePluginProperties);
@@ -283,7 +288,7 @@
     }
 
     private void handleCustomRootProperty(final Element childElement) throws CruiseControlException {
-        ProjectXMLHelper.registerCustomProperty(rootProperties, childElement,
+        ProjectXMLHelper.registerCustomProperty(rootProperties, childElement, fileResolver,
                 FAIL_UPON_MISSING_PROPERTY, PluginRegistry.createRegistry(rootPlugins));
     }
 
@@ -413,7 +418,7 @@
         projectElement.removeChildren("plugin");
 
         LOG.debug("**************** configuring project " + projectName + " *******************");
-        ProjectHelper projectHelper = new ProjectXMLHelper(thisProperties, projectPlugins, controller);
+        ProjectHelper projectHelper = new ProjectXMLHelper(thisProperties, projectPlugins, fileResolver, controller);
 
         final ProjectInterface project;
         try {
CruiseControlConfigIncludeTest.java.patch1 (text/x-diff, 5.5 KB)
Index: main/test/net/sourceforge/cruisecontrol/CruiseControlConfigIncludeTest.java
===================================================================
--- main/test/net/sourceforge/cruisecontrol/CruiseControlConfigIncludeTest.java	(revision 4347)
+++ main/test/net/sourceforge/cruisecontrol/CruiseControlConfigIncludeTest.java	(working copy)
@@ -5,6 +5,7 @@
 
 
 import junit.framework.TestCase;
+import net.sourceforge.cruisecontrol.config.FileResolver;
 import net.sourceforge.cruisecontrol.config.XmlResolver;
 import net.sourceforge.cruisecontrol.util.Util;
 
@@ -14,7 +15,8 @@
 
     private Element rootElement;
     private Element includeElement;
-    private XmlResolver resolver;
+    private XmlResolver xmlResolver;
+    private FileResolver fileResolver;
 
     protected void setUp() throws Exception {
         StringBuffer configText = new StringBuffer(200);
@@ -32,17 +34,17 @@
         includeText.append("</cruisecontrol>");
         includeElement = elementFromString(includeText.toString());
 
-        resolver = new IncludeXmlResolver(includeElement);
+        xmlResolver = new IncludeXmlResolver(includeElement);
     }
 
     protected void tearDown() throws Exception {
         rootElement = null;
         includeElement = null;
-        resolver = null;
+        xmlResolver = null;
     }
 
     public void testShouldLoadIncludedProjects() throws Exception {
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolver, null);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, xmlResolver, null);
         assertEquals(2, config.getProjectNames().size());
         assertIsFooProject(config.getProject("in.root"));
         assertIsFooProject(config.getProject("in.include"));
@@ -59,9 +61,9 @@
         Element[] elements = new Element[2];
         elements[0] = includeWithNestedInclude;
         elements[1] = includeElement;
-        resolver = new IncludeXmlResolver(elements);
+        xmlResolver = new IncludeXmlResolver(elements);
         
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolver, null);        
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, xmlResolver, null);        
         assertEquals(3, config.getProjectNames().size());
         assertIsFooProject(config.getProject("in.root"));
         assertIsFooProject(config.getProject("in.first.include"));
@@ -80,7 +82,7 @@
         barElement.setAttribute("name", "bar");
         includeElement.addContent(barElement);
         
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolver, null);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, xmlResolver, null);
         assertEquals(3, config.getProjectNames().size());
         assertIsFooProject(config.getProject("bar"));
     }
@@ -95,7 +97,7 @@
         project.setAttribute("name", "${baz}");
         includeElement.addContent(project);
         
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolver);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, xmlResolver, fileResolver);
         assertEquals(3, config.getProjectNames().size());
         assertIsFooProject(config.getProject("goo"));
     }
@@ -104,7 +106,7 @@
         Element unknownPlugin = new Element("unknown.plugin.error");
         includeElement.addContent(unknownPlugin);
         
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolver);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, xmlResolver, fileResolver);
         assertEquals(1, config.getProjectNames().size());
         assertIsFooProject(config.getProject("in.root"));
     }
@@ -116,7 +118,7 @@
             }
         };
         
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolverHitsError);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, resolverHitsError, fileResolver);
         assertEquals(1, config.getProjectNames().size());
         assertIsFooProject(config.getProject("in.root"));
     }
@@ -147,7 +149,7 @@
         includeTagElement.setAttribute("file", "include${filenameswitch}.xml");
         rootElement.addContent(includeTagElement);
 
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, includeFOOXmlResolver);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, includeFOOXmlResolver, fileResolver);
         assertEquals(2, config.getProjectNames().size());
         assertIsFooProject(config.getProject("in.root"));
         assertIsFooProject(config.getProject("in.include.withproperty"));
@@ -165,7 +167,7 @@
         includeTagElement.setAttribute("file", "include${filenameswitch}.xml");
         rootElement.addContent(includeTagElement);
 
-        CruiseControlConfig config = new CruiseControlConfig(rootElement, includeUnknownXmlResolver);
+        CruiseControlConfig config = new CruiseControlConfig(rootElement, includeUnknownXmlResolver, fileResolver);
         assertEquals(1, config.getProjectNames().size());
         assertIsFooProject(config.getProject("in.root"));
     }
@@ -201,4 +203,15 @@
         }
     }
 
+    private class EmptyFileResolver implements FileResolver {
+
+        EmptyFileResolver(Element element) {
+        }
+
+        public InputStream getInputStream(String path)
+            throws CruiseControlException {
+            // FIXME add correct implementation, if required!
+            throw new CruiseControlException("Method not implemented yet! Fix it!");
+        }
+    }
 }
XMLConfigManager.java.patch1 (text/x-diff, 2.1 KB)
Index: main/src/net/sourceforge/cruisecontrol/config/XMLConfigManager.java
===================================================================
--- main/src/net/sourceforge/cruisecontrol/config/XMLConfigManager.java	(revision 4347)
+++ main/src/net/sourceforge/cruisecontrol/config/XMLConfigManager.java	(working copy)
@@ -36,9 +36,13 @@
  ********************************************************************************/
 package net.sourceforge.cruisecontrol.config;
 
+import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -83,7 +87,7 @@
         LOG.info("reading settings from config file [" + file.getAbsolutePath() + "]");
         Element element = Util.loadRootElement(file);
         resolver.resetResolvedFiles();
-        config = new CruiseControlConfig(element, resolver, controller);
+        config = new CruiseControlConfig(element, resolver, resolver, controller);
     }
 
     public File getConfigFile() {
@@ -140,7 +144,7 @@
         return md5;
     }
 
-    class Resolver implements XmlResolver {
+    class Resolver implements XmlResolver, FileResolver {
         private final Set<File> resolvedFiles = new HashSet<File>();
 
         public Element getElement(final String path) throws CruiseControlException {
@@ -149,6 +153,16 @@
             return Util.loadRootElement(file);
         }
 
+        public InputStream getInputStream(final String path) throws CruiseControlException {
+            final File file = new File(configFile.getParentFile(), path);
+            resolvedFiles.add(file);
+            try {
+                return new BufferedInputStream(new FileInputStream(file));
+            } catch (FileNotFoundException e) {
+                throw new CruiseControlException("exception when opening file " + file.getAbsolutePath(), e);
+            }
+        }
+
         public Set<File> getResolvedFiles() {
             return resolvedFiles;
         }
ProjectXMLHelper.java.patch1 (text/x-diff, 3.5 KB)
Index: main/src/net/sourceforge/cruisecontrol/ProjectXMLHelper.java
===================================================================
--- main/src/net/sourceforge/cruisecontrol/ProjectXMLHelper.java	(revision 4347)
+++ main/src/net/sourceforge/cruisecontrol/ProjectXMLHelper.java	(working copy)
@@ -44,6 +44,7 @@
 import org.jdom.Attribute;
 import org.jdom.Element;
 import net.sourceforge.cruisecontrol.config.DefaultPropertiesPlugin;
+import net.sourceforge.cruisecontrol.config.FileResolver;
 import net.sourceforge.cruisecontrol.config.PropertiesPlugin;
 import net.sourceforge.cruisecontrol.util.Util;
 
@@ -57,23 +58,25 @@
 
     private final Map<String, String> projectProperties;
     private final PluginRegistry projectPlugins;
+    private final FileResolver fileResolver;
 
     private final CruiseControlController controller;
 
     public ProjectXMLHelper() {
         this(new HashMap<String, String>(), PluginRegistry.createRegistry(PluginRegistry.loadDefaultPluginRegistry()),
-                null);
+                null, null);
     }
 
     public ProjectXMLHelper(final Map<String, String> projectProperties, final PluginRegistry projectPlugins) {
-        this(projectProperties, projectPlugins, null);
+        this(projectProperties, projectPlugins, null, null);
     }
     
     public ProjectXMLHelper(final Map<String, String> projectProperties, final PluginRegistry projectPlugins,
-                            final CruiseControlController controller) {
+             final FileResolver fileResolver, final CruiseControlController controller) {
         this.projectProperties = projectProperties;
         this.projectPlugins = projectPlugins;
         this.controller = controller;
+        this.fileResolver = fileResolver;
     }
 
     /**
@@ -90,7 +93,12 @@
         if (projectPlugins.isPluginRegistered(pluginName)) {
             final Object pluginInstance = getConfiguredPlugin(pluginHelper, pluginElement.getName());
             if (pluginInstance != null) { // preconfigured
-                return pluginHelper.configure(pluginElement, pluginInstance, skipChildElements);
+                // Plugin wants to register files to resolve
+//              if (pluginInstance instanceof ???? && fileResolver != null){
+//                  TODO: here the fileResolver is going to be passed to each plugin 
+//                        implementing appropriate method ... 
+//              }
+              return pluginHelper.configure(pluginElement, pluginInstance, skipChildElements);
             }
             return pluginHelper.configure(pluginElement, projectPlugins.getPluginClass(pluginName), skipChildElements);
         } else {
@@ -165,12 +173,13 @@
     }
     
     public static PropertiesPlugin registerCustomProperty(final Map<String, String> props,
-            final Element propertyElement, final boolean failIfMissing,
+            final Element propertyElement, final FileResolver fileResolver, final boolean failIfMissing,
             final PluginRegistry registry) throws CruiseControlException {
 
         parsePropertiesInElement(propertyElement, props, failIfMissing);
 
-        final Object o = new ProjectXMLHelper(props, registry, null).configurePlugin(propertyElement, false);
+        final Object o = new ProjectXMLHelper(props, registry, fileResolver, null).configurePlugin(propertyElement, 
+                false);
         if (!(o instanceof PropertiesPlugin)) {
           throw new CruiseControlException("Element " + propertyElement.getName()
                   + " does not implement PropertiesPlugin interface."
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)

iEYEABECAAYFAkqCs2cACgkQuYlVhxo/P1H/NACeI44NE3HRkHRqee8x8rqFLgRf
RUkAn3mBYExGonvkHAkjEQC9OzAXHpDv
=cMvK
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.