diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2015-03-26 14:32:47 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2015-03-26 14:32:47 -0230 |
commit | 454c03e66a16a6d733163e67e317fbf565b5cdbf (patch) | |
tree | 7ecc45eecd24a65bf5bc81af2a48621d80b58caf /eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal | |
parent | Updated .gitignore files (diff) | |
download | ice-454c03e66a16a6d733163e67e317fbf565b5cdbf.tar.bz2 ice-454c03e66a16a6d733163e67e317fbf565b5cdbf.tar.xz ice-454c03e66a16a6d733163e67e317fbf565b5cdbf.zip |
ICE-6396 Move eclipse plugin to its own repo
Diffstat (limited to 'eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal')
5 files changed, 0 insertions, 1946 deletions
diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java deleted file mode 100644 index 7ff1be49682..00000000000 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Configuration.java +++ /dev/null @@ -1,1198 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. -// -// This plug-in is provided to you under the terms and conditions -// of the Eclipse Public License Version 1.0 ("EPL"). A copy of -// the EPL is available at http://www.eclipse.org/legal/epl-v10.html. -// -// ********************************************************************** - -package com.zeroc.slice2javaplugin.internal; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.preferences.InstanceScope; -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.ui.preferences.ScopedPreferenceStore; - -import com.zeroc.slice2javaplugin.Activator; -import com.zeroc.slice2javaplugin.preferences.PluginPreferencePage; - -public class Configuration -{ - public Configuration(IProject project) - { - _project = project; - - _instanceStore = new ScopedPreferenceStore(new InstanceScope(), Activator.PLUGIN_ID + "." + _project.getName()); - - _store = new ScopedPreferenceStore(new ProjectScope(project), Activator.PLUGIN_ID); - - _androidProject = false; - try - { - _androidProject = project.hasNature("com.android.ide.eclipse.adt.AndroidNature"); - } - catch(CoreException e) - { - } - - _store.setDefault(GENERATED_KEY, GENERATED_KEY); - _store.setDefault(DEFINES_KEY, ""); - _store.setDefault(TIE_KEY, false); - _store.setDefault(ICE_KEY, false); - _store.setDefault(STREAM_KEY, false); - _store.setDefault(ICE_INCLUDE_KEY, false); - _store.setDefault(META_KEY, ""); - _store.setDefault(CONSOLE_KEY, false); - _store.setDefault(SLICE_SOURCE_DIRS_KEY, "slice"); - _store.setDefault(INCLUDES_KEY, ""); - _store.setDefault(ADD_JARS_KEY, true); - _store.setDefault(UNDERSCORE_KEY, false); - - _store.setDefault(JARS_KEY, getJarName("Ice")); - } - - /** - * Turns list of strings into a single ';' delimited string. ';' in the - * string values are escaped with a leading '\'. '\' are turned into '\\'. - * - * @param l - * List of strings. - * @return Semicolon delimited string. - */ - static public String fromList(List<String> l) - { - StringBuffer sb = new StringBuffer(); - for(Iterator<String> p = l.iterator(); p.hasNext();) - { - if(sb.length() > 0) - { - sb.append(";"); - } - sb.append(escape(p.next())); - } - return sb.toString(); - } - - /** - * Turn a semicolon delimited string into a list of strings. Escaped values - * are preserved (characters prefixed with a '\'). - * - * @param s - * Semicolon delimited string. - * @return List of strings. - */ - static public List<String> toList(String s) - { - java.util.List<String> l = new ArrayList<String>(); - int curr = 0; - int end = s.length(); - boolean escape = false; - StringBuffer sb = new StringBuffer(); - for(curr = 0; curr < end; ++curr) - { - char ch = s.charAt(curr); - if(escape) - { - sb.append(ch); - escape = false; - } - else - { - if(ch == ';') - { - String tok = sb.toString().trim(); - sb.setLength(0); - if(tok.length() > 0) - { - l.add(tok); - } - } - else if(ch == '\\') - { - escape = true; - } - else - { - sb.append(ch); - } - } - } - String tok = sb.toString().trim(); - if(tok.length() > 0) - { - l.add(tok); - } - return l; - } - - public boolean write() - throws CoreException, IOException - { - boolean rc = false; - if(_store.needsSaving()) - { - _store.save(); - rc = true; - } - if(_instanceStore.needsSaving()) - { - _instanceStore.save(); - rc = true; - } - - if(rc) - { - IJavaProject javaProject = JavaCore.create(_project); - if(getAddJars()) - { - if(isAndroidProject()) - { - for(String jar : getJars()) - { - addLibrary(javaProject, jar); - } - } - else - { - addLibrary(javaProject); - } - } - else - { - removeLibrary(javaProject); - } - } - - return rc; - } - - public void initialize() - throws CoreException - { - // Create the slice source directories, if necessary. - for(Iterator<String> p = getSliceSourceDirs().iterator(); p.hasNext();) - { - IFolder slice = _project.getFolder(p.next()); - if(!slice.exists()) - { - slice.create(false, true, null); - } - } - - // Create the generated directory, if necessary. - IFolder generated = _project.getFolder(getGeneratedDir()); - if(!generated.exists()) - { - generated.create(false, true, null); - } - - fixGeneratedCP(null, getGeneratedDir()); - - IJavaProject javaProject = JavaCore.create(_project); - if(isAndroidProject()) - { - for(String jar : getJars()) - { - addLibrary(javaProject, jar); - } - } - else - { - addLibrary(javaProject); - } - } - - public void deinstall() - throws CoreException - { - IJavaProject javaProject = JavaCore.create(_project); - if(isAndroidProject()) - { - removeLibrary(javaProject, getJarName("Ice")); - removeLibrary(javaProject, getJarName("Glacier2")); - removeLibrary(javaProject, getJarName("IceBox")); - removeLibrary(javaProject, getJarName("IceGrid")); - removeLibrary(javaProject, getJarName("IcePatch2")); - removeLibrary(javaProject, getJarName("IceStorm")); - } - else - { - removeLibrary(javaProject); - } - removedGeneratedCP(); - IFolder generatedFolder = _project.getFolder(getGeneratedDir()); - if(generatedFolder != null && generatedFolder.exists()) - { - generatedFolder.delete(true, null); - } - } - - public String getJarName(String base) - { - String version = getIceVersion(); - - int intVersion = 306; - if(version != null) - { - String tokens[] = version.split(java.util.regex.Pattern.quote(".")); - if(tokens.length >= 2) - { - intVersion = (Integer.parseInt(tokens[0]) * 100) + - Integer.parseInt(tokens[1]); - } - } - - if(intVersion >= 306) - { - base = base.toLowerCase() + "-" + version; - } - - return base + ".jar"; - } - - public boolean isAndroidProject() - { - return _androidProject; - } - - public List<String> getSliceSourceDirs() - { - return toList(_store.getString(SLICE_SOURCE_DIRS_KEY)); - } - - public void setSliceSourceDirs(List<String> sliceSourceDirs) - { - setValue(SLICE_SOURCE_DIRS_KEY, fromList(sliceSourceDirs)); - } - - public String getGeneratedDir() - { - return _store.getString(GENERATED_KEY); - } - - public void fixGeneratedCP(String oldG, String newG) - throws CoreException - { - IJavaProject javaProject = JavaCore.create(_project); - - IFolder newGenerated = _project.getFolder(newG); - - IClasspathEntry[] entries = javaProject.getRawClasspath(); - IClasspathEntry newEntry = JavaCore.newSourceEntry(newGenerated.getFullPath()); - - if(oldG != null) - { - IFolder oldGenerated = _project.getFolder(oldG); - IClasspathEntry oldEntry = JavaCore.newSourceEntry(oldGenerated.getFullPath()); - for(int i = 0; i < entries.length; ++i) - { - if(entries[i].equals(oldEntry)) - { - entries[i] = newEntry; - javaProject.setRawClasspath(entries, null); - oldGenerated.delete(true, null); - return; - } - } - } - - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; - System.arraycopy(entries, 0, newEntries, 1, entries.length); - newEntries[0] = newEntry; - - newGenerated.setDerived(true, null); - - try - { - javaProject.setRawClasspath(newEntries, null); - } - catch(JavaModelException e) - { - // This can occur if a duplicate CLASSPATH entry is made. - // - // throw new CoreException(new Status(IStatus.ERROR, - // Activator.PLUGIN_ID, e.toString(), null)); - } - } - - public void removedGeneratedCP() - throws CoreException - { - IJavaProject javaProject = JavaCore.create(_project); - - IFolder generated = _project.getFolder(getGeneratedDir()); - - IClasspathEntry generatedEntry = JavaCore.newSourceEntry(generated.getFullPath()); - - IClasspathEntry[] entries = javaProject.getRawClasspath(); - IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1]; - - for(int i = 0, j = 0; i < entries.length; i++) - { - if(entries[i].equals(generatedEntry)) - { - continue; - } - newEntries[j] = entries[i]; - j++; - } - - try - { - javaProject.setRawClasspath(newEntries, null); - } - catch(JavaModelException e) - { - // This can occur if a duplicate CLASSPATH entry is made. - // - // throw new CoreException(new Status(IStatus.ERROR, - // Activator.PLUGIN_ID, e.toString(), null)); - } - } - - public void setGeneratedDir(String generated) - throws CoreException - { - String oldGenerated = getGeneratedDir(); - if(setValue(GENERATED_KEY, generated)) - { - fixGeneratedCP(oldGenerated, generated); - } - } - - public List<String> getCommandLine() - { - List<String> cmds = new ArrayList<String>(); - for(Iterator<String> p = getIncludes().iterator(); p.hasNext();) - { - cmds.add("-I" + p.next()); - } - for(Iterator<String> p = getDefines().iterator(); p.hasNext();) - { - cmds.add("-D" + p.next()); - } - for(Iterator<String> p = getMeta().iterator(); p.hasNext();) - { - cmds.add("--meta"); - cmds.add(p.next()); - } - if(getStream()) - { - cmds.add("--stream"); - } - if(getTie()) - { - cmds.add("--tie"); - } - if(getIce()) - { - cmds.add("--ice"); - } - if(getUnderscore()) - { - cmds.add("--underscore"); - } - - StringTokenizer tokens = new StringTokenizer(getExtraArguments()); - while(tokens.hasMoreTokens()) - { - cmds.add(tokens.nextToken()); - } - - return cmds; - } - - public List<String> getCommandLine(IResource resource) - { - List<String> cmds = getCommandLine(); - for(Iterator<String> p = getBareIncludes(resource).iterator(); p.hasNext();) - { - cmds.add("-I" + p.next()); - } - for(Iterator<String> p = getDefines(resource).iterator(); p.hasNext();) - { - cmds.add("-D" + p.next()); - } - for(Iterator<String> p = getMeta(resource).iterator(); p.hasNext();) - { - cmds.add("--meta"); - cmds.add(p.next()); - } - if(!getStream() && getStream(resource)) - { - cmds.add("--stream"); - } - if(!getTie() && getTie(resource)) - { - cmds.add("--tie"); - } - if(!getIce() && getIce(resource)) - { - cmds.add("--ice"); - } - if(!getUnderscore() && getUnderscore(resource)) - { - cmds.add("--underscore"); - } - - StringTokenizer tokens = new StringTokenizer(getExtraArguments(resource)); - while(tokens.hasMoreTokens()) - { - cmds.add(tokens.nextToken()); - } - - return cmds; - } - - public List<String> getIncludes() - { - List<String> s = toList(_store.getString(INCLUDES_KEY)); - - String iceHome = getIceHome(); - String path = null; - if(!System.getProperty("os.name").startsWith("Windows") && - (iceHome.equals("/usr") || iceHome.equals("/usr/local"))) - { - String version = getIceVersion(); - if(version != null) - { - File f = new File(iceHome + "/share/Ice-" + version + "/slice"); - if(f.exists()) - { - path = f.toString(); - } - } - } - if(path == null) - { - path = new File(iceHome + File.separator + "slice").toString(); - } - s.add(path); - return s; - } - - // The bare include list. - public List<String> getBareIncludes() - { - return toList(_store.getString(INCLUDES_KEY)); - } - - public List<String> getBareIncludes(IResource resource) - { - return toList(_store.getString(resourceKey(resource, INCLUDES_KEY))); - } - - public void setIncludes(List<String> includes) - { - setValue(INCLUDES_KEY, fromList(includes)); - } - - public void setIncludes(IResource resource, List<String> includes) - { - setValue(resourceKey(resource, INCLUDES_KEY), fromList(includes)); - } - - public boolean getAddJars() - { - return _store.getBoolean(ADD_JARS_KEY); - } - - public void setAddJars(boolean b) - { - _store.setValue(ADD_JARS_KEY, b); - } - - public List<String> getJars() - { - return toList(_store.getString(JARS_KEY)); - } - - public void setJars(List<String> jars) throws CoreException - { - if(setValue(JARS_KEY, fromList(jars))) - { - if(isAndroidProject()) - { - IJavaProject javaProject = JavaCore.create(_project); - ArrayList<String> removeJars = new ArrayList<String>(); - removeJars.add(getJarName("Ice")); - removeJars.add(getJarName("IceBox")); - removeJars.add(getJarName("IceGrid")); - removeJars.add(getJarName("IcePatch2")); - removeJars.add(getJarName("IceStorm")); - - for(String jar : jars) - { - removeJars.remove(jar); - addLibrary(javaProject, jar); - } - - for(String jar : removeJars) - { - removeLibrary(javaProject, jar); - } - } - else - { - IceClasspathContainerIntializer.reinitialize(_project, this); - } - } - } - - public List<String> getDefines() - { - return toList(_store.getString(DEFINES_KEY)); - } - - public List<String> getDefines(IResource resource) - { - return toList(_store.getString(resourceKey(resource, DEFINES_KEY))); - } - - public void setDefines(List<String> defines) - { - setValue(DEFINES_KEY, fromList(defines)); - } - - public void setDefines(IResource resource, List<String> defines) - { - setValue(resourceKey(resource, DEFINES_KEY), fromList(defines)); - } - - public boolean getStream() - { - return _store.getBoolean(STREAM_KEY); - } - - public boolean getStream(IResource resource) - { - return _store.getBoolean(resourceKey(resource, STREAM_KEY)); - } - - public void setStream(boolean stream) - { - _store.setValue(STREAM_KEY, stream); - } - - public void setStream(IResource resource, boolean stream) - { - _store.setValue(resourceKey(resource, STREAM_KEY), stream); - } - - public boolean getTie() - { - return _store.getBoolean(TIE_KEY); - } - - public boolean getTie(IResource resource) - { - return _store.getBoolean(resourceKey(resource, TIE_KEY)); - } - - public void setTie(boolean tie) - { - _store.setValue(TIE_KEY, tie); - } - - public void setTie(IResource resource, boolean tie) - { - _store.setValue(resourceKey(resource, TIE_KEY), tie); - } - - public boolean getIce() - { - return _store.getBoolean(ICE_KEY); - } - - public boolean getIce(IResource resource) - { - return _store.getBoolean(resourceKey(resource, ICE_KEY)); - } - - public void setIce(boolean ice) - { - _store.setValue(ICE_KEY, ice); - } - - public void setIce(IResource resource, boolean ice) - { - _store.setValue(resourceKey(resource, ICE_KEY), ice); - } - - public boolean getUnderscore() - { - return _store.getBoolean(UNDERSCORE_KEY); - } - - public boolean getUnderscore(IResource resource) - { - return _store.getBoolean(resourceKey(resource, UNDERSCORE_KEY)); - } - - public void setUnderscore(boolean underscore) - { - _store.setValue(UNDERSCORE_KEY, underscore); - } - - public void setUnderscore(IResource resource, boolean underscore) - { - _store.setValue(resourceKey(resource, UNDERSCORE_KEY), underscore); - } - - public boolean getConsole() - { - return _store.getBoolean(CONSOLE_KEY); - } - - public void setConsole(boolean console) - { - _store.setValue(CONSOLE_KEY, console); - } - - public List<String> getMeta() - { - return toList(_store.getString(META_KEY)); - } - - public List<String> getMeta(IResource resource) - { - return toList(_store.getString(resourceKey(resource, META_KEY))); - } - - public void setMeta(List<String> meta) - { - setValue(META_KEY, fromList(meta)); - } - - public void setMeta(IResource resource, List<String> meta) - { - setValue(resourceKey(resource, META_KEY), fromList(meta)); - } - - public String getExtraArguments() - { - return _store.getString(EXTRA_ARGUMENTS_KEY); - } - - public String getExtraArguments(IResource resource) - { - return _store.getString(resourceKey(resource, EXTRA_ARGUMENTS_KEY)); - } - - public void setExtraArguments(String arguments) - { - setValue(EXTRA_ARGUMENTS_KEY, arguments); - } - - public void setExtraArguments(IResource resource, String arguments) - { - setValue(resourceKey(resource, EXTRA_ARGUMENTS_KEY), arguments); - } - - public static void setupSharedLibraryPath(Map<String, String> env) - { - String iceHome = getIceHome(); - String os = System.getProperty("os.name"); - - if(iceHome.equals("/usr") && os.equals("Linux")) - { - return; - } - - String lib32Subdir = "lib"; - String lib64Subdir = "lib64"; - if(os.equals("Linux")) - { - if(new File("/usr/lib/i386-linux-gnu").exists()) - { - lib32Subdir = "lib" + File.separator + "i386-linux-gnu"; - } - - if(new File("/usr/lib/x86_64-linux-gnu").exists()) - { - lib64Subdir = "lib" + File.separator + "x86_64-linux-gnu"; - } - } - - - - String libPath; - boolean srcdist = false; - if(new File(iceHome + File.separator + "cpp" + File.separator + "bin").exists()) - { - // iceHome points at a source distribution. - libPath = new File(iceHome + File.separator + "cpp" + File.separator + "lib").toString(); - srcdist = true; - } - else - { - libPath = new File(iceHome + File.separator + lib32Subdir).toString(); - } - - String ldLibPathEnv = null; - String ldLib64PathEnv = null; - String lib64Path = null; - - if(os.equals("Mac OS X")) - { - ldLibPathEnv = "DYLD_LIBRARY_PATH"; - } - else if(os.equals("AIX")) - { - ldLibPathEnv = "LIBPATH"; - } - else if(os.equals("HP-UX")) - { - ldLibPathEnv = "SHLIB_PATH"; - ldLib64PathEnv = "LD_LIBRARY_PATH"; - if(srcdist) - { - lib64Path = libPath; - } - else - { - lib64Path = new File(iceHome + File.separator + "lib" + File.separator + "pa20_64").toString(); - } - } - else if(os.startsWith("Windows")) - { - // - // No need to change the PATH environment variable on Windows, the - // DLLs should be found - // in the translator local directory. - // - // ldLibPathEnv = "PATH"; - } - else if(os.equals("SunOS")) - { - ldLibPathEnv = "LD_LIBRARY_PATH"; - ldLib64PathEnv = "LD_LIBRARY_PATH_64"; - String arch = System.getProperty("os.arch"); - if(srcdist) - { - lib64Path = libPath; - } - else if(arch.equals("x86")) - { - lib64Path = new File(iceHome + File.separator + "lib" + File.separator + "amd64").toString(); - } - else - // Sparc - { - lib64Path = new File(iceHome + File.separator + "lib" + File.separator + "sparcv9").toString(); - } - } - else - { - ldLibPathEnv = "LD_LIBRARY_PATH"; - ldLib64PathEnv = "LD_LIBRARY_PATH"; - if(srcdist) - { - lib64Path = libPath; - } - else - { - lib64Path = new File(iceHome + File.separator + lib64Subdir).toString(); - } - } - - if(ldLibPathEnv != null) - { - if(ldLibPathEnv.equals(ldLib64PathEnv)) - { - libPath = libPath + File.pathSeparator + lib64Path; - } - - String envLibPath = env.get(ldLibPathEnv); - if(envLibPath != null) - { - libPath = libPath + File.pathSeparator + envLibPath; - } - - env.put(ldLibPathEnv, libPath); - } - - if(ldLib64PathEnv != null && !ldLib64PathEnv.equals(ldLibPathEnv)) - { - String envLib64Path = env.get(ldLib64PathEnv); - if(envLib64Path != null) - { - lib64Path = lib64Path + File.pathSeparator + envLib64Path; - } - env.put(ldLib64PathEnv, lib64Path); - } - } - - public String getTranslator() - { - return getTranslatorForHome(getIceHome()); - } - - static public boolean verifyIceHome(String dir) - { - return getTranslatorForHome(dir) != null; - } - - public static String getJarDir() - { - String iceHome = getIceHome(); - String os = System.getProperty("os.name"); - if(!System.getProperty("os.name").startsWith("Windows") && - (iceHome.equals("/usr") || iceHome.equals("/usr/local"))) - { - File f = new File(iceHome + File.separator + "share" + File.separator + "java"); - if(f.exists()) - { - return f.toString(); - } - } - - File f = new File(iceHome + File.separator + "lib"); - if(!f.exists()) - { - File f2 = new File(iceHome + File.separator + "java" + File.separator + "lib"); - if(f2.exists()) - { - return f2.toString(); - } - } - // Add the platform default even if it cannot be found. - return f.toString(); - } - - private static String getIceHome() - { - return Activator.getDefault().getPreferenceStore().getString(PluginPreferencePage.SDK_PATH); - } - - // For some reason ScopedPreferenceStore.setValue(String, String) - // doesn't check to see whether the stored value is the same as - // the new value. - private boolean setValue(String key, String value) - { - return setValue(_store, key, value); - } - - private boolean setValue(ScopedPreferenceStore store, String key, String value) - { - if(!store.getString(key).equals(value)) - { - store.setValue(key, value); - return true; - } - return false; - } - - static private String escape(String s) - { - int curr = 0; - int end = s.length(); - StringBuffer sb = new StringBuffer(); - for(curr = 0; curr < end; ++curr) - { - char ch = s.charAt(curr); - if(ch == '\\' || ch == ';') - { - sb.append('\\'); - } - sb.append(ch); - } - return sb.toString(); - } - - // Obtain the Ice version by executing the translator with the -v option. - private String getIceVersion() - { - String iceHome = getIceHome(); - if(_version == null || !iceHome.equals(_iceHome)) - { - _version = null; - String exec = getTranslatorForHome(getIceHome()); - if(exec != null) - { - try - { - ProcessBuilder b = new ProcessBuilder(exec, "-v"); - b.redirectErrorStream(true); - Map<String, String> env = b.environment(); - setupSharedLibraryPath(env); - Process p = b.start(); - int status = p.waitFor(); - if(status == 0) - { - BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = r.readLine(); - _version = line.trim(); - _iceHome = iceHome; - } - } - catch(Throwable ex) - { - // Ignore. - } - } - } - return _version; - } - - private static String getTranslatorForHome(String dir) - { - String suffix = ""; - String os = System.getProperty("os.name"); - if(os.startsWith("Windows")) - { - suffix = ".exe"; - } - File f = new File(dir + File.separator + "bin" + File.separator + "slice2java" + suffix); - if(f.exists()) - { - return f.toString(); - } - if(os.startsWith("Windows")) - { - f = new File(dir + File.separator + "bin" + File.separator + - "x64" + File.separator + "slice2java" + suffix); - if(f.exists()) - { - return f.toString(); - } - } - f = new File(dir + File.separator + "cpp" + File.separator + "bin" + File.separator + "slice2java" + suffix); - if(f.exists()) - { - return f.toString(); - } - return null; - } - - private void addLibrary(IJavaProject project) - throws CoreException - { - IClasspathEntry cpEntry = null; - if(!isAndroidProject()) - { - cpEntry = IceClasspathContainerIntializer.getContainerEntry(); - } - else - { - final String iceJarPath = "ICE_JAR_HOME/" + getJarName("Ice"); - cpEntry = JavaCore.newVariableEntry(new Path(iceJarPath), new Path(iceJarPath), - new Path("ICE_JAR_HOME/lib/"), - true); - } - - IClasspathEntry[] entries = project.getRawClasspath(); - boolean found = false; - for(int i = 0; i < entries.length; ++i) - { - if(entries[i].equals(cpEntry)) - { - found = true; - break; - } - } - - if(!found) - { - 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)); - } - } - } - - private void addLibrary(IJavaProject project, String jar) - throws CoreException - { - IClasspathEntry cpEntry = JavaCore.newVariableEntry(new Path("ICE_JAR_HOME/" + jar), - new Path("ICE_JAR_HOME/" + jar), - new Path("ICE_JAR_HOME/"), - true); - - IClasspathEntry[] entries = project.getRawClasspath(); - boolean found = false; - for(int i = 0; i < entries.length; ++i) - { - if(entries[i].equals(cpEntry)) - { - found = true; - break; - } - } - - if(!found) - { - 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)); - } - } - } - - 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)) - { - 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 - { - Path path = new Path("ICE_JAR_HOME/" + lib); - - IClasspathEntry[] entries = project.getRawClasspath(); - - for(int i = 0; i < entries.length; ++i) - { - if(entries[i].getPath().equals(path)) - { - 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; - } - } - } - - // - // Check if the given resource has any Slice compiler options set. - // - public static boolean resourceHasOptions(IResource resource) - { - Configuration configuration = new Configuration(resource.getProject()); - if(configuration.getDefines(resource) != null && configuration.getDefines(resource).size() > 0) - { - return true; - } - if(configuration.getMeta(resource) != null && configuration.getMeta(resource).size() > 0) - { - return true; - } - if(!configuration.getStream() && configuration.getStream(resource)) - { - return true; - } - if(!configuration.getTie() && configuration.getTie(resource)) - { - return true; - } - if(!configuration.getIce() && configuration.getIce(resource)) - { - return true; - } - if(!configuration.getUnderscore() && configuration.getUnderscore(resource)) - { - return true; - } - if(configuration.getExtraArguments(resource) != null && !configuration.getExtraArguments(resource).isEmpty()) - { - return true; - } - return false; - } - - public static String resourceKey(IResource resource, String key) - { - return resource.getFullPath().toString() + "." + key; - } - - private static final String JARS_KEY = "jars"; - private static final String INCLUDES_KEY = "includes"; - private static final String SLICE_SOURCE_DIRS_KEY = "sliceSourceDirs"; - private static final String CONSOLE_KEY = "console"; - private static final String META_KEY = "meta"; - private static final String STREAM_KEY = "stream"; - private static final String ICE_INCLUDE_KEY = "iceIncludes"; - private static final String ICE_KEY = "ice"; - private static final String TIE_KEY = "tie"; - private static final String DEFINES_KEY = "defines"; - private static final String GENERATED_KEY = "generated"; - private static final String ADD_JARS_KEY = "addJars"; - private static final String UNDERSCORE_KEY = "underscore"; - - private static final String EXTRA_ARGUMENTS_KEY = "extraArguments"; - - // Preferences store for items which should go in SCM. This includes things - // like build flags. - private ScopedPreferenceStore _store; - - // Preferences store per project items which should not go in SCM, such as - // the location of the Ice installation. - private ScopedPreferenceStore _instanceStore; - - private IProject _project; - - private boolean _androidProject; - - private static String _version = null; - private static String _iceHome = null; -} diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Dependencies.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Dependencies.java deleted file mode 100644 index 9222c3ed48f..00000000000 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/Dependencies.java +++ /dev/null @@ -1,528 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. -// -// This plug-in is provided to you under the terms and conditions -// of the Eclipse Public License Version 1.0 ("EPL"). A copy of -// the EPL is available at http://www.eclipse.org/legal/epl-v10.html. -// -// ********************************************************************** - -package com.zeroc.slice2javaplugin.internal; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.eclipse.core.filesystem.EFS; -import org.eclipse.core.filesystem.IFileStore; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.ui.console.MessageConsoleStream; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.xml.sax.SAXException; - -import com.zeroc.slice2javaplugin.Activator; - -public class Dependencies -{ - public Dependencies(IProject project, Set<IFile> LprojectResources, MessageConsoleStream err) - { - _project = project; - _projectResources = LprojectResources; - _err = err; - - // Build a map of location to project resource. - - for(IFile f : _projectResources) - { - _locationToResource.put(f.getLocation(), f); - } - } - - /** - * - * @param allDependencies The string of all dependencies. - * @throws CoreException - */ - public void updateDependencies(String allDependencies) - throws CoreException - { - Slice2JavaDependenciesParser parser = new Slice2JavaDependenciesParser(); - try - { - InputStream in = new ByteArrayInputStream(allDependencies.getBytes()); - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new BufferedInputStream(in)); - parser.visit(doc); - } - catch(SAXException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error reading dependencies", e)); - } - catch(ParserConfigurationException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error reading dependencies", e)); - } - catch(IOException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error reading dependencies", e)); - } - - for(Map.Entry<String, List<String>> entry : parser.dependencies.entrySet()) - { - Path sourcePath = new Path(entry.getKey()); - assert sourcePath.isAbsolute(); - - IFile sourceFile = _locationToResource.get(sourcePath); - if(sourceFile == null) - { - if(_err != null) - { - _err.println("Dependencies: ignoring non-project resource " + sourcePath.toString()); - } - // This should not occur. - continue; - } - - for(String s : entry.getValue()) - { - IFile f = getProjectResource(new Path(s)); - // Ignore any resources not in the project. - if(f != null) - { - Set<IFile> dependents = reverseSliceSliceDependencies.get(f); - if(dependents == null) - { - dependents = new HashSet<IFile>(); - reverseSliceSliceDependencies.put(f, dependents); - } - dependents.add(sourceFile); - } - } - - Set<IFile> dependents = new HashSet<IFile>(); - sliceSliceDependencies.put(sourceFile, dependents); - for(String s : entry.getValue()) - { - IFile f = getProjectResource(new Path(s)); - // Ignore any resources not in the project. - if(f != null) - { - dependents.add(f); - } - } - } - } - - private IFile getProjectResource(Path path) - { - IFile f = null; - if(path.isAbsolute()) - { - f = _locationToResource.get(path); - } - else - { - f = _project.getFile(path.toString()); - if(!f.exists()) - { - f = null; - } - } - if(_projectResources.contains(f)) - { - return f; - } - return null; - } - - public void read() - throws CoreException - { - IFileStore dependencies = getDependenciesStore(); - if(!dependencies.fetchInfo(EFS.NONE, null).exists()) - { - return; - } - InputStream in = dependencies.openInputStream(EFS.NONE, null); - - try - { - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new BufferedInputStream(in)); - DependenciesParser parser = new DependenciesParser(_project); - parser.visit(doc); - sliceSliceDependencies = parser.sliceSliceDependencies; - reverseSliceSliceDependencies = parser.reverseSliceSliceDependencies; - sliceJavaDependencies = parser.sliceJavaDependencies; - errorSliceFiles = parser.errorSliceFiles; - } - catch(SAXException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error reading dependencies", e)); - } - catch(ParserConfigurationException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error reading dependencies", e)); - } - catch(IOException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error reading dependencies", e)); - } - } - - public void write() - throws CoreException - { - // Create a DOM of the map. - Document doc = null; - try - { - doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - } - catch(ParserConfigurationException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error writing dependencies", e)); - } - - Element root = doc.createElement("dependencies"); - doc.appendChild(root); - - writeDependencies(sliceSliceDependencies, doc, "sliceSliceDependencies", root); - writeDependencies(reverseSliceSliceDependencies, doc, "reverseSliceSliceDependencies", root); - writeDependencies(sliceJavaDependencies, doc, "sliceJavaDependencies", root); - writeErrorSliceFiles(errorSliceFiles, doc, "errorSliceFiles", root); - - // Write the DOM to the dependencies.xml file. - TransformerFactory transfac = TransformerFactory.newInstance(); - Transformer trans = null; - try - { - trans = transfac.newTransformer(); - } - catch(TransformerConfigurationException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error writing dependencies", e)); - } - // tf.setAttribute("indent-number", 4); - - // trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - trans.setOutputProperty(OutputKeys.INDENT, "yes"); - trans.setOutputProperty(OutputKeys.ENCODING, "UTF8"); - trans.setOutputProperty(OutputKeys.INDENT, "yes"); - trans.setOutputProperty(OutputKeys.METHOD, "XML"); - - IFileStore dependencies = getDependenciesStore(); - OutputStream out = dependencies.openOutputStream(EFS.NONE, null); - StreamResult result = new StreamResult(new BufferedOutputStream(out)); - DOMSource source = new DOMSource(doc); - try - { - trans.transform(source, result); - } - catch(TransformerException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error writing dependencies", e)); - } - try - { - out.close(); - } - catch(IOException e) - { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "internal error writing dependencies", e)); - } - } - - private void writeErrorSliceFiles(Set<IFile> s, Document doc, String name, Element root) - { - Element jsd = doc.createElement(name); - root.appendChild(jsd); - - for(IFile f : s) - { - Element elem = doc.createElement("file"); - jsd.appendChild(elem); - Text text = doc.createTextNode(f.getProjectRelativePath().toString()); - elem.appendChild(text); - } - } - - private void writeDependencies(Map<IFile, Set<IFile>> map, Document doc, String name, Element root) - { - Element jsd = doc.createElement(name); - root.appendChild(jsd); - - Iterator<Map.Entry<IFile, Set<IFile>>> p = map.entrySet().iterator(); - while(p.hasNext()) - { - Map.Entry<IFile, Set<IFile>> e = p.next(); - Element entry = doc.createElement("entry"); - jsd.appendChild(entry); - - Element key = doc.createElement("key"); - entry.appendChild(key); - Text text = doc.createTextNode(e.getKey().getProjectRelativePath().toString()); - key.appendChild(text); - - Element value = doc.createElement("value"); - entry.appendChild(value); - - Iterator<IFile> q = e.getValue().iterator(); - while(q.hasNext()) - { - IFile f = q.next(); - Element elem = doc.createElement("file"); - value.appendChild(elem); - text = doc.createTextNode(f.getProjectRelativePath().toString()); - elem.appendChild(text); - } - } - } - - private IFileStore getDependenciesStore() - throws CoreException - { - IPath name = new Path(_project.getName()); - IFileStore store = EFS.getLocalFileSystem().getStore(Activator.getDefault().getStateLocation()).getFileStore( - name); - if(!store.fetchInfo(EFS.NONE, null).exists()) - { - store.mkdir(EFS.NONE, null); - } - return store.getFileStore(new Path("dependencies.xml")); - } - - private static class Slice2JavaDependenciesParser - { - Map<String, List<String>> dependencies = new java.util.HashMap<String, List<String>>(); - - private Node findNode(Node n, String qName) - throws SAXException - { - NodeList children = n.getChildNodes(); - for(int i = 0; i < children.getLength(); ++i) - { - Node child = children.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(qName)) - { - return child; - } - } - throw new SAXException("no such node: " + qName); - } - - private void visitDependencies(Node n) throws SAXException - { - NodeList children = n.getChildNodes(); - for(int i = 0; i < children.getLength(); ++i) - { - if(children.item(i).getNodeType() == Node.ELEMENT_NODE && children.item(i).getNodeName().equals("source")) - { - String source = ((Element)children.item(i)).getAttribute("name"); - if(source.length() == 0) - { - throw new SAXException("empty name attribute"); - } - List<String> dependsOn = visitDependsOn(children.item(i)); - dependencies.put(source, dependsOn); - } - } - } - - private List<String> visitDependsOn(Node source) throws SAXException - { - List<String> depends = new ArrayList<String>(); - NodeList dependencies = source.getChildNodes(); - for(int j = 0; j < dependencies.getLength(); ++j) - { - if(dependencies.item(j).getNodeType() == Node.ELEMENT_NODE && dependencies.item(j).getNodeName().equals("dependsOn")) - { - Element dependsOn = (Element)dependencies.item(j); - String name = dependsOn.getAttribute("name"); - if(name.length() == 0) - { - throw new SAXException("empty name attribute"); - } - depends.add(name); - } - } - return depends; - } - - public void visit(Node doc) throws SAXException - { - Node n = findNode(doc, "dependencies"); - visitDependencies(n); - } - } - - private static class DependenciesParser - { - private IProject _project; - - Map<IFile, Set<IFile>> sliceSliceDependencies = new java.util.HashMap<IFile, Set<IFile>>(); - Map<IFile, Set<IFile>> reverseSliceSliceDependencies = new java.util.HashMap<IFile, Set<IFile>>(); - Map<IFile, Set<IFile>> sliceJavaDependencies = new java.util.HashMap<IFile, Set<IFile>>(); - Set<IFile> errorSliceFiles = new java.util.HashSet<IFile>(); - - private Node findNode(Node n, String qName) - throws SAXException - { - NodeList children = n.getChildNodes(); - for(int i = 0; i < children.getLength(); ++i) - { - Node child = children.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(qName)) - { - return child; - } - } - throw new SAXException("no such node: " + qName); - } - - private String getText(Node n) - throws SAXException - { - NodeList children = n.getChildNodes(); - if(children.getLength() == 1 && children.item(0).getNodeType() == Node.TEXT_NODE) - { - return children.item(0).getNodeValue(); - } - throw new SAXException("no text element"); - } - - private List<String> processFiles(Node n) - throws SAXException - { - List<String> files = new ArrayList<String>(); - NodeList children = n.getChildNodes(); - for(int i = 0; i < children.getLength(); ++i) - { - Node child = children.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals("file")) - { - files.add(getText(child)); - } - } - return files; - } - - public void visitDependencies(Map<IFile, Set<IFile>> map, Node n) - throws SAXException - { - NodeList children = n.getChildNodes(); - for(int i = 0; i < children.getLength(); ++i) - { - Node child = children.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals("entry")) - { - IFile key = _project.getFile(new Path(getText(findNode(child, "key")))); - - Node value = findNode(child, "value"); - List<String> files = processFiles(value); - Set<IFile> f = new HashSet<IFile>(); - for(String s : files) - { - f.add(_project.getFile(new Path(s))); - } - - map.put(key, f); - } - } - } - - public void visitErrorList(Set<IFile> s, Node n) throws SAXException - { - NodeList children = n.getChildNodes(); - for(int i = 0; i < children.getLength(); ++i) - { - Node child = children.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals("file")) - { - s.add(_project.getFile(new Path(getText(child)))); - } - } - } - - public void visit(Node doc) - throws SAXException - { - Node dependencies = findNode(doc, "dependencies"); - visitDependencies(sliceSliceDependencies, findNode(dependencies, "sliceSliceDependencies")); - visitDependencies(reverseSliceSliceDependencies, findNode(dependencies, "reverseSliceSliceDependencies")); - visitDependencies(sliceJavaDependencies, findNode(dependencies, "sliceJavaDependencies")); - try - { - visitErrorList(errorSliceFiles, findNode(dependencies, "errorSliceFiles")); - } - catch(SAXException e) - { - // Optional. - } - } - - DependenciesParser(IProject project) - { - _project = project; - } - } - - // A map of slice to dependencies. - // - // sliceSliceDependencies is the set of slice files that depend on the IFile - // (the output of slice2java --depend). - // - // _reverseSliceSliceDependencies is the reverse. - public Map<IFile, Set<IFile>> sliceSliceDependencies = new java.util.HashMap<IFile, Set<IFile>>(); - public Map<IFile, Set<IFile>> reverseSliceSliceDependencies = new java.util.HashMap<IFile, Set<IFile>>(); - - // A map of slice file to java source files. - public Map<IFile, Set<IFile>> sliceJavaDependencies = new java.util.HashMap<IFile, Set<IFile>>(); - - // A set of slice files that have not, or cannot be built. - public Set<IFile> errorSliceFiles = new java.util.HashSet<IFile>(); - - private IProject _project; - private MessageConsoleStream _err; - private Set<IFile> _projectResources; - private Map<IPath, IFile> _locationToResource = new HashMap<IPath, IFile>(); -} diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathContainer.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathContainer.java deleted file mode 100644 index ea56851d25d..00000000000 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathContainer.java +++ /dev/null @@ -1,47 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. -// -// This plug-in is provided to you under the terms and conditions -// of the Eclipse Public License Version 1.0 ("EPL"). A copy of -// the EPL is available at http://www.eclipse.org/legal/epl-v10.html. -// -// ********************************************************************** - -package com.zeroc.slice2javaplugin.internal; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IClasspathEntry; - -public class IceClasspathContainer implements IClasspathContainer -{ - private IClasspathEntry[] _cpEntry; - private IPath _path; - - IceClasspathContainer(IClasspathEntry[] entries, IPath path) - { - _cpEntry = entries; - _path = path; - } - - public IClasspathEntry[] getClasspathEntries() - { - return _cpEntry; - } - - public String getDescription() - { - return "Ice Library"; - } - - public int getKind() - { - return IClasspathContainer.K_APPLICATION; - } - - public IPath getPath() - { - return _path; - } -} diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathContainerIntializer.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathContainerIntializer.java deleted file mode 100644 index 9c64c8abfae..00000000000 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathContainerIntializer.java +++ /dev/null @@ -1,129 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. -// -// This plug-in is provided to you under the terms and conditions -// of the Eclipse Public License Version 1.0 ("EPL"). A copy of -// the EPL is available at http://www.eclipse.org/legal/epl-v10.html. -// -// ********************************************************************** - -package com.zeroc.slice2javaplugin.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.ClasspathContainerInitializer; -import org.eclipse.jdt.core.IAccessRule; -import org.eclipse.jdt.core.IClasspathAttribute; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; - -public class IceClasspathContainerIntializer extends ClasspathContainerInitializer -{ - private final static String CONTAINER_ID = "com.zeroc.Slice2JavaPlugin.ICE_FRAMEWORK"; - - @Override - public void initialize(IPath containerPath, IJavaProject project) - throws CoreException - { - if(containerPath.toString().equals(CONTAINER_ID)) - { - Configuration c = new Configuration(project.getProject()); - configure(c, project, containerPath); - } - } - - public static IClasspathEntry getContainerEntry() - { - return JavaCore.newContainerEntry(new Path(CONTAINER_ID)); - } - - public static void reinitialize(IProject project, Configuration c) - throws CoreException - { - IJavaProject javaProject = JavaCore.create(project); - IPath containerPath = new Path(CONTAINER_ID); - - configure(c, javaProject, containerPath); - } - - private static String componentName(String jar) - { - String[] jars = new String[]{"Ice.jar", "Glacier2.jar", "IceBox.jar", "IceStorm.jar", "IceGrid.jar"}; - for(String f : jars) - { - if(f.equals(jar)) - { - return jar.replace(".jar", ""); - } - } - - if(jar.matches("ice-.*")) - { - return "Ice"; - } - else if(jar.matches("glacier2-.*")) - { - return "Glacier2"; - } - else if(jar.matches("icebox-.*")) - { - return "IceBox"; - } - else if(jar.matches("icestorm-.*")) - { - return "IceStorm"; - } - else if(jar.matches("icegrid-.*")) - { - return "IceGrid"; - } - return null; - } - - private static void configure(Configuration c, IJavaProject javaProject, IPath containerPath) - throws JavaModelException - { - if(c.getAddJars()) - { - Path dir = new Path(Configuration.getJarDir()); - List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); - for(String jar : c.getJars()) - { - IPath path = dir.append(new Path(c.getJarName(componentName(jar)))); - IClasspathEntry classpathEntry = JavaCore.newLibraryEntry(path, null, null, new IAccessRule[0], new IClasspathAttribute[0], false); - entries.add(classpathEntry); - } - - IClasspathContainer container = new IceClasspathContainer(entries.toArray(new IClasspathEntry[0]), containerPath); - JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { javaProject }, - new IClasspathContainer[] { container }, new NullProgressMonitor()); - } - } - - public static void updateProjects(String value, List<IJavaProject> projects) - { - for(IJavaProject p : projects) - { - IPath containerPath = new Path(CONTAINER_ID); - Configuration c = new Configuration(p.getProject()); - try - { - configure(c, p, containerPath); - } - catch(JavaModelException e) - { - e.printStackTrace(); - } - } - } -} diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathVariableInitializer.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathVariableInitializer.java deleted file mode 100644 index d454cb1e0ee..00000000000 --- a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/internal/IceClasspathVariableInitializer.java +++ /dev/null @@ -1,44 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. -// -// This plug-in is provided to you under the terms and conditions -// of the Eclipse Public License Version 1.0 ("EPL"). A copy of -// the EPL is available at http://www.eclipse.org/legal/epl-v10.html. -// -// ********************************************************************** - -package com.zeroc.slice2javaplugin.internal; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.ClasspathVariableInitializer; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; - -public class IceClasspathVariableInitializer extends ClasspathVariableInitializer -{ - private final static String VARIABLE_NAME = "ICE_JAR_HOME"; - - @Override - public void initialize(String variable) - { - if(variable.equals(VARIABLE_NAME)) - { - update(); - } - } - - public static void update() - { - IPath path = new Path(Configuration.getJarDir()); - try - { - JavaCore.setClasspathVariable(VARIABLE_NAME, path, null); - } - catch(JavaModelException e) - { - e.printStackTrace(); - } - } -}
\ No newline at end of file |