package org.eclipse.jdt.internal.launching;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Stream;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.Launch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.internal.core.OutputStreamMonitor;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.AbstractVMInstallType;
import org.eclipse.jdt.launching.ILibraryLocationResolver;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.LibraryLocation;
import org.eclipse.osgi.util.NLS;
public class StandardVMType extends AbstractVMInstallType {
private static final String RT_JAR = "rt.jar";
private static final String SRC = "src";
private static final String SRC_ZIP = "src.zip";
private static final String SRC_JAR = "src.jar";
private static final String JRE = "jre";
private static final String LIB = "lib";
private static final String BAR = "|";
private static final String RELEASE_FILE = "release";
private static final String JAVA_VERSION = "JAVA_VERSION";
private static final String JRT_FS_JAR = "jrt-fs.jar";
public static final String ID_STANDARD_VM_TYPE = "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType";
public static final String MIN_VM_SIZE = "-Xmx16m";
private static FilenameFilter fgArchiveFilter = new FilenameFilter() {
@Override
public boolean accept(File arg0, String arg1) {
return arg1.endsWith(".zip") || arg1.endsWith(".jar");
}
};
private String fDefaultRootPath = "";
private static Map<String, LibraryInfo> fgFailedInstallPath = new HashMap<>();
private static Map<String, List<LibraryLocation>> fgDefaultLibLocs = new HashMap<>();
private static final String[] fgCandidateJavaFiles = {"javaw", "javaw.exe", "java", "java.exe", "j9w", "j9w.exe", "j9", "j9.exe"};
private static final String[] fgCandidateJavaLocations = { File.separator, "bin" + File.separatorChar,
JRE + File.separatorChar + "bin" + File.separatorChar };
private static ILibraryLocationResolver[] fgLibraryLocationResolvers = null;
public static File findJavaExecutable(File vmInstallLocation) {
boolean isBin = false;
String filePath = vmInstallLocation.getPath();
int index = filePath.lastIndexOf(File.separatorChar);
if (index > 0 && filePath.substring(index + 1).equals("bin")) {
isBin = true;
}
for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
for (int j = 0; j < fgCandidateJavaLocations.length; j++) {
if (!isBin && j == 0) {
continue;
}
File javaFile = new File(vmInstallLocation, fgCandidateJavaLocations[j] + fgCandidateJavaFiles[i]);
if (javaFile.isFile()) {
return javaFile;
}
}
}
return null;
}
private static ILibraryLocationResolver[] getLibraryLocationResolvers() {
if( fgLibraryLocationResolvers == null ) {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.ID_PLUGIN, JavaRuntime.EXTENSION_POINT_LIBRARY_LOCATION_RESOLVERS);
IConfigurationElement[] configs = extensionPoint.getConfigurationElements();
Arrays.sort(configs, new Comparator<IConfigurationElement>() {
@Override
public int compare(IConfigurationElement e1, IConfigurationElement e2) {
return e1.getNamespaceIdentifier().compareTo(e2.getNamespaceIdentifier());
}
});
List<ILibraryLocationResolver> resolvers = new ArrayList<>(configs.length);
for( int i = 0; i < configs.length; i++ ) {
IConfigurationElement e = configs[i];
try {
resolvers.add((ILibraryLocationResolver) e.createExecutableExtension("class"));
}
catch (CoreException e1) {
LaunchingPlugin.log(e1.getStatus());
}
}
fgLibraryLocationResolvers = resolvers.toArray(new ILibraryLocationResolver[0]);
}
return fgLibraryLocationResolvers;
}
@Override
public String getName() {
return LaunchingMessages.StandardVMType_Standard_VM_3;
}
@Override
protected IVMInstall doCreateVMInstall(String id) {
return new StandardVM(this, id);
}
protected synchronized LibraryInfo getLibraryInfo(File javaHome, File javaExecutable) {
String installPath = javaHome.getAbsolutePath();
LibraryInfo info = LaunchingPlugin.getLibraryInfo(installPath);
if (info == null || LaunchingPlugin.timeStampChanged(installPath)) {
info = fgFailedInstallPath.get(installPath);
if (info == null) {
String version = readReleaseVersion(javaHome);
if (JavaCore.compareJavaVersions(version, JavaCore.VERSION_1_8) > 0) {
info = new LibraryInfo(version, new String[0], new String[0], new String[0]);
LaunchingPlugin.setLibraryInfo(installPath, info);
} else {
info = generateLibraryInfo(javaHome, javaExecutable);
if (info == null) {
info = generateLibraryInfo(javaHome, javaExecutable);
}
if (info == null) {
info = getDefaultLibraryInfo(javaHome);
fgFailedInstallPath.put(installPath, info);
} else {
LaunchingPlugin.setLibraryInfo(installPath, info);
}
}
}
}
return info;
}
protected boolean canDetectDefaultSystemLibraries(File javaHome, File javaExecutable) {
LibraryLocation[] locations = getDefaultLibraryLocations(javaHome);
String version = getVMVersion(javaHome, javaExecutable);
return locations.length > 0 && !version.startsWith("1.1");
}
protected String getVMVersion(File javaHome, File javaExecutable) {
LibraryInfo info = getLibraryInfo(javaHome, javaExecutable);
return info.getVersion();
}
@Override
public File detectInstallLocation() {
if(Platform.OS_MACOSX.equals(Platform.getOS())) {
return null;
}
return getJavaHomeLocation();
}
protected File getJavaHomeLocation() {
File javaHome;
try {
javaHome= new File (System.getProperty("java.home")).getCanonicalFile();
} catch (IOException e) {
LaunchingPlugin.log(e);
return null;
}
if (!javaHome.exists()) {
return null;
}
File javaExecutable = findJavaExecutable(javaHome);
if (javaExecutable == null) {
return null;
}
boolean foundLibraries = false;
if (javaHome.getName().equalsIgnoreCase(JRE)) {
File parent= new File(javaHome.getParent());
if (canDetectDefaultSystemLibraries(parent, javaExecutable)) {
javaHome = parent;
foundLibraries = true;
}
}
if (!foundLibraries) {
if (!canDetectDefaultSystemLibraries(javaHome, javaExecutable)) {
return null;
}
}
return javaHome;
}
protected IPath getDefaultSystemLibrary(File javaHome) {
IPath jreLibPath= new Path(javaHome.getPath()).append(LIB).append(RT_JAR);
if (jreLibPath.toFile().isFile()) {
return jreLibPath;
}
return new Path(javaHome.getPath()).append(JRE).append(LIB).append(RT_JAR);
}
protected IPath getDefaultSystemLibrarySource(File libLocation) {
File parent= libLocation.getParentFile();
while (parent != null) {
File parentsrc= new File(parent, SRC_JAR);
if (parentsrc.isFile()) {
setDefaultRootPath(SRC);
return new Path(parentsrc.getPath());
}
parentsrc= new File(parent, SRC_ZIP);
if (parentsrc.isFile()) {
setDefaultRootPath("");
return new Path(parentsrc.getPath());
}
parent = parent.getParentFile();
}
IPath result = checkForJ9LibrarySource(libLocation);
if (result != null) {
return result;
}
IPath libName = new Path(libLocation.getName());
String extension = libName.getFileExtension();
String prefix = libName.removeFileExtension().lastSegment();
if (extension != null) {
IPath srcPath = new Path(libLocation.getPath());
srcPath = srcPath.removeLastSegments(1);
StringBuilder buf = new StringBuilder();
buf.append(prefix);
buf.append("-src.");
buf.append(extension);
srcPath = srcPath.append(buf.toString());
if (srcPath.toFile().exists()) {
return srcPath;
}
}
setDefaultRootPath("");
return Path.EMPTY;
}
private IPath checkForJ9LibrarySource(File libLocation) {
File parent= libLocation.getParentFile();
String name = libLocation.getName();
if (name.equalsIgnoreCase("classes.zip")) {
File source = new File(parent, "source/source.zip");
return source.isFile() ? new Path(source.getPath()) : Path.EMPTY;
}
if (name.equalsIgnoreCase("locale.zip")) {
File source = new File(parent, "source/locale-src.zip");
return source.isFile() ? new Path(source.getPath()) : Path.EMPTY;
}
if (name.equalsIgnoreCase("charconv.zip")) {
File source = new File(parent, "charconv-src.zip");
return source.isFile() ? new Path(source.getPath()) : Path.EMPTY;
}
return null;
}
protected IPath getDefaultPackageRootPath() {
return new Path(getDefaultRootPath());
}
@Override
public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
List<LibraryLocation> allLibs = fgDefaultLibLocs.get(installLocation.getAbsolutePath());
if(allLibs == null) {
File javaExecutable = findJavaExecutable(installLocation);
LibraryInfo libInfo;
if (javaExecutable == null) {
libInfo = getDefaultLibraryInfo(installLocation);
} else {
libInfo = getLibraryInfo(installLocation, javaExecutable);
}
allLibs = new ArrayList<>(gatherAllLibraries(libInfo.getEndorsedDirs()));
URL url = getDefaultJavadocLocation(installLocation);
if (libInfo.getBootpath().length == 0) {
IPath sourceRootPath = Path.EMPTY;
IPath path = new Path(installLocation.getAbsolutePath()).append(LIB).append(SRC_ZIP);
File lib = path.toFile();
if (lib.exists() && lib.isFile()) {
sourceRootPath = getDefaultSystemLibrarySource(lib);
} else {
path = new Path(installLocation.getAbsolutePath()).append(SRC_ZIP);
lib = path.toFile();
if (lib.exists() && lib.isFile()) {
sourceRootPath = getDefaultSystemLibrarySource(lib);
}
}
IPath pathName = new Path(installLocation.getAbsolutePath()).append(LIB).append(JRT_FS_JAR);
File jrtfsJar = pathName.toFile();
if (!jrtfsJar.exists()) {
pathName = new Path(installLocation.getAbsolutePath()).append(JRT_FS_JAR);
}
LibraryLocation libraryLocation = new LibraryLocation(pathName,
sourceRootPath, getDefaultPackageRootPath(),
getDefaultJavadocLocation(installLocation));
allLibs.add(libraryLocation);
}
String[] bootpath = libInfo.getBootpath();
List<LibraryLocation> boot = new ArrayList<>(bootpath.length);
for (int i = 0; i < bootpath.length; i++) {
IPath path = new Path(bootpath[i]);
File lib = path.toFile();
if (lib.exists() && lib.isFile()) {
LibraryLocation libraryLocation = new LibraryLocation(path,
getDefaultSystemLibrarySource(lib),
getDefaultPackageRootPath(),
url);
boot.add(libraryLocation);
}
}
allLibs.addAll(boot);
allLibs.addAll(gatherAllLibraries(libInfo.getExtensionDirs()));
HashSet<String> set = new HashSet<>();
LibraryLocation lib = null;
for(ListIterator<LibraryLocation> liter = allLibs.listIterator(); liter.hasNext();) {
lib = liter.next();
IPath systemLibraryPath = lib.getSystemLibraryPath();
String device = systemLibraryPath.getDevice();
if (device != null) {
systemLibraryPath = systemLibraryPath.setDevice(device.toUpperCase());
}
if(!set.add(systemLibraryPath.toOSString())) {
liter.remove();
}
}
fgDefaultLibLocs.put(installLocation.getAbsolutePath(), allLibs);
}
return allLibs.toArray(new LibraryLocation[allLibs.size()]);
}
protected LibraryInfo getDefaultLibraryInfo(File installLocation) {
IPath rtjar = getDefaultSystemLibrary(installLocation);
File extDir = getDefaultExtensionDirectory(installLocation);
File endDir = getDefaultEndorsedDirectory(installLocation);
String[] dirs = null;
if (extDir == null) {
dirs = new String[0];
} else {
dirs = new String[] {extDir.getAbsolutePath()};
}
String[] endDirs = null;
if (endDir == null) {
endDirs = new String[0];
} else {
endDirs = new String[] {endDir.getAbsolutePath()};
}
return new LibraryInfo("???", new String[] {rtjar.toOSString()}, dirs, endDirs);
}
public static List<LibraryLocation> gatherAllLibraries(String[] dirPaths) {
List<LibraryLocation> libraries = new ArrayList<>();
for (int i = 0; i < dirPaths.length; i++) {
File extDir = new File(dirPaths[i]);
if (extDir.isDirectory()) {
String[] names = extDir.list(fgArchiveFilter);
if (names != null) {
for (int j = 0; j < names.length; j++) {
File jar = new File(extDir, names[j]);
if (jar.isFile()) {
try {
IPath libPath = new Path(jar.getCanonicalPath());
IPath sourcePath = Path.EMPTY;
IPath packageRoot = Path.EMPTY;
URL javadocLocation = null;
URL indexLocation = null;
for (ILibraryLocationResolver resolver : getLibraryLocationResolvers()) {
try {
sourcePath = resolver.getSourcePath(libPath);
packageRoot = resolver.getPackageRoot(libPath);
javadocLocation = resolver.getJavadocLocation(libPath);
indexLocation = resolver.getIndexLocation(libPath);
if (sourcePath != Path.EMPTY || packageRoot != Path.EMPTY || javadocLocation != null || indexLocation != null) {
break;
}
} catch(Exception e) {
LaunchingPlugin.log(e);
}
}
LibraryLocation library = new LibraryLocation(libPath, sourcePath, packageRoot, javadocLocation, indexLocation);
libraries.add(library);
} catch (IOException e) {
LaunchingPlugin.log(e);
}
}
}
}
}
}
return libraries;
}
protected File getDefaultExtensionDirectory(File installLocation) {
File jre = null;
if (installLocation.getName().equalsIgnoreCase(JRE)) {
jre = installLocation;
} else {
jre = new File(installLocation, JRE);
}
File lib = new File(jre, LIB);
File ext = new File(lib, "ext");
return ext;
}
protected File getDefaultEndorsedDirectory(File installLocation) {
File lib = new File(installLocation, LIB);
File ext = new File(lib, "endorsed");
return ext;
}
protected String getDefaultRootPath() {
return fDefaultRootPath;
}
protected void setDefaultRootPath(String defaultRootPath) {
fDefaultRootPath = defaultRootPath;
}
@Override
public IStatus validateInstallLocation(File javaHome) {
IStatus status = null;
File javaExecutable = findJavaExecutable(javaHome);
if (javaExecutable == null) {
status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Not_a_JDK_Root__Java_executable_was_not_found_1, null);
} else {
File javaHomeNew = javaHome;
if (canDetectDefaultSystemLibraries(javaHomeNew, javaExecutable)) {
status = new Status(IStatus.OK, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_ok_2, null);
} else {
status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Not_a_JDK_root__System_library_was_not_found__1, null);
}
}
return status;
}
protected LibraryInfo generateLibraryInfo(File javaHome, File javaExecutable) {
LibraryInfo info = null;
IPath classesZip = new Path(javaHome.getAbsolutePath()).append(LIB).append("classes.zip");
if (classesZip.toFile().exists()) {
return new LibraryInfo("1.1.x", new String[] {classesZip.toOSString()}, new String[0], new String[0]);
}
File file = LaunchingPlugin.getFileInPlugin(new Path("lib/launchingsupport.jar"));
if (file != null && file.exists()) {
String javaExecutablePath = javaExecutable.getAbsolutePath();
String[] cmdLine = new String[] { javaExecutablePath, MIN_VM_SIZE,
"-classpath", file.getAbsolutePath(), "org.eclipse.jdt.internal.launching.support.LibraryDetector" };
Process p = null;
try {
String envp[] = null;
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
Map<String, String> map = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironmentCasePreserved();
if (map.remove(StandardVMDebugger.JAVA_JVM_VERSION) != null) {
envp = new String[map.size()];
Iterator<Entry<String, String>> iterator = map.entrySet().iterator();
int i = 0;
while (iterator.hasNext()) {
Entry<String, String> entry = iterator.next();
envp[i] = entry.getKey() + "=" + entry.getValue();
i++;
}
}
}
p = DebugPlugin.exec(cmdLine, null, envp);
IProcess process = DebugPlugin.newProcess(new Launch(null, ILaunchManager.RUN_MODE, null), p, "Library Detection");
process.setAttribute(IProcess.ATTR_CMDLINE, String.join(" ", cmdLine));
IStreamMonitor outputStreamMonitor = process.getStreamsProxy().getOutputStreamMonitor();
for (int i= 0; i < 600; i++) {
if (process.isTerminated() && isReadingDone(outputStreamMonitor)) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
LaunchingPlugin.log(e);
}
}
checkProcessResult(process);
info = parseLibraryInfo(process);
} catch (Throwable ioe) {
LaunchingPlugin.log(ioe);
} finally {
if (p != null) {
p.destroy();
}
}
}
if (info == null) {
LaunchingPlugin.log(NLS.bind("Failed to retrieve default libraries for {0}", new String[]{javaHome.getAbsolutePath()}));
}
return info;
}
@SuppressWarnings("restriction")
private boolean isReadingDone(IStreamMonitor monitor) {
if (monitor instanceof OutputStreamMonitor) {
return ((OutputStreamMonitor) monitor).isReadingDone();
}
return true;
}
protected LibraryInfo parseLibraryInfo(IProcess process) {
IStreamsProxy streamsProxy = process.getStreamsProxy();
String text = null;
if (streamsProxy != null) {
text = streamsProxy.getOutputStreamMonitor().getContents();
}
if (text != null && text.length() > 0) {
int index = text.indexOf(BAR);
if (index > 0) {
String version = text.substring(0, index);
text = text.substring(index + 1);
index = text.indexOf(BAR);
if (index > 0) {
String bootPaths = text.substring(0, index);
String[] bootPath = parsePaths(bootPaths);
text = text.substring(index + 1);
index = text.indexOf(BAR);
if (index > 0) {
String extDirPaths = text.substring(0, index);
String endorsedDirsPath = text.substring(index + 1);
String[] extDirs = parsePaths(extDirPaths);
String[] endDirs = parsePaths(endorsedDirsPath);
return new LibraryInfo(version, bootPath, extDirs, endDirs);
}
}
}
}
return null;
}
protected String[] parsePaths(String paths) {
List<String> list = new ArrayList<>();
int pos = 0;
int index = paths.indexOf(File.pathSeparatorChar, pos);
while (index > 0) {
String path = paths.substring(pos, index);
list.add(path);
pos = index + 1;
index = paths.indexOf(File.pathSeparatorChar, pos);
}
String path = paths.substring(pos);
if (!path.equals("null")) {
list.add(path);
}
return list.toArray(new String[list.size()]);
}
@Override
public void disposeVMInstall(String id) {
IVMInstall vm = findVMInstall(id);
if (vm != null) {
String path = vm.getInstallLocation().getAbsolutePath();
LaunchingPlugin.setLibraryInfo(path, null);
fgFailedInstallPath.remove(path);
fgDefaultLibLocs.remove(path);
}
super.disposeVMInstall(id);
}
@Override
public URL getDefaultJavadocLocation(File installLocation) {
File javaExecutable = findJavaExecutable(installLocation);
if (javaExecutable != null) {
LibraryInfo libInfo = getLibraryInfo(installLocation, javaExecutable);
if (libInfo != null) {
String version = libInfo.getVersion();
return getDefaultJavadocLocation(version);
}
}
return null;
}
public static URL getDefaultJavadocLocation(String version) {
try {
if (version.startsWith(JavaCore.VERSION_13)) {
return new URL("https://docs.oracle.com/en/java/javase/13/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_12)) {
return new URL("https://docs.oracle.com/en/java/javase/12/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_11)) {
return new URL("https://docs.oracle.com/en/java/javase/11/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_10)) {
return new URL("https://docs.oracle.com/javase/10/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_9)) {
return new URL("https://docs.oracle.com/javase/9/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_1_8)) {
return new URL("https://docs.oracle.com/javase/8/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_1_7)) {
return new URL("https://docs.oracle.com/javase/7/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_1_6)) {
return new URL("https://docs.oracle.com/javase/6/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_1_5)) {
return new URL("https://docs.oracle.com/javase/1.5.0/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_1_4)) {
return new URL("https://docs.oracle.com/javase/1.5.0/docs/api/");
} else if (version.startsWith(JavaCore.VERSION_1_3)) {
return new URL("https://docs.oracle.com/javase/1.5.0/docs/api/");
}
} catch (MalformedURLException e) {
}
return null;
}
public synchronized String readReleaseVersion(File javaHome) {
String version = "";
if (Files.notExists(Paths.get(javaHome.getAbsolutePath(), RELEASE_FILE))) {
return version;
}
try (Stream<String> lines = Files.lines(Paths.get(javaHome.getAbsolutePath(), RELEASE_FILE), Charset.defaultCharset()).filter(s -> s.contains(JAVA_VERSION))) {
Optional<String> hasVersion = lines.findFirst();
if (hasVersion.isPresent()) {
String line = hasVersion.get();
version = line.substring(14, line.length() - 1);
}
}
catch (UncheckedIOException | IOException e) {
LaunchingPlugin.log(e);
}
return version;
}
private static void checkProcessResult(IProcess process) throws DebugException {
boolean isTerminated = process.isTerminated();
if (!isTerminated) {
String output = getOutput(process);
Object[] errorInfo = { process.getAttribute(IProcess.ATTR_CMDLINE), output };
String errorMessage = NLS.bind("Process not finished.\n Command line arguments: {0}\nOutput: {1}", errorInfo);
IllegalStateException exception = new IllegalStateException(errorMessage);
LaunchingPlugin.log(exception);
} else {
int exitCode = process.getExitValue();
if (exitCode != 0) {
String output = getOutput(process);
Object[] errorInfo = { Integer.valueOf(exitCode), process.getAttribute(IProcess.ATTR_CMDLINE), output };
String errorMessage = NLS.bind("Process returned with error code \"{0}\".\nCommand line arguments: {1}\nOutput: {2}", errorInfo);
IllegalStateException exception = new IllegalStateException(errorMessage);
LaunchingPlugin.log(exception);
}
}
}
private static String getOutput(IProcess process) {
IStreamsProxy streamsProxy = process.getStreamsProxy();
String output = "IProcess.getStreamsProxy() returned null";
if (streamsProxy != null) {
String[] lines = { "Standard output:",
streamsProxy.getOutputStreamMonitor().getContents(), "Standard error:",
streamsProxy.getErrorStreamMonitor().getContents() };
output = String.join(System.lineSeparator(), Arrays.asList(lines));
}
return output;
}
}