Skip to main content
summaryrefslogtreecommitdiffstats
path: root/p2
diff options
context:
space:
mode:
authorDoug Schaefer2010-04-15 22:38:02 -0400
committerDoug Schaefer2010-04-15 22:38:02 -0400
commit2dd11e7f1e2903f5eaf7bbef377938bfba16b7c5 (patch)
tree7c6146be2e9631b9e44552cc41968332babf61ba /p2
parent57b3b3f6775bfaeeab64349cf56cd08166c14bfb (diff)
downloadorg.eclipse.cdt-2dd11e7f1e2903f5eaf7bbef377938bfba16b7c5.tar.gz
org.eclipse.cdt-2dd11e7f1e2903f5eaf7bbef377938bfba16b7c5.tar.xz
org.eclipse.cdt-2dd11e7f1e2903f5eaf7bbef377938bfba16b7c5.zip
Added translate action.
Diffstat (limited to 'p2')
-rw-r--r--p2/org.eclipse.cdt.p2/plugin.xml10
-rw-r--r--p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/internal/p2/touchpoint/natives/actions/TranslateAction.java103
2 files changed, 113 insertions, 0 deletions
diff --git a/p2/org.eclipse.cdt.p2/plugin.xml b/p2/org.eclipse.cdt.p2/plugin.xml
index 9c25e5449b..c0053db9d9 100644
--- a/p2/org.eclipse.cdt.p2/plugin.xml
+++ b/p2/org.eclipse.cdt.p2/plugin.xml
@@ -21,5 +21,15 @@
version="1.0.0">
</action>
</extension>
+ <extension
+ point="org.eclipse.equinox.p2.engine.actions">
+ <action
+ class="org.eclipse.cdt.internal.p2.touchpoint.natives.actions.TranslateAction"
+ name="org.eclipse.equinox.p2.touchpoint.natives.translate"
+ touchpointType="org.eclipse.equinox.p2.native"
+ touchpointVersion="1.0.0"
+ version="1.0.0">
+ </action>
+ </extension>
</plugin>
diff --git a/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/internal/p2/touchpoint/natives/actions/TranslateAction.java b/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/internal/p2/touchpoint/natives/actions/TranslateAction.java
new file mode 100644
index 0000000000..ffeda880ae
--- /dev/null
+++ b/p2/org.eclipse.cdt.p2/src/org/eclipse/cdt/internal/p2/touchpoint/natives/actions/TranslateAction.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Wind River Systems 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.p2.touchpoint.natives.actions;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.cdt.internal.p2.Activator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ActionConstants;
+import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
+
+/**
+ * Action for post processing files to replace strings based on the install, such
+ * as install location.
+ *
+ * @author Doug Schaefer
+ */
+public class TranslateAction extends ProvisioningAction {
+
+ private static final String PARM_MAP = "map";
+
+ static int n;
+
+ @Override
+ public IStatus execute(Map<String, Object> parameters) {
+ // The file to process
+ String targetFileName = (String)parameters.get(ActionConstants.PARM_TARGET_FILE);
+ File targetFile = new File(targetFileName);
+ if (!targetFile.exists())
+ return new Status(IStatus.WARNING, Activator.PLUGIN_ID, targetFileName + " not found");
+
+ // The replacement map
+ String mapString = (String)parameters.get(PARM_MAP);
+ Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
+ "mapString:" + mapString));
+ String[] mapStrings = mapString.split("!");
+ Map<String, String> map = new HashMap<String, String>();
+ for (int i = 0; i < mapStrings.length; i += 2) {
+ if (i == mapStrings.length - 1)
+ // Odd number of strings
+ break;
+ map.put(mapStrings[i], mapStrings[i + 1]);
+ Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
+ "map:" + mapStrings[i] + ":" + mapStrings[i + 1]));
+ }
+
+
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(targetFile));
+ File tmpFile = new File(targetFile.getParentFile(), "translate" + (n++));
+ FileWriter writer = new FileWriter(tmpFile);
+
+ Pattern pattern = Pattern.compile("!(.*)!");
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ Matcher matcher = pattern.matcher(line);
+ while (matcher.find()) {
+ Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
+ "match:" + matcher.group() + ":" + matcher.group(1)));
+ String value = map.get(matcher.group(1));
+ if (value != null) {
+ line = line.replace(matcher.group(), value);
+ matcher.reset(line);
+ }
+ }
+ writer.write(line);
+ writer.write('\n');
+ }
+
+ reader.close();
+ writer.close();
+
+ targetFile.delete();
+ tmpFile.renameTo(targetFile);
+ } catch (IOException e) {
+ return new Status(IStatus.WARNING, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public IStatus undo(Map<String, Object> parameters) {
+ // No real undo since the file will likely be deleted.
+ return Status.OK_STATUS;
+ }
+
+}

Back to the top