continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r219723 - in /maven/continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/configuration/ test/java/org/apache/maven/continuum/configuration/ test/resources/ test/resources/org/apache/maven/continuum/configuration/
Date Tue, 19 Jul 2005 17:29:44 GMT
Author: jvanzyl
Date: Tue Jul 19 10:29:39 2005
New Revision: 219723

URL: http://svn.apache.org/viewcvs?rev=219723&view=rev
Log:
o adding tests for the configuration service and in particular the storing of 
  various JDKs that people might be wanting to use.

Added:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationLoadingException.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationStoringException.java
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/configuration/
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
    maven/continuum/trunk/continuum-core/src/test/resources/configuration.xml
    maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/configuration/
    maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/configuration/ConfigurationServiceTest.xml
Modified:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationLoadingException.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationLoadingException.java?rev=219723&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationLoadingException.java
(added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationLoadingException.java
Tue Jul 19 10:29:39 2005
@@ -0,0 +1,40 @@
+package org.apache.maven.continuum.configuration;
+
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:$
+ */
+public class ConfigurationLoadingException
+    extends Exception
+{
+    public ConfigurationLoadingException( String message )
+    {
+        super( message );
+    }
+
+    public ConfigurationLoadingException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public ConfigurationLoadingException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java?rev=219723&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
(added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
Tue Jul 19 10:29:39 2005
@@ -0,0 +1,75 @@
+package org.apache.maven.continuum.configuration;
+
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:$
+ */
+public interface ConfigurationService
+{
+    String ROLE = ConfigurationService.class.getName();
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public static final String CONFIGURATION = "configuration";
+
+    public static final String CONFIGURATION_URL = "url";
+
+    public static final String CONFIGURATION_BUILD_OUTPUT_DIRECTORY = "build-output-directory";
+
+    public static final String CONFIGURATION_JDKS = "jdks";
+
+    public static final String CONFIGURATION_JDK = "jdk";
+
+    public static final String CONFIGURATION_JDK_VERSION = "jdk-version";
+
+    public static final String CONFIGURATION_JDK_HOME = "jdk-home";
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    String getUrl();
+
+    void setUrl( String url );
+
+    File getBuildOutputDirectory();
+
+    void setBuildOutputDirectory( File buildOutputDirectory );
+
+    Map getJdks();
+
+    void addJdk( String version, String home );
+
+    void setJdks( Map jdks );
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    void load()
+        throws ConfigurationLoadingException;
+
+    void store()
+        throws ConfigurationStoringException;
+}

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationStoringException.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationStoringException.java?rev=219723&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationStoringException.java
(added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/ConfigurationStoringException.java
Tue Jul 19 10:29:39 2005
@@ -0,0 +1,40 @@
+package org.apache.maven.continuum.configuration;
+
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:$
+ */
+public class ConfigurationStoringException
+    extends Exception
+{
+    public ConfigurationStoringException( String message )
+    {
+        super( message );
+    }
+
+    public ConfigurationStoringException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public ConfigurationStoringException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java?rev=219723&r1=219722&r2=219723&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
Tue Jul 19 10:29:39 2005
@@ -1,12 +1,5 @@
 package org.apache.maven.continuum.configuration;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -14,9 +7,20 @@
 import org.codehaus.plexus.util.xml.Xpp3DomWriter;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Date;
+
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- * @version $Id:$
+ * @version $Id$
  */
 public class DefaultConfigurationService
     implements ConfigurationService
@@ -31,6 +35,10 @@
      */
     private File applicationHome;
 
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
     private Xpp3Dom configuration;
 
     // ----------------------------------------------------------------------
@@ -39,6 +47,16 @@
 
     private String url;
 
+    private File buildOutputDirectory;
+
+    private Map jdks;
+
+    private static final String LS = System.getProperty( "line.separator" );
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
     public String getUrl()
     {
         return url;
@@ -49,8 +67,6 @@
         this.url = url;
     }
 
-    private File buildOutputDirectory;
-
     public File getBuildOutputDirectory()
     {
         return buildOutputDirectory;
@@ -61,6 +77,26 @@
         this.buildOutputDirectory = buildOutputDirectory;
     }
 
+    public Map getJdks()
+    {
+        return jdks;
+    }
+
+    public void addJdk( String jdkVersion, String jdkHome )
+    {
+        if ( jdks == null )
+        {
+            jdks = new TreeMap();
+        }
+
+        jdks.put( jdkVersion, jdkHome );
+    }
+
+    public void setJdks( Map jdks )
+    {
+        this.jdks = jdks;
+    }
+
     // ----------------------------------------------------------------------
     // Process configuration to glean application specific values
     // ----------------------------------------------------------------------
@@ -68,9 +104,42 @@
     protected void processInboundConfiguration()
         throws ConfigurationLoadingException
     {
-        url = configuration.getChild( CONFIGURATION_URL ).getValue();
+        Xpp3Dom urlDom = configuration.getChild( CONFIGURATION_URL );
+
+        if ( urlDom != null )
+        {
+            url = urlDom.getValue();
+        }
+
+        Xpp3Dom buildOutputDirectoryDom = configuration.getChild( CONFIGURATION_BUILD_OUTPUT_DIRECTORY
);
+
+        if ( buildOutputDirectoryDom != null )
+        {
+            buildOutputDirectory = getFile( configuration, CONFIGURATION_BUILD_OUTPUT_DIRECTORY
);
+        }
+
+        Xpp3Dom jdksElement = configuration.getChild( CONFIGURATION_JDKS );
+
+        if ( jdksElement != null )
+        {
+            jdks = new TreeMap();
+
+            Xpp3Dom[] jdkElements = jdksElement.getChildren( CONFIGURATION_JDK );
 
-        buildOutputDirectory = getFile( configuration, CONFIGURATION_BUILD_OUTPUT_DIRECTORY
);
+            for ( int i = 0; i < jdkElements.length; i++ )
+            {
+                Xpp3Dom jdkElement = jdkElements[i];
+
+                String version = jdkElement.getChild( CONFIGURATION_JDK_VERSION ).getValue();
+
+                String home = jdkElement.getChild( CONFIGURATION_JDK_HOME ).getValue();
+
+                if ( version != null & home != null )
+                {
+                    jdks.put( version, home );
+                }
+            }
+        }
     }
 
     private File getFile( Xpp3Dom configuration, String elementName )
@@ -95,11 +164,39 @@
 
     protected void processOutboundConfiguration()
     {
-        configuration = new Xpp3Dom( "configuration" );
+        configuration = new Xpp3Dom( CONFIGURATION );
 
-        configuration.addChild( createDom( CONFIGURATION_URL, url ) );
+        if ( url != null )
+        {
+            configuration.addChild( createDom( CONFIGURATION_URL, url ) );
+        }
+
+        if ( buildOutputDirectory != null )
+        {
+            configuration.addChild( createFileDom( CONFIGURATION_BUILD_OUTPUT_DIRECTORY,
buildOutputDirectory ) );
+        }
+
+        if ( jdks != null )
+        {
+            Xpp3Dom jdksDom = new Xpp3Dom( CONFIGURATION_JDKS );
+
+            for ( Iterator i = jdks.keySet().iterator(); i.hasNext(); )
+            {
+                String version = (String) i.next();
+
+                String home = (String) jdks.get( version );
 
-        configuration.addChild( createFileDom( CONFIGURATION_BUILD_OUTPUT_DIRECTORY, buildOutputDirectory
) );
+                Xpp3Dom jdkDom = new Xpp3Dom( CONFIGURATION_JDK );
+
+                jdkDom.addChild( createDom( CONFIGURATION_JDK_VERSION, version ) );
+
+                jdkDom.addChild( createDom( CONFIGURATION_JDK_HOME, home ) );
+
+                jdksDom.addChild( jdkDom );
+            }
+
+            configuration.addChild( jdksDom );
+        }
     }
 
     protected Xpp3Dom createDom( String elementName, String value )
@@ -163,7 +260,13 @@
 
             Writer writer = new FileWriter( source );
 
+            writer.write( "<!-- Written by Continuum on " + new Date() + " -->" + LS
);
+
             Xpp3DomWriter.write( writer, configuration );
+
+            writer.flush();
+
+            writer.close();
         }
         catch ( IOException e )
         {

Added: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java?rev=219723&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
(added)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
Tue Jul 19 10:29:39 2005
@@ -0,0 +1,83 @@
+package org.apache.maven.continuum.configuration;
+
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id:$
+ */
+public class ConfigurationServiceTest
+    extends PlexusTestCase
+{
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        File templateConfiguration = new File( getBasedir(), "src/test/resources/configuration.xml"
);
+
+        File testConfiguration = new File( getBasedir(), "target/configuration.xml" );
+
+        FileUtils.copyFile( templateConfiguration, testConfiguration );
+    }
+
+    public void testConfigurationService()
+        throws Exception
+    {
+        ConfigurationService service = (ConfigurationService) lookup( ConfigurationService.ROLE
);
+
+        service.load();
+
+        assertEquals( "http://localhost:8080/continuum/servlet/continuum", service.getUrl()
);
+
+        assertEquals( "build-output", service.getBuildOutputDirectory().getName() );
+
+        service.addJdk( "1.3", "/jdks/1.3" );
+
+        service.addJdk( "1.4", "/jdks/1.4" );
+
+        service.addJdk( "1.5", "/jdks/1.5" );
+
+        service.store();
+
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
+        service.load();
+
+        Map jdks = service.getJdks();
+
+        assertNotNull( jdks.get( "1.3" ) );
+
+        assertEquals( "/jdks/1.3", (String) jdks.get( "1.3" ) );
+
+        assertNotNull( jdks.get( "1.4" ) );
+
+        assertEquals( "/jdks/1.4", (String) jdks.get( "1.4" ) );
+
+        assertNotNull( jdks.get( "1.5" ) );
+
+        assertEquals( "/jdks/1.5", (String) jdks.get( "1.5" ) );
+    }
+}
\ No newline at end of file

Added: maven/continuum/trunk/continuum-core/src/test/resources/configuration.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/resources/configuration.xml?rev=219723&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/resources/configuration.xml (added)
+++ maven/continuum/trunk/continuum-core/src/test/resources/configuration.xml Tue Jul 19 10:29:39
2005
@@ -0,0 +1,4 @@
+<configuration>
+  <url>http://localhost:8080/continuum/servlet/continuum</url>
+  <build-output-directory>build-output</build-output-directory>
+</configuration>

Added: maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/configuration/ConfigurationServiceTest.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/configuration/ConfigurationServiceTest.xml?rev=219723&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/configuration/ConfigurationServiceTest.xml
(added)
+++ maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/configuration/ConfigurationServiceTest.xml
Tue Jul 19 10:29:39 2005
@@ -0,0 +1,12 @@
+<plexus>
+  <components>
+    <component>
+      <role>org.apache.maven.continuum.configuration.ConfigurationService</role>
+      <implementation>org.apache.maven.continuum.configuration.DefaultConfigurationService</implementation>
+      <configuration>
+        <application-home>${basedir}/target/continuum</application-home>
+        <source>${basedir}/target/configuration.xml</source>
+      </configuration>
+    </component>
+  </components>
+</plexus>
\ No newline at end of file



Mime
View raw message