jruaux      2003/03/10 09:38:59

  Modified:    integration/eclipse/src/java/org/apache/cactus/eclipse/containers/ant
                        GenericAntProvider.java
  Log:
  Supported containers are retrieved dynamically
  
  Revision  Changes    Path
  1.13      +71 -1     
jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/containers/ant/GenericAntProvider.java
  
  Index: GenericAntProvider.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/integration/eclipse/src/java/org/apache/cactus/eclipse/containers/ant/GenericAntProvider.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- GenericAntProvider.java   7 Mar 2003 16:02:55 -0000       1.12
  +++ GenericAntProvider.java   10 Mar 2003 17:38:59 -0000      1.13
  @@ -57,6 +57,7 @@
   package org.apache.cactus.eclipse.containers.ant;
   
   import java.io.File;
  +import java.io.FilenameFilter;
   import java.net.URL;
   import java.util.Vector;
   
  @@ -118,6 +119,16 @@
        */
       private boolean serverStopped;
       /**
  +     * Plug-in relative path to the Ant container build files.
  +     */
  +    private static final String CONTAINER_BUILD_FILES_PATH = "./ant/scripts";
  +
  +    /**
  +     * Prefix of container build files.
  +     */
  +    private static final String CONTAINER_BUILD_FILES_PREFIX = "build-tests-";
  +
  +    /**
        * Constructor.
        * @param thePort the port that will be used when setting up the container
        * @param theTargetDir the directory to be used for container configuration
  @@ -287,5 +298,64 @@
       public void setEclipseRunner(EclipseRunTests theEclipseRunner)
       {
           this.eclipseRunner = theEclipseRunner;
  +    }
  +
  +    /**
  +     * @return an array of unique identifiers for a container in this container
  +     *     provider
  +     */
  +    public static String[] getContainers()
  +    {
  +        Vector containers = new Vector();
  +        URL containerDirURL =
  +            CactusPlugin.getDefault().find(
  +                new Path(CONTAINER_BUILD_FILES_PATH));
  +        if (containerDirURL == null)
  +        {
  +            // No container available
  +            return new String[0];
  +        }
  +        Path containerDir = new Path(containerDirURL.getPath());
  +        File dir = containerDir.toFile();
  +        String[] containerFiles = dir.list(new BuildFilenameFilter());
  +        for (int i = 0; i < containerFiles.length; i++)
  +        {
  +            String currentFileName = containerFiles[i];
  +            String currentId =
  +                currentFileName.substring(
  +                    CONTAINER_BUILD_FILES_PREFIX.length(),
  +                    currentFileName.lastIndexOf("."));
  +            containers.add(currentId);
  +        }
  +        return (String[]) containers.toArray(
  +            new String[containers.size()]);
  +    }
  +
  +    /**
  +     * Filter for container script files.
  +     * i.e. accepts files like 'build-tests-mycontainer3.1.xml'
  +     * 
  +     * @author <a href="mailto:[EMAIL PROTECTED]">Julien Ruaux</a>
  +     * 
  +     * @version $Id$
  +     */
  +    static class BuildFilenameFilter implements FilenameFilter
  +    {
  +        /**
  +         * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
  +         */
  +        public boolean accept(File theDir, String theFilename)
  +        {
  +            if (theFilename
  +                .substring(0, CONTAINER_BUILD_FILES_PREFIX.length())
  +                .equals(CONTAINER_BUILD_FILES_PREFIX))
  +            {
  +                return true;
  +            }
  +            else
  +            {
  +                return false;
  +            }
  +        }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to