Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use try with resources to avoid deprecated class #200

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:vincent.siveton@gmail.com">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