Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2015-05-11 17:44:19 +0000
committerRoland Grunberg2015-05-19 14:32:59 +0000
commit6b96d3294377abf5cb669024b1d69b935400bbf1 (patch)
tree23f1807801456dee5038f78a5ce66037f2d9dd0c
parentf2108c1f951752182479761bcee781d5371b987e (diff)
downloadorg.eclipse.linuxtools-6b96d3294377abf5cb669024b1d69b935400bbf1.tar.gz
org.eclipse.linuxtools-6b96d3294377abf5cb669024b1d69b935400bbf1.tar.xz
org.eclipse.linuxtools-6b96d3294377abf5cb669024b1d69b935400bbf1.zip
Bug 466857: Extract script.sh for eventual execution.
The resources/script.sh file in the core plugin cannot be executed from within the embedded jar when the plugin is distributed so it must be extracted first. Change-Id: Id613441d26d7a8b2012c70c79225532535cf4e87 Reviewed-on: https://git.eclipse.org/r/47660 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/build.properties3
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java30
2 files changed, 26 insertions, 7 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/build.properties b/containers/org.eclipse.linuxtools.docker.core/build.properties
index 34d2e4d2da..342f3ffdb3 100644
--- a/containers/org.eclipse.linuxtools.docker.core/build.properties
+++ b/containers/org.eclipse.linuxtools.docker.core/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ resources/
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index f41b14173d..95b9b0223e 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -20,6 +20,7 @@ import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.UN
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -42,11 +43,9 @@ import java.util.Set;
import jnr.unixsocket.UnixSocketAddress;
import jnr.unixsocket.UnixSocketChannel;
-import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -117,6 +116,26 @@ public class DockerConnection implements IDockerConnection {
private final Map<EnumDockerConnectionSettings, Object> settings = new HashMap<>();
public Defaults() throws DockerException {
+ File scriptFile = Activator.getDefault().getBundle()
+ .getDataFile("script.sh"); //$NON-NLS-1$
+ if (!scriptFile.exists()) {
+ InputStream is = DockerConnection.class
+ .getResourceAsStream("/resources/script.sh"); //$NON-NLS-1$
+ FileOutputStream fo;
+ try {
+ byte[] buff = new byte[1024];
+ fo = new FileOutputStream(scriptFile);
+ int n;
+ while ((n = is.read(buff)) > 0) {
+ fo.write(buff, 0, n);
+ }
+ fo.close();
+ is.close();
+ scriptFile.setExecutable(true);
+ } catch (IOException e) {
+ Activator.logErrorMessage(e.getMessage());
+ }
+ }
// first, looking for a Unix socket at /var/run/docker.sock
if (defaultsWithUnixSocket() || defaultsWithSystemEnv()
|| defaultWithShellEnv()) {
@@ -202,11 +221,10 @@ public class DockerConnection implements IDockerConnection {
private boolean defaultWithShellEnv() throws DockerException {
try {
// FIXME need to verify the OS and decide which script to run
- final URL scriptURL = FileLocator.resolve(FileLocator.find(
- Activator.getDefault().getBundle(), new Path(
- "resources/script.sh"), Collections.EMPTY_MAP));
+ File scriptFile = Activator.getDefault().getBundle()
+ .getDataFile("script.sh"); //$NON-NLS-1$
final Process process = Runtime.getRuntime().exec(
- scriptURL.getPath());
+ scriptFile.getAbsolutePath());
process.waitFor();
if (process.exitValue() == 0) {
final InputStream processInputStream = process

Back to the top