Skip to content

Commit

Permalink
It is impossible to pick up <configFile> from classpath cjdev2#44
Browse files Browse the repository at this point in the history
  • Loading branch information
kkarandin committed Mar 11, 2014
1 parent 2470797 commit cf3d77d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@
<artifactId>maven-plugin-api</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-resources</artifactId>
<version>1.0-alpha-7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
Expand Down
87 changes: 60 additions & 27 deletions src/main/java/com/cj/jshintmojo/Mojo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
package com.cj.jshintmojo;

import static com.cj.jshintmojo.util.Util.*;
import com.cj.jshintmojo.cache.Cache;
import com.cj.jshintmojo.cache.Result;
import com.cj.jshintmojo.jshint.EmbeddedJshintCode;
import com.cj.jshintmojo.jshint.FunctionalJava;
import com.cj.jshintmojo.jshint.FunctionalJava.Fn;
import com.cj.jshintmojo.jshint.JSHint;
import com.cj.jshintmojo.jshint.JSHint.Error;
import com.cj.jshintmojo.reporter.CheckStyleReporter;
import com.cj.jshintmojo.reporter.JSHintReporter;
import com.cj.jshintmojo.reporter.JSLintReporter;
import com.cj.jshintmojo.util.OptionsParser;
import com.cj.jshintmojo.util.Util;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.resource.ResourceManager;
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.FileResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.StringUtils;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -16,26 +40,7 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.StringUtils;

import com.cj.jshintmojo.cache.Cache;
import com.cj.jshintmojo.cache.Result;
import com.cj.jshintmojo.jshint.EmbeddedJshintCode;
import com.cj.jshintmojo.jshint.FunctionalJava;
import com.cj.jshintmojo.jshint.FunctionalJava.Fn;
import com.cj.jshintmojo.jshint.JSHint;
import com.cj.jshintmojo.jshint.JSHint.Error;
import com.cj.jshintmojo.reporter.CheckStyleReporter;
import com.cj.jshintmojo.reporter.JSHintReporter;
import com.cj.jshintmojo.reporter.JSLintReporter;
import com.cj.jshintmojo.util.OptionsParser;
import com.cj.jshintmojo.util.Util;
import static com.cj.jshintmojo.util.Util.mkdirs;

/**
* @goal lint
Expand Down Expand Up @@ -95,6 +100,22 @@ public class Mojo extends AbstractMojo {
* @required
*/
File basedir;

/**
* <i>Maven Internal</i>: Project to interact with.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;

/**
* @component
* @required
* @readonly
*/
private ResourceManager resourceManager;

public Mojo() {}

Expand All @@ -114,6 +135,11 @@ public Mojo(String options, String globals, File basedir, List<String> directori
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("using jshint version " + version);

//configure ResourceManager
resourceManager.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath());
resourceManager.addSearchPath("url", "");
resourceManager.setOutputDirectory(new File(project.getBuild().getDirectory()));

final String jshintCode = getEmbeddedJshintCode(version);

final JSHint jshint = new JSHint(jshintCode);
Expand Down Expand Up @@ -154,12 +180,19 @@ public Config(String options, String globals) {
}

}

private static Config readConfig(String options, String globals, String configFileParam, File basedir, Log log) throws MojoExecutionException {
final File jshintRc = findJshintrc(basedir);
final File configFile = StringUtils.isNotBlank(configFileParam)?new File(basedir, configFileParam):null;

final Config config;

private Config readConfig(String options, String globals, String configFileParam, File basedir, Log log) throws MojoExecutionException {
final File jshintRc = findJshintrc(basedir);
final File configFile;
try {
configFile = StringUtils.isNotBlank(configFileParam) ? resourceManager.getResourceAsFile(configFileParam) : null;
} catch (ResourceNotFoundException e) {
throw new MojoExecutionException("Cannot read options file", e);
} catch (FileResourceCreationException e) {
throw new MojoExecutionException("Cannot read options file", e);
}

final Config config;
if(options==null){
if(configFile!=null){
log.info("Using configuration file: " + configFile.getAbsolutePath());
Expand Down

0 comments on commit cf3d77d

Please sign in to comment.