From bdd925b20a32e8c4c2631ac23eb30e482293d647 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 4 Aug 2015 20:57:19 -0400 Subject: [PATCH] Rework resource usage --- .../revelc/code/formatter/FormatterMojo.java | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/maven-plugin/src/main/java/net/revelc/code/formatter/FormatterMojo.java b/maven-plugin/src/main/java/net/revelc/code/formatter/FormatterMojo.java index b703f52c0..af9b68cf5 100644 --- a/maven-plugin/src/main/java/net/revelc/code/formatter/FormatterMojo.java +++ b/maven-plugin/src/main/java/net/revelc/code/formatter/FormatterMojo.java @@ -63,7 +63,6 @@ import net.revelc.code.formatter.javascript.JavascriptFormatter; import net.revelc.code.formatter.model.ConfigReadException; import net.revelc.code.formatter.model.ConfigReader; -import net.revelc.code.formatter.support.io.Resource; /** * A Maven plugin mojo to format Java source code using the Eclipse code @@ -216,7 +215,6 @@ public class FormatterMojo extends AbstractMojo implements ConfigurationSource { private JavaFormatter javaFormatter = new JavaFormatter(); private JavascriptFormatter jsFormatter = new JavascriptFormatter(); - /** * Execute. * @@ -545,27 +543,8 @@ private void writeStringToFile(String str, File file) throws IOException { * @throws MojoExecutionException the mojo execution exception */ private void createCodeFormatter() throws MojoExecutionException { - Resource configFileResource = null; - Resource configJsFileResource = null; - - try { - if (this.configFile != null) { - configFileResource = Resource.forPath(this.configFile); - } - } catch (Resource.UnknownResourceException e) { - throw new MojoExecutionException("Error loading Java config", e); - } - - try { - if (this.configJsFile != null) { - configJsFileResource = Resource.forPath(this.configJsFile); - } - } catch (Resource.UnknownResourceException e) { - throw new MojoExecutionException("Error loading JS config", e); - } - - this.javaFormatter.init(getFormattingOptions(configFileResource), this); - this.jsFormatter.init(getFormattingOptions(configJsFileResource), this); + this.javaFormatter.init(getFormattingOptions(this.configFile), this); + this.jsFormatter.init(getFormattingOptions(this.configJsFile), this); } /** @@ -575,9 +554,9 @@ private void createCodeFormatter() throws MojoExecutionException { * @return the formatting options * @throws MojoExecutionException the mojo execution exception */ - private Map getFormattingOptions(Resource newConfigFile) + private Map getFormattingOptions(String newConfigFile) throws MojoExecutionException { - if (newConfigFile != null) { + if (newConfigFile != null) { return getOptionsFromConfigFile(newConfigFile); } @@ -596,7 +575,7 @@ private Map getFormattingOptions(Resource newConfigFile) * @return the options from config file * @throws MojoExecutionException the mojo execution exception */ - private Map getOptionsFromConfigFile(Resource configFile) + private Map getOptionsFromConfigFile(String newConfigFile) throws MojoExecutionException { InputStream configInput = null; @@ -604,7 +583,7 @@ private Map getOptionsFromConfigFile(Resource configFile) try { this.resourceManager.addSearchPath(FileResourceLoader.ID, this.basedir.getAbsolutePath()); - configInput = this.resourceManager.getResourceAsInputStream(this.configFile); + configInput = this.resourceManager.getResourceAsInputStream(newConfigFile); } catch (ResourceNotFoundException e) { throw new MojoExecutionException("Config file [" + this.configFile + "] cannot be found", e);