Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-15 13:16:03 -0400
committerCarsten Hammer2019-08-11 16:33:39 -0400
commit110846fc7087ced5de1385988fcf58c34b1636b3 (patch)
tree91bd78143aee0b470c5b0d5db2620db0a71f81b7
parentb47d3d311bee93b31c8956b4cffcec7a84096ec8 (diff)
downloadorg.eclipse.tycho-110846fc7087ced5de1385988fcf58c34b1636b3.tar.gz
org.eclipse.tycho-110846fc7087ced5de1385988fcf58c34b1636b3.tar.xz
org.eclipse.tycho-110846fc7087ced5de1385988fcf58c34b1636b3.zip
Use try-with-resources
Convert try finally block to try-with-resources Change-Id: I988435008804499e2397eceeeb4e34922c5eeb76 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
-rw-r--r--sisu-equinox/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java10
-rw-r--r--tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ClassfileComparator.java8
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java32
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryTest.java6
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/module/ModuleArtifactRepositoryTest.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/AbstractMavenMetadataRepository.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/ArtifactsIO.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/MetadataIO.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/LocalArtifactRepository.java20
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/index/FileBasedTychoRepositoryIndex.java10
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactMap.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactRepository.java22
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/repo/MetadataSerializableImplTest.java7
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/PomDependencyCollectorImpl.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.p2.tools.impl/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublisherServiceImpl.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/repository/streaming/testutil/ProbeOutputStream.java5
-rw-r--r--tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/FileServerServlet.java5
-rw-r--r--tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java12
-rw-r--r--tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/EclipseInstallationLayout.java15
-rw-r--r--tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java26
-rw-r--r--tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Feature.java5
-rw-r--r--tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Platform.java10
-rw-r--r--tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java5
-rw-r--r--tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java7
-rw-r--r--tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/facade/RepositoryReferenceTool.java5
-rw-r--r--tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/TargetDefinitionFile.java10
-rw-r--r--tycho-p2/tycho-p2-plugin/src/test/java/org/eclipse/tycho/plugins/p2/P2MetadataMojoTest.java5
-rw-r--r--tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java5
-rw-r--r--tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/LicenseFeatureHelper.java5
-rw-r--r--tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java5
-rw-r--r--tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java5
-rw-r--r--tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackagePluginMojoTest.java30
-rw-r--r--tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackageUpdateSiteMojoTest.java15
-rw-r--r--tycho-pomgenerator-plugin/src/main/java/org/eclipse/tycho/pomgenerator/GeneratePomsMojo.java10
-rw-r--r--tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java5
-rw-r--r--tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/ArchiveContentUtil.java5
-rw-r--r--tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/LocalMavenRepositoryTool.java10
-rw-r--r--tycho-testing-harness/src/main/java/org/eclipse/tycho/testing/AbstractTychoMojoTestCase.java5
38 files changed, 103 insertions, 257 deletions
diff --git a/sisu-equinox/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java b/sisu-equinox/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java
index b2721fa9b..0033dabea 100644
--- a/sisu-equinox/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java
+++ b/sisu-equinox/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java
@@ -150,11 +150,8 @@ public class DefaultEquinoxInstallationFactory implements EquinoxInstallationFac
File configIni = new File(location, TychoConstants.CONFIG_INI_PATH);
File configurationLocation = configIni.getParentFile();
configurationLocation.mkdirs();
- FileOutputStream fos = new FileOutputStream(configIni);
- try {
+ try (FileOutputStream fos = new FileOutputStream(configIni)) {
p.store(fos, null);
- } finally {
- fos.close();
}
return new DefaultEquinoxInstallation(description, location, configurationLocation);
@@ -174,11 +171,8 @@ public class DefaultEquinoxInstallationFactory implements EquinoxInstallationFac
File file = new File(location, "dev.properties");
Properties properties = new Properties();
properties.putAll(devEntries);
- OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
- try {
+ try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
properties.store(os, null);
- } finally {
- os.close();
}
return file.toURI().toURL().toExternalForm();
}
diff --git a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ClassfileComparator.java b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ClassfileComparator.java
index 52ba2dc48..fb0d62a0c 100644
--- a/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ClassfileComparator.java
+++ b/tycho-artifactcomparator/src/main/java/org/eclipse/tycho/zipcomparator/internal/ClassfileComparator.java
@@ -74,10 +74,10 @@ public class ClassfileComparator implements ContentsComparator {
// rendering human-readable bytecode is an eyecandy, we can compare ClassNodes directly
StringWriter buffer = new StringWriter();
- PrintWriter writer = new PrintWriter(buffer);
- clazz.accept(new TraceClassVisitor(writer));
- writer.flush();
- writer.close();
+ try (PrintWriter writer = new PrintWriter(buffer)) {
+ clazz.accept(new TraceClassVisitor(writer));
+ writer.flush();
+ }
return buffer.toString();
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java
index 7bf376b43..6a0301282 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java
@@ -565,9 +565,9 @@ public class LocalArtifactRepositoryP2APITest {
@SuppressWarnings("deprecation")
@Test
public void testWriteArtifactViaStream() throws Exception {
- OutputStream addSink = subject.getOutputStream(foreignEquivalentOf(NEW_DESCRIPTOR));
- addSink.write(new byte[33]);
- addSink.close();
+ try (OutputStream addSink = subject.getOutputStream(foreignEquivalentOf(NEW_DESCRIPTOR))) {
+ addSink.write(new byte[33]);
+ }
assertThat(subject.contains(NEW_KEY), is(true));
assertThat(subject.contains(NEW_DESCRIPTOR), is(true));
@@ -579,11 +579,11 @@ public class LocalArtifactRepositoryP2APITest {
@Test
public void testReWriteArtifactViaStreamFails() throws Exception {
ProvisionException expectedException = null;
- try {
- OutputStream addSink = subject.getOutputStream(ARTIFACT_A_CANONICAL);
+
+ try (OutputStream addSink = subject.getOutputStream(ARTIFACT_A_CANONICAL)) {
addSink.write(new byte[1]);
- addSink.close();
- } catch (ProvisionException e) {
+ }
+ catch (ProvisionException e) {
expectedException = e;
}
@@ -594,11 +594,11 @@ public class LocalArtifactRepositoryP2APITest {
@SuppressWarnings("deprecation")
@Test
public void testWriteArtifactViaStreamAndCancel() throws Exception {
- OutputStream addSink = subject.getOutputStream(foreignEquivalentOf(NEW_DESCRIPTOR));
- addSink.write(new byte[33]);
- // setStatus needs to be called when copying from a repository using getArtifact, and that method returns an error (e.g. due to artifact corruption)
- ((IStateful) addSink).setStatus(new Status(IStatus.ERROR, "test", "written data is bad"));
- addSink.close();
+ try (OutputStream addSink = subject.getOutputStream(foreignEquivalentOf(NEW_DESCRIPTOR))) {
+ addSink.write(new byte[33]);
+ // setStatus needs to be called when copying from a repository using getArtifact, and that method returns an error (e.g. due to artifact corruption)
+ ((IStateful) addSink).setStatus(new Status(IStatus.ERROR, "test", "written data is bad"));
+ }
assertThat(subject.contains(NEW_DESCRIPTOR), is(false));
assertThat(subject.contains(NEW_KEY), is(false));
@@ -607,10 +607,10 @@ public class LocalArtifactRepositoryP2APITest {
@SuppressWarnings("deprecation")
@Test
public void testWriteArtifactViaStreamWithNonFatalStatus() throws Exception {
- OutputStream addSink = subject.getOutputStream(foreignEquivalentOf(NEW_DESCRIPTOR));
- addSink.write(new byte[33]);
- ((IStateful) addSink).setStatus(new Status(IStatus.WARNING, "test", "irrelevant warning"));
- addSink.close();
+ try (OutputStream addSink = subject.getOutputStream(foreignEquivalentOf(NEW_DESCRIPTOR))) {
+ addSink.write(new byte[33]);
+ ((IStateful) addSink).setStatus(new Status(IStatus.WARNING, "test", "irrelevant warning"));
+ }
assertThat(subject.contains(NEW_DESCRIPTOR), is(true));
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryTest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryTest.java
index dfc33b843..ed18d0a59 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryTest.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryTest.java
@@ -189,9 +189,9 @@ public class LocalArtifactRepositoryTest {
private void writeDummyArtifact(LocalArtifactRepository repo, ArtifactDescriptor desc, byte[] content)
throws ProvisionException, IOException {
- OutputStream os = repo.getOutputStream(desc);
- os.write(content);
- os.close();
+ try (OutputStream os = repo.getOutputStream(desc)) {
+ os.write(content);
+ }
}
@Test
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/module/ModuleArtifactRepositoryTest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/module/ModuleArtifactRepositoryTest.java
index 5c90081cf..56f6d46be 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/module/ModuleArtifactRepositoryTest.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/module/ModuleArtifactRepositoryTest.java
@@ -231,15 +231,12 @@ public class ModuleArtifactRepositoryTest {
private static void generateBinaryTestFile(File file, int size) throws IOException {
file.getParentFile().mkdirs();
- FileOutputStream fos = new FileOutputStream(file);
- try {
+ try (FileOutputStream fos = new FileOutputStream(file)) {
OutputStream os = new BufferedOutputStream(fos);
for (int i = 0; i < size; ++i) {
os.write(0);
}
os.flush();
- } finally {
- fos.close();
}
file.deleteOnExit();
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/AbstractMavenMetadataRepository.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/AbstractMavenMetadataRepository.java
index 34b8787a4..1985963ca 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/AbstractMavenMetadataRepository.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/AbstractMavenMetadataRepository.java
@@ -75,14 +75,11 @@ public abstract class AbstractMavenMetadataRepository extends AbstractMetadataRe
// if files have been manually removed from the repository, simply remove them from the index (bug 351080)
metadataIndex.removeGav(gav);
} else {
- InputStream is = new FileInputStream(localArtifactFileLocation);
- try {
+ try (InputStream is = new FileInputStream(localArtifactFileLocation)) {
Set<IInstallableUnit> gavUnits = io.readXML(is);
unitsMap.put(gav, gavUnits);
units.addAll(gavUnits);
- } finally {
- is.close();
}
}
} catch (IOException e) {
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/ArtifactsIO.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/ArtifactsIO.java
index eb59eecf0..f79da75f1 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/ArtifactsIO.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/ArtifactsIO.java
@@ -125,11 +125,8 @@ public class ArtifactsIO {
}
public void writeXML(Set<? extends IArtifactDescriptor> descriptors, File file) throws IOException {
- OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
- try {
+ try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
writeXML(descriptors, os);
- } finally {
- os.close();
}
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/MetadataIO.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/MetadataIO.java
index ea2e184bf..df3de027f 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/MetadataIO.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/p2/maven/repository/xmlio/MetadataIO.java
@@ -190,11 +190,8 @@ public class MetadataIO {
}
public void writeXML(Set<IInstallableUnit> units, File file) throws IOException {
- OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
- try {
+ try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
writeXML(units, os);
- } finally {
- os.close();
}
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/LocalArtifactRepository.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/LocalArtifactRepository.java
index 6e45753f8..1dc91006d 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/LocalArtifactRepository.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/LocalArtifactRepository.java
@@ -73,16 +73,13 @@ public class LocalArtifactRepository extends ArtifactRepositoryBaseImpl<GAVArtif
// if files have been manually removed from the repository, simply remove them from the index (bug 351080)
index.removeGav(gav);
} else {
- final InputStream is = new FileInputStream(contentLocator.getLocalArtifactLocation(gav,
+ try (InputStream is = new FileInputStream(contentLocator.getLocalArtifactLocation(gav,
RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS,
- RepositoryLayoutHelper.EXTENSION_P2_ARTIFACTS));
- try {
+ RepositoryLayoutHelper.EXTENSION_P2_ARTIFACTS))) {
final Set<IArtifactDescriptor> gavDescriptors = io.readXML(is);
for (IArtifactDescriptor descriptor : gavDescriptors) {
internalAddDescriptor(descriptor);
}
- } finally {
- is.close();
}
}
} catch (IOException e) {
@@ -122,14 +119,11 @@ public class LocalArtifactRepository extends ArtifactRepositoryBaseImpl<GAVArtif
File file = new File(location, relpath);
file.getParentFile().mkdirs();
- try {
- OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
- try {
- io.writeXML(keyDescriptors, os);
- } finally {
- os.close();
- }
- } catch (IOException e) {
+
+ try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
+ io.writeXML(keyDescriptors, os);
+ }
+ catch (IOException e) {
throw new RuntimeException(e);
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/index/FileBasedTychoRepositoryIndex.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/index/FileBasedTychoRepositoryIndex.java
index 0f80774e5..55c81bd19 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/index/FileBasedTychoRepositoryIndex.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/index/FileBasedTychoRepositoryIndex.java
@@ -138,22 +138,18 @@ public class FileBasedTychoRepositoryIndex implements TychoRepositoryIndex {
}
private void write(OutputStream outStream) throws IOException {
- Writer out = new OutputStreamWriter(new BufferedOutputStream(outStream), ENCODING);
- try {
+ try (Writer out = new OutputStreamWriter(new BufferedOutputStream(outStream), ENCODING)) {
for (GAV gav : getProjectGAVs()) {
out.write(gav.toExternalForm());
out.write(EOL);
}
out.flush();
- } finally {
- out.close();
}
}
private Set<GAV> read(InputStream inStream) throws IOException {
LinkedHashSet<GAV> result = new LinkedHashSet<>();
- BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, ENCODING));
- try {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, ENCODING))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.trim().length() == 0) {
@@ -166,8 +162,6 @@ public class FileBasedTychoRepositoryIndex implements TychoRepositoryIndex {
logger.warn("Ignoring invalid line '" + line + "' in " + indexFile);
}
}
- } finally {
- reader.close();
}
return result;
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactMap.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactMap.java
index 11d7c8b16..ba288ef77 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactMap.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactMap.java
@@ -130,11 +130,8 @@ class ModuleArtifactMap {
private static Properties loadProperties(File propertiesFile) throws IOException {
Properties properties = new Properties();
- FileInputStream propertiesStream = new FileInputStream(propertiesFile);
- try {
+ try (FileInputStream propertiesStream = new FileInputStream(propertiesFile)) {
properties.load(propertiesStream);
- } finally {
- propertiesStream.close();
}
return properties;
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactRepository.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactRepository.java
index 18e093655..77509b1f5 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactRepository.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/module/ModuleArtifactRepository.java
@@ -234,20 +234,16 @@ class ModuleArtifactRepository extends ArtifactRepositoryBaseImpl<ModuleArtifact
}
private void load() throws ProvisionException {
- try {
- FileInputStream p2DataFileStream = new FileInputStream(p2DataFile);
- try {
- Set<IArtifactDescriptor> descriptors = new ArtifactsIO().readXML(p2DataFileStream);
- for (IArtifactDescriptor descriptor : descriptors) {
- ModuleArtifactDescriptor internalDescriptor = getInternalDescriptorFromLoadedDescriptor(descriptor,
- p2DataFile);
- // TODO check that GAV properties match module GAV
- internalAddInternalDescriptor(internalDescriptor);
- }
- } finally {
- p2DataFileStream.close();
+ try (FileInputStream p2DataFileStream = new FileInputStream(p2DataFile)) {
+ Set<IArtifactDescriptor> descriptors = new ArtifactsIO().readXML(p2DataFileStream);
+ for (IArtifactDescriptor descriptor : descriptors) {
+ ModuleArtifactDescriptor internalDescriptor = getInternalDescriptorFromLoadedDescriptor(descriptor,
+ p2DataFile);
+ // TODO check that GAV properties match module GAV
+ internalAddInternalDescriptor(internalDescriptor);
}
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw failedReadException(p2DataFile, null, e);
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/repo/MetadataSerializableImplTest.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/repo/MetadataSerializableImplTest.java
index 9078877c9..87343b36f 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/repo/MetadataSerializableImplTest.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl.test/src/test/java/org/eclipse/tycho/p2/repo/MetadataSerializableImplTest.java
@@ -88,12 +88,9 @@ public class MetadataSerializableImplTest {
}
private void serialize(MetadataSerializableImpl subject, Set<?> units, File tmpDir) throws FileNotFoundException,
- IOException {
- FileOutputStream os = new FileOutputStream(new File(tmpDir, "content.xml"));
- try {
+ IOException {
+ try (FileOutputStream os = new FileOutputStream(new File(tmpDir, "content.xml"))) {
subject.serialize(os, units);
- } finally {
- os.close();
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/PomDependencyCollectorImpl.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/PomDependencyCollectorImpl.java
index c7eabd19a..169f8787d 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/PomDependencyCollectorImpl.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/PomDependencyCollectorImpl.java
@@ -73,12 +73,9 @@ public class PomDependencyCollectorImpl implements PomDependencyCollector {
}
private Set<IInstallableUnit> readUnits(IArtifactFacade p2MetadataFile) throws IOException {
- FileInputStream inputStream = new FileInputStream(p2MetadataFile.getLocation());
- try {
+ try (FileInputStream inputStream = new FileInputStream(p2MetadataFile.getLocation())) {
MetadataIO io = new MetadataIO();
return io.readXML(inputStream);
- } finally {
- inputStream.close();
}
}
diff --git a/tycho-bundles/org.eclipse.tycho.p2.tools.impl/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublisherServiceImpl.java b/tycho-bundles/org.eclipse.tycho.p2.tools.impl/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublisherServiceImpl.java
index 8ca24143c..7ff4136bd 100644
--- a/tycho-bundles/org.eclipse.tycho.p2.tools.impl/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublisherServiceImpl.java
+++ b/tycho-bundles/org.eclipse.tycho.p2.tools.impl/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublisherServiceImpl.java
@@ -85,12 +85,9 @@ class PublisherServiceImpl implements PublisherService {
void validateProfile(File profileFile) throws FacadeException {
Properties profileProperties = new Properties();
try {
- FileInputStream stream = new FileInputStream(profileFile);
- try {
+ try (FileInputStream stream = new FileInputStream(profileFile)) {
profileProperties.load(stream);
validateProfile(profileProperties, profileFile);
- } finally {
- stream.close();
}
} catch (IOException e) {
throw new FacadeException(e);
diff --git a/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/repository/streaming/testutil/ProbeOutputStream.java b/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/repository/streaming/testutil/ProbeOutputStream.java
index 7e473f4cb..119bbe0ff 100644
--- a/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/repository/streaming/testutil/ProbeOutputStream.java
+++ b/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/repository/streaming/testutil/ProbeOutputStream.java
@@ -54,13 +54,10 @@ public class ProbeOutputStream extends OutputStream implements IStateful {
public Set<String> getFilesInZip() throws IOException {
HashSet<String> result = new HashSet<>();
- ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(byteBuffer.toByteArray()));
- try {
+ try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(byteBuffer.toByteArray()))) {
for (ZipEntry entry = zipStream.getNextEntry(); entry != null; entry = zipStream.getNextEntry()) {
result.add(entry.getName());
}
- } finally {
- zipStream.close();
}
return result;
diff --git a/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/FileServerServlet.java b/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/FileServerServlet.java
index b545fe41a..d396d2f93 100644
--- a/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/FileServerServlet.java
+++ b/tycho-bundles/org.eclipse.tycho.test.utils/src/main/java/org/eclipse/tycho/test/util/FileServerServlet.java
@@ -45,8 +45,7 @@ public class FileServerServlet extends AbstractMonitorServlet {
addUri(req);
- InputStream input = new FileInputStream(file);
- try {
+ try (InputStream input = new FileInputStream(file)) {
OutputStream output = res.getOutputStream();
try {
final byte[] buffer = new byte[10240];
@@ -57,8 +56,6 @@ public class FileServerServlet extends AbstractMonitorServlet {
} finally {
output.close();
}
- } finally {
- input.close();
}
}
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java
index adbf5fab5..43e34f6f6 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java
@@ -74,16 +74,13 @@ public class DefaultBundleReader extends AbstractLogEnabled implements BundleRea
// file but not a jar, assume it is MANIFEST.MF
return loadManifestFile(bundleLocation);
}
- // it is a jar, let's see if it has OSGi bundle manifest
- ZipFile jar = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
- try {
+ try ( // it is a jar, let's see if it has OSGi bundle manifest
+ ZipFile jar = new ZipFile(bundleLocation, ZipFile.OPEN_READ)) {
ZipEntry manifestEntry = jar.getEntry(JarFile.MANIFEST_NAME);
if (manifestEntry != null) {
InputStream stream = jar.getInputStream(manifestEntry);
return OsgiManifest.parse(stream, bundleLocation.getAbsolutePath() + "!/" + JarFile.MANIFEST_NAME);
}
- } finally {
- jar.close();
}
throw new OsgiManifestParserException(bundleLocation.getAbsolutePath(),
"Manifest file not found in JAR archive");
@@ -144,8 +141,7 @@ public class DefaultBundleReader extends AbstractLogEnabled implements BundleRea
}
private void extractZipEntries(File bundleLocation, String path, File outputDirectory) throws IOException {
- ZipFile zip = new ZipFile(bundleLocation);
- try {
+ try (ZipFile zip = new ZipFile(bundleLocation)) {
ZipEntry singleEntry = zip.getEntry(path);
InputStream singleEntryStream;
if (singleEntry != null && !singleEntry.isDirectory()
@@ -163,8 +159,6 @@ public class DefaultBundleReader extends AbstractLogEnabled implements BundleRea
}
}
}
- } finally {
- zip.close();
}
}
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/EclipseInstallationLayout.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/EclipseInstallationLayout.java
index 4361cc64e..6170a2a38 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/EclipseInstallationLayout.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/targetplatform/EclipseInstallationLayout.java
@@ -134,8 +134,7 @@ public class EclipseInstallationLayout extends AbstractLogEnabled {
File platform = new File(location, "configuration/org.eclipse.update/platform.xml");
if (platform.canRead()) {
try {
- FileInputStream is = new FileInputStream(platform);
- try {
+ try (FileInputStream is = new FileInputStream(platform)) {
XmlStreamReader reader = new XmlStreamReader(is);
Xpp3Dom dom = Xpp3DomBuilder.build(reader);
Xpp3Dom[] sites = dom.getChildren("site");
@@ -148,8 +147,6 @@ public class EclipseInstallationLayout extends AbstractLogEnabled {
}
}
}
- } finally {
- is.close();
}
} catch (Exception e) {
getLogger().warn("Exception parsing " + toString(platform), e);
@@ -192,11 +189,8 @@ public class EclipseInstallationLayout extends AbstractLogEnabled {
if (link.isFile() && link.canRead() && link.getName().endsWith(".link")) {
Properties props = new Properties();
try {
- InputStream is = new FileInputStream(link);
- try {
+ try (InputStream is = new FileInputStream(link)) {
props.load(is);
- } finally {
- is.close();
}
String path = props.getProperty("path");
if (path != null) {
@@ -254,8 +248,7 @@ public class EclipseInstallationLayout extends AbstractLogEnabled {
File eclipseIni = new File(platformBase, "eclipse.ini");
File pool = platformBase;
if (eclipseIni.isFile() && eclipseIni.canRead()) {
- BufferedReader in = new BufferedReader(new FileReader(eclipseIni));
- try {
+ try (BufferedReader in = new BufferedReader(new FileReader(eclipseIni))) {
String str = null;
while ((str = in.readLine()) != null) {
if ("-startup".equals(str.trim())) {
@@ -270,8 +263,6 @@ public class EclipseInstallationLayout extends AbstractLogEnabled {
break;
}
}
- } finally {
- in.close();
}
}
diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java b/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java
index 08de32e44..e9b6a38ef 100644
--- a/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java
+++ b/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java
@@ -44,12 +44,12 @@ public class LockProcess {
public static void main(String[] args) throws Exception {
File file = new File(args[0]);
long wait = Long.valueOf(args[1]);
- RandomAccessFile raFile = new RandomAccessFile(file, "rw");
- FileLock lock = raFile.getChannel().lock(0, 1, false);
- System.out.println(LOCK_ACQUIRED_MSG);
- Thread.sleep(wait);
- lock.release();
- raFile.close();
+ try (RandomAccessFile raFile = new RandomAccessFile(file, "rw")) {
+ FileLock lock = raFile.getChannel().lock(0, 1, false);
+ System.out.println(LOCK_ACQUIRED_MSG);
+ Thread.sleep(wait);
+ lock.release();
+ }
}
public void lockFileInForkedProcess() {
@@ -96,14 +96,14 @@ public class LockProcess {
String classNamePath = LockProcess.class.getName().replace('.', '/') + ".class";
File tmpClassFile = new File(tmpClassDir, classNamePath);
tmpClassFile.getParentFile().mkdirs();
- OutputStream out = new FileOutputStream(tmpClassFile);
- byte[] buffer = new byte[1024];
- int read = 0;
- while ((read = in.read(buffer, 0, buffer.length)) != -1) {
- out.write(buffer, 0, read);
+ try (OutputStream out = new FileOutputStream(tmpClassFile)) {
+ byte[] buffer = new byte[1024];
+ int read = 0;
+ while ((read = in.read(buffer, 0, buffer.length)) != -1) {
+ out.write(buffer, 0, read);
+ }
+ in.close();
}
- in.close();
- out.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Feature.java b/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Feature.java
index 1f9716187..5dde02a3f 100644
--- a/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Feature.java
+++ b/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Feature.java
@@ -240,16 +240,13 @@ public class Feature {
}
public static Feature readJar(File file) throws IOException {
- JarFile jar = new JarFile(file);
- try {
+ try (JarFile jar = new JarFile(file)) {
ZipEntry ze = jar.getEntry(FEATURE_XML);
if (ze != null) {
InputStream is = jar.getInputStream(ze);
return read(is);
}
throw new IOException(file.getAbsolutePath() + " does not have " + FEATURE_XML + " entry.");
- } finally {
- jar.close();
}
}
diff --git a/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Platform.java b/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Platform.java
index bacac3fc8..fc317da72 100644
--- a/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Platform.java
+++ b/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/Platform.java
@@ -169,21 +169,15 @@ public class Platform {
@SuppressWarnings("deprecation")
public static Platform read(File file) throws IOException, XmlPullParserException {
- XmlStreamReader reader = ReaderFactory.newXmlReader(file);
- try {
+ try (XmlStreamReader reader = ReaderFactory.newXmlReader(file)) {
return new Platform(Xpp3DomBuilder.build(reader));
- } finally {
- reader.close();
}
}
public static void write(Platform platform, File file) throws IOException {
file.getParentFile().mkdirs();
- Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
- try {
+ try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
Xpp3DomWriter.write(writer, platform.dom);
- } finally {
- writer.close();
}
}
diff --git a/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java b/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java
index 515faa71f..4dc8b5e1e 100644
--- a/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java
+++ b/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java
@@ -159,11 +159,8 @@ public class TarGzArchiver {
}
private static void copyFileContentToTarStream(File source, TarArchiveOutputStream tarStream) throws IOException {
- BufferedInputStream sourceStream = new BufferedInputStream(new FileInputStream(source));
- try {
+ try (BufferedInputStream sourceStream = new BufferedInputStream(new FileInputStream(source))) {
IOUtils.copy(sourceStream, tarStream);
- } finally {
- sourceStream.close();
}
}
diff --git a/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java b/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java
index 8e01f4b3a..514b66aa5 100644
--- a/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java
+++ b/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java
@@ -220,9 +220,8 @@ public class TarGzArchiverTest {
}
private byte[] getTarEntry(String name) throws IOException {
- TarArchiveInputStream tarStream = new TarArchiveInputStream(
- new GzipCompressorInputStream(new FileInputStream(tarGzArchive)));
- try {
+ try (TarArchiveInputStream tarStream = new TarArchiveInputStream(
+ new GzipCompressorInputStream(new FileInputStream(tarGzArchive)))) {
TarArchiveEntry tarEntry = null;
while ((tarEntry = tarStream.getNextTarEntry()) != null) {
if (name.equals(tarEntry.getName())) {
@@ -231,8 +230,6 @@ public class TarGzArchiverTest {
return baos.toByteArray();
}
}
- } finally {
- tarStream.close();
}
throw new IOException(name + " not found in " + tarGzArchive);
}
diff --git a/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/facade/RepositoryReferenceTool.java b/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/facade/RepositoryReferenceTool.java
index afc5d1f58..d59db8996 100644
--- a/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/facade/RepositoryReferenceTool.java
+++ b/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/facade/RepositoryReferenceTool.java
@@ -108,8 +108,7 @@ public class RepositoryReferenceTool {
try {
File repositoryLocation = new File(project.getBuild().getDirectory(), "targetPlatformRepository");
repositoryLocation.mkdirs();
- FileOutputStream stream = new FileOutputStream(new File(repositoryLocation, "content.xml"));
- try {
+ try (FileOutputStream stream = new FileOutputStream(new File(repositoryLocation, "content.xml"))) {
MetadataSerializable serializer = osgiServices.getService(MetadataSerializable.class);
TargetPlatform targetPlatform = TychoProjectUtils.getTargetPlatform(project);
@@ -140,8 +139,6 @@ public class RepositoryReferenceTool {
}
serializer.serialize(stream, targetPlatformInstallableUnits);
- } finally {
- stream.close();
}
sources.addMetadataRepository(repositoryLocation);
} catch (IOException e) {
diff --git a/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/TargetDefinitionFile.java b/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/TargetDefinitionFile.java
index 8af02237f..bbc2287ae 100644
--- a/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/TargetDefinitionFile.java
+++ b/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/TargetDefinitionFile.java
@@ -271,12 +271,9 @@ public final class TargetDefinitionFile implements TargetDefinition {
this.includeSourceMode = includeSourceMode;
- FileInputStream input = new FileInputStream(source);
- try {
+ try (FileInputStream input = new FileInputStream(source)) {
this.document = parser.parse(new XMLIOSource(source));
this.dom = document.getRootElement();
- } finally {
- input.close();
}
} catch (XMLParseException e) {
throw new TargetDefinitionSyntaxException("Target definition is not well-formed XML: " + e.getMessage(), e);
@@ -365,11 +362,8 @@ public final class TargetDefinitionFile implements TargetDefinition {
private static byte[] computeFileContentHash(File source) {
byte[] digest;
try {
- FileInputStream in = new FileInputStream(source);
- try {
+ try (FileInputStream in = new FileInputStream(source)) {
digest = computeMD5Digest(in);
- } finally {
- in.close();
}
} catch (IOException e) {
throw new RuntimeException("I/O error while reading \"" + source + "\": " + e.getMessage(), e);
diff --git a/tycho-p2/tycho-p2-plugin/src/test/java/org/eclipse/tycho/plugins/p2/P2MetadataMojoTest.java b/tycho-p2/tycho-p2-plugin/src/test/java/org/eclipse/tycho/plugins/p2/P2MetadataMojoTest.java
index 31aa7e764..81f327af5 100644
--- a/tycho-p2/tycho-p2-plugin/src/test/java/org/eclipse/tycho/plugins/p2/P2MetadataMojoTest.java
+++ b/tycho-p2/tycho-p2-plugin/src/test/java/org/eclipse/tycho/plugins/p2/P2MetadataMojoTest.java
@@ -80,11 +80,8 @@ public class P2MetadataMojoTest {
private static Properties loadProperties(File propertiesFile) throws IOException {
Properties properties = new Properties();
- FileInputStream propertiesStream = new FileInputStream(propertiesFile);
- try {
+ try (FileInputStream propertiesStream = new FileInputStream(propertiesFile)) {
properties.load(propertiesStream);
- } finally {
- propertiesStream.close();
}
return properties;
}
diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java
index 040063281..0a7ab38cb 100644
--- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java
+++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java
@@ -122,8 +122,7 @@ public class FeatureXmlTransformer {
locker.lock();
try {
try {
- JarFile jar = new JarFile(location);
- try {
+ try (JarFile jar = new JarFile(location)) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
@@ -132,8 +131,6 @@ public class FeatureXmlTransformer {
installSize += entrySize;
}
}
- } finally {
- jar.close();
}
} catch (IOException e) {
throw new RuntimeException("Could not determine installation size of file " + location, e);
diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/LicenseFeatureHelper.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/LicenseFeatureHelper.java
index 534498e01..e5509ee59 100644
--- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/LicenseFeatureHelper.java
+++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/LicenseFeatureHelper.java
@@ -92,8 +92,7 @@ public class LicenseFeatureHelper {
// feature.properties, feature.xml and build.properties itself
BuildProperties buildProperties;
- ZipFile zip = new ZipFile(licenseFeature);
- try {
+ try (ZipFile zip = new ZipFile(licenseFeature)) {
ZipEntry entry = zip.getEntry(BuildPropertiesParser.BUILD_PROPERTIES);
if (entry != null) {
InputStream is = zip.getInputStream(entry);
@@ -103,8 +102,6 @@ public class LicenseFeatureHelper {
} else {
throw new IllegalArgumentException("license feature must include build.properties file");
}
- } finally {
- zip.close();
}
List<String> includes = buildProperties.getBinIncludes();
diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java
index 0515f5cb6..f0f863e84 100644
--- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java
+++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java
@@ -263,11 +263,8 @@ public class PackagePluginMojo extends AbstractTychoPackagingMojo {
soureReferenceComputer.addSourceReferenceHeader(mf, sourceReferences, project);
mfile = new File(project.getBuild().getDirectory(), "MANIFEST.MF");
mfile.getParentFile().mkdirs();
- BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(mfile));
- try {
+ try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(mfile))) {
mf.write(os);
- } finally {
- os.close();
}
return mfile;
diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java
index 6beaed237..f4583d700 100644
--- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java
+++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java
@@ -220,16 +220,13 @@ public class UpdateSiteAssembler extends ArtifactDependencyVisitor {
private void copyUrl(String source, File destination) {
try {
URL url = new URL(source);
- InputStream is = url.openStream();
- try {
+ try (InputStream is = url.openStream()) {
OutputStream os = new BufferedOutputStream(new FileOutputStream(destination));
try {
IOUtil.copy(is, os);
} finally {
os.close();
}
- } finally {
- is.close();
}
} catch (IOException e) {
throw new RuntimeException("Could not copy URL contents", e);
diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackagePluginMojoTest.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackagePluginMojoTest.java
index a04f8bae9..729a82894 100644
--- a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackagePluginMojoTest.java
+++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackagePluginMojoTest.java
@@ -33,12 +33,9 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
PackagePluginMojo mojo = execMaven(basedir);
createDummyClassFile(basedir);
mojo.execute();
- JarFile pluginJar = new JarFile(new File(basedir, "target/test.jar"));
- try {
+ try (JarFile pluginJar = new JarFile(new File(basedir, "target/test.jar"))) {
assertNull("class files from target/classes must not be included in plugin jar if no '.' in bin.includes",
pluginJar.getEntry("TestNoDot.class"));
- } finally {
- pluginJar.close();
}
}
@@ -50,8 +47,7 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
PackagePluginMojo mojo = execMaven(basedir);
createDummyClassFile(basedir);
mojo.execute();
- JarFile pluginJar = new JarFile(new File(basedir, "target/test.jar"));
- try {
+ try (JarFile pluginJar = new JarFile(new File(basedir, "target/test.jar"))) {
//make sure we can find the WEB-INF/classes/hello.properties
//and no hello.properties in the root.
assertNotNull(pluginJar.getEntry("WEB-INF/classes/hello.properties"));
@@ -60,8 +56,6 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
//and no TestNoDot.class in the root.
assertNotNull(pluginJar.getEntry("WEB-INF/classes/TestNoDot.class"));
assertNull(pluginJar.getEntry("TestNoDot.class"));
- } finally {
- pluginJar.close();
}
}
@@ -73,11 +67,8 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
PackagePluginMojo mojo = execMaven(basedir);
mojo.execute();
- JarFile pluginJar = new JarFile(new File(basedir, "target/test.jar"));
- try {
+ try (JarFile pluginJar = new JarFile(new File(basedir, "target/test.jar"))) {
assertNotNull(pluginJar.getEntry("foo.bar"));
- } finally {
- pluginJar.close();
}
}
@@ -88,11 +79,8 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
PackagePluginMojo mojo = execMaven(basedir);
mojo.execute();
- JarFile nestedJar = new JarFile(new File(basedir, "nested.jar"));
- try {
+ try (JarFile nestedJar = new JarFile(new File(basedir, "nested.jar"))) {
assertEquals("nested", nestedJar.getManifest().getMainAttributes().getValue("Bundle-SymbolicName"));
- } finally {
- nestedJar.close();
}
}
@@ -121,12 +109,9 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
PackagePluginMojo mojo = execMaven(basedir);
mojo.execute();
- JarFile nestedJar = new JarFile(new File(basedir, "target/pluginForcedToFalse.jar"));
- try {
+ try (JarFile nestedJar = new JarFile(new File(basedir, "target/pluginForcedToFalse.jar"))) {
assertNull("Jar must not contain the maven descriptor if forced to not include it!",
nestedJar.getEntry("META-INF/maven"));
- } finally {
- nestedJar.close();
}
}
@@ -137,11 +122,8 @@ public class PackagePluginMojoTest extends AbstractTychoMojoTestCase {
PackagePluginMojo mojo = execMaven(basedir);
mojo.execute();
- JarFile nestedJar = new JarFile(new File(basedir, "target/pluginDefault.jar"));
- try {
+ try (JarFile nestedJar = new JarFile(new File(basedir, "target/pluginDefault.jar"))) {
assertNotNull("Jar must contain the maven descriptor per default!", nestedJar.getEntry("META-INF/maven"));
- } finally {
- nestedJar.close();
}
}
diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackageUpdateSiteMojoTest.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackageUpdateSiteMojoTest.java
index a897da2ab..d6693f67f 100644
--- a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackageUpdateSiteMojoTest.java
+++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildnumber/test/PackageUpdateSiteMojoTest.java
@@ -76,12 +76,9 @@ public class PackageUpdateSiteMojoTest extends AbstractTychoMojoTestCase {
Assert.assertTrue(attachedArtifacts.get(0).getFile().equals(assemblyZip));
Assert.assertTrue(attachedArtifacts.get(0).getClassifier().equals("assembly"));
Assert.assertTrue(attachedArtifacts.get(0).getType().equals("zip"));
- ZipFile zip = new ZipFile(assemblyZip);
- try {
+ try (ZipFile zip = new ZipFile(assemblyZip)) {
assertNotNull(zip.getEntry("site.xml"));
assertNotNull(zip.getEntry("content.xml"));
- } finally {
- zip.close();
}
}
@@ -105,11 +102,8 @@ public class PackageUpdateSiteMojoTest extends AbstractTychoMojoTestCase {
Assert.assertTrue(attachedArtifacts.get(0).getFile().equals(assemblyZip));
Assert.assertTrue(attachedArtifacts.get(0).getClassifier().equals("assembly"));
Assert.assertTrue(attachedArtifacts.get(0).getType().equals("zip"));
- ZipFile zip = new ZipFile(assemblyZip);
- try {
+ try (ZipFile zip = new ZipFile(assemblyZip)) {
assertNotNull(zip.getEntry("associate-sites.xml"));
- } finally {
- zip.close();
}
}
@@ -118,12 +112,9 @@ public class PackageUpdateSiteMojoTest extends AbstractTychoMojoTestCase {
Assert.assertTrue(resultzip.exists());
Assert.assertEquals(project.getArtifact().getFile(), resultzip);
- ZipFile zip = new ZipFile(resultzip);
- try {
+ try (ZipFile zip = new ZipFile(resultzip)) {
assertNotNull(zip.getEntry("site.xml"));
assertNull(zip.getEntry("content.xml"));
- } finally {
- zip.close();
}
}
diff --git a/tycho-pomgenerator-plugin/src/main/java/org/eclipse/tycho/pomgenerator/GeneratePomsMojo.java b/tycho-pomgenerator-plugin/src/main/java/org/eclipse/tycho/pomgenerator/GeneratePomsMojo.java
index 0cf9a45b3..e3d3b6bc2 100644
--- a/tycho-pomgenerator-plugin/src/main/java/org/eclipse/tycho/pomgenerator/GeneratePomsMojo.java
+++ b/tycho-pomgenerator-plugin/src/main/java/org/eclipse/tycho/pomgenerator/GeneratePomsMojo.java
@@ -668,8 +668,7 @@ public class GeneratePomsMojo extends AbstractMojo {
setParentOrAddTychoExtension(basedir, model, parent);
try {
- FileInputStream is = new FileInputStream(new File(basedir, "feature.xml"));
- try {
+ try (FileInputStream is = new FileInputStream(new File(basedir, "feature.xml"))) {
XmlStreamReader reader = new XmlStreamReader(is);
Xpp3Dom dom = Xpp3DomBuilder.build(reader);
@@ -681,8 +680,6 @@ public class GeneratePomsMojo extends AbstractMojo {
model.setArtifactId(dom.getAttribute("id"));
model.setVersion(toMavenVersion(dom.getAttribute("version")));
- } finally {
- is.close();
}
} catch (XmlPullParserException | IOException e) {
throw new MojoExecutionException("Can't create pom.xml file", e);
@@ -733,11 +730,8 @@ public class GeneratePomsMojo extends AbstractMojo {
private void writePom(File dir, String filename, Model model) throws MojoExecutionException {
try {
- Writer writer = new OutputStreamWriter(new FileOutputStream(new File(dir, filename)), "UTF-8");
- try {
+ try (Writer writer = new OutputStreamWriter(new FileOutputStream(new File(dir, filename)), "UTF-8")) {
modelWriter.write(writer, model);
- } finally {
- writer.close();
}
} catch (IOException e) {
throw new MojoExecutionException("Can't write pom.xml", e);
diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
index 59fd83e6b..398ab3a5f 100644
--- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
+++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
@@ -986,11 +986,8 @@ public class TestMojo extends AbstractMojo {
Properties p = new Properties();
p.putAll(propertiesMap);
try {
- BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
- try {
+ try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
p.store(out, null);
- } finally {
- out.close();
}
} catch (IOException e) {
throw new MojoExecutionException("Can't write test launcher properties file", e);
diff --git a/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/ArchiveContentUtil.java b/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/ArchiveContentUtil.java
index 46673962f..f25c4a13b 100644
--- a/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/ArchiveContentUtil.java
+++ b/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/ArchiveContentUtil.java
@@ -62,16 +62,13 @@ public class ArchiveContentUtil {
}
static void visitEntries(File archive, ZipEntryVisitor visitor) throws Exception {
- FileInputStream fileStream = new FileInputStream(archive);
- try {
+ try (FileInputStream fileStream = new FileInputStream(archive)) {
ZipInputStream zipStream = new ZipInputStream(fileStream);
try {
visitEntries(zipStream, visitor);
} finally {
zipStream.close();
}
- } finally {
- fileStream.close();
}
}
diff --git a/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/LocalMavenRepositoryTool.java b/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/LocalMavenRepositoryTool.java
index f580a07b5..c3cc2caac 100644
--- a/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/LocalMavenRepositoryTool.java
+++ b/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/LocalMavenRepositoryTool.java
@@ -113,26 +113,20 @@ public class LocalMavenRepositoryTool {
private Set<String> readLines(File indexFile) throws UnsupportedEncodingException, FileNotFoundException,
IOException {
Set<String> lines = new LinkedHashSet<>();
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(indexFile), "UTF-8"));
- try {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(indexFile), "UTF-8"))) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
lines.add(line);
}
- } finally {
- reader.close();
}
return lines;
}
private void writeLines(File indexFile, Collection<String> lines) throws UnsupportedEncodingException,
FileNotFoundException, IOException {
- PrintStream writer = new PrintStream(indexFile);
- try {
+ try (PrintStream writer = new PrintStream(indexFile)) {
for (String line : lines) {
writer.println(line);
}
- } finally {
- writer.close();
}
}
diff --git a/tycho-testing-harness/src/main/java/org/eclipse/tycho/testing/AbstractTychoMojoTestCase.java b/tycho-testing-harness/src/main/java/org/eclipse/tycho/testing/AbstractTychoMojoTestCase.java
index 8961a0bdb..af58fd1a8 100644
--- a/tycho-testing-harness/src/main/java/org/eclipse/tycho/testing/AbstractTychoMojoTestCase.java
+++ b/tycho-testing-harness/src/main/java/org/eclipse/tycho/testing/AbstractTychoMojoTestCase.java
@@ -106,11 +106,8 @@ public class AbstractTychoMojoTestCase extends AbstractMojoTestCase {
return new File(systemValue);
}
Properties props = new Properties();
- InputStream stream = AbstractTychoMojoTestCase.class.getResourceAsStream("settings.properties");
- try {
+ try (InputStream stream = AbstractTychoMojoTestCase.class.getResourceAsStream("settings.properties")) {
props.load(stream);
- } finally {
- stream.close();
}
String settingsFilePath = props.getProperty("settings.file");
return new File(settingsFilePath);

Back to the top