Search in sources :

Example 1 with BuildDockerImageJob

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));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) Job(org.eclipse.core.runtime.jobs.Job) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob)

Example 2 with BuildDockerImageJob

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();
}
Also used : IPath(org.eclipse.core.runtime.IPath) IPath(org.eclipse.core.runtime.IPath) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob) Job(org.eclipse.core.runtime.jobs.Job) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

IPath (org.eclipse.core.runtime.IPath)2 Job (org.eclipse.core.runtime.jobs.Job)2 BuildDockerImageJob (org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob)2 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 HashMap (java.util.HashMap)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ILaunchGroup (org.eclipse.debug.ui.ILaunchGroup)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1