Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-01 10:02:03 +0000
committerAlexander Kurtakov2019-05-09 12:38:49 +0000
commit10db156967b43ca4a97e1721a98270ea6820c660 (patch)
tree463540aca0888728d92019a014aa4d88f2fc6ef9
parent8ca01e63fb37ec4a4a673a91ad290a639c1d5583 (diff)
downloadorg.eclipse.tycho.extras-10db156967b43ca4a97e1721a98270ea6820c660.tar.gz
org.eclipse.tycho.extras-10db156967b43ca4a97e1721a98270ea6820c660.tar.xz
org.eclipse.tycho.extras-10db156967b43ca4a97e1721a98270ea6820c660.zip
Convert to lambda or member reference and use try-with-resources
Convert anonymous inner classes to lambda expressions or member references. Convert try finally block to try-with-resources. Change-Id: Ied958838966ff4dd941913a1551a555639d975bf Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
-rw-r--r--pack200/tycho-pack200-impl/src/main/java/org/eclipse/tycho/extras/pack200/ForkedPack200Wrapper.java12
-rw-r--r--tycho-buildtimestamp-jgit/src/main/java/org/eclipse/tycho/extras/buildtimestamp/jgit/JGitBuildTimestampProvider.java5
-rw-r--r--tycho-custom-bundle-plugin/src/main/java/org/eclipse/tycho/extras/custombundle/CustomBundleMojo.java5
-rw-r--r--tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/JavadocRunner.java5
-rw-r--r--tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/TocWriter.java5
-rw-r--r--tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java13
6 files changed, 8 insertions, 37 deletions
diff --git a/pack200/tycho-pack200-impl/src/main/java/org/eclipse/tycho/extras/pack200/ForkedPack200Wrapper.java b/pack200/tycho-pack200-impl/src/main/java/org/eclipse/tycho/extras/pack200/ForkedPack200Wrapper.java
index 4a41c06..e3034fd 100644
--- a/pack200/tycho-pack200-impl/src/main/java/org/eclipse/tycho/extras/pack200/ForkedPack200Wrapper.java
+++ b/pack200/tycho-pack200-impl/src/main/java/org/eclipse/tycho/extras/pack200/ForkedPack200Wrapper.java
@@ -56,16 +56,8 @@ public class ForkedPack200Wrapper extends Pack200Wrapper {
cli.addArguments(new String[] { Pack200Wrapper.class.getName(), command, fileFrom.getCanonicalPath(),
fileTo.getCanonicalPath() });
- StreamConsumer out = new StreamConsumer() {
- public void consumeLine(String line) {
- System.out.println(line);
- }
- };
- StreamConsumer err = new StreamConsumer() {
- public void consumeLine(String line) {
- System.err.println(line);
- }
- };
+ StreamConsumer out = System.out::println;
+ StreamConsumer err = System.err::println;
try {
int rc = CommandLineUtils.executeCommandLine(cli, out, err, FORKED_PROCESS_TIMEOUT_SECONDS);
diff --git a/tycho-buildtimestamp-jgit/src/main/java/org/eclipse/tycho/extras/buildtimestamp/jgit/JGitBuildTimestampProvider.java b/tycho-buildtimestamp-jgit/src/main/java/org/eclipse/tycho/extras/buildtimestamp/jgit/JGitBuildTimestampProvider.java
index b3a092a..f128fdb 100644
--- a/tycho-buildtimestamp-jgit/src/main/java/org/eclipse/tycho/extras/buildtimestamp/jgit/JGitBuildTimestampProvider.java
+++ b/tycho-buildtimestamp-jgit/src/main/java/org/eclipse/tycho/extras/buildtimestamp/jgit/JGitBuildTimestampProvider.java
@@ -132,8 +132,7 @@ public class JGitBuildTimestampProvider implements BuildTimestampProvider {
throw new MojoExecutionException("No git repository found searching upwards from " + project.getBasedir());
}
try {
- Repository repository = builder.build();
- try {
+ try (Repository repository = builder.build()) {
String relPath = getRelPath(repository, project);
TreeFilter pathFilter = createPathFilter(relPath, execution);
ObjectId headId = repository.resolve(Constants.HEAD);
@@ -190,8 +189,6 @@ public class JGitBuildTimestampProvider implements BuildTimestampProvider {
} finally {
walk.close();
}
- } finally {
- repository.close();
}
} catch (IOException e) {
throw new MojoExecutionException("Could not determine git commit timestamp", e);
diff --git a/tycho-custom-bundle-plugin/src/main/java/org/eclipse/tycho/extras/custombundle/CustomBundleMojo.java b/tycho-custom-bundle-plugin/src/main/java/org/eclipse/tycho/extras/custombundle/CustomBundleMojo.java
index a07485d..1ee562f 100644
--- a/tycho-custom-bundle-plugin/src/main/java/org/eclipse/tycho/extras/custombundle/CustomBundleMojo.java
+++ b/tycho-custom-bundle-plugin/src/main/java/org/eclipse/tycho/extras/custombundle/CustomBundleMojo.java
@@ -148,11 +148,8 @@ public class CustomBundleMojo extends AbstractMojo {
mfile = new File(project.getBuild().getDirectory(), classifier + "-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-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/JavadocRunner.java b/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/JavadocRunner.java
index be5a260..f2ee624 100644
--- a/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/JavadocRunner.java
+++ b/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/JavadocRunner.java
@@ -96,8 +96,7 @@ public class JavadocRunner {
final File optionsFile = new File(this.buildDirectory, "javadoc.options.txt");
final Commandline cli = createCommandLine(optionsFile.getAbsolutePath());
- final PrintStream ps = new PrintStream(optionsFile);
- try {
+ try (PrintStream ps = new PrintStream(optionsFile)) {
ps.print(createOptionsFileContent());
ps.close();
@@ -110,8 +109,6 @@ public class JavadocRunner {
this.log.info("execution failed with rc = " + rc);
}
}
- } finally {
- ps.close();
}
}
diff --git a/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/TocWriter.java b/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/TocWriter.java
index 2b9a137..2ff999d 100644
--- a/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/TocWriter.java
+++ b/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/TocWriter.java
@@ -105,15 +105,12 @@ public class TocWriter {
createTopic(doc, main, "Constant Values", "constant-values.html");
createTopic(doc, main, "Deprecated List", "deprecated-list.html");
- final LineNumberReader reader = new LineNumberReader(new FileReader(new File(this.javadocDir, "package-list")));
- try {
+ try (LineNumberReader reader = new LineNumberReader(new FileReader(new File(this.javadocDir, "package-list")))) {
String line;
while ((line = reader.readLine()) != null) {
createTopic(doc, packages, line, line.replace('.', '/') + "/package-summary.html");
}
- } finally {
- reader.close();
}
}
diff --git a/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java b/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java
index e1cb096..a021bd3 100644
--- a/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java
+++ b/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java
@@ -180,11 +180,8 @@ public class TychoModelReader extends ModelReaderSupport {
private Attributes readManifestHeaders(File manifestFile) throws IOException {
Manifest manifest = new Manifest();
- FileInputStream stream = new FileInputStream(manifestFile);
- try {
+ try (FileInputStream stream = new FileInputStream(manifestFile)) {
manifest.read(stream);
- } finally {
- stream.close();
}
return manifest.getMainAttributes();
}
@@ -207,13 +204,7 @@ public class TychoModelReader extends ModelReaderSupport {
}
private File getProductFile(File projectRoot) {
- File[] productFiles = projectRoot.listFiles(new FilenameFilter() {
-
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".product");
- }
- });
+ File[] productFiles = projectRoot.listFiles((File dir, String name) -> name.endsWith(".product"));
if (productFiles.length > 0 && productFiles[0].isFile()) {
return productFiles[0];
}

Back to the top