directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r651311 - in /directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations: resources/conf/ src/main/java/org/apache/directory/studio/apacheds/experimentations/
Date Thu, 24 Apr 2008 16:37:42 GMT
Author: pamarcelot
Date: Thu Apr 24 09:37:36 2008
New Revision: 651311

URL: http://svn.apache.org/viewvc?rev=651311&view=rev
Log:
Removed unused code in the Activator class.
Added methods to create an instance folder with the necessary configuration files in it.

Added:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/apacheds.conf
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/log4j.properties
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/server.xml
Modified:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/Activator.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/apacheds.conf
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/apacheds.conf?rev=651311&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/apacheds.conf
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/apacheds.conf
Thu Apr 24 09:37:36 2008
@@ -0,0 +1,41 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+#
+  
+#
+# In this file you can override parameters specified in the default
+# Apache Directory Server config file which is usually at
+# /opt/apacheds-x.x.x/conf/apacheds.conf
+#
+# See also http://wrapper.tanukisoftware.org/doc/english/properties.html
+# For a list of properties that can be set.
+#
+# Common overrides shown commented below
+
+
+# Override the JRE used
+# wrapper.java.command=%JAVA_HOME%/bin/java
+
+# Override the JVM memory settings
+# Initial Java Heap Size (in MB)
+# wrapper.java.initmemory=384
+
+# Maximum Java Heap Size (in MB)
+# wrapper.java.maxmemory=384
+
+# apacheds.instance.start=auto
\ No newline at end of file

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/log4j.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/log4j.properties?rev=651311&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/log4j.properties
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/log4j.properties
Thu Apr 24 09:37:36 2008
@@ -0,0 +1,40 @@
+#############################################################################
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You 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.
+#############################################################################
+log4j.rootCategory=WARN, R, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+
+log4j.appender.R=org.apache.log4j.RollingFileAppender
+#log4j.appender.R.File=${apacheds.log.dir}/${apacheds.instance}/apacheds-rolling.log
+log4j.appender.R.File=${apacheds.log.dir}/apacheds-rolling.log
+
+log4j.appender.R.MaxFileSize=1024KB
+# Keep some backup files
+log4j.appender.R.MaxBackupIndex=5
+
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
+log4j.appender.R.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+# with these we'll not get innundated when switching to DEBUG
+log4j.logger.org.apache.directory.shared.ldap.name=WARN
+log4j.logger.org.springframework=WARN
+log4j.logger.org.apache.directory.shared.codec=WARN
+log4j.logger.org.apache.directory.shared.asn1=WARN
+

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/server.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/server.xml?rev=651311&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/server.xml
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/resources/conf/server.xml
Thu Apr 24 09:37:36 2008
@@ -0,0 +1,241 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+
+<spring:beans xmlns:spring="http://xbean.apache.org/schemas/spring/1.0" 
+			  xmlns:s="http://www.springframework.org/schema/beans"
+			  xmlns="http://apacheds.org/config/1.0">
+
+  <defaultDirectoryService id="directoryService" instanceId="default"
+                           workingDirectory="example.com"
+                           allowAnonymousAccess="true"
+                           accessControlEnabled="false"
+                           denormalizeOpAttrsEnabled="false">
+    <systemPartition>
+      <!-- use the following partitionConfiguration to override defaults for -->
+      <!-- the system partition                                              -->
+      <jdbmPartition id="system" cacheSize="100" suffix="ou=system" optimizerEnabled="true"
syncOnWrite="true">
+        <indexedAttributes>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.1" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.2" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.3" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.4" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.5" cacheSize="10"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.6" cacheSize="10"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.7" cacheSize="10"/>
+          <jdbmIndex attributeId="ou" cacheSize="100"/>
+          <jdbmIndex attributeId="uid" cacheSize="100"/>
+          <jdbmIndex attributeId="objectClass" cacheSize="100"/>
+        </indexedAttributes>
+        <contextEntry>#systemContextEntry</contextEntry>
+        <!-- contextEntry>
+          <s:value>
+            objectClass: top
+            objectClass: organizationalUnit
+            objectClass: extensibleObject
+            ou: system
+          </s:value>
+        </contextEntry -->
+      </jdbmPartition>
+    </systemPartition>
+
+    <partitions>
+      <!-- NOTE: when specifying new partitions you need not include those   -->
+      <!-- attributes below with OID's which are the system indices, if left -->
+      <!-- out they will be automatically configured for you with defaults.  -->
+      <jdbmPartition id="example" cacheSize="100" suffix="dc=example,dc=com" optimizerEnabled="true"
+                     syncOnWrite="true">
+        <indexedAttributes>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.1" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.2" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.3" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.4" cacheSize="100"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.5" cacheSize="10"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.6" cacheSize="10"/>
+          <jdbmIndex attributeId="1.3.6.1.4.1.18060.0.4.1.2.7" cacheSize="10"/>
+          <jdbmIndex attributeId="dc" cacheSize="100"/>
+          <jdbmIndex attributeId="ou" cacheSize="100"/>
+          <jdbmIndex attributeId="krb5PrincipalName" cacheSize="100"/>
+          <jdbmIndex attributeId="uid" cacheSize="100"/>
+          <jdbmIndex attributeId="objectClass" cacheSize="100"/>
+        </indexedAttributes>
+        <contextEntry>#exampleContextEntry</contextEntry>
+        <!-- contextEntry>
+          <s:value>
+            objectClass: top
+            objectClass: domain
+            objectClass: extensibleObject
+            dc: example
+          </s:value>
+        </contextEntry -->
+      </jdbmPartition>
+    </partitions>
+
+    <interceptors>
+      <normalizationInterceptor/>
+      <authenticationInterceptor/>
+      <referralInterceptor/>
+      <aciAuthorizationInterceptor/>
+      <defaultAuthorizationInterceptor/>
+      <exceptionInterceptor/>
+      <operationalAttributeInterceptor/>
+
+      <!-- Uncomment to enable the password policy interceptor
+      <passwordPolicyInterceptor/>
+      <keyDerivationInterceptor/>
+      -->
+
+      <schemaInterceptor/>
+      <subentryInterceptor/>
+      <collectiveAttributeInterceptor/>
+      <eventInterceptor/>
+      <triggerInterceptor/>
+
+      <!-- Uncomment to enable replication interceptor
+      <replicationInterceptor>
+        <configuration>
+          <replicationConfiguration serverPort="10390" peerReplicas="instance_b@localhost:10392">
+            <replicaId>
+              <replicaId id="instance_a"/>
+            </replicaId>
+          </replicationConfiguration>
+        </configuration>
+      </replicationInterceptor>
+      -->
+    </interceptors>
+  </defaultDirectoryService>
+
+  <standardThreadPool id="standardThreadPool" maxThreads="8"/>
+  <datagramAcceptor id="datagramAcceptor" logicExecutor="#standardThreadPool"/>
+  <socketAcceptor id="socketAcceptor" logicExecutor="#standardThreadPool"/>
+
+<!--  missing  atou=users,dc=example,dc=com
+  <changePasswordServer ipPort="60464">
+    <directoryService>#directoryService</directoryService>
+    <datagramAcceptor>#datagramAcceptor</datagramAcceptor>
+    <socketAcceptor>#socketAcceptor</socketAcceptor>
+  </changePasswordServer>
+-->
+<!--  missing atou=users,dc=example,dc=com
+  <kdcServer ipPort="60088">
+    <directoryService>#directoryService</directoryService>
+    <datagramAcceptor>#datagramAcceptor</datagramAcceptor>
+    <socketAcceptor>#socketAcceptor</socketAcceptor>
+  </kdcServer>
+-->
+  <ntpServer ipPort="60123">
+    <datagramAcceptor>#datagramAcceptor</datagramAcceptor>
+    <socketAcceptor>#socketAcceptor</socketAcceptor>
+  </ntpServer>
+<!--  missing atou=users,dc=example,dc=com
+  <dnsServer ipPort="8053">
+    <directoryService>#directoryService</directoryService>
+    <datagramAcceptor>#datagramAcceptor</datagramAcceptor>
+    <socketAcceptor>#socketAcceptor</socketAcceptor>
+  </dnsServer>
+-->
+
+  <ldapServer id="ldapsServer"
+              enabled="true"
+              ipPort="10636"
+              enableLdaps="true">
+    <directoryService>#directoryService</directoryService>
+    <socketAcceptor>#socketAcceptor</socketAcceptor>
+  </ldapServer>
+
+  <ldapServer id="ldapServer"
+              ipPort="10389"
+              allowAnonymousAccess="false"
+              saslHost="ldap.example.com"
+              saslPrincipal="ldap/ldap.example.com@EXAMPLE.COM"
+              searchBaseDn="ou=users,ou=system"
+              maxTimeLimit="15000"
+              maxSizeLimit="1000">
+
+    <directoryService>#directoryService</directoryService>
+    <socketAcceptor>#socketAcceptor</socketAcceptor>
+    <!-- The list of supported authentication mechanisms.                   -->
+    <supportedMechanisms>
+      <s:value>SIMPLE</s:value>
+      <s:value>CRAM-MD5</s:value>
+      <s:value>DIGEST-MD5</s:value>
+      <!--<s:value>GSSAPI</s:value>-->
+    </supportedMechanisms>
+
+    <!-- The desired quality-of-protection, used by DIGEST-MD5 and GSSAPI.  -->
+    <saslQop>
+      <s:value>auth</s:value>
+      <s:value>auth-int</s:value>
+      <s:value>auth-conf</s:value>
+    </saslQop>
+
+    <!-- The realms serviced by this SASL host, used by DIGEST-MD5 and GSSAPI. -->
+    <saslRealms>
+      <s:value>example.com</s:value>
+      <s:value>apache.org</s:value>
+    </saslRealms>
+
+    <!-- the collection of extended operation handlers to install           -->
+    <extendedOperationHandlers>
+      <startTlsHandler/>
+      <gracefulShutdownHandler/>
+      <launchDiagnosticUiHandler/>
+      <!-- The Stored Procedure Extended Operation is not stable yet and it may cause
security risks.-->
+      <!--storedProcedureExtendedOperationHandler/-->
+    </extendedOperationHandlers>
+  </ldapServer>
+
+
+  <apacheDS id="apacheDS"
+            synchPeriodMillis="15000"
+            allowAnonymousAccess="false">
+
+    <directoryService>#directoryService</directoryService>
+    <ldapServer>#ldapServer</ldapServer>
+    <ldapsServer>#ldapsServer</ldapsServer>
+  </apacheDS>
+
+  <spring:bean id="systemContextEntry" 
+	class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <spring:property name="targetObject"><spring:ref local='directoryService'/></spring:property>
+    <spring:property name="targetMethod"><spring:value>newEntry</spring:value></spring:property>
+    <spring:property name="arguments">
+      <spring:list>
+        <spring:value xmlns="http://www.springframework.org/schema/beans">
+          objectClass: top
+          objectClass: organizationalUnit
+          objectClass: extensibleObject
+          ou: system
+        </spring:value>
+        <spring:value>ou=system</spring:value>
+      </spring:list>
+    </spring:property>
+  </spring:bean>
+  
+  <spring:bean id="exampleContextEntry" 
+	class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <spring:property name="targetObject"><spring:ref local='directoryService'/></spring:property>
+    <spring:property name="targetMethod"><spring:value>newEntry</spring:value></spring:property>
+    <spring:property name="arguments">
+      <spring:list>
+        <spring:value xmlns="http://www.springframework.org/schema/beans">
+          objectClass: top
+          objectClass: domain
+          objectClass: extensibleObject
+          dc: example
+        </spring:value>
+        <spring:value>dc=example,dc=com</spring:value>
+      </spring:list>
+    </spring:property>
+  </spring:bean>
+
+  <!-- another bean I didn't convert -->
+  <spring:bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
+    <spring:property name="customEditors">
+      <spring:map>
+        <spring:entry key="javax.naming.directory.Attributes">
+          <spring:bean class="org.apache.directory.server.core.configuration.AttributesPropertyEditor"/>
+        </spring:entry>
+      </spring:map>
+    </spring:property>
+  </spring:bean>
+</spring:beans>

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/Activator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/Activator.java?rev=651311&r1=651310&r2=651311&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/Activator.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/Activator.java
Thu Apr 24 09:37:36 2008
@@ -26,7 +26,6 @@
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunchConfiguration;
@@ -92,64 +91,7 @@
         consoleDisplayMgr.println( "MSG_WARNING", ConsoleDisplayMgr.MSG_WARNING );
         consoleDisplayMgr.println( "MSG_ERROR", ConsoleDisplayMgr.MSG_ERROR );
 
