Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox')
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherImpl.java91
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java332
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java730
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxConstants.java61
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFrameworkAdminFactoryImpl.java24
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwAdminImpl.java137
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java582
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData.java30
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java649
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Log.java92
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Messages.java52
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java202
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/messages.properties40
-rw-r--r--bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java231
14 files changed, 0 insertions, 3253 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherImpl.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherImpl.java
deleted file mode 100644
index 8058023d9..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherImpl.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * 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.frameworkadmin.equinox;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import org.eclipse.equinox.internal.frameworkadmin.utils.SimpleBundlesState;
-import org.eclipse.equinox.internal.frameworkadmin.utils.Utils;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
-import org.osgi.service.log.LogService;
-
-public class EclipseLauncherImpl {
- static String getStringOfCmd(String[] cmdarray) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < cmdarray.length; i++) {
- sb.append(cmdarray[i]);
- sb.append(" "); //$NON-NLS-1$
- }
- return sb.toString();
- }
-
- EquinoxFwAdminImpl fwAdmin = null;
-
- EclipseLauncherImpl(EquinoxFwAdminImpl fwAdmin) {
- this.fwAdmin = fwAdmin;
- }
-
- public Process launch(Manipulator manipulator, File cwd) throws IllegalArgumentException, IOException, FrameworkAdminRuntimeException {
- SimpleBundlesState.checkAvailability(fwAdmin);
- Log.log(LogService.LOG_DEBUG, this, "launch(Manipulator , File )", ""); //$NON-NLS-1$ //$NON-NLS-2$
- LauncherData launcherData = manipulator.getLauncherData();
- if (launcherData.getLauncher() == null)
- return launchInMemory(manipulator, cwd);
- return launchByLauncher(manipulator, cwd);
- }
-
- private Process launchByLauncher(Manipulator manipulator, File cwd) throws IOException {
- LauncherData launcherData = manipulator.getLauncherData();
-
- if (launcherData.getLauncher() == null)
- throw new IllegalStateException(Messages.exception_launcherLocationNotSet);
- String[] cmdarray = new String[] {launcherData.getLauncher().getAbsolutePath()};
- if (cwd == null)
- cwd = launcherData.getLauncher().getParentFile();
- Process process = Runtime.getRuntime().exec(cmdarray, null, cwd);
- Log.log(LogService.LOG_DEBUG, "\t" + getStringOfCmd(cmdarray)); //$NON-NLS-1$
- return process;
- }
-
- private Process launchInMemory(Manipulator manipulator, File cwd) throws IOException {
- LauncherData launcherData = manipulator.getLauncherData();
- Utils.checkAbsoluteFile(launcherData.getFwJar(), "fwJar"); //$NON-NLS-1$
- Utils.checkAbsoluteDir(cwd, "cwd"); //$NON-NLS-1$
-
- List cmdList = new LinkedList();
- if (launcherData.getJvm() != null)
- cmdList.add(launcherData.getJvm().getAbsolutePath());
- else
- cmdList.add("java"); //$NON-NLS-1$
-
- if (launcherData.getJvmArgs() != null)
- for (int i = 0; i < launcherData.getJvmArgs().length; i++)
- cmdList.add(launcherData.getJvmArgs()[i]);
-
- cmdList.add("-jar"); //$NON-NLS-1$
- cmdList.add(Utils.getRelativePath(launcherData.getFwJar(), cwd));
-
- EquinoxManipulatorImpl.checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData);
- cmdList.add(EquinoxConstants.OPTION_CONFIGURATION);
- cmdList.add(Utils.getRelativePath(launcherData.getFwPersistentDataLocation(), cwd));
-
- if (launcherData.isClean())
- cmdList.add(EquinoxConstants.OPTION_CLEAN);
-
- String[] cmdarray = new String[cmdList.size()];
- cmdList.toArray(cmdarray);
- Log.log(LogService.LOG_DEBUG, "In CWD = " + cwd + "\n\t" + getStringOfCmd(cmdarray)); //$NON-NLS-1$ //$NON-NLS-2$
- Process process = Runtime.getRuntime().exec(cmdarray, null, cwd);
- return process;
- }
-}
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
deleted file mode 100644
index 38eb443e4..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 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.*;
-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 MAC_OS_APP_FOLDER = ".app/Contents/MacOS"; //$NON-NLS-1$
- private static final String CONFIGURATION_FOLDER = "configuration"; //$NON-NLS-1$
-
- //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, null, base);
- if (osgiInstallArea != null)
- return URIUtil.makeAbsolute(osgiInstallArea.toURI(), base);
- return null;
- }
-
- private void setInstall(List lines, LauncherData launcherData, File launcherFolder) {
- if (launcherData.getFwConfigLocation() == null || launcherData.getFwJar() == null) {
- ParserUtils.removeArgument(EquinoxConstants.OPTION_INSTALL, lines);
- return;
- }
- String launcherString = launcherFolder.getAbsolutePath().replace('\\', '/');
- if (launcherString.endsWith(MAC_OS_APP_FOLDER)) {
- //We can do 3 calls to getParentFile without checking because
- launcherFolder = launcherFolder.getParentFile().getParentFile().getParentFile();
- }
- if (!ParserUtils.fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath()).equals(launcherFolder)) {
- ParserUtils.setValueForArgument(EquinoxConstants.OPTION_INSTALL, launcherFolder.getAbsolutePath().replace('\\', '/'), lines);
- }
- }
-
- void read(File launcherConfigFile, LauncherData launcherData) throws IOException {
- if (!launcherConfigFile.exists())
- return;
-
- List lines = FileUtils.loadFile(launcherConfigFile);
-
- 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 ? ParserUtils.fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath()).toURI() : launcherFolder;
- }
- URI configArea = getConfigurationLocation(lines, osgiInstallArea, launcherData);
- if (configArea == null)
- throw new FrameworkAdminRuntimeException(Messages.exception_nullConfigArea, ""); //$NON-NLS-1$
- getPersistentDataLocation(lines, osgiInstallArea, configArea, launcherData);
- getLauncherLibrary(lines, launcherFolder);
- getJVMArgs(lines, launcherData);
- getProgramArgs(lines, launcherData);
- getVM(lines, launcherFolder, launcherData);
-
- Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_configFile, launcherConfigFile.getAbsolutePath()));
- }
-
- private void getFrameworkJar(List lines, URI launcherFolder, LauncherData launcherData) {
- File fwJar = launcherData.getFwJar();
- if (fwJar != null)
- return;
- URI location = ParserUtils.getFrameworkJar(lines, launcherFolder);
- if (location != null)
- launcherData.setFwJar(URIUtil.toFile(location));
- }
-
- 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));
- }
- }
-
- 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, NLS.bind(Messages.log_failed_make_absolute, vm));
- return;
- }
- }
-
- private void setVM(List lines, File vm, URI launcherFolder) {
- if (vm == null) {
- if (ParserUtils.getValueForArgument(EquinoxConstants.OPTION_VM, lines) != null)
- return;
-
- ParserUtils.removeArgument(EquinoxConstants.OPTION_VM, lines);
- return;
- }
-
- URI vmRelativePath = null;
- if (vm.isAbsolute()) {
- vmRelativePath = launcherFolder.relativize(vm.toURI());
- } else {
- //For relative files, File#toURI will create an absolute URI by resolving against the current working directory, we don't want that
- String path = vm.getPath().replace('\\', '/');
- try {
- vmRelativePath = URIUtil.fromString(path);
- } catch (URISyntaxException e) {
- vmRelativePath = launcherFolder.relativize(vm.toURI());
- }
- }
-
- ParserUtils.setValueForArgument(EquinoxConstants.OPTION_VM, FileUtils.toPath(vmRelativePath).replace('\\', '/'), lines);
- }
-
- private void getJVMArgs(List lines, LauncherData launcherData) {
- ArrayList vmargs = new ArrayList(lines.size());
- boolean foundVmArgs = false;
- for (Iterator iterator = lines.iterator(); iterator.hasNext();) {
- String line = (String) iterator.next();
- if (!foundVmArgs) {
- if (EquinoxConstants.OPTION_VMARGS.equals(line))
- foundVmArgs = true;
- continue;
- }
- vmargs.add(line);
- }
-
- launcherData.setJvmArgs(null);
- launcherData.setJvmArgs((String[]) vmargs.toArray(new String[vmargs.size()]));
- }
-
- 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]);
- }
- }
-
- private void getProgramArgs(List lines, LauncherData launcherData) {
- ArrayList args = new ArrayList(lines.size());
- for (Iterator iterator = lines.iterator(); iterator.hasNext();) {
- String line = (String) iterator.next();
- if (EquinoxConstants.OPTION_VMARGS.equals(line))
- break;
- args.add(line);
- }
- launcherData.setProgramArgs(null);
- launcherData.setProgramArgs((String[]) args.toArray(new String[args.size()]));
- }
-
- 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(FileUtils.fromPath(launcherLibrary), launcherFolder);
- ParserUtils.setValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, result.toString(), lines);
- } catch (URISyntaxException e) {
- Log.log(LogService.LOG_ERROR, NLS.bind(Messages.log_failed_make_absolute, launcherLibrary));
- return null;
- }
- return result;
- }
-
- private void setLauncherLibrary(List lines, URI launcherFolder) {
- String launcherLibrary = ParserUtils.getValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, lines);
- if (launcherLibrary == null)
- return;
-
- try {
- URI result = URIUtil.makeRelative(FileUtils.fromPath(launcherLibrary), launcherFolder);
- ParserUtils.setValueForArgument(EquinoxConstants.OPTION_LAUNCHER_LIBRARY, FileUtils.toPath(result).replace('\\', '/'), lines);
- } catch (URISyntaxException e) {
- Log.log(LogService.LOG_ERROR, NLS.bind(Messages.log_failed_make_absolute, launcherLibrary));
- return;
- }
- }
-
- 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
- }
-
- 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, NLS.bind(Messages.log_failed_make_absolute, configuration));
- return null;
- }
- return result;
- }
-
- 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;
- }
-
- if (ParserUtils.getValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, lines) == null) {
- ParserUtils.setValueForArgument(EquinoxConstants.OPTION_CONFIGURATION, result.replace('\\', '/'), lines);
- }
- return;
- }
-
- 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, NLS.bind(Messages.log_failed_make_absolute, 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).replace('\\', '/'), lines);
- } catch (URISyntaxException e) {
- Log.log(LogService.LOG_ERROR, NLS.bind(Messages.log_failed_make_relative, startup));
- return;
- }
- }
-
- void save(EquinoxLauncherData launcherData, boolean backup) throws IOException {
- File launcherConfigFile = EquinoxManipulatorImpl.getLauncherConfigLocation(launcherData);
-
- if (launcherConfigFile == null)
- throw new IllegalStateException(Messages.exception_launcherLocationNotSet);
- 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, null, launcherData);
- //setInstall(lines, osgiInstallArea, launcherFolder);
- setConfigurationLocation(newlines, osgiInstallArea.toURI(), launcherData);
- setLauncherLibrary(newlines, launcherFolder.toURI());
- // setFrameworkJar(newlines, launcherData.getFwJar());
- setVM(newlines, launcherData.getJvm(), launcherFolder.toURI());
-
- //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()]));
-
- //append jvm args
- setJVMArgs(newlines, launcherData);
-
- // backup file if exists.
- if (backup)
- if (launcherConfigFile.exists()) {
- File dest = Utils.getSimpleDataFormattedFile(launcherConfigFile);
- if (!launcherConfigFile.renameTo(dest))
- throw new IOException(NLS.bind(Messages.exception_failedToRename, launcherConfigFile, dest));
- Log.log(LogService.LOG_INFO, this, "save()", NLS.bind(Messages.log_renameSuccessful, launcherConfigFile, dest)); //$NON-NLS-1$
- }
-
- //only write the file if we actually have content
- if (newlines.size() > 0) {
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(launcherConfigFile));
- 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();
- Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_launcherConfigSave, launcherConfigFile));
- } finally {
- if (bw != null)
- bw.close();
- }
- }
- File previousLauncherIni = launcherData.getPreviousLauncherIni();
- if (previousLauncherIni != null && !previousLauncherIni.equals(launcherConfigFile))
- previousLauncherIni.delete();
- launcherData.setLauncherConfigLocation(launcherConfigFile);
- }
-}
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
deleted file mode 100644
index 3fab73713..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxBundlesState.java
+++ /dev/null
@@ -1,730 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 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.*;
-import org.eclipse.core.runtime.internal.adaptor.EclipseEnvironmentInfo;
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-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.frameworkadmin.*;
-import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
-import org.eclipse.osgi.service.resolver.*;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.*;
-import org.osgi.service.log.LogService;
-
-public class EquinoxBundlesState implements BundlesState {
- static final long DEFAULT_TIMESTAMP = 0L;
- private static final boolean DEBUG = false;
- // While we recognize the amd64 architecture, we change
- // this internally to be x86_64.
- private static final String INTERNAL_AMD64 = "amd64"; //$NON-NLS-1$
- private static final String INTERNAL_ARCH_I386 = "i386"; //$NON-NLS-1$
- public static final String[] PROPS = {"osgi.os", "osgi.ws", "osgi.nl", "osgi.arch", Constants.FRAMEWORK_SYSTEMPACKAGES, "osgi.resolverMode", Constants.FRAMEWORK_EXECUTIONENVIRONMENT, "osgi.resolveOptional", "osgi.genericAliases"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-
- static boolean checkFullySupported() {
- //TODO - This was previously doing a bogus check by attempting to instantiate a particular class - it's not clear what this is trying to do
- return true;
- }
-
- /**
- * eclipse.exe will launch a fw where plugins/org.eclipse.osgi_*.*.*.*.jar
- * is an implementation of fw.
- *
- * @param launcherData
- * @param configData
- * @return File of fwJar to be used.
- */
- static File getFwJar(LauncherData launcherData, ConfigData configData) {
- return getFwJar(launcherData, configData, true);
- //
- // // EclipseLauncherParser launcherParser = new
- // EclipseLauncherParser(launcherData);
- // // launcherParser.read();
- // if (launcherData.getFwJar() != null)
- // return launcherData.getFwJar();
- //
- // // check -D arguments of jvmArgs ?
- // String[] jvmArgs = launcherData.getJvmArgs();
- // String location = null;
- // for (int i = 0; i < jvmArgs.length; i++) {
- // if (jvmArgs[i].endsWith("-D" + "osgi.framework=")) {
- // location = jvmArgs[i].substring(("-D" + "osgi.framework=").length());
- // }
- // }
- // if (location != null)
- // return new File(location);
- //
- // File ret = getSystemBundleFromBundleInfos(launcherData, configData);
- // if (ret != null)
- // return ret;
- // return getSystemBundleBySearching(launcherData);
- }
-
- private static File getFwJar(LauncherData launcherData, ConfigData configData, boolean checkBundleInfos) {
- if (launcherData.getFwJar() != null) {
- return launcherData.getFwJar();
- }
-
- // check -D arguments of jvmArgs ?
- String[] jvmArgs = launcherData.getJvmArgs();
- String location = null;
- for (int i = 0; i < jvmArgs.length; i++) {
- if (jvmArgs[i].endsWith("-D" + "osgi.framework=")) { //$NON-NLS-1$ //$NON-NLS-2$
- location = jvmArgs[i].substring(("-D" + "osgi.framework=").length()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- if (location != null) {
- return new File(location);
- }
-
- if (checkBundleInfos) {
- File ret = getSystemBundleFromBundleInfos(configData);
- if (ret != null) {
- return ret;
- }
- }
- return null;
- // return getSystemBundleBySearching(launcherData);
- }
-
- private static long getMaxId(State state) {
- BundleDescription[] bundleDescriptions = state.getBundles();
- long maxId = DEFAULT_TIMESTAMP;
- for (int i = 0; i < bundleDescriptions.length; i++)
- if (maxId < bundleDescriptions[i].getBundleId()) {
- maxId = bundleDescriptions[i].getBundleId();
- }
- return maxId;
- }
-
- private static File getSystemBundleFromBundleInfos(BundleInfo[] bundleInfos) {
- for (int i = 0; i < bundleInfos.length; i++) {
- File match = isSystemBundle(bundleInfos[i]);
- if (match != null)
- return match;
- }
- return null;
- }
-
- protected static File getSystemBundleFromBundleInfos(ConfigData configData) {
- BundleInfo[] bundleInfos = configData.getBundles();
- return getSystemBundleFromBundleInfos(bundleInfos);
- }
-
- static long getTimeStamp(File fwPersistentDataLocation) {
- if (fwPersistentDataLocation == null)
- return DEFAULT_TIMESTAMP;
-
- File file = new File(fwPersistentDataLocation, EquinoxConstants.PERSISTENT_DIR_NAME);
- if (!file.exists() || !file.isDirectory())
- return DEFAULT_TIMESTAMP;
- long ret = file.lastModified();
- File[] lists = file.listFiles();
- if (lists == null)
- return ret;
- for (int i = 0; i < lists.length; i++)
- if (ret < lists[i].lastModified())
- ret = lists[i].lastModified();
- return ret;
- }
-
- public static File isSystemBundle(BundleInfo bundleInfo) {
- if (bundleInfo == null || bundleInfo.getLocation() == null)
- return null;
- 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;
- }
-
- // "osgi.os", "osgi.ws", "osgi.nl", "osgi.arch",
- // Constants.FRAMEWORK_SYSTEMPACKAGES, "osgi.resolverMode",
- // Constants.FRAMEWORK_EXECUTIONENVIRONMENT, "osgi.resolveOptional"
- static Properties setDefaultPlatformProperties() {
- Properties platformProperties = new Properties();
- // set default value
-
- String nl = Locale.getDefault().toString();
- platformProperties.setProperty("osgi.nl", nl); //$NON-NLS-1$
-
- // TODO remove EclipseEnvironmentInfo
- String os = EclipseEnvironmentInfo.guessOS(System.getProperty("os.name"));//$NON-NLS-1$);
- platformProperties.setProperty("osgi.os", os); //$NON-NLS-1$
-
- String ws = EclipseEnvironmentInfo.guessWS(os);
- platformProperties.setProperty("osgi.ws", ws); //$NON-NLS-1$
-
- // if the user didn't set the system architecture with a command line
- // argument then use the default.
- String arch = null;
- String name = FrameworkProperties.getProperty("os.arch");//$NON-NLS-1$
- // Map i386 architecture to x86
- if (name.equalsIgnoreCase(INTERNAL_ARCH_I386))
- arch = org.eclipse.osgi.service.environment.Constants.ARCH_X86;
- // Map amd64 architecture to x86_64
- else if (name.equalsIgnoreCase(INTERNAL_AMD64))
- arch = org.eclipse.osgi.service.environment.Constants.ARCH_X86_64;
- else
- arch = name;
- platformProperties.setProperty("osgi.arch", arch); //$NON-NLS-1$
-
- platformProperties.setProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, FrameworkProperties.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES));
- platformProperties.setProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, FrameworkProperties.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT));
- platformProperties.setProperty("osgi.resolveOptional", "" + "true".equals(FrameworkProperties.getProperty("osgi.resolveOptional"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- return platformProperties;
- }
-
- EquinoxFwAdminImpl fwAdmin = null;
- BundleContext context;
- Manipulator manipulator = null;
- Properties platfromProperties = new Properties();
- long maxId = DEFAULT_TIMESTAMP;
- StateObjectFactory soFactory = null;
- State state = null;
-
- /**
- * Map of String->BundleDescription, where the key is the bundle location.
- */
- private HashMap locationStateIndex = new HashMap();
-
- /**
- * Map of String->BundleDescription, where the key is the bundle name
- * and version as defined by the {@link #getKey(BundleDescription)} method.
- */
- private HashMap nameVersionStateIndex = new HashMap();
- private final PlatformAdmin platformAdmin;
-
- /**
- * If useFwPersistentData flag equals false, this constructor will not take
- * a framework persistent data into account. Otherwise, it will.
- *
- * @param context
- * @param fwAdmin
- * @param manipulator
- * @param useFwPersistentData
- */
- EquinoxBundlesState(BundleContext context, EquinoxFwAdminImpl fwAdmin, Manipulator manipulator, PlatformAdmin admin, boolean useFwPersistentData) {
- this.context = context;
- this.fwAdmin = fwAdmin;
- this.platformAdmin = admin;
- // copy manipulator object for avoiding modifying the parameters of the
- // manipulator.
- this.manipulator = fwAdmin.getManipulator();
- this.manipulator.setConfigData(manipulator.getConfigData());
- this.manipulator.setLauncherData(manipulator.getLauncherData());
- initialize(useFwPersistentData);
- }
-
- /**
- * This constructor does NOT take a framework persistent data into account.
- * It will create State object based on the specified platformProperties.
- *
- * @param context
- * @param fwAdmin
- * @param manipulator
- * @param platformProperties
- */
- EquinoxBundlesState(BundleContext context, EquinoxFwAdminImpl fwAdmin, Manipulator manipulator, PlatformAdmin admin, Properties platformProperties) {
- super();
- this.context = context;
- this.fwAdmin = fwAdmin;
- this.platformAdmin = admin;
- // copy manipulator object for avoiding modifying the parameters of the
- // manipulator.
- this.manipulator = fwAdmin.getManipulator();
- this.manipulator.setConfigData(manipulator.getConfigData());
- this.manipulator.setLauncherData(manipulator.getLauncherData());
- LauncherData launcherData = manipulator.getLauncherData();
- ConfigData configData = manipulator.getConfigData();
- BundleInfo[] bInfos = configData.getBundles();
- this.composeNewState(launcherData, configData, platformProperties, bInfos);
- }
-
- /**
- * compose new state without reading framework persistent data. The
- * configData.getFwDependentProps() is used for the composition.
- *
- * @param launcherData
- * @param configData
- * @param bInfos
- */
- private void composeNewState(LauncherData launcherData, ConfigData configData, BundleInfo[] bInfos) {
- this.composeNewState(launcherData, configData, configData.getProperties(), bInfos);
- }
-
- /**
- * compose new state without reading framework persistent data. The given
- * properties is used for the composition. If system bundle is not included
- * in the given bInfos, the fw jar launcherData contains will be used.
- *
- * @param launcherData
- * @param configData
- * @param properties
- * @param bInfos
- */
- private void composeNewState(LauncherData launcherData, ConfigData configData, Properties properties, BundleInfo[] bInfos) {
- //Note, there use to be a lot more code in this method
- File fwJar = getSystemBundleFromBundleInfos(configData);
- launcherData.setFwJar(fwJar);
- this.setFwJar(fwJar);
- composeState(configData.getBundles(), properties, null);
- resolve(true);
- }
-
- /**
- * compose state. If it cannot compose it by somehow, false is returned.
- *
- * @param bInfos
- * @param props
- * @param fwPersistentDataLocation
- * @return if it cannot compose it by somehow, false is returned.
- * @throws IllegalArgumentException
- * @throws FrameworkAdminRuntimeException
- */
- private boolean composeState(BundleInfo[] bInfos, Dictionary props, File fwPersistentDataLocation) throws IllegalArgumentException, FrameworkAdminRuntimeException {
- BundleInfo[] infos = manipulator.getConfigData().getBundles();
- this.manipulator.getConfigData().setBundles(null);
- SimpleBundlesState.checkAvailability(fwAdmin);
- this.setStateObjectFactory();
- state = null;
- boolean flagNewState = false;
- if (fwPersistentDataLocation != null) {
- //NOTE Here there was a big chunk of code reading the framework state persisted on disk
- // and I removed it because it was causing various problems. See in previous revision
- this.manipulator.getConfigData().setBundles(infos);
- return false;
- }
- state = soFactory.createState(true);
- createStateIndexes();
- flagNewState = true;
- if (props == null) {
- this.manipulator.getConfigData().setBundles(infos);
- return false;
- }
- setPlatformPropertiesToState(props);
- setPlatformProperties(state);
-
- try {
- maxId = state.getHighestBundleId();
- } catch (NoSuchMethodError e) {
- maxId = getMaxId(state);
- }
- if (DEBUG) {
- System.out.println(""); //$NON-NLS-1$
- Log.log(LogService.LOG_DEBUG, this, "composeExpectedState()", "installBundle():"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (flagNewState) {
- int indexSystemBundle = -1;
- for (int j = 0; j < bInfos.length; j++)
- if (isSystemBundle(bInfos[j]) != null) {
- indexSystemBundle = j;
- break;
- }
-
- if (indexSystemBundle > 0) {
- BundleInfo[] newBundleInfos = new BundleInfo[bInfos.length];
- newBundleInfos[0] = bInfos[indexSystemBundle];
- System.arraycopy(bInfos, 0, newBundleInfos, 1, indexSystemBundle);
- if (indexSystemBundle < bInfos.length - 1)
- System.arraycopy(bInfos, indexSystemBundle + 1, newBundleInfos, indexSystemBundle + 1, bInfos.length - indexSystemBundle - 1);
- bInfos = newBundleInfos;
- }
- }
- for (int j = 0; j < bInfos.length; j++) {
- if (DEBUG)
- Log.log(LogService.LOG_DEBUG, this, "composeExpectedState()", "bInfos[" + j + "]=" + bInfos[j]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- try {
- this.installBundle(bInfos[j]);
- // System.out.println("install bInfos[" + j + "]=" + bInfos[j]);
- } catch (RuntimeException e) {
- //catch the exception and continue
- Log.log(LogService.LOG_ERROR, this, "composeExpectedState()", "BundleInfo:" + bInfos[j], e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- return true;
- }
-
- private BundleInfo convertSystemBundle(BundleDescription toConvert) {
- // Converting the System Bundle
- boolean markedAsStarted = false;
- int sl = BundleInfo.NO_LEVEL;
-
- URI location = null;
- String symbolicNameTarget = toConvert.getSymbolicName();
- Version versionTarget = toConvert.getVersion();
- try {
- File fwJar = manipulator.getLauncherData().getFwJar();
- if (fwJar != null) {
- 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);
- if (fwJarSymbolicName.equals(symbolicNameTarget) && fwJarVersionSt.equals(versionTarget.toString())) {
- location = fwJarLocation;
- markedAsStarted = true;
- }
- }
- } catch (FrameworkAdminRuntimeException e1) {
- Log.log(LogService.LOG_ERROR, "", e1); //$NON-NLS-1$
- }
- return createBundleInfo(toConvert, markedAsStarted, sl, location, null);
- }
-
- private BundleInfo createBundleInfo(BundleDescription toConvert, boolean markedAsStarted, int sl, URI location, String fragmentHost) {
- BundleInfo result = new BundleInfo();
- result.setSymbolicName(toConvert.getSymbolicName());
- result.setVersion(toConvert.getVersion().toString());
- result.setLocation(location);
- result.setResolved(toConvert.isResolved());
- result.setMarkedAsStarted(markedAsStarted);
- result.setStartLevel(sl);
- result.setBundleId(toConvert.getBundleId());
- result.setFragmentHost(fragmentHost);
- return result;
- }
-
- public BundleInfo[] convertState(BundleDescription[] bundles) {
- BundleInfo[] originalBInfos = manipulator.getConfigData().getBundles();
- Map bundleInfoMap = new HashMap();
- for (int i = 0; i < originalBInfos.length; i++) {
- bundleInfoMap.put(originalBInfos[i].getLocation(), originalBInfos[i]);
- }
-
- BundleInfo[] result = new BundleInfo[bundles.length];
- for (int i = 0; i < bundles.length; i++) {
- if (bundles[i].getBundleId() == 0 && EquinoxConstants.FW_SYMBOLIC_NAME.equals(bundles[i].getSymbolicName())) {
- result[i] = convertSystemBundle(bundles[i]);
- continue;
- }
-
- boolean markedAsStarted = false;
- int sl = BundleInfo.NO_LEVEL;
-
- //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
- }
- String fragmentHost = null;
- BundleInfo original = (BundleInfo) bundleInfoMap.get(location);
- if (original != null) {
- markedAsStarted = original.isMarkedAsStarted();
- sl = getStartLevel(original.getStartLevel());
- fragmentHost = original.getFragmentHost();
- }
- result[i] = createBundleInfo(bundles[i], markedAsStarted, sl, location, fragmentHost);
- }
- return result;
- }
-
- public BundleInfo[] getExpectedState() throws FrameworkAdminRuntimeException {
- SimpleBundlesState.checkAvailability(fwAdmin);
- return convertState(state.getBundles());
- }
-
- Properties getPlatformProperties() {
- return platfromProperties;
- }
-
- public BundleInfo[] getPrerequisteBundles(BundleInfo bInfo) {
- Set set = new HashSet();
- URI realLocation = bInfo.getLocation();
- BundleDescription bundle = getBundleByLocation(realLocation);
- ImportPackageSpecification[] imports = bundle.getImportPackages();
- for (int i = 0; i < imports.length; i++) {
- BaseDescription supplier = imports[i].getSupplier();
- if (supplier == null) {
- if (!imports[i].getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_OPTIONAL))
- throw new IllegalStateException("Internal error: import supplier should not be null"); //$NON-NLS-1$
- } else
- set.add(supplier.getSupplier());
- }
- BundleDescription[] requires = bundle.getResolvedRequires();
- for (int i = 0; i < requires.length; i++) {
- set.add(requires[i]);
- }
- BundleDescription[] bundles = new BundleDescription[set.size()];
- set.toArray(bundles);
- return convertState(bundles);
- }
-
- private int getStartLevel(int startLevel) {
- return (startLevel == BundleInfo.NO_LEVEL ? manipulator.getConfigData().getInitialBundleStartLevel() : startLevel);
- }
-
- public BundleInfo getSystemBundle() {
- BundleDescription bundle = this.getSystemBundleDescription();
- return (bundle != null ? convertSystemBundle(bundle) : null);
- }
-
- private BundleDescription getSystemBundleDescription() {
- BundleDescription bundle = state.getBundle(0);
- if (bundle == null || bundle.getHost() != null) { // null or a
- // fragment bundle.
- return null;
- }
- return (EquinoxConstants.FW_SYMBOLIC_NAME.equals(bundle.getSymbolicName()) ? bundle : null);
- }
-
- public BundleInfo[] getSystemFragmentedBundles() {
- BundleDescription bundle = this.getSystemBundleDescription();
- if (bundle == null)
- return null;
- return convertState(bundle.getFragments());
- }
-
- public String[] getUnsatisfiedConstraints(BundleInfo bInfo) {
- URI realLocation = bInfo.getLocation();
- BundleDescription description = getBundleByLocation(realLocation);
- StateHelper helper = platformAdmin.getStateHelper();
- VersionConstraint[] constraints = helper.getUnsatisfiedConstraints(description);
- String[] ret = new String[constraints.length];
- for (int i = 0; i < constraints.length; i++)
- ret[i] = constraints[i].toString();
- return ret;
- }
-
- private void initialize(boolean useFwPersistentData) {
- LauncherData launcherData = manipulator.getLauncherData();
- ConfigData configData = manipulator.getConfigData();
- BundleInfo[] bInfos = configData.getBundles();
-
- if (!useFwPersistentData) {
- composeNewState(launcherData, configData, bInfos);
- return;
- }
-
- EquinoxManipulatorImpl.checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData);
- if (launcherData.isClean()) {
- composeNewState(launcherData, configData, bInfos);
- } else {
- if (manipulator.getLauncherData().getFwPersistentDataLocation() == null) {
- File installArea = ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), configData.getProperties(), launcherData);
- if (DEBUG)
- Log.log(LogService.LOG_DEBUG, this, "initialize(useFwPersistentDat)", "installArea=" + installArea); //$NON-NLS-1$ //$NON-NLS-2$
- if (installArea == null)
- throw new IllegalStateException(Messages.exception_noInstallArea);
- File fwPersistentDataLocation = new File(installArea, "configuration"); //$NON-NLS-1$
- manipulator.getLauncherData().setFwPersistentDataLocation(fwPersistentDataLocation, false);
- }
- if (!composeState(bInfos, null, manipulator.getLauncherData().getFwPersistentDataLocation()))
- composeNewState(launcherData, configData, bInfos);
- resolve(true);
- }
- }
-
- public void installBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException {
- SimpleBundlesState.checkAvailability(fwAdmin);
-
- URI realLocation = bInfo.getLocation();
- if (getBundleByLocation(realLocation) != null)
- return;
-
- Dictionary manifest = Utils.getOSGiManifest(realLocation);
- if (manifest == null)
- return;
-
- String newSymbolicName = (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME);
- int position = newSymbolicName.indexOf(";"); //$NON-NLS-1$
- if (position >= 0)
- newSymbolicName = newSymbolicName.substring(0, position).trim();
- String newVersion = (String) manifest.get(Constants.BUNDLE_VERSION);
-
- if (getBundleByNameVersion(newSymbolicName, newVersion) != null)
- return;
-
- try {
- bInfo.setBundleId(++maxId);
- BundleDescription newBundleDescription = soFactory.createBundleDescription(state, manifest, realLocation.toString(), bInfo.getBundleId());
- addBundleToState(newBundleDescription);
- manipulator.getConfigData().addBundle(bInfo);
- } catch (BundleException e) {
- Log.log(LogService.LOG_WARNING, this, "installBundle(BundleInfo)", e); //$NON-NLS-1$
- }
- }
-
- public boolean isFullySupported() {
- return true;
- }
-
- public boolean isResolved() {
- return state.isResolved();
- }
-
- public boolean isResolved(BundleInfo bInfo) {
- URI realLocation = bInfo.getLocation();
- BundleDescription description = getBundleByLocation(realLocation);
- if (description == null)
- return false;
- return description.isResolved();
- }
-
- public void resolve(boolean increment) {
- state.resolve(increment);
- }
-
- void setFwJar(File fwJar) {
- manipulator.getLauncherData().setFwJar(fwJar);
- }
-
- /**
- * get platforme properties from the given state.
- *
- * @param state
- */
- private void setPlatformProperties(State state) {
- Dictionary platformProperties = state.getPlatformProperties()[0];
- platfromProperties.clear();
- if (platformProperties != null) {
- for (Enumeration enumeration = platformProperties.keys(); enumeration.hasMoreElements();) {
- String key = (String) enumeration.nextElement();
- Object value = platformProperties.get(key);
- platfromProperties.setProperty(key, (String) value);
- }
- }
- if (DEBUG)
- Utils.printoutProperties(System.out, "PlatformProperties[0]", platfromProperties); //$NON-NLS-1$
- }
-
- /**
- * set platfromProperties required to compose state object into
- * platformProperties of this state.
- *
- * @param props
- */
- private void setPlatformPropertiesToState(Dictionary props) {
- Properties platformProperties = setDefaultPlatformProperties();
-
- for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();) {
- String key = (String) enumeration.nextElement();
- for (int i = 0; i < PROPS.length; i++) {
- if (key.equals(PROPS[i])) {
- platformProperties.put(key, props.get(key));
- break;
- }
- }
- }
- state.setPlatformProperties(platformProperties);
- }
-
- private void setStateObjectFactory() {
- if (soFactory == null)
- soFactory = platformAdmin.getFactory();
- }
-
- public String toString() {
- if (state == null)
- return null;
- StringBuffer sb = new StringBuffer();
- BundleDescription[] bundleDescriptions = state.getBundles();
- for (int i = 0; i < bundleDescriptions.length; i++) {
- sb.append(bundleDescriptions[i].getBundleId() + ":"); //$NON-NLS-1$
- sb.append(bundleDescriptions[i].toString() + "("); //$NON-NLS-1$
- sb.append(bundleDescriptions[i].isResolved() + ")"); //$NON-NLS-1$
- String[] ees = bundleDescriptions[i].getExecutionEnvironments();
- for (int j = 0; j < ees.length; j++)
- sb.append(ees[j] + " "); //$NON-NLS-1$
- sb.append("\n"); //$NON-NLS-1$
- }
- sb.append("PlatformProperties:\n"); //$NON-NLS-1$
- Dictionary[] dics = state.getPlatformProperties();
- for (int i = 0; i < dics.length; i++) {
- for (Enumeration enumeration = dics[i].keys(); enumeration.hasMoreElements();) {
- String key = (String) enumeration.nextElement();
- String value = (String) dics[i].get(key);
- sb.append(" (" + key + "," + value + ")\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
- sb.append("\n"); //$NON-NLS-1$
- return sb.toString();
- }
-
- public void uninstallBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException {
- SimpleBundlesState.checkAvailability(fwAdmin);
- long id = DEFAULT_TIMESTAMP;
- URI realLocation = bInfo.getLocation();
- BundleDescription bundle = getBundleByLocation(bInfo.getLocation());
- if (bundle != null)
- id = bundle.getBundleId();
-
- if (id != DEFAULT_TIMESTAMP) {
- try {
- Dictionary manifest = Utils.getOSGiManifest(bInfo.getLocation());
- if (manifest == null) {
- 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.toString(), id);
- removeBundleFromState(bundleDescription);
- manipulator.getConfigData().removeBundle(bInfo);
- } catch (BundleException e) {
- Log.log(LogService.LOG_WARNING, this, "uninstallBundle(BundleInfo)", e); //$NON-NLS-1$
- }
- }
- }
-
- private BundleDescription getBundleByLocation(URI location) {
- if (location == null)
- return null;
- return (BundleDescription) locationStateIndex.get(location);
- }
-
- private BundleDescription getBundleByNameVersion(String bundleSymbolicName, String bundleVersion) {
- return (BundleDescription) nameVersionStateIndex.get(bundleSymbolicName + ";" + bundleVersion); //$NON-NLS-1$
- }
-
- /**
- * Returns a key for a bundle description containing the bundle name and version,
- * for use in the name/version state index map.
- */
- private String getKey(BundleDescription bundle) {
- return bundle.getSymbolicName() + ';' + bundle.getVersion();
- }
-
- private void createStateIndexes() {
- BundleDescription[] currentInstalledBundles = state.getBundles();
- for (int i = 0; i < currentInstalledBundles.length; i++) {
- URI location = FileUtils.getRealLocation(manipulator, currentInstalledBundles[i].getLocation());
- locationStateIndex.put(location, currentInstalledBundles[i]);
- nameVersionStateIndex.put(getKey(currentInstalledBundles[i]), currentInstalledBundles[i]);
- }
- }
-
- private void addBundleToState(BundleDescription bundleDescription) {
- state.addBundle(bundleDescription);
- URI location = FileUtils.getRealLocation(manipulator, bundleDescription.getLocation());
- locationStateIndex.put(location, bundleDescription);
- nameVersionStateIndex.put(getKey(bundleDescription), bundleDescription);
- }
-
- private void removeBundleFromState(BundleDescription bundleDescription) {
- URI location = FileUtils.getRealLocation(manipulator, bundleDescription.getLocation());
- 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
deleted file mode 100644
index 571448384..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxConstants.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 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;
-
-public class EquinoxConstants {
-
- /**
- * If BundleContext#getProperty(PROP_KEY_USE_REFERENCE) does not equal "false",
- * Manipulator#save() will add "reference:" to any bundle location specified osgi.bundles in order to avoid
- * caching its bundle jar. Otherwise, it will add nothing to any bundle location.
- */
- public static final String PROP_KEY_USE_REFERENCE = "org.eclipse.equinox.frameworkadmin.equinox.useReference"; //$NON-NLS-1$
-
- public static final String PLUGINS_DIR = "plugins"; //$NON-NLS-1$
- public final static String FW_SYMBOLIC_NAME = "org.eclipse.osgi"; //$NON-NLS-1$
- public static final String DEFAULT_CONFIGURATION = "configuration"; //$NON-NLS-1$
- public static final String CONFIG_INI = "config.ini"; //$NON-NLS-1$
-
- public final static String FW_VERSION = "3.3"; //$NON-NLS-1$
- public final static String FW_NAME = "Equinox"; //$NON-NLS-1$
- public final static String LAUNCHER_VERSION = "3.2"; //$NON-NLS-1$
- public final static String LAUNCHER_NAME = "Eclipse.exe"; //$NON-NLS-1$
-
- public static final String OPTION_CONFIGURATION = "-configuration"; //$NON-NLS-1$
- public static final String OPTION_FW = "-framework"; //$NON-NLS-1$
- public static final String OPTION_VM = "-vm"; //$NON-NLS-1$
- public static final String OPTION_VMARGS = "-vmargs"; //$NON-NLS-1$
- 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_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$
- public static final String PROP_BUNDLES_STARTLEVEL = "osgi.bundles.defaultStartLevel"; //$NON-NLS-1$ //The start level used to install the bundles
- public static final String PROP_INITIAL_STARTLEVEL = "osgi.startLevel"; //$NON-NLS-1$ //The start level when the fwl start
- public static final String PROP_INSTALL = "osgi.install"; //$NON-NLS-1$
- public static final String PROP_ECLIPSE_COMMANDS = "eclipse.commands"; //$NON-NLS-1$
- public static final String PROP_FW_EXTENSIONS = "osgi.framework.extensions"; //$NON-NLS-1$
- public static final String PROP_OSGI_FW = "osgi.framework"; //$NON-NLS-1$
- public static final String PROP_OSGI_SYSPATH = "osgi.syspath"; //$NON-NLS-1$
- public static final String PROP_LAUNCHER_PATH = "osgi.launcherPath"; //$NON-NLS-1$
- public static final String PROP_LAUNCHER_NAME = "osgi.launcherIni"; //$NON-NLS-1$
- public static final String PROP_SHARED_CONFIGURATION_AREA = "osgi.sharedConfiguration.area"; //$NON-NLS-1$
-
- public static final String INI_EXTENSION = ".ini"; //$NON-NLS-1$
- public static final String EXE_EXTENSION = ".exe"; //$NON-NLS-1$
-
- public static final String PROP_EQUINOX_DEPENDENT_PREFIX = "osgi."; //$NON-NLS-1$
- static final String REFERENCE = "reference:"; //$NON-NLS-1$
- public static final String PERSISTENT_DIR_NAME = "org.eclipse.osgi"; //$NON-NLS-1$
-
-}
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFrameworkAdminFactoryImpl.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFrameworkAdminFactoryImpl.java
deleted file mode 100644
index 72989059b..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFrameworkAdminFactoryImpl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * 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.frameworkadmin.equinox;
-
-import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulatorFactory;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdmin;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminFactory;
-
-public class EquinoxFrameworkAdminFactoryImpl extends FrameworkAdminFactory {
- public FrameworkAdmin createFrameworkAdmin() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
- String className = System.getProperty(ConfiguratorManipulatorFactory.SYSTEM_PROPERTY_KEY);
- if (className == null)
- return new EquinoxFwAdminImpl();
- return new EquinoxFwAdminImpl(className);
- }
-}
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwAdminImpl.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwAdminImpl.java
deleted file mode 100644
index c23aa941d..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwAdminImpl.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 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.io.IOException;
-import java.util.Dictionary;
-import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator;
-import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulatorFactory;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
-import org.eclipse.osgi.service.resolver.PlatformAdmin;
-import org.osgi.framework.*;
-import org.osgi.service.startlevel.StartLevel;
-
-public class EquinoxFwAdminImpl implements FrameworkAdmin {
-
- boolean active = false;
-
- private ConfiguratorManipulator configuratorManipulator = null;
-
- BundleContext context = null;
-
- private boolean runningFw = false;
-
- private PlatformAdmin platformAdmin;
- private StartLevel startLevelService;
-
- public EquinoxFwAdminImpl() {
- this(null, false);
- }
-
- // private String configuratorManipulatorFactoryName = null;
-
- EquinoxFwAdminImpl(BundleContext context) {
- this(context, false);
- }
-
- EquinoxFwAdminImpl(BundleContext context, boolean runningFw) {
- this.context = context;
- this.active = true;
- this.runningFw = runningFw;
- }
-
- EquinoxFwAdminImpl(String configuratorManipulatorFactoryName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
- this.context = null;
- this.active = true;
- this.runningFw = false;
- // this.configuratorManipulatorFactoryName = configuratorManipulatorFactoryName;
- loadConfiguratorManipulator(configuratorManipulatorFactoryName);
- }
-
- /**
- * DS component activator
- * @param aContext The bundle context
- */
- public void activate(BundleContext aContext) {
- this.context = aContext;
- this.runningFw = isRunningFw();
- Log.init(aContext);
- }
-
- void deactivate() {
- active = false;
- Log.dispose();
- }
-
- public ConfiguratorManipulator getConfiguratorManipulator() {
- return configuratorManipulator;
- }
-
- public Manipulator getManipulator() {
- return new EquinoxManipulatorImpl(context, this, platformAdmin, startLevelService, false);
- }
-
- public Manipulator getRunningManipulator() {
- if (!this.runningFw)
- return null;
- return new EquinoxManipulatorImpl(context, this, platformAdmin, startLevelService, true);
- }
-
- public boolean isActive() {
- return active;
- }
-
- /**
- * If both the vendor and the Bundle-Version in the manifest match,
- * return true. Otherwise false.
- *
- * @return flag true if the ManipulatorAdmin object can handle currently running fw launch.
- */
- boolean isRunningFw() {
- //TODO implementation for Eclipse.exe and for Equinox
- String fwVendor = context.getProperty(Constants.FRAMEWORK_VENDOR);
- if (!"Eclipse".equals(fwVendor)) //$NON-NLS-1$
- return false;
- //TODO decide if this version can be supported by this bundle.
- Dictionary header = context.getBundle(0).getHeaders();
- String versionSt = (String) header.get(Constants.BUNDLE_VERSION);
- Version version = new Version(versionSt);
- int value = version.compareTo(new Version(EquinoxConstants.FW_VERSION));
- if (value > 0) {
- return true;
- }
- // TODO need to identify the version of eclipse.exe used for this launch, if used.
- return false;
- }
-
- public Process launch(Manipulator manipulator, File cwd) throws IllegalArgumentException, FrameworkAdminRuntimeException, IOException {
- //return new EclipseLauncherImpl(context, this).launch(manipulator, cwd);
- return new EclipseLauncherImpl(this).launch(manipulator, cwd);
- }
-
- private void loadConfiguratorManipulator(String configuratorManipulatorFactoryName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
- if (configuratorManipulatorFactoryName == null)
- this.configuratorManipulator = null;
- else
- this.configuratorManipulator = ConfiguratorManipulatorFactory.getInstance(configuratorManipulatorFactoryName);
- return;
- }
-
- public void setPlatformAdmin(PlatformAdmin admin) {
- this.platformAdmin = admin;
- }
-
- public void setStartLevel(StartLevel sl) {
- this.startLevelService = sl;
- }
-
-}
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
deleted file mode 100644
index a96127ed7..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxFwConfigFileParser.java
+++ /dev/null
@@ -1,582 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 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.*;
-import java.net.*;
-import java.util.*;
-import org.eclipse.core.runtime.URIUtil;
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils;
-import org.eclipse.equinox.internal.frameworkadmin.utils.Utils;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.log.LogService;
-
-public class EquinoxFwConfigFileParser {
- private static final Set KNOWN_PROPERTIES = new HashSet(Arrays.asList(new String[] {EquinoxConstants.PROP_BUNDLES, EquinoxConstants.PROP_FW_EXTENSIONS, EquinoxConstants.PROP_INITIAL_STARTLEVEL, EquinoxConstants.PROP_BUNDLES_STARTLEVEL}));
- private static final String CONFIG_DIR = "@config.dir/"; //$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 REFERENCE_SCHEME = "reference:"; //$NON-NLS-1$
- private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
- private static boolean DEBUG = false;
-
- public EquinoxFwConfigFileParser(BundleContext context) {
- //Empty
- }
-
- 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();
- sb.append(locationString);
- if (startLevel == BundleInfo.NO_LEVEL && !toBeStarted)
- return sb;
- sb.append('@');
- if (startLevel != BundleInfo.NO_LEVEL)
- sb.append(startLevel);
- if (toBeStarted)
- sb.append(":start"); //$NON-NLS-1$
- return sb;
- }
-
- private static boolean getMarkedAsStartedFormat(String startInfo) {
- if (startInfo == null)
- return false;
- startInfo = startInfo.trim();
- int colon = startInfo.indexOf(':');
- if (colon > -1) {
- return startInfo.substring(colon + 1).equals("start"); //$NON-NLS-1$
- }
- return startInfo.equals("start"); //$NON-NLS-1$
- }
-
- private static int getStartLevel(String startInfo) {
- if (startInfo == null)
- return BundleInfo.NO_LEVEL;
- startInfo = startInfo.trim();
- int colon = startInfo.indexOf(":"); //$NON-NLS-1$
- if (colon > 0) {
- try {
- return Integer.parseInt(startInfo.substring(0, colon));
- } catch (NumberFormatException e) {
- return BundleInfo.NO_LEVEL;
- }
- }
- return BundleInfo.NO_LEVEL;
- }
-
- private void readBundlesList(Manipulator manipulator, URI osgiInstallArea, Properties props) throws NumberFormatException {
- ConfigData configData = manipulator.getConfigData();
-
- BundleInfo[] fwExtensions = parseBundleList(manipulator, props.getProperty(EquinoxConstants.PROP_FW_EXTENSIONS));
- if (fwExtensions != null) {
- for (int i = 0; i < fwExtensions.length; i++) {
- fwExtensions[i].setFragmentHost(Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
- configData.addBundle(fwExtensions[i]);
- }
- }
-
- BundleInfo[] bundles = parseBundleList(manipulator, props.getProperty(EquinoxConstants.PROP_BUNDLES));
- if (bundles != null) {
- for (int i = 0; i < bundles.length; i++) {
- configData.addBundle(bundles[i]);
- }
- }
- }
-
- private BundleInfo[] parseBundleList(Manipulator manipulator, String value) {
- if (value == null || value.length() == 0)
- return null;
-
- List bundles = new ArrayList();
- String[] bInfoStrings = Utils.getTokens(value, ","); //$NON-NLS-1$
- for (int i = 0; i < bInfoStrings.length; i++) {
- 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;
- if (manipulator.getLauncherData().getFwJar() != null) {
- File parentFile = manipulator.getLauncherData().getFwJar().getParentFile();
- try {
- realLocation = URIUtil.makeAbsolute(FileUtils.fromFileURL(location), parentFile.toURI());
- } catch (URISyntaxException e) {
- // try searching as a simple location
- realLocation = FileUtils.getEclipsePluginFullLocation(location, parentFile);
- }
- }
- String slAndFlag = (indexStartInfo > -1) ? entry.substring(indexStartInfo + 1) : null;
-
- boolean markedAsStarted = getMarkedAsStartedFormat(slAndFlag);
- int startLevel = getStartLevel(slAndFlag);
-
- if (realLocation != null) {
- bundles.add(new BundleInfo(realLocation, startLevel, markedAsStarted));
- continue;
- }
- if (location != null && location.startsWith(FILE_PROTOCOL))
- try {
- bundles.add(new BundleInfo(FileUtils.fromFileURL(location), startLevel, markedAsStarted));
- continue;
- } catch (URISyntaxException e) {
- //Ignore
- }
-
- //Fallback case, we use the location as a string
- bundles.add(new BundleInfo(location, null, null, startLevel, markedAsStarted));
- }
- return (BundleInfo[]) bundles.toArray(new BundleInfo[bundles.size()]);
- }
-
- private void writeBundlesList(File fwJar, Properties props, BundleInfo[] bundles) {
- StringBuffer osgiBundlesList = new StringBuffer();
- StringBuffer osgiFrameworkExtensionsList = new StringBuffer();
- for (int j = 0; j < bundles.length; j++) {
- BundleInfo bundle = bundles[j];
-
- //framework jar does not get stored on the bundle list, figure out who that is.
- if (fwJar != null) {
- if (URIUtil.sameURI(fwJar.toURI(), bundle.getLocation()))
- continue;
- } else if (EquinoxConstants.FW_SYMBOLIC_NAME.equals(bundle.getSymbolicName()))
- continue;
-
- URI location = fwJar != null ? URIUtil.makeRelative(bundle.getLocation(), fwJar.getParentFile().toURI()) : bundle.getLocation();
-
- String fragmentHost = bundle.getFragmentHost();
- boolean isFrameworkExtension = fragmentHost != null && (fragmentHost.startsWith(EquinoxConstants.FW_SYMBOLIC_NAME) || fragmentHost.startsWith(Constants.SYSTEM_BUNDLE_SYMBOLICNAME));
-
- if (isFrameworkExtension) {
- bundle.setStartLevel(BundleInfo.NO_LEVEL);
- bundle.setMarkedAsStarted(false);
- osgiFrameworkExtensionsList.append(toOSGiBundleListForm(bundle, location));
- osgiFrameworkExtensionsList.append(',');
- } else {
- osgiBundlesList.append(toOSGiBundleListForm(bundle, location));
- osgiBundlesList.append(',');
- }
- }
- if (osgiFrameworkExtensionsList.length() > 0)
- osgiFrameworkExtensionsList.deleteCharAt(osgiFrameworkExtensionsList.length() - 1);
- props.setProperty(EquinoxConstants.PROP_FW_EXTENSIONS, osgiFrameworkExtensionsList.toString());
-
- if (osgiBundlesList.length() > 0)
- osgiBundlesList.deleteCharAt(osgiBundlesList.length() - 1);
- props.setProperty(EquinoxConstants.PROP_BUNDLES, osgiBundlesList.toString());
- }
-
- /**
- * inputFile must be not a directory but a file.
- *
- * @param manipulator
- * @param 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));
-
- //Initialize data structures
- ConfigData configData = manipulator.getConfigData();
- LauncherData launcherData = manipulator.getLauncherData();
- configData.initialize();
- configData.setBundles(null);
-
- // load configuration properties
- Properties props = loadProperties(inputFile);
-
- // load shared configuration properties
- Properties sharedConfigProperties = getSharedConfiguration(props.getProperty(EquinoxConstants.PROP_SHARED_CONFIGURATION_AREA), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), props, manipulator.getLauncherData()));
- if (sharedConfigProperties != null) {
- sharedConfigProperties.putAll(props);
- props = sharedConfigProperties;
- }
-
- //Start figuring out stuffs
- //URI rootURI = launcherData.getLauncher() != null ? launcherData.getLauncher().getParentFile().toURI() : null;
-
- readFwJarLocation(configData, launcherData, props);
- URI configArea = inputFile.getParentFile().toURI();
- //readLauncherPath(props, rootURI);
- readp2DataArea(props, configArea);
- readSimpleConfiguratorURL(props, configArea);
- readBundlesList(manipulator, ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), props, launcherData).toURI(), props);
- readInitialStartLeve(configData, props);
- readDefaultStartLevel(configData, props);
-
- for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();) {
- String key = (String) enumeration.nextElement();
- if (KNOWN_PROPERTIES.contains(key))
- continue;
- String value = props.getProperty(key);
- configData.setProperty(key, value);
- }
- 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) {
- URI absoluteFwJar = null;
- absoluteFwJar = URIUtil.makeAbsolute(FileUtils.fromFileURL(props.getProperty(EquinoxConstants.PROP_OSGI_FW)), ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), props, launcherData).toURI());
-
- props.setProperty(EquinoxConstants.PROP_OSGI_FW, absoluteFwJar.toString());
- String fwJarString = props.getProperty(EquinoxConstants.PROP_OSGI_FW);
- if (fwJarString != null) {
- fwJar = URIUtil.toFile(absoluteFwJar);
- if (fwJar == null)
- throw new IllegalStateException(Messages.exception_noFrameworkLocation);
- //Here we overwrite the value read from eclipse.ini, because the value of osgi.framework always takes precedence.
- launcherData.setFwJar(fwJar);
- } else {
- throw new IllegalStateException(Messages.exception_noFrameworkLocation);
- }
- }
- if (launcherData.getFwJar() != null)
- configData.addBundle(new BundleInfo(launcherData.getFwJar().toURI()));
- return launcherData.getFwJar();
- }
-
- 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()), configData.getProperties(), launcherData).toURI())));
- }
-
- private static Properties loadProperties(File inputFile) throws FileNotFoundException, IOException {
- Properties props = new Properties();
- InputStream is = null;
- try {
- is = new FileInputStream(inputFile);
- props.load(is);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_failed_reading_properties, inputFile));
- }
- is = null;
- }
- return props;
- }
-
- private File findSharedConfigIniFile(URL rootURL, String sharedConfigurationArea) {
- URL sharedConfigurationURL = null;
- try {
- sharedConfigurationURL = new URL(sharedConfigurationArea);
- } catch (MalformedURLException e) {
- // unexpected since this was written by the framework
- Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_url, sharedConfigurationArea));
- return null;
- }
-
- // check for a relative URL
- if (!sharedConfigurationURL.getPath().startsWith("/")) { //$NON-NLS-1$
- if (!rootURL.getProtocol().equals(sharedConfigurationURL.getProtocol())) {
- Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_relative_url, rootURL.toExternalForm(), sharedConfigurationArea));
- return null;
- }
- try {
- sharedConfigurationURL = new URL(rootURL, sharedConfigurationArea);
- } catch (MalformedURLException e) {
- // unexpected since this was written by the framework
- Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_relative_url, rootURL.toExternalForm(), sharedConfigurationArea));
- return null;
- }
- }
- File sharedConfigurationFolder = new File(sharedConfigurationURL.getPath());
- if (!sharedConfigurationFolder.isDirectory()) {
- Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_file_missing, sharedConfigurationFolder));
- return null;
- }
-
- File sharedConfigIni = new File(sharedConfigurationFolder, EquinoxConstants.CONFIG_INI);
- if (!sharedConfigIni.exists()) {
- Log.log(LogService.LOG_WARNING, NLS.bind(Messages.log_shared_config_file_missing, sharedConfigIni));
- return null;
- }
-
- return sharedConfigIni;
- }
-
- 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) {
- 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());
- }
- }
- }
-
- 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 dataAreaURI = new URI(dataArea);
- URI relative = URIUtil.makeRelative(dataAreaURI, configArea);
- if (dataAreaURI.equals(relative)) {
- props.setProperty(KEY_ECLIPSE_PROV_DATA_AREA, FileUtils.toFileURL(dataAreaURI));
- return;
- }
- 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(new URI(result)));
- }
- }
-
- // private void readLauncherPath(Properties props, URI root) throws URISyntaxException {
- // if (props.getProperty(EquinoxConstants.PROP_LAUNCHER_PATH) != null) {
- // URI absoluteURI = URIUtil.makeAbsolute(URIUtil.fromString(props.getProperty(EquinoxConstants.PROP_LAUNCHER_PATH)), root);
- // props.setProperty(EquinoxConstants.PROP_LAUNCHER_PATH, URIUtil.toUnencodedString(absoluteURI));
- // }
- // }
- //
- // private void writeLauncherPath(ConfigData configData, Properties props, URI root) throws URISyntaxException {
- // String value = getFwProperty(configData, EquinoxConstants.PROP_LAUNCHER_PATH);
- // if (value != null) {
- // URI launcherPathURI = FileUtils.fromPath(value);
- // String launcherPath = URIUtil.toUnencodedString(URIUtil.makeRelative(launcherPathURI, root));
- // if ("/".equals(launcherPath) || "".equals(launcherPath)) //$NON-NLS-1$ //$NON-NLS-2$
- // launcherPath = "."; //$NON-NLS-1$
- // props.setProperty(EquinoxConstants.PROP_LAUNCHER_PATH, launcherPath);
- // }
- // }
-
- 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());
- }
-
- 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 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();
- //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()) {
- if (!outputFile.getName().equals(EquinoxConstants.CONFIG_INI))
- throw new IllegalStateException(NLS.bind(Messages.exception_fwConfigLocationName, outputFile.getAbsolutePath(), EquinoxConstants.CONFIG_INI));
- } else { // Directory
- outputFile = new File(outputFile, EquinoxConstants.CONFIG_INI);
- }
- } else {
- if (!outputFile.getName().equals(EquinoxConstants.CONFIG_INI)) {
- if (!outputFile.mkdir())
- throw new IOException(NLS.bind(Messages.exception_failedToCreateDir, outputFile));
- outputFile = new File(outputFile, EquinoxConstants.CONFIG_INI);
- }
- }
- String header = "This configuration file was written by: " + this.getClass().getName(); //$NON-NLS-1$
-
- Properties configProps = new Properties();
- //URI rootURI = launcherData.getLauncher() != null ? launcherData.getLauncher().getParentFile().toURI() : null;
-
- writeFwJarLocation(configData, launcherData, configProps);
- try {
- //writeLauncherPath(configData, configProps, rootURI);
- URI configArea = manipulator.getLauncherData().getFwConfigLocation().toURI();
- writep2DataArea(configData, configProps, configArea);
- writeSimpleConfiguratorURL(configData, configProps, configArea);
- writeBundlesList(launcherData.getFwJar(), configProps, bInfos);
- writeInitialStartLevel(configData, configProps);
- writeDefaultStartLevel(configData, configProps);
- } catch (URISyntaxException e) {
- throw new FrameworkAdminRuntimeException(e, Messages.exception_errorSavingConfigIni);
- }
-
- 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;
- }
- if (!Utils.createParentDir(outputFile)) {
- throw new IllegalStateException(NLS.bind(Messages.exception_failedToCreateDir, outputFile.getParent()));
- }
-
- if (DEBUG)
- Utils.printoutProperties(System.out, "configProps", configProps); //$NON-NLS-1$
-
- if (backup)
- if (outputFile.exists()) {
- File dest = Utils.getSimpleDataFormattedFile(outputFile);
- if (!outputFile.renameTo(dest))
- throw new IOException(NLS.bind(Messages.exception_failedToRename, outputFile, dest));
- Log.log(LogService.LOG_INFO, this, "saveFwConfig()", NLS.bind(Messages.log_renameSuccessful, outputFile, dest)); //$NON-NLS-1$
- }
-
- FileOutputStream out = null;
- try {
- out = new FileOutputStream(outputFile);
- // configProps = makeRelative(configProps, launcherData.getLauncher().getParentFile().toURI(), fwJar, outputFile.getParentFile(), getOSGiInstallArea(manipulator.getLauncherData()));
- filterPropertiesFromSharedArea(configProps, manipulator);
- configProps.store(out, header);
- Log.log(LogService.LOG_INFO, NLS.bind(Messages.log_fwConfigSave, outputFile));
- } finally {
- try {
- out.flush();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- out = null;
- }
- }
-
- private void filterPropertiesFromSharedArea(Properties configProps, Manipulator manipulator) {
- LauncherData launcherData = manipulator.getLauncherData();
- //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), ParserUtils.getOSGiInstallArea(Arrays.asList(launcherData.getProgramArgs()), configProps, launcherData));
- if (sharedConfigProperties == null)
- return;
- Enumeration keys = configProps.propertyNames();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- String sharedValue = sharedConfigProperties.getProperty(key);
- if (sharedValue == null)
- continue;
- String value = configProps.getProperty(key);
- if (equalsIgnoringSeparators(sharedValue, value)) {
- configProps.remove(key);
- continue;
- }
-
- if (key.equals(EquinoxConstants.PROP_BUNDLES) && equalBundleLists(manipulator, value, sharedValue)) {
- configProps.remove(key);
- continue;
- }
-
- if (key.equals(EquinoxConstants.PROP_FW_EXTENSIONS) && equalBundleLists(manipulator, value, sharedValue)) {
- configProps.remove(key);
- continue;
- }
- }
- }
-
- private boolean equalBundleLists(Manipulator manipulator, String value, String sharedValue) {
- BundleInfo[] bundles = parseBundleList(manipulator, value);
- BundleInfo[] sharedBundles = parseBundleList(manipulator, sharedValue);
- if (bundles == null || sharedBundles == null || bundles.length != sharedBundles.length)
- return false;
-
- List compareList = new ArrayList(Arrays.asList(bundles));
- compareList.removeAll(Arrays.asList(sharedBundles));
- return compareList.isEmpty();
- }
-
- private boolean equalsIgnoringSeparators(String s1, String s2) {
- if (s1 == null && s2 == null)
- return true;
- if (s1 == null || s2 == null)
- return false;
- StringBuffer sb1 = new StringBuffer(s1);
- StringBuffer sb2 = new StringBuffer(s2);
- canonicalizePathsForComparison(sb1);
- canonicalizePathsForComparison(sb2);
- return sb1.toString().equals(sb2.toString());
- }
-
- private void canonicalizePathsForComparison(StringBuffer s) {
- final String[] tokens = new String[] {"\\\\", "\\", "//", "/"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
- for (int t = 0; t < tokens.length; t++) {
- int idx = s.length();
- for (int i = s.length(); i != 0 && idx != -1; i--) {
- idx = s.toString().lastIndexOf(tokens[t], idx);
- if (idx != -1)
- s.replace(idx, idx + tokens[t].length(), "^"); //$NON-NLS-1$
- }
- }
- }
-
- private Properties getSharedConfiguration(String sharedConfigurationArea, File baseFile) {
- if (sharedConfigurationArea == null)
- return null;
- File sharedConfigIni;
- try {
- sharedConfigIni = findSharedConfigIniFile(baseFile.toURL(), sharedConfigurationArea);
- } catch (MalformedURLException e) {
- return null;
- }
- if (sharedConfigIni != null && sharedConfigIni.exists())
- try {
- return loadProperties(sharedConfigIni);
- } catch (FileNotFoundException e) {
- return null;
- } catch (IOException e) {
- return null;
- }
- return null;
- }
-}
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData.java
deleted file mode 100644
index 869115bd4..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxLauncherData.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * 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 org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
-
-public class EquinoxLauncherData extends LauncherData {
- File previousLauncher = null;
-
- public EquinoxLauncherData(String fwName, String fwVersion, String launcherName, String launcherVersion) {
- super(fwName, fwVersion, launcherName, launcherVersion);
- }
-
- public void setLauncher(File launcherFile) {
- if (previousLauncher == null && launcherFile != null && !launcherFile.equals(getLauncher()))
- previousLauncher = EquinoxManipulatorImpl.getLauncherConfigLocation(this);
- super.setLauncher(launcherFile);
- }
-
- File getPreviousLauncherIni() {
- return previousLauncher;
- }
-}
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
deleted file mode 100644
index fba4751fc..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EquinoxManipulatorImpl.java
+++ /dev/null
@@ -1,649 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 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.io.IOException;
-import java.net.*;
-import java.util.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-import org.eclipse.equinox.internal.frameworkadmin.utils.SimpleBundlesState;
-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.osgi.service.datalocation.Location;
-import org.eclipse.osgi.service.resolver.PlatformAdmin;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.*;
-import org.osgi.service.log.LogService;
-import org.osgi.service.startlevel.StartLevel;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- *
- */
-public class EquinoxManipulatorImpl implements Manipulator {
- private static final long DEFAULT_LASTMODIFIED = 0L;
- private static final boolean LOG_ILLEGALSTATEEXCEPTION = false;
- private static final String COMMA = ","; //$NON-NLS-1$
- private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
- private static final String IGNORED = "ignored"; //$NON-NLS-1$
-
- /**
- * If the fwConfigLocation is a file and its name does not equal "config.ini",
- * throw an IllegaStateException.
- * If the fwConfigLocation is a file and its name equals "config.ini",
- * fwConfigLocation will be updated by its parent directory.
- *
- * Then, reset fwConfigLocation and fwPersistentDataLocation to be matched.
- *
- * @param launcherData
- */
- static void checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(LauncherData launcherData) {
- File fwConfigLocation = launcherData.getFwConfigLocation();
- File fwPersistentDataLocation = launcherData.getFwPersistentDataLocation();
-
- if (fwConfigLocation != null) {
- if (fwConfigLocation.isFile()) {
- if (fwConfigLocation.getName().equals(EquinoxConstants.CONFIG_INI))
- fwConfigLocation = fwConfigLocation.getParentFile();
- else
- throw new IllegalStateException(NLS.bind(Messages.exception_unexpectedfwConfigLocation, fwConfigLocation.getAbsolutePath(), EquinoxConstants.CONFIG_INI));
- launcherData.setFwConfigLocation(fwConfigLocation);
- }
- if (fwPersistentDataLocation != null) {
- if (!fwConfigLocation.equals(fwPersistentDataLocation))
- throw new IllegalStateException(NLS.bind(Messages.exception_persistantLocationNotEqualConfigLocation, fwPersistentDataLocation.getAbsolutePath(), fwConfigLocation.getAbsolutePath()));
- } else
- launcherData.setFwPersistentDataLocation(fwConfigLocation, launcherData.isClean());
- } else {
- if (fwPersistentDataLocation != null) {
- launcherData.setFwConfigLocation(fwPersistentDataLocation);
- } else {
- File home = launcherData.getHome();
- if (home == null)
- throw new IllegalStateException(Messages.exception_noLocations);
- fwConfigLocation = new File(home, "configuration"); //$NON-NLS-1$
- launcherData.setFwPersistentDataLocation(fwConfigLocation, launcherData.isClean());
- launcherData.setFwConfigLocation(fwConfigLocation);
- }
- }
- }
-
- //This returns the location of the <eclipse>.ini file
- static File getLauncherConfigLocation(LauncherData launcherData) {
- 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('.');
- if (dotLocation != -1)
- launcherName = launcherName.substring(0, dotLocation);
- File result = new File(launcher.getParentFile(), launcherName + EquinoxConstants.INI_EXTENSION);
- return result;
- }
-
- ConfigData configData = new ConfigData(EquinoxConstants.FW_NAME, EquinoxConstants.FW_VERSION, EquinoxConstants.LAUNCHER_NAME, EquinoxConstants.LAUNCHER_VERSION);
- EquinoxLauncherData launcherData = new EquinoxLauncherData(EquinoxConstants.FW_NAME, EquinoxConstants.FW_VERSION, EquinoxConstants.LAUNCHER_NAME, EquinoxConstants.LAUNCHER_VERSION);
- BundleContext context = null;
- private Properties platformProperties = new Properties();
-
- ServiceTracker cmTracker;
- int trackingCount = -1;
- private final PlatformAdmin platformAdmin;
- private final StartLevel startLevelService;
-
- // private final boolean runtime;
-
- ConfiguratorManipulator configuratorManipulator;
-
- EquinoxFwAdminImpl fwAdmin = null;
-
- EquinoxManipulatorImpl(BundleContext context, EquinoxFwAdminImpl fwAdmin, PlatformAdmin admin, StartLevel slService, boolean runtime) {
- this.context = context;
- this.fwAdmin = fwAdmin;
- this.platformAdmin = admin;
- this.startLevelService = slService;
- if (context != null) {
- cmTracker = new ServiceTracker(context, ConfiguratorManipulator.class.getName(), null);
- cmTracker.open();
- }
- // this.runtime = runtime;
- if (runtime)
- initializeRuntime();
- // XXX For Equinox, default value of Initial Bundle Start Level is 4.
- // Precisely speaking, it's not correct.
- // Equinox doesn't support setting initial bundle start level as an OSGi terminology.
- // Only bundles installed by config.ini and updateconfigurator will have that start level(4).
- // Others has a start level of 1.
- configData.setInitialBundleStartLevel(4);
- }
-
- public BundlesState getBundlesState() throws FrameworkAdminRuntimeException {
- if (context == null)
- return new SimpleBundlesState(fwAdmin, this, EquinoxConstants.FW_SYMBOLIC_NAME);
-
- if (!EquinoxBundlesState.checkFullySupported())
- return new SimpleBundlesState(fwAdmin, this, EquinoxConstants.FW_SYMBOLIC_NAME);
-
- if (platformProperties.isEmpty())
- return new EquinoxBundlesState(context, fwAdmin, this, platformAdmin, false);
- // XXX checking if fwDependent or fwIndependent platformProperties are updated after the platformProperties was created might be required for better implementation.
- return new EquinoxBundlesState(context, fwAdmin, this, platformAdmin, platformProperties);
- }
-
- public ConfigData getConfigData() throws FrameworkAdminRuntimeException {
- return configData;
- }
-
- public BundleInfo[] getExpectedState() throws IllegalArgumentException, FrameworkAdminRuntimeException {
- //Log.log(LogService.LOG_DEBUG, this, "getExpectedState()", "BEGIN");
- SimpleBundlesState.checkAvailability(fwAdmin);
-
- BundlesState bundleState = this.getBundlesState();
- if (bundleState instanceof SimpleBundlesState)
- return new BundleInfo[0];
- bundleState.resolve(true);
-
- return bundleState.getExpectedState();
- }
-
- public LauncherData getLauncherData() throws FrameworkAdminRuntimeException {
- return launcherData;
- }
-
- /**
- * Return the configuration location.
- *
- * @see Location
- */
- private File getRunningConfigurationLocation() {
- ServiceTracker tracker = null;
- Filter filter = null;
- try {
- filter = context.createFilter(Location.CONFIGURATION_FILTER);
- } catch (InvalidSyntaxException e) {
- // ignore this. It should never happen as we have tested the above format.
- }
- tracker = new ServiceTracker(context, filter, null);
- tracker.open();
- Location location = (Location) tracker.getService();
- URL url = location.getURL();
- if (!url.getProtocol().equals("file")) //$NON-NLS-1$
- return null;
- return new File(url.getFile());
- }
-
- private File getRunningLauncherFile() {
- File launcherFile = null;
- String eclipseCommandsSt = context.getProperty(EquinoxConstants.PROP_ECLIPSE_COMMANDS);
- if (eclipseCommandsSt == null)
- return null;
-
- StringTokenizer tokenizer = new StringTokenizer(eclipseCommandsSt, "\n"); //$NON-NLS-1$
- boolean found = false;
- String launcherSt = null;
- while (tokenizer.hasMoreTokens()) {
- String token = tokenizer.nextToken();
- if (found) {
- launcherSt = token;
- break;
- }
- if (token.equals("-launcher")) //$NON-NLS-1$
- found = true;
- }
- if (launcherSt != null)
- launcherFile = new File(launcherSt);
- return launcherFile;
- }
-
- private Properties getRunningPlatformProperties() {
- Properties props = new Properties();
- for (int i = 0; i < EquinoxBundlesState.PROPS.length; i++) {
- String value = context.getProperty(EquinoxBundlesState.PROPS[i]);
- if (value != null)
- props.setProperty(EquinoxBundlesState.PROPS[i], value);
- }
- return props;
- }
-
- public long getTimeStamp() {
- long ret = this.getTimeStampWithoutFwPersistentData();
- if (this.launcherData.isClean())
- return ret;
- long lastModifiedFwPersistent = EquinoxBundlesState.getTimeStamp(launcherData.getFwPersistentDataLocation());
- return Math.max(ret, lastModifiedFwPersistent);
- }
-
- private long getTimeStampWithoutFwPersistentData() {
- SimpleBundlesState.checkAvailability(fwAdmin);
- File launcherConfigFile = getLauncherConfigLocation(launcherData);
- long lastModifiedLauncherConfigFile = DEFAULT_LASTMODIFIED;
- long lastModifiedFwConfigFile = DEFAULT_LASTMODIFIED;
- if (launcherConfigFile != null) {
- // use launcher. -- > load from LaucnherConfig file.
- lastModifiedLauncherConfigFile = launcherConfigFile.lastModified();
- }
- checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData);
-
- if (launcherData.getFwConfigLocation() != null) {
- File fwConfigFile = new File(launcherData.getFwConfigLocation(), EquinoxConstants.CONFIG_INI);
- lastModifiedFwConfigFile = fwConfigFile.lastModified();
- }
- long ret = Math.max(lastModifiedLauncherConfigFile, lastModifiedFwConfigFile);
- return ret;
- }
-
- public void initialize() {
- Log.log(LogService.LOG_DEBUG, this, "initialize()", "BEGIN"); //$NON-NLS-1$ //$NON-NLS-2$
- configData.initialize();
- launcherData.initialize();
- }
-
- private void initializeRuntime() {
- //TODO refine the implementation. using some MAGIC dependent on Eclipse.exe and Equinox implementation,
- // set parameters according to the current running fw.
-
- // 1. retrieve location data from Location services registered by equinox fw.
- String fwJarLocation = context.getProperty(EquinoxConstants.PROP_OSGI_FW);
- if (!fwJarLocation.startsWith("file:")) //$NON-NLS-1$
- throw new IllegalStateException(NLS.bind(Messages.exception_fileURLExpected, EquinoxConstants.PROP_OSGI_FW, fwJarLocation));
- File fwJar = new File(fwJarLocation.substring("file:".length())); //$NON-NLS-1$
- File fwConfigLocation = getRunningConfigurationLocation();
- File launcherFile = getRunningLauncherFile();
- launcherData.setFwJar(fwJar);
- launcherData.setFwPersistentDataLocation(fwConfigLocation, false);
- launcherData.setLauncher(launcherFile);
- launcherData.setOS(context.getProperty("osgi.os")); //$NON-NLS-1$
- try {
- this.loadWithoutFwPersistentData();
- } catch (IOException e1) {
- // 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());
- StartLevel startLevel = (StartLevel) context.getService(reference);
- Bundle[] bundles = context.getBundles();
- BundleInfo[] bInfos = new BundleInfo[bundles.length];
- for (int i = 0; i < bundles.length; i++) {
- // 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]).getAbsoluteFile().toURI(), -1, true);
- else {
- 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();
- }
- }
- configData.setBundles(bInfos);
- platformProperties = this.getRunningPlatformProperties();
-
- // copy system properties to ConfigData
- Properties props = System.getProperties();
- for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();) {
- String key = (String) enumeration.nextElement();
- String value = props.getProperty(key);
- if (toBeEliminated(key))
- continue;
- configData.setProperty(key, value);
- }
-
- // update initialBundleStartLevel
- int initialBSL = configData.getInitialBundleStartLevel();
- if (initialBSL != startLevelService.getInitialBundleStartLevel())
- configData.setInitialBundleStartLevel(startLevelService.getInitialBundleStartLevel());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator#load()
- */
- public void load() throws IllegalStateException, IOException, FrameworkAdminRuntimeException {
- Log.log(LogService.LOG_DEBUG, this, "load()", "BEGIN"); //$NON-NLS-1$//$NON-NLS-2$
- loadWithoutFwPersistentData();
-
- BundlesState bundlesState = null;
- if (EquinoxBundlesState.checkFullySupported()) {
- bundlesState = new EquinoxBundlesState(context, fwAdmin, this, platformAdmin, !launcherData.isClean());
- platformProperties = ((EquinoxBundlesState) bundlesState).getPlatformProperties();
- } else {
- bundlesState = new SimpleBundlesState(fwAdmin, this, EquinoxConstants.FW_SYMBOLIC_NAME);
- platformProperties.clear();
- }
- updateAccordingToExpectedState(bundlesState);
- // if (!useConfigurator)
- // return;
- setConfiguratorManipulator();
- if (this.configuratorManipulator == null)
- return;
- configuratorManipulator.updateBundles(this);
- return;
- }
-
- private void loadWithoutFwPersistentData() throws IOException {
- SimpleBundlesState.checkAvailability(fwAdmin);
- File launcherConfigFile = getLauncherConfigLocation(launcherData);
- if (launcherConfigFile != null && !launcherConfigFile.getName().endsWith(IGNORED)) {
- // use launcher. -- > load from LaucnherConfig file.
- // the parameters in memory will be updated.
- EclipseLauncherParser parser = new EclipseLauncherParser();
- parser.read(launcherConfigFile, launcherData);
- }
- checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData);
-
- File fwConfigFile = new File(launcherData.getFwConfigLocation(), EquinoxConstants.CONFIG_INI);
- EquinoxFwConfigFileParser parser = new EquinoxFwConfigFileParser(context);
- if (fwConfigFile.exists())
- try {
- parser.readFwConfig(this, fwConfigFile);
- } catch (URISyntaxException e) {
- throw new FrameworkAdminRuntimeException(e, NLS.bind(Messages.exception_errorReadingFile, fwConfigFile.getAbsolutePath()));
- }
- }
-
- // Save all parameter in memory into proper config files.
- public void save(boolean backup) throws IOException, FrameworkAdminRuntimeException {
- Log.log(LogService.LOG_DEBUG, this, "save()", "BEGIN"); //$NON-NLS-1$//$NON-NLS-2$
- SimpleBundlesState.checkAvailability(fwAdmin);
-
- try {
- updateAccordingToExpectedState(this.getBundlesState());
- } catch (IllegalStateException e) {
- // ignore.
- }
-
- boolean stateIsEmpty = configData.getBundles().length == 0;
-
- File launcherConfigFile = getLauncherConfigLocation(launcherData);
- if (launcherConfigFile != null) {
- if (!stateIsEmpty) {
- // Use launcher. -- > save LauncherConfig file.
- EclipseLauncherParser launcherParser = new EclipseLauncherParser();
- launcherParser.save(launcherData, backup);
- } else {
- // No bundles in configuration, so delete the launcher config file
- launcherConfigFile.delete();
- }
- }
-
- checkConsistencyOfFwConfigLocAndFwPersistentDataLoc(launcherData);
-
- 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
- EquinoxFwConfigFileParser parser = new EquinoxFwConfigFileParser(context);
- parser.saveFwConfig(newBInfos.length != 0 ? newBInfos : getConfigData().getBundles(), this, backup, false);
- } else {
- File configDir = launcherData.getFwConfigLocation();
- File outputFile = new File(configDir, EquinoxConstants.CONFIG_INI);
- if (outputFile != null && outputFile.exists()) {
- outputFile.delete();
- }
- if (configDir != null && configDir.exists()) {
- configDir.delete();
- }
- }
- }
-
- public void setConfigData(ConfigData configData) {
- this.configData.initialize();
- this.configData.setInitialBundleStartLevel(configData.getInitialBundleStartLevel());
- this.configData.setBeginningFwStartLevel(configData.getBeginingFwStartLevel());
- BundleInfo[] bInfos = configData.getBundles();
- for (int i = 0; i < bInfos.length; i++)
- this.configData.addBundle(bInfos[i]);
- 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.setProperties(configData.getProperties());
- }
- }
-
- /**
- * 1. get all ServiceReferences of ConfiguratorManipulator.
- * 2. Check if there any ConfiguratorBundle in the Bundles list that can be manipulated by
- * the available ConfiguratorManipulators.
- * 3. Choose the one that will be firstly started among them.
- * 4. set the object that corresponds to the chosen ConfiguratorBundle.
- *
- */
- private ConfiguratorManipulator setConfiguratorManipulator() {
- if (context == null) {
- this.configuratorManipulator = this.fwAdmin.getConfiguratorManipulator();
- return null;
- }
- ServiceReference[] references = cmTracker.getServiceReferences();
- if (references == null)
- return null;
-
- // int count = cmTracker.getTrackingCount();
- // if (count == this.trackingCount)
- // return;
- // this.trackingCount = count;
-
- BundleInfo[] bInfos = configData.getBundles();
- int initialBSL = configData.getInitialBundleStartLevel();
- bInfos = Utils.sortBundleInfos(bInfos, initialBSL);
- //int index = -1;
- ConfiguratorManipulator previousConfiguratorManipulator = configuratorManipulator;
- configuratorManipulator = null;
- for (int i = 0; i < bInfos.length; i++) {
- URI location = bInfos[i].getLocation();
- if (!bInfos[i].isMarkedAsStarted())
- continue;
- for (int j = 0; j < references.length; j++)
- if (references[j].getProperty(ConfiguratorManipulator.SERVICE_PROP_KEY_CONFIGURATOR_BUNDLESYMBOLICNAME).equals(Utils.getPathFromClause(Utils.getManifestMainAttributes(location, Constants.BUNDLE_SYMBOLICNAME)))) {
- configuratorManipulator = (ConfiguratorManipulator) cmTracker.getService(references[j]);
- break;
- }
- if (configuratorManipulator != null)
- break;
- }
- if (configuratorManipulator != previousConfiguratorManipulator)
- return previousConfiguratorManipulator;
- return null;
- }
-
- public void setLauncherData(LauncherData value) {
- launcherData.initialize();
- launcherData.setFwConfigLocation(value.getFwConfigLocation());
- launcherData.setFwPersistentDataLocation(value.getFwPersistentDataLocation(), value.isClean());
- launcherData.setJvm(value.getJvm());
- launcherData.setJvmArgs(value.getJvmArgs());
- launcherData.setOS(value.getOS());
- if (launcherData.getFwName().equals(value.getFwName()))
- if (launcherData.getFwVersion().equals(value.getFwVersion())) {
- // TODO launcherData.getFwName()/getFwVersion()/
- // getLauncherName()/getLauncherVersion() might be taken into consideration
- // for copying .
- launcherData.setFwJar(value.getFwJar());
- launcherData.setHome(value.getHome());
- launcherData.setLauncher(value.getLauncher());
- launcherData.setLauncherConfigLocation(value.getLauncherConfigLocation());
- }
- }
-
- /**
- * Temporal implementation.
- *
- * If a property of the given key should be eliminated
- * from FwDependentProperties and FwIndependentProperties,
- * return true. Otherwise false.
- *
- * @param key
- * @return true if it should be elimineted from FwDependentProperties and FwIndependentProperties,
- */
- private boolean toBeEliminated(String key) {
- if (key.startsWith("java.")) //$NON-NLS-1$
- return true;
- return false;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append("++++++++++++++++++++++++++++++++++++++++++\n" + "Class:" + this.getClass().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- sb.append("------------- LauncherData -----------\n"); //$NON-NLS-1$
- sb.append(launcherData.toString());
- sb.append("------------- ConfigData -----------\n"); //$NON-NLS-1$
- sb.append(configData.toString());
- sb.append("\n" + Utils.toStringProperties("platformProperties", this.platformProperties)); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append("++++++++++++++++++++++++++++++++++++++++++\n"); //$NON-NLS-1$
- return sb.toString();
- }
-
- private void updateAccordingToExpectedState(BundlesState bundlesState) {
- // File newFwJar = EquinoxBundlesState.getFwJar(launcherData, configData);
- // if (bundlesState instanceof EquinoxBundlesState)
- // ((EquinoxBundlesState) bundlesState).setFwJar(newFwJar);
- //
- // if (launcherData.getFwJar() == null && newFwJar != null)
- // launcherData.setFwJar(newFwJar);
- BundleInfo[] newBundleInfos = bundlesState.getExpectedState();
- configData.setBundles(newBundleInfos);
- }
-
- public static String makeRelative(String original, String rootPath) {
- IPath path = new Path(original);
- // ensure we have an absolute path to start with
- if (!path.isAbsolute())
- return original;
-
- //Returns the original string if no relativization has been done
- IPath result = path.makeRelativeTo(new Path(rootPath));
- return path.equals(result) ? original : result.toString();
- }
-
- 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) + one.makeRelativeTo(two);
- }
-
- public static String makeArrayRelative(String array, URL rootURL) {
- StringBuffer buffer = new StringBuffer();
- for (StringTokenizer tokenizer = new StringTokenizer(array, COMMA); tokenizer.hasMoreTokens();) {
- String token = tokenizer.nextToken();
- String absolute = makeRelative(token, rootURL);
- buffer.append(absolute);
- if (tokenizer.hasMoreTokens())
- buffer.append(',');
- }
- return buffer.toString();
- }
-
- public static String makeArrayAbsolute(String array, URL rootURL) {
- StringBuffer buffer = new StringBuffer();
- for (StringTokenizer tokenizer = new StringTokenizer(array, COMMA); tokenizer.hasMoreTokens();) {
- String token = tokenizer.nextToken();
- String absolute = makeAbsolute(token, rootURL);
- buffer.append(absolute);
- if (tokenizer.hasMoreTokens())
- buffer.append(',');
- }
- return buffer.toString();
- }
-
- /*
- * Make the given path absolute to the specified root, if applicable. If not, then
- * return the path as-is.
- *
- * TODO: can we use URIUtil in these #make* methods?
- */
- 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('}', ':');
- }
-
- 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());
- }
-}
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Log.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Log.java
deleted file mode 100644
index e83b92058..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Log.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * 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.frameworkadmin.equinox;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Utility class with static methods for logging to LogService, if available
- */
-public class Log {
- static private ServiceTracker logTracker;
- static private boolean useLog = false;
-
- public static void dispose() {
- if (logTracker != null) {
- logTracker.close();
- }
- logTracker = null;
- }
-
- public static void init(BundleContext bc) {
- logTracker = new ServiceTracker(bc, LogService.class.getName(), null);
- logTracker.open();
- }
-
- public static void log(int level, Object obj, String method, String message) {
- log(level, obj, method, message, null);
- }
-
- public static void log(int level, Object obj, String method, String message, Throwable e) {
- LogService logService = null;
- String msg = "";
- if (method == null) {
- if (obj != null)
- msg = "(" + obj.getClass().getName() + ")";
- } else if (obj == null)
- msg = "[" + method + "]" + message;
- else
- msg = "[" + method + "](" + obj.getClass().getName() + ")";
- msg += message;
- if (logTracker != null)
- logService = (LogService) logTracker.getService();
-
- if (logService != null) {
- logService.log(level, msg, e);
- } else {
- String levelSt = null;
- if (level == LogService.LOG_DEBUG)
- levelSt = "DEBUG";
- else if (level == LogService.LOG_INFO)
- levelSt = "INFO";
- else if (level == LogService.LOG_WARNING)
- levelSt = "WARNING";
- else if (level == LogService.LOG_ERROR) {
- levelSt = "ERROR";
- useLog = true;
- }
- if (useLog) {
- System.err.println("[" + levelSt + "]" + msg);
- if (e != null)
- e.printStackTrace();
- }
- }
- }
-
- public static void log(int level, Object obj, String method, Throwable e) {
- log(level, obj, method, null, e);
- }
-
- public static void log(int level, String message) {
- log(level, null, null, message, null);
- }
-
- public static void log(int level, String message, Throwable e) {
- log(level, null, null, message, e);
- }
-
- private Log() {
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Messages.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Messages.java
deleted file mode 100644
index 2453f7ba3..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/Messages.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 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 - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.frameworkadmin.equinox;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.frameworkadmin.equinox.messages";//$NON-NLS-1$
-
- public static String exception_inputFileIsDirectory;
- public static String exception_fwConfigLocationName;
- public static String exception_failedToCreateDir;
- public static String exception_failedToRename;
- public static String exception_launcherLocationNotSet;
- public static String exception_noInstallArea;
- public static String exception_fileURLExpected;
- public static String exception_bundleManifest;
- public static String exception_createAbsoluteURI;
- public static String exception_nullConfigArea;
- public static String exception_noFrameworkLocation;
- public static String exception_errorSavingConfigIni;
-
- public static String log_configFile;
- public static String log_configProps;
- public static String log_renameSuccessful;
- public static String log_fwConfigSave;
- public static String log_launcherConfigSave;
- public static String log_shared_config_url;
- public static String log_shared_config_relative_url;
- public static String log_shared_config_file_missing;
- public static String log_failed_reading_properties;
- public static String log_failed_make_absolute;
- public static String log_failed_make_relative;
-
- public static String exception_unexpectedfwConfigLocation;
- public static String exception_persistantLocationNotEqualConfigLocation;
- public static String exception_noLocations;
- public static String exception_errorReadingFile;
-
- static {
- // load message values from bundle file
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-} \ No newline at end of file
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
deleted file mode 100644
index ff4c32b12..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 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.List;
-import java.util.Properties;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.frameworkadmin.equinox.utils.FileUtils;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
-import org.eclipse.osgi.service.environment.Constants;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.service.log.LogService;
-
-public class ParserUtils {
- private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
-
- public static File getOSGiInstallArea(List programArgs, Properties properties, LauncherData launcherData) {
- if (launcherData == null)
- return null;
-
- URI base = null;
- if (launcherData.getLauncher() != null)
- base = launcherData.getLauncher().getParentFile().toURI();
- else if (launcherData.getHome() != null)
- base = launcherData.getHome().toURI();
- File result = getOSGiInstallArea(programArgs, properties, base);
- if (result != null)
- return result;
-
- if (launcherData.getHome() != null) {
- return launcherData.getHome();
- }
-
- if (launcherData.getFwJar() != null)
- return fromOSGiJarToOSGiInstallArea(launcherData.getFwJar().getAbsolutePath());
-
- File launcherFile = launcherData.getLauncher();
- if (launcherFile != null) {
- if (Constants.OS_MACOSX.equals(launcherData.getOS())) {
- //the equinox launcher will look 3 levels up on the mac when going from executable to launcher.jar
- //see org.eclipse.equinox.executable/library/eclipse.c : findStartupJar();
- IPath launcherPath = new Path(launcherFile.getAbsolutePath());
- if (launcherPath.segmentCount() > 4) {
- //removing "Eclipse.app/Contents/MacOS/eclipse"
- launcherPath = launcherPath.removeLastSegments(4);
- return launcherPath.toFile();
- }
- }
- return launcherFile.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, NLS.bind(Messages.exception_createAbsoluteURI, fwk, launcherFolder));
- 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, Properties properties, URI base) {
- if (args == null)
- return null;
- String install = getValueForArgument(EquinoxConstants.OPTION_INSTALL, args);
- if (install == null && properties != null)
- install = properties.getProperty("osgi.install.area"); //$NON-NLS-1$
-
- if (install != null) {
- if (install.startsWith(FILE_PROTOCOL))
- install = install.substring(FILE_PROTOCOL.length() + 1);
- File installFile = new File(install);
- if (installFile.isAbsolute())
- return installFile;
- return URIUtil.toFile(URIUtil.makeAbsolute(installFile.toURI(), base));
- }
-
- String startup = getValueForArgument(EquinoxConstants.OPTION_STARTUP, args);
- if (startup != null && base != null) {
- if (startup.startsWith(FILE_PROTOCOL)) {
- try {
- URI startupURI = new URI(startup);
- startup = new File(startupURI).getAbsolutePath();
- } catch (URISyntaxException e) {
- startup = startup.substring(FILE_PROTOCOL.length() + 1);
- }
- }
-
- File osgiInstallArea = fromOSGiJarToOSGiInstallArea(startup);
- if (osgiInstallArea.isAbsolute())
- return osgiInstallArea;
-
- File baseFile = new File(base);
- return new File(baseFile, osgiInstallArea.getPath());
- }
- return null;
- }
-
- public static File fromOSGiJarToOSGiInstallArea(String path) {
- IPath parentFolder = new Path(path).removeLastSegments(1);
- if ("plugins".equalsIgnoreCase(parentFolder.lastSegment())) //$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()) {
- String value = (String) args.get(i + 1);
- if (value != null && value.length() > 0 && value.charAt(0) != '-')
- return value;
- }
- }
- }
- 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()) {
- String nextArg = (String) args.get(i + 1);
- if (nextArg == null || nextArg.charAt(0) != '-') {
- args.set(i + 1, value);
- } else {
- args.add(i + 1, value);
- }
- return true;
- }
- // else just append the value on the end
- args.add(value);
- return true;
- }
- }
- 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(0) != '-') {
- args.set(i + 1, null);
- i++;
- }
- }
- }
- return false;
- }
-}
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/messages.properties b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/messages.properties
deleted file mode 100644
index a5d0d5083..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/messages.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-###############################################################################
-# Copyright (c) 2008, 2010 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
-###############################################################################
-
-exception_inputFileIsDirectory= Illegal Argument: inputFile {0} must not be a directory.
-exception_fwConfigLocationName = Illegal State: Framework Configuration location "{0}" does not match {1}.
-exception_failedToCreateDir = Failed to create directory {0}.
-exception_failedToRename=Failed to rename {0} to {1}.
-exception_launcherLocationNotSet=The launcher location has not been set.
-exception_noInstallArea=Unable to determine osgi.install.area.
-exception_fileURLExpected= The property {0} = {1} is expected to be a \"file:\" URL.
-exception_bundleManifest= Unable to get bundle manifest for: {0}
-exception_createAbsoluteURI=Failed to create absolute URI from \"{0}\" and \"{1}\".
-exception_nullConfigArea=The configuration area is not set.
-exception_noFrameworkLocation = Unable to determinate the osgi.framework location.
-exception_errorSavingConfigIni = Error saving config.ini.
-exception_errorReadingFile = An error occured while reading {0}.
-
-log_configFile= Configuration file ({0}) has been read successfully.
-log_configProps= Configuration properties is empty.
-log_renameSuccessful= Successfully renamed {0} to {1}.
-log_fwConfigSave= Framework Configuration was saved successfully in {0}.
-log_launcherConfigSave= Launcher Configuration was saved successfully in {0}.
-log_shared_config_url=Failed creating shared configuration url for {0}.
-log_shared_config_relative_url=Failed creating shared configuration url for root: {0} and sharedConfiguration: {1}.
-log_shared_config_file_missing=Failed creating shared configuration. File missing: {0}.
-log_failed_reading_properties=Failed reading properties from file: {0}.
-log_failed_make_absolute=Failed to create absolute path for {0}.
-log_failed_make_relative=Failed to create relative path for {0}.
-
-exception_unexpectedfwConfigLocation=The specified framework configuration ({0}) location is not a directory but its name does NOT equal \"{1}\".
-exception_persistantLocationNotEqualConfigLocation=The framework persistent data location ({0}) is not the same as the framework configuration location ({1}).
-exception_noLocations=No locations are set (framework configuration, persistent data, or launcher home).
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
deleted file mode 100644
index e5a439fc3..000000000
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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.utils;
-
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import org.eclipse.core.runtime.*;
-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.eclipse.osgi.service.environment.Constants;
-import org.osgi.framework.Version;
-
-public class FileUtils {
- private static String FILE_SCHEME = "file"; //$NON-NLS-1$
- 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$
-
- // based on org.eclipse.core.runtime.adaptor.EclipseStarter#searchForBundle
- public static URI getEclipseRealLocation(Manipulator manipulator, String location) {
- //if this is some form of URL just return it
- try {
- new URL(location);
- return URIUtil.makeAbsolute(new URI(location), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData()).toURI());
- } catch (URISyntaxException e) {
- // expected
- } catch (MalformedURLException e) {
- // expected
- }
-
- File base = new File(location);
- if (!base.isAbsolute()) {
- String pluginsDir = getSysPath(manipulator);
- if (pluginsDir == null)
- return null;
- base = new File(pluginsDir, location);
- }
-
- return getEclipsePluginFullLocation(base.getName(), base.getParentFile());
- }
-
- //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;
- path = (String) properties.get(EquinoxConstants.PROP_OSGI_FW);
- if (path != null) {
- if (path.startsWith(FILE_PROTOCOL))
- path = path.substring(FILE_PROTOCOL.length());
- File file = new File(path);
- return file.getParentFile().getAbsolutePath();
- }
-
- LauncherData launcherData = manipulator.getLauncherData();
- File home = launcherData.getHome();
- File pluginsDir = null;
- if (home != null)
- pluginsDir = new File(home, EquinoxConstants.PLUGINS_DIR);
- else if (launcherData.getFwJar() != null)
- pluginsDir = launcherData.getFwJar().getParentFile();
- else if (launcherData.getLauncher() != null) {
- File launcherDir = null;
- if (Constants.OS_MACOSX.equals(launcherData.getOS())) {
- IPath launcherPath = new Path(launcherData.getLauncher().getAbsolutePath());
- if (launcherPath.segmentCount() > 4) {
- launcherPath = launcherPath.removeLastSegments(4);
- launcherDir = launcherPath.toFile();
- }
- } else
- launcherDir = launcherData.getLauncher().getParentFile();
- pluginsDir = new File(launcherDir, EquinoxConstants.PLUGINS_DIR);
- }
- if (pluginsDir != null)
- return pluginsDir.getAbsolutePath();
- return null;
- }
-
- public static String removeEquinoxSpecificProtocols(String location) {
- if (location == null)
- return null;
- String ret = location;
- if (location.startsWith(REFERENCE_PROTOCOL))
- ret = location.substring(REFERENCE_PROTOCOL.length());
- else if (location.startsWith(INITIAL_PREFIX))
- ret = location.substring(INITIAL_PREFIX.length());
- return ret;
- }
-
- public static URI getRealLocation(Manipulator manipulator, final String location) {
- return FileUtils.getEclipseRealLocation(manipulator, removeEquinoxSpecificProtocols(location));
- }
-
- /**
- * If a bundle of the specified location is in the Eclipse plugin format (either plugin-name_version.jar
- * or as a folder named plugin-name_version ), return version string.Otherwise, return null;
- *
- * @return version string. If invalid format, return null.
- */
- private static Version getVersion(String version) {
- if (version.length() == 0)
- return Version.emptyVersion;
-
- if (version.endsWith(".jar")) //$NON-NLS-1$
- version = version.substring(0, version.length() - 4);
-
- try {
- return new Version(version);
- } catch (IllegalArgumentException e) {
- // bad format
- return null;
- }
- }
-
- /**
- * Find the named plugin in the given bundlesDir
- * @param pluginName
- * @param bundlesDir
- * @return a URL string for the found plugin, or null
- */
- // Based on org.eclipse.core.runtime.adaptor.EclipseStarter#searchFor
- public static URI getEclipsePluginFullLocation(String pluginName, File bundlesDir) {
- if (bundlesDir == null)
- return null;
- File[] candidates = bundlesDir.listFiles();
- if (candidates == null)
- return null;
-
- File result = null;
- Version maxVersion = null;
-
- for (int i = 0; i < candidates.length; i++) {
- String candidateName = candidates[i].getName();
- if (!candidateName.startsWith(pluginName))
- continue;
-
- if (candidateName.length() > pluginName.length() && candidateName.charAt(pluginName.length()) != '_') {
- // allow jar file with no _version tacked on the end
- if (!candidates[i].isFile() || (candidateName.length() != 4 + pluginName.length()) || !candidateName.endsWith(".jar")) //$NON-NLS-1$
- continue;
- }
-
- String candidateVersion = ""; //$NON-NLS-1$
- if (candidateName.length() > pluginName.length() + 1 && candidateName.charAt(pluginName.length()) == '_')
- candidateVersion = candidateName.substring(pluginName.length() + 1);
-
- Version currentVersion = getVersion(candidateVersion);
- if (currentVersion == null)
- continue;
-
- if (maxVersion == null || maxVersion.compareTo(currentVersion) < 0) {
- maxVersion = currentVersion;
- result = candidates[i];
- }
- }
- return result != null ? result.getAbsoluteFile().toURI() : null;
- }
-
- public static URI fromPath(String path) throws URISyntaxException {
- if (path.startsWith(FILE_PROTOCOL)) {
- try {
- return new URI(path);
- } catch (URISyntaxException e) {
- path = path.substring(FILE_PROTOCOL.length() + 1);
- }
- }
-
- 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_SCHEME.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");
- }
-
- /**
- * Loads an ini file, returning a list of all non-blank lines in the file.
- */
- public static List loadFile(File file) throws IOException {
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(file));
-
- String line;
- List list = new ArrayList();
- while ((line = br.readLine()) != null) {
- //skip whitespace
- if (line.trim().length() > 0)
- list.add(line);
- }
- return list;
- } finally {
- if (br != null)
- try {
- br.close();
- } catch (IOException e) {
- //Ignore
- }
- }
- }
-
-}

Back to the top