portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util/ant OverwritePropertiesTask.java
Date Tue, 11 Feb 2003 23:18:57 GMT
taylor      2003/02/11 15:18:57

  Added:       src/java/org/apache/jetspeed/util
                        TestOverwriteProperties.java
               src/java/org/apache/jetspeed/util/ant
                        OverwritePropertiesTask.java
  Log:
  Overwrite properties Ant task and test case contributed by Eric Pugh
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/util/TestOverwriteProperties.java
  
  Index: TestOverwriteProperties.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.util;
  
  import java.util.*;
  import java.io.*;
  
  // Junit imports
  import junit.awtui.TestRunner;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.framework.TestCase;
  
  import org.apache.turbine.util.StringUtils;
  import org.apache.tools.ant.util.FileUtils;
  
  
  
  /**
   *
   * @author <a href="epugh@upstate.com">Eric Pugh</a>
   */
  
  public class TestOverwriteProperties extends TestCase
  {
  
      private static String SRC_JETSPEED_RESOURCES = "../test/testdata/conf/SrcJetspeedResources.properties";
      private static String JETSPEED_RESOURCES = "../test/testdata/conf/JetspeedResources.properties";
  
      private static String MERGE_JETSPEED_RESOURCES = "../test/testdata/conf/MergeJetspeedResources.properties";
      private static String MERGE_REMOVE_JETSPEED_RESOURCES = "../test/testdata/conf/MergeRemoveJetspeedResources.properties";
      private static String MERGE_ADD_JETSPEED_RESOURCES = "../test/testdata/conf/MergeAddJetspeedResources.properties";
  
      private static String RESULT_MERGE_JETSPEED_RESOURCES = "../test/testdata/conf/ResultMergeJetspeedResources.properties";
      private static String RESULT_MERGE_REMOVE_JETSPEED_RESOURCES = "../test/testdata/conf/ResultMergeRemoveJetspeedResources.properties";
      private static String RESULT_MERGE_ADD_JETSPEED_RESOURCES = "../test/testdata/conf/ResultMergeAddJetspeedResources.properties";
  
      private static String INCLUDE_ROOT = "../test/testdata/conf/";
  
      private File SRC_JETSPEED_RESOURCES_FILE = null;
      private File JETSPEED_RESOURCES_FILE = null;
      private File MERGE_JETSPEED_RESOURCES_FILE = null;
      private File MERGE_REMOVE_JETSPEED_RESOURCES_FILE = null;
      private File MERGE_ADD_JETSPEED_RESOURCES_FILE = null;
      private File RESULT_MERGE_JETSPEED_RESOURCES_FILE = null;
      private File RESULT_MERGE_REMOVE_JETSPEED_RESOURCES_FILE = null;
      private File RESULT_MERGE_ADD_JETSPEED_RESOURCES_FILE = null;
      private File INCLUDE_ROOT_DIR = null;
      private FileUtils fileUtils = FileUtils.newFileUtils();
  
  
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestOverwriteProperties( String name ) {
          super( name );
      }
  
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[])
      {
          junit.awtui.TestRunner.main( new String[] { TestOverwriteProperties.class.getName()
} );
      }
  
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite( TestOverwriteProperties.class );
      }
  
  
      public void setUp() throws Exception{
  
        SRC_JETSPEED_RESOURCES_FILE = new File(SRC_JETSPEED_RESOURCES);
        assertTrue("Check SRC_JETSPEED_RESOURCES_FILE exists:" + SRC_JETSPEED_RESOURCES_FILE,SRC_JETSPEED_RESOURCES_FILE.exists());
  
        JETSPEED_RESOURCES_FILE = new File(JETSPEED_RESOURCES);
        if (JETSPEED_RESOURCES_FILE.exists()){
          assertTrue("Check JETSPEED_RESOURCES_FILE exists, then delete it:" + JETSPEED_RESOURCES_FILE,JETSPEED_RESOURCES_FILE.delete());
        }
        fileUtils.copyFile(SRC_JETSPEED_RESOURCES_FILE,JETSPEED_RESOURCES_FILE);
        assertTrue("Check JETSPEED_RESOURCES_FILE exists:" + JETSPEED_RESOURCES_FILE,JETSPEED_RESOURCES_FILE.exists());
  
  
        MERGE_JETSPEED_RESOURCES_FILE = new File(MERGE_JETSPEED_RESOURCES);
        assertTrue("Check MERGE_JETSPEED_RESOURCES_FILE exists:" + MERGE_JETSPEED_RESOURCES_FILE,MERGE_JETSPEED_RESOURCES_FILE.exists());
        MERGE_REMOVE_JETSPEED_RESOURCES_FILE = new File(MERGE_REMOVE_JETSPEED_RESOURCES);
        assertTrue("Check MERGE_REMOVE_JETSPEED_RESOURCES_FILE exists:" + MERGE_REMOVE_JETSPEED_RESOURCES_FILE,MERGE_REMOVE_JETSPEED_RESOURCES_FILE.exists());
        MERGE_ADD_JETSPEED_RESOURCES_FILE = new File(MERGE_ADD_JETSPEED_RESOURCES);
        assertTrue("Check MERGE_ADD_JETSPEED_RESOURCES_FILE exists:" + MERGE_ADD_JETSPEED_RESOURCES_FILE,MERGE_ADD_JETSPEED_RESOURCES_FILE.exists());
  
        RESULT_MERGE_JETSPEED_RESOURCES_FILE = new File(RESULT_MERGE_JETSPEED_RESOURCES);
        assertTrue("Check RESULT_MERGE_JETSPEED_RESOURCES_FILE exists:" + RESULT_MERGE_JETSPEED_RESOURCES_FILE,RESULT_MERGE_JETSPEED_RESOURCES_FILE.exists());
        RESULT_MERGE_REMOVE_JETSPEED_RESOURCES_FILE = new File(RESULT_MERGE_REMOVE_JETSPEED_RESOURCES);
        assertTrue("Check RESULT_MERGE_REMOVE_JETSPEED_RESOURCES_FILE exists:" + RESULT_MERGE_REMOVE_JETSPEED_RESOURCES_FILE,RESULT_MERGE_REMOVE_JETSPEED_RESOURCES_FILE.exists());
        RESULT_MERGE_ADD_JETSPEED_RESOURCES_FILE = new File(RESULT_MERGE_ADD_JETSPEED_RESOURCES);
        assertTrue("Check RESULT_MERGE_ADD_JETSPEED_RESOURCES_FILE exists:" + RESULT_MERGE_ADD_JETSPEED_RESOURCES_FILE,RESULT_MERGE_ADD_JETSPEED_RESOURCES_FILE.exists());
  
        INCLUDE_ROOT_DIR = new File(INCLUDE_ROOT);
        assertTrue("Check include root dir exists:" + INCLUDE_ROOT_DIR,INCLUDE_ROOT_DIR.exists());
        assertTrue(INCLUDE_ROOT_DIR.isDirectory());
      }
  
      /**
       * Tests overwriting property
       * @throws Exception
       */
  
      public void testOverwriteProperty() throws Exception
      {
         try
          {
            String args[] = new String[]{JETSPEED_RESOURCES_FILE.toString(),MERGE_JETSPEED_RESOURCES.toString(),INCLUDE_ROOT.toString()};
            OverwriteProperties.main(args);
            assertTrue("Make sure our merge worked properly.",fileUtils.contentEquals(JETSPEED_RESOURCES_FILE,RESULT_MERGE_JETSPEED_RESOURCES_FILE));
          }
          catch (Exception e)
          {
              fail(StringUtils.stackTrace(e));
          }
      }
  
      /**
       * Tests removing properties
       * @throws Exception
       */
  
      public void testRemoveProperties() throws Exception
      {
          try
          {
            String args[] = new String[]{JETSPEED_RESOURCES_FILE.toString(),MERGE_REMOVE_JETSPEED_RESOURCES.toString(),INCLUDE_ROOT.toString()};
            OverwriteProperties.main(args);
            assertTrue("Make sure our merge worked properly.",fileUtils.contentEquals(JETSPEED_RESOURCES_FILE,RESULT_MERGE_REMOVE_JETSPEED_RESOURCES_FILE));
          }
          catch (Exception e)
          {
              fail(StringUtils.stackTrace(e));
          }
      }
  
      /**
       * Tests adding properties
       * @throws Exception
       */
  
      public void testAddProperties() throws Exception
      {
          try
          {
            String args[] = new String[]{JETSPEED_RESOURCES_FILE.toString(),MERGE_ADD_JETSPEED_RESOURCES.toString(),INCLUDE_ROOT.toString()};
            OverwriteProperties.main(args);
            assertTrue("Make sure our merge worked properly.",fileUtils.contentEquals(JETSPEED_RESOURCES_FILE,RESULT_MERGE_ADD_JETSPEED_RESOURCES_FILE));
          }
          catch (Exception e)
          {
              fail(StringUtils.stackTrace(e));
          }
      }
  
      public void tearDown(){
        if (JETSPEED_RESOURCES_FILE.exists()){
          //JETSPEED_RESOURCES_FILE.delete();
        }
      }
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/util/ant/OverwritePropertiesTask.java
  
  Index: OverwritePropertiesTask.java
  ===================================================================
  /*
   *  ====================================================================
   *  The Apache Software License, Version 1.1
   *
   *  Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   *  reserved.
   *
   *  Redistribution and use in source and binary forms, with or without
   *  modification, are permitted provided that the following conditions
   *  are met:
   *
   *  1. Redistributions of source code must retain the above copyright
   *  notice, this list of conditions and the following disclaimer.
   *
   *  2. Redistributions in binary form must reproduce the above copyright
   *  notice, this list of conditions and the following disclaimer in
   *  the documentation and/or other materials provided with the
   *  distribution.
   *
   *  3. The end-user documentation included with the redistribution,
   *  if any, must include the following acknowledgment:
   *  "This product includes software developed by the
   *  Apache Software Foundation (http://www.apache.org/)."
   *  Alternately, this acknowledgment may appear in the software itself,
   *  if and wherever such third-party acknowledgments normally appear.
   *
   *  4. The names "Apache" and "Apache Software Foundation" and
   *  "Apache Jetspeed" must not be used to endorse or promote products
   *  derived from this software without prior written permission. For
   *  written permission, please contact apache@apache.org.
   *
   *  5. Products derived from this software may not be called "Apache" or
   *  "Apache Jetspeed", nor may "Apache" appear in their name, without
   *  prior written permission of the Apache Software Foundation.
   *
   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   *  SUCH DAMAGE.
   *  ====================================================================
   *
   *  This software consists of voluntary contributions made by many
   *  individuals on behalf of the Apache Software Foundation.  For more
   *  information on the Apache Software Foundation, please see
   *  <http://www.apache.org/>.
   */
  package org.apache.jetspeed.util.ant;
  
  import java.io.*;
  import java.util.*;
  
  import org.apache.tools.ant.*;
  
  import org.apache.jetspeed.util.OverwriteProperties;
  
  /**
   * <code>OverwritePropertiesTask</code> is the task definition for an Ant
   * interface to the <code>OverwriteProperties</code>.
   *
   * @author     Eric Pugh
   * @created    January 29, 2003
   * @version    $Revision: 1.1 $
   * @see        org.apache.tools.ant.Task
   */
  public class OverwritePropertiesTask extends Task {
  
      /** File to merge properties into */
      private File mergeBaseProperties;
  
      /** File to merge properties from */
      private File mergeProperties;
  
      /** Directory to look for includes in */
      private File includesDir;
  
  
      /**
       *  Sets the File to merge properties into
       *
       * @param  mergeBaseProperties  File to merge properties into
       */
      public void setMergeBaseProperties(File mergeBaseProperties) {
          this.mergeBaseProperties = mergeBaseProperties;
      }
  
  
      /**
       *  Sets the File to merge properties from
       *
       * @param  mergeProperties  File to merge properties from
       */
      public void setMergeProperties(File mergeProperties) {
          this.mergeProperties = mergeProperties;
      }
  
  
      /**
       *  Sets the Directory to look for includes in
       *
       * @param  includesDir  Directory to look for includes in
       */
      public void setIncludesDir(File includesDir) {
          this.includesDir = includesDir;
      }
  
  
      /**
       *  Gets the File to merge properties into
       *
       * @return    File to merge properties into
       */
      public File getMergeBaseProperties() {
          return mergeBaseProperties;
      }
  
  
      /**
       *  Gets the File to merge properties from
       *
       * @return    File to merge properties from
       */
      public File getMergeProperties() {
          return mergeProperties;
      }
  
  
      /**
       *  Gets the Directory to look for includes in
       *
       * @return    Directory to look for includes in
       */
      public File getIncludesDir() {
          return includesDir;
      }
  
  
  
      /**
       * Load the step and then execute it
       *
       * @exception  BuildException  Description of the Exception
       */
      public void execute() throws BuildException {
        try {
          OverwriteProperties overwriteProperties = new OverwriteProperties();
          overwriteProperties.setBaseProperties(getMergeBaseProperties());
          overwriteProperties.setProperties(getMergeProperties());
          overwriteProperties.setIncludeRoot(getIncludesDir());
  
          overwriteProperties.execute();
  
        }
        catch (Exception e){
          throw new BuildException(e.toString());
        }
  
  
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message