From adc67e182048eeae17c87a73d411a52a686934dd Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 21 Jul 2024 18:38:25 +0000 Subject: [PATCH] Use try with resources to avoid deprecated class (#200) --- .../site/stubs/SiteMavenProjectStub.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java index f624b2ce..2e229cd7 100644 --- a/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java @@ -19,15 +19,16 @@ package org.apache.maven.plugins.site.stubs; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.Properties; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Site; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.xml.XmlStreamReader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * @author Vincent Siveton @@ -41,24 +42,21 @@ public class SiteMavenProjectStub extends MavenProjectStub { public SiteMavenProjectStub(String projectName) { basedir = new File(super.getBasedir() + "/src/test/resources/unit/" + projectName); - XmlStreamReader reader = null; - try { - reader = ReaderFactory.newXmlReader(new File(getBasedir(), "pom.xml")); - setModel(new MavenXpp3Reader().read(reader)); - reader.close(); - } catch (Exception e) { + File pom = new File(getBasedir(), "pom.xml"); + try (InputStream in = new FileInputStream(pom)) { + setModel(new MavenXpp3Reader().read(in)); + Site site = new Site(); + site.setId("localhost"); + distributionManagement.setSite(site); + } catch (IOException | XmlPullParserException e) { throw new RuntimeException(e); - } finally { - IOUtil.close(reader); } - Site site = new Site(); - site.setId("localhost"); - distributionManagement.setSite(site); } /** * @see org.apache.maven.project.MavenProject#getName() */ + @Override public String getName() { return getModel().getName(); } @@ -66,6 +64,7 @@ public String getName() { /** * @see org.apache.maven.project.MavenProject#getProperties() */ + @Override public Properties getProperties() { return new Properties(); } @@ -76,6 +75,7 @@ public DistributionManagement getDistributionManagement() { } /** {@inheritDoc} */ + @Override public File getBasedir() { return basedir; }