Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Kaegi2008-11-10 19:27:24 +0000
committerSimon Kaegi2008-11-10 19:27:24 +0000
commit04e29098c0b244b86a9e71bdba81dd9a00b7491a (patch)
tree915000417fa1d206a29d0b456b70d2d9637351cb /bundles/org.eclipse.equinox.p2.touchpoint.natives
parent669c6762ffbdffe4c1e42f67344c42a025a255fd (diff)
downloadrt.equinox.p2-04e29098c0b244b86a9e71bdba81dd9a00b7491a.tar.gz
rt.equinox.p2-04e29098c0b244b86a9e71bdba81dd9a00b7491a.tar.xz
rt.equinox.p2-04e29098c0b244b86a9e71bdba81dd9a00b7491a.zip
Bug 252685 [touchpoints] Cleanout redundant actions
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.touchpoint.natives')
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml20
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Activator.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupFiles.java317
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java162
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Permissions.java29
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Util.java67
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Zip.java68
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java20
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java36
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java56
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/LinkAction.java30
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/MkdirAction.java38
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/RmdirAction.java38
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java79
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties12
17 files changed, 372 insertions, 619 deletions
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF
index d41132bf6..3f2f37760 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF
@@ -22,4 +22,5 @@ Eclipse-LazyStart: true
Require-Bundle: org.eclipse.equinox.common
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
-Export-Package: org.eclipse.equinox.internal.p2.touchpoint.natives;x-internal:=true
+Export-Package: org.eclipse.equinox.internal.p2.touchpoint.natives;x-internal:=true,
+ org.eclipse.equinox.internal.p2.touchpoint.natives.actions;x-internal:=true
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml
index c7ac11bef..ac366ee16 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml
@@ -48,6 +48,26 @@
<extension
point="org.eclipse.equinox.p2.engine.actions">
<action
+ class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.MkdirAction"
+ name="mkdir"
+ touchpointType="org.eclipse.equinox.p2.native"
+ touchpointVersion="1.0.0"
+ version="1.0.0">
+ </action>
+ </extension>
+ <extension
+ point="org.eclipse.equinox.p2.engine.actions">
+ <action
+ class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.RmdirAction"
+ name="rmdir"
+ touchpointType="org.eclipse.equinox.p2.native"
+ touchpointVersion="1.0.0"
+ version="1.0.0">
+ </action>
+ </extension>
+ <extension
+ point="org.eclipse.equinox.p2.engine.actions">
+ <action
class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.UnzipAction"
name="unzip"
touchpointType="org.eclipse.equinox.p2.native"
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Activator.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Activator.java
index f45461808..7c5101e3b 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Activator.java
@@ -14,7 +14,7 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
- public static final String ID = "org.eclipse.equinox.p2.touchpoint.native"; //$NON-NLS-1$
+ public static final String ID = "org.eclipse.equinox.p2.touchpoint.natives"; //$NON-NLS-1$
private static BundleContext context = null;
public static BundleContext getContext() {
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupFiles.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupFiles.java
deleted file mode 100644
index 1f3201bfa..000000000
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/BackupFiles.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.touchpoint.natives;
-
-import java.io.*;
-import java.net.URL;
-import java.util.*;
-import java.util.zip.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
-import org.eclipse.osgi.util.NLS;
-
-public class BackupFiles {
-
- private static final String ZIP_SUFFIX = ".zip"; //$NON-NLS-1$
- private static final String PROPERTIES_SUFFIX = ".properties"; //$NON-NLS-1$
-
- private final File backupDir;
- private boolean doBackup;
-
- /**
- * Save or restore backups of files in backupDir
- */
- public BackupFiles(File backupDir) {
- this.doBackup = true;
- this.backupDir = backupDir;
- this.backupDir.mkdirs();
- }
-
- // /**
- // * If doBackup is set to false, files are deleted on uninstall, instead of restored.
- // */
- // public void setDoBackup(boolean doBackup) {
- // this.doBackup = doBackup;
- // }
-
- /**
- * Restore all backups made in this dir.
- */
- public void restore(IProgressMonitor monitor) throws IOException {
- // find backup properties files, do in reverse order
- List propsFiles = new LinkedList();
- for (int i = 0;; i += 1) {
- File propsFile = getBackupProperties(i);
- if (!propsFile.exists()) {
- break;
- }
- propsFiles.add(0, propsFile);
- }
- SubMonitor subMonitor = SubMonitor.convert(monitor, propsFiles.size());
- for (Iterator i = propsFiles.iterator(); i.hasNext();) {
- File propsFile = (File) i.next();
- restoreFilesFromBackup(propsFile, subMonitor.newChild(1));
- }
- if (!this.backupDir.delete()) {
- //not empty? log a warning?
- } else {
- // delete the parent if empty
- this.backupDir.getParentFile().delete();
- }
- monitor.done();
- }
-
- /**
- * Find files under outputDir that will be overwritten in unzipURL
- * and save under backupDir, and delete.
- * Include properties file to indicate files to delete or restore on rolled back.
- * The progress monitor is used only to display sub-tasks; we don't update it otherwise.
- */
- public void backupFilesInZip(String identifier, URL zipURL, File outputDir, IProgressMonitor monitor) throws IOException {
- BackupProperties backupProps = new BackupProperties(identifier, outputDir);
- ZipOutputStream zos = null;
- String prevDir = null;
- try {
- ZipInputStream in = new ZipInputStream(zipURL.openStream());
- ZipEntry ze;
- while ((ze = in.getNextEntry()) != null) {
- String name = ze.getName();
- int i = name.lastIndexOf('/');
- if (i != -1) {
- String dir = name.substring(0, i);
- if (this.doBackup && !dir.equals(prevDir)) {
- monitor.subTask(name.substring(0, i));
- prevDir = dir;
- }
- }
- if (!ze.isDirectory()) {
- File origFile = new File(outputDir, name);
- if (this.doBackup && origFile.exists()) {
- if (zos == null) {
- File zipFile = backupProps.getArchive();
- zos = new ZipOutputStream(new FileOutputStream(zipFile));
- }
- ZipEntry zipEntry = new ZipEntry(name);
- zipEntry.setTime(origFile.lastModified());
- zos.putNextEntry(zipEntry);
- FileUtils.copyStream(new FileInputStream(origFile), true, zos, false);
- zos.closeEntry();
- } else {
- backupProps.addFileToDelete(name);
- }
- origFile.delete();
- }
- in.closeEntry();
- }
- in.close();
- } finally {
- backupProps.store();
- if (zos != null) {
- zos.close();
- }
- }
- }
-
- private void restoreFilesFromBackup(File propsFile, IProgressMonitor monitor) throws IOException {
- BackupProperties backupProps = new BackupProperties(propsFile);
- monitor.beginTask(NLS.bind(Messages.restoring, propsFile.toString()), 3);
- monitor.subTask(""); //$NON-NLS-1$
- for (Iterator i = backupProps.getFilesToDelete().iterator(); i.hasNext();) {
- String name = (String) i.next();
- File full = new File(backupProps.getRootDir(), name);
- full.delete();
- }
- monitor.worked(1);
- File zipFile = backupProps.getArchive();
- if (zipFile.exists()) { // only exists if files were saved
- SubProgressMonitor sub = new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
- FileUtils.unzipFile(zipFile, backupProps.getRootDir(), "", sub); //$NON-NLS-1$
- zipFile.delete();
- } else {
- monitor.worked(1);
- }
- for (Iterator i = backupProps.getDirsToDelete().iterator(); i.hasNext();) {
- String name = (String) i.next();
- File full = new File(backupProps.getRootDir(), name);
- FileUtils.deleteEmptyDirs(full);
- }
- propsFile.delete();
- monitor.worked(1);
- monitor.done();
- }
-
- // Backup files are just 0.properties, 1.properties, etc.
- // Get the next unused one.
- File getBackupProperties() {
- for (int i = 0;; i += 1) {
- File result = getBackupProperties(i);
- if (!result.exists())
- return result;
- }
- }
-
- private File getBackupProperties(int i) {
- return new File(BackupFiles.this.backupDir, Integer.toString(i) + PROPERTIES_SUFFIX);
- }
-
- private class BackupProperties extends Properties {
- private static final long serialVersionUID = 2268313492348533029L;
- private static final char FILE_KIND = 'f';
- private static final char DIR_KIND = 'd';
- private static final String ROOT_DIR = "rootDir"; //$NON-NLS-1$
- private static final String ARTIFACT_KEY = "artifactKey"; //$NON-NLS-1$
- // private static final String ARTIFACT_USER = "artifactUser"; //$NON-NLS-1$
-
- private int n = 0; // number of properties
- private File file; // file to store properties in
- private List keys = new LinkedList(); // keys, in order they were added or read
- private final File rootDir; // root of where files are going
- private Set dirsToCreate = new TreeSet(); // set of dirs we will create
-
- // create properties based on file we are backing up to
- public BackupProperties(String identifier, File rootDir) {
- this.file = BackupFiles.this.getBackupProperties();
- this.rootDir = rootDir;
- setProperty(ROOT_DIR, rootDir.getPath().replace('\\', '/'));
- setProperty(ARTIFACT_KEY, (identifier != null ? identifier : rootDir.getAbsolutePath()));
- // setProperty(ARTIFACT_USER, artifact.toUserString());
- // make sure rootDir is deleted if appropriate
- addDir("./"); //$NON-NLS-1$
- }
-
- // create backup properties from a previously saved BackupProperties
- public BackupProperties(File file) throws IOException {
- this.file = file;
- FileInputStream stream = new FileInputStream(file);
- try {
- load(stream);
- } finally {
- stream.close();
- }
- this.rootDir = new File(getProperty(ROOT_DIR));
- }
-
- // public String getArtifactKey() {
- // return getProperty(ARTIFACT_KEY);
- // }
-
- // public String getArtifactUserString() {
- // String result = getProperty(ARTIFACT_USER);
- // if (result != null) {
- // return result;
- // } else {
- // // return something if the key wasn't saved
- // result = getArtifactKey();
- // result = result.replaceFirst(",native,", ","); //$NON-NLS-1$ //$NON-NLS-2$
- // return result.replace(',', ' ').trim();
- // }
- // }
-
- public File getRootDir() {
- return this.rootDir;
- }
-
- // We are backing up files for this artifact.
- // Create a backup zip based on the artifact key (as a hint).
- public File getArchive() {
- String path = this.file.getPath();
- if (path.endsWith(PROPERTIES_SUFFIX)) {
- path = path.substring(0, path.length() - PROPERTIES_SUFFIX.length());
- }
- return new File(path + ZIP_SUFFIX);
- }
-
- public List getFilesToDelete() {
- return getMatchingProperties(FILE_KIND);
- }
-
- public List getDirsToDelete() {
- return getMatchingProperties(DIR_KIND);
- }
-
- private List getMatchingProperties(char c) {
- List result = new LinkedList();
- for (Enumeration e = propertyNames(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- if (key.equals(BackupProperties.ROOT_DIR)) {
- continue;
- }
- if (key.charAt(0) == c) {
- result.add(getProperty(key));
- }
- }
- return result;
- }
-
- public void addFileToDelete(String name) {
- add(FILE_KIND, name);
- addDir(name);
- }
-
- public void store() throws IOException {
- // add the directories -- at end because we want them all in order
- for (Iterator i = this.dirsToCreate.iterator(); i.hasNext();) {
- String name = (String) i.next();
- add(DIR_KIND, name);
- }
- FileOutputStream stream = new FileOutputStream(this.file);
- try {
- store(stream, /*header*/null);
- } finally {
- stream.close();
- }
- }
-
- public Object put(Object key, Object value) {
- if (!(key instanceof String))
- throw new AssertionError("expected String: " + key); //$NON-NLS-1$
- if (!(value instanceof String))
- throw new AssertionError("expected String: " + value); //$NON-NLS-1$
- this.keys.add(key);
- return super.put(key, value);
- }
-
- // return keys in the order they were added
- public synchronized Enumeration keys() {
- final Iterator iterator = this.keys.iterator();
- return new Enumeration() {
- public boolean hasMoreElements() {
- return iterator.hasNext();
- }
-
- public Object nextElement() {
- return iterator.next();
- }
- };
- }
-
- private void add(char kind, String name) {
- StringBuffer key = new StringBuffer(4);
- key.append(kind).append(n++);
- setProperty(key.toString(), name.replace('\\', '/'));
- }
-
- // if we're going to create this dir, remember that so we delete it
- private void addDir(String name) {
- int slash = name.lastIndexOf('/');
- if (slash == -1)
- return; // no dir
- String dirName = name.substring(0, slash);
- if (this.dirsToCreate.contains(dirName))
- return; // already have it
- if (new File(this.rootDir, dirName).exists())
- return; // already exists
- this.dirsToCreate.add(dirName);
- }
-
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java
index c2d7d1b78..1aae150ef 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java
@@ -10,172 +10,22 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives;
-import java.io.File;
-import java.net.URI;
-import java.util.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.p2.engine.Profile;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
-import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
-import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation;
-import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
+import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
import org.eclipse.equinox.internal.provisional.p2.engine.Touchpoint;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
-import org.eclipse.osgi.util.NLS;
public class NativeTouchpoint extends Touchpoint {
- public static final String PARM_TARGET_FILE = "targetFile"; //$NON-NLS-1$
- public static final String PARM_PERMISSIONS = "permissions"; //$NON-NLS-1$
- public static final String PARM_TARGET_DIR = "targetDir"; //$NON-NLS-1$
- public static final String PARM_TARGET = "target"; //$NON-NLS-1$
- public static final String ACTION_CHMOD = "chmod"; //$NON-NLS-1$
- public static final String PARM_IU = "iu"; //$NON-NLS-1$
- public static final String PIPE = "|"; //$NON-NLS-1$
- public static final String PARM_SOURCE = "source"; //$NON-NLS-1$
- public static final String PARM_ARTIFACT = "@artifact"; //$NON-NLS-1$
- public static final String PARM_INSTALL_FOLDER = "installFolder"; //$NON-NLS-1$
- public static final String ACTION_CLEANUPZIP = "cleanupzip"; //$NON-NLS-1$
- public static final String ACTION_UNZIP = "unzip"; //$NON-NLS-1$
- public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$
- public static final String PARM_OPERAND = "operand"; //$NON-NLS-1$
- public static final String PARM_PROFILE = "profile"; //$NON-NLS-1$
- public static final String ACTION_COLLECT = "collect"; //$NON-NLS-1$
- public static final String ID = "org.eclipse.equinox.p2.touchpoint.natives"; //$NON-NLS-1$
-
- public static IStatus createError(String message) {
- return new Status(IStatus.ERROR, ID, message);
- }
-
- private String getInstallFolder(IProfile profile) {
- return profile.getProperty(IProfile.PROP_INSTALL_FOLDER);
- }
-
- private static AgentLocation getAgentLocation() {
- return (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName());
- }
-
- public static IArtifactRepositoryManager getArtifactRepositoryManager() {
- return (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
- }
- static public IFileArtifactRepository getDownloadCacheRepo() throws ProvisionException {
- URI location = getDownloadCacheLocation();
- if (location == null)
- throw new IllegalStateException(Messages.could_not_obtain_download_cache);
- IArtifactRepositoryManager manager = getArtifactRepositoryManager();
- if (manager == null)
- throw new IllegalStateException(Messages.artifact_repo_not_found);
- IArtifactRepository repository;
- try {
- repository = manager.loadRepository(location, null);
- } catch (ProvisionException e) {
- // the download cache doesn't exist or couldn't be read. Create new cache.
- String repositoryName = location + " - Agent download cache"; //$NON-NLS-1$
- Map properties = new HashMap(1);
- properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString());
- repository = manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
- }
-
- IFileArtifactRepository downloadCache = (IFileArtifactRepository) repository.getAdapter(IFileArtifactRepository.class);
- if (downloadCache == null)
- throw new ProvisionException(NLS.bind(Messages.download_cache_not_writeable, location));
- return downloadCache;
- }
-
- static private URI getDownloadCacheLocation() {
- AgentLocation location = getAgentLocation();
- return (location != null ? location.getArtifactRepositoryURI() : null);
- }
+ public static final String PARM_INSTALL_FOLDER = "installFolder"; //$NON-NLS-1$
public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) {
- touchpointParameters.put(PARM_INSTALL_FOLDER, getInstallFolder(profile));
+ touchpointParameters.put(PARM_INSTALL_FOLDER, Util.getInstallFolder(profile));
return null;
}
- public static IStatus unzip(Map parameters) {
- String source = (String) parameters.get(PARM_SOURCE);
- if (source == null)
- return createError(NLS.bind(Messages.param_not_set, PARM_SOURCE, ACTION_UNZIP));
-
- String originalSource = source;
- String target = (String) parameters.get(PARM_TARGET);
- if (target == null)
- return createError(NLS.bind(Messages.param_not_set, PARM_TARGET, ACTION_UNZIP));
-
- IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
- Profile profile = (Profile) parameters.get(PARM_PROFILE);
-
- if (source.equals(PARM_ARTIFACT)) {
- //TODO: fix wherever this occurs -- investigate as this is probably not desired
- if (iu.getArtifacts() == null || iu.getArtifacts().length == 0)
- return Status.OK_STATUS;
-
- IArtifactKey artifactKey = iu.getArtifacts()[0];
-
- IFileArtifactRepository downloadCache;
- try {
- downloadCache = getDownloadCacheRepo();
- } catch (ProvisionException e) {
- return e.getStatus();
- }
- File fileLocation = downloadCache.getArtifactFile(artifactKey);
- if ((fileLocation == null) || !fileLocation.exists())
- return createError(NLS.bind(Messages.artifact_not_available, artifactKey));
- source = fileLocation.getAbsolutePath();
- }
-
- File[] unzippedFiles = new Zip().unzip(source, target, null);
- StringBuffer unzippedFileNameBuffer = new StringBuffer();
- for (int i = 0; i < unzippedFiles.length; i++)
- unzippedFileNameBuffer.append(unzippedFiles[i].getAbsolutePath()).append(PIPE);
-
- profile.setInstallableUnitProperty(iu, "unzipped" + PIPE + originalSource + PIPE + target, unzippedFileNameBuffer.toString()); //$NON-NLS-1$
-
- return Status.OK_STATUS;
- }
-
- public static IStatus cleanupzip(Map parameters) {
- String source = (String) parameters.get(PARM_SOURCE);
- if (source == null)
- return createError(NLS.bind(Messages.param_not_set, PARM_SOURCE, ACTION_CLEANUPZIP));
- String target = (String) parameters.get(PARM_TARGET);
- if (target == null)
- return createError(NLS.bind(Messages.param_not_set, PARM_TARGET, ACTION_CLEANUPZIP));
-
- IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
- IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
-
- String unzipped = profile.getInstallableUnitProperty(iu, "unzipped" + PIPE + source + PIPE + target); //$NON-NLS-1$
-
- if (unzipped == null)
- return Status.OK_STATUS;
-
- StringTokenizer tokenizer = new StringTokenizer(unzipped, PIPE);
- List directories = new ArrayList();
- while (tokenizer.hasMoreTokens()) {
- String fileName = tokenizer.nextToken();
- File file = new File(fileName);
- if (!file.exists())
- continue;
-
- if (file.isDirectory())
- directories.add(file);
- else
- file.delete();
- }
-
- for (Iterator it = directories.iterator(); it.hasNext();) {
- File directory = (File) it.next();
- directory.delete();
- }
-
- return Status.OK_STATUS;
- }
-
public String qualifyAction(String actionId) {
- return ID + "." + actionId; //$NON-NLS-1$
+ return Activator.ID + "." + actionId; //$NON-NLS-1$
}
}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Permissions.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Permissions.java
deleted file mode 100644
index 927c37c06..000000000
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Permissions.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat Incorporated
- * 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:
- * Red Hat Incorporated - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.touchpoint.natives;
-
-import java.io.IOException;
-import org.eclipse.core.runtime.IPath;
-
-public class Permissions {
- public void chmod(String targetDir, String targetFile, String perms) {
- Runtime r = Runtime.getRuntime();
- try {
- r.exec(new String[] {"chmod", perms, targetDir + IPath.SEPARATOR + targetFile}); //$NON-NLS-1$
- } catch (IOException e) {
- // FIXME: we should probably throw some sort of error here
- }
- }
-
- public void chmod(String target, String targetFile, int perms) {
- chmod(target, targetFile, Integer.toString(perms));
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Util.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Util.java
new file mode 100644
index 000000000..ce42a53f7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Util.java
@@ -0,0 +1,67 @@
+package org.eclipse.equinox.internal.p2.touchpoint.natives;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
+import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation;
+import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
+import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
+import org.eclipse.osgi.util.NLS;
+
+public class Util {
+
+ public static void log(String message) {
+ LogHelper.log(createError(message));
+ }
+
+ public static IStatus createError(String message) {
+ return new Status(IStatus.ERROR, Activator.ID, message);
+ }
+
+ public static String getInstallFolder(IProfile profile) {
+ return profile.getProperty(IProfile.PROP_INSTALL_FOLDER);
+ }
+
+ private static AgentLocation getAgentLocation() {
+ return (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName());
+ }
+
+ public static IArtifactRepositoryManager getArtifactRepositoryManager() {
+ return (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
+ }
+
+ public static IFileArtifactRepository getDownloadCacheRepo() throws ProvisionException {
+ URI location = getDownloadCacheLocation();
+ if (location == null)
+ throw new IllegalStateException(Messages.could_not_obtain_download_cache);
+ IArtifactRepositoryManager manager = getArtifactRepositoryManager();
+ if (manager == null)
+ throw new IllegalStateException(Messages.artifact_repo_not_found);
+ IArtifactRepository repository;
+ try {
+ repository = manager.loadRepository(location, null);
+ } catch (ProvisionException e) {
+ // the download cache doesn't exist or couldn't be read. Create new cache.
+ String repositoryName = location + " - Agent download cache"; //$NON-NLS-1$
+ Map properties = new HashMap(1);
+ properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString());
+ repository = manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
+ }
+
+ IFileArtifactRepository downloadCache = (IFileArtifactRepository) repository.getAdapter(IFileArtifactRepository.class);
+ if (downloadCache == null)
+ throw new ProvisionException(NLS.bind(Messages.download_cache_not_writeable, location));
+ return downloadCache;
+ }
+
+ static private URI getDownloadCacheLocation() {
+ AgentLocation location = getAgentLocation();
+ return (location != null ? location.getArtifactRepositoryURI() : null);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Zip.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Zip.java
deleted file mode 100644
index 721096676..000000000
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Zip.java
+++ /dev/null
@@ -1,68 +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.p2.touchpoint.natives;
-
-import java.io.File;
-import java.io.IOException;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.osgi.util.NLS;
-
-//TODO: Do we need this class or is just using FileUtils.unzip sufficient?
-//TODO Be careful here with the permissions.... We may need to have a proper unzip technology here that supports file permissions for linux
-public class Zip {
- private void log(String message) {
- LogHelper.log(new Status(IStatus.ERROR, Activator.ID, message, null));
- }
-
- public File[] unzip(String source, String destination, String backupDir) {
- // IArtifact artifact = data.getArtifact();
- // String destination = performVariableSubstitutions(data.getDestination());
- // if (canInstallArtifact()) {
- //TODO if artifact has isExploded==true should pass in progress monitor
- // for unzipping
- File zipFile = new File(source);
- if (zipFile == null || !zipFile.exists()) {
- // internal error?
- log(this.getClass().getName() + " the files to be unzipped is not here"); //$NON-NLS-1$
- // throw Util.coreException(null, NLS.bind(Messages.failed_to_download_artifact, source));
- }
-
- try {
- if (backupDir != null) {
- try {
- // backupPM.beginTask(Messages.backing_up, 1);
- BackupFiles backupFiles = new BackupFiles(new File(backupDir));
- backupFiles.backupFilesInZip(backupDir, zipFile.toURL(), new File(destination), null);
- } catch (IOException e) {
- log(this.getClass().getName() + " error backing up the files"); //$NON-NLS-1$
- // throw Util.coreException(e, NLS.bind(Messages.error_backing_up, zipFile));
- } finally {
- // backupPM.done();
- }
- }
- try {
- String taskName = NLS.bind(Messages.unzipping, source);
- return FileUtils.unzipFile(zipFile, new File(destination), taskName, new NullProgressMonitor());
- } catch (IOException e) {
- log(this.getClass().getName() + " error unzipping zipfile: " + zipFile.getAbsolutePath() + "destination: " + destination); //$NON-NLS-1$ //$NON-NLS-2$
- // throw Util.coreException(e.getMessage());
- } finally {
- // unzipPM.done();
- }
- } finally {
- // monitor.done();
- }
- // }
- return null;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java
new file mode 100644
index 000000000..a9cfaba15
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java
@@ -0,0 +1,20 @@
+package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;
+
+public class ActionConstants {
+
+ public static final String PARM_PATH = "path"; //$NON-NLS-1$
+ public static final String PARM_TARGET_FILE = "targetFile"; //$NON-NLS-1$
+ public static final String PARM_PERMISSIONS = "permissions"; //$NON-NLS-1$
+ public static final String PARM_TARGET_DIR = "targetDir"; //$NON-NLS-1$
+ public static final String PARM_TARGET = "target"; //$NON-NLS-1$
+ public static final String PARM_SOURCE = "source"; //$NON-NLS-1$
+ public static final String PARM_IU = "iu"; //$NON-NLS-1$
+ public static final String PIPE = "|"; //$NON-NLS-1$
+ public static final String PARM_ARTIFACT = "@artifact"; //$NON-NLS-1$
+ public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$
+ public static final String PARM_OPERAND = "operand"; //$NON-NLS-1$
+ public static final String PARM_PROFILE = "profile"; //$NON-NLS-1$
+ public static final String PARM_LINK_NAME = "linkName"; //$NON-NLS-1$
+ public static final String PARM_LINK_TARGET = "linkTarget"; //$NON-NLS-1$
+ public static final String PARM_LINK_FORCE = "force"; //$NON-NLS-1$
+}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java
index eab30c987..4f8dfd8a0 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java
@@ -6,30 +6,34 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * Red Hat Incorporated - initial API and implementation
+ * IBM Corporation - ongoing development
*******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;
+import java.io.IOException;
import java.util.Map;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.internal.p2.touchpoint.natives.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
import org.eclipse.osgi.util.NLS;
public class ChmodAction extends ProvisioningAction {
+ private static final String ACTION_CHMOD = "chmod"; //$NON-NLS-1$
+
public IStatus execute(Map parameters) {
- String targetDir = (String) parameters.get(NativeTouchpoint.PARM_TARGET_DIR);
+ String targetDir = (String) parameters.get(ActionConstants.PARM_TARGET_DIR);
if (targetDir == null)
- return NativeTouchpoint.createError(NLS.bind(Messages.param_not_set, NativeTouchpoint.PARM_TARGET_DIR, NativeTouchpoint.ACTION_CHMOD));
- String targetFile = (String) parameters.get(NativeTouchpoint.PARM_TARGET_FILE);
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET_DIR, ACTION_CHMOD));
+ String targetFile = (String) parameters.get(ActionConstants.PARM_TARGET_FILE);
if (targetFile == null)
- return NativeTouchpoint.createError(NLS.bind(Messages.param_not_set, NativeTouchpoint.PARM_TARGET_FILE, NativeTouchpoint.ACTION_CHMOD));
- String permissions = (String) parameters.get(NativeTouchpoint.PARM_PERMISSIONS);
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET_FILE, ACTION_CHMOD));
+ String permissions = (String) parameters.get(ActionConstants.PARM_PERMISSIONS);
if (permissions == null)
- return NativeTouchpoint.createError(NLS.bind(Messages.param_not_set, NativeTouchpoint.PARM_PERMISSIONS, NativeTouchpoint.ACTION_CHMOD));
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_PERMISSIONS, ACTION_CHMOD));
- new Permissions().chmod(targetDir, targetFile, permissions);
+ chmod(targetDir, targetFile, permissions);
return Status.OK_STATUS;
}
@@ -37,4 +41,14 @@ public class ChmodAction extends ProvisioningAction {
//TODO: implement undo ??
return Status.OK_STATUS;
}
+
+ public void chmod(String targetDir, String targetFile, String perms) {
+ Runtime r = Runtime.getRuntime();
+ try {
+ r.exec(new String[] {"chmod", perms, targetDir + IPath.SEPARATOR + targetFile}); //$NON-NLS-1$
+ } catch (IOException e) {
+ // FIXME: we should probably throw some sort of error here
+ }
+ }
+
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java
index 7373df20c..6e1059ecd 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupzipAction.java
@@ -10,17 +10,65 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;
-import java.util.Map;
+import java.io.File;
+import java.util.*;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
+import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.osgi.util.NLS;
public class CleanupzipAction extends ProvisioningAction {
+
+ public static final String ACTION_CLEANUPZIP = "cleanupzip"; //$NON-NLS-1$
+
public IStatus execute(Map parameters) {
- return NativeTouchpoint.cleanupzip(parameters);
+ return cleanupzip(parameters);
}
public IStatus undo(Map parameters) {
- return NativeTouchpoint.unzip(parameters);
+ return UnzipAction.unzip(parameters);
+ }
+
+ public static IStatus cleanupzip(Map parameters) {
+ String source = (String) parameters.get(ActionConstants.PARM_SOURCE);
+ if (source == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_SOURCE, ACTION_CLEANUPZIP));
+ String target = (String) parameters.get(ActionConstants.PARM_TARGET);
+ if (target == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET, ACTION_CLEANUPZIP));
+
+ IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU);
+ IProfile profile = (IProfile) parameters.get(ActionConstants.PARM_PROFILE);
+
+ String unzipped = profile.getInstallableUnitProperty(iu, "unzipped" + ActionConstants.PIPE + source + ActionConstants.PIPE + target); //$NON-NLS-1$
+
+ if (unzipped == null)
+ return Status.OK_STATUS;
+
+ StringTokenizer tokenizer = new StringTokenizer(unzipped, ActionConstants.PIPE);
+ List directories = new ArrayList();
+ while (tokenizer.hasMoreTokens()) {
+ String fileName = tokenizer.nextToken();
+ File file = new File(fileName);
+ if (!file.exists())
+ continue;
+
+ if (file.isDirectory())
+ directories.add(file);
+ else
+ file.delete();
+ }
+
+ for (Iterator it = directories.iterator(); it.hasNext();) {
+ File directory = (File) it.next();
+ directory.delete();
+ }
+
+ return Status.OK_STATUS;
}
+
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java
index 7d22719d0..6fbf20b84 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java
@@ -14,7 +14,7 @@ import java.util.Collection;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
@@ -24,12 +24,14 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
public class CollectAction extends ProvisioningAction {
+ public static final String ACTION_COLLECT = "collect"; //$NON-NLS-1$
+
public IStatus execute(Map parameters) {
- IProfile profile = (IProfile) parameters.get(NativeTouchpoint.PARM_PROFILE);
- InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(NativeTouchpoint.PARM_OPERAND);
+ IProfile profile = (IProfile) parameters.get(ActionConstants.PARM_PROFILE);
+ InstallableUnitOperand operand = (InstallableUnitOperand) parameters.get(ActionConstants.PARM_OPERAND);
try {
IArtifactRequest[] requests = collect(operand.second(), profile);
- Collection artifactRequests = (Collection) parameters.get(NativeTouchpoint.PARM_ARTIFACT_REQUESTS);
+ Collection artifactRequests = (Collection) parameters.get(ActionConstants.PARM_ARTIFACT_REQUESTS);
artifactRequests.add(requests);
} catch (ProvisionException e) {
return e.getStatus();
@@ -46,12 +48,12 @@ public class CollectAction extends ProvisioningAction {
IArtifactKey[] toDownload = installableUnit.getArtifacts();
if (toDownload == null)
return new IArtifactRequest[0];
- IArtifactRepository destination = NativeTouchpoint.getDownloadCacheRepo();
+ IArtifactRepository destination = Util.getDownloadCacheRepo();
IArtifactRequest[] requests = new IArtifactRequest[toDownload.length];
int count = 0;
for (int i = 0; i < toDownload.length; i++) {
//TODO Here there are cases where the download is not necessary again because what needs to be done is just a configuration step
- requests[count++] = NativeTouchpoint.getArtifactRepositoryManager().createMirrorRequest(toDownload[i], destination, null, null);
+ requests[count++] = Util.getArtifactRepositoryManager().createMirrorRequest(toDownload[i], destination, null, null);
}
if (requests.length == count)
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/LinkAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/LinkAction.java
index a70a56868..6cb13d914 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/LinkAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/LinkAction.java
@@ -8,6 +8,7 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;
+import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.eclipse.core.runtime.*;
@@ -18,32 +19,34 @@ import org.eclipse.osgi.util.NLS;
public class LinkAction extends ProvisioningAction {
public static final String ID = "ln"; //$NON-NLS-1$
- public static final String PARM_TARGET_DIR = "targetDir"; //$NON-NLS-1$
- public static final String PARM_LINK_NAME = "linkName"; //$NON-NLS-1$
- public static final String PARM_LINK_TARGET = "linkTarget"; //$NON-NLS-1$
- public static final String PARM_LINK_FORCE = "force"; //$NON-NLS-1$
public IStatus execute(Map parameters) {
- String targetDir = (String) parameters.get(PARM_TARGET_DIR);
+ String targetDir = (String) parameters.get(ActionConstants.PARM_TARGET_DIR);
if (targetDir == null)
- return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, PARM_TARGET_DIR, ID), null);
+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET_DIR, ID), null);
- String linkTarget = (String) parameters.get(PARM_LINK_TARGET);
+ String linkTarget = (String) parameters.get(ActionConstants.PARM_LINK_TARGET);
if (linkTarget == null)
- return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, PARM_LINK_TARGET, ID), null);
+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_LINK_TARGET, ID), null);
- String linkName = (String) parameters.get(PARM_LINK_NAME);
+ String linkName = (String) parameters.get(ActionConstants.PARM_LINK_NAME);
if (linkName == null)
- return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, PARM_LINK_NAME, ID), null);
+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_LINK_NAME, ID), null);
- String force = (String) parameters.get(PARM_LINK_FORCE);
+ String force = (String) parameters.get(ActionConstants.PARM_LINK_FORCE);
ln(targetDir, linkTarget, linkName, Boolean.valueOf(force).booleanValue());
return Status.OK_STATUS;
}
public IStatus undo(Map parameters) {
- // TODO Auto-generated method stub
+ String linkTarget = (String) parameters.get(ActionConstants.PARM_LINK_TARGET);
+ String linkName = (String) parameters.get(ActionConstants.PARM_LINK_NAME);
+
+ if (linkTarget != null && linkName != null) {
+ File linkFile = new File(linkTarget, linkName);
+ linkFile.delete();
+ }
return null;
}
@@ -52,8 +55,7 @@ public class LinkAction extends ProvisioningAction {
try {
r.exec(new String[] {"ln", "-s" + (force ? "f" : ""), linkTarget, targetDir + IPath.SEPARATOR + linkName}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // ignore
}
}
}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/MkdirAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/MkdirAction.java
new file mode 100644
index 000000000..2dccc3aae
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/MkdirAction.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.p2.touchpoint.natives.actions;
+
+import java.io.File;
+import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
+import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
+import org.eclipse.osgi.util.NLS;
+
+public class MkdirAction extends ProvisioningAction {
+ public static final String ID = "mkdir"; //$NON-NLS-1$
+
+ public IStatus execute(Map parameters) {
+ String path = (String) parameters.get(ActionConstants.PARM_PATH);
+ if (path == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_PATH, ID));
+ new File(path).mkdir();
+ return Status.OK_STATUS;
+ }
+
+ public IStatus undo(Map parameters) {
+ String path = (String) parameters.get(ActionConstants.PARM_PATH);
+ if (path == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_PATH, ID));
+ new File(path).delete();
+ return Status.OK_STATUS;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/RmdirAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/RmdirAction.java
new file mode 100644
index 000000000..b8eccc88f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/RmdirAction.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.p2.touchpoint.natives.actions;
+
+import java.io.File;
+import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
+import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
+import org.eclipse.osgi.util.NLS;
+
+public class RmdirAction extends ProvisioningAction {
+ public static final String ID = "rmdir"; //$NON-NLS-1$
+
+ public IStatus execute(Map parameters) {
+ String path = (String) parameters.get(ActionConstants.PARM_PATH);
+ if (path == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_PATH, ID));
+ new File(path).delete();
+ return Status.OK_STATUS;
+ }
+
+ public IStatus undo(Map parameters) {
+ String path = (String) parameters.get(ActionConstants.PARM_PATH);
+ if (path == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_PATH, ID));
+ new File(path).mkdir();
+ return Status.OK_STATUS;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java
index 183f82ba4..4109fe37f 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/UnzipAction.java
@@ -10,18 +10,89 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;
+import java.io.File;
+import java.io.IOException;
import java.util.Map;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.engine.Profile;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.osgi.util.NLS;
public class UnzipAction extends ProvisioningAction {
+ public static final String ACTION_UNZIP = "unzip"; //$NON-NLS-1$
+
public IStatus execute(Map parameters) {
- return NativeTouchpoint.unzip(parameters);
+ return unzip(parameters);
}
public IStatus undo(Map parameters) {
- return NativeTouchpoint.cleanupzip(parameters);
+ return CleanupzipAction.cleanupzip(parameters);
+ }
+
+ public static IStatus unzip(Map parameters) {
+ String source = (String) parameters.get(ActionConstants.PARM_SOURCE);
+ if (source == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_SOURCE, ACTION_UNZIP));
+
+ String originalSource = source;
+ String target = (String) parameters.get(ActionConstants.PARM_TARGET);
+ if (target == null)
+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET, ACTION_UNZIP));
+
+ IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU);
+ Profile profile = (Profile) parameters.get(ActionConstants.PARM_PROFILE);
+
+ if (source.equals(ActionConstants.PARM_ARTIFACT)) {
+ //TODO: fix wherever this occurs -- investigate as this is probably not desired
+ if (iu.getArtifacts() == null || iu.getArtifacts().length == 0)
+ return Status.OK_STATUS;
+
+ IArtifactKey artifactKey = iu.getArtifacts()[0];
+
+ IFileArtifactRepository downloadCache;
+ try {
+ downloadCache = Util.getDownloadCacheRepo();
+ } catch (ProvisionException e) {
+ return e.getStatus();
+ }
+ File fileLocation = downloadCache.getArtifactFile(artifactKey);
+ if ((fileLocation == null) || !fileLocation.exists())
+ return Util.createError(NLS.bind(Messages.artifact_not_available, artifactKey));
+ source = fileLocation.getAbsolutePath();
+ }
+
+ File[] unzippedFiles = unzip(source, target, null);
+ StringBuffer unzippedFileNameBuffer = new StringBuffer();
+ for (int i = 0; i < unzippedFiles.length; i++)
+ unzippedFileNameBuffer.append(unzippedFiles[i].getAbsolutePath()).append(ActionConstants.PIPE);
+
+ profile.setInstallableUnitProperty(iu, "unzipped" + ActionConstants.PIPE + originalSource + ActionConstants.PIPE + target, unzippedFileNameBuffer.toString()); //$NON-NLS-1$
+
+ return Status.OK_STATUS;
+ }
+
+ // this is a drastically simplified version of the code that was in org.eclipse.equinox.internal.p2.touchpoint.natives (Zip, BackupFiles)
+ // In particular backing up files might be useful to look at
+ private static File[] unzip(String source, String destination, String backupDir) {
+ File zipFile = new File(source);
+ if (zipFile == null || !zipFile.exists()) {
+ Util.log(UnzipAction.class.getName() + " the files to be unzipped is not here"); //$NON-NLS-1$
+ }
+
+ try {
+ String taskName = NLS.bind(Messages.unzipping, source);
+ return FileUtils.unzipFile(zipFile, new File(destination), taskName, new NullProgressMonitor());
+ } catch (IOException e) {
+ Util.log(UnzipAction.class.getName() + " error unzipping zipfile: " + zipFile.getAbsolutePath() + "destination: " + destination); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties
index b18ba373f..50d361bb7 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties
@@ -1,8 +1,5 @@
-artifact_repo_not_found=The artifact repository manager could not be found.
-could_not_obtain_download_cache=Could not obtain the download cache location.
-download_cache_not_writeable=Agent download cache not writeable: {0}.
###############################################################################
-# Copyright (c) 2007 IBM Corporation and others.
+# 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
@@ -12,13 +9,12 @@ download_cache_not_writeable=Agent download cache not writeable: {0}.
# IBM Corporation - initial API and implementation
###############################################################################
-# NativeInstallAdapter
artifact_not_available=The artifact for {0} is not available.
restoring=Restoring {0}
-
-
unzipping=Extracting {0}
-
param_not_set=The \"{0}\" parameter was not set in the \"{1}\" action.
+artifact_repo_not_found=The artifact repository manager could not be found.
+could_not_obtain_download_cache=Could not obtain the download cache location.
+download_cache_not_writeable=Agent download cache not writeable: {0}.

Back to the top