Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.touchpoint.eclipse')
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml10
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/LinkAction.java122
3 files changed, 133 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml
index d5d246e69..01940251a 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/plugin.xml
@@ -68,6 +68,16 @@
<extension
point="org.eclipse.equinox.p2.engine.actions">
<action
+ class="org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.LinkAction"
+ name="ln"
+ touchpointType="org.eclipse.equinox.p2.osgi"
+ 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.eclipse.actions.CollectAction"
name="collect"
touchpointType="org.eclipse.equinox.p2.osgi"
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java
index 27a6819a8..4e7cf5ebc 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java
@@ -32,7 +32,7 @@ public class EclipseTouchpoint extends Touchpoint {
public static final String PARM_IU = "iu"; //$NON-NLS-1$
private static final String NATIVE_TOUCHPOINT_ID = "org.eclipse.equinox.p2.touchpoint.natives"; //$NON-NLS-1$
- private static List NATIVE_ACTIONS = Arrays.asList(new String[] {"ln", "mkdir", "rmdir"}); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
+ private static List NATIVE_ACTIONS = Arrays.asList(new String[] {"mkdir", "rmdir"}); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
private static final String VALIDATE_PROFILE = "org.eclipse.equinox.internal.p2.touchpoint.eclipse.validateProfile"; //$NON-NLS-1$
private static Map manipulators = new WeakHashMap();
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/LinkAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/LinkAction.java
new file mode 100644
index 000000000..e18ef9b9b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/LinkAction.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 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.p2.touchpoint.eclipse.actions;
+
+import java.io.*;
+import java.util.Map;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.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.IArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.osgi.util.NLS;
+
+//This is basically a copy of the ln action in the native touchpoint only it provides @artifact support and does not support the backup store.
+//We should just use the native touchpoint copy when we have a replacement for the use of @artifact in parameters
+public class LinkAction extends ProvisioningAction {
+ public static final String ID = "ln"; //$NON-NLS-1$
+
+ public IStatus execute(Map parameters) {
+ String targetDir = (String) parameters.get(ActionConstants.PARM_TARGET_DIR);
+ if (targetDir == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_TARGET_DIR, ID));
+
+ if (targetDir.equals(ActionConstants.PARM_ARTIFACT)) {
+ try {
+ targetDir = resolveArtifactParam(parameters);
+ } catch (CoreException e) {
+ return e.getStatus();
+ }
+ File dir = new File(targetDir);
+ if (!dir.isDirectory()) {
+ return Util.createError(NLS.bind(Messages.artifact_not_directory, dir));
+ }
+ }
+
+ String linkTarget = (String) parameters.get(ActionConstants.PARM_LINK_TARGET);
+ if (linkTarget == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_LINK_TARGET, ID));
+
+ String linkName = (String) parameters.get(ActionConstants.PARM_LINK_NAME);
+ if (linkName == null)
+ return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_LINK_NAME, ID));
+
+ 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) {
+ return null;
+ }
+
+ /**
+ * Creates a link to the source file linkTarget - the created link is targetDir/linkName.
+ * TODO: Only runs on systems with a "ln -s" command supported.
+ * TODO: Does not report errors if the "ln -s" fails
+ * @param targetDir the directory where the link is created
+ * @param linkTarget the source
+ * @param linkName the name of the created link
+ * @param force if overwrite of existing file should be performed.
+ */
+ private void ln(String targetDir, String linkTarget, String linkName, boolean force) {
+
+ Runtime r = Runtime.getRuntime();
+ try {
+ Process process = 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$
+ readOffStream(process.getErrorStream());
+ readOffStream(process.getInputStream());
+ try {
+ process.waitFor();
+ } catch (InterruptedException e) {
+ // mark thread interrupted and continue
+ Thread.currentThread().interrupt();
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+ private void readOffStream(InputStream inputStream) {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+ try {
+ while (reader.readLine() != null) {
+ // do nothing
+ }
+ } catch (IOException e) {
+ // ignore
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ private static String resolveArtifactParam(Map parameters) throws CoreException {
+ IProfile profile = (IProfile) parameters.get(ActionConstants.PARM_PROFILE);
+ IInstallableUnit iu = (IInstallableUnit) parameters.get(EclipseTouchpoint.PARM_IU);
+ IArtifactKey[] artifacts = iu.getArtifacts();
+ if (artifacts == null || artifacts.length == 0)
+ throw new CoreException(Util.createError(NLS.bind(Messages.iu_contains_no_arifacts, iu)));
+
+ IArtifactKey artifactKey = artifacts[0];
+
+ File fileLocation = Util.getArtifactFile(artifactKey, profile);
+ if (fileLocation == null || !fileLocation.exists())
+ throw new CoreException(Util.createError(NLS.bind(Messages.artifact_file_not_found, artifactKey)));
+ return fileLocation.getAbsolutePath();
+ }
+}

Back to the top