diff options
88 files changed, 2217 insertions, 1401 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/.classpath b/bundles/org.eclipse.equinox.frameworkadmin.equinox/.classpath index ce0c7a5d4..6f3b481ac 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/.classpath +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF index fe7ef37a1..7f3334cad 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF @@ -26,5 +26,5 @@ Import-Package: org.eclipse.core.runtime.adaptor, Export-Package: org.eclipse.equinox.internal.frameworkadmin.equinox;x-friends:="org.eclipse.equinox.p2.publisher,org.eclipse.equinox.p2.metadata.generator", org.eclipse.equinox.internal.frameworkadmin.equinox.utils;x-internal:=true Require-Bundle: org.eclipse.equinox.common -Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, +Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, J2SE-1.4 diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java index 248d36608..1dab2b1c4 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java @@ -11,240 +11,242 @@ package org.eclipse.equinox.internal.frameworkadmin.equinox; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.LinkedList; -import java.util.List; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; +import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException; import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; import org.eclipse.osgi.util.NLS; import org.osgi.service.log.LogService; public class EclipseLauncherParser { + private static final String CONFIGURATION_FOLDER = "configuration"; //$NON-NLS-1$ - private String[] getConfigFileLines(LauncherData launcherData, File outputFile, boolean relative) { - List lines = new LinkedList(); - - boolean startUpFlag = false; - final String[] programArgs = launcherData.getProgramArgs(); - if (programArgs != null && programArgs.length != 0) - for (int i = 0; i < programArgs.length; i++) { - if (programArgs[i].equals(EquinoxConstants.OPTION_STARTUP) && (programArgs[i + 1] != null || programArgs[i + 1].length() != 0)) { - lines.add(programArgs[i]); - lines.add(programArgs[++i]); - startUpFlag = true; - } else - lines.add(programArgs[i]); - } - if (launcherData.isClean()) - lines.add(EquinoxConstants.OPTION_CLEAN); - File fwPersistentDataLocation = launcherData.getFwPersistentDataLocation(); - File fwConfigLocation = launcherData.getFwConfigLocation(); - if (fwPersistentDataLocation != null) { - if (fwConfigLocation != null) { - if (!fwPersistentDataLocation.equals(fwConfigLocation)) - throw new IllegalStateException(); - } - launcherData.setFwConfigLocation(fwPersistentDataLocation); - } else if (fwConfigLocation != null) - launcherData.setFwPersistentDataLocation(fwConfigLocation, launcherData.isClean()); + //this figures out the location of the data area on partial data read from the <eclipse>.ini + private URI getOSGiInstallArea(List lines, URI base) { + File osgiInstallArea = ParserUtils.getOSGiInstallArea(lines, base); + if (osgiInstallArea != null) + return URIUtil.makeAbsolute(osgiInstallArea.toURI(), base); + return null; + } - if (launcherData.getFwConfigLocation() != null) { - lines.add(EquinoxConstants.OPTION_CONFIGURATION); - lines.add(launcherData.getFwConfigLocation().getAbsolutePath()); + private void setInstall(List lines, LauncherData launcherData, File launcherFolder) { + if (launcherData.getFwConfigLocation() == null || launcherData.getFwJar() == null) { + ParserUtils.removeArgument(EquinoxConstants.OPTION_INSTALL, lines); + return; } + if (!launcherData.getFwJar().getParentFile().equals(launcherFolder)) { + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_INSTALL, launcherFolder.getAbsolutePath(), lines); + } + } - if (!startUpFlag) - if (launcherData.getFwJar() != null) { - lines.add(EquinoxConstants.OPTION_FW); - String path = ""; //$NON-NLS-1$ - //if (relative) - // path = Utils.getRelativePath(launcherData.getFwJar(), outputFile.getParentFile()); - //else - path = launcherData.getFwJar().getAbsolutePath(); - lines.add(path); - } + void read(File launcherConfigFile, LauncherData launcherData) throws IOException { + if (!launcherConfigFile.exists()) + return; + + List lines = FileUtils.loadFile(launcherConfigFile); - if (launcherData.getJvm() != null) { - lines.add(EquinoxConstants.OPTION_VM); - lines.add(launcherData.getJvm().getAbsolutePath()); + URI launcherFolder = launcherData.getLauncher().getParentFile().toURI(); + getStartup(lines, launcherFolder); + // getFrameworkJar(lines, launcherFolder, launcherData); + URI osgiInstallArea = getOSGiInstallArea(lines, launcherFolder); + if (osgiInstallArea == null) { + osgiInstallArea = launcherData.getFwJar() != null ? launcherData.getFwJar().getParentFile().toURI() : launcherFolder; } - final String[] jvmArgs = launcherData.getJvmArgs(); - if (jvmArgs != null && jvmArgs.length != 0) { - lines.add(EquinoxConstants.OPTION_VMARGS); - for (int i = 0; i < jvmArgs.length; i++) - lines.add(jvmArgs[i]); + URI configArea = getConfigurationLocation(lines, osgiInstallArea, launcherData); + if (configArea == null) + throw new FrameworkAdminRuntimeException("config area is null", ""); + getPersistentDataLocation(lines, osgiInstallArea, configArea, launcherData); + getLauncherLibrary(lines, launcherFolder); + getJVMArgs(lines, launcherData); + getVM(lines, launcherFolder, launcherData); + + launcherData.setProgramArgs(null); + launcherData.setProgramArgs((String[]) lines.toArray(new String[lines.size()])); + + Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_configFile, launcherConfigFile.getAbsolutePath())); + } + + private void getPersistentDataLocation(List lines, URI osgiInstallArea, URI configArea, LauncherData launcherData) { + //TODO The setting of the -clean could only do properly once config.ini has been read + if (launcherData.getFwPersistentDataLocation() == null) { + launcherData.setFwPersistentDataLocation(URIUtil.toFile(configArea), ParserUtils.isArgumentSet(EquinoxConstants.OPTION_CLEAN, lines)); } - String[] ret = new String[lines.size()]; - lines.toArray(ret); - return ret; } - private void parseCmdLine(LauncherData launcherData, String[] lines) { - //Log.log(LogService.LOG_DEBUG, "inputFile=" + inputFile.getAbsolutePath()); - // final File launcherFile = launcherData.getLauncher(); - final File launcherConfigFile = EquinoxManipulatorImpl.getLauncherConfigLocation(launcherData); - - boolean clean = launcherData.isClean(); - boolean needToUpdate = false; - File fwPersistentDataLoc = launcherData.getFwPersistentDataLocation(); - File fwConfigLocation = launcherData.getFwConfigLocation(); - if (fwPersistentDataLoc == null) { - if (fwConfigLocation == null) { - fwPersistentDataLoc = new File(launcherConfigFile.getParent(), EquinoxConstants.DEFAULT_CONFIGURATION); - fwConfigLocation = fwPersistentDataLoc; - needToUpdate = true; - } else { - fwPersistentDataLoc = fwConfigLocation; - needToUpdate = true; - } - } else { - if (fwConfigLocation == null) { - fwConfigLocation = fwPersistentDataLoc; - needToUpdate = true; - } + private void getVM(List lines, URI launcherFolder, LauncherData launcherData) { + String vm = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_VM, lines); + if (vm == null) + return; + + URI VMFullPath; + try { + VMFullPath = URIUtil.makeAbsolute(FileUtils.fromPath(vm), launcherFolder); + launcherData.setJvm(URIUtil.toFile(VMFullPath)); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_VM, VMFullPath.toString(), lines); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make absolute of:" + vm); + return; } + } - File fwJar = launcherData.getFwJar(); - if (fwJar == null) { - String location = FileUtils.getEclipsePluginFullLocation(EquinoxConstants.FW_SYMBOLIC_NAME, new File(launcherConfigFile.getParent(), EquinoxConstants.PLUGINS_DIR)); - if (location != null) - try { - fwJar = new File(new URL(location).getFile()); - launcherData.setFwJar(fwJar); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + private void setVM(List lines, URI launcherFolder) { + String vm = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_VM, lines); + if (vm == null) + return; + + try { + URI VMRelativePath = URIUtil.makeRelative(URIUtil.fromString(vm), launcherFolder); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_VM, FileUtils.toPath(VMRelativePath), lines); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make relative of:" + vm); } - // launcherData.initialize(); // reset except launcherFile. - - // launcherData.setLauncher(launcherFile); - boolean vmArgsFlag = false; - - for (int i = 0; i < lines.length; i++) { - final String line = lines[i].trim(); - if (line.startsWith("#")) //$NON-NLS-1$ - continue; - if (line.length() == 0) - continue; - if (vmArgsFlag) { - launcherData.addJvmArg(line); - continue; - } - if (line.equalsIgnoreCase(EquinoxConstants.OPTION_VMARGS)) { - vmArgsFlag = true; - continue; - } - if (line.equalsIgnoreCase(EquinoxConstants.OPTION_CONFIGURATION)) { - final String nextLine = lines[++i].trim(); - File file = new File(nextLine); - if (!file.isAbsolute()) - file = new File(launcherConfigFile.getParent() + File.separator + nextLine); - fwPersistentDataLoc = file; - needToUpdate = true; - continue; - } else if (line.equalsIgnoreCase(EquinoxConstants.OPTION_CLEAN)) { - clean = true; - needToUpdate = true; - continue; - } else if (line.equalsIgnoreCase(EquinoxConstants.OPTION_VM)) { - final String nextLine = lines[++i].trim(); - File file = new File(nextLine); - if (!file.isAbsolute()) { - file = new File(launcherConfigFile.getAbsolutePath() + File.separator + nextLine); - } - launcherData.setJvm(file); - continue; - } else if (line.equalsIgnoreCase(EquinoxConstants.OPTION_FW)) { - final String nextLine = lines[++i].trim(); - File file = new File(nextLine); - if (!file.isAbsolute()) { - file = new File(launcherConfigFile.getAbsolutePath() + File.separator + nextLine); - } - launcherData.setFwJar(file); - continue; - } else { - launcherData.addProgramArg(lines[i]); - // Log.log(LogService.LOG_WARNING, this, "parseCmdLine(String[] lines, File inputFile)", "Unsupported by current impl:line=" + line); - } + } + + private void getJVMArgs(List lines, LauncherData launcherData) { + String[] vmargs = ParserUtils.getMultiValuedArgument(EquinoxConstants.OPTION_VMARGS, lines); + if (vmargs != null) + launcherData.setJvmArgs(vmargs); + } + + private void setJVMArgs(List lines, LauncherData launcherData) { + ParserUtils.removeArgument(EquinoxConstants.OPTION_VMARGS, lines); + if (launcherData.getJvmArgs() == null || launcherData.getJvmArgs().length == 0) + return; + String[] args = launcherData.getJvmArgs(); + lines.add(EquinoxConstants.OPTION_VMARGS); + for (int i = 0; i < args.length; i++) { + lines.add(args[i]); } - if (needToUpdate) { - launcherData.setFwPersistentDataLocation(fwPersistentDataLoc, clean); - launcherData.setFwConfigLocation(fwPersistentDataLoc); + } + + private URI getLauncherLibrary(List lines, URI launcherFolder) { + String launcherLibrary = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, lines); + if (launcherLibrary == null) + return null; + + URI result = null; + try { + result = URIUtil.makeAbsolute(URIUtil.fromString(launcherLibrary), launcherFolder); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, result.toString(), lines); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make absolute of:" + launcherLibrary); + return null; } + return result; } - public void read(LauncherData launcherData) throws IOException { - final File launcherConfigFile = EquinoxManipulatorImpl.getLauncherConfigLocation(launcherData); - if (launcherConfigFile == null) - throw new IllegalStateException(Messages.exception_launcherLocationNotSet); - if (!launcherConfigFile.exists()) + private void setLauncherLibrary(List lines, URI launcherFolder) { + String launcherLibrary = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, lines); + if (launcherLibrary == null) return; - BufferedReader br = null; try { - br = new BufferedReader(new FileReader(launcherConfigFile)); + URI result = URIUtil.makeRelative(FileUtils.fromPath(launcherLibrary), launcherFolder); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, FileUtils.toPath(result), lines); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make absolute of:" + launcherLibrary); + return; + } + } - String line; - List list = new LinkedList(); - while ((line = br.readLine()) != null) { - list.add(line); + private URI getConfigurationLocation(List lines, URI osgiInstallArea, LauncherData data) { + String configuration = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, lines); + if (configuration == null) + try { + return URIUtil.makeAbsolute(new URI(CONFIGURATION_FOLDER), osgiInstallArea); + } catch (URISyntaxException e1) { + //ignore } - String[] lines = (String[]) list.toArray(new String[list.size()]); - String osgiInstallArea = getLauncher(lines) != null ? EquinoxManipulatorImpl.makeAbsolute(getLauncher(lines).getPath(), launcherData.getLauncher().getParentFile().getAbsolutePath()) : null; - - String resolveNextLine = null; - for (int i = 0; i < lines.length; i++) { - if (resolveNextLine != null) { - lines[i] = EquinoxManipulatorImpl.makeAbsolute(lines[i], resolveNextLine); - resolveNextLine = null; - } else { - resolveNextLine = needsPathResolution(lines[i], osgiInstallArea, launcherData.getLauncher().getParentFile().getAbsolutePath() + File.separator); - } - } - this.parseCmdLine(launcherData, lines); - } finally { - if (br != null) - br.close(); + + URI result = null; + try { + result = URIUtil.makeAbsolute(FileUtils.fromPath(configuration), osgiInstallArea); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, result.toString(), lines); + data.setFwConfigLocation(URIUtil.toFile(result)); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make absolute of:" + configuration); + return null; } - Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_configFile, launcherConfigFile.getAbsolutePath())); + return result; } - private File getLauncher(String[] args) { - for (int i = 0; i < args.length; i++) { - if (args[i].equals(EquinoxConstants.OPTION_STARTUP) && i + 1 < args.length && args[i + 1].charAt(1) != '-') { - IPath parentFolder = new Path(args[i + 1]).removeLastSegments(1); - if (parentFolder.lastSegment().equals("plugins")) //$NON-NLS-1$ - return parentFolder.removeLastSegments(1).toFile(); - return parentFolder.toFile(); - } + private void setConfigurationLocation(List lines, URI osgiInstallArea, LauncherData data) { + String result = FileUtils.toPath(URIUtil.makeRelative(data.getFwConfigLocation().toURI(), osgiInstallArea)); + //We don't write the default + if (CONFIGURATION_FOLDER.equals(result)) { + if (ParserUtils.getValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, lines) != null) + ParserUtils.removeArgument(EquinoxConstants.OPTION_CONFIGURATION, lines); + return; } - return null; + + if (ParserUtils.getValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, lines) == null) { + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, result, lines); + } + return; } - //Return the base against which the path needs to be resolved, if resolution is needed. - private String needsPathResolution(String entry, String osgiInstallArea, String launcherFolder) { - if (EquinoxConstants.OPTION_CONFIGURATION.equalsIgnoreCase(entry)) - return osgiInstallArea; - if ("--launcher.library".equalsIgnoreCase(entry)) //$NON-NLS-1$ - return launcherFolder; - if (EquinoxConstants.OPTION_STARTUP.equalsIgnoreCase(entry)) - return launcherFolder; - if (EquinoxConstants.OPTION_FW.equalsIgnoreCase(entry)) - return osgiInstallArea != null ? osgiInstallArea : launcherFolder; - return null; + private URI getStartup(List lines, URI launcherFolder) { + String startup = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_STARTUP, lines); + if (startup == null) + return null; + + URI result = null; + try { + result = URIUtil.makeAbsolute(FileUtils.fromPath(startup), launcherFolder); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_STARTUP, result.toString(), lines); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make absolute of:" + startup); + return null; + } + return result; + } + + private void setStartup(List lines, URI launcherFolder) { + String startup = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_STARTUP, lines); + if (startup == null) + return; + + try { + URI result = URIUtil.makeRelative(FileUtils.fromPath(startup), launcherFolder); + ParserUtils.setValueForArgument(EquinoxConstants.OPTION_STARTUP, FileUtils.toPath(result), lines); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make relative of:" + startup); + return; + } } - public void save(EquinoxLauncherData launcherData, boolean relative, boolean backup) throws IOException { + void save(EquinoxLauncherData launcherData, boolean backup) throws IOException { File launcherConfigFile = EquinoxManipulatorImpl.getLauncherConfigLocation(launcherData); if (launcherConfigFile == null) throw new IllegalStateException(Messages.exception_launcherLocationNotSet); - Utils.createParentDir(launcherConfigFile); + if (!Utils.createParentDir(launcherConfigFile)) { + throw new IllegalStateException(Messages.exception_failedToCreateDir); + } + //Tweak all the values to make them relative + File launcherFolder = launcherData.getLauncher().getParentFile(); + List newlines = new ArrayList(); + newlines.addAll(Arrays.asList(launcherData.getProgramArgs())); + + setStartup(newlines, launcherFolder.toURI()); + setInstall(newlines, launcherData, launcherFolder); + //Get the osgi install area + File osgiInstallArea = ParserUtils.getOSGiInstallArea(newlines, launcherData); + //setInstall(lines, osgiInstallArea, launcherFolder); + setConfigurationLocation(newlines, osgiInstallArea.toURI(), launcherData); + setLauncherLibrary(newlines, launcherFolder.toURI()); + // setFrameworkJar(newlines, launcherData.getFwJar()); + setVM(newlines, launcherFolder.toURI()); + setJVMArgs(newlines, launcherData); + + //We are done, let's update the program args in the launcher data + launcherData.setProgramArgs(null); + launcherData.setProgramArgs((String[]) newlines.toArray(new String[newlines.size()])); + // backup file if exists. if (backup) if (launcherConfigFile.exists()) { @@ -257,42 +259,11 @@ public class EclipseLauncherParser { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(launcherConfigFile)); - - String launcherFolder = launcherData.getLauncher().getParentFile().getAbsolutePath(); - String[] lines = this.getConfigFileLines(launcherData, launcherConfigFile, relative); - String osgiInstallArea = getLauncher(lines) != null ? EquinoxManipulatorImpl.makeAbsolute(getLauncher(lines).getPath(), launcherFolder) : launcherFolder; - String resolveNextLine = null; - for (int i = 0; i < lines.length; i++) { - if (resolveNextLine != null) { - lines[i] = EquinoxManipulatorImpl.makeRelative(lines[i], resolveNextLine); - resolveNextLine = null; - } else { - resolveNextLine = needsPathResolution(lines[i], osgiInstallArea, launcherFolder + File.separator); - if (EquinoxConstants.OPTION_CONFIGURATION.equalsIgnoreCase(lines[i])) { - resolveNextLine = null; - - //We don't write -configuration when it is the default value - File defaultConfigArea = new File(osgiInstallArea, "configuration"); //$NON-NLS-1$ - File specifiedArea = new File(lines[i + 1]); - if (defaultConfigArea.equals(specifiedArea)) { - i++; - continue; - } - - Path configLocation = new Path(lines[i + 1]); - Path osgiPath = new Path(osgiInstallArea); - int commonSegments = osgiPath.matchingFirstSegments(configLocation.removeLastSegments(1)); - if (commonSegments == configLocation.segmentCount() - 1) { - String path = ""; //$NON-NLS-1$ - for (int j = osgiPath.segmentCount() - commonSegments; j != 0; j--) { - path += "../"; //$NON-NLS-1$ - } - path += configLocation.lastSegment(); - lines[i + 1] = path; - } - } - } - bw.write(lines[i]); + for (int j = 0; j < newlines.size(); j++) { + String arg = (String) newlines.get(j); + if (arg == null) + continue; + bw.write(arg); bw.newLine(); } bw.flush(); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java index 2828563d6..4d1e2d6f2 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java @@ -11,7 +11,8 @@ package org.eclipse.equinox.internal.frameworkadmin.equinox; import java.io.File; -import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.internal.adaptor.EclipseEnvironmentInfo; import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; @@ -118,7 +119,7 @@ public class EquinoxBundlesState implements BundlesState { return null; } - private static File getSystemBundleFromBundleInfos(ConfigData configData) { + protected static File getSystemBundleFromBundleInfos(ConfigData configData) { BundleInfo[] bundleInfos = configData.getBundles(); return getSystemBundleFromBundleInfos(bundleInfos); } @@ -143,20 +144,15 @@ public class EquinoxBundlesState implements BundlesState { public static File isSystemBundle(BundleInfo bundleInfo) { if (bundleInfo == null || bundleInfo.getLocation() == null) return null; - String bundleLocation = bundleInfo.getLocation(); - if (bundleLocation.startsWith(EquinoxConstants.REFERENCE)) - bundleLocation = bundleLocation.substring(EquinoxConstants.REFERENCE.length()); - if (bundleLocation.startsWith("file:")) { //$NON-NLS-1$ - try { - String[] clauses = Utils.getClausesManifestMainAttributes(bundleLocation, Constants.BUNDLE_SYMBOLICNAME); - if (bundleLocation.indexOf(EquinoxConstants.FW_SYMBOLIC_NAME) > 0) - if (EquinoxConstants.PERSISTENT_DIR_NAME.equals(Utils.getPathFromClause(clauses[0]))) - return new File(bundleLocation.substring("file:".length())); //$NON-NLS-1$ - } catch (RuntimeException e) { - e.printStackTrace(); - } + URI bundleLocation = bundleInfo.getLocation(); + try { + String[] clauses = Utils.getClausesManifestMainAttributes(bundleLocation, Constants.BUNDLE_SYMBOLICNAME); + if (bundleLocation.getPath().indexOf(EquinoxConstants.FW_SYMBOLIC_NAME) > 0) + if (EquinoxConstants.PERSISTENT_DIR_NAME.equals(Utils.getPathFromClause(clauses[0]))) + return new File(bundleLocation); + } catch (RuntimeException e) { + e.printStackTrace(); } - return null; } @@ -274,7 +270,7 @@ public class EquinoxBundlesState implements BundlesState { * @param bInfos */ private void composeNewState(LauncherData launcherData, ConfigData configData, BundleInfo[] bInfos) { - this.composeNewState(launcherData, configData, configData.getFwDependentProps(), bInfos); + this.composeNewState(launcherData, configData, configData.getProperties(), bInfos); } /** @@ -374,13 +370,13 @@ public class EquinoxBundlesState implements BundlesState { boolean markedAsStarted = false; int sl = BundleInfo.NO_LEVEL; - String location = null; + URI location = null; String symbolicNameTarget = toConvert.getSymbolicName(); Version versionTarget = toConvert.getVersion(); try { File fwJar = manipulator.getLauncherData().getFwJar(); if (fwJar != null) { - String fwJarLocation = fwJar.toURL().toExternalForm(); + URI fwJarLocation = fwJar.toURI(); String[] clauses = Utils.getClausesManifestMainAttributes(fwJarLocation, Constants.BUNDLE_SYMBOLICNAME); String fwJarSymbolicName = Utils.getPathFromClause(clauses[0]); String fwJarVersionSt = Utils.getManifestMainAttributes(fwJarLocation, Constants.BUNDLE_VERSION); @@ -389,15 +385,13 @@ public class EquinoxBundlesState implements BundlesState { markedAsStarted = true; } } - } catch (MalformedURLException e1) { - Log.log(LogService.LOG_ERROR, "", e1); //$NON-NLS-1$ } catch (FrameworkAdminRuntimeException e1) { Log.log(LogService.LOG_ERROR, "", e1); //$NON-NLS-1$ } return createBundleInfo(toConvert, markedAsStarted, sl, location); } - private BundleInfo createBundleInfo(BundleDescription toConvert, boolean markedAsStarted, int sl, String location) { + private BundleInfo createBundleInfo(BundleDescription toConvert, boolean markedAsStarted, int sl, URI location) { BundleInfo result = new BundleInfo(); result.setSymbolicName(toConvert.getSymbolicName()); result.setVersion(toConvert.getVersion().toString()); @@ -425,7 +419,16 @@ public class EquinoxBundlesState implements BundlesState { boolean markedAsStarted = false; int sl = BundleInfo.NO_LEVEL; - String location = FileUtils.getEclipseRealLocation(manipulator, bundles[i].getLocation()); + + //URI location = FileUtils.getEclipseRealLocation(manipulator, bundles[i].getLocation()); + //TODO: I believe this is always an absolute URI + URI location; + try { + location = new URI(bundles[i].getLocation()); + } catch (URISyntaxException e) { + e.printStackTrace(); + throw new IllegalStateException("BundleDescription conversion problem" + e.getMessage()); //$NON-NLS-1$ //TODO path_fun + } BundleInfo original = (BundleInfo) bundleInfoMap.get(location); if (original != null) { markedAsStarted = original.isMarkedAsStarted(); @@ -447,7 +450,7 @@ public class EquinoxBundlesState implements BundlesState { public BundleInfo[] getPrerequisteBundles(BundleInfo bInfo) { Set set = new HashSet(); - String realLocation = FileUtils.getRealLocation(manipulator, bInfo.getLocation(), true); + URI realLocation = bInfo.getLocation(); BundleDescription bundle = getBundleByLocation(realLocation); ImportPackageSpecification[] imports = bundle.getImportPackages(); for (int i = 0; i < imports.length; i++) { @@ -493,7 +496,7 @@ public class EquinoxBundlesState implements BundlesState { } public String[] getUnsatisfiedConstraints(BundleInfo bInfo) { - String realLocation = FileUtils.getRealLocation(manipulator, bInfo.getLocation(), true); + URI realLocation = bInfo.getLocation(); BundleDescription description = getBundleByLocation(realLocation); PlatformAdmin platformAdmin = (PlatformAdmin) Activator.acquireService(PlatformAdmin.class.getName()); StateHelper helper = platformAdmin.getStateHelper(); @@ -521,7 +524,7 @@ public class EquinoxBundlesState implements BundlesState { if (manipulator.getLauncherData().getFwPersistentDataLocation() == null) { // TODO default value should be set more precisely. File installArea = null; - String installAreaSt = configData.getFwDependentProp(EquinoxConstants.PROP_INSTALL); + String installAreaSt = configData.getProperty(EquinoxConstants.PROP_INSTALL); if (installAreaSt == null) { if (manipulator.getLauncherData().getLauncher() == null) { // TODO implement @@ -548,7 +551,7 @@ public class EquinoxBundlesState implements BundlesState { public void installBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException { SimpleBundlesState.checkAvailability(fwAdmin); - String realLocation = FileUtils.getRealLocation(manipulator, bInfo.getLocation(), true); + URI realLocation = bInfo.getLocation(); if (getBundleByLocation(realLocation) != null) return; @@ -567,7 +570,7 @@ public class EquinoxBundlesState implements BundlesState { try { bInfo.setBundleId(++maxId); - BundleDescription newBundleDescription = soFactory.createBundleDescription(state, manifest, realLocation, bInfo.getBundleId()); + BundleDescription newBundleDescription = soFactory.createBundleDescription(state, manifest, realLocation.toString(), bInfo.getBundleId()); addBundleToState(newBundleDescription); manipulator.getConfigData().addBundle(bInfo); } catch (BundleException e) { @@ -584,7 +587,7 @@ public class EquinoxBundlesState implements BundlesState { } public boolean isResolved(BundleInfo bInfo) { - String realLocation = FileUtils.getRealLocation(manipulator, bInfo.getLocation(), true); + URI realLocation = bInfo.getLocation(); BundleDescription description = getBundleByLocation(realLocation); if (description == null) return false; @@ -676,8 +679,8 @@ public class EquinoxBundlesState implements BundlesState { public void uninstallBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException { SimpleBundlesState.checkAvailability(fwAdmin); long id = DEFAULT_TIMESTAMP; - String realLocation = FileUtils.getRealLocation(manipulator, bInfo.getLocation(), true); - BundleDescription bundle = getBundleByLocation(realLocation); + URI realLocation = bInfo.getLocation(); + BundleDescription bundle = getBundleByLocation(bInfo.getLocation()); if (bundle != null) id = bundle.getBundleId(); @@ -688,7 +691,7 @@ public class EquinoxBundlesState implements BundlesState { Log.log(LogService.LOG_WARNING, this, "uninstallBundle(BundleInfo)", NLS.bind(Messages.exception_bundleManifest, bInfo.getLocation())); //$NON-NLS-1$ return; } - BundleDescription bundleDescription = soFactory.createBundleDescription(state, manifest, realLocation, id); + BundleDescription bundleDescription = soFactory.createBundleDescription(state, manifest, realLocation.toString(), id); removeBundleFromState(bundleDescription); manipulator.getConfigData().removeBundle(bInfo); } catch (BundleException e) { @@ -697,8 +700,10 @@ public class EquinoxBundlesState implements BundlesState { } } - private BundleDescription getBundleByLocation(String location) { - return (BundleDescription) locationStateIndex.get(location); + private BundleDescription getBundleByLocation(URI location) { + if (location == null) + return null; + return (BundleDescription) locationStateIndex.get(location.toString()); } private BundleDescription getBundleByNameVersion(String bundleSymbolicName, String bundleVersion) { @@ -716,7 +721,7 @@ public class EquinoxBundlesState implements BundlesState { private void createStateIndexes() { BundleDescription[] currentInstalledBundles = state.getBundles(); for (int i = 0; i < currentInstalledBundles.length; i++) { - String location = FileUtils.getRealLocation(manipulator, currentInstalledBundles[i].getLocation(), true); + URI location = FileUtils.getRealLocation(manipulator, currentInstalledBundles[i].getLocation().toString()); locationStateIndex.put(location, currentInstalledBundles[i]); nameVersionStateIndex.put(getKey(currentInstalledBundles[i]), currentInstalledBundles[i]); } @@ -724,13 +729,13 @@ public class EquinoxBundlesState implements BundlesState { private void addBundleToState(BundleDescription bundleDescription) { state.addBundle(bundleDescription); - String location = FileUtils.getRealLocation(manipulator, bundleDescription.getLocation(), true); + URI location = FileUtils.getRealLocation(manipulator, bundleDescription.getLocation().toString()); locationStateIndex.put(location, bundleDescription); nameVersionStateIndex.put(getKey(bundleDescription), bundleDescription); } private void removeBundleFromState(BundleDescription bundleDescription) { - String location = FileUtils.getRealLocation(manipulator, bundleDescription.getLocation(), true); + URI location = FileUtils.getRealLocation(manipulator, bundleDescription.getLocation().toString()); locationStateIndex.remove(location); nameVersionStateIndex.remove(getKey(bundleDescription)); state.removeBundle(bundleDescription); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxConstants.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxConstants.java index 8c1e20ec9..bc68cc5d0 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxConstants.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxConstants.java @@ -36,6 +36,8 @@ public class EquinoxConstants { public static final String OPTION_CLEAN = "-clean"; //$NON-NLS-1$ public static final String OPTION_STARTUP = "-startup"; //$NON-NLS-1$ public static final String OPTION_SHOWSPLASH = "-showsplash"; //$NON-NLS-1$ + public static final String OPTION_INSTALL = "-install"; //$NON-NLS-1$ + public static final String OPTION_LAUNCHER_LIBRARY = "--launcher.library"; //$NON-NLS-1$ // System properties public static final String PROP_BUNDLES = "osgi.bundles"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java index 23cc06d63..55f372e50 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java @@ -11,12 +11,9 @@ package org.eclipse.equinox.internal.frameworkadmin.equinox; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Enumeration; -import java.util.Properties; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; +import java.net.*; +import java.util.*; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; @@ -26,137 +23,59 @@ import org.osgi.service.log.LogService; public class EquinoxFwConfigFileParser { private static final String CONFIG_DIR = "@config.dir/"; //$NON-NLS-1$ - private static final String KEY_ECLIPSE_PROV_CACHE = "eclipse.p2.cache"; //$NON-NLS-1$ private static final String KEY_ECLIPSE_PROV_DATA_AREA = "eclipse.p2.data.area"; //$NON-NLS-1$ private static final String KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL = "org.eclipse.equinox.simpleconfigurator.configUrl"; //$NON-NLS-1$ - private static final String KEY_OSGI_BUNDLES = "osgi.bundles"; //$NON-NLS-1$ - private static final String KEY_OSGI_FRAMEWORK = "osgi.framework"; //$NON-NLS-1$ - private static final String KEY_OSGI_LAUNCHER_PATH = "osgi.launcherPath"; //$NON-NLS-1$ - private static final String[] PATHS = new String[] {KEY_OSGI_LAUNCHER_PATH, KEY_ECLIPSE_PROV_CACHE}; - + private static final String REFERENCE_SCHEME = "reference:"; //$NON-NLS-1$ + private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$ private static boolean DEBUG = false; - private static String USE_REFERENCE_STRING = null; public EquinoxFwConfigFileParser(BundleContext context) { - if (context != null) - USE_REFERENCE_STRING = context.getProperty(EquinoxConstants.PROP_KEY_USE_REFERENCE); - + //Empty } - private static String getCommandLine(BundleInfo bundleInfo, final URL baseUrl) { - String location = bundleInfo.getLocation(); - if (location == null) - return null; - boolean useReference = true; - if (location.startsWith("file:")) { //$NON-NLS-1$ - if (USE_REFERENCE_STRING != null && USE_REFERENCE_STRING.equals("false")) //$NON-NLS-1$ - useReference = false; - } - - try { - new URL(location); - } catch (MalformedURLException e) { - Log.log(LogService.LOG_ERROR, "EquinoxFwConfigFileParser.getCommandLine():bundleInfo=" + bundleInfo, e); //$NON-NLS-1$ - // Never happen. ignore. - } - if (useReference) - if (!location.startsWith("reference:")) //$NON-NLS-1$ - location = "reference:" + location; //$NON-NLS-1$ + private static StringBuffer toOSGiBundleListForm(BundleInfo bundleInfo, URI location) { + StringBuffer locationString = new StringBuffer(REFERENCE_SCHEME); + if (URIUtil.isFileURI(location)) + locationString.append(URIUtil.toUnencodedString(location)); + else if (location.getScheme() == null) + locationString.append(FILE_PROTOCOL).append(URIUtil.toUnencodedString(location)); + else + locationString = new StringBuffer(URIUtil.toUnencodedString(location)); int startLevel = bundleInfo.getStartLevel(); boolean toBeStarted = bundleInfo.isMarkedAsStarted(); StringBuffer sb = new StringBuffer(); - // if (baseUrl != null && bundleUrl.getProtocol().equals("file")) { - // String bundlePath = bundleUrl.toString(); - // bundlePath = Utils.getRelativePath(bundleUrl, baseUrl); - // sb.append(bundlePath); - // } else - sb.append(location); + sb.append(locationString); if (startLevel == BundleInfo.NO_LEVEL && !toBeStarted) - return sb.toString(); + return sb; sb.append('@'); if (startLevel != BundleInfo.NO_LEVEL) sb.append(startLevel); if (toBeStarted) sb.append(":start"); //$NON-NLS-1$ - return sb.toString(); - } - - private static Properties getConfigProps(BundleInfo[] bInfos, ConfigData configData, LauncherData launcherData, boolean relative, File fwJar) { - Properties props = new Properties(); - - if (configData.getInitialBundleStartLevel() != BundleInfo.NO_LEVEL) - props.setProperty(EquinoxConstants.PROP_BUNDLES_STARTLEVEL, Integer.toString(configData.getInitialBundleStartLevel())); - if (configData.getBeginingFwStartLevel() != BundleInfo.NO_LEVEL) - props.setProperty(EquinoxConstants.PROP_INITIAL_STARTLEVEL, Integer.toString(configData.getBeginingFwStartLevel())); - - final File launcher = launcherData.getLauncher(); - if (launcher != null) { - String launcherName = launcher.getName(); - if (launcherName.endsWith(EquinoxConstants.EXE_EXTENSION)) { - props.setProperty(EquinoxConstants.PROP_LAUNCHER_NAME, launcherName.substring(0, launcherName.lastIndexOf(EquinoxConstants.EXE_EXTENSION))); - props.setProperty(EquinoxConstants.PROP_LAUNCHER_PATH, launcher.getParentFile().getAbsolutePath()); - } - } - - String fwJarSt = null; - try { - if (fwJar != null) { - fwJarSt = fwJar.toURL().toExternalForm(); - } - } catch (MalformedURLException e) { - // Never happens - e.printStackTrace(); - } - - if (bInfos != null) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < bInfos.length; i++) { - normalizeLocation(bInfos[i]); - if (fwJarSt != null && fwJarSt.equals(bInfos[i].getLocation())) - continue; //framework jar should not appear in the bundles list - sb.append(getCommandLine(bInfos[i], null)); - if (i + 1 < bInfos.length) - sb.append(','); - } - props.setProperty(EquinoxConstants.PROP_BUNDLES, sb.toString()); - - } - //TODO The following merging operations are suspicious. - props = Utils.appendProperties(props, configData.getFwIndependentProps()); - - props = Utils.appendProperties(props, configData.getFwDependentProps()); - - //Deal with the fw jar and ensure it is not set. - //TODO This can't be done before because of the previous calls to appendProperties - if (fwJarSt != null) - props.setProperty(EquinoxConstants.PROP_OSGI_FW, fwJarSt /* fwJar.getAbsolutePath() */); - else - props.remove(EquinoxConstants.PROP_OSGI_FW); - - return props; + return sb; } - private static boolean getMarkedAsStartedFormat(String msg, String original) { - if (msg == null) + private static boolean getMarkedAsStartedFormat(String startInfo) { + if (startInfo == null) return false; - msg = msg.trim(); - int colon = msg.indexOf(":"); //$NON-NLS-1$ + startInfo = startInfo.trim(); + int colon = startInfo.indexOf(':'); if (colon > -1) { - return msg.substring(colon + 1).equals("start"); //$NON-NLS-1$ + return startInfo.substring(colon + 1).equals("start"); //$NON-NLS-1$ } - return msg.equals("start"); //$NON-NLS-1$ + return startInfo.equals("start"); //$NON-NLS-1$ } - private static int getStartLevel(String msg, String original) { - if (msg == null) + private static int getStartLevel(String startInfo) { + if (startInfo == null) return BundleInfo.NO_LEVEL; - msg = msg.trim(); - int colon = msg.indexOf(":"); //$NON-NLS-1$ + startInfo = startInfo.trim(); + int colon = startInfo.indexOf(":"); //$NON-NLS-1$ if (colon > 0) { try { - return Integer.parseInt(msg.substring(0, colon)); + return Integer.parseInt(startInfo.substring(0, colon)); } catch (NumberFormatException e) { return BundleInfo.NO_LEVEL; } @@ -164,64 +83,63 @@ public class EquinoxFwConfigFileParser { return BundleInfo.NO_LEVEL; } - static boolean isFwDependent(String key) { - // TODO This algorithm is temporal. - if (key.startsWith(EquinoxConstants.PROP_EQUINOX_DEPENDENT_PREFIX)) - return true; - return false; - } - - private static void normalizeLocation(BundleInfo bInfo) { - String location = bInfo.getLocation(); - try { - if (location.startsWith("file:")) { //$NON-NLS-1$ - bInfo.setLocation(new URL(location).toExternalForm()); - } else { - bInfo.setLocation(new File(location).toURL().toExternalForm()); - } - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // location = location.substring("file:".length()); - // if (!location.startsWith("/")) - // location = "/" + location; - // // if (fwJarSt != null) - // // if (fwJarSt.equals(location)) - // // continue; - // location = Utils.replaceAll(location, File.separator, "/"); - // //String jarName = location.substring(location.lastIndexOf("/") + 1); - // // if (jarName.startsWith(EquinoxConstants.FW_JAR_PLUGIN_NAME)) - // // continue; - // bInfo.setLocation("file:" + location); - // } - } - - /** - * @param value - */ - private static void setInstallingBundles(Manipulator manipulator, String value) throws NumberFormatException { + private void readBundlesList(Manipulator manipulator, URI osgiInstallArea, String value) throws NumberFormatException { ConfigData configData = manipulator.getConfigData(); if (value != null) { String[] bInfoStrings = Utils.getTokens(value, ","); //$NON-NLS-1$ for (int i = 0; i < bInfoStrings.length; i++) { - String token = bInfoStrings[i].trim(); - token = FileUtils.getRealLocation(manipulator, token, false).trim(); + String entry = bInfoStrings[i].trim(); + entry = FileUtils.removeEquinoxSpecificProtocols(entry); + + int indexStartInfo = entry.indexOf('@'); + String location = (indexStartInfo == -1) ? entry : entry.substring(0, indexStartInfo); + URI realLocation = null; + try { + if (manipulator.getLauncherData().getFwJar() != null) { + realLocation = URIUtil.makeAbsolute(FileUtils.fromFileURL(location), manipulator.getLauncherData().getFwJar().getParentFile().toURI()); + } + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "Can't make absolute..."); + continue; + } + String slAndFlag = (indexStartInfo > -1) ? entry.substring(indexStartInfo + 1) : null; + + boolean markedAsStarted = getMarkedAsStartedFormat(slAndFlag); + int startLevel = getStartLevel(slAndFlag); + + if (realLocation != null) { + configData.addBundle(new BundleInfo(realLocation, startLevel, markedAsStarted)); + return; + } + if (location != null && location.startsWith(FILE_PROTOCOL)) + try { + configData.addBundle(new BundleInfo(FileUtils.fromFileURL(location), startLevel, markedAsStarted)); + return; + } catch (URISyntaxException e) { + //Ignore + } + + //Fallback case, we use the location as a string + configData.addBundle(new BundleInfo(location, null, null, startLevel, markedAsStarted)); + } + } + } - int indexI = token.indexOf("@"); //$NON-NLS-1$ - String location = (indexI == -1) ? token : token.substring(0, indexI); - String realLocation = FileUtils.getEclipseRealLocation(manipulator, location); - String slAndFlag = (indexI > -1) ? token.substring(indexI + 1) : null; + private void writeBundlesList(File fwJar, Properties props, URI base, BundleInfo[] bundles) { + //framework jar does not get stored on the bundle list, figure out who that is. - boolean markedAsStarted = getMarkedAsStartedFormat(slAndFlag, token); - int startLevel = getStartLevel(slAndFlag, token); + StringBuffer osgiBundlesList = new StringBuffer(); + for (int j = 0; j < bundles.length; j++) { + if (fwJar != null) { + if (URIUtil.sameURI(fwJar.toURI(), bundles[j].getLocation())) + continue; + } else if (EquinoxConstants.FW_SYMBOLIC_NAME.equals(bundles[j].getSymbolicName())) + continue; - if (realLocation != null) - configData.addBundle(new BundleInfo(realLocation, startLevel, markedAsStarted)); - else - configData.addBundle(new BundleInfo(location, null, null, startLevel, markedAsStarted)); - } + URI location = fwJar != null ? URIUtil.makeRelative(bundles[j].getLocation(), fwJar.getParentFile().toURI()) : bundles[j].getLocation(); + osgiBundlesList.append(toOSGiBundleListForm(bundles[j], location)); } + props.setProperty(EquinoxConstants.PROP_BUNDLES, osgiBundlesList.toString()); } /** @@ -231,7 +149,7 @@ public class EquinoxFwConfigFileParser { * @param inputFile * @throws IOException */ - public void readFwConfig(Manipulator manipulator, File inputFile) throws IOException { + public void readFwConfig(Manipulator manipulator, File inputFile) throws IOException, URISyntaxException { if (inputFile.isDirectory()) throw new IllegalArgumentException(NLS.bind(Messages.exception_inputFileIsDirectory, inputFile)); @@ -239,63 +157,101 @@ public class EquinoxFwConfigFileParser { ConfigData configData = manipulator.getConfigData(); LauncherData launcherData = manipulator.getLauncherData(); configData.initialize(); + configData.setBundles(null); + + String launcherName = null; + String launcherPath = null; // load configuration properties Properties props = loadProperties(inputFile); - //Start figuring out stuffs - URL rootURL = launcherData.getLauncher() != null ? launcherData.getLauncher().getParentFile().toURL() : null; - - Properties sharedConfigProperties = getSharedConfiguration(props.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), getOSGiInstallArea(manipulator.getLauncherData())); + // load shared configuration properties + Properties sharedConfigProperties = getSharedConfiguration(props.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getLauncherData())); if (sharedConfigProperties != null) { sharedConfigProperties.putAll(props); props = sharedConfigProperties; } - //Extracting fwkJar location needs to be done first - String launcherName = null; - String launcherPath = null; - configData.setBundles(null); + //Start figuring out stuffs + URI rootURL = launcherData.getLauncher() != null ? launcherData.getLauncher().getParentFile().toURI() : null; + + readFwJarLocation(configData, launcherData, props); + URI configArea = inputFile.getParentFile().toURI(); + readLauncherPath(props, rootURL); + readp2DataArea(props, configArea); + readSimpleConfiguratorURL(props, configArea); + readBundlesList(manipulator, ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), launcherData).toURI(), props.getProperty(EquinoxConstants.PROP_BUNDLES)); + readInitialStartLeve(configData, props); + readDefaultStartLevel(configData, props); + // if (key.equals(EquinoxConstants.PROP_LAUNCHER_NAME)) + // if (launcherData.getLauncher() == null) + // launcherName = value; + // if (key.equals(EquinoxConstants.PROP_LAUNCHER_PATH)) + // if (launcherData.getLauncher() == null) + // launcherPath = value; + String[] KNOWN_PROPERTIES = {EquinoxConstants.PROP_BUNDLES, EquinoxConstants.PROP_INITIAL_STARTLEVEL, EquinoxConstants.PROP_BUNDLES_STARTLEVEL}; + top: for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();) { + String key = (String) enumeration.nextElement(); + for (int i = 0; i < KNOWN_PROPERTIES.length; i++) { + if (KNOWN_PROPERTIES[i].equals(key)) + continue top; + } + String value = props.getProperty(key); + configData.setProperty(key, value); + } + if (launcherName != null && launcherPath != null) { + launcherData.setLauncher(new File(launcherPath, launcherName + EquinoxConstants.EXE_EXTENSION)); + } + Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_configFile, inputFile.getAbsolutePath())); + } + + private void readDefaultStartLevel(ConfigData configData, Properties props) { + if (props.getProperty(EquinoxConstants.PROP_BUNDLES_STARTLEVEL) != null) + configData.setInitialBundleStartLevel(Integer.parseInt(props.getProperty(EquinoxConstants.PROP_BUNDLES_STARTLEVEL))); + } + + private void writeDefaultStartLevel(ConfigData configData, Properties props) { + if (configData.getInitialBundleStartLevel() != BundleInfo.NO_LEVEL) + props.setProperty(EquinoxConstants.PROP_BUNDLES_STARTLEVEL, Integer.toString(configData.getInitialBundleStartLevel())); + } + private void readInitialStartLeve(ConfigData configData, Properties props) { + if (props.getProperty(EquinoxConstants.PROP_INITIAL_STARTLEVEL) != null) + configData.setBeginningFwStartLevel(Integer.parseInt(props.getProperty(EquinoxConstants.PROP_INITIAL_STARTLEVEL))); + } + + private void writeInitialStartLevel(ConfigData configData, Properties props) { + if (configData.getBeginingFwStartLevel() != BundleInfo.NO_LEVEL) + props.setProperty(EquinoxConstants.PROP_INITIAL_STARTLEVEL, Integer.toString(configData.getBeginingFwStartLevel())); + } + + private File readFwJarLocation(ConfigData configData, LauncherData launcherData, Properties props) throws URISyntaxException { File fwJar = null; if (props.getProperty(EquinoxConstants.PROP_OSGI_FW) != null) { - props.setProperty(KEY_OSGI_FRAMEWORK, EquinoxManipulatorImpl.makeAbsolute(props.getProperty(EquinoxConstants.PROP_OSGI_FW), getOSGiInstallArea(launcherData).toURL())); - String fwJarString = props.getProperty(KEY_OSGI_FRAMEWORK); + URI absoluteFwJar = null; + absoluteFwJar = URIUtil.makeAbsolute(FileUtils.fromFileURL(props.getProperty(EquinoxConstants.PROP_OSGI_FW)), ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), launcherData).toURI()); + + props.setProperty(EquinoxConstants.PROP_OSGI_FW, absoluteFwJar.toString()); + String fwJarString = props.getProperty(EquinoxConstants.PROP_OSGI_FW); if (fwJarString != null) { - fwJar = new File(new URL(fwJarString).getFile()); + fwJar = URIUtil.toFile(absoluteFwJar); + if (fwJar == null) + throw new IllegalStateException("Can't determinate the osgi.framework location"); + //Here we overwrite the value read from eclipse.ini, because the value of osgi.framework always takes precedence. launcherData.setFwJar(fwJar); - configData.addBundle(new BundleInfo(fwJarString)); - } - } - - props = makeAbsolute(props, rootURL, fwJar, inputFile.getParentFile(), getOSGiInstallArea(manipulator.getLauncherData())); - for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();) { - String key = (String) enumeration.nextElement(); - String value = props.getProperty(key); - if (key.equals(EquinoxConstants.PROP_BUNDLES_STARTLEVEL)) - configData.setInitialBundleStartLevel(Integer.parseInt(value)); - else if (key.equals(EquinoxConstants.PROP_INITIAL_STARTLEVEL)) { - configData.setBeginningFwStartLevel(Integer.parseInt(value)); - } else if (key.equals(EquinoxConstants.PROP_BUNDLES)) { - setInstallingBundles(manipulator, value); } else { - if (isFwDependent(key)) { - configData.setFwDependentProp(key, value); - } else - configData.setFwIndependentProp(key, value); - if (key.equals(EquinoxConstants.PROP_LAUNCHER_NAME)) - if (launcherData.getLauncher() == null) - launcherName = value; - if (key.equals(EquinoxConstants.PROP_LAUNCHER_PATH)) - if (launcherData.getLauncher() == null) - launcherPath = value; + throw new IllegalStateException("Can't determinate the osgi.framework location"); } } - if (launcherName != null && launcherPath != null) { - launcherData.setLauncher(new File(launcherPath, launcherName + EquinoxConstants.EXE_EXTENSION)); - } + if (launcherData.getFwJar() != null) + configData.addBundle(new BundleInfo(launcherData.getFwJar().toURI())); + return launcherData.getFwJar(); + } - Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_configFile, inputFile.getAbsolutePath())); + private void writeFwJarLocation(ConfigData configData, LauncherData launcherData, Properties props) { + if (launcherData.getFwJar() == null) + return; + props.setProperty(EquinoxConstants.PROP_OSGI_FW, FileUtils.toFileURL(URIUtil.makeRelative(launcherData.getFwJar().toURI(), ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), launcherData).toURI()))); } private static Properties loadProperties(File inputFile) throws FileNotFoundException, IOException { @@ -354,102 +310,71 @@ public class EquinoxFwConfigFileParser { return sharedConfigIni; } - private static Properties makeRelative(Properties props, URL rootURL, File fwJar, File configArea, File osgiInstallArea) throws IOException { - for (int i = 0; i < PATHS.length; i++) { - String path = props.getProperty(PATHS[i]); - if (path != null) - props.put(PATHS[i], EquinoxManipulatorImpl.makeRelative(path, rootURL.getFile())); - } - - if (props.getProperty(KEY_OSGI_FRAMEWORK) != null && osgiInstallArea != null) { - props.put(KEY_OSGI_FRAMEWORK, EquinoxManipulatorImpl.makeRelative(props.getProperty(KEY_OSGI_FRAMEWORK), osgiInstallArea.toURL())); - } - - if (props.getProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL) != null) { - props.put(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeRelative(props.getProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL), configArea.toURL())); - } - + private void readp2DataArea(Properties props, URI configArea) throws URISyntaxException { if (props.getProperty(KEY_ECLIPSE_PROV_DATA_AREA) != null) { String url = props.getProperty(KEY_ECLIPSE_PROV_DATA_AREA); if (url != null) { - String result = EquinoxManipulatorImpl.makeRelative(url, configArea.toURL()); - //We only relativize up to the level where the p2 and config folder are siblings (e.g. foo/p2 and foo/config) - if (result.startsWith("file:../..")) //$NON-NLS-1$ - result = url; - else if (!result.equals(url) && result.startsWith("file:")) //$NON-NLS-1$ - result = CONFIG_DIR + result.substring(5); - props.put(KEY_ECLIPSE_PROV_DATA_AREA, result); + if (url.startsWith(CONFIG_DIR)) + url = "file:" + url.substring(CONFIG_DIR.length()); //$NON-NLS-1$ + props.setProperty(KEY_ECLIPSE_PROV_DATA_AREA, URIUtil.makeAbsolute(FileUtils.fromFileURL(url), configArea).toString()); } } - - String value = props.getProperty(KEY_OSGI_BUNDLES); - if (value != null && fwJar != null) { - File parent = fwJar.getParentFile(); - if (parent != null) - props.setProperty(KEY_OSGI_BUNDLES, EquinoxManipulatorImpl.makeArrayRelative(value, parent.toURL())); - } - return props; } - private static Properties makeAbsolute(Properties props, URL rootURL, File fwJar, File configArea, File osgiInstallArea) throws IOException { - for (int i = 0; i < PATHS.length; i++) { - String path = props.getProperty(PATHS[i]); - if (path != null) - props.setProperty(PATHS[i], EquinoxManipulatorImpl.makeAbsolute(path, rootURL.getFile())); + private void writep2DataArea(ConfigData configData, Properties props, URI configArea) throws URISyntaxException { + String dataArea = getFwProperty(configData, KEY_ECLIPSE_PROV_DATA_AREA); + if (dataArea != null) { + if (dataArea.startsWith(CONFIG_DIR)) { + props.setProperty(KEY_ECLIPSE_PROV_DATA_AREA, dataArea); + return; + } + URI relative = URIUtil.makeRelative(URIUtil.fromString(dataArea), configArea); + String result = URIUtil.toUnencodedString(relative); + //We only relativize up to the level where the p2 and config folder are siblings (e.g. foo/p2 and foo/config) + if (result.startsWith("../..")) //$NON-NLS-1$ + result = dataArea; + else if (!result.equals(dataArea)) { + props.setProperty(KEY_ECLIPSE_PROV_DATA_AREA, CONFIG_DIR + result); + return; + } + props.setProperty(KEY_ECLIPSE_PROV_DATA_AREA, FileUtils.toFileURL(URIUtil.fromString(result))); } + } - if (props.getProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL) != null) { - props.put(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeAbsolute(props.getProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL), configArea.toURL())); - } + private void readLauncherPath(Properties props, URI root) throws URISyntaxException { + if (props.getProperty(EquinoxConstants.PROP_LAUNCHER_PATH) != null) + props.setProperty(EquinoxConstants.PROP_LAUNCHER_PATH, URIUtil.makeAbsolute(URIUtil.fromString(props.getProperty(EquinoxConstants.PROP_LAUNCHER_PATH)), root).toString()); + } - if (props.getProperty(KEY_ECLIPSE_PROV_DATA_AREA) != null) { - String url = props.getProperty(KEY_ECLIPSE_PROV_DATA_AREA); - if (url != null) { - if (url.startsWith(CONFIG_DIR)) - url = "file:" + url.substring(CONFIG_DIR.length()); //$NON-NLS-1$ - props.put(KEY_ECLIPSE_PROV_DATA_AREA, EquinoxManipulatorImpl.makeAbsolute(url, configArea.toURL())); - } - } + private void writeLauncherPath(ConfigData configData, Properties props, URI root) throws URISyntaxException { + String value = getFwProperty(configData, EquinoxConstants.PROP_LAUNCHER_PATH); + if (value != null) + props.setProperty(EquinoxConstants.PROP_LAUNCHER_PATH, URIUtil.toUnencodedString(URIUtil.makeRelative(URIUtil.fromString(value), root))); + } - String value = props.getProperty(KEY_OSGI_BUNDLES); - if (value != null && fwJar != null) { - File parent = fwJar.getParentFile(); - if (parent != null) - props.setProperty(KEY_OSGI_BUNDLES, EquinoxManipulatorImpl.makeArrayAbsolute(value, parent.toURL())); - } - return props; + private void readSimpleConfiguratorURL(Properties props, URI configArea) throws URISyntaxException { + if (props.getProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL) != null) + props.setProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, URIUtil.makeAbsolute(FileUtils.fromFileURL(props.getProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL)), configArea).toString()); } - public static File getOSGiInstallArea(LauncherData launcherData) { - if (launcherData == null) - return null; - String[] args = launcherData.getProgramArgs(); - if (args == null) - return null; - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-startup") && i + 1 < args.length && args[i + 1].charAt(1) != '-') { //$NON-NLS-1$ - return fromOSGiJarToOSGiInstallArea(args[i + 1]); - } - } - if (launcherData.getFwJar() != null) - return fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath()); - if (launcherData.getLauncher() != null) - return launcherData.getLauncher().getParentFile(); - return null; + private void writeSimpleConfiguratorURL(ConfigData configData, Properties props, URI configArea) throws URISyntaxException { + //FIXME How would someone set such a value..... + String value = getFwProperty(configData, KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL); + if (value != null) + props.setProperty(KEY_ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, FileUtils.toFileURL(URIUtil.makeRelative(URIUtil.fromString(value), configArea))); } - private static File fromOSGiJarToOSGiInstallArea(String path) { - IPath parentFolder = new Path(path).removeLastSegments(1); - if (parentFolder.lastSegment().equals("plugins")) //$NON-NLS-1$ - return parentFolder.removeLastSegments(1).toFile(); - return parentFolder.toFile(); + private String getFwProperty(ConfigData data, String key) { + return data.getProperty(key); } public void saveFwConfig(BundleInfo[] bInfos, Manipulator manipulator, boolean backup, boolean relative) throws IOException {//{ ConfigData configData = manipulator.getConfigData(); LauncherData launcherData = manipulator.getLauncherData(); - File fwJar = EquinoxBundlesState.getFwJar(launcherData, configData); + //Get the OSGi jar from the bundle.info + File fwJar = EquinoxBundlesState.getSystemBundleFromBundleInfos(configData); launcherData.setFwJar(fwJar); + File outputFile = launcherData.getFwConfigLocation(); if (outputFile.exists()) { if (outputFile.isFile()) { @@ -467,7 +392,27 @@ public class EquinoxFwConfigFileParser { } String header = "This configuration file was written by: " + this.getClass().getName(); //$NON-NLS-1$ - Properties configProps = getConfigProps(bInfos, configData, launcherData, relative, fwJar); + Properties configProps = new Properties(); + writeFwJarLocation(configData, launcherData, configProps); + try { + writeLauncherPath(configData, configProps, null); + URI configArea = manipulator.getLauncherData().getFwConfigLocation().toURI(); + writep2DataArea(configData, configProps, configArea); + writeSimpleConfiguratorURL(configData, configProps, configArea); + writeBundlesList(launcherData.getFwJar(), configProps, ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), launcherData).toURI(), bInfos); + writeInitialStartLevel(configData, configProps); + writeDefaultStartLevel(configData, configProps); + } catch (URISyntaxException e) { + throw new FrameworkAdminRuntimeException(e, "saving config.ini"); + } + + Properties original = configData.getProperties(); + original.putAll(configProps); + configProps = original; + + //Deal with the fw jar and ensure it is not set. + //TODO This can't be done before because of the previous calls to appendProperties + if (configProps == null || configProps.size() == 0) { Log.log(LogService.LOG_WARNING, this, "saveFwConfig() ", Messages.log_configProps); //$NON-NLS-1$ return; @@ -488,7 +433,7 @@ public class EquinoxFwConfigFileParser { FileOutputStream out = null; try { out = new FileOutputStream(outputFile); - configProps = makeRelative(configProps, launcherData.getLauncher().getParentFile().toURL(), fwJar, outputFile.getParentFile(), getOSGiInstallArea(manipulator.getLauncherData())); + // configProps = makeRelative(configProps, launcherData.getLauncher().getParentFile().toURI(), fwJar, outputFile.getParentFile(), getOSGiInstallArea(manipulator.getLauncherData())); filterPropertiesFromSharedArea(configProps, launcherData); configProps.store(out, header); Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_fwConfigSave, outputFile)); @@ -505,7 +450,7 @@ public class EquinoxFwConfigFileParser { private void filterPropertiesFromSharedArea(Properties configProps, LauncherData launcherData) { //Remove from the config file that we are about to write the properties that are unchanged compared to what is in the base - Properties sharedConfigProperties = getSharedConfiguration(configProps.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), getOSGiInstallArea(launcherData)); + Properties sharedConfigProperties = getSharedConfiguration(configProps.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), launcherData)); if (sharedConfigProperties == null) return; Enumeration keys = configProps.propertyNames(); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java index 06836757f..ce5036ba9 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java @@ -12,10 +12,9 @@ package org.eclipse.equinox.internal.frameworkadmin.equinox; import java.io.File; import java.io.IOException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; import org.eclipse.equinox.internal.frameworkadmin.utils.SimpleBundlesState; import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator; @@ -81,20 +80,20 @@ public class EquinoxManipulatorImpl implements Manipulator { } } + //This returns the location of the <eclipse>.ini file static File getLauncherConfigLocation(LauncherData launcherData) { - File launcherConfigLocation = launcherData.getLauncherConfigLocation(); - if (launcherConfigLocation != null) - return launcherConfigLocation; + File launcherIni = launcherData.getLauncherConfigLocation(); + if (launcherIni != null) + return launcherIni; File launcher = launcherData.getLauncher(); if (launcher == null) return null; String launcherName = launcher.getName(); - int dotLocation = launcherName.lastIndexOf("."); + int dotLocation = launcherName.lastIndexOf('.'); if (dotLocation != -1) launcherName = launcherName.substring(0, dotLocation); - File result = new File(launcher.getParent() + File.separator + launcherName + EquinoxConstants.INI_EXTENSION); - // launcherData.setLauncherConfigLocation(result); + File result = new File(launcher.getParentFile(), launcherName + EquinoxConstants.INI_EXTENSION); return result; } @@ -282,7 +281,6 @@ public class EquinoxManipulatorImpl implements Manipulator { // TODO Auto-generated catch block e1.printStackTrace(); } - // 2. Create a Manipulator object fully initialized to the current running fw. ServiceReference reference = context.getServiceReference(StartLevel.class.getName()); @@ -293,9 +291,9 @@ public class EquinoxManipulatorImpl implements Manipulator { // System.out.println("bundles[" + i + "]=" + bundles[i]); try { if (bundles[i].getBundleId() == 0) // SystemBundle - bInfos[i] = new BundleInfo(bundles[i].getSymbolicName(), (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION), FileLocator.getBundleFile(bundles[i]).getAbsolutePath(), -1, true); + bInfos[i] = new BundleInfo(bundles[i].getSymbolicName(), (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION), FileLocator.getBundleFile(bundles[i]).getAbsoluteFile().toURI(), -1, true); else { - bInfos[i] = new BundleInfo(bundles[i].getSymbolicName(), (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION), FileLocator.getBundleFile(bundles[i]).getAbsolutePath(), startLevel.getBundleStartLevel(bundles[i]), startLevel.isBundlePersistentlyStarted(bundles[i])); + bInfos[i] = new BundleInfo(bundles[i].getSymbolicName(), (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION), FileLocator.getBundleFile(bundles[i]).getAbsoluteFile().toURI(), startLevel.getBundleStartLevel(bundles[i]), startLevel.isBundlePersistentlyStarted(bundles[i])); } } catch (IOException e) { e.printStackTrace(); @@ -311,10 +309,7 @@ public class EquinoxManipulatorImpl implements Manipulator { String value = props.getProperty(key); if (toBeEliminated(key)) continue; - if (EquinoxFwConfigFileParser.isFwDependent(key)) - configData.setFwDependentProp(key, value); - else - configData.setFwIndependentProp(key, value); + configData.setProperty(key, value); } // update initialBundleStartLevel @@ -336,10 +331,8 @@ public class EquinoxManipulatorImpl implements Manipulator { BundlesState bundlesState = null; if (EquinoxBundlesState.checkFullySupported()) { - // bundlesState = new EquinoxBundlesState(context, fwAdmin, this, true, runtime); bundlesState = new EquinoxBundlesState(context, fwAdmin, this, !launcherData.isClean()); platformProperties = ((EquinoxBundlesState) bundlesState).getPlatformProperties(); - } else { bundlesState = new SimpleBundlesState(fwAdmin, this, EquinoxConstants.FW_SYMBOLIC_NAME); platformProperties.clear(); @@ -361,15 +354,18 @@ public class EquinoxManipulatorImpl implements Manipulator { // use launcher. -- > load from LaucnherConfig file. // the parameters in memory will be updated. EclipseLauncherParser parser = new EclipseLauncherParser(); - parser.read(launcherData); + parser.read(launcherConfigFile, launcherData); } checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData); File fwConfigFile = new File(launcherData.getFwConfigLocation(), EquinoxConstants.CONFIG_INI); EquinoxFwConfigFileParser parser = new EquinoxFwConfigFileParser(context); if (fwConfigFile.exists()) - parser.readFwConfig(this, fwConfigFile); - + try { + parser.readFwConfig(this, fwConfigFile); + } catch (URISyntaxException e) { + throw new FrameworkAdminRuntimeException(e, "loading"); + } } // Save all parameter in memory into proper config files. @@ -382,28 +378,6 @@ public class EquinoxManipulatorImpl implements Manipulator { } catch (IllegalStateException e) { // ignore. } - // File fwJar = EquinoxBundlesState.getFwJar(launcherData, configData); - // if (fwJar != null) - // launcherData.setFwJar(fwJar); - - //if (context != null) - ConfiguratorManipulator previousConfigurator = setConfiguratorManipulator(); - if (previousConfigurator != null) - previousConfigurator.cleanup(this); - - BundleInfo[] newBInfos = null; - if (configuratorManipulator != null) { // Optimize BundleInfo[] - try { - newBInfos = configuratorManipulator.save(this, backup); - } catch (IllegalStateException e) { - // TODO Auto-generated catch block - if (LOG_ILLEGALSTATEEXCEPTION) - Log.log(LogService.LOG_WARNING, this, "save()", e); - newBInfos = configData.getBundles(); - } - } else { - newBInfos = configData.getBundles(); - } boolean stateIsEmpty = configData.getBundles().length == 0; @@ -412,7 +386,7 @@ public class EquinoxManipulatorImpl implements Manipulator { if (!stateIsEmpty) { // Use launcher. -- > save LauncherConfig file. EclipseLauncherParser launcherParser = new EclipseLauncherParser(); - launcherParser.save(launcherData, true, backup); + launcherParser.save(launcherData, backup); } else { // No bundles in configuration, so delete the launcher config file launcherConfigFile.delete(); @@ -421,22 +395,22 @@ public class EquinoxManipulatorImpl implements Manipulator { checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData); - // //if (context != null) - // setConfiguratorManipulator(); - // - // BundleInfo[] newBInfos = null; - // if (configuratorManipulator != null) { // Optimize BundleInfo[] - // try { - // newBInfos = configuratorManipulator.save(this, backup); - // } catch (IllegalStateException e) { - // // TODO Auto-generated catch block - // if (LOG_ILLEGALSTATEEXCEPTION) - // Log.log(LogService.LOG_WARNING, this, "save()", e); - // newBInfos = configData.getBundles(); - // } - // } else { - // newBInfos = configData.getBundles(); - // } + ConfiguratorManipulator previousConfigurator = setConfiguratorManipulator(); + if (previousConfigurator != null) + previousConfigurator.cleanup(this); + + BundleInfo[] newBInfos = null; + if (configuratorManipulator != null) { // Optimize BundleInfo[] + try { + newBInfos = configuratorManipulator.save(this, backup); + } catch (IllegalStateException e) { + if (LOG_ILLEGALSTATEEXCEPTION) + Log.log(LogService.LOG_WARNING, this, "save()", e); //$NON-NLS-1$ + newBInfos = configData.getBundles(); + } + } else { + newBInfos = configData.getBundles(); + } if (!stateIsEmpty) { // Save FwConfigFile @@ -461,13 +435,13 @@ public class EquinoxManipulatorImpl implements Manipulator { BundleInfo[] bInfos = configData.getBundles(); for (int i = 0; i < bInfos.length; i++) this.configData.addBundle(bInfos[i]); - this.configData.setFwIndependentProps(configData.getFwIndependentProps()); + this.configData.setProperties(configData.getProperties()); if (this.configData.getFwName().equals(configData.getFwName())) if (this.configData.getFwVersion().equals(configData.getFwVersion())) { // TODO refine the algorithm to copying fw dependent props. // configData.getFwName()/getFwVersion()/ // getLauncherName()/getLauncherVersion() might be taken into consideration. - this.configData.setFwDependentProps(configData.getFwDependentProps()); + this.configData.setProperties(configData.getProperties()); } } @@ -500,8 +474,7 @@ public class EquinoxManipulatorImpl implements Manipulator { ConfiguratorManipulator previousConfiguratorManipulator = configuratorManipulator; configuratorManipulator = null; for (int i = 0; i < bInfos.length; i++) { - String location = bInfos[i].getLocation(); - location = FileUtils.getRealLocation(this, location, true); + URI location = bInfos[i].getLocation(); if (!bInfos[i].isMarkedAsStarted()) continue; for (int j = 0; j < references.length; j++) diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java new file mode 100644 index 000000000..a57f40c83 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.frameworkadmin.equinox; + +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; +import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; +import org.osgi.service.log.LogService; + +public class ParserUtils { + public static File getOSGiInstallArea(List programArgs, LauncherData launcherData) { + if (launcherData == null) + return null; + + //TODO This is not enough because if you only have -startup then osgi.install.area from the config.ini is used + File result = getOSGiInstallArea(programArgs, launcherData.getLauncher().getParentFile().toURI()); + if (result != null) + return result; + + if (launcherData.getFwJar() != null) + return fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath()); + if (launcherData.getLauncher() != null) + return launcherData.getLauncher().getParentFile(); + return null; + } + + public static URI getFrameworkJar(List lines, URI launcherFolder) { + String fwk = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_FW, lines); + if (fwk == null) { + //Search the file system using the default location + URI location = FileUtils.getEclipsePluginFullLocation(EquinoxConstants.FW_SYMBOLIC_NAME, new File(URIUtil.toFile(launcherFolder), EquinoxConstants.PLUGINS_DIR)); + if (location != null) + return location; + return null; + } + try { + return URIUtil.makeAbsolute(URIUtil.fromString(fwk), launcherFolder); + } catch (URISyntaxException e) { + Log.log(LogService.LOG_ERROR, "can't make absolute of:" + fwk); + return null; + } + } + + //This method should only be used to determine the osgi install area when reading the eclipse.ini + public static File getOSGiInstallArea(List args, URI base) { + if (args == null) + return null; + String install = getValueForArgument(EquinoxConstants.OPTION_INSTALL, args); + if (install != null) + return new File(install); + String startup = getValueForArgument(EquinoxConstants.OPTION_STARTUP, args); + if (startup != null) { + return URIUtil.toFile(URIUtil.makeAbsolute(fromOSGiJarToOSGiInstallArea(startup).toURI(), base)); + } + return null; + } + + private static File fromOSGiJarToOSGiInstallArea(String path) { + IPath parentFolder = new Path(path).removeLastSegments(1); + if (parentFolder.lastSegment().equalsIgnoreCase("plugins")) //$NON-NLS-1$ + return parentFolder.removeLastSegments(1).toFile(); + return parentFolder.toFile(); + } + + public static boolean isArgumentSet(String arg, List args) { + if (arg == null || args == null) + return false; + for (int i = 0; i < args.size(); i++) { + if (args.get(i) == null) + continue; + if (((String) args.get(i)).equalsIgnoreCase(arg)) { + return true; + } + } + return false; + } + + public static String getValueForArgument(String arg, List args) { + if (arg == null || args == null) + return null; + for (int i = 0; i < args.size(); i++) { + if (args.get(i) == null) + continue; + if (((String) args.get(i)).equalsIgnoreCase(arg)) { + if (i + 1 < args.size() && args.get(i + 1) != null && ((String) args.get(i + 1)).charAt(1) != '-') + return (String) args.get(i + 1); + } + } + return null; + } + + public static String[] getMultiValuedArgument(String arg, List args) { + if (arg == null || args == null) + return null; + ArrayList values = null; + for (int i = 0; i < args.size(); i++) { + if (args.get(i) == null) + continue; + if (arg.equalsIgnoreCase((String) args.get(i))) { + values = new ArrayList(); + continue; + } + if (values != null && ((String) args.get(i)).charAt(1) == '-') { + break; + } + if (values != null) + values.add(((String) args.get(i)).trim()); + } + if (values != null) + return (String[]) values.toArray(new String[values.size()]); + return null; + } + + public static boolean setValueForArgument(String arg, String value, List args) { + if (arg == null || args == null) + return false; + for (int i = 0; i < args.size(); i++) { + if (args.get(i) == null) + continue; + String currentArg = ((String) args.get(i)).trim(); + if (currentArg.equalsIgnoreCase(arg)) { + if (i + 1 < args.size() && args.get(i + 1) != null && ((String) args.get(i + 1)).charAt(1) != '-') { + args.set(i + 1, value); + return true; + } + break; + } + } + args.add(arg); + args.add(value); + return true; + } + + public static boolean removeArgument(String arg, List args) { + if (arg == null || args == null) + return false; + for (int i = 0; i < args.size(); i++) { + if (args.get(i) == null) + continue; + String currentArg = ((String) args.get(i)).trim(); + if (currentArg.equalsIgnoreCase(arg)) { + args.set(i, null); + while (i + 1 < args.size() && args.get(i + 1) != null && ((String) args.get(i + 1)).charAt(1) != '-') { + args.set(i + 1, null); + i++; + } + } + } + return false; + } +} diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java index 193518dad..35a0fba0f 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java @@ -10,42 +10,36 @@ *******************************************************************************/ package org.eclipse.equinox.internal.frameworkadmin.equinox.utils; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Properties; +import java.io.*; +import java.net.*; +import java.util.*; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxConstants; +import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils; import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; import org.osgi.framework.Version; public class FileUtils { - private static String FILE_PROTOCOL = "file:"; //$NON-NLS-1$ private static String REFERENCE_PROTOCOL = "reference:"; //$NON-NLS-1$ private static String INITIAL_PREFIX = "initial@"; //$NON-NLS-1$ - /** - * locations that are URLs are returned as is. Otherwise, resolve the location against - * the given Manipulator - * - * @param manipulator - * @param location - * @return a URL string for the actual location, or null - */ // based on org.eclipse.core.runtime.adaptor.EclipseStarter#searchForBundle - public static String getEclipseRealLocation(final Manipulator manipulator, String location) { + public static URI getEclipseRealLocation(Manipulator manipulator, String location) { //if this is some form of URL just return it try { new URL(location); - return location; + return URIUtil.makeAbsolute(URIUtil.fromString(location), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getLauncherData()).toURI()); + } catch (URISyntaxException e) { + // expected } catch (MalformedURLException e) { - //expected + // expected } File base = new File(location); if (!base.isAbsolute()) { - String pluginsDir = getSyspath(manipulator); + String pluginsDir = getSysPath(manipulator); if (pluginsDir == null) return null; base = new File(pluginsDir, location); @@ -54,8 +48,9 @@ public class FileUtils { return getEclipsePluginFullLocation(base.getName(), base.getParentFile()); } - private static String getSyspath(final Manipulator manipulator) { - Properties properties = manipulator.getConfigData().getFwDependentProps(); + //This mimics the logic of EclipseStarter#getSysPath(); + private static String getSysPath(final Manipulator manipulator) { + Properties properties = manipulator.getConfigData().getProperties(); String path = (String) properties.get(EquinoxConstants.PROP_OSGI_SYSPATH); if (path != null) return path; @@ -82,7 +77,7 @@ public class FileUtils { return null; } - public static String getRealLocation(Manipulator manipulator, final String location, boolean useEclipse) { + public static String removeEquinoxSpecificProtocols(String location) { if (location == null) return null; String ret = location; @@ -90,11 +85,11 @@ public class FileUtils { ret = location.substring(REFERENCE_PROTOCOL.length()); else if (location.startsWith(INITIAL_PREFIX)) ret = location.substring(INITIAL_PREFIX.length()); + return ret; + } - if (!useEclipse) - return ret; - - return FileUtils.getEclipseRealLocation(manipulator, ret); + public static URI getRealLocation(Manipulator manipulator, final String location) { + return FileUtils.getEclipseRealLocation(manipulator, removeEquinoxSpecificProtocols(location)); } /** @@ -125,7 +120,7 @@ public class FileUtils { * @return a URL string for the found plugin, or null */ // Based on org.eclipse.core.runtime.adaptor.EclipseStarter#searchFor - public static String getEclipsePluginFullLocation(String pluginName, File bundlesDir) { + public static URI getEclipsePluginFullLocation(String pluginName, File bundlesDir) { if (bundlesDir == null) return null; File[] candidates = bundlesDir.listFiles(); @@ -159,10 +154,54 @@ public class FileUtils { result = candidates[i]; } } + return result != null ? result.getAbsoluteFile().toURI() : null; + } + + public static URI fromPath(String path) throws URISyntaxException { + File f = new File(path); + if (f.isAbsolute()) + return f.toURI(); + return URIUtil.fromString(FILE_PROTOCOL + path); + } + + public static String toPath(URI uri) { + if (!FILE_PROTOCOL.equalsIgnoreCase(uri.getScheme())) + return new File(URIUtil.toUnencodedString(uri)).getPath(); + return URIUtil.toFile(uri).getAbsolutePath(); + } + + public static String toFileURL(URI uri) { + if (uri.getScheme() != null) + return URIUtil.toUnencodedString(uri); + return FILE_PROTOCOL + URIUtil.toUnencodedString(uri); + } + + public static URI fromFileURL(String url) throws URISyntaxException { + if (url.startsWith(FILE_PROTOCOL)) { + return URIUtil.fromString(new File(url.substring(FILE_PROTOCOL.length())).isAbsolute() ? url : url.substring(FILE_PROTOCOL.length())); + } + throw new URISyntaxException(url, "Not a file url"); + } + + public static List loadFile(File file) throws IOException { + BufferedReader br = null; try { - return result != null ? result.getAbsoluteFile().toURL().toExternalForm() : null; - } catch (MalformedURLException e) { - return null; + br = new BufferedReader(new FileReader(file)); + + String line; + List list = new ArrayList(); + while ((line = br.readLine()) != null) { + list.add(line); + } + return list; + } finally { + if (br != null) + try { + br.close(); + } catch (IOException e) { + //Ignore + } } } + } diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/Framework Admin Test.launch b/bundles/org.eclipse.equinox.frameworkadmin.test/Framework Admin Test.launch index f12eebb9f..874f0ea3a 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/Framework Admin Test.launch +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/Framework Admin Test.launch @@ -6,33 +6,31 @@ <booleanAttribute key="automaticAdd" value="true"/> <booleanAttribute key="automaticValidate" value="false"/> <stringAttribute key="bootstrap" value=""/> -<stringAttribute key="checked" value="[NONE]"/> <booleanAttribute key="clearConfig" value="true"/> <booleanAttribute key="clearws" value="true"/> <booleanAttribute key="clearwslog" value="false"/> <stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> <booleanAttribute key="default" value="false"/> -<stringAttribute key="deselected_workspace_plugins" value="org.eclipse.equinox.p2.updatechecker.app,org.eclipse.equinox.p2.ui.admin,org.eclipse.equinox.p2.directorywatcher,org.eclipse.equinox.p2.artifact.optimizers,org.eclipse.equinox.p2.ui,org.eclipse.ecf,org.eclipse.equinox.p2.tests,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.repositoryoptimizer,org.eclipse.equinox.p2.director,org.eclipse.equinox.p2.director.app,ie.wombat.jbdiff,ie.wombat.jbdiff.test,org.eclipse.equinox.p2.target,org.eclipse.equinox.p2.core,org.eclipse.equinox.p2.download,org.eclipse.equinox.p2.artifact.repository,org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.ui.sdk,org.eclipse.equinox.p2.engine,org.eclipse.equinox.p2.metadata.repository,org.eclipse.equinox.p2.sar.test,org.eclipse.equinox.p2.metadata,org.eclipse.ecf.filetransfer,org.eclipse.equinox.p2.touchpoint.natives,org.eclipse.equinox.p2.sar,org.eclipse.equinox.p2.exemplarysetup,org.eclipse.equinox.p2.console,org.eclipse.equinox.simpleconfigurator.test,org.eclipse.equinox.p2.artifact.processors,org.eclipse.test.performance,zzTest,org.eclipse.equinox.p2.tools,org.eclipse.ecf.identity,org.eclipse.equinox.p2.ui.admin.rcp,org.eclipse.ecf.provider.filetransfer,org.eclipse.equinox.simpleconfigurator,org.eclipse.equinox.p2.selfhosting,org.eclipse.equinox.p2.updatechecker,org.eclipse.equinox.p2.jarprocessor"/> +<stringAttribute key="deselected_workspace_plugins" value="org.eclipse.equinox.p2.ui.admin,org.eclipse.equinox.p2.artifact.optimizers,org.eclipse.equinox.p2.ui,org.eclipse.ecf,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.core,org.eclipse.equinox.p2.artifact.repository,org.eclipse.equinox.p2.metadata.repository,org.eclipse.equinox.p2.sar,org.eclipse.ecf.identity,org.eclipse.equinox.p2.selfhosting,org.eclipse.equinox.p2.jarprocessor,org.eclipse.equinox.p2.directorywatcher,org.eclipse.equinox.p2.tests,org.eclipse.equinox.p2.director.app,org.eclipse.equinox.p2.director,ie.wombat.jbdiff,ie.wombat.jbdiff.test,org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.ui.sdk,org.eclipse.equinox.p2.engine,org.eclipse.ecf.filetransfer,org.eclipse.equinox.p2.metadata,org.eclipse.equinox.p2.touchpoint.natives,org.eclipse.equinox.p2.exemplarysetup,org.eclipse.equinox.p2.console,org.eclipse.equinox.p2.artifact.processors,org.eclipse.equinox.p2.tools,org.eclipse.equinox.p2.ui.admin.rcp,org.eclipse.ecf.provider.filetransfer,org.eclipse.equinox.p2.updatechecker"/> <booleanAttribute key="includeOptional" value="true"/> <stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/org.eclipse.equinox.frameworkadmin.test"/> +<listEntry value="/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AllTests.java"/> </listAttribute> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="4"/> +<listEntry value="1"/> </listAttribute> <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> -<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.equinox.frameworkadmin.test"/> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> <booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> -<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> -<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.equinox.frameworkadmin.tests.AllTests"/> <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.equinox.frameworkadmin.test"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> <stringAttribute key="pde.version" value="3.3"/> <stringAttribute key="product" value="org.eclipse.equinox.p2.director.app.product"/> -<stringAttribute key="selected_target_plugins" value="com.ibm.icu,javax.servlet,org.eclipse.ant.core,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.databinding,org.eclipse.core.expressions,org.eclipse.core.filesystem,org.eclipse.core.filesystem.win32.x86,org.eclipse.core.jobs,org.eclipse.core.net,org.eclipse.core.resources,org.eclipse.core.resources.compatibility,org.eclipse.core.resources.win32,org.eclipse.core.runtime,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.core.variables,org.eclipse.equinox.app,org.eclipse.equinox.common,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.jface,org.eclipse.jface.databinding,org.eclipse.jface.text,org.eclipse.osgi,org.eclipse.osgi.services,org.eclipse.swt,org.eclipse.swt.win32.win32.x86,org.eclipse.text,org.eclipse.ui,org.eclipse.ui.forms,org.eclipse.ui.ide,org.eclipse.ui.views,org.eclipse.ui.win32,org.eclipse.ui.workbench,org.eclipse.update.core.win32,org.eclipse.update.ui"/> +<stringAttribute key="selected_target_plugins" value="org.eclipse.ui.win32,org.eclipse.core.net,org.eclipse.osgi,org.eclipse.core.resources.compatibility,org.eclipse.help,org.eclipse.ui,org.eclipse.core.databinding,org.eclipse.core.jobs,org.eclipse.swt,org.eclipse.core.runtime.compatibility.auth,org.eclipse.equinox.registry,org.eclipse.core.filesystem,org.eclipse.swt.win32.win32.x86,org.eclipse.core.resources,org.eclipse.equinox.common,org.eclipse.ui.ide,org.eclipse.text,org.eclipse.ui.forms,org.eclipse.core.runtime,org.eclipse.jface,org.eclipse.equinox.app,org.eclipse.update.core.win32,org.eclipse.core.filesystem.win32.x86,org.eclipse.core.expressions,org.eclipse.core.variables,org.eclipse.equinox.preferences,org.eclipse.ant.core,org.eclipse.core.contenttype,org.eclipse.ui.workbench,org.eclipse.ui.views,org.eclipse.osgi.services,com.ibm.icu,org.eclipse.jface.text,org.eclipse.update.ui,javax.servlet,org.eclipse.jface.databinding,org.eclipse.core.commands,org.eclipse.core.runtime.compatibility.registry"/> <booleanAttribute key="show_selected_only" value="false"/> <stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/> <booleanAttribute key="tracing" value="false"/> diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest1/conf/config.ini b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest1/conf/config.ini new file mode 100644 index 000000000..c9f0304f6 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest1/conf/config.ini @@ -0,0 +1 @@ +foo=bar
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest1/eclipse.ini b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest1/eclipse.ini new file mode 100644 index 000000000..4f54e6223 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest1/eclipse.ini @@ -0,0 +1,2 @@ +-configuration +conf
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest3/configuration/config.ini b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest3/configuration/config.ini new file mode 100644 index 000000000..c9f0304f6 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest3/configuration/config.ini @@ -0,0 +1 @@ +foo=bar
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest3/eclipse.ini b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest3/eclipse.ini new file mode 100644 index 000000000..fbcc88191 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/dataFile/readerTest3/eclipse.ini @@ -0,0 +1 @@ +-foobar
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java index 212df3ff7..6253a7311 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java @@ -10,17 +10,16 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; -import org.osgi.framework.BundleException; - -import java.io.File; -import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; -import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; - import java.io.*; +import java.net.URI; import java.net.URL; +import java.util.List; +import java.util.Properties; import junit.framework.TestCase; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdmin; +import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils; +import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; +import org.eclipse.equinox.internal.provisional.frameworkadmin.*; import org.osgi.framework.*; import org.osgi.util.tracker.ServiceTracker; @@ -69,7 +68,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { } return file.delete(); } - + public FrameworkAdmin getEquinoxFrameworkAdmin() throws BundleException { final String FILTER_OBJECTCLASS = "(" + Constants.OBJECTCLASS + "=" + FrameworkAdmin.class.getName() + ")"; final String filterFwName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_FW_NAME + "=Equinox)"; @@ -144,6 +143,39 @@ public abstract class AbstractFwkAdminTest extends TestCase { fail("String: " + search + " not found in " + file.getAbsolutePath()); } } + + public void assertIniFileNotContain(File file, String argument, String value) { + List args = null; + try { + args = FileUtils.loadFile(file); + } catch (IOException e) { + fail("Can't read file " + file); + } + String tmp = ParserUtils.getValueForArgument(argument, args); + if (tmp == null) + return; + + assertTrue(tmp.indexOf(value) == -1); + } + public void assertPropertyNotContain(File file, String property, String search) { + Properties p = new Properties(); + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + p.load(fis); + } catch (FileNotFoundException e) { + fail("Can't find file " + file); + } catch (IOException e) { + fail("Error reading " + file); + } finally { + if (fis != null) + try { + fis.close(); + } catch (IOException e) { + //ignore + } + } + } public void assertContent(File file, String search) { if (!file.exists()) @@ -192,7 +224,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { fail("Exception while starting up " + SIMPLECONFIGURATOR_MANIPULATOR + ' ' + e.getMessage()); } } - + /* * Copy * - if we have a file, then copy the file @@ -242,7 +274,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { } } } - + /* * Look up and return a file handle to the given entry in the bundle. */ @@ -264,7 +296,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { // avoid compile error... should never reach this code return null; } - + protected Manipulator getFrameworkManipulator(File configuration, File launcher) throws BundleException { startSimpleConfiguratormManipulator(); FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); @@ -273,7 +305,60 @@ public abstract class AbstractFwkAdminTest extends TestCase { LauncherData launcherData = manipulator.getLauncherData(); launcherData.setFwConfigLocation(configuration); launcherData.setLauncher(launcher); - + return manipulator; } + + //This is a dumb helper writing out the values as they have been passed to it. + protected void writeEclipseIni(File location, String[] lines) { + location.getParentFile().mkdirs(); + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(location)); + for (int j = 0; j < lines.length; j++) { + bw.write(lines[j]); + bw.newLine(); + } + bw.flush(); + + } catch (IOException e) { + fail("Fail writing eclipse.ini file"); + } finally { + if (bw != null) + try { + bw.close(); + } catch (IOException e) { + fail("Fail writing eclipse.ini file in " + location); + } + } + } + + //This is a dumb helper writing out the values as they have been passed to it + protected void writeConfigIni(File location, Properties properties) { + location.getParentFile().mkdirs(); + FileOutputStream out = null; + try { + out = new FileOutputStream(location); + properties.store(out, "#header"); + } catch (IOException e) { + fail("Faile writing config.ini in" + location); + } finally { + try { + out.flush(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + out = null; + } + } + + public void assertContains(String message, BundleInfo[] bundles, URI location) { + for (int i = 0; i < bundles.length; i++) { + if (bundles[i].getLocation().equals(location)) + return; + } + fail(message + " Can't find the bundle info " + location); + } + } diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AllTests.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AllTests.java index 19d75a0d7..b94aa9332 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AllTests.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AllTests.java @@ -26,6 +26,11 @@ public class AllTests extends TestCase { suite.addTestSuite(NoConfigurationValueInEclipseIni.class); suite.addTestSuite(NoRenamingLauncherIni.class); suite.addTestSuite(OSGiVersionChange.class); + suite.addTestSuite(ReaderTest1.class); + suite.addTestSuite(ReaderTest2.class); + suite.addTestSuite(ReaderTest3.class); + suite.addTestSuite(ReaderTest4.class); + suite.addTestSuite(ReaderTest5.class); suite.addTestSuite(RelativePathTest.class); suite.addTestSuite(RemovingAllBundles.class); suite.addTestSuite(RenamingLauncherIni.class); @@ -33,7 +38,7 @@ public class AllTests extends TestCase { suite.addTestSuite(SimpleConfiguratorComingAndGoing.class); suite.addTestSuite(SimpleConfiguratorTest.class); suite.addTestSuite(TestEclipseDataArea.class); - suite.addTestSuite(TestRunningInstance.class); +// suite.addTestSuite(TestRunningInstance.class); suite.addTestSuite(ManipulatorTests.class); suite.addTestSuite(UtilsTest.class); return suite; diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/Bug196525.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/Bug196525.java index 466c15e0e..4886136b5 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/Bug196525.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/Bug196525.java @@ -12,7 +12,10 @@ package org.eclipse.equinox.frameworkadmin.tests; import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; import org.osgi.framework.BundleException; @@ -49,8 +52,8 @@ public class Bug196525 extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); @@ -58,7 +61,7 @@ public class Bug196525 extends AbstractFwkAdminTest { manipulator.save(false); } - public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { + public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -71,7 +74,13 @@ public class Bug196525 extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo bundle1Bi = new BundleInfo("bundle_1", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm(), 2, true); + try { + assertContains("1.0", manipulator.getConfigData().getBundles(), URIUtil.toURI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")))); + assertContains("2.0", manipulator.getConfigData().getBundles(), URIUtil.toURI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")))); + } catch (URISyntaxException e) { + fail("Unexpected failure while creating URI"); + } + BundleInfo bundle1Bi = new BundleInfo("bundle_1", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm()), 2, true); manipulator.getConfigData().addBundle(bundle1Bi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/CleanupTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/CleanupTest.java index beac61966..f8a32bd01 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/CleanupTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/CleanupTest.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -87,8 +91,8 @@ public class CleanupTest extends FwkAdminAndSimpleConfiguratorTest { assertNothing(new File(getInstallFolder(), getLauncherName() + ".ini")); } - public void testWithMutipleBundles() throws IOException { - BundleInfo bi = new BundleInfo(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm(), 2); + public void testWithMutipleBundles() throws IOException, URISyntaxException { + BundleInfo bi = new BundleInfo(new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm()), 2); m.getConfigData().addBundle(bi); m.save(false); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java index 95a5c538c..986d0f40f 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -52,8 +54,8 @@ public abstract class FwkAdminAndSimpleConfiguratorTest extends AbstractFwkAdmin protected Manipulator createMinimalConfiguration(String workArea) throws Exception { Manipulator manipulator = getNewManipulator(workArea); - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/LauncherConfigLocationTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/LauncherConfigLocationTest.java index 67ecf7775..703e3fa69 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/LauncherConfigLocationTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/LauncherConfigLocationTest.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -22,7 +26,7 @@ public class LauncherConfigLocationTest extends AbstractFwkAdminTest { super(name); } - public void testCustomLauncherConfig() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { + public void testCustomLauncherConfig() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { startSimpleConfiguratormManipulator(); FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -50,8 +54,8 @@ public class LauncherConfigLocationTest extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java index 15991ea56..e6971dcef 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java @@ -11,6 +11,8 @@ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URI; + import java.io.*; import java.util.Properties; import org.eclipse.core.runtime.FileLocator; @@ -28,8 +30,8 @@ public class ManipulatorTests extends AbstractFwkAdminTest { File configurationFolder = new File( installFolder, "configuration"); Manipulator manipulator = getFrameworkManipulator(configurationFolder, new File(installFolder, "foo")); - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoConfigurationValueInEclipseIni.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoConfigurationValueInEclipseIni.java index 98f53c472..e40df043f 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoConfigurationValueInEclipseIni.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoConfigurationValueInEclipseIni.java @@ -8,6 +8,10 @@ ******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -26,7 +30,7 @@ public class NoConfigurationValueInEclipseIni extends FwkAdminAndSimpleConfigura assertNotContent(launcherIni, "-configuration"); } - public void testPresenceOfConfigurationInEclipseINI() throws FrameworkAdminRuntimeException, IOException, BundleException { + public void testPresenceOfConfigurationInEclipseINI() throws FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -38,8 +42,8 @@ public class NoConfigurationValueInEclipseIni extends FwkAdminAndSimpleConfigura launcherData.setFwConfigLocation(configurationFolder); launcherData.setLauncher(new File(installFolder, launcherName)); - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoRenamingLauncherIni.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoRenamingLauncherIni.java index 1b4025623..7a36301fe 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoRenamingLauncherIni.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/NoRenamingLauncherIni.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -22,7 +26,7 @@ public class NoRenamingLauncherIni extends AbstractFwkAdminTest { super(name); } - public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { + public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { startSimpleConfiguratormManipulator(); FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -40,8 +44,8 @@ public class NoRenamingLauncherIni extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/OSGiVersionChange.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/OSGiVersionChange.java index 08201ba11..4b16a17c1 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/OSGiVersionChange.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/OSGiVersionChange.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.IOException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; @@ -37,10 +41,10 @@ public class OSGiVersionChange extends FwkAdminAndSimpleConfiguratorTest { break; } } - defaultManipulator.getConfigData().removeBundle(osgi); + assertEquals(true, defaultManipulator.getConfigData().removeBundle(osgi)); defaultManipulator.save(false); assertNotContent(getBundleTxt(), "org.eclipse.osgi"); - assertNotContent(getConfigIni(), "org.eclipse.osgi"); + assertPropertyNotContain(getConfigIni(),"osgi.bundles", "org.eclipse.osgi"); } public void testRemovalUsingOtherManipulator() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { @@ -56,7 +60,7 @@ public class OSGiVersionChange extends FwkAdminAndSimpleConfiguratorTest { newManipulator.getConfigData().removeBundle(osgi); newManipulator.save(false); assertNotContent(getBundleTxt(), "org.eclipse.osgi"); - assertNotContent(getConfigIni(), "org.eclipse.osgi"); + assertPropertyNotContain(getConfigIni(),"osgi.bundles", "org.eclipse.osgi"); } public void testAdditionUsingOtherManipulator() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { @@ -68,7 +72,7 @@ public class OSGiVersionChange extends FwkAdminAndSimpleConfiguratorTest { break; } } - defaultManipulator.getConfigData().removeBundle(osgi); + assertEquals(true, defaultManipulator.getConfigData().removeBundle(osgi)); defaultManipulator.save(false); Manipulator newManipulator = getNewManipulator(workArea); @@ -76,10 +80,10 @@ public class OSGiVersionChange extends FwkAdminAndSimpleConfiguratorTest { newManipulator.getConfigData().addBundle(osgi); newManipulator.save(false); assertContent(getBundleTxt(), "org.eclipse.osgi"); - assertContent(getConfigIni(), "org.eclipse.osgi"); + assertPropertyNotContain(getConfigIni(),"osgi.bundles", "org.eclipse.osgi"); } - public void testChangeVersion() throws IllegalStateException, FrameworkAdminRuntimeException, IOException { + public void testChangeVersion() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, URISyntaxException { BundleInfo[] infos = defaultManipulator.getConfigData().getBundles(); BundleInfo osgi = null; for (int i = 0; i < infos.length; i++) { @@ -94,7 +98,7 @@ public class OSGiVersionChange extends FwkAdminAndSimpleConfiguratorTest { //These two constants describe the data file used in the test final String FILENAME = "org.eclipse.osgi_3.4.0.jar"; final String VERSION = "3.4.0.v20071105"; - BundleInfo newOSGi = new BundleInfo("org.eclipse.osgi", "3.4.0.v20071105", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/" + FILENAME)).toExternalForm(), 0, true); + BundleInfo newOSGi = new BundleInfo("org.eclipse.osgi", "3.4.0.v20071105", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/" + FILENAME)).toExternalForm()), 0, true); defaultManipulator.getConfigData().addBundle(newOSGi); defaultManipulator.save(false); assertContent(getBundleTxt(), VERSION); @@ -114,9 +118,9 @@ public class OSGiVersionChange extends FwkAdminAndSimpleConfiguratorTest { defaultManipulator.getConfigData().removeBundle(osgi); defaultManipulator.save(false); assertNotContent(getBundleTxt(), "org.eclipse.osgi"); - assertNotContent(getConfigIni(), "org.eclipse.osgi"); + assertPropertyNotContain(getConfigIni(),"osgi.bundles", "org.eclipse.osgi"); Manipulator newManipulator = getNewManipulator(workArea); - assertEquals(newManipulator.getConfigData().getBundles().length, 1); + assertEquals(1, newManipulator.getConfigData().getBundles().length); } } diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest1.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest1.java new file mode 100644 index 000000000..e5e279992 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest1.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.frameworkadmin.tests; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.osgi.framework.BundleException; + +public class ReaderTest1 extends AbstractFwkAdminTest { + private File installFolder = null; + private String launcherName = "eclipse"; + + public ReaderTest1(String name) { + super(name); + } + + + public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { + startSimpleConfiguratormManipulator(); + + FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); + Manipulator manipulator = fwkAdmin.getManipulator(); + + installFolder = getTestData(ReaderTest1.class.getName(),"dataFile/readerTest1"); + + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setLauncher(new File(installFolder, launcherName)); + try { + manipulator.load(); + } catch (IllegalStateException e) { + //TODO We ignore the framework JAR location not set exception + } + assertEquals(new File(installFolder, "conf"), manipulator.getLauncherData().getFwConfigLocation()); + assertEquals("bar", manipulator.getConfigData().getProperty("foo")); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest2.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest2.java new file mode 100644 index 000000000..b671a6a64 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest2.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.frameworkadmin.tests; + +import java.util.Properties; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.osgi.framework.BundleException; + +public class ReaderTest2 extends AbstractFwkAdminTest { + private File installFolder = null; + private File configurationFolder = null; + private String launcherName = "eclipse"; + + public ReaderTest2(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + startSimpleConfiguratormManipulator(); + + installFolder = Activator.getContext().getDataFile(ReaderTest2.class.getName()); + configurationFolder = new File(installFolder, "conf"); + writeEclipseIni(new File(installFolder, "eclipse.ini"), new String[] { "-configuration", configurationFolder.getAbsolutePath() }); + Properties properties = new Properties(); + properties.setProperty("foo", "bar"); + writeConfigIni(new File(configurationFolder, "config.ini"), properties); + } + + public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { + FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); + Manipulator manipulator = fwkAdmin.getManipulator(); + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setLauncher(new File(installFolder, launcherName)); + try { + manipulator.load(); + } catch (IllegalStateException e) { + //TODO We ignore the framework JAR location not set exception + } + + assertEquals(new File(installFolder, "conf"), manipulator.getLauncherData().getFwConfigLocation()); + assertEquals("bar", manipulator.getConfigData().getProperty("foo")); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest3.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest3.java new file mode 100644 index 000000000..772f2cd95 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest3.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.frameworkadmin.tests; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.osgi.framework.BundleException; + +public class ReaderTest3 extends AbstractFwkAdminTest { + private File installFolder = null; + private String launcherName = "eclipse"; + + public ReaderTest3(String name) { + super(name); + } + + + public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { + startSimpleConfiguratormManipulator(); + + FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); + Manipulator manipulator = fwkAdmin.getManipulator(); + + installFolder = getTestData(ReaderTest3.class.getName(),"dataFile/readerTest3"); + + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setLauncher(new File(installFolder, launcherName)); + try { + manipulator.load(); + } catch (IllegalStateException e) { + //TODO We ignore the framework JAR location not set exception + } + assertEquals(new File(installFolder, "configuration"), manipulator.getLauncherData().getFwConfigLocation()); + assertEquals("bar", manipulator.getConfigData().getProperty("foo")); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest4.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest4.java new file mode 100644 index 000000000..e237a5266 --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest4.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.frameworkadmin.tests; + +import org.eclipse.core.runtime.URIUtil; + +import java.util.Properties; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.osgi.framework.BundleException; + +public class ReaderTest4 extends AbstractFwkAdminTest { + private File installFolder = null; + private File configurationFolder = null; + private String launcherName = "eclipse"; + + public ReaderTest4(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + startSimpleConfiguratormManipulator(); + + installFolder = Activator.getContext().getDataFile(ReaderTest4.class.getName()); + configurationFolder = new File(installFolder, "conf"); + writeEclipseIni(new File(installFolder, "eclipse.ini"), new String[] { "-install", installFolder.getAbsolutePath(), "-configuration", URIUtil.toUnencodedString(URIUtil.makeRelative(configurationFolder.toURI(), installFolder.toURI())) }); + Properties properties = new Properties(); + properties.setProperty("foo", "bar"); + writeConfigIni(new File(configurationFolder, "config.ini"), properties); + } + + public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { + FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); + Manipulator manipulator = fwkAdmin.getManipulator(); + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setLauncher(new File(installFolder, launcherName)); + try { + manipulator.load(); + } catch (IllegalStateException e) { + //TODO We ignore the framework JAR location not set exception + } + + assertEquals(new File(installFolder, "conf"), manipulator.getLauncherData().getFwConfigLocation()); + assertEquals("bar", manipulator.getConfigData().getProperty("foo")); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest5.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest5.java new file mode 100644 index 000000000..bb834bf7d --- /dev/null +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ReaderTest5.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.frameworkadmin.tests; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Properties; +import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.osgi.framework.BundleException; + +public class ReaderTest5 extends AbstractFwkAdminTest { + private File installFolder = null; + private File configurationFolder = null; + private String launcherName = "eclipse"; + + public ReaderTest5(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + startSimpleConfiguratormManipulator(); + + installFolder = Activator.getContext().getDataFile(ReaderTest5.class.getName()); + configurationFolder = new File(installFolder, "configuration"); + writeEclipseIni(new File(installFolder, "eclipse.ini"), new String[] { "-install", installFolder.getAbsolutePath()}); + Properties properties = new Properties(); + properties.setProperty("foo", "bar"); + writeConfigIni(new File(configurationFolder, "config.ini"), properties); + } + + public void testConfigContent() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { + FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); + Manipulator manipulator = fwkAdmin.getManipulator(); + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setLauncher(new File(installFolder, launcherName)); + try { + manipulator.load(); + } catch (IllegalStateException e) { + //TODO We ignore the framework JAR location not set exception + } + + assertEquals(configurationFolder, manipulator.getLauncherData().getFwConfigLocation()); + assertEquals("bar", manipulator.getConfigData(). getProperty("foo")); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RelativePathTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RelativePathTest.java index 46b1d3542..38d26b651 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RelativePathTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RelativePathTest.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URI; + import java.io.*; import org.eclipse.core.runtime.FileLocator; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; @@ -19,16 +21,6 @@ public class RelativePathTest extends FwkAdminAndSimpleConfiguratorTest { super(name); } - /** - * Adjusts slashes in a given path string to match current platform. Note that - * because '\' is a valid path character on Linux, we cannot safely convert '\' to '/'. - * Thus all tests should be written using '/' as the path separator, and use this - * method to adjust the paths for platforms where '\' is the path separator (win32). - */ - private String adjustSlashes(String path) { - return File.separatorChar == '\\' ? path.replace('/', '\\') : path; - } - public void testRelativePaths() throws Exception { File installFolder = Activator.getContext().getDataFile(RelativePathTest.class.getName()); @@ -55,8 +47,8 @@ public class RelativePathTest extends FwkAdminAndSimpleConfiguratorTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", osgiJar.toURL().toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", scJar.toURL().toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", osgiJar.toURI(), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", scJar.toURI(), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); try { @@ -71,10 +63,10 @@ public class RelativePathTest extends FwkAdminAndSimpleConfiguratorTest { assertNotContent(new File(configurationFolder, "config.ini"), installFolder.getAbsolutePath()); assertNotContent(new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info"), installFolder.getAbsolutePath()); assertContent(new File(configurationFolder, "config.ini"), ":org.eclipse.equinox.simpleconfigurator.jar"); - assertContent(new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info"), adjustSlashes(":plugins/org.eclipse.equinox.simpleconfigurator.jar")); - assertContent(new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info"), adjustSlashes(":plugins/org.eclipse.osgi.jar")); + assertContent(new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info"), ",plugins/org.eclipse.equinox.simpleconfigurator.jar"); + assertContent(new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info"), ",plugins/org.eclipse.osgi.jar"); - BundleInfo bi = new BundleInfo(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm(), 2); + BundleInfo bi = new BundleInfo(new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm()), 2); manipulator.getConfigData().addBundle(bi); manipulator.save(false); // assertContent(new File(configurationFolder, "org.eclipse.equinox.simpleconfigurator/bundles.info"), FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm()); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingABundle.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingABundle.java index 5ddf80277..a33c18f29 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingABundle.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingABundle.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URI; + import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; @@ -28,7 +30,7 @@ public class RemovingABundle extends FwkAdminAndSimpleConfiguratorTest { protected void setUp() throws Exception { super.setUp(); Manipulator manipulator = createMinimalConfiguration(RemovingABundle.class.getName()); - manipulator.getConfigData().addBundle(new BundleInfo("bundle_1", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm(), 4, false)); + manipulator.getConfigData().addBundle(new BundleInfo("bundle_1", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm()), 4, false)); manipulator.save(false); File fooINI = new File(getInstallFolder(), getLauncherName() +".ini"); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingAllBundles.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingAllBundles.java index dd1757afc..da264d0e9 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingAllBundles.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RemovingAllBundles.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -22,7 +26,7 @@ public class RemovingAllBundles extends AbstractFwkAdminTest { super(name); } - public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { + public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { startSimpleConfiguratormManipulator(); FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -40,8 +44,8 @@ public class RemovingAllBundles extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RenamingLauncherIni.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RenamingLauncherIni.java index 6d2f25b68..367990f51 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RenamingLauncherIni.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/RenamingLauncherIni.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -22,7 +26,7 @@ public class RenamingLauncherIni extends AbstractFwkAdminTest { super(name); } - public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { + public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { startSimpleConfiguratormManipulator(); FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -40,8 +44,8 @@ public class RenamingLauncherIni extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java index 2cba41a70..1af667f55 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SharedConfigurationTest.java @@ -43,8 +43,8 @@ public class SharedConfigurationTest extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - assertEquals("false", manipulator.getConfigData().getFwIndependentProp("config.shared")); - assertEquals("true", manipulator.getConfigData().getFwIndependentProp("from.parent")); + assertEquals("false", manipulator.getConfigData().getProperty("config.shared")); + assertEquals("true", manipulator.getConfigData().getProperty("from.parent")); } public void testSharedConfiguration() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { @@ -72,8 +72,8 @@ public class SharedConfigurationTest extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - assertEquals("true", manipulator.getConfigData().getFwIndependentProp("config.shared")); - assertEquals("true", manipulator.getConfigData().getFwIndependentProp("from.parent")); + assertEquals("true", manipulator.getConfigData().getProperty("config.shared")); + assertEquals("true", manipulator.getConfigData().getProperty("from.parent")); } public void testNotSharedConfiguration() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { @@ -101,7 +101,7 @@ public class SharedConfigurationTest extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - assertEquals("false", manipulator.getConfigData().getFwIndependentProp("config.shared")); - assertEquals(null, manipulator.getConfigData().getFwIndependentProp("from.parent")); + assertEquals("false", manipulator.getConfigData().getProperty("config.shared")); + assertEquals(null, manipulator.getConfigData().getProperty("from.parent")); } } diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorComingAndGoing.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorComingAndGoing.java index 1e831f7f1..22190ec7d 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorComingAndGoing.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorComingAndGoing.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -28,8 +32,8 @@ public class SimpleConfiguratorComingAndGoing extends FwkAdminAndSimpleConfigura m = createMinimalConfiguration(SimpleConfiguratorComingAndGoing.class.getName()); } - public void testWithMutipleBundles() throws IOException, BundleException { - BundleInfo bi = new BundleInfo(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm(), 2); + public void testWithMutipleBundles() throws IOException, BundleException, URISyntaxException { + BundleInfo bi = new BundleInfo(new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/bundle_1")).toExternalForm()), 2); m.getConfigData().addBundle(bi); m.save(false); @@ -56,7 +60,7 @@ public class SimpleConfiguratorComingAndGoing extends FwkAdminAndSimpleConfigura //TODO We ignore the framework JAR location not set exception } - newManipulator.getConfigData().addBundle(new BundleInfo(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true)); + newManipulator.getConfigData().addBundle(new BundleInfo(new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true)); newManipulator.save(false); assertContent(getBundleTxt(), "org.eclipse.osgi"); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorTest.java index 143d0543f..8126c6ade 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/SimpleConfiguratorTest.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; +import java.net.URISyntaxException; + +import java.net.URI; + import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.FileLocator; @@ -22,7 +26,7 @@ public class SimpleConfiguratorTest extends AbstractFwkAdminTest { super(name); } - public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException { + public void testConfigFiles() throws IllegalStateException, FrameworkAdminRuntimeException, IOException, BundleException, URISyntaxException { startSimpleConfiguratormManipulator(); FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -40,8 +44,8 @@ public class SimpleConfiguratorTest extends AbstractFwkAdminTest { //TODO We ignore the framework JAR location not set exception } - BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm(), 0, true); - BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm(), 1, true); + BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar")).toExternalForm()), 0, true); + BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", new URI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar")).toExternalForm()), 1, true); manipulator.getConfigData().addBundle(osgiBi); manipulator.getConfigData().addBundle(configuratorBi); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestEclipseDataArea.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestEclipseDataArea.java index fa147ad49..cb563bd8a 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestEclipseDataArea.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestEclipseDataArea.java @@ -25,28 +25,28 @@ public class TestEclipseDataArea extends FwkAdminAndSimpleConfiguratorTest { } public void testp2DataArea() throws IOException { - m.getConfigData().setFwDependentProp("eclipse.p2.data.area", "@config.dir/../p2"); + m.getConfigData().setProperty("eclipse.p2.data.area", "@config.dir/../p2"); m.save(false); assertContent(getConfigIni(), "@config.dir/../p2"); m.load(); m.save(false); assertContent(getConfigIni(), "@config.dir/../p2"); - m.getConfigData().setFwDependentProp("eclipse.p2.data.area", new File(getConfigurationFolder(), "p2").getAbsoluteFile().toURL().toExternalForm()); + m.getConfigData().setProperty("eclipse.p2.data.area", new File(getConfigurationFolder(), "p2").getAbsoluteFile().toURL().toExternalForm()); m.save(false); assertContent(getConfigIni(), "@config.dir/p2"); m.load(); m.save(false); assertContent(getConfigIni(), "@config.dir/p2"); - m.getConfigData().setFwDependentProp("eclipse.p2.data.area", new File(getConfigurationFolder(), "../p2").getAbsoluteFile().toURL().toExternalForm()); + m.getConfigData().setProperty("eclipse.p2.data.area", new File(getConfigurationFolder(), "../p2").getAbsoluteFile().toURL().toExternalForm()); m.save(false); assertContent(getConfigIni(), "@config.dir/../p2"); m.load(); m.save(false); assertContent(getConfigIni(), "@config.dir/../p2"); - m.getConfigData().setFwDependentProp("eclipse.p2.data.area", "file:d:/tmp/foo/bar/p2"); + m.getConfigData().setProperty("eclipse.p2.data.area", "file:d:/tmp/foo/bar/p2"); m.save(false); assertContent(getConfigIni(), "/tmp/foo/bar/p2"); m.load(); diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/UtilsTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/UtilsTest.java index 6f375e8f7..573c93450 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/UtilsTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/UtilsTest.java @@ -9,7 +9,6 @@ package org.eclipse.equinox.frameworkadmin.tests; import java.io.File; -import java.net.URL; import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; @@ -35,13 +34,13 @@ public class UtilsTest extends AbstractFwkAdminTest { Manipulator manipulator = getFrameworkManipulator(new File(installFolder, "configuration"), new File(installFolder, "eclipse")); - assertEquals(new URL(FileUtils.getEclipseRealLocation(manipulator, "org.foo")), foo2.toURL()); - assertEquals(new URL(FileUtils.getEclipseRealLocation(manipulator, "org.foo_1.2.3.abc")), foo1.toURL()); - assertEquals(new URL(FileUtils.getEclipseRealLocation(manipulator, "org.foo.x86_64")), foo_64.toURL()); + assertEquals(FileUtils.getEclipseRealLocation(manipulator, "org.foo"), foo2.toURI()); + assertEquals(FileUtils.getEclipseRealLocation(manipulator, "org.foo_1.2.3.abc"), foo1.toURI()); + assertEquals(FileUtils.getEclipseRealLocation(manipulator, "org.foo.x86_64"), foo_64.toURI()); File other = new File(installFolder, "other/org.foo_1.2.4"); other.mkdirs(); - manipulator.getConfigData().setFwDependentProp("osgi.syspath", other.getParentFile().getAbsolutePath()); - assertEquals(new URL(FileUtils.getEclipseRealLocation(manipulator, "org.foo")), other.toURL()); + manipulator.getConfigData().setProperty("osgi.syspath", other.getParentFile().getAbsolutePath()); + assertEquals(FileUtils.getEclipseRealLocation(manipulator, "org.foo"), other.toURI()); } } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java index f0f4f4523..9a479d614 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java @@ -11,7 +11,8 @@ package org.eclipse.equinox.internal.frameworkadmin.utils; import java.io.File; -import java.net.MalformedURLException; +import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; import org.osgi.framework.Constants; @@ -118,7 +119,7 @@ public class SimpleBundlesState implements BundlesState { * @see org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState#getPrerequisteBundles(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo) */ public BundleInfo[] getPrerequisteBundles(BundleInfo bInfo) { - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); final String requiredBundles = Utils.getManifestMainAttributes(location, Constants.REQUIRE_BUNDLE); if (requiredBundles == null) return new BundleInfo[] {this.getSystemBundle()}; @@ -132,7 +133,7 @@ public class SimpleBundlesState implements BundlesState { ret.add(this.getSystemBundle()); for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo currentBInfo = (BundleInfo) ite.next(); - String currentLocation = currentBInfo.getLocation(); + URI currentLocation = currentBInfo.getLocation(); String currentSymbolicName = Utils.getManifestMainAttributes(currentLocation, Constants.BUNDLE_SYMBOLICNAME); if (currentSymbolicName == null) continue; @@ -154,7 +155,7 @@ public class SimpleBundlesState implements BundlesState { BundleInfo bInfo = (BundleInfo) ite.next(); // if (bInfo.getStartLevel() != 1) // return null;; - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); String bundleName = Utils.getManifestMainAttributes(location, Constants.BUNDLE_NAME); if (systemBundleName.equals(bundleName)) { String bundleVendor = Utils.getManifestMainAttributes(location, Constants.BUNDLE_VENDOR); @@ -166,7 +167,7 @@ public class SimpleBundlesState implements BundlesState { } for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo bInfo = (BundleInfo) ite.next(); - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); String symbolicName = Utils.getManifestMainAttributes(location, Constants.BUNDLE_SYMBOLICNAME); symbolicName = Utils.getPathFromClause(symbolicName); if (this.systemBundleSymbolicName.equals(symbolicName)) @@ -183,7 +184,7 @@ public class SimpleBundlesState implements BundlesState { List list = new LinkedList(); for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo bInfo = (BundleInfo) ite.next(); - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); String manifestVersion = Utils.getManifestMainAttributes(location, Constants.BUNDLE_MANIFESTVERSION); if (manifestVersion == null) continue; @@ -227,20 +228,14 @@ public class SimpleBundlesState implements BundlesState { this.installBundle(bInfos[j]); if (getSystemBundle() == null) { - try { - BundleInfo sysBInfo = new BundleInfo(launcherData.getFwJar().toURL().toExternalForm(), 0, true, 0); - this.installBundle(sysBInfo); - - } catch (MalformedURLException e) { - // Nothign to do because never happens. - e.printStackTrace(); - } + BundleInfo sysBInfo = new BundleInfo(launcherData.getFwJar().toURI(), 0, true, 0); + this.installBundle(sysBInfo); } } public void installBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException { - String newLocation = bInfo.getLocation(); + URI newLocation = bInfo.getLocation(); Dictionary newManifest = Utils.getOSGiManifest(newLocation); if (newManifest == null) { // TODO log something here @@ -252,7 +247,7 @@ public class SimpleBundlesState implements BundlesState { boolean found = false; for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo currentBInfo = (BundleInfo) ite.next(); - String location = currentBInfo.getLocation(); + URI location = currentBInfo.getLocation(); if (newLocation.equals(location)) { found = true; break; @@ -315,12 +310,12 @@ public class SimpleBundlesState implements BundlesState { } public void uninstallBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException { - String targetLocation = bInfo.getLocation(); + URI targetLocation = bInfo.getLocation(); int index = -1; for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { index++; BundleInfo currentBInfo = (BundleInfo) ite.next(); - String location = currentBInfo.getLocation(); + URI location = currentBInfo.getLocation(); if (targetLocation.equals(location)) { break; } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java index 68a5575ef..95d79bf58 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java @@ -26,7 +26,7 @@ import org.osgi.framework.Constants; public class Utils { private static final String FEATURE_MANIFEST = "feature.xml"; //$NON-NLS-1$ - private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$ + private static final String FILE_SCHEME = "file"; //$NON-NLS-1$ private static final String FRAGMENT_MANIFEST = "fragment.xml"; //$NON-NLS-1$ private static final String PATH_SEP = "/"; //$NON-NLS-1$ private static final String PLUGIN_MANIFEST = "plugin.xml"; //$NON-NLS-1$ @@ -171,11 +171,13 @@ public class Utils { } } - public static void createParentDir(File file) throws IOException { + public static boolean createParentDir(File file) { File parent = file.getParentFile(); if (parent == null) - return; - parent.mkdirs(); + return false; + if (parent.exists()) + return true; + return parent.mkdirs(); } public static BundleInfo[] getBundleInfosFromList(List list) { @@ -197,32 +199,32 @@ public class Utils { return ret; } - public static String[] getClausesManifestMainAttributes(String location, String name) { + public static String[] getClausesManifestMainAttributes(URI location, String name) { return getClauses(getManifestMainAttributes(location, name)); } - public static String getManifestMainAttributes(String location, String name) { + public static String getManifestMainAttributes(URI location, String name) { Dictionary manifest = Utils.getOSGiManifest(location); if (manifest == null) throw new RuntimeException("Unable to locate bundle manifest: " + location); return (String) manifest.get(name); } - public static Dictionary getOSGiManifest(String location) { + public static Dictionary getOSGiManifest(URI location) { if (location == null) return null; // if we have a file-based URL that doesn't end in ".jar" then... - if (location.startsWith(FILE_PROTOCOL) && !location.endsWith(".jar")) - return basicLoadManifest(new File(location.substring(FILE_PROTOCOL.length()))); + if (FILE_SCHEME.equals(location.getScheme()) && !location.getPath().endsWith(".jar")) + return basicLoadManifest(new File(location)); try { JarFile jar = null; File file = null; - if (location.startsWith(FILE_PROTOCOL)) { - file = new File(location.substring(FILE_PROTOCOL.length())); + if (FILE_SCHEME.equals(location.getScheme())) { + file = new File(location); jar = new JarFile(file); } else { - URL url = new URL("jar:" + location + "!/"); + URL url = new URL("jar:" + location.toString() + "!/"); JarURLConnection jarConnection = (JarURLConnection) url.openConnection(); jar = jarConnection.getJarFile(); // todo should set this var if possible diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java index c3c1c1a9d..c755c0dab 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.frameworkadmin; -import org.eclipse.core.runtime.Path; +import java.net.URI; /** * This object represents information of a bundle. @@ -22,7 +22,8 @@ public class BundleInfo { private String symbolicName = null; private String version = null; - private String location; + private URI baseLocation; + private URI location; private long bundleId = NO_BUNDLEID; private boolean markedAsStarted = false; @@ -34,71 +35,50 @@ public class BundleInfo { public BundleInfo() { } - public BundleInfo(String location) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location) { + this.location = location; } - public BundleInfo(String location, boolean started) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, boolean started) { + this.location = location; this.markedAsStarted = started; } - public BundleInfo(String location, int startLevel) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, int startLevel) { + this.location = location; this.startLevel = startLevel; } - public BundleInfo(String location, int startLevel, boolean started) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, int startLevel, boolean started) { + this.location = location; this.startLevel = startLevel; this.markedAsStarted = started; } - public BundleInfo(String location, int startLevel, boolean started, long bundleId) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, int startLevel, boolean started, long bundleId) { + this.location = location; this.startLevel = startLevel; this.markedAsStarted = started; this.bundleId = bundleId; } - public BundleInfo(String symbolic, String version, String location, int startLevel, boolean started) { + public BundleInfo(String symbolic, String version, URI location, int startLevel, boolean started) { this.symbolicName = symbolic; this.version = version; - if (location != null) - this.location = location.trim(); + this.location = location; this.markedAsStarted = started; this.startLevel = startLevel; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object toCompare) { - if (toCompare instanceof BundleInfo) { - BundleInfo info = (BundleInfo) toCompare; - //if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.url == null || url == null ? true : info.url.equals(url))) - if (info.symbolicName != null && info.version != null && symbolicName != null && version != null) { - // TODO: the equalsIgnoreCase for location comparison is a bug; - // need a platform sensitive location comparison method - if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.location == null || location == null ? true : new Path(info.location).toFile().equals(new Path(location).toFile()))) - return true; - } else { - return (info.location == null || location == null ? false : new Path(info.location).toFile().equals(new Path(location).toFile())); - } - } - return false; - } - public long getBundleId() { return bundleId; } - public String getLocation() { + public URI getBaseLocation() { + return baseLocation; + } + + public URI getLocation() { return location; } @@ -118,15 +98,6 @@ public class BundleInfo { return version; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int result = symbolicName == null ? 0 : symbolicName.hashCode(); - result = result + (version == null ? 0 : version.hashCode()); - return result; - } - public boolean isMarkedAsStarted() { return markedAsStarted; } @@ -139,9 +110,12 @@ public class BundleInfo { this.bundleId = bundleId; } - public void setLocation(String location) { - this.location = (location != null ? location.trim() : null); + public void setBaseLocation(URI baseLocation) { + this.baseLocation = baseLocation; + } + public void setLocation(URI location) { + this.location = location; } public void setManifest(String manifest) { @@ -179,8 +153,12 @@ public class BundleInfo { buffer.append(", "); //$NON-NLS-1$ if (version != null) buffer.append(version); - buffer.append(", "); //$NON-NLS-1$ - buffer.append("location="); //$NON-NLS-1$ + + if (baseLocation != null) { + buffer.append(", baseLocation="); //$NON-NLS-1$ + buffer.append(baseLocation); + } + buffer.append(", location="); //$NON-NLS-1$ buffer.append(location); buffer.append(", startLevel="); //$NON-NLS-1$ buffer.append(startLevel); @@ -194,4 +172,45 @@ public class BundleInfo { buffer.append(')'); return buffer.toString(); } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((symbolicName == null) ? 0 : symbolicName.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + + if (obj == null) + return false; + + if (getClass() != obj.getClass()) + return false; + + BundleInfo other = (BundleInfo) obj; + if (symbolicName == null) { + if (other.symbolicName != null) + return false; + } else if (!symbolicName.equals(other.symbolicName)) + return false; + + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + + if (location == null || other.location == null) + return true; + + //compare absolute location URIs + URI absoluteLocation = baseLocation == null ? location : baseLocation.resolve(location); + URI otherAbsoluteLocation = other.baseLocation == null ? other.location : other.baseLocation.resolve(other.location); + + return absoluteLocation.equals(otherAbsoluteLocation); + } } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java index 8a4bf076f..2118b5e72 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java @@ -47,9 +47,8 @@ public class ConfigData { private int initialBundleStartLevel = BundleInfo.NO_LEVEL; // List of BundleInfo private LinkedHashSet bundlesList = new LinkedHashSet(); - private Properties fwIndependentProps = new Properties(); - private Properties fwDependentProps = new Properties(); + private Properties properties = new Properties(); public ConfigData(String fwName, String fwVersion, String launcherName, String launcherVersion) { this.fwName = fwName; @@ -75,23 +74,13 @@ public class ConfigData { return ret; } - public String getFwDependentProp(String key) { - return fwDependentProps.getProperty(key); + public String getProperty(String key) { + return properties.getProperty(key); } - public Properties getFwDependentProps() { + public Properties getProperties() { Properties ret = new Properties(); - appendProperties(ret, fwDependentProps); - return ret; - } - - public String getFwIndependentProp(String key) { - return fwIndependentProps.getProperty(key); - } - - public Properties getFwIndependentProps() { - Properties ret = new Properties(); - appendProperties(ret, fwIndependentProps); + appendProperties(ret, properties); return ret; } @@ -119,8 +108,8 @@ public class ConfigData { beginningFwStartLevel = BundleInfo.NO_LEVEL; initialBundleStartLevel = BundleInfo.NO_LEVEL; bundlesList.clear(); - fwIndependentProps.clear(); - fwDependentProps.clear(); + properties.clear(); + properties.clear(); } public boolean removeBundle(BundleInfo bundleInfo) { @@ -140,28 +129,16 @@ public class ConfigData { bundlesList.add(bundleInfos[i]); } - public void setFwDependentProp(String key, String value) { - if (value == null) - fwDependentProps.remove(key); - else - fwDependentProps.setProperty(key, value); - } - - public void setFwDependentProps(Properties props) { - fwDependentProps.clear(); - appendProperties(fwDependentProps, props); - } - - public void setFwIndependentProp(String key, String value) { + public void setProperty(String key, String value) { if (value == null) - fwIndependentProps.remove(key); + properties.remove(key); else - fwIndependentProps.setProperty(key, value); + properties.setProperty(key, value); } - public void setFwIndependentProps(Properties props) { - fwIndependentProps.clear(); - appendProperties(fwIndependentProps, props); + public void setProperties(Properties props) { + properties.clear(); + appendProperties(properties, props); } public void setInitialBundleStartLevel(int startLevel) { @@ -189,12 +166,9 @@ public class ConfigData { } } - sb.append("============ Fw Independent Props ===============\n"); //$NON-NLS-1$ + sb.append("============ Properties ===============\n"); //$NON-NLS-1$ sb.append("fwIndependentProps="); //$NON-NLS-1$ - setPropsStrings(sb, fwIndependentProps); - sb.append("============ Fw Dependent Props ===============\n"); //$NON-NLS-1$ - sb.append("fwDependentProps="); //$NON-NLS-1$ - setPropsStrings(sb, fwDependentProps); + setPropsStrings(sb, properties); return sb.toString(); } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java index ad8fd4917..a5dcb34d8 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java @@ -23,7 +23,6 @@ import java.util.*; * @see Manipulator */ public class LauncherData { - //private static final String[] NULL_STRINGS = new String[0]; private File fwPersistentDataLocation = null; private File jvm = null; private List jvmArgs = new LinkedList(); diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/Metadata Generator Plugins and Features.launch b/bundles/org.eclipse.equinox.p2.metadata.generator/Metadata Generator Plugins and Features.launch index 271620c70..5464e6492 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/Metadata Generator Plugins and Features.launch +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/Metadata Generator Plugins and Features.launch @@ -4,7 +4,6 @@ <booleanAttribute key="automaticAdd" value="false"/> <booleanAttribute key="automaticValidate" value="false"/> <stringAttribute key="bootstrap" value=""/> -<stringAttribute key="checked" value="[NONE]"/> <booleanAttribute key="clearConfig" value="false"/> <stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Metadata Generator Plugins and Features"/> <booleanAttribute key="default_auto_start" value="false"/> @@ -15,9 +14,9 @@ <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> <stringAttribute key="pde.version" value="3.3"/> <booleanAttribute key="show_selected_only" value="false"/> -<stringAttribute key="target_bundles" value="org.eclipse.osgi.services*3.1.200.v20071203@default:default,org.eclipse.core.runtime.compatibility.auth*3.2.100.v20070502@default:default,org.eclipse.equinox.common*3.4.0.v20080421-2006@default:default,org.eclipse.equinox.registry*3.4.0.v20080421-2006@default:default,org.eclipse.core.runtime.compatibility.registry*3.2.200.v20070717@default:false,org.eclipse.core.variables*3.2.100.v20080324-1600@default:default,org.eclipse.core.runtime*3.4.0.v20080421-1805@default:true,org.eclipse.equinox.app*1.1.0.v20080421-2006@default:default,org.eclipse.core.jobs*3.4.0.v20080310@default:default,org.eclipse.core.contenttype*3.3.0.v20080414@default:default,org.eclipse.ant.core*3.2.0.v20080425@default:default"/> +<stringAttribute key="target_bundles" value="org.eclipse.core.runtime.compatibility.registry@default:false,org.eclipse.ant.core@default:default,org.eclipse.osgi.services@default:default,org.eclipse.equinox.app@default:default,org.eclipse.core.jobs@default:default,org.eclipse.equinox.common@default:default,org.eclipse.core.runtime.compatibility.auth@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.core.variables@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.runtime@default:true"/> <booleanAttribute key="tracing" value="false"/> <booleanAttribute key="useDefaultConfigArea" value="true"/> <booleanAttribute key="useNamedJRE" value="true"/> -<stringAttribute key="workspace_bundles" value="org.eclipse.equinox.p2.garbagecollector*1.0.0.qualifier@default:default,org.eclipse.equinox.security*1.0.0.qualifier@default:default,org.eclipse.equinox.p2.metadata*1.0.0.qualifier@default:default,org.eclipse.equinox.p2.touchpoint.natives*1.0.0.qualifier@default:default,org.eclipse.equinox.frameworkadmin*1.0.0.qualifier@default:default,org.eclipse.equinox.frameworkadmin.equinox*1.0.0.qualifier@default:default,org.eclipse.equinox.p2.metadata.repository*1.0.0.qualifier@default:default,org.eclipse.equinox.simpleconfigurator.manipulator*1.0.0.qualifier@default:default,org.eclipse.osgi*3.4.0.qualifier@:,org.eclipse.equinox.p2.touchpoint.eclipse*1.0.0.qualifier@default:default,org.eclipse.ecf.provider.filetransfer*2.0.0.qualifier@default:default,org.eclipse.equinox.p2.artifact.repository*1.0.0.qualifier@default:default,org.eclipse.ecf*2.0.0.qualifier@default:default,org.eclipse.ecf.ssl*1.0.0.qualifier@default:false,org.eclipse.equinox.p2.metadata.generator*1.0.0.qualifier@default:default,org.eclipse.equinox.security.win32.x86*1.0.0.qualifier@default:false,org.eclipse.equinox.p2.core*1.0.0.qualifier@default:default,org.eclipse.equinox.preferences*3.2.200.qualifier@default:default,org.eclipse.ecf.provider.filetransfer.ssl*1.0.0.qualifier@default:false,org.eclipse.equinox.simpleconfigurator*1.0.0.qualifier@default:true,org.eclipse.ecf.filetransfer*2.0.0.qualifier@default:default,org.eclipse.equinox.p2.engine*1.0.0.qualifier@default:default,org.eclipse.ecf.identity*2.0.0.qualifier@default:default"/> +<stringAttribute key="workspace_bundles" value="org.eclipse.ecf.identity@default:default,org.eclipse.ecf.provider.filetransfer@default:default,org.eclipse.equinox.p2.core@default:default,org.eclipse.equinox.p2.metadata.repository@default:default,org.eclipse.equinox.simpleconfigurator@default:true,org.eclipse.ecf.filetransfer@default:default,org.eclipse.equinox.p2.touchpoint.natives@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.equinox.p2.metadata@default:default,org.eclipse.equinox.simpleconfigurator.manipulator@default:default,org.eclipse.ecf.ssl@default:false,org.eclipse.ecf.provider.filetransfer.ssl@default:false,org.eclipse.equinox.frameworkadmin.equinox@default:default,org.eclipse.equinox.frameworkadmin@default:default,org.eclipse.ecf@default:default,org.eclipse.equinox.p2.artifact.repository@default:default,org.eclipse.equinox.p2.garbagecollector@default:default,org.eclipse.equinox.p2.metadata.generator@default:default,org.eclipse.equinox.p2.touchpoint.eclipse@default:default"/> </launchConfiguration> diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/EclipseInstallGeneratorInfoProvider.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/EclipseInstallGeneratorInfoProvider.java index 661e0f65f..5dc15cb29 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/EclipseInstallGeneratorInfoProvider.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/EclipseInstallGeneratorInfoProvider.java @@ -258,10 +258,12 @@ public class EclipseInstallGeneratorInfoProvider implements IGeneratorInfo { } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); } ConfigData data = manipulator.getConfigData(); - String value = data.getFwIndependentProp(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL); + String value = data.getProperty(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL); if (value != null) { try { //config.ini uses simpleconfigurator, read the bundles.info and replace the bundle infos @@ -274,7 +276,7 @@ public class EclipseInstallGeneratorInfoProvider implements IGeneratorInfo { } try { - data.setFwIndependentProp(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeRelative(value, configLocation.toURL())); + data.setProperty(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeRelative(value, configLocation.toURL())); } catch (MalformedURLException e) { //ignore } @@ -345,8 +347,15 @@ public class EclipseInstallGeneratorInfoProvider implements IGeneratorInfo { tok.nextToken(); // , boolean markedAsStarted = Boolean.valueOf(tok.nextToken()).booleanValue(); - BundleInfo bInfo = new BundleInfo(symbolicName, version, urlSt, sl, markedAsStarted); - bundles.add(bInfo); + BundleInfo bInfo; + try { + bInfo = new BundleInfo(symbolicName, version, new URI(urlSt), sl, markedAsStarted); + + bundles.add(bInfo); + } catch (URISyntaxException e) { + e.printStackTrace(); + throw new IllegalStateException("Error coverting url based string to uri: " + e.getMessage()); + } } } finally { try { diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java index 4f21e74fb..dfe81c38a 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java @@ -275,7 +275,7 @@ public class Generator { private String[] getConfigurationStrings(ConfigData configData) { String configurationData = ""; //$NON-NLS-1$ String unconfigurationData = ""; //$NON-NLS-1$ - for (Iterator iterator = configData.getFwDependentProps().entrySet().iterator(); iterator.hasNext();) { + for (Iterator iterator = configData.getProperties().entrySet().iterator(); iterator.hasNext();) { Entry aProperty = (Entry) iterator.next(); String key = ((String) aProperty.getKey()); if (key.equals("osgi.frameworkClassPath") || key.equals("osgi.framework") || key.equals("osgi.bundles") || key.equals("eof")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ @@ -283,7 +283,7 @@ public class Generator { configurationData += "setProgramProperty(propName:" + key + ", propValue:" + ((String) aProperty.getValue()) + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ unconfigurationData += "setProgramProperty(propName:" + key + ", propValue:);"; //$NON-NLS-1$ //$NON-NLS-2$ } - for (Iterator iterator = configData.getFwIndependentProps().entrySet().iterator(); iterator.hasNext();) { + for (Iterator iterator = configData.getProperties().entrySet().iterator(); iterator.hasNext();) { Entry aProperty = (Entry) iterator.next(); String key = ((String) aProperty.getKey()); if (key.equals("osgi.frameworkClassPath") || key.equals("osgi.framework") || key.equals("osgi.bundles") || key.equals("eof")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java index 82b9e9c70..dc1d5f372 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java @@ -10,8 +10,7 @@ package org.eclipse.equinox.internal.p2.publisher.eclipse; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -101,8 +100,15 @@ public class DataLoader { tok.nextToken(); // , boolean markedAsStarted = Boolean.valueOf(tok.nextToken()).booleanValue(); - BundleInfo bInfo = new BundleInfo(symbolicName, version, urlSt, sl, markedAsStarted); - bundles.add(bInfo); + BundleInfo bInfo; + try { + bInfo = new BundleInfo(symbolicName, version, new URI(urlSt), sl, markedAsStarted); + + bundles.add(bInfo); + } catch (URISyntaxException e) { + e.printStackTrace(); + throw new IllegalStateException("Error coverting url based string to uri: " + e.getMessage()); + } } } finally { try { @@ -157,9 +163,11 @@ public class DataLoader { parser.readFwConfig(manipulator, configurationLocation); } catch (IOException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error loading config.", e)); //$NON-NLS-1$ //TODO: Fix error string + } catch (URISyntaxException e) { + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error loading config.", e)); //$NON-NLS-1$ //TODO: Fix error string } ConfigData data = manipulator.getConfigData(); - String value = data.getFwIndependentProp(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL); + String value = data.getProperty(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL); if (value != null) { try { //config.ini uses simpleconfigurator, read the bundles.info and replace the bundle infos @@ -171,7 +179,7 @@ public class DataLoader { // ignore } try { - data.setFwIndependentProp(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeRelative(value, configurationLocation.toURL())); + data.setProperty(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeRelative(value, configurationLocation.toURL())); } catch (MalformedURLException e) { //ignore } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigAdvice.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigAdvice.java index cd778de70..2e25a1b97 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigAdvice.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigAdvice.java @@ -34,8 +34,7 @@ public class ConfigAdvice extends AbstractAdvice implements IConfigAdvice { public Properties getProperties() { Properties result = new Properties(); - result.putAll(data.getFwDependentProps()); - result.putAll(data.getFwIndependentProps()); + result.putAll(data.getProperties()); return result; } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java index 93eb17bf1..f376c4971 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ConfigCUsAction.java @@ -11,8 +11,6 @@ package org.eclipse.equinox.p2.publisher.eclipse; import java.io.File; -import java.io.IOException; -import java.net.URL; import java.util.*; import java.util.Map.Entry; import org.eclipse.core.runtime.*; @@ -135,7 +133,7 @@ public class ConfigCUsAction extends AbstractPublisherAction { result.add(bundles[i]); else { try { - File location = new File(new URL(bundleInfo.getLocation()).getPath()); + File location = new File(bundleInfo.getLocation()); Dictionary manifest = BundlesAction.loadManifest(location); if (manifest == null) continue; @@ -147,9 +145,6 @@ public class ConfigCUsAction extends AbstractPublisherAction { } catch (BundleException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ProductFileAdvice.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ProductFileAdvice.java index 41049123e..b4db04776 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ProductFileAdvice.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/eclipse/ProductFileAdvice.java @@ -43,10 +43,10 @@ public class ProductFileAdvice extends AbstractAdvice implements ILaunchingAdvic result = loader.getConfigData(); else result = generateConfigData(); - result.setFwIndependentProp("eclipse.product", product.getId()); //$NON-NLS-1$ + result.setProperty("eclipse.product", product.getId()); //$NON-NLS-1$ String location = getSplashLocation(); if (location != null) - result.setFwIndependentProp("osgi.splashPath", location); //$NON-NLS-1$ + result.setProperty("osgi.splashPath", location); //$NON-NLS-1$ return result; } @@ -100,8 +100,7 @@ public class ProductFileAdvice extends AbstractAdvice implements ILaunchingAdvic public Properties getProperties() { Properties result = new Properties(); - result.putAll(configData.getFwDependentProps()); - result.putAll(configData.getFwIndependentProps()); + result.putAll(configData.getProperties()); return result; } diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF index e66cfc263..22137f32d 100644 --- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF @@ -74,7 +74,8 @@ Require-Bundle: org.eclipse.equinox.p2.metadata.generator, org.sat4j.pb;bundle-version="2.0.0", org.eclipse.equinox.p2.installer;bundle-version="[1.0.0,2.0.0)", org.eclipse.equinox.simpleconfigurator;bundle-version="1.0.100", - org.eclipse.equinox.p2.updatechecker;bundle-version="1.0.0" + org.eclipse.equinox.p2.updatechecker;bundle-version="1.0.0", + org.eclipse.equinox.simpleconfigurator.manipulator;bundle-version="1.0.100" Bundle-ActivationPolicy: lazy Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AutomatedTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AutomatedTests.java index 7126c141f..706152760 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AutomatedTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AutomatedTests.java @@ -38,6 +38,7 @@ public class AutomatedTests extends TestCase { suite.addTest(org.eclipse.equinox.p2.tests.planner.AllTests.suite()); suite.addTest(org.eclipse.equinox.p2.tests.publisher.AllTests.suite()); suite.addTest(org.eclipse.equinox.p2.tests.simpleconfigurator.SimpleConfiguratorTests.suite()); + suite.addTest(org.eclipse.equinox.p2.tests.simpleconfigurator.manipulator.AllTests.suite()); suite.addTest(org.eclipse.equinox.p2.tests.updatesite.AllTests.suite()); suite.addTest(org.eclipse.equinox.p2.tests.touchpoint.eclipse.AllTests.suite()); suite.addTest(org.eclipse.equinox.p2.tests.reconciler.dropins.AllTests.suite()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AccumulateConfigDataActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AccumulateConfigDataActionTest.java index 11e13371f..e18f9a8bc 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AccumulateConfigDataActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/AccumulateConfigDataActionTest.java @@ -11,6 +11,7 @@ package org.eclipse.equinox.p2.tests.publisher.actions; import java.io.File; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Properties; import org.easymock.Capture; @@ -19,6 +20,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData; +import org.eclipse.equinox.internal.simpleconfigurator.utils.URIUtil; import org.eclipse.equinox.p2.publisher.eclipse.*; import org.eclipse.equinox.p2.tests.TestActivator; @@ -53,18 +55,18 @@ public class AccumulateConfigDataActionTest extends ActionTest { debug("Completed AccumulateConfigDataActionTest."); //$NON-NLS-1$ } - private void verifyLaunchAdvice() { + private void verifyLaunchAdvice() throws URISyntaxException { LaunchingAdvice captured = launchingAdviceCapture.getValue(); String[] programArgs = captured.getProgramArguments(); assertTrue(programArgs.length == 4); assertTrue(programArgs[0].equalsIgnoreCase("-startup")); //$NON-NLS-1$ Path path1 = new Path(TestActivator.getTestDataFolder().getPath() + FOO); - assertTrue(new Path(programArgs[1]).equals(path1)); + assertTrue(path1.toFile().toURI().equals(URIUtil.fromString(programArgs[1]))); assertTrue(programArgs[2].equalsIgnoreCase("--launcher.library"));//$NON-NLS-1$ Path path2 = new Path(TestActivator.getTestDataFolder().getPath() + BAR); - assertTrue(new Path(programArgs[3]).equals(path2)); + assertTrue(path2.toFile().toURI().equals(URIUtil.fromString(programArgs[3]))); String[] vmArgs = captured.getVMArguments(); assertTrue(vmArgs.length == 0); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java index 8d50c5015..a3b448fa5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java @@ -16,6 +16,7 @@ public class SimpleConfiguratorTests { public static Test suite() { TestSuite suite = new TestSuite("Tests for org.eclipse.equinox.simpleconfigurator"); //$JUnit-BEGIN$ + suite.addTestSuite(SimpleConfiguratorUtilsTest.class); suite.addTestSuite(BundlesTxtTest.class); suite.addTestSuite(NonExclusiveMode.class); //$JUnit-END$ diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorUtilsTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorUtilsTest.java new file mode 100644 index 000000000..a0722c49a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorUtilsTest.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.simpleconfigurator; + +import java.io.File; +import java.io.IOException; +import java.net.*; +import java.util.List; +import org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo; +import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; + +public class SimpleConfiguratorUtilsTest extends AbstractProvisioningTest { + + public void testParseBundleInfo() throws MalformedURLException { + + File baseFile = getTempFolder(); + URI baseURI = baseFile.toURI(); + + String canonicalForm = "javax.servlet,2.4.0.v200806031604,plugins/javax.servlet_2.4.0.v200806031604.jar,4,false"; + BundleInfo canonicalInfo = SimpleConfiguratorUtils.parseBundleInfoLine(canonicalForm, baseURI); + File canonicalFile = new File(baseFile, "plugins/javax.servlet_2.4.0.v200806031604.jar"); + + String line[] = new String[7]; + line[0] = "javax.servlet,2.4.0.v200806031604,file:plugins/javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[1] = "javax.servlet,2.4.0.v200806031604,plugins\\javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[2] = "javax.servlet,2.4.0.v200806031604,file:plugins\\javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[3] = "javax.servlet,2.4.0.v200806031604,file:plugins\\javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[4] = "javax.servlet,2.4.0.v200806031604,file:" + canonicalFile.toString() + ",4,false"; + line[5] = "javax.servlet,2.4.0.v200806031604," + canonicalFile.toURL().toExternalForm() + ",4,false"; + line[6] = "javax.servlet,2.4.0.v200806031604," + canonicalFile.toURI().toString() + ",4,false"; + + String relativeBundleLocation = "reference:file:plugins/javax.servlet_2.4.0.v200806031604.jar"; + String absoluteBundleLocation = "reference:" + canonicalFile.toURL().toExternalForm(); + + for (int i = 0; i < line.length; i++) { + BundleInfo info = SimpleConfiguratorUtils.parseBundleInfoLine(line[i], baseURI); + assertEquals("[" + i + "]", canonicalInfo, info); + if (info.getLocation().isAbsolute()) + assertEquals("[" + i + "]", absoluteBundleLocation, SimpleConfiguratorUtils.getBundleLocation(info, true)); + else + assertEquals("[" + i + "]", relativeBundleLocation, SimpleConfiguratorUtils.getBundleLocation(info, true)); + } + } + + public void testParseUNCBundleInfo() throws MalformedURLException { + + File baseFile = new File("\\\\127.0.0.1\\somefolder\\"); + URI baseURI = baseFile.toURI(); + + String canonicalForm = "javax.servlet,2.4.0.v200806031604,plugins/javax.servlet_2.4.0.v200806031604.jar,4,false"; + BundleInfo canonicalInfo = SimpleConfiguratorUtils.parseBundleInfoLine(canonicalForm, baseURI); + File canonicalFile = new File(baseFile, "plugins/javax.servlet_2.4.0.v200806031604.jar"); + + String line[] = new String[4]; + line[0] = "javax.servlet,2.4.0.v200806031604,file:plugins/javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[1] = "javax.servlet,2.4.0.v200806031604,plugins\\javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[2] = "javax.servlet,2.4.0.v200806031604,file:plugins\\javax.servlet_2.4.0.v200806031604.jar,4,false"; + line[3] = "javax.servlet,2.4.0.v200806031604,file:plugins\\javax.servlet_2.4.0.v200806031604.jar,4,false"; + + //TODO: we need to fix URI.resolve for UNC paths + //line[4] = "javax.servlet,2.4.0.v200806031604," + canonicalFile.toURI().toString() + ",4,false"; + + String relativeBundleLocation = "reference:file:plugins/javax.servlet_2.4.0.v200806031604.jar"; + String absoluteBundleLocation = "reference:" + canonicalFile.toURL().toExternalForm(); + + for (int i = 0; i < line.length; i++) { + BundleInfo info = SimpleConfiguratorUtils.parseBundleInfoLine(line[i], baseURI); + assertEquals("[" + i + "]", canonicalInfo, info); + if (info.getLocation().isAbsolute()) + assertEquals("[" + i + "]", absoluteBundleLocation, SimpleConfiguratorUtils.getBundleLocation(info, true)); + else + assertEquals("[" + i + "]", relativeBundleLocation, SimpleConfiguratorUtils.getBundleLocation(info, true)); + } + } + + public void testRead34BundlesInfo() { + + File data = getTestData("1.0", "testData/simpleConfiguratorTest/3.4.bundles.info"); + try { + URI baseLocation = new URI("file:/c:/tmp/foo"); + List infos = SimpleConfiguratorUtils.readConfiguration(data.toURL(), baseLocation); + assertEquals("1.1", 2, infos.size()); + + BundleInfo a = new BundleInfo("a", "1.0.0", new URI("plugins/a_1.0.0.jar"), 4, false); + a.setBaseLocation(baseLocation); + BundleInfo b = new BundleInfo("b", "1.0.0", new URI("plugins/b_1.0.0.jar"), -1, true); + b.setBaseLocation(baseLocation); + + assertEquals("1.2", a, infos.get(0)); + assertEquals("1.3", b, infos.get(1)); + + } catch (URISyntaxException e) { + fail("1.97", e); + } catch (MalformedURLException e) { + fail("1.98", e); + } catch (IOException e) { + fail("1.99", e); + } + } + +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/manipulator/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/manipulator/AllTests.java new file mode 100644 index 000000000..e8ed347c3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/manipulator/AllTests.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.simpleconfigurator.manipulator; + +import junit.framework.*; + +/** + * Performs all automated director tests. + */ +public class AllTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(AllTests.class.getName()); + suite.addTestSuite(SimpleConfiguratorManipulatorUtilsTest.class); + return suite; + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtilsTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtilsTest.java new file mode 100644 index 000000000..e3a2d51a1 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtilsTest.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.simpleconfigurator.manipulator; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorUtils; +import org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo; +import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; + +public class SimpleConfiguratorManipulatorUtilsTest extends AbstractProvisioningTest { + + public void testWriteBundleInfoLine() throws URISyntaxException, IOException { + String expectedLine = "javax.servlet,2.4.0.v200806031604,plugins/javax.servlet_2.4.0.v200806031604.jar,4,false"; + BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugins/javax.servlet_2.4.0.v200806031604.jar"), 4, false); + String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo); + assertEquals(expectedLine, line); + assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null)); + } + + public void testWriteBundleInfoLineWithComma() throws URISyntaxException, IOException { + String expectedLine = "javax.servlet,2.4.0.v200806031604,plugin%2Cs/javax.servlet_2.4.0.v200806031604.jar,4,false"; + BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugin,s/javax.servlet_2.4.0.v200806031604.jar"), 4, false); + String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo); + assertEquals(expectedLine, line); + assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null)); + } + + public void testWriteBundleInfoLineWithSpace() throws URISyntaxException, IOException { + String expectedLine = "javax.servlet,2.4.0.v200806031604,plugin%20s/javax.servlet_2.4.0.v200806031604.jar,4,false"; + BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugin%20s/javax.servlet_2.4.0.v200806031604.jar"), 4, false); + String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo); + assertEquals(expectedLine, line); + assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null)); + } + + public void testWriteBundleInfoLineWithAtSymbol() throws URISyntaxException, IOException { + String expectedLine = "javax.servlet,2.4.0.v200806031604,plugin@s/javax.servlet_2.4.0.v200806031604.jar,4,false"; + BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugin@s/javax.servlet_2.4.0.v200806031604.jar"), 4, false); + String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo); + assertEquals(expectedLine, line); + assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null)); + } + +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddSourceBundleActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddSourceBundleActionTest.java index 8c2a82b46..b843c661e 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddSourceBundleActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddSourceBundleActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.equinox.p2.tests.touchpoint.eclipse; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionConstants; @@ -79,7 +80,7 @@ public class AddSourceBundleActionTest extends AbstractProvisioningTest { } private boolean inBundles(SourceManipulator manipulator, File osgiTarget) throws IOException { - String location = osgiTarget.toURL().toExternalForm(); + URI location = osgiTarget.toURI(); BundleInfo[] bundles = manipulator.getBundles(); for (int i = 0; i < bundles.length; i++) { if (location.equals(bundles[i].getLocation())) diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/InstallBundleActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/InstallBundleActionTest.java index f134c25d0..e01d82325 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/InstallBundleActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/InstallBundleActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.equinox.p2.tests.touchpoint.eclipse; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; @@ -80,8 +81,8 @@ public class InstallBundleActionTest extends AbstractProvisioningTest { assertFalse(inBundles(manipulator, osgiTarget)); } - private boolean inBundles(Manipulator manipulator, File osgiTarget) throws IOException { - String location = osgiTarget.toURL().toExternalForm(); + private boolean inBundles(Manipulator manipulator, File osgiTarget) { + URI location = osgiTarget.toURI(); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (location.equals(bundles[i].getLocation())) diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/MarkStartedActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/MarkStartedActionTest.java index 91cf3ba87..5d4ecd0b5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/MarkStartedActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/MarkStartedActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.equinox.p2.tests.touchpoint.eclipse; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; @@ -83,8 +84,8 @@ public class MarkStartedActionTest extends AbstractProvisioningTest { assertTrue(isMarkedStarted(manipulator, osgiTarget, false)); } - private boolean isMarkedStarted(Manipulator manipulator, File osgiTarget, boolean started) throws IOException { - String location = osgiTarget.toURL().toExternalForm(); + private boolean isMarkedStarted(Manipulator manipulator, File osgiTarget, boolean started) { + URI location = osgiTarget.toURI(); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (location.equals(bundles[i].getLocation()) && (started == bundles[i].isMarkedAsStarted())) diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveSourceBundleActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveSourceBundleActionTest.java index 8fb4f1b65..f87e6dc3a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveSourceBundleActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/RemoveSourceBundleActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.equinox.p2.tests.touchpoint.eclipse; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionConstants; @@ -70,7 +71,7 @@ public class RemoveSourceBundleActionTest extends AbstractProvisioningTest { SourceManipulator manipulator = (SourceManipulator) parameters.get(EclipseTouchpoint.PARM_SOURCE_BUNDLES); assertNotNull(manipulator); - manipulator.addBundle(osgiTarget); + manipulator.addBundle(osgiTarget, key.getId(), key.getVersion()); assertTrue(inBundles(manipulator, osgiTarget)); RemoveSourceBundleAction action = new RemoveSourceBundleAction(); action.execute(parameters); @@ -80,7 +81,7 @@ public class RemoveSourceBundleActionTest extends AbstractProvisioningTest { } private boolean inBundles(SourceManipulator manipulator, File osgiTarget) throws IOException { - String location = osgiTarget.toURL().toExternalForm(); + URI location = osgiTarget.toURI(); BundleInfo[] bundles = manipulator.getBundles(); for (int i = 0; i < bundles.length; i++) { if (location.equals(bundles[i].getLocation())) diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkDependentPropertyActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkDependentPropertyActionTest.java index 909edd96e..284b7676e 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkDependentPropertyActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkDependentPropertyActionTest.java @@ -42,15 +42,15 @@ public class SetFrameworkDependentPropertyActionTest extends AbstractProvisionin String frameworkDependentPropertyName = "test"; String frameworkDependentPropertyValue = "true"; - assertFalse(manipulator.getConfigData().getFwDependentProps().containsKey(frameworkDependentPropertyName)); + assertFalse(manipulator.getConfigData().getProperties().containsKey(frameworkDependentPropertyName)); parameters.put(ActionConstants.PARM_PROP_NAME, frameworkDependentPropertyName); parameters.put(ActionConstants.PARM_PROP_VALUE, frameworkDependentPropertyValue); parameters = Collections.unmodifiableMap(parameters); SetFrameworkDependentPropertyAction action = new SetFrameworkDependentPropertyAction(); action.execute(parameters); - assertEquals("true", manipulator.getConfigData().getFwDependentProp(frameworkDependentPropertyName)); + assertEquals("true", manipulator.getConfigData().getProperty(frameworkDependentPropertyName)); action.undo(parameters); - assertFalse(manipulator.getConfigData().getFwDependentProps().containsKey(frameworkDependentPropertyName)); + assertFalse(manipulator.getConfigData().getProperties().containsKey(frameworkDependentPropertyName)); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkIndependentPropertyActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkIndependentPropertyActionTest.java index 46fcdf31f..8cad52796 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkIndependentPropertyActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetFrameworkIndependentPropertyActionTest.java @@ -42,15 +42,15 @@ public class SetFrameworkIndependentPropertyActionTest extends AbstractProvision String frameworkDependentPropertyName = "test"; String frameworkDependentPropertyValue = "true"; - assertFalse(manipulator.getConfigData().getFwIndependentProps().containsKey(frameworkDependentPropertyName)); + assertFalse(manipulator.getConfigData().getProperties().containsKey(frameworkDependentPropertyName)); parameters.put(ActionConstants.PARM_PROP_NAME, frameworkDependentPropertyName); parameters.put(ActionConstants.PARM_PROP_VALUE, frameworkDependentPropertyValue); parameters = Collections.unmodifiableMap(parameters); SetFrameworkIndependentPropertyAction action = new SetFrameworkIndependentPropertyAction(); action.execute(parameters); - assertEquals("true", manipulator.getConfigData().getFwIndependentProp(frameworkDependentPropertyName)); + assertEquals("true", manipulator.getConfigData().getProperty(frameworkDependentPropertyName)); action.undo(parameters); - assertFalse(manipulator.getConfigData().getFwIndependentProps().containsKey(frameworkDependentPropertyName)); + assertFalse(manipulator.getConfigData().getProperties().containsKey(frameworkDependentPropertyName)); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetProgramPropertyActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetProgramPropertyActionTest.java index 7d5b00920..6e7e7c8ec 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetProgramPropertyActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetProgramPropertyActionTest.java @@ -42,16 +42,16 @@ public class SetProgramPropertyActionTest extends AbstractProvisioningTest { String frameworkDependentPropertyName = "test"; String frameworkDependentPropertyValue = "true"; - assertFalse(manipulator.getConfigData().getFwDependentProps().containsKey(frameworkDependentPropertyName)); + assertFalse(manipulator.getConfigData().getProperties().containsKey(frameworkDependentPropertyName)); parameters.put(ActionConstants.PARM_PROP_NAME, frameworkDependentPropertyName); parameters.put(ActionConstants.PARM_PROP_VALUE, frameworkDependentPropertyValue); parameters = Collections.unmodifiableMap(parameters); SetProgramPropertyAction action = new SetProgramPropertyAction(); action.execute(parameters); - assertEquals("true", manipulator.getConfigData().getFwDependentProp(frameworkDependentPropertyName)); + assertEquals("true", manipulator.getConfigData().getProperty(frameworkDependentPropertyName)); action.undo(parameters); - assertFalse(manipulator.getConfigData().getFwDependentProps().containsKey(frameworkDependentPropertyName)); + assertFalse(manipulator.getConfigData().getProperties().containsKey(frameworkDependentPropertyName)); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetStartLevelActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetStartLevelActionTest.java index e34957de9..40640360d 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetStartLevelActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/SetStartLevelActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.equinox.p2.tests.touchpoint.eclipse; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; @@ -83,8 +84,8 @@ public class SetStartLevelActionTest extends AbstractProvisioningTest { assertTrue(isStartLevel(manipulator, osgiTarget, -1)); } - private boolean isStartLevel(Manipulator manipulator, File osgiTarget, int startLevel) throws IOException { - String location = osgiTarget.toURL().toExternalForm(); + private boolean isStartLevel(Manipulator manipulator, File osgiTarget, int startLevel) { + URI location = osgiTarget.toURI(); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (location.equals(bundles[i].getLocation()) && (startLevel == bundles[i].getStartLevel())) diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UninstallBundleActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UninstallBundleActionTest.java index 13cff5345..c3d72e62c 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UninstallBundleActionTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/UninstallBundleActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.equinox.p2.tests.touchpoint.eclipse; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint; import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; @@ -82,8 +83,8 @@ public class UninstallBundleActionTest extends AbstractProvisioningTest { assertTrue(inBundles(manipulator, osgiTarget)); } - private boolean inBundles(Manipulator manipulator, File osgiTarget) throws IOException { - String location = osgiTarget.toURL().toExternalForm(); + private boolean inBundles(Manipulator manipulator, File osgiTarget) { + URI location = osgiTarget.toURI(); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (location.equals(bundles[i].getLocation())) diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/simpleConfiguratorTest/3.4.bundles.info b/bundles/org.eclipse.equinox.p2.tests/testData/simpleConfiguratorTest/3.4.bundles.info new file mode 100644 index 000000000..d3497f344 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/simpleConfiguratorTest/3.4.bundles.info @@ -0,0 +1,2 @@ +a,1.0.0,file:plugins\a_1.0.0.jar,4,false +b,1.0.0,file:plugins\b_1.0.0.jar,-1,true diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/LazyManipulator.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/LazyManipulator.java index 6f62a4045..d06f005b2 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/LazyManipulator.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/LazyManipulator.java @@ -57,8 +57,8 @@ public class LazyManipulator implements Manipulator { LogHelper.log(Util.createError(Messages.error_loading_manipulator, e)); } //TODO These values should be inserted by a configuration unit (bug 204124) - manipulator.getConfigData().setFwDependentProp("eclipse.p2.profile", profile.getProfileId()); //$NON-NLS-1$ - manipulator.getConfigData().setFwDependentProp("eclipse.p2.data.area", Util.computeRelativeAgentLocation(profile)); //$NON-NLS-1$ + manipulator.getConfigData().setProperty("eclipse.p2.profile", profile.getProfileId()); //$NON-NLS-1$ + manipulator.getConfigData().setProperty("eclipse.p2.data.area", Util.computeRelativeAgentLocation(profile)); //$NON-NLS-1$ } public static FrameworkAdmin getFrameworkAdmin() { diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java index a49567754..0336efd29 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java @@ -44,8 +44,8 @@ public class PlatformConfigurationWrapper { if (bis[i].getSymbolicName().equals(searchFor)) { if (bis[i].getLocation() != null) { try { - if (bis[i].getLocation().startsWith("file:")) //$NON-NLS-1$ - return fromOSGiJarToOSGiInstallArea(bis[i].getLocation().substring(5)).toURL(); + if (bis[i].getLocation().getScheme().equals("file")) //$NON-NLS-1$ + return fromOSGiJarToOSGiInstallArea(bis[i].getLocation().getPath()).toURL(); } catch (MalformedURLException e) { //do nothing } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/SourceManipulator.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/SourceManipulator.java index e3c677c14..deffa0a76 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/SourceManipulator.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/SourceManipulator.java @@ -11,21 +11,22 @@ package org.eclipse.equinox.internal.p2.touchpoint.eclipse; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; import org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorImpl; import org.osgi.framework.Version; -//This class deals with source bundles and how their addition to the sourcerce.info +//This class deals with source bundles and how their addition to the source.info public class SourceManipulator { private List sourceBundles; private IProfile profile; boolean changed = false; + private SimpleConfiguratorManipulatorImpl manipulator; public SourceManipulator(IProfile profile) { this.profile = profile; + this.manipulator = new SimpleConfiguratorManipulatorImpl(); } public BundleInfo[] getBundles() throws IOException { @@ -34,16 +35,10 @@ public class SourceManipulator { return (BundleInfo[]) sourceBundles.toArray(new BundleInfo[sourceBundles.size()]); } - public void addBundle(File bundleFile) throws IOException { - if (sourceBundles == null) - load(); - sourceBundles.add(new BundleInfo(bundleFile.toURL().toString())); - } - public void addBundle(File bundleFile, String bundleId, Version bundleVersion) throws IOException { if (sourceBundles == null) load(); - BundleInfo sourceInfo = new BundleInfo(bundleFile.toURL().toString()); + BundleInfo sourceInfo = new BundleInfo(bundleFile.toURI()); sourceInfo.setSymbolicName(bundleId); sourceInfo.setVersion(bundleVersion.toString()); sourceBundles.add(sourceInfo); @@ -55,7 +50,7 @@ public class SourceManipulator { BundleInfo sourceInfo = new BundleInfo(); if (bundleFile != null) - sourceInfo.setLocation(bundleFile.toURL().toString()); + sourceInfo.setLocation(bundleFile.toURI()); sourceInfo.setSymbolicName(bundleId); sourceInfo.setVersion(bundleVersion.toString()); sourceBundles.remove(sourceInfo); @@ -63,12 +58,12 @@ public class SourceManipulator { public void save() throws IOException { if (sourceBundles != null) - SimpleConfiguratorManipulatorImpl.saveConfiguration(sourceBundles, getFileLocation(), getLauncherLocation(), false); + manipulator.saveConfiguration((BundleInfo[]) sourceBundles.toArray(new BundleInfo[sourceBundles.size()]), getFileLocation(), getLauncherLocation()); } private void load() throws MalformedURLException, IOException { if (getFileLocation().exists()) - sourceBundles = SimpleConfiguratorManipulatorImpl.readConfiguration(getFileLocation().toURL(), getLauncherLocation()); + sourceBundles = new ArrayList(Arrays.asList(manipulator.loadConfiguration(getFileLocation().toURL(), getLauncherLocation()))); else sourceBundles = new ArrayList(); } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java index 789542c54..fdcfde41d 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java @@ -162,12 +162,7 @@ public class Util { public static BundleInfo createBundleInfo(File bundleFile, String manifest) { BundleInfo bundleInfo = new BundleInfo(); - try { - if (bundleFile != null) - bundleInfo.setLocation(bundleFile.toURL().toExternalForm()); - } catch (MalformedURLException e) { - //Ignore since we are creating the URL from the file - } + bundleInfo.setLocation(bundleFile.toURI()); bundleInfo.setManifest(manifest); try { diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkDependentPropertyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkDependentPropertyAction.java index 904650740..9531cf32e 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkDependentPropertyAction.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkDependentPropertyAction.java @@ -26,8 +26,8 @@ public class SetFrameworkDependentPropertyAction extends ProvisioningAction { if (propName == null) return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID)); String propValue = (String) parameters.get(ActionConstants.PARM_PROP_VALUE); - getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, manipulator.getConfigData().getFwDependentProp(propName)); - manipulator.getConfigData().setFwDependentProp(propName, propValue); + getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, manipulator.getConfigData().getProperty(propName)); + manipulator.getConfigData().setProperty(propName, propValue); return Status.OK_STATUS; } @@ -37,7 +37,7 @@ public class SetFrameworkDependentPropertyAction extends ProvisioningAction { if (propName == null) return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID)); String previousValue = (String) getMemento().get(ActionConstants.PARM_PREVIOUS_VALUE); - manipulator.getConfigData().setFwDependentProp(propName, previousValue); + manipulator.getConfigData().setProperty(propName, previousValue); return Status.OK_STATUS; } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkIndependentPropertyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkIndependentPropertyAction.java index d69624c97..d69c027c0 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkIndependentPropertyAction.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetFrameworkIndependentPropertyAction.java @@ -26,8 +26,8 @@ public class SetFrameworkIndependentPropertyAction extends ProvisioningAction { if (propName == null) return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID)); String propValue = (String) parameters.get(ActionConstants.PARM_PROP_VALUE); - getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, manipulator.getConfigData().getFwDependentProp(propName)); - manipulator.getConfigData().setFwIndependentProp(propName, propValue); + getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, manipulator.getConfigData().getProperty(propName)); + manipulator.getConfigData().setProperty(propName, propValue); return Status.OK_STATUS; } @@ -37,7 +37,7 @@ public class SetFrameworkIndependentPropertyAction extends ProvisioningAction { if (propName == null) return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID)); String previousValue = (String) getMemento().get(ActionConstants.PARM_PREVIOUS_VALUE); - manipulator.getConfigData().setFwIndependentProp(propName, previousValue); + manipulator.getConfigData().setProperty(propName, previousValue); return Status.OK_STATUS; } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetProgramPropertyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetProgramPropertyAction.java index f3bd95f26..49dce7299 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetProgramPropertyAction.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/SetProgramPropertyAction.java @@ -26,8 +26,8 @@ public class SetProgramPropertyAction extends ProvisioningAction { if (propName == null) return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID)); String propValue = (String) parameters.get(ActionConstants.PARM_PROP_VALUE); - getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, manipulator.getConfigData().getFwDependentProp(propName)); - manipulator.getConfigData().setFwDependentProp(propName, propValue); + getMemento().put(ActionConstants.PARM_PREVIOUS_VALUE, manipulator.getConfigData().getProperty(propName)); + manipulator.getConfigData().setProperty(propName, propValue); return Status.OK_STATUS; } @@ -37,7 +37,7 @@ public class SetProgramPropertyAction extends ProvisioningAction { if (propName == null) return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_PROP_NAME, ID)); String previousValue = (String) getMemento().get(ActionConstants.PARM_PREVIOUS_VALUE); - manipulator.getConfigData().setFwDependentProp(propName, previousValue); + manipulator.getConfigData().setProperty(propName, previousValue); return Status.OK_STATUS; } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.classpath b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.classpath index ce0c7a5d4..6f3b481ac 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.classpath +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.settings/org.eclipse.jdt.core.prefs index ffb4d45dd..c1430320d 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ -#Wed Jan 23 10:00:33 EST 2008 +#Fri Nov 14 17:13:48 EST 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 +org.eclipse.jdt.core.compiler.compliance=1.4 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -81,7 +81,6 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/META-INF/MANIFEST.MF index 7b8991e3f..556894876 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/META-INF/MANIFEST.MF @@ -10,12 +10,14 @@ Import-Package: org.eclipse.equinox.internal.frameworkadmin.equinox, org.eclipse.equinox.internal.frameworkadmin.utils, org.eclipse.equinox.internal.provisional.configuratormanipulator, org.eclipse.equinox.internal.provisional.frameworkadmin, + org.eclipse.equinox.internal.simpleconfigurator.utils, org.osgi.framework;version="1.3.0", org.osgi.service.packageadmin;version="1.2.0", org.osgi.service.startlevel;version="1.0.0", org.osgi.util.tracker Bundle-Vendor: %providerName -Export-Package: org.eclipse.equinox.internal.simpleconfigurator.manipulator;x-friends:="org.eclipse.equinox.p2.touchpoint.eclipse" -Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, +Export-Package: org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator;x-internal:=true, + org.eclipse.equinox.internal.simpleconfigurator.manipulator;x-friends:="org.eclipse.equinox.p2.touchpoint.eclipse" +Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, J2SE-1.4 Require-Bundle: org.eclipse.equinox.common;bundle-version="3.4.0" diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/provisional/simpleconfigurator/manipulator/SimpleConfiguratorManipulator.java b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/provisional/simpleconfigurator/manipulator/SimpleConfiguratorManipulator.java new file mode 100644 index 000000000..2a990d947 --- /dev/null +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/provisional/simpleconfigurator/manipulator/SimpleConfiguratorManipulator.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator; +import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo; + +public interface SimpleConfiguratorManipulator extends ConfiguratorManipulator { + /** + * An instance of an ISimpleConfiguratorManipulator is registered as a ConfiguratorManipulator + * service with ConfiguratorManipulator.SERVICE_PROP_KEY_CONFIGURATOR_BUNDLESYMBOLICNAME = + * SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME. + */ + public static final String SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME = "org.eclipse.equinox.simpleconfigurator"; + + /** + * + * @param url + * @param launcherLocation + * @return + * @throws IOException + */ + public BundleInfo[] loadConfiguration(URL url, File launcherLocation) throws IOException; + + /** + * + * @param bundleConfiguration + * @param outputFile + * @param base + * @throws IOException + */ + public void saveConfiguration(BundleInfo[] configuration, File outputFile, File base) throws IOException; +} diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/Activator.java b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/Activator.java index d88b93740..099d36247 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/Activator.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/Activator.java @@ -11,6 +11,7 @@ package org.eclipse.equinox.internal.simpleconfigurator.manipulator; import java.util.Dictionary; import java.util.Hashtable; import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator; +import org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator.SimpleConfiguratorManipulator; import org.osgi.framework.*; public class Activator implements BundleActivator { @@ -27,7 +28,8 @@ public class Activator implements BundleActivator { props.put(ConfiguratorManipulator.SERVICE_PROP_KEY_CONFIGURATOR_BUNDLESYMBOLICNAME, SimpleConfiguratorManipulatorImpl.SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME); props.put(Constants.SERVICE_VENDOR, "Eclipse.org"); //$NON-NLS-1$ SimpleConfiguratorManipulatorImpl manipulator = new SimpleConfiguratorManipulatorImpl(); - registration = context.registerService(ConfiguratorManipulator.class.getName(), manipulator, props); + String[] clazzes = new String[] {ConfiguratorManipulator.class.getName(), SimpleConfiguratorManipulator.class.getName()}; + registration = context.registerService(clazzes, manipulator, props); } public void start(BundleContext bundleContext) throws Exception { diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java index 0173d898a..73dd84383 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorImpl.java @@ -8,54 +8,48 @@ *******************************************************************************/ package org.eclipse.equinox.internal.simpleconfigurator.manipulator; -import java.io.*; -import java.net.MalformedURLException; +import java.io.File; +import java.io.IOException; +import java.net.URI; import java.net.URL; import java.util.*; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxFwConfigFileParser; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils; import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; -import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator.SimpleConfiguratorManipulator; +import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; import org.osgi.framework.Constants; /** * */ -public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulator { +public class SimpleConfiguratorManipulatorImpl implements SimpleConfiguratorManipulator { class LocationInfo { - String[] prerequisiteLocations = null; - String systemBundleLocation = null; - String[] systemFragmentedBundleLocations = null; + URI[] prerequisiteLocations = null; + URI systemBundleLocation = null; + URI[] systemFragmentedBundleLocations = null; } private final static boolean DEBUG = false; - static String CONFIG_LOCATION = SimpleConfiguratorManipulatorImpl.CONFIG_LIST; - private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$ - private static final String COMMA = ","; //$NON-NLS-1$ - private static final BundleInfo[] NULL_BUNDLEINFOS = new BundleInfo[0]; - private Set manipulators = new HashSet(); - - public static final String PARAMETER_BASEURL = "org.eclipse.equinox.simpleconfigurator.baseUrl"; //$NON-NLS-1$ public static final String PROP_KEY_EXCLUSIVE_INSTALLATION = "org.eclipse.equinox.simpleconfigurator.exclusiveInstallation"; //$NON-NLS-1$ public static final String CONFIG_LIST = "bundles.info"; //$NON-NLS-1$ public static final String CONFIGURATOR_FOLDER = "org.eclipse.equinox.simpleconfigurator"; //$NON-NLS-1$ public static final String PROP_KEY_CONFIGURL = "org.eclipse.equinox.simpleconfigurator.configUrl"; //$NON-NLS-1$ - public static final String TARGET_CONFIGURATOR_NAME = "org.eclipse.equinox.simpleconfigurator"; //$NON-NLS-1$ - public static final String SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME = TARGET_CONFIGURATOR_NAME; + + private Set manipulators = new HashSet(); /** - * Return the ConfiguratorConfigLocation which is determined + * Return the ConfiguratorConfigFile which is determined * by the parameters set in Manipulator. * * @param manipulator - * @return URL + * @return File */ - private static URL getConfigLocation(Manipulator manipulator) throws IllegalStateException { + private static File getConfigFile(Manipulator manipulator) throws IllegalStateException { File fwConfigLoc = manipulator.getLauncherData().getFwConfigLocation(); File baseDir = null; if (fwConfigLoc == null) { @@ -81,26 +75,14 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato baseDir = fwConfigLoc; } } - try { - baseDir = new File(baseDir, SimpleConfiguratorManipulatorImpl.CONFIGURATOR_FOLDER); - File targetFile = new File(baseDir, SimpleConfiguratorManipulatorImpl.CONFIG_LIST); - try { - Utils.createParentDir(targetFile); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; - } - return targetFile.toURL(); - } catch (MalformedURLException e) { - // Never happen. ignore. - e.printStackTrace(); + File configuratorFolder = new File(baseDir, SimpleConfiguratorManipulatorImpl.CONFIGURATOR_FOLDER); + File targetFile = new File(configuratorFolder, SimpleConfiguratorManipulatorImpl.CONFIG_LIST); + if (!Utils.createParentDir(targetFile)) return null; - } - + return targetFile; } - static boolean isPrerequisiteBundles(String location, LocationInfo info) { + static boolean isPrerequisiteBundles(URI location, LocationInfo info) { boolean ret = false; if (info.prerequisiteLocations == null) @@ -114,7 +96,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato return ret; } - static boolean isSystemBundle(String location, LocationInfo info) { + static boolean isSystemBundle(URI location, LocationInfo info) { if (info.systemBundleLocation == null) return false; if (location.equals(info.systemBundleLocation)) @@ -122,7 +104,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato return false; } - static boolean isSystemFragmentBundle(String location, LocationInfo info) { + static boolean isSystemFragmentBundle(URI location, LocationInfo info) { boolean ret = false; if (info.systemFragmentedBundleLocations == null) return false; @@ -144,7 +126,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato return false; } - private static boolean isTargetConfiguratorBundle(String location) { + private static boolean isTargetConfiguratorBundle(URI location) { final String symbolic = Utils.getPathFromClause(Utils.getManifestMainAttributes(location, Constants.BUNDLE_SYMBOLICNAME)); return (SimpleConfiguratorManipulatorImpl.SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME.equals(symbolic)); } @@ -307,99 +289,47 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato } } - private BundleInfo[] loadConfiguration(URL url, File launcherLocation) throws IOException { + public BundleInfo[] loadConfiguration(URL url, File base) throws IOException { if (url == null) return NULL_BUNDLEINFOS; - List bundleInfoList = readConfiguration(url, launcherLocation); - return Utils.getBundleInfosFromList(bundleInfoList); - } - - /** - * This method is copied from SimpleConfiguratorUtils class. - */ - public static List readConfiguration(URL url, File base) throws IOException { - List bundles = new ArrayList(); - BufferedReader r = null; - try { - r = new BufferedReader(new InputStreamReader(url.openStream())); - } catch (IOException e) { - //exception opening stream - return bundles; - } + List simpleBundles = SimpleConfiguratorUtils.readConfiguration(url, base.toURI()); - // System.out.println("readConfiguration(URL url):url()=" + url); - String line; - try { - URL baseUrl = new URL(url, "./"); //$NON-NLS-1$ - while ((line = r.readLine()) != null) { - if (line.startsWith("#")) //$NON-NLS-1$ - continue; - line = line.trim();// symbolicName,version,location,startlevel,expectedState - if (line.length() == 0) - continue; - - // (expectedState is an integer). - //System.out.println("line=" + line); - if (line.startsWith(SimpleConfiguratorManipulatorImpl.PARAMETER_BASEURL + "=")) { //$NON-NLS-1$ - String baseUrlSt = line.substring((SimpleConfiguratorManipulatorImpl.PARAMETER_BASEURL + "=").length()); //$NON-NLS-1$ - if (!baseUrlSt.endsWith("/")) //$NON-NLS-1$ - baseUrlSt += "/"; //$NON-NLS-1$ - baseUrl = new URL(url, baseUrlSt); - continue; - } - StringTokenizer tok = new StringTokenizer(line, COMMA, true); - String symbolicName = tok.nextToken(); - if (symbolicName.equals(COMMA)) - symbolicName = null; - else - tok.nextToken(); // , + // convert to FrameworkAdmin BundleInfo Type + BundleInfo[] result = new BundleInfo[simpleBundles.size()]; + int i = 0; + for (Iterator iterator = simpleBundles.iterator(); iterator.hasNext();) { + org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo simpleInfo = (org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo) iterator.next(); + URI location = simpleInfo.getLocation(); + if (!location.isAbsolute() && simpleInfo.getBaseLocation() != null) + location = URIUtil.makeAbsolute(location, simpleInfo.getBaseLocation()); - String version = tok.nextToken(); - if (version.equals(COMMA)) - version = null; - else - tok.nextToken(); // , - - String urlSt = tok.nextToken(); - if (urlSt.equals(COMMA)) { - if (symbolicName != null && version != null) - urlSt = symbolicName + "_" + version + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ - else - urlSt = null; - } else - tok.nextToken(); // , - try { - new URL(urlSt); - // if (DEBUG) - // System.out.println("1 urlSt=" + urlSt); - } catch (MalformedURLException e) { - urlSt = Utils.getUrlInFull(urlSt, baseUrl).toExternalForm(); - // if (DEBUG) - // System.out.println("2 urlSt=" + urlSt); - } + BundleInfo bundleInfo = new BundleInfo(simpleInfo.getSymbolicName(), simpleInfo.getVersion(), location, simpleInfo.getStartLevel(), simpleInfo.isMarkedAsStarted()); + result[i++] = bundleInfo; + } + return result; + } - int sl = Integer.parseInt(tok.nextToken().trim()); - tok.nextToken(); // , - boolean markedAsStarted = Boolean.valueOf(tok.nextToken()).booleanValue(); + public void saveConfiguration(BundleInfo[] configuration, File outputFile, File base) throws IOException { + saveConfiguration(configuration, outputFile, base, false); + } - urlSt = makeAbsolute(urlSt, base != null ? base.toURL() : null); - BundleInfo bInfo = new BundleInfo(symbolicName, version, urlSt, sl, markedAsStarted); - bundles.add(bInfo); - // System.out.println("tail line=" + line); - } - } catch (IOException e) { - e.printStackTrace(); - // TODO log something - // bundleInfos = NULL_BUNDLEINFOS; - } finally { - try { - r.close(); - } catch (IOException ex) { - // ignore + private void saveConfiguration(BundleInfo[] configuration, File outputFile, File base, boolean backup) throws IOException { + if (backup && outputFile.exists()) { + File backupFile = Utils.getSimpleDataFormattedFile(outputFile); + if (!outputFile.renameTo(backupFile)) { + throw new IOException("Fail to rename from (" + outputFile + ") to (" + backupFile + ")"); } } - return bundles; + + // convert to SimpleConfigurator BundleInfo Type + org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[configuration.length]; + for (int i = 0; i < configuration.length; i++) { + BundleInfo bundleInfo = (BundleInfo) configuration[i]; + URI location = URIUtil.makeRelative(bundleInfo.getLocation(), base != null ? base.toURI() : null); + simpleInfos[i] = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo(bundleInfo.getSymbolicName(), bundleInfo.getVersion(), location, bundleInfo.getStartLevel(), bundleInfo.isMarkedAsStarted()); + } + SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, outputFile); } public BundleInfo[] save(Manipulator manipulator, boolean backup) throws IOException { @@ -407,175 +337,13 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato List setToSimpleConfig = new LinkedList(); ConfigData configData = manipulator.getConfigData(); - //try { if (!divideBundleInfos(manipulator, setToInitialConfig, setToSimpleConfig, configData.getInitialBundleStartLevel())) return configData.getBundles(); - //} catch (Exception e) { - // e.printStackTrace(); - // System.exit(-1); - //} - // if (DEBUG) { - // System.out.println("setToInitialConfig=\n" + SimpleConfiguratorUtils.getListSt(setToInitialConfig)); - // System.out.println("setToSimpleConfig=\n" + SimpleConfiguratorUtils.getListSt(setToSimpleConfig)); - // } - URL configuratorConfigUrl = getConfigLocation(manipulator); - if (!configuratorConfigUrl.getProtocol().equals("file")) //$NON-NLS-1$ - new IllegalStateException("configuratorConfigUrl should start with \"file\".\nconfiguratorConfigUrl=" + configuratorConfigUrl); - File outputFile = new File(configuratorConfigUrl.getFile()); - saveConfiguration(setToSimpleConfig, outputFile, EquinoxFwConfigFileParser.getOSGiInstallArea(manipulator.getLauncherData()), backup); - configData.setFwIndependentProp(SimpleConfiguratorManipulatorImpl.PROP_KEY_CONFIGURL, outputFile.toURL().toExternalForm()); - return orderingInitialConfig(setToInitialConfig); - } - - public static void saveConfiguration(List bundleInfoList, File outputFile, File base, boolean backup) throws IOException { - if (DEBUG) { - System.out.println("saveConfiguration(List bundleInfoList, File outputFile, boolean backup): outFile=" + outputFile.getAbsolutePath()); //$NON-NLS-1$ - } - BufferedWriter bw; - if (backup) - if (outputFile.exists()) { - File dest = Utils.getSimpleDataFormattedFile(outputFile); - if (!outputFile.renameTo(dest)) { - throw new IOException("Fail to rename from (" + outputFile + ") to (" + dest + ")"); - } - } - - Collections.sort(bundleInfoList, new Comparator() { - public int compare(Object o1, Object o2) { - if (o1 instanceof BundleInfo && o2 instanceof BundleInfo) { - return ((BundleInfo) o1).getSymbolicName().compareTo(((BundleInfo) o2).getSymbolicName()); - } - return 0; - } - }); - - if (bundleInfoList.size() > 0) { - Utils.createParentDir(outputFile); - bw = new BufferedWriter(new FileWriter(outputFile)); - - for (Iterator ite = bundleInfoList.iterator(); ite.hasNext();) { - BundleInfo bInfo = (BundleInfo) ite.next(); - String location = bInfo.getLocation(); - - if (bInfo.getSymbolicName() == null) - bw.write(COMMA); - else - bw.write(bInfo.getSymbolicName() + COMMA); - if (bInfo.getVersion() == null) - bw.write(COMMA); - else - bw.write(bInfo.getVersion() + COMMA); - - location = makeRelative(location, base != null ? base.toURL() : null); - bw.write(location + COMMA); - bw.write(bInfo.getStartLevel() + COMMA + bInfo.isMarkedAsStarted()); - bw.newLine(); - } - bw.flush(); - bw.close(); - } else { - if (outputFile.exists()) { - outputFile.delete(); - } - File parentDir = outputFile.getParentFile(); - if (parentDir.exists()) { - parentDir.delete(); - } - } - - } - - private static String makeRelative(IPath toRel, IPath base) { - String relDevice = toRel.getDevice(); - String baseDevice = base.getDevice(); - //if the devices are different, we cannot make one relative to the other - if (relDevice != baseDevice && (relDevice == null || !relDevice.equalsIgnoreCase(baseDevice))) - return toRel.toOSString(); - int i = base.matchingFirstSegments(toRel); - if (i == 0) { - return toRel.toOSString(); - } - String result = ""; //$NON-NLS-1$ - for (int j = 0; j < (base.segmentCount() - i); j++) { - result += ".." + IPath.SEPARATOR; //$NON-NLS-1$ - } - if (i == toRel.segmentCount()) - return "."; //$NON-NLS-1$ - result += toRel.setDevice(null).removeFirstSegments(i).toOSString(); - return result; - } - public static String makeRelative(String urlString, URL rootURL) { - // we only traffic in file: URLs - int index = urlString.indexOf(FILE_PROTOCOL); - if (index == -1) - return urlString; - index = index + 5; - - // ensure we have an absolute path to start with - boolean done = false; - URL url = null; - String file = urlString; - while (!done) { - try { - url = new URL(file); - file = url.getFile(); - } catch (java.net.MalformedURLException e) { - done = true; - } - } - if (url == null || !new File(url.getFile()).isAbsolute()) - return urlString; - - String rootString = rootURL.toExternalForm(); - IPath one = new Path(urlString.substring(index)); - IPath two = new Path(rootString.substring(rootString.indexOf(FILE_PROTOCOL) + 5)); - String deviceOne = one.getDevice(); - String deviceTwo = two.getDevice(); - // do checking here because we want to return the exact string we got initially if - // we are unable to make it relative. - if (deviceOne != deviceTwo && (deviceOne == null || !deviceOne.equalsIgnoreCase(two.getDevice()))) - return urlString; - - return urlString.substring(0, index) + makeRelative(one, two); - } - - public static String makeAbsolute(String original, String rootPath) { - IPath path = new Path(original); - // ensure we have a relative path to start with - if (path.isAbsolute()) - return original; - IPath root = new Path(rootPath); - return root.addTrailingSeparator().append(original.replace(':', '}')).toOSString().replace('}', ':'); - } - - /* - * Make the given path absolute to the specified root, if applicable. If not, then - * return the path as-is. - */ - public static String makeAbsolute(String urlString, URL rootURL) { - // we only traffic in file: URLs - int index = urlString.indexOf(FILE_PROTOCOL); - if (index == -1) - return urlString; - index = index + 5; - - // ensure we have a relative path to start with - boolean done = false; - URL url = null; - String file = urlString; - while (!done) { - try { - url = new URL(file); - file = url.getFile(); - } catch (java.net.MalformedURLException e) { - done = true; - } - } - if (url == null || new File(url.getFile()).isAbsolute()) - return urlString; - - return urlString.substring(0, index - 5) + makeAbsolute(urlString.substring(index), rootURL.toExternalForm()); + File outputFile = getConfigFile(manipulator); + saveConfiguration((BundleInfo[]) setToSimpleConfig.toArray(new BundleInfo[setToSimpleConfig.size()]), outputFile, ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getLauncherData()), backup); + configData.setProperty(SimpleConfiguratorManipulatorImpl.PROP_KEY_CONFIGURL, outputFile.toURL().toExternalForm()); + return orderingInitialConfig(setToInitialConfig); } void setPrerequisiteBundles(BundleInfo configuratorBundleInfo, BundlesState state, LocationInfo info) { @@ -585,7 +353,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato return; } BundleInfo[] prerequisites = state.getPrerequisteBundles(configuratorBundleInfo); - info.prerequisiteLocations = new String[prerequisites.length]; + info.prerequisiteLocations = new URI[prerequisites.length]; for (int i = 0; i < prerequisites.length; i++) info.prerequisiteLocations[i] = prerequisites[i].getLocation(); return; @@ -606,7 +374,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato } info.systemBundleLocation = systemBundleInfo.getLocation(); BundleInfo[] fragments = state.getSystemFragmentedBundles(); - info.systemFragmentedBundleLocations = new String[fragments.length]; + info.systemFragmentedBundleLocations = new URI[fragments.length]; for (int i = 0; i < fragments.length; i++) info.systemFragmentedBundleLocations[i] = fragments[i].getLocation(); } @@ -627,7 +395,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato return; Properties properties = new Properties(); String[] jvmArgs = manipulator.getLauncherData().getJvmArgs(); - for (int i = 0; i < jvmArgs.length; i++) + for (int i = 0; i < jvmArgs.length; i++) { if (jvmArgs[i].startsWith("-D")) { //$NON-NLS-1$ int index = jvmArgs[i].indexOf("="); //$NON-NLS-1$ if (index > 0 && jvmArgs[i].length() > 2) { @@ -636,12 +404,13 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato properties.setProperty(key, value); } } + } - Utils.appendProperties(properties, manipulator.getConfigData().getFwIndependentProps()); + Utils.appendProperties(properties, manipulator.getConfigData().getProperties()); boolean exclusiveInstallation = Boolean.valueOf(properties.getProperty(SimpleConfiguratorManipulatorImpl.PROP_KEY_EXCLUSIVE_INSTALLATION)).booleanValue(); - URL configuratorConfigUrl = getConfigLocation(manipulator); + File configFile = getConfigFile(manipulator); - BundleInfo[] toInstall = this.loadConfiguration(configuratorConfigUrl, EquinoxFwConfigFileParser.getOSGiInstallArea(manipulator.getLauncherData())); + BundleInfo[] toInstall = loadConfiguration(configFile.toURL(), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getLauncherData())); List toUninstall = new LinkedList(); if (exclusiveInstallation) @@ -674,7 +443,7 @@ public class SimpleConfiguratorManipulatorImpl implements ConfiguratorManipulato } public void cleanup(Manipulator manipulator) { - File outputFile = new File(getConfigLocation(manipulator).getFile()); + File outputFile = getConfigFile(manipulator); outputFile.delete(); if (outputFile.getParentFile().isDirectory()) diff --git a/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtils.java b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtils.java new file mode 100644 index 000000000..183a5aaa1 --- /dev/null +++ b/bundles/org.eclipse.equinox.simpleconfigurator.manipulator/src/org/eclipse/equinox/internal/simpleconfigurator/manipulator/SimpleConfiguratorManipulatorUtils.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.simpleconfigurator.manipulator; + +import java.io.*; +import java.net.URI; +import java.util.Arrays; +import java.util.Comparator; +import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; +import org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo; + +public class SimpleConfiguratorManipulatorUtils { + + public static void writeConfiguration(BundleInfo[] simpleInfos, File outputFile) throws IOException { + + // if empty remove the configuration file + if (simpleInfos == null || simpleInfos.length == 0) { + if (outputFile.exists()) { + outputFile.delete(); + } + File parentDir = outputFile.getParentFile(); + if (parentDir.exists()) { + parentDir.delete(); + } + return; + } + + // sort by symbolic name + Arrays.sort(simpleInfos, new Comparator() { + public int compare(Object o1, Object o2) { + if (o1 instanceof BundleInfo && o2 instanceof BundleInfo) { + return ((BundleInfo) o1).getSymbolicName().compareTo(((BundleInfo) o2).getSymbolicName()); + } + return 0; + } + }); + + Utils.createParentDir(outputFile); + BufferedWriter writer = null; + IOException caughtException = null; + try { + writer = new BufferedWriter(new FileWriter(outputFile)); + for (int i = 0; i < simpleInfos.length; i++) { + writer.write(createBundleInfoLine(simpleInfos[i])); + writer.newLine(); + } + } catch (IOException e) { + caughtException = e; + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + // we want to avoid over-writing the original exception + if (caughtException != null) + caughtException = e; + } + } + } + if (caughtException != null) + throw caughtException; + } + + public static String createBundleInfoLine(BundleInfo bundleInfo) throws IOException { + // symbolicName,version,location,startLevel,markedAsStarted + StringBuffer buffer = new StringBuffer(); + buffer.append(bundleInfo.getSymbolicName()); + buffer.append(','); + buffer.append(bundleInfo.getVersion()); + buffer.append(','); + buffer.append(createBundleLocation(bundleInfo.getLocation())); + buffer.append(','); + buffer.append(bundleInfo.getStartLevel()); + buffer.append(','); + buffer.append(bundleInfo.isMarkedAsStarted()); + return buffer.toString(); + } + + public static String createBundleLocation(URI location) { + String result = location.toString(); + int commaIndex = result.indexOf(','); + while (commaIndex != -1) { + result = result.substring(0, commaIndex) + "%2C" + result.substring(commaIndex + 1); + commaIndex = result.indexOf(','); + } + return result; + } + +} diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.simpleconfigurator/META-INF/MANIFEST.MF index 4911ea0a1..9021d49b4 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.simpleconfigurator/META-INF/MANIFEST.MF @@ -17,6 +17,6 @@ Import-Package: org.eclipse.osgi.framework.console;version="1.0.0";resolution:=o Export-Package: org.eclipse.equinox.internal.provisional.configurator;x-friends:="org.eclipse.equinox.p2.reconciler.dropins,org.eclipse.equinox.p2.console,org.eclipse.equinox.p2.ui", org.eclipse.equinox.internal.simpleconfigurator;x-internal:=true, org.eclipse.equinox.internal.simpleconfigurator.console;x-internal:=true, - org.eclipse.equinox.internal.simpleconfigurator.utils;x-internal:=true + org.eclipse.equinox.internal.simpleconfigurator.utils;x-friends:="org.eclipse.equinox.simpleconfigurator.manipulator" Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, J2SE-1.4 diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java index beaa3fa80..e73f0e63a 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java @@ -9,6 +9,7 @@ package org.eclipse.equinox.internal.simpleconfigurator; import java.io.*; +import java.net.URI; import java.net.URL; import java.util.*; import org.eclipse.equinox.internal.simpleconfigurator.utils.*; @@ -17,7 +18,7 @@ import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.service.startlevel.StartLevel; class ConfigApplier { - private static final String LAST_BUNDLES_TXT = "last.bundles.info"; //$NON-NLS-1$ + private static final String LAST_BUNDLES_INFO = "last.bundles.info"; //$NON-NLS-1$ private static final String PROP_DEVMODE = "osgi.dev"; //$NON-NLS-1$ private final BundleContext manipulatingContext; @@ -27,18 +28,18 @@ class ConfigApplier { private final boolean inDevMode; private final Bundle callingBundle; + private final URI baseLocation; ConfigApplier(BundleContext context, Bundle callingBundle) { manipulatingContext = context; this.callingBundle = callingBundle; - //String vendor = context.getProperty(Constants.FRAMEWORK_VENDOR); - //System.out.println("vendor=" + vendor); runningOnEquinox = "Eclipse".equals(context.getProperty(Constants.FRAMEWORK_VENDOR)); //$NON-NLS-1$ inDevMode = manipulatingContext.getProperty(PROP_DEVMODE) != null; + baseLocation = runningOnEquinox ? EquinoxUtils.getInstallLocationURI(context) : null; + ServiceReference packageAdminRef = manipulatingContext.getServiceReference(PackageAdmin.class.getName()); if (packageAdminRef == null) throw new IllegalStateException("No PackageAdmin service is available."); //$NON-NLS-1$ - packageAdminService = (PackageAdmin) manipulatingContext.getService(packageAdminRef); ServiceReference startLevelRef = manipulatingContext.getServiceReference(StartLevel.class.getName()); @@ -47,7 +48,15 @@ class ConfigApplier { startLevelService = (StartLevel) manipulatingContext.getService(startLevelRef); } - void install(BundleInfo[] expectedState, URL url, boolean exclusiveMode) { + void install(URL url, boolean exclusiveMode) throws IOException { + List bundleInfoList = SimpleConfiguratorUtils.readConfiguration(url, baseLocation); + if (Activator.DEBUG) + System.out.println("applyConfiguration() bundleInfoList.size()=" + bundleInfoList.size()); + if (bundleInfoList.size() == 0) + return; + + BundleInfo[] expectedState = Utils.getBundleInfosFromList(bundleInfoList); + HashSet toUninstall = null; if (!exclusiveMode) { BundleInfo[] lastInstalledBundles = getLastState(); @@ -82,13 +91,6 @@ class ConfigApplier { // do nothing; no resolver package available } startBundles((Bundle[]) toStart.toArray(new Bundle[toStart.size()])); - //if time stamps are the same - // do nothing - // return - //if list exists - // force the list in the fwk - //else - // discover bundles in folders and force the list in the fwk } private Collection getResolvedBundles() { @@ -121,7 +123,7 @@ class ConfigApplier { InputStream sourceStream = null; OutputStream destinationStream = null; - File lastBundlesTxt = getLastBundleTxt(); + File lastBundlesTxt = getLastBundleInfo(); try { try { destinationStream = new FileOutputStream(lastBundlesTxt); @@ -138,16 +140,16 @@ class ConfigApplier { } } - private File getLastBundleTxt() { - return manipulatingContext.getDataFile(LAST_BUNDLES_TXT); + private File getLastBundleInfo() { + return manipulatingContext.getDataFile(LAST_BUNDLES_INFO); } private BundleInfo[] getLastState() { - File lastBundlesTxt = getLastBundleTxt(); - if (!lastBundlesTxt.isFile()) + File lastBundlesInfo = getLastBundleInfo(); + if (!lastBundlesInfo.isFile()) return null; try { - return (BundleInfo[]) SimpleConfiguratorUtils.readConfiguration(lastBundlesTxt.toURL()).toArray(new BundleInfo[1]); + return (BundleInfo[]) SimpleConfiguratorUtils.readConfiguration(lastBundlesInfo.toURL(), baseLocation).toArray(new BundleInfo[1]); } catch (IOException e) { return null; } @@ -155,13 +157,9 @@ class ConfigApplier { private ArrayList installBundles(BundleInfo[] finalList, Collection toStart) { ArrayList toRefresh = new ArrayList(); - //printSystemBundle(); - boolean useReference = true; - if (manipulatingContext.getProperty(SimpleConfiguratorConstants.PROP_KEY_USE_REFERENCE) == null) - useReference = true; - else - useReference = Boolean.valueOf(manipulatingContext.getProperty(SimpleConfiguratorConstants.PROP_KEY_USE_REFERENCE)).booleanValue(); + String useReferenceProperty = manipulatingContext.getProperty(SimpleConfiguratorConstants.PROP_KEY_USE_REFERENCE); + boolean useReference = useReferenceProperty == null ? runningOnEquinox : Boolean.valueOf(useReferenceProperty).booleanValue(); for (int i = 0; i < finalList.length; i++) { if (finalList[i] == null) @@ -176,18 +174,15 @@ class ConfigApplier { if (symbolicName != null && version != null) matches = packageAdminService.getBundles(symbolicName, getVersionRange(version)); - String location = finalList[i].getLocation(); - if (location == null) - continue; - if (runningOnEquinox && useReference && location.startsWith("file:")) //$NON-NLS-1$ - location = "reference:" + location; //$NON-NLS-1$ + String bundleLocation = SimpleConfiguratorUtils.getBundleLocation(finalList[i], useReference); + Bundle current = matches == null ? null : (matches.length == 0 ? null : matches[0]); if (current == null) { try { //TODO Need to eliminate System Bundle. // If a system bundle doesn't have a SymbolicName header, like Knopflerfish 4.0.0, // it will be installed unfortunately. - current = manipulatingContext.installBundle(location); + current = manipulatingContext.installBundle(bundleLocation); if (Activator.DEBUG) System.out.println("installed bundle:" + finalList[i]); //$NON-NLS-1$ toRefresh.add(current); @@ -198,7 +193,7 @@ class ConfigApplier { } continue; } - } else if (inDevMode && current.getBundleId() != 0 && current != manipulatingContext.getBundle() && !location.equals(current.getLocation()) && !current.getLocation().startsWith("initial@")) { + } else if (inDevMode && current.getBundleId() != 0 && current != manipulatingContext.getBundle() && !bundleLocation.equals(current.getLocation()) && !current.getLocation().startsWith("initial@")) { // We do not do this for the system bundle (id==0), the manipulating bundle or any bundle installed from the osgi.bundles list (locations starting with "@initial" // The bundle exists; but the location is different. Unintall the current and install the new one (bug 229700) try { @@ -206,13 +201,13 @@ class ConfigApplier { toRefresh.add(current); } catch (BundleException e) { if (Activator.DEBUG) { - System.err.println("Can't uninstalll " + symbolicName + '/' + version + " from location " + current.getLocation()); //$NON-NLS-1$ //$NON-NLS-2$ + System.err.println("Can't uninstall " + symbolicName + '/' + version + " from location " + current.getLocation()); //$NON-NLS-1$ //$NON-NLS-2$ e.printStackTrace(); } continue; } try { - current = manipulatingContext.installBundle(location); + current = manipulatingContext.installBundle(bundleLocation); if (Activator.DEBUG) System.out.println("installed bundle:" + finalList[i]); //$NON-NLS-1$ toRefresh.add(current); diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java index c09e4d774..d94cd8315 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java @@ -12,7 +12,6 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.util.List; import org.eclipse.equinox.internal.provisional.configurator.Configurator; import org.eclipse.equinox.internal.simpleconfigurator.utils.*; import org.osgi.framework.Bundle; @@ -114,14 +113,9 @@ public class SimpleConfiguratorImpl implements Configurator { return; configurationURL = url; - List bundleInfoList = SimpleConfiguratorUtils.readConfiguration(url); - if (Activator.DEBUG) - System.out.println("applyConfiguration() bundleInfoList.size()=" + bundleInfoList.size()); - if (bundleInfoList.size() == 0) - return; if (this.configApplier == null) configApplier = new ConfigApplier(context, bundle); - configApplier.install(Utils.getBundleInfosFromList(bundleInfoList), url, isExclusiveInstallation()); + configApplier.install(url, isExclusiveInstallation()); } } diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/BundleInfo.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/BundleInfo.java index bfefb62ec..30d8f4b9a 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/BundleInfo.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/BundleInfo.java @@ -8,47 +8,31 @@ ******************************************************************************/ package org.eclipse.equinox.internal.simpleconfigurator.utils; -/** +import java.net.URI; + +/* * This object represents information of a bundle. - * */ public class BundleInfo { public static final int NO_LEVEL = -1; private String symbolicName = null; private String version = null; - private String location; + private URI location; + private URI baseLocation; private boolean markedAsStarted = false; private int startLevel = NO_LEVEL; - private boolean resolved = false; - public BundleInfo(String symbolic, String version, String location, int startLevel, boolean started) { + public BundleInfo(String symbolic, String version, URI location, int startLevel, boolean started) { this.symbolicName = symbolic; this.version = version; - this.location = location.trim(); + this.location = location; this.markedAsStarted = started; this.startLevel = startLevel; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object toCompare) { - if (toCompare instanceof BundleInfo) { - BundleInfo info = (BundleInfo) toCompare; - //if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.url == null || url == null ? true : info.url.equals(url))) - if (info.symbolicName != null && info.version != null && symbolicName != null && version != null) { - if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.location == null || location == null ? true : info.location.equals(location))) - return true; - } else { - return (info.location == null || location == null ? false : info.location.equals(location)); - } - } - return false; - } - - public String getLocation() { + public URI getLocation() { return location; } @@ -64,20 +48,18 @@ public class BundleInfo { return version; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int result = symbolicName == null ? 0 : symbolicName.hashCode(); - result = result + (version == null ? 0 : version.hashCode()); - result = result + (location == null ? 0 : location.hashCode()); - return result; - } - public boolean isMarkedAsStarted() { return markedAsStarted; } + public URI getBaseLocation() { + return baseLocation; + } + + public void setBaseLocation(URI baseLocation) { + this.baseLocation = baseLocation; + } + /* (non-Javadoc) * @see java.lang.Object#toString() */ @@ -89,16 +71,58 @@ public class BundleInfo { buffer.append(", "); //$NON-NLS-1$ if (version != null) buffer.append(version); - buffer.append(", "); //$NON-NLS-1$ - buffer.append("location="); //$NON-NLS-1$ + if (baseLocation != null) { + buffer.append(", baseLocation="); //$NON-NLS-1$ + buffer.append(baseLocation); + } + buffer.append(", location="); //$NON-NLS-1$ buffer.append(location); buffer.append(", startLevel="); //$NON-NLS-1$ buffer.append(startLevel); buffer.append(", toBeStarted="); //$NON-NLS-1$ buffer.append(markedAsStarted); - buffer.append(", resolved="); //$NON-NLS-1$ - buffer.append(resolved); buffer.append(')'); return buffer.toString(); } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((symbolicName == null) ? 0 : symbolicName.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + + if (obj == null) + return false; + + if (getClass() != obj.getClass()) + return false; + + BundleInfo other = (BundleInfo) obj; + if (symbolicName == null) { + if (other.symbolicName != null) + return false; + } else if (!symbolicName.equals(other.symbolicName)) + return false; + + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + + if (location == null || other.location == null) + return true; + + //compare absolute location URIs + URI absoluteLocation = baseLocation == null ? location : baseLocation.resolve(location); + URI otherAbsoluteLocation = other.baseLocation == null ? other.location : other.baseLocation.resolve(other.location); + + return URIUtil.sameURI(absoluteLocation, otherAbsoluteLocation); + } } diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/EquinoxUtils.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/EquinoxUtils.java index ad5dc6fa7..d0ae2cc1d 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/EquinoxUtils.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/EquinoxUtils.java @@ -8,7 +8,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.simpleconfigurator.utils; -import java.net.URL; +import java.net.*; import org.eclipse.equinox.internal.simpleconfigurator.console.ConfiguratorCommandProvider; import org.eclipse.osgi.framework.console.CommandProvider; import org.eclipse.osgi.service.datalocation.Location; @@ -47,6 +47,31 @@ public class EquinoxUtils { } } + public static URI getInstallLocationURI(BundleContext context) { + try { + ServiceReference[] references = context.getServiceReferences(Location.class.getName(), Location.INSTALL_FILTER); + if (references != null && references.length > 0) { + ServiceReference reference = references[0]; + Location installLocation = (Location) context.getService(reference); + if (installLocation != null) { + try { + if (installLocation.isSet()) { + URL location = installLocation.getURL(); + return URIUtil.toURI(location); + } + } catch (URISyntaxException e) { + //TODO: log an error + } finally { + context.ungetService(reference); + } + } + } + } catch (InvalidSyntaxException e) { + //TODO: log an error + } + return null; + } + public static ServiceRegistration registerConsoleCommands(BundleContext context) { return context.registerService(CommandProvider.class.getName(), new ConfiguratorCommandProvider(context), null); } diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/SimpleConfiguratorUtils.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/SimpleConfiguratorUtils.java index 6a83fac2d..05682f25b 100644 --- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/SimpleConfiguratorUtils.java +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/SimpleConfiguratorUtils.java @@ -1,98 +1,114 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2007, 2008 IBM Corporation and others. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: IBM Corporation - initial API and implementation ******************************************************************************/ package org.eclipse.equinox.internal.simpleconfigurator.utils; import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; public class SimpleConfiguratorUtils { - public static List readConfiguration(URL url) throws IOException { + private static final String FILE_SCHEME = "file"; + private static final String REFERENCE_PREFIX = "reference:"; + private static final String FILE_PREFIX = "file:"; + private static final String COMMA = ","; + private static final String ENCODED_COMMA = "%2C"; + + public static List readConfiguration(URL url, URI base) throws IOException { List bundles = new ArrayList(); + BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); try { - BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); - String line; + while ((line = r.readLine()) != null) { + line = line.trim(); + //ignore any comment or empty lines + if (line.length() == 0 || line.startsWith("#")) //$NON-NLS-1$ + continue; + + BundleInfo bundleInfo = parseBundleInfoLine(line, base); + if (bundleInfo != null) + bundles.add(bundleInfo); + } + } finally { try { - URL baseUrl = new URL(url, "./"); //$NON-NLS-1$ - while ((line = r.readLine()) != null) { - if (line.startsWith("#")) //$NON-NLS-1$ - continue; - line = line.trim();// symbolicName,version,location,startlevel,expectedState - if (line.length() == 0) - continue; - - // (expectedState is an integer). - if (line.startsWith(SimpleConfiguratorConstants.PARAMETER_BASEURL + "=")) { //$NON-NLS-1$ - String baseUrlSt = line.substring((SimpleConfiguratorConstants.PARAMETER_BASEURL + "=").length()); //$NON-NLS-1$ - if (!baseUrlSt.endsWith("/")) //$NON-NLS-1$ - baseUrlSt += "/"; //$NON-NLS-1$ - baseUrl = new URL(url, baseUrlSt); - continue; - } - StringTokenizer tok = new StringTokenizer(line, ",", true); //$NON-NLS-1$ - String symbolicName = tok.nextToken(); - if (symbolicName.equals(",")) //$NON-NLS-1$ - symbolicName = null; - else - tok.nextToken(); // , - - String version = tok.nextToken(); - if (version.equals(",")) //$NON-NLS-1$ - version = null; - else - tok.nextToken(); // , - - String urlSt = tok.nextToken(); - if (urlSt.equals(",")) { //$NON-NLS-1$ - if (symbolicName != null && version != null) - urlSt = symbolicName + "_" + version + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ - else - urlSt = null; - } else - tok.nextToken(); // , - try { - Utils.buildURL(urlSt); - } catch (MalformedURLException e) { - urlSt = Utils.getUrlInFull(urlSt, baseUrl).toExternalForm(); - } - - int sl = Integer.parseInt(tok.nextToken().trim()); - tok.nextToken(); // , - boolean markedAsStarted = Boolean.valueOf(tok.nextToken()).booleanValue(); - // URL urlBundle = null; - // try { - // urlBundle = Utils.buildURL(urlSt); - // } catch (MalformedURLException e) { - // urlBundle = Utils.getFullUrl(urlSt, baseUrl); - // } - - BundleInfo bInfo = new BundleInfo(symbolicName, version, urlSt, sl, markedAsStarted); - bundles.add(bInfo); - } - } finally { - try { - r.close(); - } catch (IOException ex) { - // ignore - } + r.close(); + } catch (IOException ex) { + // ignore } - } catch (MalformedURLException e) { - e.printStackTrace(); - // TODO log something - // bundleInfos = NULL_BUNDLEINFOS; } return bundles; } + public static BundleInfo parseBundleInfoLine(String line, URI base) { + // symbolicName,version,location,startLevel,markedAsStarted + StringTokenizer tok = new StringTokenizer(line, COMMA); //$NON-NLS-1$ + int numberOfTokens = tok.countTokens(); + if (numberOfTokens < 5) + throw new IllegalArgumentException("Line does not contain at least 5 tokens: " + line); + + String symbolicName = tok.nextToken().trim(); + String version = tok.nextToken().trim(); + URI location = parseLocation(tok.nextToken().trim()); + int startLevel = Integer.parseInt(tok.nextToken().trim()); + boolean markedAsStarted = Boolean.valueOf(tok.nextToken()).booleanValue(); + BundleInfo result = new BundleInfo(symbolicName, version, location, startLevel, markedAsStarted); + if (!location.isAbsolute()) + result.setBaseLocation(base); + return result; + } + + public static URI parseLocation(String location) { + // decode any commas we previously encoded when writing this line + int encodedCommaIndex = location.indexOf(ENCODED_COMMA); + while (encodedCommaIndex != -1) { + location = location.substring(0, encodedCommaIndex) + COMMA + location.substring(encodedCommaIndex + 3); + encodedCommaIndex = location.indexOf(ENCODED_COMMA); + } + + if (File.separatorChar != '/') { + int colon = location.indexOf(':'); + String scheme = colon < 0 ? null : location.substring(0, colon); + if (scheme == null || scheme.equals(FILE_SCHEME)) + location = location.replace(File.separatorChar, '/'); + } + + try { + URI uri = new URI(location); + if (!uri.isOpaque()) + return uri; + } catch (URISyntaxException e1) { + // this will catch the use of invalid URI characters (e.g. spaces, etc.) + // ignore and fall through + } + + try { + return URIUtil.fromString(location); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid location: " + location); + } + } + + private static boolean validateURI(URI uri) { + // relative URIs when written scheme:a/b are considered opaque and indicate an improperly constructed URI string + if (uri.isOpaque()) + return false; + + // We check here for any improperly constructed file URI. + if (File.separatorChar == '/') + return true; + + if (uri.isAbsolute() && !uri.getScheme().equals(FILE_SCHEME)) + return true; + + return -1 == uri.getPath().indexOf(File.separatorChar); + } + public static void transferStreams(InputStream source, OutputStream destination) throws IOException { source = new BufferedInputStream(source); destination = new BufferedOutputStream(destination); @@ -117,4 +133,31 @@ public class SimpleConfiguratorUtils { } } } + + public static String getBundleLocation(BundleInfo bundle, boolean useReference) { + String bundleLocation = null; + URI location = bundle.getLocation(); + try { + if (location.getScheme() != null) + bundleLocation = URIUtil.toURL(location).toExternalForm(); + else { + URI baseLocation = bundle.getBaseLocation(); + if (baseLocation != null && baseLocation.getScheme() != null) { + String scheme = baseLocation.getScheme(); + String host = baseLocation.getHost(); + String path = location.getPath(); + URL bundleLocationURL = new URL(scheme, host, path); + bundleLocation = bundleLocationURL.toExternalForm(); + } + } + } catch (MalformedURLException e1) { + // fall through + } + if (bundleLocation == null) + bundleLocation = location.toString(); + + if (useReference && bundleLocation.startsWith(FILE_PREFIX)) //$NON-NLS-1$ + bundleLocation = REFERENCE_PREFIX + bundleLocation; //$NON-NLS-1$ + return bundleLocation; + } } diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/URIUtil.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/URIUtil.java new file mode 100644 index 000000000..b4173318d --- /dev/null +++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/utils/URIUtil.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.simpleconfigurator.utils; + +import java.io.File; +import java.net.*; + +public class URIUtil { + + private static final String SCHEME_FILE = "file"; //$NON-NLS-1$ + + /** + * Returns a URI corresponding to the given unencoded string. + * @throws URISyntaxException If the string cannot be formed into a valid URI + */ + public static URI fromString(String uriString) throws URISyntaxException { + int colon = uriString.indexOf(':'); + int hash = uriString.lastIndexOf('#'); + boolean noHash = hash < 0; + if (noHash) + hash = uriString.length(); + String scheme = colon < 0 ? null : uriString.substring(0, colon); + String ssp = uriString.substring(colon + 1, hash); + String fragment = noHash ? null : uriString.substring(hash + 1); + //use java.io.File for constructing file: URIs + if (scheme != null && scheme.equals(SCHEME_FILE)) { + File file = new File(uriString.substring(5)); + if (file.isAbsolute()) + return file.toURI(); + scheme = null; + if (File.separatorChar != '/') + ssp = ssp.replace(File.separatorChar, '/'); + } + return new URI(scheme, ssp, fragment); + } + + /* + * Compares two URI for equality. + * Return false if one of them is null + */ + public static boolean sameURI(URI url1, URI url2) { + if (url1 == url2) + return true; + if (url1 == null || url2 == null) + return false; + if (url1.equals(url2)) + return true; + + if (url1.isAbsolute() != url2.isAbsolute()) + return false; + + // check if we have two local file references that are case variants + File file1 = toFile(url1); + return file1 == null ? false : file1.equals(toFile(url2)); + } + + /** + * Returns the URI as a local file, or <code>null</code> if the given + * URI does not represent a local file. + * @param uri The URI to return the file for + * @return The local file corresponding to the given URI, or <code>null</code> + */ + public static File toFile(URI uri) { + try { + if (!SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) + return null; + //assume all illegal characters have been properly encoded, so use URI class to unencode + return new File(uri); + } catch (IllegalArgumentException e) { + //File constructor does not support non-hierarchical URI + String path = uri.getPath(); + //path is null for non-hierarchical URI such as file:c:/tmp + if (path == null) + path = uri.getSchemeSpecificPart(); + return new File(path); + } + } + + /** + * Returns the URL as a URI. This method will handle broken URLs that are + * not properly encoded (for example they contain unencoded space characters). + */ + public static URI toURI(URL url) throws URISyntaxException { + //URL behaves differently across platforms so for file: URLs we parse from string form + if (SCHEME_FILE.equals(url.getProtocol())) { + String pathString = url.toExternalForm().substring(5); + //ensure there is a leading slash to handle common malformed URLs such as file:c:/tmp + if (pathString.indexOf('/') != 0) + pathString = '/' + pathString; + return new URI(SCHEME_FILE, pathString, null); + } + try { + return new URI(url.toExternalForm()); + } catch (URISyntaxException e) { + //try multi-argument URI constructor to perform encoding + return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); + } + } + + /** + * Returns a URI as a URL. + * + * @throws MalformedURLException + */ + public static URL toURL(URI uri) throws MalformedURLException { + return new URL(uri.toString()); + } +} |