use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class ContainerVMInstall method findJavaExecutable.
// org.eclipse.jdt.internal.launching.StandardVMType#findJavaExecutable(File)
public File findJavaExecutable(File vmInstallLocation) {
// $NON-NLS-1$
final String JRE = "jre";
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
final String[] fgCandidateJavaFiles = { "javaw", "javaw.exe", "java", "java.exe", "j9w", "j9w.exe", "j9", "j9.exe" };
// $NON-NLS-1$ //$NON-NLS-2$
final String[] fgCandidateJavaLocations = { "bin" + UnixFile.separatorChar, JRE + UnixFile.separatorChar + "bin" + UnixFile.separatorChar };
DockerConnection conn = getConnection();
ImageQuery q = new ImageQuery(conn, image.id());
// of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
for (int j = 0; j < fgCandidateJavaLocations.length; j++) {
File javaFile = new UnixFile(vmInstallLocation, fgCandidateJavaLocations[j] + fgCandidateJavaFiles[i]);
if (q.isFile(javaFile)) {
q.destroy();
return javaFile;
}
}
}
q.destroy();
return null;
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class JavaAppInContainerLaunchDelegate method launch.
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
// $NON-NLS-1$
monitor.beginTask(NLS.bind("{0}...", new String[] { configuration.getName() }), 3);
// check for cancellation
if (monitor.isCanceled()) {
return;
}
String connectionURI = configuration.getAttribute(JavaLaunchConfigurationConstants.CONNECTION_URI, (String) null);
String imageID = configuration.getAttribute(JavaLaunchConfigurationConstants.IMAGE_ID, (String) null);
List<String> extraDirs = configuration.getAttribute(JavaLaunchConfigurationConstants.DIRS, Arrays.asList(new String[0]));
try {
DockerConnection conn = (DockerConnection) DockerConnectionManager.getInstance().getConnectionByUri(connectionURI);
if (conn == null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_connection_not_found_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_connection_not_found_text, connectionURI));
}
});
return;
} else if (!conn.isOpen()) {
try {
conn.open(false);
} catch (DockerException e) {
}
if (!conn.isOpen()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_connection_not_active_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_connection_not_active_text, connectionURI));
}
});
return;
}
}
IDockerImage img = conn.getImage(imageID);
if (img == null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_image_not_found_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_image_not_found_text, imageID));
}
});
return;
}
// randomized port between 1025 and 65535
int port = ILaunchManager.DEBUG_MODE.equals(mode) ? (int) ((65535 - 1025) * Math.random()) + 1025 : -1;
monitor.subTask(Messages.JavaAppInContainerLaunchDelegate_Verifying_launch_attributes____1);
String mainTypeName = verifyMainTypeName(configuration);
IVMInstall vm = new ContainerVMInstall(configuration, img, port);
ContainerVMRunner runner = new ContainerVMRunner(vm);
File workingDir = verifyWorkingDirectory(configuration);
String workingDirName = null;
if (workingDir != null) {
workingDirName = workingDir.getAbsolutePath();
}
runner.setAdditionalDirectories(extraDirs);
// Environment variables
String[] envp = getEnvironment(configuration);
// Program & VM arguments
String pgmArgs = getProgramArguments(configuration);
String vmArgs = getVMArguments(configuration);
ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
// VM-specific attributes
Map<String, Object> vmAttributesMap = getVMSpecificAttributesMap(configuration);
// Classpath
String[] classpath = getClasspath(configuration);
if (Platform.OS_WIN32.equals(Platform.getOS())) {
for (int i = 0; i < classpath.length; i++) {
classpath[i] = UnixFile.convertDOSPathToUnixPath(classpath[i]);
}
}
// Create VM config
VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
runConfig.setEnvironment(envp);
List<String> finalVMArgs = new ArrayList<>(Arrays.asList(execArgs.getVMArgumentsArray()));
if (ILaunchManager.DEBUG_MODE.equals(mode)) {
double version = getJavaVersion(conn, img);
if (version < 1.5) {
// $NON-NLS-1$
finalVMArgs.add("-Xdebug");
// $NON-NLS-1$
finalVMArgs.add("-Xnoagent");
}
// check if java 1.4 or greater
if (version < 1.4) {
// $NON-NLS-1$
finalVMArgs.add("-Djava.compiler=NONE");
}
if (version < 1.5) {
// $NON-NLS-1$
finalVMArgs.add("-Xrunjdwp:transport=dt_socket,server=y,address=" + port);
} else {
// $NON-NLS-1$
finalVMArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,address=" + port);
}
}
runConfig.setVMArguments(finalVMArgs.toArray(new String[0]));
runConfig.setWorkingDirectory(workingDirName);
runConfig.setVMSpecificAttributesMap(vmAttributesMap);
// Bootpath
runConfig.setBootClassPath(getBootpath(configuration));
// check for cancellation
if (monitor.isCanceled()) {
return;
}
// stop in main
prepareStopInMain(configuration);
// done the verification phase
monitor.worked(1);
monitor.subTask(Messages.JavaAppInContainerLaunchDelegate_Creating_source_locator____2);
// set the default source locator if required
setDefaultSourceLocator(launch, configuration);
monitor.worked(1);
// Launch the configuration - 1 unit of work
runner.run(runConfig, launch, monitor);
// check for cancellation
if (monitor.isCanceled()) {
return;
}
if (ILaunchManager.DEBUG_MODE.equals(mode)) {
while (runner.getIPAddress() == null || !runner.isListening()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
IDockerContainerInfo info = runner.getContainerInfo();
// $NON-NLS-1$
String configName = info.name().startsWith("/") ? info.name().substring(1) : info.name();
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_REMOTE_JAVA_APPLICATION);
ILaunchConfiguration cfgForAttach = type.newInstance(null, configName);
ILaunchConfigurationWorkingCopy wc = cfgForAttach.getWorkingCopy();
String ip = runner.getIPAddress();
// Can we reach it ? Or is it on a different network.
if (!isListening(ip, port)) {
// If the daemon is reachable via TCP it should forward traffic.
if (conn.getSettings() instanceof TCPConnectionSettings) {
ip = ((TCPConnectionSettings) conn.getSettings()).getAddr();
if (!isListening(ip, port)) {
// Try to find some network interface that's listening
ip = getIPAddressListening(port);
if (!isListening(ip, port)) {
ip = null;
}
}
} else {
ip = null;
}
}
if (ip == null) {
String imageName = conn.getImage(imageID).repoTags().get(0);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_session_unreachable_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_session_unreachable_text, new Object[] { imageName, imageID, runner.getIPAddress() }));
}
});
return;
}
Map<String, String> map = new HashMap<>();
// $NON-NLS-1$
map.put("hostname", ip);
// $NON-NLS-1$
map.put("port", String.valueOf(port));
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, map);
String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
wc.doSave();
DebugUITools.launch(cfgForAttach, ILaunchManager.DEBUG_MODE);
}
} finally {
monitor.done();
}
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class JavaImageTab method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
Label connLbl = new Label(composite, SWT.NONE);
connLbl.setText(Messages.ImageSelectionDialog_connection_label);
connCmb = new ComboViewer(composite, SWT.READ_ONLY);
connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
connCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
try {
((DockerConnection) conn).open(false);
} catch (DockerException e) {
}
}
return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
}
});
// $NON-NLS-1$
connCmb.setInput("place_holder");
Label imageLbl = new Label(composite, SWT.NONE);
imageLbl.setText(Messages.ImageSelectionDialog_image_label);
imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
imageCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
IDockerConnection conn = (IDockerConnection) inputElement;
if (conn == null || conn.getImages() == null) {
return new Object[0];
} else {
return conn.getImages().stream().filter(// $NON-NLS-1$
i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
}
}
});
imageCmb.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
IDockerImage img = (IDockerImage) element;
return img.repoTags().get(0);
}
});
imageCmb.setInput(null);
connCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
selectedConnection = conn;
imageCmb.setInput(conn);
updateLaunchConfigurationDialog();
}
});
imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerImage img = (IDockerImage) sel.getFirstElement();
selectedImage = img;
updateLaunchConfigurationDialog();
}
});
Group dirGroup = new Group(composite, SWT.NONE);
dirGroup.setText(Messages.JavaImageTab_additional_dirs);
dirGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
dirGroup.setLayout(new GridLayout(2, false));
directoryList = new List(dirGroup, SWT.SINGLE | SWT.V_SCROLL);
directoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
directoryList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
removeButton.setEnabled(true);
}
});
addButton = createPushButton(dirGroup, Messages.JavaImageTab_button_add, null);
addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
String directory = dialog.open();
if (directory != null && !listContains(directoryList, directory)) {
directoryList.add(directory);
updateLaunchConfigurationDialog();
}
}
});
removeButton = createPushButton(dirGroup, Messages.JavaImageTab_button_remove, null);
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int i = directoryList.getSelectionIndex();
if (i >= 0) {
directoryList.remove(i);
updateLaunchConfigurationDialog();
}
if (directoryList.getItemCount() == 0) {
removeButton.setEnabled(false);
}
}
});
removeButton.setEnabled(false);
setControl(composite);
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class JavaImageTab method initializeFrom.
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
DockerConnection conn;
String connUri = configuration.getAttribute(JavaLaunchConfigurationConstants.CONNECTION_URI, (String) null);
if (connUri != null) {
connCmb.getCombo().setText(connUri);
conn = (DockerConnection) DockerConnectionManager.getInstance().getConnectionByUri(connUri);
String imageId = configuration.getAttribute(JavaLaunchConfigurationConstants.IMAGE_ID, (String) null);
if (imageId != null && conn != null) {
selectedConnection = conn;
// generate known images for given connection
imageCmb.setInput(conn);
IDockerImage img = conn.getImage(imageId);
if (img != null) {
String repoTag = img.repoTags().get(0);
imageCmb.getCombo().setText(repoTag);
selectedImage = img;
}
}
}
java.util.List<String> dirs = configuration.getAttribute(JavaLaunchConfigurationConstants.DIRS, Arrays.asList(new String[0]));
directoryList.setItems(dirs.toArray(new String[0]));
} catch (CoreException e) {
}
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class CommitContainerCommandHandler method performCommitContainer.
private void performCommitContainer(final ContainerCommit wizard, final IDockerConnection connection, final IDockerContainer container) {
final Job commitContainerJob = new Job(DVMessages.getString(COMMIT_CONTAINER_JOB_TITLE)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
final String tag = wizard.getTag();
final String repo = wizard.getRepo();
final String author = wizard.getAuthor();
final String comment = wizard.getComment();
monitor.beginTask(DVMessages.getString(COMMIT_CONTAINER_MSG), 1);
// commit the Container and then update the list of Images
try {
((DockerConnection) connection).commitContainer(container.id(), repo, tag, comment, author);
monitor.worked(1);
} catch (DockerException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_COMMITTING_CONTAINER, tag), e.getMessage()));
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
commitContainerJob.schedule();
}
Aggregations