[ooo-build-commit] ooeclipse: Branch 'master'

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Mon Oct 5 14:03:47 PDT 2009


 java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java     |   38 +-
 java/source/org/openoffice/ide/eclipse/java/client/CnxProjectHelper.java |  144 ++++++++++
 java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl    |    7 
 3 files changed, 170 insertions(+), 19 deletions(-)

New commits:
commit 0522635cb416303aa8888d726bdffd99d760f5b3
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Mon Oct 5 23:03:26 2009 +0200

    [Java] Separated the Uno connection classes
    
    A new Java project is created specially for the Uno connection classes
    takend from JODConverter. This allows the user to write code under an
    non-LGPL license as the connection classes are used as a library.
    
    Missing: still have to add the LICENSE, AUTHOR files in the generated
    project

diff --git a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java
index 17c53e7..5cc7e36 100644
--- a/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java
+++ b/java/source/org/openoffice/ide/eclipse/java/client/ClientWizard.java
@@ -30,9 +30,11 @@
  ************************************************************************/
 package org.openoffice.ide.eclipse.java.client;
 
+import org.eclipse.core.resources.ICommand;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
@@ -42,6 +44,7 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne;
 import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageTwo;
 import org.eclipse.ui.IWorkbenchPage;
@@ -59,16 +62,8 @@ import org.openoffice.ide.eclipse.java.utils.TemplatesHelper;
  *
  */
 public class ClientWizard extends BasicNewResourceWizard {
-    
-    private static final String[] HELPER_CLASSES = {
-        "AbstractConnection", //$NON-NLS-1$
-        "Connection", //$NON-NLS-1$
-        "OpenOfficeException", //$NON-NLS-1$
-        "PipeConnection", //$NON-NLS-1$
-        "SocketConnection" //$NON-NLS-1$
-    };
 
-    private static final String DEST_PACKAGE = "org.openoffice.connection"; //$NON-NLS-1$
+    private static final String DEST_PACKAGE = "org.openoffice.client"; //$NON-NLS-1$
     private static final String CLIENT_CLASS = "UnoClient"; //$NON-NLS-1$
 
     private IWorkbenchPage mActivePage;
@@ -99,7 +94,7 @@ public class ClientWizard extends BasicNewResourceWizard {
                 
                 try {
                     mThirdPage.performFinish( pMonitor );
-                    setupClientProject( mThirdPage.getJavaProject() );
+                    setupClientProject( mThirdPage.getJavaProject(), pMonitor );
                 } catch ( Exception e ) {
                     PluginLogger.error( Messages.getString("ClientWizard.ProjectCreationError"), e ); //$NON-NLS-1$
                     status = new Status( IStatus.ERROR, OOoJavaPlugin.PLUGIN_ID, 
@@ -116,21 +111,22 @@ public class ClientWizard extends BasicNewResourceWizard {
 
     /**
      * Configure the Java project in order to have a Java UNO client project.
-     *  
+     *
      * @param pJavaProject the Java project to configure
+     * @param pMonitor progress monitor to update
+     * 
+     * @throws Exception if anything wrong happens 
      */
-    protected void setupClientProject(IJavaProject pJavaProject ) {
+    protected void setupClientProject(IJavaProject pJavaProject, IProgressMonitor pMonitor ) throws Exception {
+        
         // Generate the sample classes in org.openoffice.connection
         IProject prj = pJavaProject.getProject();
+        
         IClasspathEntry[] srcEntries = mFirstPage.getSourceClasspathEntries();
         IFolder srcFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder( srcEntries[0].getPath() ); 
         IPath srcPath = srcFolder.getProjectRelativePath();
         
         String path = srcPath.append( DEST_PACKAGE.replace( '.', '/' ) ).toString();
-        for ( String helperClass : HELPER_CLASSES ) {
-            TemplatesHelper.copyTemplate( prj, helperClass, ClientWizard.class, path, DEST_PACKAGE );
-        }
-        
         TemplatesHelper.copyTemplate( prj, CLIENT_CLASS, ClientWizard.class,
                 path, DEST_PACKAGE, mCnxPage.getConnectionCode() );
         
@@ -148,6 +144,16 @@ public class ClientWizard extends BasicNewResourceWizard {
         IFile javaClientFile = srcDir.getFile( CLIENT_CLASS + ".java" ); //$NON-NLS-1$
         selectAndReveal( javaClientFile );
         WorkbenchHelper.showFile( javaClientFile, mActivePage );
+        
+        // Create the Uno connection project
+        IJavaProject cnxPrj = CnxProjectHelper.getConnectionProject( mCnxPage.getOoo(), pMonitor );
+        if ( cnxPrj != null ) {
+            IClasspathEntry[] oldClasspath = pJavaProject.getRawClasspath();
+            IClasspathEntry[] classpath = new IClasspathEntry[ oldClasspath.length + 1 ];
+            classpath[0] = JavaCore.newProjectEntry( cnxPrj.getProject().getFullPath() );
+            System.arraycopy( oldClasspath, 0, classpath, 1, oldClasspath.length );
+            pJavaProject.setRawClasspath( classpath, pMonitor );
+        }
     }
 
     @Override
diff --git a/java/source/org/openoffice/ide/eclipse/java/client/CnxProjectHelper.java b/java/source/org/openoffice/ide/eclipse/java/client/CnxProjectHelper.java
new file mode 100644
index 0000000..25ad719
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/client/CnxProjectHelper.java
@@ -0,0 +1,144 @@
+package org.openoffice.ide.eclipse.java.client;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.openoffice.ide.eclipse.core.model.config.IOOo;
+import org.openoffice.ide.eclipse.java.JavaProjectHandler;
+import org.openoffice.ide.eclipse.java.OOoJavaPlugin;
+import org.openoffice.ide.eclipse.java.utils.TemplatesHelper;
+
+/**
+ * Helper class for the creation of the UNO connection library project.
+ * 
+ * @author cbosdonnat
+ *
+ */
+public class CnxProjectHelper {
+
+    public static final String DEST_PACKAGE = "org.openoffice.connection"; //$NON-NLS-1$
+    
+    private static final String[] HELPER_CLASSES = {
+        "AbstractConnection", //$NON-NLS-1$
+        "Connection", //$NON-NLS-1$
+        "OpenOfficeException", //$NON-NLS-1$
+        "PipeConnection", //$NON-NLS-1$
+        "SocketConnection" //$NON-NLS-1$
+    };
+    
+    // TODO Should be configured ?
+    private static final String CNX_PROJECT_NAME = "Java Uno Connector"; //$NON-NLS-1$
+    private static final String SRC_DIR = "src"; //$NON-NLS-1$
+    private static final String BIN_DIR = "bin"; //$NON-NLS-1$
+
+    private static final String JRE_ID = "org.eclipse.jdt.launching.JRE_CONTAINER"; //$NON-NLS-1$
+    
+    
+    /**
+     * Get the java project named {@value #CNX_PROJECT_NAME} if it exists or create it.
+     *  
+     * <p>This project contains the LGPL library for the UNO Connection and should
+     * be used as a dependency of the Java UNO Client projects.</p>
+     * 
+     * @param pOOo the OOo instance to use as project's dependencies
+     * @param pMonitor a progress monitor to use for reporting the progress
+     *  
+     * @return the connector project
+     * 
+     * @throws Exception if the project can't be created or opened
+     */
+    public static IJavaProject getConnectionProject( IOOo pOOo, IProgressMonitor pMonitor ) throws Exception {
+        
+        IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject( CNX_PROJECT_NAME );
+        
+        boolean creating = false;
+        if ( !prj.exists() ) {
+            IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription( CNX_PROJECT_NAME );
+            desc.setNatureIds( new String[] { JavaCore.NATURE_ID } );
+            prj.create( desc, pMonitor );
+            creating = true;
+        }
+        
+        if ( !prj.isOpen() ) {
+            // Opens the project if it is closed
+            prj.open( pMonitor );
+        }
+        
+        // Create the src folder if not existing
+        IFolder src = prj.getFolder( SRC_DIR );
+        if ( !src.exists() ) {
+            src.create( true, true, pMonitor );
+        }
+        
+        IFolder bin = prj.getFolder( BIN_DIR );
+        if ( !bin.exists() ) {
+            bin.create( true, true, pMonitor );
+        }
+        
+        IJavaProject cnxPrj = null;
+        // Create & configure the java project
+        if ( creating ) {
+            cnxPrj = JavaCore.create( prj );
+            IClasspathEntry srcEntry = JavaCore.newSourceEntry( src.getFullPath() );
+            IClasspathEntry jreEntry = JavaCore.newContainerEntry( new Path( JRE_ID ) );
+            cnxPrj.setRawClasspath( new IClasspathEntry[] { srcEntry, jreEntry }, pMonitor );
+            cnxPrj.setOutputLocation( bin.getFullPath(), pMonitor );
+            cnxPrj.save( pMonitor, true );
+            
+            JavaProjectHandler prjHandler = new JavaProjectHandler();
+            prjHandler.addOOoDependencies( pOOo, prj );
+            
+            // Set the Java builder
+            setJavaBuilder( prj, pMonitor );
+            
+            // Add the sources 
+            String path = src.getProjectRelativePath().append( DEST_PACKAGE.replace( '.', '/' ) ).toString();
+            for ( String helperClass : HELPER_CLASSES ) {
+                TemplatesHelper.copyTemplate( prj, helperClass, ClientWizard.class, path, DEST_PACKAGE );
+            }
+            prj.refreshLocal( IResource.DEPTH_INFINITE, pMonitor );
+        } else if ( prj.hasNature( JavaCore.NATURE_ID ) ) {
+            cnxPrj = JavaCore.create( prj );
+        } else {
+            throw new CoreException( new Status( IStatus.ERROR, OOoJavaPlugin.PLUGIN_ID, 
+                    "Already existing non-Java project: " + CNX_PROJECT_NAME ) );
+        }
+        
+        return cnxPrj;
+    }
+
+
+    /**
+     * Add the Java builder to the the project builders. 
+     * 
+     * @param pPrj the project on which to add the Java builder
+     * @param pMonitor the monitor to report the progress
+     * 
+     * @throws CoreException if the project's description can't be get or set
+     */
+    private static void setJavaBuilder(IProject pPrj, IProgressMonitor pMonitor) throws CoreException {
+        IProjectDescription descr = pPrj.getDescription();
+        ICommand[] builders = descr.getBuildSpec();
+        ICommand[] newCommands = new ICommand[builders.length + 1];
+    
+        ICommand typesbuilderCommand = descr.newCommand();
+        typesbuilderCommand.setBuilderName( JavaCore.BUILDER_ID );
+        newCommands[0] = typesbuilderCommand;
+        
+        System.arraycopy( builders, 0, newCommands, 1, builders.length );
+        
+        descr.setBuildSpec( newCommands );
+        pPrj.setDescription( descr, pMonitor );
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl b/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl
index 78a5df7..de7e165 100644
--- a/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl
+++ b/java/source/org/openoffice/ide/eclipse/java/client/UnoClient.java.tpl
@@ -1,8 +1,9 @@
 package {0};
 
-import com.sun.star.frame.XDesktop;
-import com.sun.star.text.XTextDocument;
-import com.sun.star.uno.UnoRuntime;
+import org.openoffice.connection.AbstractConnection;
+import org.openoffice.connection.PipeConnection;
+import org.openoffice.connection.SocketConnection;
+
 import com.sun.star.uno.XComponentContext;
 
 public class UnoClient '{'


More information about the ooo-build-commit mailing list