From a4db75cf3f550e05781754a41c66cb4c9e740c75 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 15 Mar 2012 22:03:10 +0100 Subject: ICE-3303 - Build Ice services in separate JAR files --- .../slice2javaplugin/internal/Configuration.java | 137 +++++++++++++++++++-- .../properties/ProjectProperties.java | 102 +++++++++++---- 2 files changed, 205 insertions(+), 34 deletions(-) (limited to 'eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin') diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java index ad50b474c14..87ffba48c17 100644 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java +++ b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java @@ -33,6 +33,7 @@ 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.core.JavaProject; import org.eclipse.ui.preferences.ScopedPreferenceStore; import com.zeroc.slice2javaplugin.Activator; @@ -167,7 +168,17 @@ public class Configuration IJavaProject javaProject = JavaCore.create(_project); if(getAddJars()) { - addLibrary(javaProject); + if(isAndroidProject()) + { + for(String jar : getJars()) + { + addLibrary(javaProject, jar); + } + } + else + { + addLibrary(javaProject); + } } else { @@ -201,14 +212,36 @@ public class Configuration fixGeneratedCP(null, getGeneratedDir()); IJavaProject javaProject = JavaCore.create(_project); - addLibrary(javaProject); + if(isAndroidProject()) + { + for(String jar : getJars()) + { + addLibrary(javaProject, jar); + } + } + else + { + addLibrary(javaProject); + } } public void deinstall() throws CoreException { IJavaProject javaProject = JavaCore.create(_project); - removeLibrary(javaProject); + if(isAndroidProject()) + { + removeLibrary(javaProject, "Ice.jar"); + removeLibrary(javaProject, "Glacier2.jar"); + removeLibrary(javaProject, "IceBox.jar"); + removeLibrary(javaProject, "IceGrid.jar"); + removeLibrary(javaProject, "IcePatch2.jar"); + removeLibrary(javaProject, "IceStorm.jar"); + } + else + { + removeLibrary(javaProject); + } removedGeneratedCP(); IFolder generatedFolder = _project.getFolder(getGeneratedDir()); if(generatedFolder != null && generatedFolder.exists()) @@ -480,7 +513,31 @@ public class Configuration { if(setValue(JARS_KEY, fromList(jars))) { - IceClasspathContainerIntializer.reinitialize(_project, this); + if(isAndroidProject()) + { + IJavaProject javaProject = JavaCore.create(_project); + ArrayList removeJars = new ArrayList(); + removeJars.add("Glacier2.jar"); + removeJars.add("IceBox.jar"); + removeJars.add("IceGrid.jar"); + removeJars.add("IcePatch2.jar"); + removeJars.add("IceStorm.jar"); + + for(String jar : jars) + { + iceJars.remove(jar); + addLibrary(javaProject, jar); + } + + for(String jar : removeJars) + { + removeLibrary(javaProject, jar); + } + } + else + { + IceClasspathContainerIntializer.reinitialize(_project, this); + } } } @@ -913,21 +970,47 @@ public class Configuration } } } - - public void removeLibrary(IJavaProject project) + + private void addLibrary(IJavaProject project, String jar) throws CoreException { - IClasspathEntry cpEntry = null; - if(!isAndroidProject()) + IClasspathEntry cpEntry = JavaCore.newVariableEntry(new Path("ICE_HOME/lib/" + jar), null, null); + + IClasspathEntry[] entries = project.getRawClasspath(); + boolean found = false; + for(int i = 0; i < entries.length; ++i) { - cpEntry = IceClasspathContainerIntializer.getContainerEntry(); + if(entries[i].equals(cpEntry)) + { + found = true; + break; + } } - else + + if(!found) { - cpEntry = JavaCore.newVariableEntry(new Path("ICE_HOME/lib/Ice.jar"), null, null); + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; + System.arraycopy(entries, 0, newEntries, 0, entries.length); + newEntries[entries.length] = cpEntry; + + try + { + project.setRawClasspath(newEntries, null); + } + catch(JavaModelException e) + { + throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), null)); + } } - IClasspathEntry[] entries = project.getRawClasspath(); + } + + public void removeLibrary(IJavaProject project) + throws CoreException + { + IClasspathEntry cpEntry = IceClasspathContainerIntializer.getContainerEntry(); + IClasspathEntry[] entries = project.getRawClasspath(); + for(int i = 0; i < entries.length; ++i) { if(entries[i].equals(cpEntry)) @@ -935,7 +1018,35 @@ public class Configuration IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1]; System.arraycopy(entries, 0, newEntries, 0, i); System.arraycopy(entries, i + 1, newEntries, i, entries.length - i - 1); - + + try + { + project.setRawClasspath(newEntries, null); + } + catch(JavaModelException e) + { + throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), null)); + } + break; + } + } + } + + public void removeLibrary(IJavaProject project, String lib) + throws CoreException + { + IClasspathEntry cpEntry = JavaCore.newVariableEntry(new Path("ICE_HOME/lib/" + lib), null, null); + + IClasspathEntry[] entries = project.getRawClasspath(); + + for(int i = 0; i < entries.length; ++i) + { + if(entries[i].equals(cpEntry)) + { + IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1]; + System.arraycopy(entries, 0, newEntries, 0, i); + System.arraycopy(entries, i + 1, newEntries, i, entries.length - i - 1); + try { project.setRawClasspath(newEntries, null); diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/properties/ProjectProperties.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/properties/ProjectProperties.java index 28611e45fcd..d87d6192c81 100644 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/properties/ProjectProperties.java +++ b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/properties/ProjectProperties.java @@ -85,6 +85,26 @@ public class ProjectProperties extends PropertyPage { jars.add("Freeze.jar"); } + if(_glacier2Jar.getSelection()) + { + jars.add("Glacier2.jar"); + } + if(_iceBoxJar.getSelection()) + { + jars.add("IceBox.jar"); + } + if(_iceStormJar.getSelection()) + { + jars.add("IceStorm.jar"); + } + if(_iceGridJar.getSelection()) + { + jars.add("IceGrid.jar"); + } + if(_icePatch2Jar.getSelection()) + { + jars.add("IcePatch2.jar"); + } _config.setJars(jars); } @@ -118,8 +138,8 @@ public class ProjectProperties extends PropertyPage } catch(IOException e) { - ErrorDialog.openError(getShell(), "Error", "Error saving preferences", - new Status(Status.ERROR, Activator.PLUGIN_ID, 0, null, e)); + ErrorDialog.openError(getShell(), "Error", "Error saving preferences", new Status(Status.ERROR, + Activator.PLUGIN_ID, 0, null, e)); return false; } return true; @@ -129,16 +149,32 @@ public class ProjectProperties extends PropertyPage { _jarsGroup = new Group(composite, SWT.NONE); _jarsGroup.setText("Add references to the following JAR files:"); - + GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 1; + gridLayout.numColumns = 7; _jarsGroup.setLayout(gridLayout); _jarsGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); - + _freezeJar = new Button(_jarsGroup, SWT.CHECK); - _freezeJar.setText("Freeze.jar"); + _freezeJar.setText("Freeze"); + + _glacier2Jar = new Button(_jarsGroup, SWT.CHECK); + _glacier2Jar.setText("Glacier2"); + + _iceBoxJar = new Button(_jarsGroup, SWT.CHECK); + _iceBoxJar.setText("IceBox"); + + _iceGridJar = new Button(_jarsGroup, SWT.CHECK); + _iceGridJar.setText("IceGrid"); + + _icePatch2Jar = new Button(_jarsGroup, SWT.CHECK); + _icePatch2Jar.setText("IcePatch2"); + + _iceStormJar = new Button(_jarsGroup, SWT.CHECK); + _iceStormJar.setText("IceStorm"); } + /** * @see PreferencePage#createContents(Composite) */ @@ -187,6 +223,26 @@ public class ProjectProperties extends PropertyPage { _freezeJar.setSelection(true); } + else if(jarFile.equals("Glacier2.jar")) + { + _glacier2Jar.setSelection(true); + } + else if(jarFile.equals("IceBox.jar")) + { + _iceBoxJar.setSelection(true); + } + else if(jarFile.equals("IceGrid.jar")) + { + _iceGridJar.setSelection(true); + } + else if(jarFile.equals("IcePatch2.jar")) + { + _icePatch2Jar.equals(true); + } + else if(jarFile.equals("IceStorm.jar")) + { + _iceStormJar.setSelection(true); + } } _defines.setText(Configuration.fromList(_config.getDefines())); _meta.setText(Configuration.fromList(_config.getMeta())); @@ -198,11 +254,10 @@ public class ProjectProperties extends PropertyPage _extraArguments.setText(_config.getExtraArguments()); // - // Android projects don't support extra Jar. + // Android projects don't support Freeze. // - _jarsGroup.setEnabled(!_config.isAndroidProject()); _freezeJar.setEnabled(!_config.isAndroidProject()); - + checkValid(); } @@ -306,9 +361,9 @@ public class ProjectProperties extends PropertyPage Label l = new Label(tc, SWT.WRAP); l.setForeground(new Color(null, 255, 0, 0)); - l.setText("This subdirectory is used by the plug-in to manage the source files generated from " + - "your Slice definitions. It should not be used for any other purpose. " + - "Files added manually are removed during project rebuilds."); + l.setText("This subdirectory is used by the plug-in to manage the source files generated from " + + "your Slice definitions. It should not be used for any other purpose. " + + "Files added manually are removed during project rebuilds."); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.widthHint = 400; @@ -357,17 +412,17 @@ public class ProjectProperties extends PropertyPage { if(path.members().length > 0) { - ErrorDialog.openError(getShell(), "Error", - "Generated code location should be an empty folder", - new Status(Status.ERROR, Activator.PLUGIN_ID, "The chosen directory '" + - path.getFullPath().toOSString() + "' is not empty." )); + ErrorDialog.openError(getShell(), "Error", + "Generated code location should be an empty folder", new Status(Status.ERROR, + Activator.PLUGIN_ID, "The chosen directory '" + + path.getFullPath().toOSString() + "' is not empty.")); return; } } catch(CoreException ex) { - ErrorDialog.openError(getShell(), "Error", ex.toString(), - new Status(Status.ERROR, Activator.PLUGIN_ID, 0, "Failed to set generated code location.", ex)); + ErrorDialog.openError(getShell(), "Error", ex.toString(), new Status(Status.ERROR, + Activator.PLUGIN_ID, 0, "Failed to set generated code location.", ex)); return; } _generatedDir.setText(newPath); @@ -375,12 +430,17 @@ public class ProjectProperties extends PropertyPage } } }); - + return composite; } - + private Button _freezeJar; - + private Button _glacier2Jar; + private Button _iceBoxJar; + private Button _iceGridJar; + private Button _icePatch2Jar; + private Button _iceStormJar; + private Text _generatedDir; private List _sourceDirectories; private Group _jarsGroup; -- cgit v1.2.3