├── .gitignore
├── pom.xml
├── README.md
└── src
└── main
└── java
└── com
└── magnars
└── autolint
└── AutolintMavenPlugin.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | autolint-maven-plugin.iml
3 | target
4 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 | autolint-maven-plugin
9 |
10 | com.magnars.autolint
11 | autolint-maven-plugin
12 | 1.2.0-SNAPSHOT
13 | Autolint.JS Maven Plugin
14 | maven-plugin
15 |
16 |
17 | UTF-8
18 |
19 |
20 |
21 |
22 | org.apache.maven
23 | maven-plugin-api
24 | 2.0
25 |
26 |
27 |
28 |
29 | git:git://github.com/magnars/autolint-maven-plugin.git
30 | scm:git:git://github.com/magnars/autolint-maven-plugin.git
31 | scm:git:git://github.com/magnars/autolint-maven-plugin.git
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # autolint-maven-plugin
2 |
3 | A maven plugin for linting your javascript with
4 | [autolint](https://github.com/magnars/autolint).
5 |
6 | ## Getting started
7 |
8 | At the moment, this plugin does not exists in the public maven repo.
9 | So for now you will need to clone the project and do a `mvn install`.
10 |
11 | ### Configure plugin
12 |
13 |
14 | com.magnars.autolint
15 | autolint-maven-plugin
16 | 1.0.0-SNAPSHOT
17 |
18 | ${basedir}/src/test/javascript/
19 | false
20 |
21 |
22 |
23 | - `rootDirectory` is the location that contains your autolint.js config file.
24 |
25 | - `skip` can be set to true if linting should be skipped in certain environments.
26 |
27 | - `command` is the command to run. Defaults to `autolint` on the path. This is useful
28 | if you don't want to globally install autolint on a build server, but would rather bundle
29 | it with the project.
30 |
31 | Autolint also requires [node](http://nodejs.org/) to be available on the path.
32 |
33 | ## Running the plugin
34 |
35 | mvn autolint:verify
36 |
37 | ## License
38 |
39 | Copyright (c) 2013 Magnar Sveen
40 |
41 | Permission is hereby granted, free of charge, to any person obtaining
42 | a copy of this software and associated documentation files (the
43 | "Software"), to deal in the Software without restriction, including
44 | without limitation the rights to use, copy, modify, merge, publish,
45 | distribute, sublicense, and/or sell copies of the Software, and to
46 | permit persons to whom the Software is furnished to do so, subject to
47 | the following conditions:
48 |
49 | The above copyright notice and this permission notice shall be
50 | included in all copies or substantial portions of the Software.
51 |
52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
53 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 |
--------------------------------------------------------------------------------
/src/main/java/com/magnars/autolint/AutolintMavenPlugin.java:
--------------------------------------------------------------------------------
1 | package com.magnars.autolint;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.io.InputStreamReader;
7 |
8 | import org.apache.maven.plugin.AbstractMojo;
9 | import org.apache.maven.plugin.MojoExecutionException;
10 | import org.apache.maven.plugin.MojoFailureException;
11 | import org.apache.maven.plugin.logging.Log;
12 |
13 | /**
14 | * Goal which runs autolint.js
15 | *
16 | * @goal verify
17 | *
18 | * @phase verify
19 | */
20 | public class AutolintMavenPlugin
21 | extends AbstractMojo {
22 | /**
23 | * Directory where the autolint.js configuration file resides.
24 | * @parameter expression="${project.build.directory}"
25 | * @required
26 | */
27 | private File rootDirectory;
28 |
29 | /**
30 | * The command to run autolint. Defaults to just "autolint" (on the path).
31 | * @parameter
32 | */
33 | private String command;
34 |
35 | /**
36 | * Whether the test should be skipped
37 | * @parameter
38 | */
39 | private boolean skip;
40 |
41 | public void execute() throws MojoExecutionException, MojoFailureException {
42 | Log log = getLog();
43 |
44 | if (skip) {
45 | log.info("Skipping Autolint.js");
46 | return;
47 | }
48 |
49 | log.info("");
50 | log.info("------------------------------------------------------------------------");
51 | log.info("Running Autolint.js");
52 | log.info("------------------------------------------------------------------------");
53 | log.info("Using path " + rootDirectory.toString());
54 |
55 | if (command == null) {
56 | command = "autolint";
57 | }
58 |
59 | ProcessBuilder pb = new ProcessBuilder(command, "--once");
60 | pb.directory(rootDirectory);
61 | pb.redirectErrorStream(true);
62 |
63 | Process process = null;
64 | try {
65 | process = pb.start();
66 |
67 | final BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
68 |
69 | for (String line = inputReader.readLine(); line != null; line = inputReader.readLine()) {
70 | log.info(line);
71 | }
72 |
73 | int exitCode = process.waitFor();
74 |
75 | if (exitCode != 0) {
76 | throw new MojoFailureException("Linting of JavaScript code FAILED");
77 | }
78 | } catch (InterruptedException e) {
79 | throw new MojoExecutionException(e.getMessage());
80 | } catch (IOException e) {
81 | throw new MojoExecutionException(e.getMessage());
82 | } finally {
83 | if (process != null) {
84 | process.destroy();
85 | }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------