Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 98341 invoked from network); 24 Apr 2008 13:33:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Apr 2008 13:33:20 -0000 Received: (qmail 6216 invoked by uid 500); 24 Apr 2008 13:33:21 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 6181 invoked by uid 500); 24 Apr 2008 13:33:21 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 6170 invoked by uid 99); 24 Apr 2008 13:33:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Apr 2008 06:33:21 -0700 X-ASF-Spam-Status: No, hits=-1998.0 required=10.0 tests=ALL_TRUSTED,URIBL_BLACK X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Apr 2008 13:32:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D40391A9832; Thu, 24 Apr 2008 06:32:50 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r651263 - in /directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations: Activator.java PluginUtils.java Date: Thu, 24 Apr 2008 13:32:49 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080424133250.D40391A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Thu Apr 24 06:32:47 2008 New Revision: 651263 URL: http://svn.apache.org/viewvc?rev=651263&view=rev Log: Updated the Activator. o When the plugin is started, it verifies the Apache DS libraries and eventually copy them in the plugin's folder. o Apache DS is launched from the libraries copied in the plugin's folder. Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/Activator.java 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=651263&r1=651262&r2=651263&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 06:32:47 2008 @@ -51,7 +51,6 @@ */ public class Activator extends AbstractUIPlugin { - // The plug-in ID public static final String PLUGIN_ID = "org.apache.directory.studio.apacheds.experimentations"; private static Logger logger = Logger.getLogger( Activator.class ); @@ -80,6 +79,8 @@ super.start( context ); plugin = this; + PluginUtils.verifyLibrariesFolder(); + // Configuring Log4J PropertyConfigurator.configure( Platform.getBundle( PLUGIN_ID ).getResource( "log4j.properties" ) ); //$NON-NLS-1$ logger.info( "Entering Apache Directory Studio." ); //$NON-NLS-1$ @@ -159,19 +160,29 @@ workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, vmInstall .getInstallLocation().toString() ); workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, - "org.apache.directory.server.Main" ); + "org.apache.directory.server.UberjarMain" ); - IPath bootstrapPath = new Path( "/Users/pajbam/Desktop/apacheds-main.jar" ); - IRuntimeClasspathEntry bootstrapEntry = JavaRuntime.newArchiveRuntimeClasspathEntry( bootstrapPath ); - bootstrapEntry.setClasspathProperty( IRuntimeClasspathEntry.USER_CLASSES ); + String[] libraries = PluginUtils.apachedsLibraries; + IPath apacheDsLibrariesFolder = PluginUtils.getApacheDsLibrariesFolder(); List classpath = new ArrayList(); - classpath.add( bootstrapEntry.getMemento() ); + for ( String library : libraries ) + { + IPath libraryPath = apacheDsLibrariesFolder.append( library ); + IRuntimeClasspathEntry libraryClasspathEntry = JavaRuntime.newArchiveRuntimeClasspathEntry( libraryPath ); + libraryClasspathEntry.setClasspathProperty( IRuntimeClasspathEntry.USER_CLASSES ); + classpath.add( libraryClasspathEntry.getMemento() ); + } + workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath ); workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false ); + workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, + "/usr/local/apacheds-1.5.2/conf/server.xml" ); + ILaunchConfiguration configuration = workingCopy.doSave(); DebugUITools.launch( configuration, ILaunchManager.RUN_MODE ); + } @@ -194,7 +205,7 @@ } - /* + /** * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ Added: 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=651263&view=auto ============================================================================== --- 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/src/main/java/org/apache/directory/studio/apacheds/experimentations/PluginUtils.java Thu Apr 24 06:32:47 2008 @@ -0,0 +1,160 @@ +/* + * 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. + * + */ +package org.apache.directory.studio.apacheds.experimentations; + + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + + +/** + * This class contains helpful methods. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class PluginUtils +{ + private static final String RESOURCES = "resources"; + private static final String LIBS = "libs"; + /** The name of the libraries folder */ + private static final String LIBRARIES_FOLDER_NAME = "libs"; + private static final String APACHEDS = "apacheds"; + /** The version of ApacheDS bundle with the plugin */ + private static final String APACHEDS_VERSION = "1.5.2"; + + /** This array of String contains all filenames of the needed libraries to launch Apache DS */ + public static final String[] apachedsLibraries = new String[] + { "antlr-2.7.7.jar", "apacheds-bootstrap-extract-1.5.2.jar", "apacheds-bootstrap-partition-1.5.2.jar", + "apacheds-btree-base-1.5.2.jar", "apacheds-core-1.5.2.jar", "apacheds-core-constants-1.5.2.jar", + "apacheds-core-entry-1.5.2.jar", "apacheds-core-shared-1.5.2.jar", "apacheds-jdbm-store-1.5.2.jar", + "apacheds-kerberos-shared-1.5.2.jar", "apacheds-noarch-installer-1.5.2.jar", + "apacheds-protocol-changepw-1.5.2.jar", "apacheds-protocol-dns-1.5.2.jar", + "apacheds-protocol-kerberos-1.5.2.jar", "apacheds-protocol-ldap-1.5.2.jar", + "apacheds-protocol-ntp-1.5.2.jar", "apacheds-protocol-shared-1.5.2.jar", + "apacheds-schema-bootstrap-1.5.2.jar", "apacheds-schema-extras-1.5.2.jar", + "apacheds-schema-registries-1.5.2.jar", "apacheds-server-jndi-1.5.2.jar", "apacheds-server-xml-1.5.2.jar", + "apacheds-utils-1.5.2.jar", "apacheds-xbean-spring-1.5.2.jar", "bootstrapper.jar", "commons-cli-1.1.jar", + "commons-collections-3.2.jar", "commons-daemon-1.0.1.jar", "commons-lang-2.3.jar", + "jcl104-over-slf4j-1.4.3.jar", "jdbm-1.0.jar", "log4j-1.2.14.jar", "mina-core-1.1.2.jar", + "mina-filter-ssl-1.1.2.jar", "shared-asn1-0.9.10.jar", "shared-asn1-codec-0.9.10.jar", + "shared-bouncycastle-reduced-0.9.10.jar", "shared-ldap-0.9.10.jar", "shared-ldap-constants-0.9.10.jar", + "slf4j-api-1.4.3.jar", "slf4j-log4j12-1.4.3.jar", "spring-beans-2.0.6.jar", "spring-context-2.0.6.jar", + "spring-core-2.0.6.jar", "xbean-spring-3.2.jar" }; + + + /** + * Verifies that the libraries folder exists and contains the jar files + * needed to launch the server. + */ + public static void verifyLibrariesFolder() + { + IPath stateLocationPath = Activator.getDefault().getStateLocation(); + + // Libraries folder + IPath librariesFolderPath = stateLocationPath.append( LIBRARIES_FOLDER_NAME ); + File librariesFolder = new File( librariesFolderPath.toOSString() ); + if ( !librariesFolder.exists() ) + { + librariesFolder.mkdir(); + } + + // Specific Apache DS folder + IPath apacheDsFolderPath = librariesFolderPath.append( APACHEDS + "-" + APACHEDS_VERSION ); + File apacheDsFolder = new File( apacheDsFolderPath.toOSString() ); + if ( !apacheDsFolder.exists() ) + { + apacheDsFolder.mkdir(); + } + + // Jar libraries + for ( String apachedsLibraryFilename : apachedsLibraries ) + { + IPath apachedsLibraryPath = apacheDsFolderPath.append( apachedsLibraryFilename ); + File apachedsLibrary = new File( apachedsLibraryPath.toOSString() ); + if ( !apachedsLibrary.exists() ) + { + try + { + copyLibrary( apachedsLibraryFilename, apachedsLibrary ); + } + catch ( IOException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + + /** + * Copy the given library. + * + * @param library + * the name of the library + * @param destination + * the destination + * @throws IOException + * if an error occurrs when copying the jar file + */ + private static void copyLibrary( String library, File destination ) throws IOException + { + // Getting he URL of the library within the bundle + URL libraryUrl = FileLocator.find( Activator.getDefault().getBundle(), new Path( RESOURCES + IPath.SEPARATOR + + LIBS + IPath.SEPARATOR + library ), null ); + + // Creating the input and output streams + InputStream libraryInputStream = libraryUrl.openStream(); + 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 ); + } + + // Closing the streams + libraryInputStream.close(); + libraryOutputStream.close(); + } + + + /** + * Get the path to the Apache DS libraries folder. + * + * @return + * the path to the Apache DS libraries folder + */ + public static IPath getApacheDsLibrariesFolder() + { + return Activator.getDefault().getStateLocation().append( LIBRARIES_FOLDER_NAME ).append( + APACHEDS + "-" + APACHEDS_VERSION ); + } +}