-        IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
-        for ( int i = 0; i < types.length; i++ )
-        {
-            IVMInstallType type = types[i];
-            IVMInstall[] jres = type.getVMInstalls();
-            for ( IVMInstall vmInstall : jres )
-            {
-                consoleDisplayMgr.println( vmInstall.getId(), ConsoleDisplayMgr.MSG_INFORMATION
);
-                consoleDisplayMgr.println( vmInstall.getName(), ConsoleDisplayMgr.MSG_INFORMATION
);
-                consoleDisplayMgr
-                    .println( vmInstall.getInstallLocation().toString(), ConsoleDisplayMgr.MSG_INFORMATION
);
-                consoleDisplayMgr.println( vmInstall.getVMInstallType().toString(), ConsoleDisplayMgr.MSG_INFORMATION
);
-                consoleDisplayMgr.println( vmInstall.getVMRunner( ILaunchManager.RUN_MODE
).toString(),
-                    ConsoleDisplayMgr.MSG_INFORMATION );
-                System.out.println( vmInstall.getName() );
-            }
-        }
-
-        System.out.println( "*****************" );
-
         IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
-        System.out.println( vmInstall.getId() );
-        System.out.println( vmInstall.getName() );
-        System.out.println( vmInstall.getInstallLocation() );
-        System.out.println( vmInstall.getVMArguments() );
-        System.out.println( vmInstall.getVMInstallType() );
-        System.out.println( vmInstall.getVMRunner( ILaunchManager.RUN_MODE ) );
-
-        Thread thread = new Thread()
-        {
-            Logger LOGGER = Logger.getLogger( "testLogger" );
-
-
-            @Override
-            public void run()
-            {
-                for ( int i = 0; i < 10; i++ )
-                {
-                    try
-                    {
-                        sleep( 2000 );
-                    }
-                    catch ( InterruptedException e )
-                    {
-                        // TODO Auto-generated catch block
-                        e.printStackTrace();
-                    }
-
-                    LOGGER.info( "INFO" );
-                    LOGGER.debug( "DEBUG" );
-                    LOGGER.warn( "WARN" );
-                    LOGGER.error( "ERROR" );
-                    LOGGER.fatal( "FATAL" );
-                }
-            }
-        };
-
-        thread.start();
 
         // Testing the launch configuration
         ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java?rev=651311&r1=651310&r2=651311&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java
