diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java index d516709deab9..5832872f6fc5 100644 --- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java +++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AccessQueryImpl.java @@ -30,7 +30,6 @@ import java.util.regex.Pattern; import org.netbeans.api.annotations.common.SuppressWarnings; import org.netbeans.modules.maven.api.NbMavenProject; -import org.codehaus.plexus.util.IOUtil; import org.netbeans.api.project.Project; import org.netbeans.spi.java.queries.AccessibilityQueryImplementation; import org.netbeans.spi.project.ProjectServiceProvider; @@ -166,17 +165,13 @@ private static List loadPublicPackagesPatterns(Project project) { } else { FileObject obj = project.getProjectDirectory().getFileObject(MANIFEST_PATH); if (obj != null) { - InputStream in = null; - try { - in = obj.getInputStream(); + try (InputStream in = obj.getInputStream()) { Manifest man = new Manifest(); man.read(in); String value = man.getMainAttributes().getValue(ATTR_PUBLIC_PACKAGE); toRet = prepareManifestPublicPackagesPatterns(value); } catch (Exception ex) { Exceptions.printStackTrace(ex); - } finally { - IOUtil.close(in); } } } diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenWhiteListQueryImpl.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenWhiteListQueryImpl.java index 57500b4f7b89..f437c1ba3cc8 100644 --- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenWhiteListQueryImpl.java +++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenWhiteListQueryImpl.java @@ -44,7 +44,6 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.netbeans.api.annotations.common.NonNull; @@ -367,18 +366,14 @@ private Tuple cacheOrLoad() { private Manifest getManifest(FileObject root) { FileObject manifestFo = root.getFileObject("META-INF/MANIFEST.MF"); if (manifestFo != null) { - InputStream is = null; - try { - is = manifestFo.getInputStream(); - return new Manifest(is); + try (InputStream is = manifestFo.getInputStream()) { + Manifest manifest = new Manifest(is); + return manifest; } catch (IOException ex) { //Exceptions.printStackTrace(ex); - } finally { - IOUtil.close(is); } } return null; - } private static class MavenWhiteListImplementation implements WhiteListImplementation { diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java index b736d1e66f15..16b3c8508079 100644 --- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java +++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java @@ -24,6 +24,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Properties; @@ -32,7 +34,6 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.PluginManagement; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.eclipse.aether.repository.RemoteRepository; import org.netbeans.modules.apisupport.project.api.EditableManifest; @@ -103,14 +104,10 @@ public void run() { if (packageName != null) { String path = packageName.replace(".", "/") + "/Bundle.properties"; mf.setAttribute("OpenIDE-Module-Localizing-Bundle", path, null); - BufferedOutputStream bos = null; - try { - bos = new BufferedOutputStream(new FileOutputStream(new File(src, "manifest.mf"))); - mf.write(bos); + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(new File(src, "manifest.mf")))) { + mf.write(os); } catch (IOException ex) { Exceptions.printStackTrace(ex); - } finally { - IOUtil.close(bos); } } @@ -121,20 +118,13 @@ public void run() { String path = packageName.replace(".", File.separator); File res = new File(src, path); res.mkdirs(); - OutputStream bos = null; - try { - bos = new BufferedOutputStream(new FileOutputStream(new File(res, "Bundle.properties"))); + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(new File(res, "Bundle.properties")))) { Properties p = new Properties(); - p.store(bos, EMPTY_BUNDLE_FILE); - + p.store(os, EMPTY_BUNDLE_FILE); } catch (IOException ex) { Exceptions.printStackTrace(ex); - } finally { - IOUtil.close(bos); } - } - } } diff --git a/java/maven.checkstyle/nbproject/project.properties b/java/maven.checkstyle/nbproject/project.properties index 0f4ec98bc91a..3213bab58cb5 100644 --- a/java/maven.checkstyle/nbproject/project.properties +++ b/java/maven.checkstyle/nbproject/project.properties @@ -14,5 +14,6 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -javac.source=1.8 +javac.source=11 +javac.target=11 javac.compilerargs=-Xlint -Xlint:-serial diff --git a/java/maven.checkstyle/src/org/netbeans/modules/maven/checkstyle/Bundle.properties b/java/maven.checkstyle/src/org/netbeans/modules/maven/checkstyle/Bundle.properties index a4e92aff12ac..d78180a2e720 100644 --- a/java/maven.checkstyle/src/org/netbeans/modules/maven/checkstyle/Bundle.properties +++ b/java/maven.checkstyle/src/org/netbeans/modules/maven/checkstyle/Bundle.properties @@ -1,3 +1,4 @@ +OpenIDE-Module-Display-Category=Maven # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information diff --git a/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/AuxPropsImpl.java b/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/AuxPropsImpl.java index 2e13454800f5..65cf94a05abb 100644 --- a/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/AuxPropsImpl.java +++ b/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/AuxPropsImpl.java @@ -41,7 +41,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; -import org.codehaus.plexus.util.IOUtil; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.maven.api.Constants; @@ -93,14 +92,8 @@ private FileObject copyToCacheDir(InputStream in) throws IOException { if (file == null) { file = cacheDir.createData("checkstyle-checker", "xml"); } - InputStream inst = in; - OutputStream outst = null; - try { - outst = file.getOutputStream(); + try (in; OutputStream outst = file.getOutputStream()) { FileUtil.copy(in, outst); - } finally { - IOUtil.close(inst); - IOUtil.close(outst); } return file; } @@ -159,10 +152,8 @@ private Properties convert() { RP.post(new Runnable() { @Override public void run() { - InputStream urlis = null; - try { - urlis = url.openStream(); - byte[] arr = IOUtil.toByteArray(urlis); + try (InputStream urlis = url.openStream()) { + byte[] arr = urlis.readAllBytes(); synchronized (AuxPropsImpl.this) { //#174401 ByteArrayInputStream bais = new ByteArrayInputStream(arr); @@ -171,8 +162,6 @@ public void run() { } } catch (IOException ex) { ex.printStackTrace(); - } finally { - IOUtil.close(urlis); } } }); diff --git a/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/ModuleConvertor.java b/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/ModuleConvertor.java index eaac07a0f2a2..9cef88099ccd 100644 --- a/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/ModuleConvertor.java +++ b/java/maven.checkstyle/src/org/netbeans/modules/maven/format/checkstyle/ModuleConvertor.java @@ -19,7 +19,6 @@ package org.netbeans.modules.maven.format.checkstyle; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import java.io.IOException; import java.io.InputStream; @@ -103,7 +102,7 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc return is; } }); - try { + try (checkstyleStream) { Document doc = bldr.build(checkstyleStream); Element root = doc.getRootElement(); processModule(root, "", props); @@ -114,8 +113,6 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); - } finally { - IOUtil.close(checkstyleStream); } return props; diff --git a/java/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java b/java/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java index 94c4d2f40807..4bf5554492ac 100644 --- a/java/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java +++ b/java/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java @@ -34,7 +34,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.jdom2.DefaultJDOMFactory; import org.jdom2.Document; @@ -415,10 +414,6 @@ private static void writeNbActionsModel(final Project project, final FileObject @Override public void run() throws IOException { JDOMFactory factory = new DefaultJDOMFactory(); - - InputStream inStr = null; - FileLock lock = null; - OutputStreamWriter outStr = null; try { Document doc; if (mapping.getActions().isEmpty()) { //#224450 don't write empty nbactions.xml files @@ -434,19 +429,19 @@ public void run() throws IOException { doc = factory.document(factory.element("actions")); //NOI18N } else { //TODO.. - inStr = fo.getInputStream(); - SAXBuilder builder = new SAXBuilder(); - doc = builder.build(inStr); - inStr.close(); - inStr = null; + try (InputStream inStr = fo.getInputStream()) { + SAXBuilder builder = new SAXBuilder(); + doc = builder.build(inStr); + } } - lock = fo.lock(); - NetbeansBuildActionJDOMWriter writer = new NetbeansBuildActionJDOMWriter(); String encoding = mapping.getModelEncoding() != null ? mapping.getModelEncoding() : "UTF-8"; //NOI18N - outStr = new OutputStreamWriter(fo.getOutputStream(lock), encoding); - Format form = Format.getRawFormat().setEncoding(encoding); - form = form.setLineSeparator(System.getProperty("line.separator")); //NOI18N - writer.write(mapping, doc, outStr, form); + try (FileLock lock = fo.lock(); + OutputStreamWriter outStr = new OutputStreamWriter(fo.getOutputStream(lock), encoding);) { + NetbeansBuildActionJDOMWriter writer = new NetbeansBuildActionJDOMWriter(); + Format form = Format.getRawFormat().setEncoding(encoding); + form = form.setLineSeparator(System.getProperty("line.separator")); //NOI18N + writer.write(mapping, doc, outStr, form); + } } catch (JDOMException exc){ //throw (IOException) new IOException("Cannot parse the nbactions.xml by JDOM.").initCause(exc); //NOI18N //TODO this would need it's own problem provider, but how to access it in project lookup if all are merged into one? @@ -461,13 +456,6 @@ public void run() throws IOException { impl.addReport(rep); } Logger.getLogger(CustomizerProviderImpl.class.getName()).log(Level.INFO, exc.getMessage(), exc); - } finally { - IOUtil.close(inStr); - IOUtil.close(outStr); - if (lock != null) { - lock.releaseLock(); - } - } } }); diff --git a/java/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java b/java/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java index 7ceb6dea6a9e..f24f5e5ec2de 100644 --- a/java/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java +++ b/java/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java @@ -28,6 +28,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; +import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; @@ -54,7 +55,6 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.netbeans.api.annotations.common.NonNull; @@ -1029,7 +1029,6 @@ private File checkAvailability(String ver, VersionRange vr, InputOutput ioput) { } else { f.mkdirs(); ioput.getOut().println("NetBeans: Downloading and unzipping Maven version " + ver); - ZipInputStream str = null; try { //this url pattern works for all versions except the last one 3.2.3 //which is only under /apache/maven/maven-3/3.2.3/binaries/ @@ -1048,24 +1047,19 @@ private File checkAvailability(String ver, VersionRange vr, InputOutput ioput) { LOGGER.log(Level.WARNING, "wasn''t able to download maven binaries, version {0}", ver); return null; } - str = new ZipInputStream(is); - ZipEntry entry; - while ((entry = str.getNextEntry()) != null) { - //base it of f not child as the zip contains the maven base folder - File fileOrDir = new File(f, entry.getName()); - if (entry.isDirectory()) { - fileOrDir.mkdirs(); - } else { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(fileOrDir); - FileUtil.copy(str, fos); - } finally { - IOUtil.close(fos); - } - // correct way to set executable flag? - if ("bin".equals(fileOrDir.getParentFile().getName()) && !fileOrDir.getName().endsWith(".conf")) { - fileOrDir.setExecutable(true); + try (ZipInputStream str = new ZipInputStream(is)) { + ZipEntry entry; + while ((entry = str.getNextEntry()) != null) { + //base it of f not child as the zip contains the maven base folder + File fileOrDir = new File(f, entry.getName()); + if (entry.isDirectory()) { + fileOrDir.mkdirs(); + } else { + Files.copy(str, fileOrDir.toPath()); + // correct way to set executable flag? + if ("bin".equals(fileOrDir.getParentFile().getName()) && !fileOrDir.getName().endsWith(".conf")) { + fileOrDir.setExecutable(true); + } } } } @@ -1088,8 +1082,6 @@ private File checkAvailability(String ver, VersionRange vr, InputOutput ioput) { } catch (IOException ex1) { Exceptions.printStackTrace(ex1); } - } finally { - IOUtil.close(str); } } return null;