use of org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob in project linuxtools by eclipse.
the class BuildDockerImageLaunchConfigurationDelegate method launch.
@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
final String sourcePathLocation = configuration.getAttribute(SOURCE_PATH_LOCATION, (String) null);
final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(SOURCE_PATH_WORKSPACE_RELATIVE_LOCATION, false);
final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
final String repoName = configuration.getAttribute(REPO_NAME, (String) null);
final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
final Map<String, Object> buildOptions = new HashMap<>();
buildOptions.put(QUIET_BUILD, configuration.getAttribute(QUIET_BUILD, false));
buildOptions.put(NO_CACHE, configuration.getAttribute(NO_CACHE, false));
buildOptions.put(RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(RM_INTERMEDIATE_CONTAINERS, true));
buildOptions.put(FORCE_RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(FORCE_RM_INTERMEDIATE_CONTAINERS, false));
if (connection != null && sourcePath != null) {
final Job buildImageJob = new BuildDockerImageJob(connection, sourcePath, repoName, buildOptions);
buildImageJob.schedule();
} else {
final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
"run");
// prompt the user with the launch configuration editor
Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
}
}
use of org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob in project linuxtools by eclipse.
the class BuildImageCommandHandler method performBuildImage.
private void performBuildImage(final ImageBuild wizard, final IDockerConnection connection) {
final Job buildImageJob = new Job(DVMessages.getString(BUILD_IMAGE_JOB_TITLE)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
final String id = wizard.getImageName();
@SuppressWarnings("unused") final int lines = wizard.getNumberOfLines();
final IPath path = wizard.getDirectory();
monitor.beginTask(DVMessages.getString(BUILD_IMAGE_JOB_TITLE), 2);
monitor.subTask(WizardMessages.getString(IMAGE_DIRECTORY_VALIDATE));
try {
Files.walkFileTree(Paths.get(path.toString()), new FileVisitor<java.nio.file.Path>() {
@Override
public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes attrs) throws IOException {
if (!file.toFile().canRead()) {
throw new IOException();
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(java.nio.file.Path file, IOException exc) throws IOException {
throw exc;
}
@Override
public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) {
return FileVisitResult.CONTINUE;
}
});
} catch (final IOException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), WizardMessages.getString(// $NON-NLS-1$
"ErrorInvalidDirectory.msg"), WizardMessages.getFormattedString(// $NON-NLS-1$
"ErrorInvalidPermissions.msg", path.toString())));
return Status.OK_STATUS;
}
monitor.worked(1);
// handler refresh the images when done
try {
monitor.subTask(DVMessages.getString(BUILD_IMAGE_JOB_TITLE));
final Job buildImageJob = new BuildDockerImageJob(connection, path, id, null);
buildImageJob.schedule();
monitor.worked(1);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
buildImageJob.schedule();
}
Aggregations