Thu Apr 24 09:37:36 2008
@@ -24,6 +24,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URL;
 
 import org.eclipse.core.runtime.FileLocator;
@@ -41,6 +42,7 @@
 {
     private static final String RESOURCES = "resources";
     private static final String LIBS = "libs";
+    private static final String INSTANCES = "instances";
     /** The name of the libraries folder */
     private static final String LIBRARIES_FOLDER_NAME = "libs";
     private static final String APACHEDS = "apacheds";
@@ -133,12 +135,7 @@
         FileOutputStream libraryOutputStream = new FileOutputStream( destination );
 
         // Copying the library
-        byte[] buf = new byte[1024];
-        int i = 0;
-        while ( ( i = libraryInputStream.read( buf ) ) != -1 )
-        {
-            libraryOutputStream.write( buf, 0, i );
-        }
+        copyFile( libraryInputStream, libraryOutputStream );
 
         // Closing the streams
         libraryInputStream.close();
@@ -147,6 +144,27 @@
 
 
     /**
+     * Copies a file from the given streams.
+     *
+     * @param inputStream
+     *      the input stream
+     * @param outputStream
+     *      the output stream
+     * @throws IOException
+     *      if an error occurs when copying the file
+     */
+    private static void copyFile( InputStream inputStream, OutputStream outputStream ) throws
IOException
+    {
+        byte[] buf = new byte[1024];
+        int i = 0;
+        while ( ( i = inputStream.read( buf ) ) != -1 )
+        {
+            outputStream.write( buf, 0, i );
+        }
+    }
+
+
+    /**
      * Get the path to the Apache DS libraries folder.
      *
      * @return
@@ -156,5 +174,101 @@
     {
         return Activator.getDefault().getStateLocation().append( LIBRARIES_FOLDER_NAME ).append(
             APACHEDS + "-" + APACHEDS_VERSION );
+    }
+
+
+    /**
+     * Get the path to the Apache DS instances folder.
+     *
+     * @return
+     *      the path to the Apache DS instances folder
+     */
+    public static IPath getApacheDsInstancesFolder()
+    {
+        return Activator.getDefault().getStateLocation().append( INSTANCES );
+    }
+
+
+    /**
+     * Creates a new instance folder for the given id.
+     *
+     * @param id
+     *      the id of the instance
+     */
+    public static void createNewInstanceFolder( String id )
+    {
+        // Checking if the Apache DS instance folder exists
+        checkApacheDsInstancesFolder();
+
+        // Creating the instance folder
+        IPath instanceFolderPath = getApacheDsInstancesFolder().append( id );
+        File instanceFolder = new File( instanceFolderPath.toOSString() );
+        instanceFolder.mkdir();
+
+        // Creating the instance sub folders
+        File confFolder = new File( instanceFolder, "conf" );
+        confFolder.mkdir();
+        new File( instanceFolder, "ldif" ).mkdir();
+        new File( instanceFolder, "log" ).mkdir();
+        new File( instanceFolder, "partitions" ).mkdir();
+
+        // Copying default configuration files
+        try
+        {
+            // Copying apacheds.conf file
+            File apachedsConfFile = new File( confFolder, "apacheds.conf" );
+            copyConfigurationFile( "apacheds.conf", apachedsConfFile );
+
+            // Copying log4j.properties file
+            File log4jPropertiesFile = new File( confFolder, "log4j.properties" );
+            copyConfigurationFile( "log4j.properties", log4jPropertiesFile );
+
+            // Copying server.xml file
+            File serverXmlFile = new File( confFolder, "server.xml" );
+            copyConfigurationFile( "", serverXmlFile );
+        }
+        catch ( IOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * Copies a configuration file.
+     *
+     * @param inputFilename
+     *      the filename
+     * @param ouputFile
+     *      the output file
+     * @throws IOException
+     *      if an error occurs when copying
+     */
+    private static void copyConfigurationFile( String inputFilename, File ouputFile ) throws
IOException
+    {
+        URL inputFilenameUrl = FileLocator.find( Activator.getDefault().getBundle(), new
Path( RESOURCES
+            + IPath.SEPARATOR + "conf" + IPath.SEPARATOR + inputFilename ), null );
+        InputStream inputStream = inputFilenameUrl.openStream();
+        OutputStream outputStream = new FileOutputStream( ouputFile );
+
+        copyFile( inputStream, outputStream );
+
+        inputStream.close();
+        outputStream.close();
+    }
+
+
+    /**
+     * Verifies that the Apache DS instances folder exists.
+     * If it does not exists, it creates it.
+     */
+    private static void checkApacheDsInstancesFolder()
+    {
+        File apacheDsInstancesFolder = new File( getApacheDsInstancesFolder().toOSString()
);
+        if ( !apacheDsInstancesFolder.exists() )
+        {
+            apacheDsInstancesFolder.mkdir();
+        }
     }
 }



Mime
View raw message