diff options
author | Ludovic SMADJA <ludovic.smadja@jalios.com> | 2012-08-14 10:35:26 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-08-14 10:35:26 +0200 |
commit | 6d316d8c5a1cb2a04c6a5d1712b536a073e2bb66 (patch) | |
tree | aedf512996722b4ebad4ed99ef5788fa001d0347 /java | |
parent | a0b6bf7306e3c27074d35b2ceb5e09b47086e7fd (diff) |
Add compatibility with LibreOffice 3.5
Diffstat (limited to 'java')
-rw-r--r-- | java/.classpath | 1 | ||||
-rw-r--r-- | java/build.xml | 19 | ||||
-rw-r--r-- | java/source/org/openoffice/ide/eclipse/java/JavaDebugExtraOptionsProvider.java | 13 | ||||
-rw-r--r-- | java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java | 213 |
4 files changed, 155 insertions, 91 deletions
diff --git a/java/.classpath b/java/.classpath index d6914fe..55be196 100644 --- a/java/.classpath +++ b/java/.classpath @@ -4,5 +4,6 @@ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="src" path="source"/> + <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ANT"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/java/build.xml b/java/build.xml index b591473..d85291a 100644 --- a/java/build.xml +++ b/java/build.xml @@ -106,5 +106,24 @@ </jar> </target> + <target name="java.site" depends="java.plugin" unless="java.nobuild"> + + <!-- Echo the needed bits for site.xml --> + <copy tofile="${out.path}/site-java.xml" file="${build.basedir}/site-feature.xml" /> + <replace file="${out.path}/site-java.xml" token="@@URL@@" value="features/org.openoffice.ide.eclipse.java_${java.Bundle-Version}.jar"/> + <replace file="${out.path}/site-java.xml" token="@@ID@@" value="org.openoffice.ide.eclipse.java"/> + <replace file="${out.path}/site-java.xml" token="@@VERSION@@" value="${java.Bundle-Version}"/> + + <!-- Copying the plugins --> + <copy todir="${out.path}/plugins"> + <fileset dir="${java.out.path}/plugins/" + includes="*.jar" /> + <mapper type="flatten" /> + </copy> + + <!-- Preparing the plugins for p2 update site --> + <prepareJar jar="${out.path}/plugins/${package.prefix}.java_${java.Bundle-Version}.jar" outdir="${out.path}/plugins"/> + </target> + </project> diff --git a/java/source/org/openoffice/ide/eclipse/java/JavaDebugExtraOptionsProvider.java b/java/source/org/openoffice/ide/eclipse/java/JavaDebugExtraOptionsProvider.java index d0b7443..39f18cf 100644 --- a/java/source/org/openoffice/ide/eclipse/java/JavaDebugExtraOptionsProvider.java +++ b/java/source/org/openoffice/ide/eclipse/java/JavaDebugExtraOptionsProvider.java @@ -12,6 +12,7 @@ import org.openoffice.ide.eclipse.core.model.utils.SystemHelper; public class JavaDebugExtraOptionsProvider implements IExtraOptionsProvider {
private String mPort;
+ private String OOO_EXTRA_JAVA_TOOL_OPTIONS = "OOO_EXTRA_JAVA_TOOL_OPTIONS"; //$NON-NLS-1$
/**
*
@@ -26,8 +27,16 @@ public class JavaDebugExtraOptionsProvider implements IExtraOptionsProvider { * {@inheritDoc}
*/
public String[] addEnv(String[] pEnv) {
- pEnv = SystemHelper.addEnv(pEnv, "JAVA_TOOL_OPTIONS", "\"-Xdebug\" "
- + "\"-Xrunjdwp:transport=dt_socket,address=localhost:" + mPort + "\"", null);
+ String extraJavaOptEnv = System.getenv(OOO_EXTRA_JAVA_TOOL_OPTIONS);
+ if ( extraJavaOptEnv == null )
+ extraJavaOptEnv = new String( );
+ else
+ extraJavaOptEnv = extraJavaOptEnv.replaceAll("\"","\\\""); //$NON-NLS-1$//$NON-NLS-2$
+
+
+ pEnv = SystemHelper.addEnv(pEnv, "JAVA_TOOL_OPTIONS", //$NON-NLS-1$
+ extraJavaOptEnv + "\"-Xdebug\" " + //$NON-NLS-1$
+ "\"-Xrunjdwp:transport=dt_socket,address=localhost:" + mPort + "\"", null); //$NON-NLS-1$ //$NON-NLS-2$
return pEnv;
}
diff --git a/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java b/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java index 36136f8..d2cbc5c 100644 --- a/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java +++ b/java/source/org/openoffice/ide/eclipse/java/JavaProjectHandler.java @@ -44,9 +44,16 @@ package org.openoffice.ide.eclipse.java; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Vector; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathException; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -72,25 +79,26 @@ import org.openoffice.ide.eclipse.core.model.language.IProjectHandler; import org.openoffice.ide.eclipse.java.build.OOoContainerPage; import org.openoffice.ide.eclipse.java.registration.RegistrationHelper; import org.openoffice.ide.eclipse.java.tests.TestsHelper; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; /** * The Project handler implementation for Java. * * @author cedricbosdo - * + * */ public class JavaProjectHandler implements IProjectHandler { - private static final String P_REGISTRATION_CLASSNAME = "regclassname"; //$NON-NLS-1$ - private static final String P_JAVA_VERSION = "javaversion"; //$NON-NLS-1$ - - private static final String[] KEPT_JARS = { - "unoil.jar", //$NON-NLS-1$ - "ridl.jar", //$NON-NLS-1$ - "juh.jar", //$NON-NLS-1$ - "jurt.jar", //$NON-NLS-1$ - "unoloader.jar", //$NON-NLS-1$ - "officebean.jar" //$NON-NLS-1$ + private static final String P_REGISTRATION_CLASSNAME = "regclassname"; //$NON-NLS-1$ + private static final String P_JAVA_VERSION = "javaversion"; //$NON-NLS-1$ + + private static final String[] KEPT_JARS = { "unoil.jar", //$NON-NLS-1$ + "ridl.jar", //$NON-NLS-1$ + "juh.jar", //$NON-NLS-1$ + "jurt.jar", //$NON-NLS-1$ + "unoloader.jar", //$NON-NLS-1$ + "officebean.jar" //$NON-NLS-1$ }; /** @@ -99,7 +107,7 @@ public class JavaProjectHandler implements IProjectHandler { public void addOOoDependencies(IOOo pOoo, IProject pProject) { IJavaProject javaProject = JavaCore.create(pProject); - + OOoContainerPage.addOOoDependencies(pOoo, javaProject); } @@ -110,27 +118,26 @@ public class JavaProjectHandler implements IProjectHandler { try { if (!pProject.exists()) { pProject.create(null); - PluginLogger.debug( - "Project created during language specific operation"); //$NON-NLS-1$ + PluginLogger.debug("Project created during language specific operation"); //$NON-NLS-1$ } - + if (!pProject.isOpen()) { pProject.open(null); PluginLogger.debug("Project opened"); //$NON-NLS-1$ } - + IProjectDescription description = pProject.getDescription(); String[] natureIds = description.getNatureIds(); String[] newNatureIds = new String[natureIds.length + 1]; System.arraycopy(natureIds, 0, newNatureIds, 0, natureIds.length); - + // Adding the nature newNatureIds[natureIds.length] = JavaCore.NATURE_ID; - + description.setNatureIds(newNatureIds); pProject.setDescription(description, null); PluginLogger.debug(Messages.getString("Language.JavaNatureSet")); //$NON-NLS-1$ - + } catch (CoreException e) { PluginLogger.error(Messages.getString("Language.NatureSettingFailed")); //$NON-NLS-1$ } @@ -142,8 +149,7 @@ public class JavaProjectHandler implements IProjectHandler { public void configureProject(UnoFactoryData pData, IProgressMonitor pMonitor) throws Exception { // Get the project from data - IProject prj = (IProject)pData.getProperty( - IUnoFactoryConstants.PROJECT_HANDLE); + IProject prj = (IProject) pData.getProperty(IUnoFactoryConstants.PROJECT_HANDLE); IUnoidlProject unoprj = ProjectsManager.getProject(prj.getName()); // Set some properties on the project @@ -153,38 +159,34 @@ public class JavaProjectHandler implements IProjectHandler { unoprj.setProperty(P_REGISTRATION_CLASSNAME, regclass); // Java version - String javaversion = (String)pData.getProperty( - JavaWizardPage.JAVA_VERSION); + String javaversion = (String) pData.getProperty(JavaWizardPage.JAVA_VERSION); unoprj.setProperty(P_JAVA_VERSION, javaversion); - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( - unoprj.getName()); - + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(unoprj.getName()); + // Create the project structure IJavaProject javaProject = JavaCore.create(project); - javaProject.open( pMonitor ); - + javaProject.open(pMonitor); + IPath sourcePath = unoprj.getFolder(unoprj.getSourcePath()).getFullPath(); IPath buildPath = unoprj.getFolder(unoprj.getBuildPath()).getFullPath(); - - IClasspathEntry[] entries = new IClasspathEntry[] { - JavaCore.newSourceEntry(sourcePath), - JavaRuntime.getDefaultJREContainerEntry(), - JavaCore.newLibraryEntry(buildPath, null, null, false) - }; - + + IClasspathEntry[] entries = new IClasspathEntry[] { JavaCore.newSourceEntry(sourcePath), + JavaRuntime.getDefaultJREContainerEntry(), + JavaCore.newLibraryEntry(buildPath, null, null, false) }; + javaProject.setRawClasspath(entries, pMonitor); - + // Add the registration files - RegistrationHelper.generateFiles( unoprj ); - + 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 ); + Boolean usetests = (Boolean) pData.getProperty(JavaWizardPage.JAVA_TESTS); + if (usetests.booleanValue()) { + TestsHelper.writeTestClasses(unoprj); + + IJavaProject javaprj = JavaCore.create(prj); + TestsHelper.addJUnitLibraries(javaprj); } } @@ -194,24 +196,24 @@ public class JavaProjectHandler implements IProjectHandler { public String getImplementationName(IUnoidlProject pPrj, String pService) throws Exception { String prefix = pPrj.getCompanyPrefix(); String comp = pPrj.getOutputExtension(); - + String implementationName = null; - + if (pService.startsWith(prefix)) { String localName = pService.substring(prefix.length()); implementationName = prefix + "." + comp + localName + "Impl"; //$NON-NLS-1$ //$NON-NLS-2$ } else { throw new Exception("Cannot find implementation name for service: " + pService); //$NON-NLS-1$ } - + return implementationName; } - + /** * {@inheritDoc} */ public IPath getImplementationFile(String pImplementationName) { - + return new Path(pImplementationName.replace(".", "/") + ".java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @@ -220,10 +222,9 @@ public class JavaProjectHandler implements IProjectHandler { */ public String getSkeletonMakerLanguage(UnoFactoryData pData) throws Exception { // Get the project from data - String name = (String)pData.getProperty( - IUnoFactoryConstants.PROJECT_NAME); + String name = (String) pData.getProperty(IUnoFactoryConstants.PROJECT_NAME); IUnoidlProject unoprj = ProjectsManager.getProject(name); - + return "--" + unoprj.getProperty(P_JAVA_VERSION); //$NON-NLS-1$ } @@ -232,33 +233,68 @@ public class JavaProjectHandler implements IProjectHandler { */ public void removeOOoDependencies(IOOo pOoo, IProject pProject) { IJavaProject javaProject = JavaCore.create(pProject); - + OOoContainerPage.removeOOoDependencies(javaProject); } - + /** * {@inheritDoc} */ public String getLibraryPath(IUnoidlProject pProject) { return getJarFile(pProject).getLocation().toOSString(); } - + /** - * Returns a handle to the project jar file. Beware that this handle - * may refer to a non-existing file. Users have to create it if necessary. + * Returns a handle to the project jar file. Beware that this handle may refer to a non-existing file. Users have to + * create it if necessary. * - * @param pProject the concerned UNO project + * @param pProject + * the concerned UNO project * @return a handle to the jar file of the project */ public IFile getJarFile(IUnoidlProject pProject) { String filename = pProject.getName().replace(" ", "") + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return pProject.getFile(filename); } - + + /** + * Returns a handle to the project jar file. Beware that this handle may refer to a non-existing file. Users have to + * create it if necessary. + * + * @param pProjectDir + * the concerned UNO project directory + * @return a handle to the jar file of the project + */ + public File getJarFile(File pProjectDir) throws IOException, XPathException { + String filename = getName(pProjectDir).replace(" ", "") + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return new File(pProjectDir, filename); + } + + private String getName(File projectDir) throws IOException, XPathException { + File projectFile = new File(projectDir, ".project"); + if (!projectFile.exists()) { + return null; + } + final FileInputStream byteStream = new FileInputStream(projectFile); + InputSource source = new InputSource(byteStream); + + // evaluation de l'expression XPath + XPathFactory factory = XPathFactory.newInstance(); + javax.xml.xpath.XPath xpath = factory.newXPath(); + final String xPathExpr = "//projectDescription/name"; + XPathExpression exp = xpath.compile(xPathExpr); + Node node = (Node) exp.evaluate(source, XPathConstants.NODE); + if (node == null) { + return null; + } + return node.getTextContent(); + } + /** * Get the UNO registration class name of the project. * - * @param pProject the project for witch to get the registration class. + * @param pProject + * the project for witch to get the registration class. * * @return the registration class name */ @@ -270,69 +306,68 @@ public class JavaProjectHandler implements IProjectHandler { * {@inheritDoc} */ public IFolder[] getBinFolders(IUnoidlProject pUnoidlProject) { - ArrayList< IFolder > folders = new ArrayList<IFolder>(); - + ArrayList<IFolder> folders = new ArrayList<IFolder>(); + IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); - IProject prj = workspace.getProject( pUnoidlProject.getName() ); - IJavaProject javaPrj = JavaCore.create( prj ); + IProject prj = workspace.getProject(pUnoidlProject.getName()); + IJavaProject javaPrj = JavaCore.create(prj); try { - folders.add( workspace.getFolder( javaPrj.getOutputLocation() ) ); - + folders.add(workspace.getFolder(javaPrj.getOutputLocation())); + IClasspathEntry[] entries = javaPrj.getRawClasspath(); for (IClasspathEntry entry : entries) { - if ( entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && - entry.getOutputLocation() != null ) { - folders.add( workspace.getFolder( entry.getOutputLocation() ) ); + if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() != null) { + folders.add(workspace.getFolder(entry.getOutputLocation())); } } - } catch ( JavaModelException e ) { + } catch (JavaModelException e) { } - - return folders.toArray( new IFolder[folders.size()] ); + + return folders.toArray(new IFolder[folders.size()]); } - - //--------------------------------------------- Jar finding private methods - + + // --------------------------------------------- Jar finding private methods + /** * returns the path of all the kept jars contained in the folder pointed by path. * - * @param pOoo the OOo instance from which to get the jars + * @param pOoo + * the OOo instance from which to get the jars * @return a vector of Path pointing to each jar. */ public static Vector<Path> findJarsFromPath(IOOo pOoo) { Vector<Path> jarsPath = new Vector<Path>(); - + String[] paths = pOoo.getClassesPath(); for (String path : paths) { Path folderPath = new Path(path); File programFolder = folderPath.toFile(); - + String[] content = programFolder.list(); for (int i = 0, length = content.length; i < length; i++) { String contenti = content[i]; if (isKeptJar(contenti)) { - Path jariPath = new Path ( - path + "/" + contenti); //$NON-NLS-1$ + Path jariPath = new Path(path + "/" + contenti); //$NON-NLS-1$ jarsPath.add(jariPath); } - } + } } - + return jarsPath; } - + /** * Check if the specified jar file is one of those define in the KEPT_JARS constant. * - * @param pJarName name of the jar file to check - * @return <code>true</code> if jarName is one of those defined in KEPT_JARS, - * <code>false</code> otherwise. + * @param pJarName + * name of the jar file to check + * @return <code>true</code> if jarName is one of those defined in KEPT_JARS, <code>false</code> otherwise. */ private static boolean isKeptJar(String pJarName) { - + int i = 0; boolean isKept = false; - + while (i < KEPT_JARS.length && !isKept) { if (pJarName.equals(KEPT_JARS[i])) { isKept = true; |