diff --git a/src/it/MLICENSE-44/pom.xml b/src/it/MLICENSE-44/pom.xml
index ae6799944..4f9c20b53 100644
--- a/src/it/MLICENSE-44/pom.xml
+++ b/src/it/MLICENSE-44/pom.xml
@@ -19,7 +19,7 @@
test
CodeHaus
- file:${basedir}/src/license
+ ${project.baseUri}/src/license
${basedir}/src/license/test/descriptionTemplate.ftl
2010
diff --git a/src/it/add-third-party-missing-file/pom.xml b/src/it/add-third-party-missing-file/pom.xml
index ed2279107..c7c0da6da 100644
--- a/src/it/add-third-party-missing-file/pom.xml
+++ b/src/it/add-third-party-missing-file/pom.xml
@@ -103,7 +103,7 @@
add-third-party
- file:///${basedir}/missing-licenses.properties
+ ${project.baseUri}/missing-licenses.properties
THIRD-PARTY-by-file.txt
diff --git a/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java
index 69450bb42..78ba9d0be 100644
--- a/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java
+++ b/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java
@@ -37,6 +37,7 @@
import java.util.concurrent.ConcurrentHashMap;
import freemarker.template.Template;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
@@ -758,7 +759,7 @@ private boolean processFile(FileHeaderProcessor processor, File file, File proce
// this is a costy operation
// TODO-TC-20100411 We should process always from the read content not reading again from file
- content = FileUtil.readAsString(file, getEncoding());
+ content = IOUtils.toString(file.toURI(), getEncoding());
} catch (IOException e) {
throw new IOException("Could not obtain content of file " + file);
@@ -859,7 +860,7 @@ private void finalizeFile(File file, File processFile) throws IOException {
} else {
try {
// replace file with the updated one
- String updatedContent = FileUtil.readAsString(processFile, getEncoding());
+ String updatedContent = IOUtils.toString(processFile.toURI(), getEncoding());
FileUtil.printString(file, updatedContent, getEncoding());
Files.deleteIfExists(processFile.toPath());
} catch (IOException e) {
diff --git a/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java
index 9809d14c5..c0eb09b9b 100644
--- a/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java
+++ b/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java
@@ -34,6 +34,7 @@
import java.util.TreeMap;
import freemarker.template.Template;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
@@ -408,7 +409,7 @@ private boolean processFile(FileHeaderTransformer transformer, File file, File p
String content;
try {
- content = FileUtil.readAsString(file, getEncoding());
+ content = IOUtils.toString(file.toURI(), getEncoding());
} catch (IOException e) {
throw new IOException("Could not obtain content of file " + file);
}
diff --git a/src/main/java/org/codehaus/mojo/license/model/License.java b/src/main/java/org/codehaus/mojo/license/model/License.java
index 12169ce6e..c44009ad9 100644
--- a/src/main/java/org/codehaus/mojo/license/model/License.java
+++ b/src/main/java/org/codehaus/mojo/license/model/License.java
@@ -22,16 +22,14 @@
* #L%
*/
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
+import java.io.InputStream;
import java.net.URL;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.codehaus.mojo.license.utils.MojoHelper;
-import org.codehaus.plexus.util.IOUtil;
/**
* The model of a license.
@@ -113,11 +111,8 @@ public String getLicenseContent(String encoding) throws IOException {
throw new IllegalStateException("no baseURL defined, can not obtain license content in " + this);
}
- Reader r = new BufferedReader(new InputStreamReader(getLicenseURL().openStream(), encoding));
- try {
- return IOUtil.toString(r);
- } finally {
- r.close();
+ try (InputStream in = getLicenseURL().openStream()) {
+ return IOUtils.toString(in, encoding);
}
}
@@ -125,11 +120,9 @@ public String getHeaderContent(String encoding) throws IOException {
if (baseURL == null) {
throw new IllegalStateException("no baseURL defined, can not obtain header content in " + this);
}
- Reader r = new BufferedReader(new InputStreamReader(getHeaderURL().openStream(), encoding));
- try {
- return IOUtil.toString(r);
- } finally {
- r.close();
+
+ try (InputStream in = getHeaderURL().openStream()) {
+ return IOUtils.toString(in, encoding);
}
}
diff --git a/src/main/java/org/codehaus/mojo/license/model/LicenseRepository.java b/src/main/java/org/codehaus/mojo/license/model/LicenseRepository.java
index 6ad14b00c..8fd744024 100644
--- a/src/main/java/org/codehaus/mojo/license/model/LicenseRepository.java
+++ b/src/main/java/org/codehaus/mojo/license/model/LicenseRepository.java
@@ -23,6 +23,7 @@
*/
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
@@ -106,7 +107,9 @@ public void load() throws IOException {
"no licenses.properties found with url [" + definitionURL + "] for resolver " + this);
}
Properties p = new Properties();
- p.load(definitionURL.openStream());
+ try (InputStream in = definitionURL.openStream()) {
+ p.load(in);
+ }
for (Entry