Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/man
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2014-06-12 19:15:48 +0000
committerAlexander Kurtakov2014-07-28 08:20:43 +0000
commit754beff64a40d6ae465cbaee19f7107a77bcc2b7 (patch)
tree33c45124c67c7e4b0bb0f21ffa477e7f4922faef /man
parent789298c66263ddb219c26785ddf0e3c9bcc45131 (diff)
downloadorg.eclipse.linuxtools-754beff64a40d6ae465cbaee19f7107a77bcc2b7.tar.gz
org.eclipse.linuxtools-754beff64a40d6ae465cbaee19f7107a77bcc2b7.tar.xz
org.eclipse.linuxtools-754beff64a40d6ae465cbaee19f7107a77bcc2b7.zip
Man: Add support for remote manpages.
Allow for fetching manpages of executables from a remote machine. Also add Linuxtools support for launching remote processes to make this possible. Change-Id: I69b840b2a15d6268ff5d1a42642ff0176646c354 Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com> Reviewed-on: https://git.eclipse.org/r/29064 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'man')
-rw-r--r--man/org.eclipse.linuxtools.man.core/META-INF/MANIFEST.MF6
-rw-r--r--man/org.eclipse.linuxtools.man.core/pom.xml2
-rw-r--r--man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/ManParser.java47
-rw-r--r--man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/Messages.java26
-rw-r--r--man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/messages.properties11
-rw-r--r--man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/man/parser/ManPage.java19
6 files changed, 105 insertions, 6 deletions
diff --git a/man/org.eclipse.linuxtools.man.core/META-INF/MANIFEST.MF b/man/org.eclipse.linuxtools.man.core/META-INF/MANIFEST.MF
index 178bc2efb4..7cd94f24a3 100644
--- a/man/org.eclipse.linuxtools.man.core/META-INF/MANIFEST.MF
+++ b/man/org.eclipse.linuxtools.man.core/META-INF/MANIFEST.MF
@@ -2,11 +2,13 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.linuxtools.man.core;singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Bundle-Activator: org.eclipse.linuxtools.internal.man.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
- org.eclipse.jface.text
+ org.eclipse.jface.text,
+ org.eclipse.linuxtools.tools.launch.core,
+ com.jcraft.jsch
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: org.eclipse.linuxtools.man.parser,
diff --git a/man/org.eclipse.linuxtools.man.core/pom.xml b/man/org.eclipse.linuxtools.man.core/pom.xml
index afa1ef880b..9abaa9c989 100644
--- a/man/org.eclipse.linuxtools.man.core/pom.xml
+++ b/man/org.eclipse.linuxtools.man.core/pom.xml
@@ -23,7 +23,7 @@
</parent>
<artifactId>org.eclipse.linuxtools.man.core</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>Linux Tools Man Plug-in</name>
diff --git a/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/ManParser.java b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/ManParser.java
index fbd5d8b08b..c99631e31c 100644
--- a/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/ManParser.java
+++ b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/ManParser.java
@@ -14,11 +14,15 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.man.Activator;
import org.eclipse.linuxtools.internal.man.preferences.PreferenceConstants;
+import org.eclipse.linuxtools.tools.launch.core.factory.LinuxtoolsProcessFactory;
+
+import com.jcraft.jsch.JSchException;
/**
* Parser for the man executable output.
@@ -35,9 +39,7 @@ public class ManParser {
* @return Raw output of the man command.
*/
public StringBuilder getRawManPage(String manPage) {
- String manExecutable = Activator.getDefault().getPreferenceStore()
- .getString(PreferenceConstants.P_PATH);
- ProcessBuilder builder = new ProcessBuilder(manExecutable, manPage);
+ ProcessBuilder builder = new ProcessBuilder(getManExecutable(), manPage);
builder.redirectErrorStream(true);
Process process;
StringBuilder sb = new StringBuilder();
@@ -63,4 +65,43 @@ public class ManParser {
}
return sb;
}
+
+ /**
+ * Returns the raw representation of the man page of an executable on a
+ * remote machine.
+ *
+ * @param manPage
+ * The man page to fetch.
+ * @param user
+ * The name of the user to access the man page as.
+ * @param host
+ * The name of host where the man page is to be fetched from.
+ * @param password
+ * The user's login password.
+ * @return Raw output of the man command.
+ */
+ public StringBuilder getRemoteRawManPage(String manPage, String user,
+ String host, String password) {
+ final StringBuilder sb = new StringBuilder();
+ OutputStream out = new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ sb.append((char) b);
+ }
+ };
+ try {
+ LinuxtoolsProcessFactory.execRemoteAndWait(new String[] {
+ getManExecutable(), manPage }, out, out, user, host,
+ password);
+ } catch (JSchException e) {
+ sb.setLength(0);
+ sb.append(Messages.ManParser_RemoteAccessError);
+ }
+ return sb;
+ }
+
+ private static String getManExecutable() {
+ return Activator.getDefault().getPreferenceStore()
+ .getString(PreferenceConstants.P_PATH);
+ }
}
diff --git a/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/Messages.java b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/Messages.java
new file mode 100644
index 0000000000..cf5285afe0
--- /dev/null
+++ b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/Messages.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Red Hat Inc.
+ * 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 - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.man.parser;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.man.parser.messages"; //$NON-NLS-1$
+ public static String ManParser_RemoteAccessError;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/messages.properties b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/messages.properties
new file mode 100644
index 0000000000..fcb9f7b579
--- /dev/null
+++ b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/internal/man/parser/messages.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2014 Red Hat Inc. 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:
+# Red Hat - initial API and implementation
+###############################################################################
+ManParser_RemoteAccessError=Could not obtain remote manpage
diff --git a/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/man/parser/ManPage.java b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/man/parser/ManPage.java
index aeb0f98361..7d6d64cb3d 100644
--- a/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/man/parser/ManPage.java
+++ b/man/org.eclipse.linuxtools.man.core/src/org/eclipse/linuxtools/man/parser/ManPage.java
@@ -32,6 +32,25 @@ public class ManPage {
parse(new ManParser().getRawManPage(manPage));
}
+ /**
+ * Creates the man page for an executable on the remote machine with the
+ * specified credentials.
+ *
+ * @param manPage
+ * The man page.
+ * @param user
+ * The name of the user to access the man page as.
+ * @param host
+ * The name of host where the man page is to be fetched from.
+ * @param password
+ * The user's login password.
+ * @since 1.2
+ */
+ public ManPage(String manPage, String user, String host, String password) {
+ parse(new ManParser()
+ .getRemoteRawManPage(manPage, user, host, password));
+ }
+
// TODO make bold and underline be ranges instead of separate symbols.
private void parse(StringBuilder rawManPage) {
StringBuilder sb = new StringBuilder();

Back to the top