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

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Wed Aug 26 23:38:55 PDT 2009


 core/source/org/openoffice/ide/eclipse/core/editors/main/AbstractOverviewSection.java |    2 
 core/source/org/openoffice/ide/eclipse/core/editors/main/GeneralSection.java          |    2 
 core/source/org/openoffice/ide/eclipse/core/editors/main/PackageOverviewFormPage.java |   57 -
 core/source/org/openoffice/ide/eclipse/core/editors/messages.properties               |    8 
 core/source/org/openoffice/ide/eclipse/core/i18n/ImageManager.properties              |   56 -
 core/source/org/openoffice/ide/eclipse/core/internal/model/UnoFactory.java            |    2 
 core/source/org/openoffice/ide/eclipse/core/model/language/IProjectHandler.java       |    8 
 cpp/source/org/openoffice/ide/eclipse/cpp/CppProjectHandler.java                      |    6 
 java/META-INF/MANIFEST.MF                                                             |    3 
 java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java                   |   20 
 java/source/org/openoffice/ide/eclipse/java/JavaWizardPage.java                       |   34 -
 java/source/org/openoffice/ide/eclipse/java/registration/RegistrationHelper.java      |   63 -
 java/source/org/openoffice/ide/eclipse/java/registration/messages.properties          |    2 
 java/source/org/openoffice/ide/eclipse/java/tests/AllTests.java.tpl                   |   44 +
 java/source/org/openoffice/ide/eclipse/java/tests/Messages.java                       |   22 
 java/source/org/openoffice/ide/eclipse/java/tests/ProjectTest.java.tpl                |   35 +
 java/source/org/openoffice/ide/eclipse/java/tests/TestsHelper.java                    |   94 ++
 java/source/org/openoffice/ide/eclipse/java/tests/base/Bootstrap.java.tpl             |  337 ++++++++++
 java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestCase.java.tpl           |   69 ++
 java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestSuite.java.tpl          |  145 ++++
 java/source/org/openoffice/ide/eclipse/java/tests/messages.properties                 |    1 
 java/source/org/openoffice/ide/eclipse/java/utils/TemplatesHelper.java                |  135 ++++
 java/source/org/openoffice/ide/eclipse/java/utils/messages.properties                 |    3 
 23 files changed, 994 insertions(+), 154 deletions(-)

New commits:
commit 1eebdfb4b8202a6e63da6185a88a32df673dbd72
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Aug 27 08:38:08 2009 +0200

    Added some unit test classes to the Java project
    
    These base classes have been taken from the COOoder extension and are
    generated to help the user to write his own Unit tests for his
    extension.

diff --git a/core/source/org/openoffice/ide/eclipse/core/internal/model/UnoFactory.java b/core/source/org/openoffice/ide/eclipse/core/internal/model/UnoFactory.java
index 41ff267..e2c5d2f 100644
--- a/core/source/org/openoffice/ide/eclipse/core/internal/model/UnoFactory.java
+++ b/core/source/org/openoffice/ide/eclipse/core/internal/model/UnoFactory.java
@@ -123,8 +123,6 @@ public final class UnoFactory {
                 IUnoFactoryConstants.PROJECT_LANGUAGE);
         language.getProjectHandler().configureProject(pData);
         
-        language.getProjectHandler().createRegistrationSystem(prj);
-        
         return prj;
     }
     
diff --git a/core/source/org/openoffice/ide/eclipse/core/model/language/IProjectHandler.java b/core/source/org/openoffice/ide/eclipse/core/model/language/IProjectHandler.java
index 4e9c5a0..48f193d 100644
--- a/core/source/org/openoffice/ide/eclipse/core/model/language/IProjectHandler.java
+++ b/core/source/org/openoffice/ide/eclipse/core/model/language/IProjectHandler.java
@@ -154,12 +154,4 @@ public interface IProjectHandler {
      * <code>File</code> class constructor.
      */
     public String getLibraryPath(IUnoidlProject pPrj);
-    
-    /**
-     * Adds the necessary code for the registration of several services
-     * implementation.
-     * 
-     * @param pPrj the project where to add the registration system
-     */
-    public void createRegistrationSystem(IUnoidlProject pPrj);
 }
diff --git a/cpp/source/org/openoffice/ide/eclipse/cpp/CppProjectHandler.java b/cpp/source/org/openoffice/ide/eclipse/cpp/CppProjectHandler.java
index 88e9888..1255164 100644
--- a/cpp/source/org/openoffice/ide/eclipse/cpp/CppProjectHandler.java
+++ b/cpp/source/org/openoffice/ide/eclipse/cpp/CppProjectHandler.java
@@ -104,12 +104,6 @@ public class CppProjectHandler implements IProjectHandler {
         // TODO Auto-generated method stub
 
     }
