From: Tuukka Lehtonen Date: Mon, 9 Jan 2017 20:08:20 +0000 (+0200) Subject: Removed rubbish included in previous commit X-Git-Tag: v1.27.0~29 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=f1b5a0bf9e546ff51e4460140ae529b909a3e188 Removed rubbish included in previous commit org.simantics.msvc.runtime.x86_64 contained copies of other plug-ins, sorry I missed it in the review for some reason. Also put latest versions of Gnuplot and GnuplotSession in since I imported old versions of both on the first try. refs #6945 Change-Id: I7a703e4d76364efb4a5f2bddd568c6064b5d677a --- diff --git a/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/Gnuplot.java b/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/Gnuplot.java index f1321796a..be2eda1dc 100644 --- a/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/Gnuplot.java +++ b/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/Gnuplot.java @@ -19,10 +19,19 @@ public class Gnuplot { private Path executable; - public Gnuplot(Path executable) { + public Gnuplot(Path executable) throws IOException { + if (!Files.exists(executable)) + throw new IOException("Provided gnuplot executable does not exist: " + executable); + if (!Files.isExecutable(executable)) + throw new IOException("Provided gnuplot executable is not marked executable: " + executable); this.executable = executable; } + @Override + public String toString() { + return executable.toString(); + } + public static Gnuplot detect() throws IOException { try { return new Gnuplot(findGnuplotPath()); @@ -104,23 +113,40 @@ public class Gnuplot { } private void execute0(Path workingDirectory, Path stdout, Path stderr, String... cmdline) throws IOException { - Process process = new ProcessBuilder(cmdline) - .directory(workingDirectory.toFile()) - .start(); + ProcessBuilder builder = new ProcessBuilder(cmdline) + .directory(workingDirectory.toFile()); + + if (stdout != null) + builder.redirectOutput(stdout.toFile()); + if (stderr != null) + builder.redirectError(stderr.toFile()); + + Process process = builder.start(); + Thread stdoutDumper = stdout == null ? new Thread(new InputStreamToFileCopier(process.getInputStream(), null)) : null; + Thread stderrDumper = stderr == null ? new Thread(new InputStreamToFileCopier(process.getErrorStream(), null)) : null; + if (stdoutDumper != null) + stdoutDumper.start(); + if (stderrDumper != null) + stderrDumper.start(); + process.getOutputStream().close(); - Thread stdoutDumper = new Thread(new InputStreamToFileCopier(process.getInputStream(), stdout)); - Thread stderrDumper = new Thread(new InputStreamToFileCopier(process.getErrorStream(), stderr)); - stdoutDumper.start(); - stderrDumper.start(); try { - stdoutDumper.join(); - stderrDumper.join(); + if (stdoutDumper != null) + stdoutDumper.join(); + if (stderrDumper != null) + stderrDumper.join(); process.waitFor(); } catch (InterruptedException e) { throw new IOException(e); } } + public void execute(Path workingDirectory, Path stdout, Path stderr, boolean redirectStderr, InputStream input, String charset) throws IOException { + try (GnuplotSession session = newSession(workingDirectory, stdout, stderr, redirectStderr)) { + session.evaluateStream(input, charset); + } + } + public void execute(Path workingDirectory, Path stdout, Path stderr, Path script) throws IOException { execute0(workingDirectory, stdout, stderr, executable.toString(), "-c", script.toString()); } @@ -138,11 +164,24 @@ public class Gnuplot { execute0(workingDirectory, stdout, stderr, executable.toString(), "-e", e.toString()); } - public GnuplotSession newSession(Path workingDirectory, Path stdout, Path stderr) throws IOException { - Process process = new ProcessBuilder(executable.toString()) - .directory(workingDirectory.toFile()) - .start(); - return new GnuplotSession(workingDirectory, stdout, stderr, process); + private ProcessBuilder buildSessionProcess(Path workingDirectory, Path stdout, Path stderr, boolean redirectErrorStream) { + ProcessBuilder builder = new ProcessBuilder(executable.toString()) + .directory(workingDirectory != null ? workingDirectory.toFile() : null) + .redirectErrorStream(redirectErrorStream); + if (stdout != null) + builder.redirectOutput(stdout.toFile()); + if (stderr != null) + builder.redirectError(stderr.toFile()); + return builder; + } + + public GnuplotSession newSession(Path workingDirectory, Path stdout) throws IOException { + return newSession(workingDirectory, stdout, null, true); + } + + public GnuplotSession newSession(Path workingDirectory, Path stdout, Path stderr, boolean redirectStderr) throws IOException { + return new GnuplotSession(workingDirectory, stdout == null, stderr == null, + buildSessionProcess(workingDirectory, stdout, stderr, redirectStderr).start()); } static enum OSType { diff --git a/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/GnuplotSession.java b/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/GnuplotSession.java index 32534e0cf..6bc3e5baf 100644 --- a/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/GnuplotSession.java +++ b/bundles/org.simantics.gnuplot/src/org/simantics/gnuplot/GnuplotSession.java @@ -1,7 +1,10 @@ package org.simantics.gnuplot; +import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; @@ -18,13 +21,17 @@ public class GnuplotSession implements Closeable { private Thread stdoutDumper; private Thread stderrDumper; - GnuplotSession(Path workingDirectory, Path stdout, Path stderr, Process process) { + GnuplotSession(Path workingDirectory, boolean drainStdout, boolean drainStderr, Process process) { this.process = process; this.out = new PrintStream(process.getOutputStream()); - stdoutDumper = new Thread(new InputStreamToFileCopier(process.getInputStream(), stdout)); - stderrDumper = new Thread(new InputStreamToFileCopier(process.getErrorStream(), stderr)); - stdoutDumper.start(); - stderrDumper.start(); + if (drainStdout) { + stdoutDumper = new Thread(new InputStreamToFileCopier(process.getInputStream(), null)); + stdoutDumper.start(); + } + if (drainStderr) { + stderrDumper = new Thread(new InputStreamToFileCopier(process.getErrorStream(), null)); + stderrDumper.start(); + } } private void assertAlive() { @@ -37,6 +44,15 @@ public class GnuplotSession implements Closeable { out.println(commands); } + public void evaluateStream(InputStream input, String charset) throws IOException { + try (BufferedReader br = new BufferedReader(new InputStreamReader(input, charset))) { + for (String line = br.readLine(); null != line; line = br.readLine()) { + out.println(line); + out.println(); + } + } + } + public void evaluateFile(Path file) throws IOException { try { Files.lines(file).forEachOrdered(l -> { @@ -67,8 +83,10 @@ public class GnuplotSession implements Closeable { out.close(); try { // Wait for the outputs to be closed by the process itself. - stdoutDumper.join(); - stderrDumper.join(); + if (stdoutDumper != null) + stdoutDumper.join(); + if (stderrDumper != null) + stderrDumper.join(); p.waitFor(); //System.out.println("gnuplot process ended"); } catch (InterruptedException e) { diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.classpath b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.classpath deleted file mode 100644 index ad32c83a7..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.project b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.project deleted file mode 100644 index 050f09e08..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.simantics.msvc.runtime.x86 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index c537b6306..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/META-INF/MANIFEST.MF b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/META-INF/MANIFEST.MF deleted file mode 100644 index 864f441ec..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/META-INF/MANIFEST.MF +++ /dev/null @@ -1,10 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Microsoft Visual C++ Runtime x86 libraries -Bundle-SymbolicName: org.simantics.msvc.runtime.x86 -Bundle-Version: 10.0.40219.qualifier -Bundle-Vendor: Semantum Oy -Fragment-Host: org.simantics.msvc.runtime -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86)) -Bundle-NativeCode: msvcr100.dll; msvcp100.dll; processor=x86 diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/build.properties b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/build.properties deleted file mode 100644 index 47c6edf6d..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/build.properties +++ /dev/null @@ -1,6 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - msvcp100.dll,\ - msvcr100.dll diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/msvcp100.dll b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/msvcp100.dll deleted file mode 100644 index e9eae444e..000000000 Binary files a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/msvcp100.dll and /dev/null differ diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/msvcr100.dll b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/msvcr100.dll deleted file mode 100644 index fd91c89d8..000000000 Binary files a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime.x86/msvcr100.dll and /dev/null differ diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.classpath b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.classpath deleted file mode 100644 index ad32c83a7..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.project b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.project deleted file mode 100644 index 5c92a7c84..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.simantics.msvc.runtime - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index c537b6306..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/META-INF/MANIFEST.MF b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/META-INF/MANIFEST.MF deleted file mode 100644 index 42eebe12d..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/META-INF/MANIFEST.MF +++ /dev/null @@ -1,11 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Microsoft Visual C++ Runtimes -Bundle-SymbolicName: org.simantics.msvc.runtime -Bundle-Version: 10.0.40219.qualifier -Bundle-Activator: org.simantics.msvc.runtime.Activator -Bundle-Vendor: Semantum Oy -Require-Bundle: org.eclipse.core.runtime -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Bundle-ActivationPolicy: lazy -Export-Package: org.simantics.msvc.runtime diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/build.properties b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/build.properties deleted file mode 100644 index 34d2e4d2d..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/src/org/simantics/msvc/runtime/Activator.java b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/src/org/simantics/msvc/runtime/Activator.java deleted file mode 100644 index b956a448e..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/src/org/simantics/msvc/runtime/Activator.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.simantics.msvc.runtime; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -public class Activator implements BundleActivator { - - private static BundleContext context; - - static BundleContext getContext() { - return context; - } - - /* - * (non-Javadoc) - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext bundleContext) throws Exception { - Activator.context = bundleContext; - Runtimes.initialize(Runtimes.VC_2010); - } - - /* - * (non-Javadoc) - * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext bundleContext) throws Exception { - Activator.context = null; - } - -} diff --git a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/src/org/simantics/msvc/runtime/Runtimes.java b/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/src/org/simantics/msvc/runtime/Runtimes.java deleted file mode 100644 index 31702fd10..000000000 --- a/bundles/org.simantics.msvc.runtime.x86_64/org.simantics.msvc.runtime/src/org/simantics/msvc/runtime/Runtimes.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.simantics.msvc.runtime; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLDecoder; - -import org.eclipse.core.runtime.Path; - -/** - * @author Tuukka Lehtonen - */ -public final class Runtimes { - - public static final String VC_2010 = "vc2010"; - - static boolean vc100Initialized = false; - - public static void initialize(String vc) { - OSType os = OSType.calculate(); - if (os == OSType.WINDOWS) { - if (VC_2010.equals(vc) && !vc100Initialized) { - initializeVC100(); - } - } - } - - static synchronized void initializeVC100() { - try { - // Works in OSGi environment. - System.loadLibrary("msvcr100"); - System.loadLibrary("msvcp100"); - vc100Initialized = true; - } catch (UnsatisfiedLinkError e) { - // Try to load from a workspace in POJO environment. - try { - String archStr = ARCHType.calculate().toString().toLowerCase(); - URL url = Runtimes.class.getResource("."); - File dir = new File(URLDecoder.decode(url.getPath(), "UTF-8") + "../../../../../../org.simantics.msvc.runtime." + archStr); - dir = new Path(dir.getAbsolutePath()).toFile(); - String vcr = new File(dir, "msvcr100.dll").getAbsolutePath(); - String vcp = new File(dir, "msvcp100.dll").getAbsolutePath(); - System.load(vcr); - System.load(vcp); - vc100Initialized = true; - } catch (UnsupportedEncodingException e1) { - throw new Error("UTF-8 not supported, impossible"); - } - } - } - - public enum ARCHType { - PPC, PPC_64, SPARC, X86, X86_64, UNKNOWN; - - public static ARCHType calculate() { - String osArch = System.getProperty("os.arch"); - assert osArch != null; - osArch = osArch.toLowerCase(); - if (osArch.equals("i386") || osArch.equals("i586") || osArch.equals("i686") || osArch.equals("x86")) - return X86; - if (osArch.startsWith("amd64") || osArch.startsWith("x86_64")) - return X86_64; - if (osArch.equals("ppc")) - return PPC; - if (osArch.startsWith("ppc")) - return PPC_64; - if (osArch.startsWith("sparc")) - return SPARC; - return UNKNOWN; - } - } - - public enum OSType { - APPLE, LINUX, SUN, WINDOWS, UNKNOWN; - - public static OSType calculate() { - String osName = System.getProperty("os.name"); - assert osName != null; - osName = osName.toLowerCase(); - if (osName.startsWith("mac os x")) - return APPLE; - if (osName.startsWith("windows")) - return WINDOWS; - if (osName.startsWith("linux")) - return LINUX; - if (osName.startsWith("sun")) - return SUN; - return UNKNOWN; - } - } - -}