Skip to content

Commit

Permalink
Rework resource usage
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz committed Aug 5, 2015
1 parent b065687 commit bdd925b
Showing 1 changed file with 6 additions and 27 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -216,7 +215,6 @@ public class FormatterMojo extends AbstractMojo implements ConfigurationSource {
private JavaFormatter javaFormatter = new JavaFormatter();
private JavascriptFormatter jsFormatter = new JavascriptFormatter();


/**
* Execute.
*
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -575,9 +554,9 @@ private void createCodeFormatter() throws MojoExecutionException {
* @return the formatting options
* @throws MojoExecutionException the mojo execution exception
*/
private Map<String, String> getFormattingOptions(Resource newConfigFile)
private Map<String, String> getFormattingOptions(String newConfigFile)
throws MojoExecutionException {
if (newConfigFile != null) {
if (newConfigFile != null) {
return getOptionsFromConfigFile(newConfigFile);
}

Expand All @@ -596,15 +575,15 @@ private Map<String, String> getFormattingOptions(Resource newConfigFile)
* @return the options from config file
* @throws MojoExecutionException the mojo execution exception
*/
private Map<String, String> getOptionsFromConfigFile(Resource configFile)
private Map<String, String> getOptionsFromConfigFile(String newConfigFile)
throws MojoExecutionException {

InputStream configInput = null;

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);
Expand Down

0 comments on commit bdd925b

Please sign in to comment.