) failed -- " + strerror(Native.getLastError()));
- }
- }
- }
-
- // Success ... assign fd's to FileObjects
- Util.assignFd(mfd, master_fd);
- Util.assignFd(sfd, slave_fd);
-
- } catch (PtyException x) {
- CLibrary.INSTANCE.close(mfd);
- CLibrary.INSTANCE.close(sfd);
- throw x;
- }
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/OS.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/OS.java
deleted file mode 100644
index 73d177621b8a..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/OS.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-/**
- * Describes the kind of operating system we're running on.
- *
- * Pty's are notoriously un-standardized. Their use varies subtly between
- * Linux, BSD and Solaris, not to mention MacOS.
- * This enum helps with customization of behaviour.
- * @author ivan
- */
-public enum OS {
-
- OTHER, LINUX, WINDOWS, SOLARIS, MACOS;
-
- /**
- * Returns the kind of OS we're running on.
- * @return The kind of OS we're running on.
- */
- public static OS get() {
- String osName = System.getProperty("os.name");
- osName = osName.toLowerCase();
- // System.out.printf("os.name: \'%s\'\n", osName);
-
- if (osName.startsWith("windows")) {
- return OS.WINDOWS;
- } else if (osName.startsWith("linux")) {
- return OS.LINUX;
- } else if (osName.startsWith("sunos")) {
- return OS.SOLARIS;
- } else if (osName.startsWith("mac os x")) {
- return OS.MACOS ;
- } else {
- return OS.OTHER;
- }
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Platform.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Platform.java
deleted file mode 100644
index f0b8b62abdd7..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Platform.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-/**
- * Describes the kind of platform system running on.
- *
- * Pty's are notoriously un-standardized. Their use varies subtly between
- * Linux, BSD and Solaris, not to mention MacOS.
- * This enum helps with customization of behaviour.
- * @author ivan
- */
-enum Platform {
-
- Other,
-
- LinuxIntel32,
- LinuxIntel64,
-
- WindowsIntel32,
-
- SolarisSparc32,
- SolarisSparc64,
- SolarisIntel32,
- SolarisIntel64,
-
- MacosIntel32;
-
- /**
- * Returns the platform we're running on.
- * @return The kind of platform we're running on.
- */
- public static Platform get() {
- String osName = System.getProperty("os.name").toLowerCase();
- String osArch = System.getProperty("os.arch").toLowerCase();
- // System.out.printf("Platform.get: os.name: \'%s\' os.arch: '%s'\n", osName, osArch);
- if (osName.equals("sunos")) {
- if (osArch.equals("sparc"))
- return SolarisSparc32;
- else if (osArch.equals("sparcv9"))
- return SolarisSparc64;
- else if (osArch.equals("x86"))
- return SolarisIntel32;
- else if (osArch.equals("amd64"))
- return SolarisIntel64;
- else
- return Other;
- } else if (osName.equals("linux")) {
- if (osArch.equals("i386"))
- return LinuxIntel32;
- else if (osArch.equals("amd64"))
- return LinuxIntel64;
- else
- return Other;
- } else if (osName.startsWith("mac os x")) {
- if (osArch.equals("i386"))
- return MacosIntel32;
- else
- return Other;
- } else {
- return Other;
- }
- }
-
- /**
- * Returns the platform string used for finding helper executables.
- * @return One of "linux-intel", "solaris-sparc", "solaris-intel", "mac-intel" or null.
- */
- public String platform() {
- switch (get()) {
- case LinuxIntel32:
- case LinuxIntel64:
- return "linux-intel";
- case SolarisSparc32:
- case SolarisSparc64:
- return "solaris-sparc";
- case SolarisIntel32:
- case SolarisIntel64:
- return "solaris-intel";
- case MacosIntel32:
- return "mac-intel";
- case WindowsIntel32:
- case Other:
- default:
- return null;
- }
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Pty.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Pty.java
deleted file mode 100644
index 39ac6da6d200..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Pty.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Pseudo Terminal.
- *
- * See
- * TerminalEmulatorPty for a full description of
- * what a pty is.
- * @author Ivan Soleimanipour
- */
-public abstract class Pty {
- /**
- * Describes the kind of pty.
- */
- public static enum Mode {
- /**
- * To be used by client to signify that no pty shall be used.
- */
- NONE,
-
- /**
- * NOT IMPLEMENTED YET.
- *
- * A raw pty is effectively the same as a pipe ... and as useless.
- */
- RAW,
-
- /**
- * A standard pty.
- *
- * A regular pty provides:
- *
- * - Line buffering.
- *
- BS and TAB handling.
- *
- Control character handling (^C, ^Z, ^D etc).
- *
- Terminal size propagation.
- *
- */
- REGULAR,
-
- /**
- * NOT IMPLEMENTED YET.
- *
- * An extended functionality pty.
- */
- PACKET
- };
-
- protected FileDescriptor master_fd = new FileDescriptor();
- protected FileDescriptor slave_fd = new FileDescriptor();
- protected String slave_name = null;
- InputStream inputStream;
- OutputStream outputStream;
-
- private Mode mode;
-
- public static Pty create(Mode mode) throws PtyException {
- return new JNAPty(mode);
- }
-
- /**
- * Create a Pty in the given mode.
- *
- * Pty's are a kind of enhanced "named fifos/pipes". The enhancement
- * has to do with terminal related stuff, line discipline and
- * all that. Otherwise they are just conduits of information.
- * In fact that is just what RAW Pty's are.
- *
- * Now there's gotta be something similar to "named fifos" on
- * Windows ... SHOULD look for it.
- *
- * Until then, even if mode is NONE or RAW, we really can't create
- * Ptys on Windows.
- *
- * Note that {@link PtyProcess} and all the higher level stuff that is
- * based on it still works on Windows ... it uses direct Process streams
- * rather than Pty's.
- */
- protected Pty(Mode mode) throws PtyException {
- if (OS.get() == OS.WINDOWS) {
- throw new UnsupportedOperationException("Pty's not supported on windows");
- }
- this.mode = mode;
- setup();
- }
-
- /**
- * Construct the actual physical pty.
- * @throws pty.PtyException
- */
- protected abstract void setup() throws PtyException;
-
- /**
- * Declare the new size of the "terminal" on the master side of this pty.
- *
- * This sends a SIGWINCH to the process on the master side of the pty.
- * The process may then issue ioctl(TIOCGWINSZ, ...) and update it's
- * idea of the terminal size.
- */
- public abstract void masterTIOCSWINSZ(int rows, int cols, int height, int width);
-
- /**
- * Declare the new size of the "terminal" on the slave side of this pty.
- *
- * This sends a SIGWINCH to the process on the slave side of the pty.
- * The process may then issue ioctl(TIOCGWINSZ, ...) and update it's
- * idea of the terminal size.
- */
- public abstract void slaveTIOCSWINSZ(int rows, int cols, int height, int width);
-
- /**
- * Return the mode the pty was created in.
- * @return the mode the pty was created in.
- */
- protected Mode mode() {
- return mode;
- }
-
- /**
- * Return the slave end of the pty which should be opened for reading and
- * writing by the child process.
- *
- * The pty slave is a file like /dev/pts14
.
- * @return The slave end of the pty which should be opened for reading and
- * writing by the child process.
- */
- public String slaveName() {
- return slave_name;
- }
-
- /**
- * Close the slave file descriptor.
- *
- * We don't close the master fd; it usually gets closed when it's
- * reading InputStream gets closed.
- *
- * Until we call this the reader of the master side (a terminal) will
- * not see an EOF, even if the child process has exited. The reason
- * for this is that we maintain a file desriptor for the slave in
- * addition to the one dup'ed for the child process.
- *
- * And the reason for _that_ is that it allows us to manipulate terminal
- * characteristics.
- * @throws java.io.IOException
- */
- public void close() throws IOException {
- // On linux it seems one can manipulate terminal characteristics
- // through the master fd, hence masterTIOCSWINSZ(). So perhaps keeping
- // a slave fd around is pointless.
- // On Solaris it used to be that you could manipulate only
- // from the slave end. Needs more experimentation.
-
- // Can't close fd's directly so create a temporary stream
- (new FileOutputStream(slave_fd)).close();
- }
-
- /**
- * Return an InputStream to be connected to a terminal.
- * @return An InputStream to be connected to a terminal.
- */
- public InputStream getInputStream() {
- openMasterSide();
- return inputStream;
- }
-
- /**
- * Return an OutputStream to be connected to a terminal.
- * @return An OutputStream to be connected to a terminal.
- */
- public OutputStream getOutputStream() {
- openMasterSide();
- return outputStream;
- }
-
- private void openMasterSide() {
- if (inputStream == null) {
- outputStream = new FileOutputStream(master_fd);
- inputStream = new FileInputStream(master_fd);
- }
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyException.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyException.java
deleted file mode 100644
index d24d57124087..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-/**
- * @author Ivan Soleinmanipour
- */
-public class PtyException extends Exception {
- public PtyException(String msg) {
- super(msg);
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyExecutor.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyExecutor.java
deleted file mode 100644
index 01285f110407..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyExecutor.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-import org.netbeans.lib.richexecution.program.Program;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.MissingResourceException;
-import java.util.StringTokenizer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.netbeans.lib.richexecution.Pty.Mode;
-
-/**
- * Execute a {@link Program}, {@link Shell} or {@link Command} connected to a Pty.
- *
- * If the pty is null, as the case might be on Windows, executes the program
- * as {@link java.lang.ProcessBuilder} would.
- * @author ivan
- */
-public final class PtyExecutor {
- private static String setpgrpCmd = null;
- private Mode mode = Mode.REGULAR;
-
- /**
- * Locate executable 'bin' somewhere "near" us.
- *
- * "near" us is in a lib/ directory. That is because 'bin' is not meant
- * for execution by the user who has bin/ in the their $PATH.
- *
- * Where are we?
- * We figure this by using Class.getResource() and massaging the url.
- * But we can be loaded in a variety of contexts so there are a lot
- * of variations.
- *
- * @param bin
- * @return Full pathname to 'bin' or null.
- */
- private static String findBin(String bin) {
- final String myClass =
- "/org/netbeans/lib/richexecution/PtyExecutor.class";
- URL url = PtyExecutor.class.getResource(myClass);
- System.out.printf("findBin(): my resource is \"%s\"\n", url);
- String urlString = url.toString();
-
- // We usually get something like this:
- // jar:file:/home/ivan/work/pty/share/Pty/dist/Pty.jar!/pty/TermProgram.class
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- // Sometimes instead of "jar:" we get "nbjcl:" ... these occur for
- // example if Pty.jar is loaded via a NB library wrapper.
- boolean isJar = false;
- boolean isNbjcl = false;
-
- if (urlString.startsWith("jar:")) {
- isJar = true;
- } else if (urlString.startsWith("nbjcl:")) {
- isNbjcl = true;
- } else if (urlString.startsWith("file:")) {
- ;
- } else {
- System.out.printf("findBin(): " + "can only handle jar: nbjcl: or file: resources but got %s\n", urlString);
- return null;
- }
-
-
- if (isJar || isNbjcl) {
- // Extract the pathname to the jarfile and stuff it back into urlString.
- int colonx = urlString.indexOf(':');
- if (colonx == -1) {
- System.out.printf("findBin(): cannot find \':\' in %s\n", urlString);
- return null;
- }
-
- int bangx = urlString.indexOf('!');
- if (bangx == -1) {
- System.out.printf("findBin(): malformed jar url (no !): %s\n", urlString);
- return null;
- }
- String jarLocation = urlString.substring(colonx + 1, bangx);
- System.out.printf("findBin(): jarLocation \"%s\"\n", jarLocation);
- urlString = jarLocation;
- }
-
- // Now urlString has something like these in it:
- // file:/home/ivan/work/pty/share/Pty/dist/Pty.jar
- // file:/home/ivan/work/pty/share/TermSuite/build/cluster/modules/ext/Pty.jar
- if (urlString.startsWith("file:")) {
- // strip the "file:"
- urlString = urlString.substring(5);
- }
-
- File binFile = null;
- if (isJar || isNbjcl) {
- File jarFile = new File(urlString);
- File installDir = jarFile.getParentFile();
- if (!installDir.getName().equals("lib")) {
- File libDir = new File(installDir, "lib");
- binFile = new File(libDir, bin);
- } else {
- binFile = new File(installDir, bin);
- }
- } else {
- final String classes = "/build/classes";
-
- // strip the pkg/class part
- if (!urlString.endsWith(myClass)) {
- System.out.printf("findBin(): urlString %s doesn\'t end with %s\n", urlString, myClass);
- }
- urlString = urlString.substring(0, urlString.length() - myClass.length());
- System.out.printf("findBin(): classpath \"%s\"\n", urlString);
- if (urlString.endsWith(classes)) {
- String projectDir = urlString.substring(0, urlString.length() - classes.length());
- System.out.printf("findBin(): projectDir \"%s\"\n", projectDir);
- File projectDirFile = new File(projectDir);
- binFile = new File(projectDirFile, bin);
- }
- }
-
- if (binFile != null) {
- if (binFile.exists()) {
- System.out.printf("findBin(): found: %s\n", binFile);
- return binFile.toString();
- } else {
- System.out.printf("findBin(): doesn\'t exist here: %s\n", binFile);
- }
- }
- return null;
- }
-
- /**
- * Find and cache one of /usr/bin/setpgrp or /usr/bin/setsid.
- * We usually get setsid on linux and setpgrp on solaris.
- */
- private static String setpgrpCmd() {
- if (false) {
- return null;
- }
-
- if (OS.get() == OS.MACOS) {
- return null;
- }
- if (setpgrpCmd == null) {
- File file;
- file = new File("/usr/bin/setpgrp");
- if (file.exists()) {
- setpgrpCmd = file.getPath();
- return setpgrpCmd;
- }
- file = new File("/usr/bin/setsid");
- if (file.exists()) {
- setpgrpCmd = file.getPath();
- return setpgrpCmd;
- }
- throw new MissingResourceException("Can\'t find setpgrp or setsid", null, null);
- }
- return setpgrpCmd;
- }
-
- /**
- * Ensure executable is executable.
- * @param executable
- */
- private static void fixExecution(String executable) {
- // The wrapper executables get nunzipped often, like when an NBM
- // is installed, and zip doesn't preserve execution permission bits.
- // So we force it each time.
- String[] chmodProgram = new String[3];
- switch (OS.get()) {
- case LINUX:
- case MACOS:
- case SOLARIS:
- chmodProgram[0] = "chmod";
- chmodProgram[1] = "u+x";
- chmodProgram[2] = executable;
- try {
- Process p = Runtime.getRuntime().exec(chmodProgram);
- p.waitFor();
- } catch (InterruptedException ex) {
- Logger.getLogger(PtyExecutor.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(PtyExecutor.class.getName()).log(Level.SEVERE, null, ex);
- }
- break;
- case WINDOWS:
- case OTHER:
- break;
- }
- }
-
- private static String wrapper;
- private static String pgrp; // set as side-effect of getWrapper()
-
- /**
- * Locate the process_start helper, either as process_start- or,
- * if not found, the fallback process_start.sh".
- */
- private static String getWrapper() {
- if (wrapper == null) {
- if ((wrapper = findBin("process_start" + "-" + Platform.get().platform())) != null) {
- pgrp = null;
- } else if ((wrapper = findBin("process_start.sh")) != null) {
- pgrp = setpgrpCmd();
- } else {
- throw new MissingResourceException("Can\'t find a wrapper", null, null);
- }
- fixExecution(wrapper);
- }
- return wrapper;
- }
-
- private static List wrappedCmd(List cmd, Pty pty) {
- if (pty == null) {
- return cmd;
- }
- List wrapperCmd = new ArrayList();
- if (pgrp != null) {
- wrapperCmd.add(setpgrpCmd());
- }
- wrapperCmd.add(getWrapper());
- wrapperCmd.add("-pty");
- wrapperCmd.add(pty.slaveName());
- wrapperCmd.addAll(cmd);
-
-
- return wrapperCmd;
- }
-
- public final PtyProcess start(Program program, Pty pty) {
- Process process;
- int pid = -1;
- try {
- ProcessBuilder pb = new ProcessBuilder(wrappedCmd(program.command(), pty));
- pb.directory(program.directory());
- pb.environment().putAll(program.environment());
- // LATER
- pb.redirectErrorStream(true /* LATER program.redirectErrorStream() */);
- System.out.printf("\nExecuting %s\n", program.command());
- process = pb.start();
- } catch (IOException ex) {
- Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- }
-
- // On windows ...
- // skip this part, no PID
- // On unixy platforms ...
- // extract pid and other information from the wrapper, 'process_start'.
- if (pty != null) {
- BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
- while (true) {
- String line;
- try {
- line = stdout.readLine();
- if (line == null) {
- break;
- }
- StringTokenizer tokens = new StringTokenizer(line);
- String info = tokens.nextToken();
- if ("PID".equals(info)) {
- String pidString = tokens.nextToken();
- pid = Integer.parseInt(pidString);
- System.out.printf("pid is %d\n", pid);
- } else if ("ARGS".equals(info)) {
- System.out.printf("args is \'%s\'\n", line);
- } else {
- System.err.printf("%s\n", line);
- }
- } catch (IOException ex) {
- Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- return new PtyProcess(process, pid, pty);
- }
-
- /**
- * Set the Pty mode.
- * Should be called before start().
- */
- public void setMode(Mode mode) {
- this.mode = mode;
- }
-
- public Mode getMode() {
- return mode;
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyProcess.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyProcess.java
deleted file mode 100644
index f1977b291996..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/PtyProcess.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * A process being run connected to a Pty.
- *
- * After and partial delegator to {@link java.lang.Process}.
- *
- * Use {@link PtyExecutor} or subclasses thereof to create a PtyProcess.
- *
- *
Closing of the Pty
- * One reason we pass in a Pty is so Ptyprocess can close it when the process
- * exits. The closing of the pty really only closes the slave side file
- * descriptor and that is neccessary so that any master side reader will see
- * an EOF.
- *
- * Why not close the slave side right after the process is created?
- *
- * Because apparently on solaris one can manipulate terminal characteristics,
- * like size changes, only from the slave side. But the key word here is
- * apparently. SHOULD experiment further.
- * @author ivan
- */
-public final class PtyProcess extends java.lang.Process {
-
- private final Process process;
- private final int pid;
- private final Pty pty;
-
- private Runnable reaper;
- private boolean reaped = false;
-
- PtyProcess(Process process, int pid, Pty pty) {
- this.process = process;
- this.pid = pid;
- this.pty = pty;
- }
-
- /**
- * {@inheritDoc}
- */
- public InputStream getInputStream() {
- if (pty == null)
- return process.getInputStream(); // Mode.RAW
- else
- return pty.getInputStream();
- }
-
- /**
- * {@inheritDoc}
- *
- * Note that PtyProcess always has it's error redirected via
- * {@link java.lang.ProcessBuilder#redirectErrorStream}.
- */
- public InputStream getErrorStream() {
- if (pty == null)
- return process.getErrorStream(); // Mode.RAW
- else
- throw new UnsupportedOperationException("No error stream");
- }
-
- /**
- * {@inheritDoc}
- */
- public OutputStream getOutputStream() {
- if (pty == null)
- return process.getOutputStream();
- else
- return pty.getOutputStream();
- }
-
- /**
- * When run() it will block and wait for the started process to exit.
- * @return A Runnable which, when run(), will block and wait for the started
- * process to exit.
- */
- private Runnable getReaper() {
- if (reaper == null) {
- reaper = new Runnable() {
- public void run() {
- try {
- process.waitFor();
- if (pty != null)
- pty.close();
- reaped = true;
- } catch (Exception ex) {
- Logger.getLogger(PtyProcess.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- };
- }
- return reaper;
- }
-
- /**
- * {@inheritDoc}
- */
- public int waitFor() {
- getReaper().run();
- return exitValue();
- }
-
-
- /**
- * Send a SIGHUP to the child.
- *
- * On unix ...
- *
- * java.lang.Process.destroy() sends a SIGTERM to the process.
- * While that usually works for regular processes, shells tend to
- * ignore SIGTERM and instead are sensitive to SIGHUP.
- *
- * Elsewhere ...
- *
- * Same as {@link java.lang.Process#destroy }.
- */
- public void hangup() {
- if (reaped)
- return;
- if (pid == -1) {
- // System.out.printf("No PID -- will try terminating\n");
- process.destroy();
- } else {
- CLibrary.INSTANCE.kill(pid, CLibrary.INSTANCE.SIGHUP());
- }
- }
-
- /**
- * Send a SIGTERM to the child.
- *
- * On unix ...
- *
- * Sends a SIGTERM to the process.
- *
- * Elsewhere ...
- *
- * Same as {@link java.lang.Process#destroy }.
- */
- public void terminate() {
- if (reaped)
- return;
- if (pid == -1) {
- // System.out.printf("No PID -- will try terminating\n");
- process.destroy();
- } else {
- CLibrary.INSTANCE.kill(pid, CLibrary.INSTANCE.SIGTERM());
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void destroy() {
- if (reaped)
- return;
- process.destroy();
- }
-
- public boolean isFinished() {
- return reaped;
- }
-
- /**
- * {@inheritDoc}
- */
- public int exitValue() {
- return process.exitValue();
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Util.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Util.java
deleted file mode 100644
index 780fa8273bd8..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/Util.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution;
-
-import java.io.FileDescriptor;
-import java.lang.reflect.Field;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- *
- * @author ivan
- */
-
-// public because it's needed by "Term Driver".
-public final class Util {
-
- /**
- * Assign a numeric value to the {@link FileDescriptor} object.
- * @param fd Numeric file descriptor value.
- * @param FD Java object.
- */
- public static void assignFd(int fd, FileDescriptor FD) {
- Class cls = FileDescriptor.class;
- try {
- Field fieldFd = cls.getDeclaredField("fd");
- // Allow setting of private fields:
- fieldFd.setAccessible(true);
- fieldFd.setInt(FD, fd);
- } catch (IllegalArgumentException ex) {
- Logger.getLogger(JNAPty.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(JNAPty.class.getName()).log(Level.SEVERE, null, ex);
- } catch (NoSuchFieldException ex) {
- Logger.getLogger(JNAPty.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SecurityException ex) {
- Logger.getLogger(JNAPty.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- /**
- * Get the numeric value to the {@link FileDescriptor} object.
- * @param FD Java object.
- * @return Numeric file descriptor value.
- */
- public static int getFd(FileDescriptor FD) {
- Class cls = FileDescriptor.class;
- try {
- Field fieldFd = cls.getDeclaredField("fd");
- // Allow getting of private fields:
- fieldFd.setAccessible(true);
- return fieldFd.getInt(FD);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(JNAPty.class.getName()).log(Level.SEVERE, null, ex);
- } catch (NoSuchFieldException ex) {
- Logger.getLogger(JNAPty.class.getName()).log(Level.SEVERE, null, ex);
- }
- return -1;
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/package.html b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/package.html
deleted file mode 100644
index c54793b17059..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/package.html
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-Unix-flavored External Process Execution.
-
-While this API is mostly geared to serving process execution under UNIX-based
-environments, it will fall back to reasonable behaviour, no worse than
-standard Java execution, under Windows.
-
-
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Command.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Command.java
deleted file mode 100644
index 7aa4ebd2be2f..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Command.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution.program;
-
-import org.netbeans.lib.richexecution.*;
-import java.util.StringTokenizer;
-
-/**
- * Description of a command to be run under a shell.
- *
- * For example:
- *
- * Program printit = new Command("/bin/cat /etc/termcap");
- *
- *
- * Use {@link PtyExecutor} or subclasses thereof to run the program.
- * @author ivan
- */
-public final class Command extends Shell {
- private final String name;
-
- public Command(String command) {
- StringTokenizer st = new StringTokenizer(command);
- String cmdName = st.nextToken();
- name = basename(cmdName);
-
- if (OS.get() == OS.WINDOWS)
- add("/c");
- else
- add("-c");
- add(command);
- }
-
- /**
- * Return basename of the first word of the command.
- * @return basename of the first word of the command.
- */
- @Override
- public String name() {
- return name;
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Program.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Program.java
deleted file mode 100644
index 6ae588963bda..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Program.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution.program;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Description of a program to be executed.
- * Similar to {@link java.lang.ProcessBuilder} except for the lack of start().
- * Use {@link PtyExecutor} or subclasses thereof to run the program.
- * @author ivan
- */
-public class Program {
- // Use ProcessBuilder strictly as a convenience to hold state
- private final ProcessBuilder processBuilder;
- private List command;
-
- public Program() {
- processBuilder = new ProcessBuilder();
- processBuilder.redirectErrorStream(true);
- command = new ArrayList();
- }
-
- /**
- * After {@link ProcessBuilder#ProcessBuilder(java.util.List)}.
- */
- public Program(List command) {
- if (command == null)
- throw new NullPointerException();
- this.command = command;
- processBuilder = new ProcessBuilder();
- processBuilder.redirectErrorStream(true);
- }
-
- /**
- * After {@link ProcessBuilder#ProcessBuilder(java.lang.String[])}.
- */
- public Program(String... command) {
- processBuilder = new ProcessBuilder();
- processBuilder.redirectErrorStream(true);
- command(command);
- }
-
- public void add(String arg) {
- command.add(arg);
- }
-
- protected String basename(String name) {
- File nameFile = new File(name);
- return nameFile.getName();
- }
-
- public List command() {
- return command;
- }
-
- public void command(List command) {
- if (command == null) {
- throw new NullPointerException();
- }
- this.command = command;
- }
-
- public void command(String... command) {
- this.command = new ArrayList(command.length);
- for (String arg : command) {
- this.command.add(arg);
- }
- }
-
- public File directory() {
- return processBuilder.directory();
- }
-
- public void directory(File directory) {
- processBuilder.directory(directory);
- }
-
- public Map environment() {
- return processBuilder.environment();
- }
-
- public String name() {
- if (command.size() == 0) {
- throw new IllegalStateException("No arguments assigned yet");
- }
- return command.get(0);
- }
-}
diff --git a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Shell.java b/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Shell.java
deleted file mode 100644
index 46e3f1dcf997..000000000000
--- a/lib.terminalemulator/examples/lib.richexecution/src/org/netbeans/lib/richexecution/program/Shell.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.netbeans.lib.richexecution.program;
-
-import org.netbeans.lib.richexecution.OS;
-import org.netbeans.lib.richexecution.PtyExecutor;
-
-/**
- * Description of a shell to be started under a pty.
- *
- * On unix ...
- *
- * The shell defined by $SHELL
is started.
- * If $SHELL
is empty /bin/bash
is started.
- *
- * On windows ...
- *
- * cmd.exe
is started.
- *
- * Use {@link PtyExecutor} or subclasses thereof to run the program.
- * @author ivan
- */
-public class Shell extends Program {
-
- private final static OS os = OS.get();
- private final String name;
-
- private static void error(String fmt, Object...args) {
- String msg = String.format(fmt, args);
- throw new IllegalStateException(msg);
- }
-
-
- public Shell() {
- String shell = System.getenv("SHELL");
-
- if (shell == null)
- shell = "/bin/bash";
-
- switch (os) {
- case WINDOWS:
- add("cmd.exe");
- add("/q"); // turn echo off
- add("/a"); // use ANSI
- name = "cmd.exe";
- break;
-
- case LINUX:
-// add("/usr/bin/strace");
-// add("-o");
-// add("/tmp/rich-cmd.tr");
- add(shell);
- name = basename(shell);
- break;
- case SOLARIS:
-// add("/usr/bin/truss");
-// add("-o");
-// add("/tmp/rich-cmd.tr");
- add(shell);
- name = basename(shell);
- break;
- case MACOS:
- add(shell);
- name = basename(shell);
- break;
- default:
- error("Unsupported os '%s'", os);
- name = "";
- break;
- }
- }
-
- /**
- * Return the basename of the shell being run.
- * @return the basename of the shell being run.
- */
- @Override
- public String name() {
- return name;
- }
-}
diff --git a/lib.terminalemulator/examples/telnet/README b/lib.terminalemulator/examples/telnet/README
deleted file mode 100644
index 5009a3ee004d..000000000000
--- a/lib.terminalemulator/examples/telnet/README
+++ /dev/null
@@ -1,48 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-A simple telnet application
-===========================
-
-TelnetApp implements a simple telnet client based on ...
- org.netbeans.lib.terminalemulator.Term
- de.mud.jta.*
- de.mud.telnet.*
-
-It illustrates ...
-- Simple Term creation and i/o connectivity.
-- Terminal emulation capabilities through setting of the terminal
- type to "ansi".
-
-To run it issue from a shell
- ./telnet
-
-For telnet connectivity it uses portions of
- JTA - Telnet/SSH for the JAVA(tm) platform
-by Matthias L. Jugel and Marcus Meisner at
- http://javassh.org/space/start
-
-I haven't included that stuff under CVS to avoid licensing issues since
-their code is GPL, but you only need:
-
-de/mud/jta/Wrapper.java
-de/mud/telnet/ScriptHandler.java
-de/mud/telnet/TelnetProtocolHandler.java
-de/mud/telnet/TelnetWrapper.java
-
-To build this demo download JTA, copy these files to a local de/ and issue 'ant'
diff --git a/lib.terminalemulator/examples/telnet/TelnetApp.java b/lib.terminalemulator/examples/telnet/TelnetApp.java
deleted file mode 100644
index 6f1a6e48cb59..000000000000
--- a/lib.terminalemulator/examples/telnet/TelnetApp.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-import de.mud.telnet.*;
-
-import org.netbeans.lib.terminalemulator.Term;
-import org.netbeans.lib.terminalemulator.TermInputListener;
-import org.netbeans.lib.terminalemulator.WordDelineator;
-
-
-public class TelnetApp extends JFrame {
- TermInputListener input_listener;
- Term term;
- TelnetWrapper tio;
-
- /*
- * Override de.mud.telnet.TelnetWrapper so we can specialize
- * the terminal type.
- */
- static class MyTelnetWrapper extends TelnetWrapper {
-
- private String terminalType;
-
- MyTelnetWrapper(String terminalType) {
- this.terminalType = terminalType;
- }
-
- public String getTerminalType() {
- return terminalType;
- }
- }
-
- TelnetApp(Font font) {
- super("TelnetApp");
-
- input_listener = new TermInputListener() {
- public void sendChar(char c) {
- // System.out.println(c);
- final char tmp[]= new char[1];
- tmp[0] = c;
- String s = new String(tmp);
- try {
- tio.write(s.getBytes());
- } catch (Exception x) {
- x.printStackTrace();
- }
- }
- public void sendChars(char[] c, int offset, int count) {
- // System.out.println(c);
- String s = new String(c, offset, count);
- try {
- tio.write(s.getBytes());
- } catch (Exception x) {
- x.printStackTrace();
- }
- }
- };
-
- term = new Term();
- term.addInputListener(input_listener);
-
- term.setEmulation("ansi");
- term.setBackground(Color.white);
- term.setClickToType(false);
- term.setHighlightColor(Color.orange);
- term.setWordDelineator(new WordDelineator() {
- public int charClass(char c) {
- if (Character.isJavaIdentifierPart(c))
- return 1;
- else
- return 0;
- }
- } );
- }
-
- public String terminalType() {
- return term.getEmulation();
- }
-
- private void setup_gui() {
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- setContentPane(term);
- pack();
- }
-
- private void setup_telnet(String host, String terminalType) {
- tio = new MyTelnetWrapper(terminalType);
- try {
- System.out.println("connecting to '" + host + "' ...");
- tio.connect(host, 23);
- } catch (Exception x) {
- x.printStackTrace();
- }
- }
-
- private void run() {
- byte[] buf = new byte[512];
- int count;
- while (true) {
- try {
- count = tio.read(buf);
- } catch (Exception x) {
- x.printStackTrace();
- break;
- }
- if (count == -1)
- break;
- String s = new String(buf, 0, count);
- char[] tmp = new char[s.length()];
- s.getChars(0, s.length(), tmp, 0);
- term.putChars(tmp, 0, s.length());
- }
- System.exit(0);
- }
-
- private static void usage(String msg) {
- System.out.println(msg);
- System.out.println("usage: TelnetApp [ ]");
- System.exit(1);
- }
-
- public static void main(String[] args) {
-
- String host = "localhost";
-
- // process cmdline args
- for (int cx = 0; cx < args.length; cx++) {
- if (args[cx].startsWith("-")) {
- usage("Unrecognized option: " + args[cx]);
- } else {
- host = args[cx];
- }
- }
-
- Font term_font = new Font("Helvetica", Font.PLAIN, 10);
- TelnetApp app = new TelnetApp(term_font);
- app.setup_gui();
- app.setVisible(true);
- app.setup_telnet(host, app.terminalType());
- app.run();
- }
-}
diff --git a/lib.terminalemulator/examples/telnet/build.xml b/lib.terminalemulator/examples/telnet/build.xml
deleted file mode 100644
index 80cc43fb6e0c..000000000000
--- a/lib.terminalemulator/examples/telnet/build.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib.terminalemulator/examples/telnet/telnet b/lib.terminalemulator/examples/telnet/telnet
deleted file mode 100644
index 7607418dc54d..000000000000
--- a/lib.terminalemulator/examples/telnet/telnet
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/ksh
-
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-TERM=../../build/classes
-java -classpath "classes:$TERM" TelnetApp $*