Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2018-05-10 11:19:04 +0000
committerAlexander Kurtakov2018-05-10 12:04:12 +0000
commitf2fdebe5713b4b64a92fd5a2a55774c8a15b2eb6 (patch)
treebe23b7a982ea363619d9c02dcda71dc81eb9d0e2
parentb8d6666dbb16fc2eb11910bbcbcb43697aa06ea7 (diff)
downloadorg.eclipse.linuxtools-f2fdebe5713b4b64a92fd5a2a55774c8a15b2eb6.tar.gz
org.eclipse.linuxtools-f2fdebe5713b4b64a92fd5a2a55774c8a15b2eb6.tar.xz
org.eclipse.linuxtools-f2fdebe5713b4b64a92fd5a2a55774c8a15b2eb6.zip
docker: Convert to try-with-resources.
Change-Id: I361a0664f915be896a7e7d62f96cc9153b8d52e3 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/122404
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.core.prefs47
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java127
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java105
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java91
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionPage.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuild.java11
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java6
8 files changed, 188 insertions, 208 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.core.prefs b/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.core.prefs
index 22cbad082b..96ae8dcf80 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.core.prefs
+++ b/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.core.prefs
@@ -16,6 +16,7 @@ org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
@@ -27,7 +28,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
@@ -53,12 +54,14 @@ org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
@@ -75,12 +78,16 @@ org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
@@ -101,7 +108,9 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
@@ -113,10 +122,13 @@ org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
-org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
@@ -126,6 +138,8 @@ org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
@@ -150,18 +164,21 @@ org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=true
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
org.eclipse.jdt.core.formatter.comment.format_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_source_code=true
-org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
-org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=false
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
-org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
@@ -172,7 +189,7 @@ org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
-org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
@@ -184,6 +201,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
@@ -211,7 +229,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
-org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
@@ -373,16 +391,29 @@ org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
-org.eclipse.jdt.core.formatter.lineSplit=80
+org.eclipse.jdt.core.formatter.lineSplit=120
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.ui.prefs b/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.ui.prefs
index 446b847248..ea129e97ce 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.ui.prefs
+++ b/containers/org.eclipse.linuxtools.docker.ui/.settings/org.eclipse.jdt.ui.prefs
@@ -1,7 +1,7 @@
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
-formatter_settings_version=12
+formatter_settings_version=14
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
@@ -36,6 +36,7 @@ sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_modifiers=false
sp_cleanup.remove_redundant_type_arguments=true
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_trailing_whitespaces_all=true
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java
index 919ab15ca1..3dab4d060d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/launch/ContainerLauncher.java
@@ -1,5 +1,6 @@
/*******************************************************************************
- * Copyright (c) 2015, 2016, 2017 Red Hat Inc. and others.
+ * Copyright (c) 2015, 2018 Red Hat Inc. and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -232,19 +233,17 @@ public class ContainerLauncher {
@Override
protected IStatus run(final IProgressMonitor monitor) {
- monitor.beginTask(
- Messages.getFormattedString(COPY_VOLUMES_FROM_DESC, image),
- volumes.size());
+ monitor.beginTask(Messages.getFormattedString(COPY_VOLUMES_FROM_DESC, image), volumes.size());
String containerId = null;
String currentVolume = null;
-
- // keep a list of already copied/being copied volumes so we can skip them and wait at the end to
+
+ // keep a list of already copied/being copied volumes so we can skip them and
+ // wait at the end to
// make sure if another job was copying them, it has finished
List<String> alreadyCopiedList = new ArrayList<>();
-
+
try {
- IDockerImage dockerImage = ((DockerConnection) connection)
- .getImageByTag(image);
+ IDockerImage dockerImage = ((DockerConnection) connection).getImageByTag(image);
// if there is a .image_id file, check the image id to ensure
// the user hasn't loaded a new version which may have
// different header files installed.
@@ -253,8 +252,7 @@ public class ContainerLauncher {
boolean needImageIdFile = !imageFile.exists();
if (!needImageIdFile) {
try (FileReader reader = new FileReader(imageFile);
- BufferedReader bufferReader = new BufferedReader(
- reader);) {
+ BufferedReader bufferReader = new BufferedReader(reader);) {
String imageId = bufferReader.readLine();
if (!dockerImage.id().equals(imageId)) {
// if image id has changed...all bets are off
@@ -271,8 +269,7 @@ public class ContainerLauncher {
}
if (needImageIdFile) {
try (FileWriter writer = new FileWriter(imageFile);
- BufferedWriter bufferedWriter = new BufferedWriter(
- writer);) {
+ BufferedWriter bufferedWriter = new BufferedWriter(writer);) {
bufferedWriter.write(dockerImage.id());
bufferedWriter.newLine();
synchronized (lockObject) {
@@ -290,9 +287,8 @@ public class ContainerLauncher {
for (String volume : volumes) {
boolean excluded = false;
for (String dir : excludedDirs) {
- if (volume.equals(dir) || (volume.startsWith(dir)
- && volume.charAt(dir
- .length()) == File.separatorChar)) {
+ if (volume.equals(dir)
+ || (volume.startsWith(dir) && volume.charAt(dir.length()) == File.separatorChar)) {
excluded = true;
break;
}
@@ -303,8 +299,7 @@ public class ContainerLauncher {
boolean alreadyCopied = false;
for (String path : dirList) {
if (volume.equals(path) || (volume.startsWith(path)
- && volume.charAt(path
- .length()) == File.separatorChar)) {
+ && volume.charAt(path.length()) == File.separatorChar)) {
if (!copyingList.contains(path)) {
alreadyCopied = true;
break;
@@ -325,14 +320,12 @@ public class ContainerLauncher {
}
// create base container to use for copying
- DockerContainerConfig.Builder builder = new DockerContainerConfig.Builder()
- .cmd("/bin/sh").image(image); //$NON-NLS-1$
+ DockerContainerConfig.Builder builder = new DockerContainerConfig.Builder().cmd("/bin/sh").image(image); //$NON-NLS-1$
IDockerContainerConfig config = builder.build();
DockerHostConfig.Builder hostBuilder = new DockerHostConfig.Builder();
IDockerHostConfig hostConfig = hostBuilder.build();
- containerId = ((DockerConnection) connection)
- .createContainer(config, hostConfig, null);
-
+ containerId = ((DockerConnection) connection).createContainer(config, hostConfig, null);
+
// copy each volume if it exists and is not copied over yet
for (String volume : volumes) {
currentVolume = volume;
@@ -349,8 +342,7 @@ public class ContainerLauncher {
boolean excluded = false;
for (String dir : excludedDirs) {
if (volume.equals(dir)
- || (volume.startsWith(dir) && volume.charAt(
- dir.length()) == File.separatorChar)) {
+ || (volume.startsWith(dir) && volume.charAt(dir.length()) == File.separatorChar)) {
excluded = true;
break;
}
@@ -366,8 +358,7 @@ public class ContainerLauncher {
synchronized (lockObject) {
for (String path : dirList) {
if (volume.equals(path) || (volume.startsWith(path)
- && volume.charAt(path
- .length()) == File.separatorChar)) {
+ && volume.charAt(path.length()) == File.separatorChar)) {
alreadyCopied = path;
if (!dirList.contains(volume)) {
dirList.add(volume);
@@ -390,15 +381,11 @@ public class ContainerLauncher {
// instead of returning too fast and the headers won't be
// there
synchronized (volume) {
- try (Closeable token = ((DockerConnection) connection)
- .getOperationToken()) {
- monitor.setTaskName(Messages.getFormattedString(
- COPY_VOLUMES_FROM_TASK, volume));
+ try (Closeable token = ((DockerConnection) connection).getOperationToken()) {
+ monitor.setTaskName(Messages.getFormattedString(COPY_VOLUMES_FROM_TASK, volume));
monitor.worked(1);
-
- InputStream in = ((DockerConnection) connection)
- .copyContainer(token, containerId, volume);
+ InputStream in = ((DockerConnection) connection).copyContainer(token, containerId, volume);
synchronized (lockObject) {
if (!dirList.contains(volume)) {
@@ -410,47 +397,42 @@ public class ContainerLauncher {
}
/*
- * The input stream from copyContainer might be
- * incomplete or non-blocking so we should wrap it
- * in a stream that is guaranteed to block until
- * data is available.
+ * The input stream from copyContainer might be incomplete or non-blocking so we
+ * should wrap it in a stream that is guaranteed to block until data is
+ * available.
*/
- TarArchiveInputStream k = new TarArchiveInputStream(
- new BlockingInputStream(in));
- TarArchiveEntry te = null;
- target.toFile().mkdirs();
- IPath currDir = target.append(volume)
- .removeLastSegments(1);
- currDir.toFile().mkdirs();
- while ((te = k.getNextTarEntry()) != null) {
- long size = te.getSize();
- IPath path = currDir;
- path = path.append(te.getName());
- File f = new File(path.toOSString());
- if (te.isDirectory()) {
- f.mkdir();
- continue;
- } else {
- f.createNewFile();
- }
- FileOutputStream os = new FileOutputStream(f);
- int bufferSize = ((int) size > 4096 ? 4096
- : (int) size);
- byte[] barray = new byte[bufferSize];
- int result = -1;
- while ((result = k.read(barray, 0,
- bufferSize)) > -1) {
- if (monitor.isCanceled()) {
- monitor.done();
- k.close();
- os.close();
- return Status.CANCEL_STATUS;
+ try (TarArchiveInputStream k = new TarArchiveInputStream(new BlockingInputStream(in))) {
+ TarArchiveEntry te = null;
+ target.toFile().mkdirs();
+ IPath currDir = target.append(volume).removeLastSegments(1);
+ currDir.toFile().mkdirs();
+ while ((te = k.getNextTarEntry()) != null) {
+ long size = te.getSize();
+ IPath path = currDir;
+ path = path.append(te.getName());
+ File f = new File(path.toOSString());
+ if (te.isDirectory()) {
+ f.mkdir();
+ continue;
+ } else {
+ f.createNewFile();
+ }
+ try (FileOutputStream os = new FileOutputStream(f)) {
+ int bufferSize = ((int) size > 4096 ? 4096 : (int) size);
+ byte[] barray = new byte[bufferSize];
+ int result = -1;
+ while ((result = k.read(barray, 0, bufferSize)) > -1) {
+ if (monitor.isCanceled()) {
+ monitor.done();
+ k.close();
+ os.close();
+ return Status.CANCEL_STATUS;
+ }
+ os.write(barray, 0, result);
+ }
}
- os.write(barray, 0, result);
}
- os.close();
}
- k.close();
// remove from copying list so subsequent jobs might
// know that the volume
// is fully copied
@@ -484,8 +466,7 @@ public class ContainerLauncher {
// remove the container used for copying
if (containerId != null) {
try {
- ((DockerConnection) connection)
- .removeContainer(containerId);
+ ((DockerConnection) connection).removeContainer(containerId);
} catch (DockerException | InterruptedException e) {
// ignore
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java
index 2bb90762aa..d8e75cfbc4 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java
@@ -1,5 +1,6 @@
/*******************************************************************************
- * Copyright (c) 2016 Red Hat Inc. and others.
+ * Copyright (c) 2016, 2018 Red Hat Inc. and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -103,85 +104,67 @@ public class CopyFromContainerCommandHandler extends AbstractHandler {
}
}
- private void performCopyFromContainer(final IDockerConnection connection,
- final IDockerContainer container, final String target,
- final List<ContainerFileProxy> files) {
+ private void performCopyFromContainer(final IDockerConnection connection, final IDockerContainer container,
+ final String target, final List<ContainerFileProxy> files) {
final Job copyFromContainerJob = new Job(
- CommandMessages.getFormattedString(
- COPY_FROM_CONTAINER_JOB_TITLE, container.name())) {
+ CommandMessages.getFormattedString(COPY_FROM_CONTAINER_JOB_TITLE, container.name())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
- monitor.beginTask(
- CommandMessages.getString(COPY_FROM_CONTAINER_JOB_TASK),
- files.size());
- try (Closeable token = ((DockerConnection) connection)
- .getOperationToken()) {
+ monitor.beginTask(CommandMessages.getString(COPY_FROM_CONTAINER_JOB_TASK), files.size());
+ try (Closeable token = ((DockerConnection) connection).getOperationToken()) {
for (ContainerFileProxy proxy : files) {
if (monitor.isCanceled()) {
monitor.done();
return Status.CANCEL_STATUS;
}
try {
- monitor.setTaskName(
- CommandMessages.getFormattedString(
- COPY_FROM_CONTAINER_JOB_SUBTASK,
- proxy.getFullPath()));
+ monitor.setTaskName(CommandMessages.getFormattedString(COPY_FROM_CONTAINER_JOB_SUBTASK,
+ proxy.getFullPath()));
monitor.worked(1);
- InputStream in = ((DockerConnection) connection)
- .copyContainer(token, container.id(),
- proxy.getLink());
+ InputStream in = ((DockerConnection) connection).copyContainer(token, container.id(),
+ proxy.getLink());
/*
- * The input stream from copyContainer might be
- * incomplete or non-blocking so we should wrap it
- * in a stream that is guaranteed to block until
- * data is available.
+ * The input stream from copyContainer might be incomplete or non-blocking so we
+ * should wrap it in a stream that is guaranteed to block until data is
+ * available.
*/
- TarArchiveInputStream k = new TarArchiveInputStream(
- new BlockingInputStream(in));
- TarArchiveEntry te = null;
- while ((te = k.getNextTarEntry()) != null) {
- long size = te.getSize();
- IPath path = new Path(target);
- path = path.append(te.getName());
- File f = new File(path.toOSString());
- if (te.isDirectory()) {
- f.mkdir();
- continue;
- } else {
- f.createNewFile();
- }
- FileOutputStream os = new FileOutputStream(f);
- int bufferSize = ((int) size > 4096 ? 4096
- : (int) size);
- byte[] barray = new byte[bufferSize];
- int result = -1;
- while ((result = k.read(barray, 0,
- bufferSize)) > -1) {
- if (monitor.isCanceled()) {
- monitor.done();
- k.close();
- os.close();
- return Status.CANCEL_STATUS;
+ try (TarArchiveInputStream k = new TarArchiveInputStream(new BlockingInputStream(in))) {
+ TarArchiveEntry te = null;
+ while ((te = k.getNextTarEntry()) != null) {
+ long size = te.getSize();
+ IPath path = new Path(target);
+ path = path.append(te.getName());
+ File f = new File(path.toOSString());
+ if (te.isDirectory()) {
+ f.mkdir();
+ continue;
+ } else {
+ f.createNewFile();
+ }
+ try (FileOutputStream os = new FileOutputStream(f)) {
+ int bufferSize = ((int) size > 4096 ? 4096 : (int) size);
+ byte[] barray = new byte[bufferSize];
+ int result = -1;
+ while ((result = k.read(barray, 0, bufferSize)) > -1) {
+ if (monitor.isCanceled()) {
+ monitor.done();
+ k.close();
+ os.close();
+ return Status.CANCEL_STATUS;
+ }
+ os.write(barray, 0, result);
+ }
}
- os.write(barray, 0, result);
}
- os.close();
}
- k.close();
} catch (final DockerException e) {
Display.getDefault()
.syncExec(() -> MessageDialog.openError(
- PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getShell(),
- CommandMessages.getFormattedString(
- ERROR_COPYING_FROM_CONTAINER,
- proxy.getLink(),
- container.name()),
- e.getCause() != null
- ? e.getCause().getMessage()
- : e.getMessage()));
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ CommandMessages.getFormattedString(ERROR_COPYING_FROM_CONTAINER,
+ proxy.getLink(), container.name()),
+ e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
}
}
} catch (InterruptedException e) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
index d02194de61..f7994117ff 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
@@ -1,5 +1,6 @@
/*******************************************************************************
- * Copyright (c) 2017 Red Hat Inc. and others.
+ * Copyright (c) 2017, 2018 Red Hat Inc. and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -278,68 +279,59 @@ public class ContainerCommandProcess extends Process {
@Override
protected IStatus run(final IProgressMonitor monitor) {
- monitor.beginTask(Messages.getFormattedString(
- COPY_VOLUMES_FROM_DESC, imageName), remoteVolumes.size());
+ monitor.beginTask(Messages.getFormattedString(COPY_VOLUMES_FROM_DESC, imageName), remoteVolumes.size());
String containerId = null;
try {
- DockerContainerConfig.Builder builder = new DockerContainerConfig.Builder()
- .cmd("/bin/sh").image(imageName); //$NON-NLS-1$
+ DockerContainerConfig.Builder builder = new DockerContainerConfig.Builder().cmd("/bin/sh") //$NON-NLS-1$
+ .image(imageName);
IDockerContainerConfig config = builder.build();
DockerHostConfig.Builder hostBuilder = new DockerHostConfig.Builder();
IDockerHostConfig hostConfig = hostBuilder.build();
- containerId = ((DockerConnection) connection)
- .createContainer(config, hostConfig, null);
+ containerId = ((DockerConnection) connection).createContainer(config, hostConfig, null);
for (String volume : remoteVolumes.keySet()) {
- try (Closeable token = ((DockerConnection) connection)
- .getOperationToken()) {
- monitor.setTaskName(Messages.getFormattedString(
- COPY_VOLUMES_FROM_TASK, volume));
+ try (Closeable token = ((DockerConnection) connection).getOperationToken()) {
+ monitor.setTaskName(Messages.getFormattedString(COPY_VOLUMES_FROM_TASK, volume));
monitor.worked(1);
- InputStream in = ((DockerConnection) connection)
- .copyContainer(token, containerId,
- remoteVolumes.get(volume));
+ InputStream in = ((DockerConnection) connection).copyContainer(token, containerId,
+ remoteVolumes.get(volume));
/*
- * The input stream from copyContainer might be
- * incomplete or non-blocking so we should wrap it in a
- * stream that is guaranteed to block until data is
+ * The input stream from copyContainer might be incomplete or non-blocking so we
+ * should wrap it in a stream that is guaranteed to block until data is
* available.
*/
- TarArchiveInputStream k = new TarArchiveInputStream(
- new BlockingInputStream(in));
- TarArchiveEntry te = null;
- IPath currDir = new Path(volume).removeLastSegments(1);
- currDir.toFile().mkdirs();
- while ((te = k.getNextTarEntry()) != null) {
- long size = te.getSize();
- IPath path = currDir;
- path = path.append(te.getName());
- File f = new File(path.toOSString());
- if (te.isDirectory()) {
- f.mkdir();
- continue;
- } else {
- f.createNewFile();
- }
- FileOutputStream os = new FileOutputStream(f);
- int bufferSize = ((int) size > 4096 ? 4096
- : (int) size);
- byte[] barray = new byte[bufferSize];
- int result = -1;
- while ((result = k.read(barray, 0,
- bufferSize)) > -1) {
- if (monitor.isCanceled()) {
- monitor.done();
- k.close();
- os.close();
- return Status.CANCEL_STATUS;
+ try (TarArchiveInputStream k = new TarArchiveInputStream(new BlockingInputStream(in))) {
+ TarArchiveEntry te = null;
+ IPath currDir = new Path(volume).removeLastSegments(1);
+ currDir.toFile().mkdirs();
+ while ((te = k.getNextTarEntry()) != null) {
+ long size = te.getSize();
+ IPath path = currDir;
+ path = path.append(te.getName());
+ File f = new File(path.toOSString());
+ if (te.isDirectory()) {
+ f.mkdir();
+ continue;
+ } else {
+ f.createNewFile();
+ }
+ try (FileOutputStream os = new FileOutputStream(f)) {
+ int bufferSize = ((int) size > 4096 ? 4096 : (int) size);
+ byte[] barray = new byte[bufferSize];
+ int result = -1;
+ while ((result = k.read(barray, 0, bufferSize)) > -1) {
+ if (monitor.isCanceled()) {
+ monitor.done();
+ k.close();
+ os.close();
+ return Status.CANCEL_STATUS;
+ }
+ os.write(barray, 0, result);
+ }
}
- os.write(barray, 0, result);
}
- os.close();
}
- k.close();
} catch (final DockerException e) {
// ignore
}
@@ -353,8 +345,7 @@ public class ContainerCommandProcess extends Process {
} finally {
if (containerId != null) {
try {
- ((DockerConnection) connection)
- .removeContainer(containerId);
+ ((DockerConnection) connection).removeContainer(containerId);
} catch (DockerException | InterruptedException e) {
// ignore
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionPage.java
index 65ca079ef7..4c6dd4c07a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2016 Red Hat Inc. and others.
+ * Copyright (c) 2014, 2018 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -406,10 +406,8 @@ public class EditDockerConnectionPage extends WizardPage {
monitor.beginTask(WizardMessages.getString(
"DockerConnectionPage.pingTask"), //$NON-NLS-1$
IProgressMonitor.UNKNOWN);
- try {
- final DockerConnection dockerConnection = getDockerConnection();
+ try (DockerConnection dockerConnection = getDockerConnection()) {
dockerConnection.open(false);
- dockerConnection.close();
// ping succeeded
displaySuccessDialog();
} catch (DockerException e) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuild.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuild.java
index 1b3a8f00e4..a0e0cb9609 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuild.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuild.java
@@ -1,5 +1,6 @@
/*******************************************************************************
- * Copyright (c) 2015 Red Hat.
+ * Copyright (c) 2015, 2018 Red Hat.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -56,11 +57,10 @@ public class ImageBuild extends Wizard {
private int numberOfLines() throws IOException {
String fileName = directory.append("Dockerfile").toString(); //$NON-NLS-1$
- InputStream is = null;
int count = 0;
boolean empty = false;
- try {
- is = new BufferedInputStream(new FileInputStream(fileName));
+ try (InputStream is = new BufferedInputStream(
+ new FileInputStream(fileName))) {
byte[] c = new byte[1024];
int readChars = 0;
while ((readChars = is.read(c)) != -1) {
@@ -71,9 +71,6 @@ public class ImageBuild extends Wizard {
}
}
}
- } finally {
- if (is != null)
- is.close();
}
return (count == 0 && !empty) ? 1 : count;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
index 42df302e2c..2ee6cc1c3c 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2016 Red Hat Inc. and others.
+ * Copyright (c) 2014, 2018 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -613,11 +613,9 @@ public class NewDockerConnectionPage extends WizardPage {
monitor.beginTask(WizardMessages.getString(
"DockerConnectionPage.pingTask"), //$NON-NLS-1$
IProgressMonitor.UNKNOWN);
- try {
- final DockerConnection dockerConnection = getDockerConnection();
+ try (DockerConnection dockerConnection = getDockerConnection()) {
dockerConnection.open(false);
dockerConnection.ping();
- dockerConnection.close();
// ping succeeded
displaySuccessDialog();
} catch (DockerException e) {

Back to the top