Skip to content
Merged
Show file tree
Hide file tree
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 @@ -41,7 +41,6 @@
import org.codehaus.plexus.mailsender.MailMessage;
import org.codehaus.plexus.mailsender.MailSenderException;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;

/**
* Goal which sends an announcement through email.
Expand Down Expand Up @@ -339,7 +338,7 @@ protected void sendMessage() throws MojoExecutionException {
protected String readAnnouncement(File file) throws MojoExecutionException {
try {
if (templateEncoding == null || templateEncoding.isEmpty()) {
templateEncoding = ReaderFactory.FILE_ENCODING;
templateEncoding = System.getProperty("file.encoding");
getLog().warn("File encoding has not been set, using platform encoding '" + templateEncoding
+ "', i.e. build is platform dependent!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import org.apache.commons.io.input.XmlStreamReader;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
import org.xml.sax.SAXException;

/**
Expand Down Expand Up @@ -88,26 +87,15 @@ public Schema getSchema(String schemaPath) throws SAXException, IOException {
return schema;
}

/**
* @param uriSchema
* @return Schema
* @throws Exception
*/
private Schema compileJAXPSchema(String uriSchema) throws IOException, SAXException, NullPointerException {
InputStream in = null;
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uriSchema);
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uriSchema)) {
if (in == null) {
throw new NullPointerException(" impossible to load schema with path " + uriSchema);
}

// newInstance de SchemaFactory not ThreadSafe
final Schema schema = SchemaFactory.newInstance(W3C_XML_SCHEMA).newSchema(new StreamSource(in));
in.close();
in = null;
return schema;
} finally {
IOUtil.close(in);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.StatusLine;
Expand All @@ -57,7 +56,6 @@ public ClassicJiraDownloader() {}

/**
* Execute the query on the JIRA server.
*
*/
public void doExecute() {
try {
Expand Down Expand Up @@ -306,22 +304,17 @@ private void determineProxy(String jiraUrl, HttpClient client) {
* @param link the URL to JIRA
*/
private void download(final HttpClient cl, final String link) {
InputStream in = null;
OutputStream out = null;
try {
GetMethod gm = new GetMethod(link);

getLog().info("Downloading from JIRA at: " + link);

gm.setFollowRedirects(true);

GetMethod gm = new GetMethod(link);
getLog().info("Downloading from JIRA at: " + link);
gm.setFollowRedirects(true);
try {
cl.executeMethod(gm);

StatusLine sl = gm.getStatusLine();

if (sl == null) {
getLog().error("Unknown error validating link: " + link);

return;
}

Expand All @@ -333,47 +326,34 @@ private void download(final HttpClient cl, final String link) {
getLog().warn("Site sent redirect, but did not set Location header");
} else {
String newLink = locationHeader.getValue();

getLog().debug("Following redirect to " + newLink);

download(cl, newLink);
}
}

if (gm.getStatusCode() == HttpStatus.SC_OK) {
in = gm.getResponseBodyAsStream();

if (!output.getParentFile().exists()) {
output.getParentFile().mkdirs();
if (!output.getParentFile().mkdirs()) {
getLog().error("Downloading issues from JIRA failed. Could not create "
+ output.getParentFile());
return;
}
}

// write the response to file
out = new FileOutputStream(output);
IOUtil.copy(in, out);
out.close();
out = null;
in.close();
in = null;

getLog().debug("Downloading from JIRA was successful");
try (InputStream in = gm.getResponseBodyAsStream();
OutputStream out = new FileOutputStream(output)) {
IOUtil.copy(in, out);
getLog().debug("Downloading from JIRA was successful");
}
} else {
getLog().warn("Downloading from JIRA failed. Received: [" + gm.getStatusCode() + "]");
}
} catch (HttpException e) {
if (getLog().isDebugEnabled()) {
getLog().error("Error downloading issues from JIRA:", e);
} else {
getLog().error("Error downloading issues from JIRA url: " + e.getLocalizedMessage());
}
} catch (IOException e) {
if (getLog().isDebugEnabled()) {
getLog().error("Error downloading issues from JIRA:", e);
} else {
getLog().error("Error downloading issues from JIRA. Cause is " + e.getLocalizedMessage());
}
} finally {
IOUtil.close(out);
IOUtil.close(in);
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/apache/maven/plugins/jira/JiraXML.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand All @@ -35,7 +36,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.issues.Issue;
import org.codehaus.plexus.util.IOUtil;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
Expand Down Expand Up @@ -64,8 +64,8 @@ public class JiraXML extends DefaultHandler {
private SimpleDateFormat sdf;

/**
* @param log not null.
* @param datePattern may be null.
* @param log not null
* @param datePattern may be null
* @since 2.4
*/
public JiraXML(Log log, String datePattern) {
Expand All @@ -83,22 +83,20 @@ public JiraXML(Log log, String datePattern) {
}

/**
* Parse the given xml file. The list of issues can then be retrieved with {@link #getIssueList()}.
* Parse the given XML file. The list of issues can then be retrieved with {@link #getIssueList()}.
*
* @param xmlPath the file to pares.
* @throws MojoExecutionException in case of errors.
* @param xmlPath the file to parse
* @throws MojoExecutionException in case of errors
* @since 2.4
*/
public void parseXML(File xmlPath) throws MojoExecutionException {
InputStream xmlStream = null;
try {
xmlStream = new FileInputStream(xmlPath);
try (InputStream xmlStream = new FileInputStream(xmlPath)) {
InputSource inputSource = new InputSource(xmlStream);
parse(inputSource);
} catch (FileNotFoundException e) {
throw new MojoExecutionException("Failed to open JIRA XML file " + xmlPath, e);
} finally {
IOUtil.close(xmlStream);
} catch (IOException e) {
throw new MojoExecutionException("Failed to read JIRA XML file " + xmlPath, e);
}
}

Expand Down