Skip to content

Commit

Permalink
Use try with resources to avoid deprecated class (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo authored and michael-o committed Jul 22, 2024
1 parent 2e867c6 commit adc67e1
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:[email protected]">Vincent Siveton</a>
Expand All @@ -41,31 +42,29 @@ 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();
}

/**
* @see org.apache.maven.project.MavenProject#getProperties()
*/
@Override
public Properties getProperties() {
return new Properties();
}
Expand All @@ -76,6 +75,7 @@ public DistributionManagement getDistributionManagement() {
}

/** {@inheritDoc} */
@Override
public File getBasedir() {
return basedir;
}
Expand Down

0 comments on commit adc67e1

Please sign in to comment.