-
-    @Override
-    public void createRegistrationSystem(IUnoidlProject prj) {
-        // TODO Auto-generated method stub
-
-    }
     
     /**
      * {@inheritDoc}
diff --git a/java/META-INF/MANIFEST.MF b/java/META-INF/MANIFEST.MF
index c3bb516..049fba1 100644
--- a/java/META-INF/MANIFEST.MF
+++ b/java/META-INF/MANIFEST.MF
@@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.jdt.launching,
  org.eclipse.jdt,
  org.eclipse.jdt.ui,
- org.eclipse.jface.text
+ org.eclipse.jface.text,
+ org.eclipse.jdt.junit;bundle-version="3.5.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java b/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java
index 9283018..a464439 100644
--- a/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java
+++ b/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java
@@ -66,6 +66,7 @@ import org.openoffice.ide.eclipse.core.model.language.IProjectHandler;
 import org.openoffice.ide.eclipse.core.preferences.IOOo;
 import org.openoffice.ide.eclipse.java.build.OOoContainerPage;
 import org.openoffice.ide.eclipse.java.registration.RegistrationHelper;
+import org.openoffice.ide.eclipse.java.tests.TestsHelper;
 
 /**
  * The Project handler implementation for Java.
@@ -175,6 +176,18 @@ public class JavaProjectHandler implements IProjectHandler {
         String javaversion = (String)pData.getProperty(
                 JavaWizardPage.JAVA_VERSION);
         unoprj.setProperty(P_JAVA_VERSION, javaversion);
+        
+        // Add the registration files
+        RegistrationHelper.generateFiles( unoprj );
+        
+        // Tests creation
+        Boolean usetests = (Boolean)pData.getProperty( JavaWizardPage.JAVA_TESTS );
+        if ( usetests.booleanValue() ) {
+            TestsHelper.writeTestClasses( unoprj );
+            
+            IJavaProject javaprj = JavaCore.create( prj );
+            TestsHelper.addJUnitLibraries( javaprj );
+        }
     }
 
     /**
@@ -231,13 +244,6 @@ public class JavaProjectHandler implements IProjectHandler {
     public String getLibraryPath(IUnoidlProject pProject) {
         return getJarFile(pProject).getAbsolutePath();
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void createRegistrationSystem(IUnoidlProject pProject) {
-        RegistrationHelper.generateFiles(pProject);
-    }
     
     /**
      * Returns a handle to the project jar file. Beware that this handle
diff --git a/java/source/org/openoffice/ide/eclipse/java/JavaWizardPage.java b/java/source/org/openoffice/ide/eclipse/java/JavaWizardPage.java
index b17d993..a90087e 100644
--- a/java/source/org/openoffice/ide/eclipse/java/JavaWizardPage.java
+++ b/java/source/org/openoffice/ide/eclipse/java/JavaWizardPage.java
@@ -47,6 +47,7 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.openoffice.ide.eclipse.core.gui.rows.BooleanRow;
 import org.openoffice.ide.eclipse.core.gui.rows.ChoiceRow;
 import org.openoffice.ide.eclipse.core.gui.rows.FieldEvent;
 import org.openoffice.ide.eclipse.core.gui.rows.IFieldChangedListener;
@@ -62,17 +63,13 @@ import org.openoffice.ide.eclipse.core.model.language.LanguageWizardPage;
 public class JavaWizardPage extends LanguageWizardPage {
 
     public static final String JAVA_VERSION = "java_version"; //$NON-NLS-1$
+    public static final String JAVA_TESTS = "java_tests"; //$NON-NLS-1$
     
     private ChoiceRow mJavaVersionRow;
+    private BooleanRow mJavaTestsRow;
     
     private String mJavaVersion;
-    
-    private IFieldChangedListener mListener = new IFieldChangedListener() {
-
-        public void fieldChanged(FieldEvent pEvent) {
-            mJavaVersion = mJavaVersionRow.getValue();
-        }
-    };
+    private boolean mUseTests;
     
     /**
      * Constructor.
@@ -93,8 +90,9 @@ public class JavaWizardPage extends LanguageWizardPage {
      * {@inheritDoc}
      */
     public void setProjectInfos(UnoFactoryData pData) {
-        // default value
+        // default values
         mJavaVersion = "java4"; //$NON-NLS-1$
+        mUseTests = true;
     }
     
     /**
@@ -104,6 +102,7 @@ public class JavaWizardPage extends LanguageWizardPage {
         
         if (pData != null) {
             pData.setProperty(JAVA_VERSION, mJavaVersion);
+            pData.setProperty(JAVA_TESTS, mUseTests);
         }
         
         return pData;
@@ -118,14 +117,31 @@ public class JavaWizardPage extends LanguageWizardPage {
         body.setLayout(new GridLayout(2, false));
         body.setLayoutData(new GridData(GridData.FILL_BOTH));
         
+        // Create the Java version row
         mJavaVersionRow = new ChoiceRow(body, JAVA_VERSION, 
                 Messages.getString("JavaWizardPage.JavaVersion")); //$NON-NLS-1$
         mJavaVersionRow.add(Messages.getString("JavaWizardPage.Java4"), "java4"); //$NON-NLS-1$ //$NON-NLS-2$
         mJavaVersionRow.add(Messages.getString("JavaWizardPage.Java5"), "java5"); //$NON-NLS-1$ //$NON-NLS-2$
-        mJavaVersionRow.setFieldChangedListener(mListener);
+        mJavaVersionRow.setFieldChangedListener( new IFieldChangedListener() {
+            
+            public void fieldChanged(FieldEvent pEvent) {
+                mJavaVersion = mJavaVersionRow.getValue();
+            }
+        });
         mJavaVersionRow.select(0);
         mJavaVersionRow.setTooltip(Messages.getString("JavaWizardPage.JavaVersionTooltip")); //$NON-NLS-1$
         
+        // Create the test row
+        mJavaTestsRow = new BooleanRow( body, JAVA_TESTS, 
+                "Include base classes for tests" );
+        mJavaTestsRow.setValue( true );
+        mJavaTestsRow.setFieldChangedListener( new IFieldChangedListener() {
+            
+            public void fieldChanged(FieldEvent pEvent) {
+                mUseTests = mJavaTestsRow.getBooleanValue();
+            }
+        });
+        
         setControl(body);
     }
 }
diff --git a/java/source/org/openoffice/ide/eclipse/java/registration/RegistrationHelper.java b/java/source/org/openoffice/ide/eclipse/java/registration/RegistrationHelper.java
index 842ea0f..06ac9e5 100644
--- a/java/source/org/openoffice/ide/eclipse/java/registration/RegistrationHelper.java
+++ b/java/source/org/openoffice/ide/eclipse/java/registration/RegistrationHelper.java
@@ -59,6 +59,7 @@ import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.runtime.IPath;
 import org.openoffice.ide.eclipse.core.PluginLogger;
 import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
+import org.openoffice.ide.eclipse.java.utils.TemplatesHelper;
 
 /**
  * This class provides utility methods to generate the class and files needed
@@ -79,66 +80,8 @@ public abstract class RegistrationHelper {
      */
     public static void generateFiles(IUnoidlProject pProject) {
         
-        // Get the path where to place the class and the implementations list
-        IPath relPath = pProject.getImplementationPath();
-        IFolder dest = pProject.getFolder(relPath);
-        
-        // Compute the name of the main implementation class
-        String implPkg = pProject.getCompanyPrefix() + "." + pProject.getOutputExtension(); //$NON-NLS-1$
-        
-        // Create the RegistrationHandler.java file
-
-        StringBuffer pattern = new StringBuffer();
-        
-        BufferedReader patternReader = null;
-        InputStream in = null;
-        try {
-            in = RegistrationHelper.class.getResourceAsStream("RegistrationHandler.java.tpl"); //$NON-NLS-1$
-            patternReader = new BufferedReader(new InputStreamReader(in));
-            String line = patternReader.readLine();
-            while (line != null) {
-                pattern.append(line + "\n"); //$NON-NLS-1$
-                line = patternReader.readLine();
-            }
-        } catch (IOException e) {
-            // log the error
-            PluginLogger.error(Messages.getString("RegistrationHelper.ReadTemplateError"), e); //$NON-NLS-1$
-        } finally {
-            try {
-                patternReader.close();
-                in.close();
-            } catch (Exception e) {
-            }
-        }
-        
-        if (pattern.length() > 0) {
-            String content = MessageFormat.format(pattern.toString(), new Object[]{implPkg});
-
-            FileWriter writer = null;
-            try {
-                IFile classIFile = dest.getFile(CLASS_FILENAME + ".java"); //$NON-NLS-1$
-                File classFile = classIFile.getLocation().toFile();
-                
-                if (!classFile.exists()) {
-                    classFile.getParentFile().mkdirs();
-                    classFile.createNewFile();
-                }
-                
-                writer = new FileWriter(classFile);
-                writer.append(content);
-                
-                // Define the new registration class
-                
-                
-            } catch (IOException e) {
-                PluginLogger.error(Messages.getString("RegistrationHelper.WriteClassError"), e); //$NON-NLS-1$
-            } finally {
-                try {
-                    writer.close();
-                } catch (Exception e) {
-                }
-            }
-        }
+        // Copy the RegistrationHandler.java.tpl file
+        TemplatesHelper.copyTemplate( pProject, CLASS_FILENAME, RegistrationHelper.class, new String( ) );
         
         // Create the empty RegistrationHandler.classes file
         ByteArrayInputStream empty = new ByteArrayInputStream(new byte[0]);
diff --git a/java/source/org/openoffice/ide/eclipse/java/registration/messages.properties b/java/source/org/openoffice/ide/eclipse/java/registration/messages.properties
index 5baee50..28a67f8 100644
--- a/java/source/org/openoffice/ide/eclipse/java/registration/messages.properties
+++ b/java/source/org/openoffice/ide/eclipse/java/registration/messages.properties
@@ -1,4 +1,2 @@
 FileRefreshJob.Error=Can't refresh the registration classes file
-RegistrationHelper.ReadTemplateError=Error during registration class creation [reading template]
-RegistrationHelper.WriteClassError=Error during registration class creation [writing class]
 RegistrationHelper.WriteClassesListError=Error during classes list writing
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/AllTests.java.tpl b/java/source/org/openoffice/ide/eclipse/java/tests/AllTests.java.tpl
new file mode 100644
index 0000000..6324a2a
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/AllTests.java.tpl
@@ -0,0 +1,44 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  Cédric Bosdonnat cedricbosdo at openoffice.org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package {0}.tests;
+
+import junit.framework.Test;
+
+import {0}.tests.base.UnoTestSuite;
+
+
+/**
+ * This is a sample class to create UNO test suites using JUnit
+ */
+public class AllTests  '{'
+
+    public static Test suite() '{'
+        
+        // The tests to run by the suite
+        Class[] testClasses = new Class[] '{'
+                ProjectTest.class
+                // TODO Add some more test cases here 
+        };
+        
+        // Create the test suite
+        UnoTestSuite suite = new UnoTestSuite(testClasses);
+        
+        return suite;
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/Messages.java b/java/source/org/openoffice/ide/eclipse/java/tests/Messages.java
new file mode 100644
index 0000000..4e5f522
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/Messages.java
@@ -0,0 +1,22 @@
+package org.openoffice.ide.eclipse.java.tests;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+    private static final String BUNDLE_NAME = "org.openoffice.ide.eclipse.java.tests.messages"; //$NON-NLS-1$
+
+    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+            .getBundle(BUNDLE_NAME);
+
+    private Messages() {
+    }
+
+    public static String getString(String key) {
+        try {
+            return RESOURCE_BUNDLE.getString(key);
+        } catch (MissingResourceException e) {
+            return '!' + key + '!';
+        }
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/ProjectTest.java.tpl b/java/source/org/openoffice/ide/eclipse/java/tests/ProjectTest.java.tpl
new file mode 100644
index 0000000..69092ac
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/ProjectTest.java.tpl
@@ -0,0 +1,35 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  Cédric Bosdonnat cedricbosdo at openoffice.org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package {0}.tests;
+
+import {0}.tests.base.UnoTestCase;
+
+
+
+/**
+ * This is a sample Unit test case for Uno extensions, feel free to create more of them.
+ */
+public class ProjectTest extends UnoTestCase '{'
+
+    public void testSomething() '{'
+        // TODO Write a unit test here
+    }
+    
+    // TODO Add some more tests methods
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/TestsHelper.java b/java/source/org/openoffice/ide/eclipse/java/tests/TestsHelper.java
new file mode 100644
index 0000000..cb1c9b9
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/TestsHelper.java
@@ -0,0 +1,94 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the GNU Lesser General Public License Version 2.1
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2009 by Cédric Bosdonnat.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ * 
+ * The Initial Developer of the Original Code is: Cédric Bosdonnat.
+ *
+ * Copyright: 2009 by Cédric Bosdonnat.
+ *
+ * All Rights Reserved.
+ * 
+ ************************************************************************/
+package org.openoffice.ide.eclipse.java.tests;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.junit.buildpath.JUnitContainerInitializer;
+import org.openoffice.ide.eclipse.core.PluginLogger;
+import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
+import org.openoffice.ide.eclipse.java.utils.TemplatesHelper;
+
+/**
+ * Class used to generate the test files in the Java project.
+ * 
+ * @author cbosdonnat
+ *
+ */
+public class TestsHelper {
+    
+    private static final String[] TEMPLATES = new String[] {
+        "AllTests", //$NON-NLS-1$
+        "ProjectTest", //$NON-NLS-1$
+        "base/Bootstrap", //$NON-NLS-1$
+        "base/UnoTestCase", //$NON-NLS-1$
+        "base/UnoTestSuite" //$NON-NLS-1$
+    };
+    private static final String TEST_PATH = "tests"; //$NON-NLS-1$
+    
+    /**
+     * Creates all the test classes files in the UNO project.
+     * 
+     * @param pProject the destination UNO project
+     */
+    public static void writeTestClasses( IUnoidlProject pProject ) {
+        for (String template : TEMPLATES) {
+            TemplatesHelper.copyTemplate( pProject, template, TestsHelper.class, TEST_PATH );
+        }
+    }
+    
+    /**
+     * Add the JUnit3 library to the project libraries.
+     * 
+     * @param pProject the project to add the libraries on
+     */
+    @SuppressWarnings("restriction")
+    public static void addJUnitLibraries( IJavaProject pProject ) {
+        try {
+            IClasspathEntry[] oldEntries = pProject.getRawClasspath();
+            IClasspathEntry[] entries = new IClasspathEntry[oldEntries.length + 1];
+            
+            System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length);
+            
+            IPath path = JUnitContainerInitializer.JUNIT3_PATH;
+            IClasspathEntry containerEntry = JavaCore.newContainerEntry(path);
+            entries[entries.length - 1] = containerEntry;
+            
+            pProject.setRawClasspath(entries, null);
+        } catch (JavaModelException e) {
+            PluginLogger.error(
+                    Messages.getString("TestsHelper.AddJUnitError"), e); //$NON-NLS-1$
+        }
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/base/Bootstrap.java.tpl b/java/source/org/openoffice/ide/eclipse/java/tests/base/Bootstrap.java.tpl
new file mode 100644
index 0000000..b343372
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/base/Bootstrap.java.tpl
@@ -0,0 +1,337 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: Bootstrap.java,v $
+ * $Revision: 1.16 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package {0}.tests.base;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Random;
+
+import com.sun.star.bridge.UnoUrlResolver;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.comp.helper.BootstrapException;
+import com.sun.star.comp.helper.ComponentContext;
+import com.sun.star.comp.helper.ComponentContextEntry;
+import com.sun.star.comp.loader.JavaLoader;
+import com.sun.star.container.XSet;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.util.NativeLibraryLoader;
+import com.sun.star.loader.XImplementationLoader;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+/** Bootstrap offers functionality to obtain a context or simply
+    a service manager.
+    The service manager can create a few basic services, whose implementations  are:
+    <ul>
+    <li>com.sun.star.comp.loader.JavaLoader</li>
+    <li>com.sun.star.comp.urlresolver.UrlResolver</li>
+    <li>com.sun.star.comp.bridgefactory.BridgeFactory</li>
+    <li>com.sun.star.comp.connections.Connector</li>
+    <li>com.sun.star.comp.connections.Acceptor</li>
+    <li>com.sun.star.comp.servicemanager.ServiceManager</li>
+    </ul>
+
+    Other services can be inserted into the service manager by
+    using its XSet interface:
+    <pre>
+        XSet xSet = (XSet)UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
+        // insert the service manager
+        xSet.insert( aSingleComponentFactory );
+    </pre>
+    
+    @author cbosdo Changed the class for a better control of the bootstrap using a custom classloader
+*/  
+public class Bootstrap '{'
+    
+    private static void insertBasicFactories(
+        XSet xSet, XImplementationLoader xImpLoader )
+        throws Exception
+    '{'
+        // insert the factory of the loader        
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.loader.JavaLoader", null, null, null ) );
+        
+        // insert the factory of the URLResolver        
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) );
+        
+        // insert the bridgefactory
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null ) );
+        
+        // insert the connector
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.connections.Connector", null, null, null ) );
+        
+        // insert the acceptor
+        xSet.insert( xImpLoader.activate(
+            "com.sun.star.comp.connections.Acceptor", null, null, null ) );
+    }
+    
+    /** Bootstraps an initial component context with service manager and basic
+        jurt components inserted.
+        @param context_entries the hash table contains mappings of entry names (type string) to
+        context entries (type class ComponentContextEntry).
+        @return a new context.
+    */
+    static public XComponentContext createInitialComponentContext( Hashtable context_entries )
+        throws Exception
+    '{'
+        XImplementationLoader xImpLoader = (XImplementationLoader)UnoRuntime.queryInterface(
+            XImplementationLoader.class, new JavaLoader() );
+        
+        // Get the factory of the ServiceManager
+        XSingleComponentFactory smgr_fac = (XSingleComponentFactory)UnoRuntime.queryInterface(
+            XSingleComponentFactory.class, xImpLoader.activate(
+                "com.sun.star.comp.servicemanager.ServiceManager", null, null, null ) );
+        
+        // Create an instance of the ServiceManager
+        XMultiComponentFactory xSMgr = (XMultiComponentFactory)UnoRuntime.queryInterface(
+            XMultiComponentFactory.class, smgr_fac.createInstanceWithContext( null ) );
+        
+        // post init loader
+        XInitialization xInit = (XInitialization)UnoRuntime.queryInterface(
+            XInitialization.class, xImpLoader );
+        Object[] args = new Object [] '{' xSMgr };
+        xInit.initialize( args );
+        
+        // initial component context
+        if (context_entries == null)
+            context_entries = new Hashtable( 1 );
+        // add smgr
+        context_entries.put(
+            "/singletons/com.sun.star.lang.theServiceManager",
+            new ComponentContextEntry( null, xSMgr ) );
+        // ... xxx todo: add standard entries
+        XComponentContext xContext = new ComponentContext( context_entries, null );
+        
+        // post init smgr
+        xInit = (XInitialization)UnoRuntime.queryInterface(
+            XInitialization.class, xSMgr );
+        args = new Object [] '{' null, xContext }; // no registry, default context
+        xInit.initialize( args );
+        
+        XSet xSet = (XSet)UnoRuntime.queryInterface( XSet.class, xSMgr );
+        // insert the service manager
+        xSet.insert( smgr_fac );
+        // and basic jurt factories
+        insertBasicFactories( xSet, xImpLoader );
+        
+        return xContext;
+    }
+    
+    /**
+     * Bootstraps a servicemanager with the jurt base components registered.
+     * <p>
+     * @return     a freshly boostrapped service manager
+     * @see        com.sun.star.lang.ServiceManager
+     */
+    static public XMultiServiceFactory createSimpleServiceManager() throws Exception
+    '{'
+        return (XMultiServiceFactory)UnoRuntime.queryInterface(
+            XMultiServiceFactory.class, createInitialComponentContext( null ).getServiceManager() );
+    }
+    
+    
+    /** Bootstraps the initial component context from a native UNO installation.
+        
+        @see cppuhelper/defaultBootstrap_InitialComponentContext()
+    */
+    static public final XComponentContext defaultBootstrap_InitialComponentContext()
+        throws Exception
+    '{'
+        return defaultBootstrap_InitialComponentContext( null, null );
+    }
+    /** Bootstraps the initial component context from a native UNO installation.
+        
+        @param ini_file
+               ini_file (may be null: uno.rc besides cppuhelper lib)
+        @param bootstrap_parameters
+               bootstrap parameters (maybe null)
+               
+        @see cppuhelper/defaultBootstrap_InitialComponentContext()
+    */
+    static public final XComponentContext defaultBootstrap_InitialComponentContext(
+        String ini_file, Hashtable bootstrap_parameters )
+        throws Exception
+    '{'
+        // jni convenience: easier to iterate over array than calling Hashtable
+        String pairs [] = null;
+        if (null != bootstrap_parameters)
+        '{'
+            pairs = new String [ 2 * bootstrap_parameters.size() ];
+            Enumeration keys = bootstrap_parameters.keys();
+            int n = 0;
+            while (keys.hasMoreElements())
+            '{'
+                String name = (String)keys.nextElement();
+                pairs[ n++ ] = name;
+                pairs[ n++ ] = (String)bootstrap_parameters.get( name );
+            }
+        }
+        
+        if (! m_loaded_juh)
+        '{'
+            System.loadLibrary( "juh" );
+            m_loaded_juh = true;
+        }
+        return (XComponentContext)UnoRuntime.queryInterface(
+            XComponentContext.class,
+            cppuhelper_bootstrap(
+                ini_file, pairs, Bootstrap.class.getClassLoader() ) );
+    }
+    
+    static private boolean m_loaded_juh = false;
+    static private native Object cppuhelper_bootstrap(
+        String ini_file, String bootstrap_parameters [], ClassLoader loader )
+        throws Exception;
+
+    /**
+     * Bootstraps the component context from a UNO installation.
+     *   
+     * @return a bootstrapped component context.
+     * 
+     * @since UDK 3.1.0
+     */    
+    public static final XComponentContext bootstrap(URLClassLoader loader)
+        throws BootstrapException '{'
+        
+        XComponentContext xContext = null;
+        
+        try '{'
+            // create default local component context                
+            XComponentContext xLocalContext =
+                createInitialComponentContext( null );
+            if ( xLocalContext == null )
+                throw new BootstrapException( "no local component context!" );
+            
+            // find office executable relative to this class's class loader
+            String sOffice =
+                System.getProperty( "os.name" ).startsWith( "Windows" ) ?
+                "soffice.exe" : "soffice";            
+            File fOffice = NativeLibraryLoader.getResource( loader, sOffice );
+            if ( fOffice == null )
+                throw new BootstrapException( "no office executable found!" );
+
+            // create random pipe name
+            String sPipeName = "uno" +
+                Long.toString( (new Random()).nextLong() & 0x7fffffffffffffffL );
+            
+            // create call with arguments
+            String[] cmdArray = new String[7];
+            cmdArray[0] = fOffice.getPath();
+            cmdArray[1] = "-nologo";
+            cmdArray[2] = "-nodefault";
+            cmdArray[3] = "-norestore";
+            cmdArray[4] = "-nocrashreport";
+            cmdArray[5] = "-nolockcheck";
+            cmdArray[6] = "-accept=pipe,name=" + sPipeName + ";urp;";
+            
+            // start office process
+            Process p = Runtime.getRuntime().exec( cmdArray );
+            pipe( p.getInputStream(), System.out, "CO> " );
+            pipe( p.getErrorStream(), System.err, "CE> " );
+            
+            // initial service manager
+            XMultiComponentFactory xLocalServiceManager =
+                xLocalContext.getServiceManager();
+            if ( xLocalServiceManager == null )
+                throw new BootstrapException( "no initial service manager!" );
+            
+            // create a URL resolver
+            XUnoUrlResolver xUrlResolver =
+                UnoUrlResolver.create( xLocalContext );
+            
+            // connection string
+            String sConnect = "uno:pipe,name=" + sPipeName +
+                ";urp;StarOffice.ComponentContext";
+            
+            // wait until office is started
+            for (int i = 0;; ++i) '{'
+                try '{'
+                    // try to connect to office
+                    Object context = xUrlResolver.resolve( sConnect );
+                    xContext = (XComponentContext) UnoRuntime.queryInterface(
+                        XComponentContext.class, context);
+                    if ( xContext == null )
+                        throw new BootstrapException( "no component context!" );
+                    break;
+                } catch ( com.sun.star.connection.NoConnectException ex ) '{'
+                    // Wait 500 ms, then try to connect again, but do not wait
+                    // longer than 5 min (= 600 * 500 ms) total:
+                    if (i == 600) '{'
+                        throw new BootstrapException(ex.toString());
+                    }
+                    Thread.sleep( 500 );
+                }
+            }
+        } catch ( BootstrapException e ) '{'
+            throw e;
+        } catch ( java.lang.RuntimeException e ) '{'
+            throw e;
+        } catch ( java.lang.Exception e ) '{'
+            throw new BootstrapException( e );
+        }
+        
+        return xContext;
+    }
+
+    private static void pipe(
+        final InputStream in, final PrintStream out, final String prefix ) '{'
+        
+        new Thread( "Pipe: " + prefix) '{'
+            public void run() '{'
+                BufferedReader r = new BufferedReader(
+                    new InputStreamReader( in ) );
+                try '{'
+                    for ( ; ; ) '{'
+                        String s = r.readLine();
+                        if ( s == null ) '{'
+                            break;
+                        }
+                        out.println( prefix + s );
+                    }
+                } catch ( java.io.IOException e ) '{'
+                    e.printStackTrace( System.err );
+                }
+            }
+        }.start();
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestCase.java.tpl b/java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestCase.java.tpl
new file mode 100644
index 0000000..9349ea7
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestCase.java.tpl
@@ -0,0 +1,69 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  Cédric Bosdonnat cedricbosdo at openoffice.org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package {0}.tests.base;
+
+import junit.framework.TestCase;
+
+import com.sun.star.uno.XComponentContext;
+
+/**
+ * Base for all test cases to use along with '{'@link UnoTestSuite}.
+ * 
+ * @author cbosdo
+ *
+ */
+public abstract class UnoTestCase extends TestCase '{'
+    
+    /**
+     * Default constructor.
+     */
+    public UnoTestCase() '{'
+        super();
+    }
+
+    /**
+     * Constructor to use to run only one test
+     *  
+     * @param pName the test name
+     */
+    public UnoTestCase(String pName) '{'
+        super(pName);
+    }
+    
+
+    private XComponentContext mContext;
+
+    /**
+     * Set the office context to use in the tests.
+     * 
+     * @param pContext the remote office context
+     */
+    public void setContext(XComponentContext pContext) '{'
+        mContext = pContext;
+    }
+    
+    /**
+     * Get the office context to use in the tests.
+     * 
+     * @return the remote office context
+     */
+    protected XComponentContext getContext() '{'
+        return mContext;
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestSuite.java.tpl b/java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestSuite.java.tpl
new file mode 100644
index 0000000..718084c
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/base/UnoTestSuite.java.tpl
@@ -0,0 +1,145 @@
+/*
+ *   OpenOffice.org extension for syntax highlighting
+ *   Copyright (C) 2008  Cédric Bosdonnat cedricbosdo at openoffice.org
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Library General Public
+ *   License as published by the Free Software Foundation; 
+ *   version 2 of the License.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this library; if not, write to the Free
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+package {0}.tests.base;
+
+ 
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import com.sun.star.frame.XDesktop;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+/**
+ * This is a test suite for an OOo extension unit tests: 
+ * it bootstraps an OOo instance and handles the connection with it.
+ * 
+ * The extension to test has to be already installed on OOo for the
+ * current user.
+ * 
+ * @author cbosdo
+ *
+ */
+public class UnoTestSuite extends TestSuite '{'
+    
+    private XComponentContext mContext;
+    private boolean mHandleConnection = false;
+    
+    
+    public UnoTestSuite() '{'
+        super();
+    }
+
+    public UnoTestSuite(Class pTheClass, String pName) '{'
+        super(pTheClass, pName);
+    }
+
+    public UnoTestSuite(Class pTheClass) '{'
+        super(pTheClass);
+    }
+
+    public UnoTestSuite(Class[] pClasses, String pName) '{'
+        super(pClasses, pName);
+    }
+
+    public UnoTestSuite(Class[] pClasses) '{'
+        // Override to create UnoTestSuites instead of TestSuites
+        for (int i= 0; i < pClasses.length; i++) '{'
+            addTest(new UnoTestSuite(pClasses[i]));
+        }
+    }
+
+    public UnoTestSuite(String pName) '{'
+        super(pName);
+    }
+    
+    public void run(TestResult pResult) '{'
+        
+        try '{'
+            startOffice();
+            
+            super.run(pResult);
+        } catch (Exception e) '{'
+            System.err.println("Unable to run the tests");
+            e.printStackTrace();
+        }
+        
+        stopOffice();
+    }
+    
+    public void runTest(Test pTest, TestResult pResult) '{'
+        // Try to set the context on the test
+        if (pTest instanceof UnoTestCase) '{'
+            ((UnoTestCase)pTest).setContext(mContext);
+        } else if (pTest instanceof UnoTestSuite) '{'
+            UnoTestSuite suite = (UnoTestSuite)pTest;
+            suite.setContext(mContext);
+        }
+        
+        super.runTest(pTest, pResult);
+    }
+    
+    protected void setContext(XComponentContext pContext) '{'
+        mContext = pContext;
+    }
+    
+    protected void setHandleConnection(boolean pHandle) '{'
+        mHandleConnection = pHandle;
+    }
+    
+    /**
+     * Starts openoffice.org only if the context isn't set.
+     * 
+     * @throws Exception if anything wrong happens when starting the office
+     */
+    private void startOffice() throws Exception '{'
+        if (mContext == null) '{'
+            String path = System.getProperty("openoffice.program.path");
+            if (path == null) '{'
+                throw new Exception("The openoffice.install.path variable is missing");
+            }
+
+            File baseDir = new File(path);
+            URLClassLoader classLoader = new URLClassLoader(new URL[]'{'baseDir.toURI().toURL()});
+            mContext = Bootstrap.bootstrap(classLoader);
+            mHandleConnection = true;
+        }
+    }
+    
+    private void stopOffice() '{'
+        try '{'
+            if (mContext != null && mHandleConnection) '{'
+                // Only the uno test suite which started the office can stop it
+                XMultiComponentFactory xMngr = mContext.getServiceManager();
+                Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", mContext);
+                XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+                
+                xDesktop.terminate();
+            }
+        } catch (Exception e) '{'
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/tests/messages.properties b/java/source/org/openoffice/ide/eclipse/java/tests/messages.properties
new file mode 100644
index 0000000..044e69d
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/tests/messages.properties
@@ -0,0 +1 @@
+TestsHelper.AddJUnitError=Error adding JUnit libraries
diff --git a/java/source/org/openoffice/ide/eclipse/java/utils/TemplatesHelper.java b/java/source/org/openoffice/ide/eclipse/java/utils/TemplatesHelper.java
new file mode 100644
index 0000000..748ed2b
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/utils/TemplatesHelper.java
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the GNU Lesser General Public License Version 2.1
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2009 by Cédric Bosdonnat.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ * 
+ * The Initial Developer of the Original Code is: Cédric Bosdonnat.
+ *
+ * Copyright: 2009 by Cédric Bosdonnat.
+ *
+ * All Rights Reserved.
+ * 
+ ************************************************************************/
+package org.openoffice.ide.eclipse.java.utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.IPath;
+import org.openoffice.ide.eclipse.core.PluginLogger;
+import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
+
+/**
+ * Provides convenient methods to load, and save templates of Java source 
+ * files into a target projet.
+ * 
+ * <p>In order to generate the template <tt>foo/bar.java.tpl</tt>, the following
+ * call call be used, where <tt>LoadingClass</tt> is a class from which it is
+ * possible to run a <tt>getResource( "foo/bar.java.tpl" )</tt> to get the file.</p>
+ * 
+ * <code>
+ * TemplatesHelper.copyTemplate( myProject, "foo/bar", LoadingClass.class );
+ * </code>
+ * 
+ * @author cbosdonnat
+ *
+ */
+public class TemplatesHelper {
+    
+
+    private static final String JAVA_EXT  = ".java"; //$NON-NLS-1$
+    private static final String TEMPLATE_EXT = JAVA_EXT + ".tpl"; //$NON-NLS-1$
+
+    /**
+     * Copies the template to the UNO project.
+     * 
+     * @param pProject the project where to copy the file
+     * @param pTemplateName the template name (without the extension)
+     * @param pClazz the class from which to load the resource file
+     * @param pDestSuffix the subpath in which the file should be copied, relatively to 
+     *          the implementation package.
+     */
+    public static void copyTemplate( IUnoidlProject pProject, String pTemplateName, 
+            Class<?> pClazz, String pDestSuffix ) {
+       
+        String fileName = pTemplateName + TEMPLATE_EXT;
+        
+        // Get the path where to place the files
+        IPath relPath = pProject.getImplementationPath();
+        relPath = relPath.append( pDestSuffix );
+        IFolder dest = pProject.getFolder(relPath);
+        
+        relPath.toFile().mkdirs();
+        
+        // Compute the name of the project's implementation package
+        String implPkg = pProject.getCompanyPrefix() + "." + pProject.getOutputExtension(); //$NON-NLS-1$
+        
+
+        // Read the template into a buffer
+        FileWriter writer = null;
+        
+        
+        BufferedReader patternReader = null;
+        InputStream in = null;
+        try {
+            // Destination file opening
+            IFile classIFile = dest.getFile( pTemplateName + JAVA_EXT );
+            File classFile = classIFile.getLocation().toFile();
+            
+            if (!classFile.exists()) {
+                classFile.getParentFile().mkdirs();
+                classFile.createNewFile();
+            }
+            writer = new FileWriter(classFile); 
+            
+            // Input template opening
+            in = pClazz.getResourceAsStream( fileName );
+            patternReader = new BufferedReader(new InputStreamReader(in));
+            
+            // Loop over the lines, format and write them.
+            String line = patternReader.readLine();
+            while (line != null) {
+                line = MessageFormat.format(line, new Object[]{implPkg});
+                writer.append(line + "\n"); //$NON-NLS-1$
+                line = patternReader.readLine();
+            }
+        } catch (IOException e) {
+            // log the error
+            String msg = MessageFormat.format( Messages.getString("TemplatesHelper.ErrorPattern"),  //$NON-NLS-1$
+                    pTemplateName, Messages.getString("TemplatesHelper.ReadError") ); //$NON-NLS-1$
+            PluginLogger.error( msg, e);
+        } finally {
+            try {
+                patternReader.close();
+                in.close();
+                writer.close(); 
+            } catch (Exception e) {
+            }
+        }
+    }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties b/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties
index 184df19..654f160 100644
--- a/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties
+++ b/java/source/org/openoffice/ide/eclipse/java/utils/messages.properties
@@ -1 +1,4 @@
+TemplatesHelper.ErrorPattern=Error during {0} creation [{1}]
+TemplatesHelper.ReadError=reading template
+TemplatesHelper.WriteError=writing class
 ZipContentHelper.NotDirectoryError=Not a directory: 
commit 0f279f336e8e0424a11e8222315ec47d07828e4a
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Aug 27 08:36:28 2009 +0200

    Fixes in the Description.xml editor page
    
    The page was really too large in Eclipse 3.5 due to some bug introduced
    in this version. The labels have been shortened and the layout of the
    editor page is fixed.

diff --git a/core/source/org/openoffice/ide/eclipse/core/editors/main/AbstractOverviewSection.java b/core/source/org/openoffice/ide/eclipse/core/editors/main/AbstractOverviewSection.java
index 153f745..95ea862 100644
--- a/core/source/org/openoffice/ide/eclipse/core/editors/main/AbstractOverviewSection.java
+++ b/core/source/org/openoffice/ide/eclipse/core/editors/main/AbstractOverviewSection.java
@@ -1,5 +1,6 @@
 package org.openoffice.ide.eclipse.core.editors.main;
 
+import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.forms.SectionPart;
 import org.eclipse.ui.forms.editor.FormPage;
@@ -27,6 +28,7 @@ public abstract class AbstractOverviewSection extends SectionPart {
         super(pParent, pPage.getManagedForm().getToolkit(), pStyle);
         initialize( pPage.getManagedForm() );
         getManagedForm().addPart( this );
+        getSection( ).setLayoutData( new GridData( GridData.FILL_BOTH ) );
     }
     
     /**
diff --git a/core/source/org/openoffice/ide/eclipse/core/editors/main/GeneralSection.java b/core/source/org/openoffice/ide/eclipse/core/editors/main/GeneralSection.java
index 75b9271..54ff65a 100644
--- a/core/source/org/openoffice/ide/eclipse/core/editors/main/GeneralSection.java
+++ b/core/source/org/openoffice/ide/eclipse/core/editors/main/GeneralSection.java
@@ -67,7 +67,7 @@ public class GeneralSection extends LocalizedSection {
         super( pParent, pPage, Section.TITLE_BAR );
         
         
-        getSection().setText( Messages.getString("GeneralSection.Title") ); //$NON-NLS-1$
+        getSection( ).setText( Messages.getString("GeneralSection.Title") ); //$NON-NLS-1$
         
         mModel = pPage.getModel();
         loadData( );
diff --git a/core/source/org/openoffice/ide/eclipse/core/editors/main/PackageOverviewFormPage.java b/core/source/org/openoffice/ide/eclipse/core/editors/main/PackageOverviewFormPage.java
index e744001..8847526 100644
--- a/core/source/org/openoffice/ide/eclipse/core/editors/main/PackageOverviewFormPage.java
+++ b/core/source/org/openoffice/ide/eclipse/core/editors/main/PackageOverviewFormPage.java
@@ -47,10 +47,11 @@ import java.util.ArrayList;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.forms.IManagedForm;
@@ -110,29 +111,35 @@ public class PackageOverviewFormPage extends FormPage {
         
         ScrolledForm form = pManagedForm.getForm();
         form.setText( Messages.getString("PackageOverviewFormPage.Title") ); //$NON-NLS-1$
-        
-        form.getBody().setLayout( new GridLayout( ) );
+        Composite body = form.getBody( );
         
         FormToolkit toolkit = getManagedForm().getToolkit();
         toolkit.decorateFormHeading( form.getForm() );
         
-        Label descrLbl = toolkit.createLabel( form.getBody(), 
+        Label descrLbl = toolkit.createLabel( body, 
                 Messages.getString("PackageOverviewFormPage.Description"),  //$NON-NLS-1$
                 SWT.WRAP );
-        descrLbl.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = 2;
+        descrLbl.setLayoutData( gd );
+        
+        body.setLayout( new GridLayout( 2, false ) );
         
-        Composite body = toolkit.createComposite( form.getBody() );
-        body.setLayoutData( new GridData( GridData.FILL_BOTH ) );
-        body.setLayout( new GridLayout( ) );
+        ArrayList<LocalizedSection> sections = createMainPage( toolkit, body );
         
         // Create the locale selector line
-        Composite bottomLine = toolkit.createComposite( form.getBody() );
-        bottomLine.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        Composite bottomLine = toolkit.createComposite( body );
+        gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = 2;
+        bottomLine.setLayoutData( gd );
         bottomLine.setLayout( new GridLayout( ) );
         
-        mLocaleSel = new LocaleSelector( toolkit, bottomLine );   
+        mLocaleSel = new LocaleSelector( toolkit, bottomLine );  
         
-        createMainPage( toolkit, body );
+        // Set the locale listeners
+        for (LocalizedSection section : sections) {
+            mLocaleSel.addListener( section );
+        }
         
         mLocaleSel.loadLocales( mModel.getAllLocales() );
         
@@ -148,21 +155,19 @@ public class PackageOverviewFormPage extends FormPage {
      * @param pToolkit the toolkit used to create the page
      * @param pParent the parent composite where to create the page.
      * 
-     * @return the page control
+     * @return the localized sections of the page
      */
-    private Control createMainPage( FormToolkit pToolkit, Composite pParent ) {
+    private ArrayList<LocalizedSection> createMainPage( FormToolkit pToolkit, Composite pParent ) {
         
-        Composite body = pToolkit.createComposite( pParent );
-        body.setLayoutData( new GridData( GridData.FILL_BOTH ) );
-        body.setLayout( new GridLayout( 2, true ) );
+        ArrayList<LocalizedSection> localized = new ArrayList<LocalizedSection>();
         
-        Composite leftColumn = pToolkit.createComposite( body );
-        leftColumn.setLayoutData( new GridData( GridData.FILL_BOTH ));
+        Composite leftColumn = pToolkit.createComposite( pParent );
+        leftColumn.setLayoutData( new GridData( GridData.FILL_BOTH ) );
         leftColumn.setLayout( new GridLayout( ) ); 
         
         
-        Composite rightColumn = pToolkit.createComposite( body );
-        rightColumn.setLayoutData( new GridData( GridData.FILL_BOTH ));
+        Composite rightColumn = pToolkit.createComposite( pParent );
+        rightColumn.setLayoutData( new GridData( GridData.FILL_BOTH ) );
         rightColumn.setLayout( new GridLayout( ) );
         
         /*
@@ -173,18 +178,18 @@ public class PackageOverviewFormPage extends FormPage {
          *    + Section "Release notes"
          */
         GeneralSection generalSection = new GeneralSection( leftColumn, this );
-        mLocaleSel.addListener( generalSection );
+        localized.add( generalSection );
         mSections.add( generalSection );
         
         IntegrationSection integrationSection = new IntegrationSection( leftColumn, this );
         mSections.add( integrationSection );
         
         PublisherSection publisherSection = new PublisherSection( leftColumn, this );
-        mLocaleSel.addListener( publisherSection );
+        localized.add( publisherSection );
         mSections.add( publisherSection );
         
         ReleaseNotesSection releaseNotesSection = new ReleaseNotesSection( leftColumn, this );
-        mLocaleSel.addListener( releaseNotesSection );
+        localized.add( releaseNotesSection );
         mSections.add( releaseNotesSection );
         
         MirrorsSection mirrorSection = new MirrorsSection( rightColumn, this );
@@ -194,13 +199,13 @@ public class PackageOverviewFormPage extends FormPage {
         IProject project = input.getFile().getProject();
         LicenseSection licenseSection = new LicenseSection( rightColumn, this, project );
         mSections.add( licenseSection );
-        mLocaleSel.addListener( licenseSection );
+        localized.add( licenseSection );
         
         // Suspend the first dirty notifications in all sections 
         for ( AbstractOverviewSection section : mSections ) {
             section.setNotifyChanges( false );
         }
-        return body;
+        return localized;
     }
     
     /**
diff --git a/core/source/org/openoffice/ide/eclipse/core/editors/messages.properties b/core/source/org/openoffice/ide/eclipse/core/editors/messages.properties
index 88ecb06..1cbcf30 100644
--- a/core/source/org/openoffice/ide/eclipse/core/editors/messages.properties
+++ b/core/source/org/openoffice/ide/eclipse/core/editors/messages.properties
@@ -3,7 +3,7 @@ RegDocumentProvider.RegviewError=Error while reading regview output
 PackagePropertiesEditor.DescriptionParseError=Error parsing description.xml file
 PackagePropertiesFormPage.PackagePropertiesText=Contents
 ContentsSection.Title=Package content
-IntegrationSection.Description=Define the dependencies of the extension: OpenOffice.org version and compatible system.
+IntegrationSection.Description=Define the dependencies of the extension.
 IntegrationSection.MaxOOoVersion=Maximum OOo version
 IntegrationSection.MinOOoVersion=Minimum OOo version
 IntegrationSection.Platforms=Platforms
@@ -26,20 +26,20 @@ GeneralSection.Identifier=Identifier
 GeneralSection.Name=Name
 GeneralSection.Title=General informations
 GeneralSection.Version=Version
-LicenseSection.Description=License files are TXT files. They are localized and have to be selected here. If no file is selected for any locale, then no license will apply.
+LicenseSection.Description=License files are localized TXT files.\nIf no file is selected for any locale, then no license will apply.
 LicenseSection.FileChooserTooltip=Choose the folder where to place the license files
 LicenseSection.LicenseFile=License file
 LicenseSection.SuppressUpdate=Do not ask to accept the license during an update.
 LicenseSection.Title=License
 LicenseSection.UserAccept=Every user have to accept the license or only the administrator.
 MirrorsSection.Add=Add
-MirrorsSection.Description=List the URLs of the update sites to use for this extension. The first one is the primary mirror.
+MirrorsSection.Description=List the URLs of the update sites. The first one is the primary mirror.
 MirrorsSection.MirrorTextTitle=Specify a new mirror URL
 MirrorsSection.Remove=Remove
 PublisherSection.Description=Define the localized informartions on the extension publisher.
 PublisherSection.Name=Name
 PublisherSection.Title=Provider informations
 PublisherSection.Url=Url
-ReleaseNotesSection.Description=Defines the localized release notes web pages for this version.
+ReleaseNotesSection.Description=Defines the localized release notes web pages.
 ReleaseNotesSection.Title=Release notes
 ReleaseNotesSection.Url=Url
diff --git a/core/source/org/openoffice/ide/eclipse/core/i18n/ImageManager.properties b/core/source/org/openoffice/ide/eclipse/core/i18n/ImageManager.properties
index 2ada490..58691a7 100755
--- a/core/source/org/openoffice/ide/eclipse/core/i18n/ImageManager.properties
+++ b/core/source/org/openoffice/ide/eclipse/core/i18n/ImageManager.properties
@@ -1,29 +1,29 @@
-SDK_DIALOG_IMAGE = /icons/sdk_banner.gif
-OOO_DIALOG_IMAGE = /icons/ooo_banner.gif
-ERROR            = /icons/error.gif
-UNO_PROJECT      = /icons/uno_prj.gif
-NEWPROJECT_WIZ   = /icons/newunoprj_wiz.gif
-NEWFILE_WIZ      = /icons/newunofile_wiz.gif
-NEW_SERVICE_IMAGE = /icons/newservice_wiz.gif
-CHECKED           = /icons/checked.gif
-UNCHECKED         = /icons/unchecked.gif
-SERVICE           = /icons/service.gif
-INTERFACE         = /icons/interface.gif
-ABOUT_BANNER      = /icons/aboutBanner.png
+SDK_DIALOG_IMAGE    = /icons/sdk_banner.gif
+OOO_DIALOG_IMAGE    = /icons/ooo_banner.gif
+ERROR               = /icons/error.gif
+UNO_PROJECT         = /icons/uno_prj.gif
+NEWPROJECT_WIZ      = /icons/newunoprj_wiz.gif
+NEWFILE_WIZ         = /icons/newunofile_wiz.gif
+NEW_SERVICE_IMAGE   = /icons/newservice_wiz.gif
+CHECKED             = /icons/checked.gif
+UNCHECKED           = /icons/unchecked.gif
+SERVICE             = /icons/service.gif
+INTERFACE           = /icons/interface.gif
+ABOUT_BANNER        = /icons/aboutBanner.png
 NEW_INTERFACE_IMAGE = /icons/newinterface_wiz.gif
-URE_APP			  = /icons/ure_app.gif
-ATTRIBUTE		  = /icons/member.gif
-METHOD			  = /icons/method.gif
-STRUCT			  = /icons/struct.gif
-ENUM			  = /icons/enum.gif
-CONSTANTS		  = /icons/const.gif
-TYPEDEF			  = /icons/typedef.gif
-EXCEPTION		  = /icons/exception.gif
-PRJ_MODIFIER	  = /icons/prj_modifier.gif
-DB_MODIFIER		  = /icons/db_modifier.gif
-IDL_MODIFIER	  = /icons/idl_modifier.gif
-PACKAGE_EXPORT_WIZ = /icons/export_package_banner.gif
-URE_APP_WIZ		  = /icons/ure_app_wiz.png
-REFRESH			  = /icons/refresh.gif
-ADD               = /icons/add.gif
-DELETE            = /icons/delete.gif
\ No newline at end of file
+URE_APP             = /icons/ure_app.gif
+ATTRIBUTE           = /icons/member.gif
+METHOD              = /icons/method.gif
+STRUCT              = /icons/struct.gif
+ENUM                = /icons/enum.gif
+CONSTANTS           = /icons/const.gif
+TYPEDEF             = /icons/typedef.gif
+EXCEPTION           = /icons/exception.gif
+PRJ_MODIFIER        = /icons/prj_modifier.gif
+DB_MODIFIER         = /icons/db_modifier.gif
+IDL_MODIFIER        = /icons/idl_modifier.gif
+PACKAGE_EXPORT_WIZ  = /icons/export_package_banner.gif
+URE_APP_WIZ         = /icons/ure_app_wiz.png
+REFRESH             = /icons/refresh.gif
+ADD                 = /icons/add.gif
+DELETE              = /icons/delete.gif
\ No newline at end of file


More information about the ooo-build-commit mailing list