├── src
├── test
│ ├── resources
│ │ ├── src
│ │ │ ├── a
│ │ │ │ ├── test-async.js
│ │ │ │ ├── test-react.js
│ │ │ │ └── test-es6.js
│ │ │ └── test.js
│ │ └── trans
│ │ │ └── a
│ │ │ ├── trans-test-react.js
│ │ │ ├── trans-test-es6.js
│ │ │ ├── trans-test-plugin-async.js
│ │ │ └── trans-test-async.js
│ └── java
│ │ └── com
│ │ └── jarslab
│ │ └── maven
│ │ └── babel
│ │ └── plugin
│ │ ├── TestUtils.java
│ │ ├── TargetFileWriterTest.java
│ │ ├── transpiler
│ │ ├── BabelTranspilerCp1252Test.java
│ │ └── BabelTranspilerTest.java
│ │ ├── BabelMojoTest.java
│ │ ├── TranspilationInitializerTest.java
│ │ └── ReusableEngineTest.java
├── example
│ ├── src
│ │ └── main
│ │ │ └── resources
│ │ │ └── js
│ │ │ ├── a
│ │ │ ├── file-2.js
│ │ │ ├── file-3.js
│ │ │ ├── file-4.js
│ │ │ ├── file-5.js
│ │ │ ├── file-6.js
│ │ │ ├── file-7.js
│ │ │ ├── file-8.js
│ │ │ ├── file-9.js
│ │ │ └── file-1.js
│ │ │ ├── b
│ │ │ ├── file-2.js
│ │ │ ├── file-3.js
│ │ │ ├── file-4.js
│ │ │ ├── file-5.js
│ │ │ ├── file-6.js
│ │ │ ├── file-7.js
│ │ │ ├── file-8.js
│ │ │ ├── file-9.js
│ │ │ └── file-1.js
│ │ │ ├── c
│ │ │ ├── file-2.js
│ │ │ ├── file-3.js
│ │ │ ├── file-4.js
│ │ │ ├── file-5.js
│ │ │ ├── file-6.js
│ │ │ ├── file-7.js
│ │ │ ├── file-8.js
│ │ │ ├── file-9.js
│ │ │ └── file-1.js
│ │ │ ├── d
│ │ │ ├── file-2.js
│ │ │ ├── file-3.js
│ │ │ ├── file-4.js
│ │ │ ├── file-5.js
│ │ │ ├── file-6.js
│ │ │ ├── file-7.js
│ │ │ ├── file-8.js
│ │ │ ├── file-9.js
│ │ │ └── file-1.js
│ │ │ └── e
│ │ │ ├── file-2.js
│ │ │ ├── file-3.js
│ │ │ ├── file-4.js
│ │ │ ├── file-5.js
│ │ │ ├── file-6.js
│ │ │ ├── file-7.js
│ │ │ ├── file-8.js
│ │ │ ├── file-9.js
│ │ │ └── file-1.js
│ └── pom.xml
└── main
│ └── java
│ └── com
│ └── jarslab
│ └── maven
│ └── babel
│ └── plugin
│ ├── transpiler
│ ├── TranspileStrategy.java
│ ├── BabelTranspilerStrategy.java
│ ├── Transpilation.java
│ ├── TranspilationContext.java
│ ├── ParallelBabelTranspilerStrategy.java
│ └── BabelTranspiler.java
│ ├── TargetFileWriter.java
│ ├── TranspilationInitializer.java
│ └── BabelMojo.java
├── .travis.yml
├── .gitignore
├── LICENSE
├── README.md
└── pom.xml
/src/test/resources/src/a/test-async.js:
--------------------------------------------------------------------------------
1 | async function f() {
2 | return 1;
3 | }
--------------------------------------------------------------------------------
/src/test/resources/src/test.js:
--------------------------------------------------------------------------------
1 | var x = function(x, y) {
2 | return x * y;
3 | }
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-2.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-3.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-4.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-5.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-6.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-7.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-8.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-9.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-2.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-3.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-4.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-5.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-6.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-7.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-8.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-9.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-2.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-3.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-4.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-5.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-6.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-7.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-8.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-9.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-2.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-3.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-4.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-5.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-6.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-7.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-8.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-9.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-2.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-3.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-4.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-5.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-6.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-7.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-8.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-9.js:
--------------------------------------------------------------------------------
1 | const hello = (name) => 'Hello ' + name;
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | dist: trusty
3 | jdk:
4 | - oraclejdk8
5 | script: mvn verify
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/a/file-1.js:
--------------------------------------------------------------------------------
1 | const bar = 'BAR';
2 | const foo = () => bar;
3 |
--------------------------------------------------------------------------------
/src/test/resources/src/a/test-react.js:
--------------------------------------------------------------------------------
1 | class Welcome extends React.Component {
2 | render() {
3 | return
Hello, {this.props.name}
;
4 | }
5 | }
--------------------------------------------------------------------------------
/src/test/resources/src/a/test-es6.js:
--------------------------------------------------------------------------------
1 | let numbers = [4, 9, 16, 25, 29];
2 | let first = numbers.find(myFunction);
3 |
4 | function myFunction(value, index, array) {
5 | return value > 18;
6 | }
--------------------------------------------------------------------------------
/src/test/resources/trans/a/trans-test-react.js:
--------------------------------------------------------------------------------
1 | class Welcome extends React.Component {
2 | render() {
3 | return React.createElement("h1", null, "Hello, ", this.props.name);
4 | }
5 |
6 | }
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/b/file-1.js:
--------------------------------------------------------------------------------
1 | let numbers = [4, 9, 16, 25, 29];
2 | let first = numbers.find(myFunction);
3 |
4 | function myFunction(value, index, array) {
5 | return value > 18;
6 | }
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/c/file-1.js:
--------------------------------------------------------------------------------
1 | let numbers = [4, 9, 16, 25, 29];
2 | let first = numbers.find(myFunction);
3 |
4 | function myFunction(value, index, array) {
5 | return value > 18;
6 | }
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/d/file-1.js:
--------------------------------------------------------------------------------
1 | let numbers = [4, 9, 16, 25, 29];
2 | let first = numbers.find(myFunction);
3 |
4 | function myFunction(value, index, array) {
5 | return value > 18;
6 | }
--------------------------------------------------------------------------------
/src/example/src/main/resources/js/e/file-1.js:
--------------------------------------------------------------------------------
1 | let numbers = [4, 9, 16, 25, 29];
2 | let first = numbers.find(myFunction);
3 |
4 | function myFunction(value, index, array) {
5 | return value > 18;
6 | }
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/transpiler/TranspileStrategy.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | public enum TranspileStrategy
4 | {
5 | PARALLEL,
6 | SEQUENTIAL
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/resources/trans/a/trans-test-es6.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | var numbers = [4, 9, 16, 25, 29];
4 | var first = numbers.find(myFunction);
5 |
6 | function myFunction(value, index, array) {
7 | return value > 18;
8 | }
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/transpiler/BabelTranspilerStrategy.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import java.util.Set;
4 | import java.util.stream.Stream;
5 |
6 | public interface BabelTranspilerStrategy
7 | {
8 | Stream execute(Set transpilations);
9 | }
--------------------------------------------------------------------------------
/src/test/resources/trans/a/trans-test-plugin-async.js:
--------------------------------------------------------------------------------
1 | import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2 |
3 | function f() {
4 | return _f.apply(this, arguments);
5 | }
6 |
7 | function _f() {
8 | _f = _asyncToGenerator(function* () {
9 | return 1;
10 | });
11 | return _f.apply(this, arguments);
12 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | pom.xml.tag
3 | pom.xml.releaseBackup
4 | pom.xml.versionsBackup
5 | pom.xml.next
6 | release.properties
7 | dependency-reduced-pom.xml
8 | buildNumber.properties
9 | .mvn/timing.properties
10 | .idea
11 | *.iml
12 |
13 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
14 | !/.mvn/wrapper/maven-wrapper.jar
15 |
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/transpiler/Transpilation.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import org.immutables.value.Value;
4 |
5 | import java.nio.file.Path;
6 | import java.util.Optional;
7 |
8 | @Value.Immutable
9 | public interface Transpilation
10 | {
11 | TranspilationContext getContext();
12 |
13 | Path getSource();
14 |
15 | Path getTarget();
16 |
17 | Optional getResult();
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/transpiler/TranspilationContext.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import org.apache.maven.plugin.logging.Log;
4 | import org.immutables.value.Value;
5 |
6 | import java.io.File;
7 | import java.nio.charset.Charset;
8 |
9 | @Value.Immutable
10 | public interface TranspilationContext
11 | {
12 | File getBabelSource();
13 |
14 | Charset getCharset();
15 |
16 | Log getLog();
17 |
18 | @Value.Default
19 | default boolean isVerbose()
20 | {
21 | return false;
22 | }
23 |
24 | String getPresets();
25 |
26 | @Value.Default
27 | default String getPlugins()
28 | {
29 | return "";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/resources/trans/a/trans-test-async.js:
--------------------------------------------------------------------------------
1 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
2 |
3 | function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4 |
5 | function f() {
6 | return _f.apply(this, arguments);
7 | }
8 |
9 | function _f() {
10 | _f = _asyncToGenerator(function* () {
11 | return 1;
12 | });
13 | return _f.apply(this, arguments);
14 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Milosz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/TargetFileWriter.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import com.jarslab.maven.babel.plugin.transpiler.Transpilation;
4 | import org.apache.maven.plugin.logging.Log;
5 |
6 | import java.io.IOException;
7 | import java.io.UncheckedIOException;
8 | import java.nio.charset.Charset;
9 | import java.nio.file.Files;
10 |
11 | class TargetFileWriter
12 | {
13 | static void writeTargetFile(final Transpilation transpilation)
14 | {
15 | final Log log = transpilation.getContext().getLog();
16 | final Charset charset = transpilation.getContext().getCharset();
17 | try {
18 | log.debug(String.format("writing to %s", transpilation.getTarget()));
19 | Files.createDirectories(transpilation.getTarget().getParent());
20 | final byte[] bytes = transpilation.getResult()
21 | .orElseThrow(() -> new IllegalStateException(
22 | "No result for transpilation. Cannot write transpilation (" + transpilation + ")"))
23 | .getBytes(charset);
24 | Files.write(transpilation.getTarget(), bytes);
25 | } catch (IOException e) {
26 | throw new UncheckedIOException(e);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/TestUtils.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.InputStreamReader;
5 | import java.net.URISyntaxException;
6 | import java.nio.file.Path;
7 | import java.nio.file.Paths;
8 | import java.util.stream.Collectors;
9 |
10 | public class TestUtils
11 | {
12 | public static Path getBasePath()
13 | {
14 | try {
15 | return Paths.get(TestUtils.class.getResource("/").toURI());
16 | } catch (URISyntaxException e) {
17 | throw new RuntimeException(e);
18 | }
19 | }
20 |
21 | public static Path getBabelPath()
22 | {
23 | try {
24 | return Paths.get(TestUtils.class.getResource("/babel-7.8.4.min.js").toURI());
25 | } catch (URISyntaxException e) {
26 | throw new RuntimeException(e);
27 | }
28 | }
29 |
30 | public static String getResourceAsString(String resource)
31 | {
32 | return getResourceAsString(TestUtils.class, resource);
33 | }
34 |
35 | private static String getResourceAsString(Class aClass, String resource)
36 | {
37 | return new BufferedReader(new InputStreamReader(
38 | aClass.getResourceAsStream(resource)))
39 | .lines()
40 | .collect(Collectors.joining("\n"));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/TargetFileWriterTest.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import com.jarslab.maven.babel.plugin.transpiler.ImmutableTranspilation;
4 | import com.jarslab.maven.babel.plugin.transpiler.ImmutableTranspilationContext;
5 | import com.jarslab.maven.babel.plugin.transpiler.Transpilation;
6 | import org.apache.maven.plugin.logging.Log;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.mockito.Mock;
10 | import org.mockito.junit.MockitoJUnitRunner;
11 |
12 | import java.io.File;
13 | import java.nio.charset.Charset;
14 | import java.nio.file.Files;
15 | import java.nio.file.Path;
16 | import java.nio.file.Paths;
17 |
18 | import static org.assertj.core.api.Assertions.assertThat;
19 |
20 | @RunWith(MockitoJUnitRunner.class)
21 | public class TargetFileWriterTest
22 | {
23 | private static final Path TMP_DIRECTORY = Paths.get(System.getProperty("java.io.tmpdir"));
24 | private static final String TEST_INPUT = "test";
25 |
26 | @Mock
27 | private Log log;
28 |
29 | @Test
30 | public void shouldWriteFile() throws Exception
31 | {
32 | // Given
33 | Transpilation transpileContext = ImmutableTranspilation.builder()
34 | .source(Paths.get("foo"))
35 | .target(TMP_DIRECTORY.resolve(Paths.get("src", "test.js")))
36 | .result(TEST_INPUT)
37 | .context(ImmutableTranspilationContext.builder()
38 | .babelSource(new File("/"))
39 | .presets("'es2015'")
40 | .charset(Charset.forName("UTF-8"))
41 | .log(log).build())
42 | .build();
43 |
44 | // When
45 | TargetFileWriter.writeTargetFile(transpileContext);
46 |
47 | // Then
48 | byte[] bytes = Files.readAllBytes(TMP_DIRECTORY.resolve(Paths.get("src", "test.js")));
49 | assertThat(bytes).isEqualTo(TEST_INPUT.getBytes());
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/transpiler/BabelTranspilerCp1252Test.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import com.jarslab.maven.babel.plugin.TestUtils;
4 | import org.apache.maven.plugin.logging.Log;
5 | import org.junit.BeforeClass;
6 | import org.junit.Rule;
7 | import org.junit.Test;
8 | import org.junit.rules.ExpectedException;
9 | import org.junit.runner.RunWith;
10 | import org.mockito.Mock;
11 | import org.mockito.junit.MockitoJUnitRunner;
12 |
13 | import java.io.File;
14 | import java.nio.charset.Charset;
15 | import java.nio.file.Files;
16 | import java.nio.file.Path;
17 | import java.nio.file.Paths;
18 |
19 | import static org.assertj.core.api.Assertions.assertThat;
20 |
21 | /**
22 | * This test is broken by design.
23 | * To run it properly it requires jvm option `-Dfile.encoding=windows-1252`.
24 | * Due to runtime caches System::setProperty will not work as expected.
25 | */
26 | @RunWith(MockitoJUnitRunner.class)
27 | public class BabelTranspilerCp1252Test {
28 |
29 | @Rule
30 | public ExpectedException expectedException = ExpectedException.none();
31 |
32 | @Mock
33 | private Log log;
34 |
35 | @BeforeClass
36 | public static void setUpClass() {
37 | System.setProperty("file.encoding", "Cp1252");
38 | }
39 |
40 | @Test
41 | public void shouldTranspileCp1252Encoding() throws Exception {
42 | // Given
43 | File sourceFile = File.createTempFile("babel-test", "");
44 | Path sourceFilePath = sourceFile.toPath();
45 | sourceFile.deleteOnExit();
46 | Files.write(
47 | sourceFilePath,
48 | Files.readAllLines(TestUtils.getBasePath().resolve("src/a/test-react.js")),
49 | Charset.forName("UTF-8"));
50 |
51 | Transpilation transpilation = ImmutableTranspilation.builder()
52 | .source(sourceFilePath)
53 | .target(Paths.get("foo"))
54 | .context(ImmutableTranspilationContext.builder()
55 | .log(log)
56 | .babelSource(TestUtils.getBabelPath().toFile())
57 | .presets("'react'")
58 | .charset(Charset.forName("UTF-8"))
59 | .build())
60 | .build();
61 |
62 | // When
63 | transpilation = new BabelTranspiler().execute(transpilation);
64 |
65 | // Then
66 | assertThat(transpilation.getResult()).isPresent();
67 | //noinspection OptionalGetWithoutIsPresent
68 | assertThat(transpilation.getResult().get()).contains("createElement");
69 | }
70 | }
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/BabelMojoTest.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import org.apache.maven.plugin.MojoExecutionException;
4 | import org.apache.maven.plugin.MojoFailureException;
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.ExpectedException;
8 |
9 | import java.nio.file.Paths;
10 | import java.util.Collections;
11 |
12 | import static org.assertj.core.api.Assertions.assertThat;
13 |
14 | public class BabelMojoTest
15 | {
16 | @Rule
17 | public ExpectedException expectedException = ExpectedException.none();
18 |
19 | @Test
20 | public void shouldFailForNotExistedBabelPath() throws MojoFailureException, MojoExecutionException
21 | {
22 | // Given
23 | final BabelMojo babelMojo = getBabelMojo();
24 | babelMojo.setBabelSrc(TestUtils.getBasePath().resolve("bagel.min.js").toFile());
25 |
26 | // Expect
27 | expectedException.expect(MojoFailureException.class);
28 |
29 | // When
30 | babelMojo.execute();
31 | }
32 |
33 | @Test
34 | public void shouldFailForNoPresets() throws MojoFailureException, MojoExecutionException
35 | {
36 | // Given
37 | final BabelMojo babelMojo = getBabelMojo();
38 | babelMojo.setPresets("");
39 |
40 | // Expect
41 | expectedException.expect(MojoFailureException.class);
42 |
43 | // When
44 | babelMojo.execute();
45 | }
46 |
47 | @Test
48 | public void shouldDoNothingForMissingSourceFiles() throws MojoFailureException, MojoExecutionException
49 | {
50 | // Given
51 | final BabelMojo babelMojo = getBabelMojo();
52 | babelMojo.setJsSourceFiles(Collections.emptyList());
53 | babelMojo.setJsSourceIncludes(Collections.emptyList());
54 |
55 | // When
56 | babelMojo.execute();
57 |
58 | // Then
59 | // Pass
60 | }
61 |
62 | @Test
63 | public void shouldRunCompleteExecution() throws MojoFailureException, MojoExecutionException
64 | {
65 | // Given
66 | final BabelMojo babelMojo = getBabelMojo();
67 |
68 | // When
69 | babelMojo.execute();
70 |
71 | // Then
72 | assertThat(Paths.get(System.getProperty("java.io.tmpdir")).resolve(Paths.get("src", "a"))).exists();
73 | }
74 |
75 | private BabelMojo getBabelMojo()
76 | {
77 | BabelMojo babelMojo = new BabelMojo();
78 | babelMojo.setVerbose(true);
79 | babelMojo.setBabelSrc(TestUtils.getBabelPath().toFile());
80 | babelMojo.setSourceDir(TestUtils.getBasePath().toFile());
81 | babelMojo.setTargetDir(Paths.get(System.getProperty("java.io.tmpdir")).toFile());
82 | babelMojo.setJsSourceFile("/src/test.js");
83 | babelMojo.setJsSourceInclude("/src/a/*.js");
84 | babelMojo.setJsSourceExclude("/src/a/*react.js");
85 | babelMojo.setPrefix("t.");
86 | babelMojo.setPresets("es2015,react");
87 | babelMojo.setEncoding("UTF-8");
88 | return babelMojo;
89 | }
90 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |  
2 |
3 | # Babel Maven Plugin
4 | Plugin lets you to execute Babel transcription for given JavaScript files.
5 | It requires no npm or node.js, it is plain Java project (based on embedded GraalVM from version 1.4) which works perfectly combined with WebJars.
6 |
7 | ## Maven coords
8 | ```xml
9 |
10 | com.jarslab.maven
11 | babel-maven-plugin
12 | 1.6
13 |
14 | ```
15 |
16 | ## Settings, ie buttons and knobs
17 | * **`verbose`** - no surprises, the execution becomes a bit more talkative (default: _false_),
18 | * **`threads`** - number of threads to use when transpiling (default: _1_, will be capped on the amount of processors available)
19 | * **`encoding`** - will apply chosen encoding during files operations (read/write) (default: `Charset.defaultCharset()`),
20 | * **`babelSrc`** - readable path to standalone(!) Babel sources. It can be provided from WebJars dependency, minified
21 | or development version,
22 | * **`sourceDir`** - base path for JavaScript files you are going to translate,
23 | * **`targetDir`** - result path, note that all sub-directories from `sourceDir` will be preserved,
24 | * **`jsFiles`** - list of JavaScript files (static) from `sourceDir` to translate,
25 | * **`jsIncludes`** - list of JavaScript files (with simple masks `*`/`?`),
26 | * **`jsExcludes`** - list of exceptions for `jsIncludes`,
27 | * **`prefix`** - optional prefix applied for every translated file,
28 | * **`formatPresets`** - enable/disable presets formatting (default: _true_). Once disabled `presets` are required to be well formatted,
29 | * **`presets`** - presets for Babel execution (default: _es2015_),
30 | * **`plugins`** - plugins for Babel execution (default: _""_ (empty)) _NOTE: any custom plugins are required to be available in provided `babelSrc`_
31 |
32 | ## Example
33 | ```xml
34 |
35 | com.jarslab.maven
36 | babel-maven-plugin
37 | 1.6
38 |
39 |
40 | js-transpile
41 | process-resources
42 |
43 | babel
44 |
45 |
46 | true
47 | 4
48 | ${project.basedir}/target/classes/assets/jslib/babel.min.js
49 | ${project.basedir}/target/classes/assets/
50 | ${project.basedir}/target/classes/assets/
51 |
52 | src/*.js
53 |
54 | trans-
55 | react,es2015
56 |
57 |
58 |
59 |
60 | ```
61 |
62 | ## Changelog
63 | * **1.6**: Fix Presets handling
64 | * **1.5**: Add `plugins` option for Babel execution
65 | * **1.4**: Switch from deprecated Nashorn engine to GraalVM
66 |
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/transpiler/ParallelBabelTranspilerStrategy.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import org.apache.maven.plugin.logging.Log;
4 |
5 | import java.util.Collection;
6 | import java.util.HashSet;
7 | import java.util.Set;
8 | import java.util.concurrent.CompletableFuture;
9 | import java.util.concurrent.ConcurrentLinkedQueue;
10 | import java.util.function.Supplier;
11 | import java.util.stream.Stream;
12 |
13 | import static java.lang.Runtime.getRuntime;
14 | import static java.lang.String.format;
15 | import static java.util.Objects.requireNonNull;
16 |
17 | public class ParallelBabelTranspilerStrategy implements BabelTranspilerStrategy
18 | {
19 | private final Log log;
20 | private final int threads;
21 |
22 | public ParallelBabelTranspilerStrategy(final Log log,
23 | final int threads)
24 | {
25 | this.log = requireNonNull(log);
26 | this.threads = getAvailableThreads(threads);
27 | }
28 |
29 | @Override
30 | public Stream execute(final Set transpilations)
31 | {
32 | final ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue<>(transpilations);
33 | // Each thread's task is to create babel transpiler and perform as much transpilations as possible
34 | final Supplier> task = () -> {
35 | Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
36 | try (BabelTranspiler transpiler = new BabelTranspiler()) {
37 | final Set transpilationResults = new HashSet<>();
38 | Transpilation currentTranspilation;
39 | while ((currentTranspilation = queue.poll()) != null) {
40 | if (log.isDebugEnabled()) {
41 | String name = Thread.currentThread().getName();
42 | log.debug(format("[%s] transpiling %s", name, currentTranspilation.getSource()));
43 | }
44 | transpilationResults.add(transpiler.execute(currentTranspilation));
45 | }
46 | return transpilationResults;
47 | }
48 | };
49 |
50 | final Collection>> futures = new HashSet<>();
51 | for (int i = 0; i < threads; i++) {
52 | futures.add(CompletableFuture.supplyAsync(task));
53 | }
54 |
55 | return futures.stream()
56 | .map(CompletableFuture::join)
57 | .flatMap(Collection::stream);
58 | }
59 |
60 | private int getAvailableThreads(final int threads)
61 | {
62 | final int availableThreads = getRuntime().availableProcessors();
63 | if (threads < 1) {
64 | log.warn(format("Invalid number of threads (%d). Setting number of threads to 1", threads));
65 | return 1;
66 | } else if (threads > availableThreads) {
67 | log.warn(format("Configured number of threads (%d) exceeds the number of available processors (%d), " +
68 | "setting number of threads to %2$d", threads, availableThreads));
69 | return availableThreads;
70 | } else {
71 | return threads;
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/example/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.jarslab.maven
5 | babel-maven-plugin-example
6 | 1.4-SNAPSHOT
7 | Babel Maven Plugin Example
8 | https://github.com/jarslab/babel-maven-plugin
9 |
10 |
11 | MIT License
12 | http://www.opensource.org/licenses/mit-license.php
13 | repo
14 |
15 |
16 |
17 |
18 | Milosz Polak
19 | http://jarslab.com
20 |
21 | Project owner
22 | Developer
23 |
24 | Europe/Warsaw
25 |
26 |
27 | Jonas Koperdraat
28 | http://jonaskoperdraat.nl
29 |
30 | Developer
31 |
32 | Europe/Amsterdam
33 |
34 |
35 |
36 |
37 | 1.8
38 | 1.8
39 | UTF-8
40 |
41 |
42 |
43 |
44 |
45 | com.jarslab.maven
46 | babel-maven-plugin
47 | 1.3-SNAPSHOT
48 |
49 |
50 | js-transpile
51 | process-resources
52 |
53 | babel
54 |
55 |
56 | true
57 | 3
58 | ${project.build.sourceEncoding}
59 | ${project.basedir}/src/main/resources/babel-7.8.4.min.js
60 | ${project.basedir}/src/main/resources/js
61 | ${project.basedir}/target/classes/assets
62 |
63 | a/file-2.js
64 |
65 |
66 | a/*
67 |
68 |
69 | **/*.js
70 |
71 | trans-
72 | react,es2015
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/transpiler/BabelTranspiler.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import org.apache.maven.plugin.logging.Log;
4 | import org.graalvm.polyglot.Context;
5 | import org.graalvm.polyglot.PolyglotAccess;
6 | import org.graalvm.polyglot.Source;
7 | import org.graalvm.polyglot.Value;
8 |
9 | import java.io.IOException;
10 | import java.io.UncheckedIOException;
11 | import java.nio.file.Files;
12 |
13 | import static java.lang.String.format;
14 | import static java.lang.System.lineSeparator;
15 | import static java.util.Objects.requireNonNull;
16 | import static java.util.Optional.ofNullable;
17 | import static java.util.stream.Collectors.joining;
18 |
19 | public class BabelTranspiler implements AutoCloseable
20 | {
21 | private static final String INPUT_VARIABLE = "input";
22 | private static final String FILENAME_VARIABLE = "filename";
23 | private static final String BABEL_EXECUTE = "Babel.transform(%s, {filename: %s, presets: [%s], plugins: [%s]}).code";
24 |
25 | private TranspilationContext transpilationContext;
26 | private Context executionContext;
27 |
28 | private void initialize(final TranspilationContext context)
29 | {
30 | requireNonNull(context);
31 | if (this.transpilationContext == null || !this.transpilationContext.equals(context)) {
32 | this.transpilationContext = context;
33 | createEngine();
34 | }
35 | }
36 |
37 | private void createEngine()
38 | {
39 | transpilationContext.getLog().debug("Initializing script engine");
40 | try {
41 | executionContext = Context.newBuilder()
42 | .allowExperimentalOptions(true)
43 | .allowPolyglotAccess(PolyglotAccess.ALL)
44 | .build();
45 | executionContext.eval(Source.newBuilder("js", transpilationContext.getBabelSource()).build());
46 | } catch (IOException e) {
47 | throw new UncheckedIOException(e);
48 | }
49 | }
50 |
51 | public synchronized Transpilation execute(final Transpilation transpilation)
52 | {
53 | initialize(transpilation.getContext());
54 | final Log log = transpilationContext.getLog();
55 | if (transpilationContext.isVerbose()) {
56 | log.info(format("Transpiling %s -> %s", transpilation.getSource(), transpilation.getTarget()));
57 | }
58 | try {
59 | final String source = Files.lines(transpilation.getSource(), transpilationContext.getCharset())
60 | .collect(joining(lineSeparator()));
61 | final Value bindings = executionContext.getBindings("js");
62 | bindings.putMember(INPUT_VARIABLE, source);
63 | bindings.putMember(FILENAME_VARIABLE, transpilation.getSource().toString());
64 | final String result = executionContext.eval("js", format(
65 | BABEL_EXECUTE,
66 | INPUT_VARIABLE,
67 | FILENAME_VARIABLE,
68 | transpilationContext.getPresets(),
69 | transpilationContext.getPlugins())).asString();
70 | if (log.isDebugEnabled()) {
71 | log.debug(format("%s result:\n%s", transpilation.getTarget(), result));
72 | }
73 | return ImmutableTranspilation.copyOf(transpilation).withResult(result);
74 | } catch (Exception e) {
75 | throw new RuntimeException(e);
76 | }
77 | }
78 |
79 | @Override
80 | public void close()
81 | {
82 | ofNullable(executionContext).ifPresent(Context::close);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/transpiler/BabelTranspilerTest.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin.transpiler;
2 |
3 | import com.jarslab.maven.babel.plugin.TestUtils;
4 | import org.apache.maven.plugin.logging.Log;
5 | import org.apache.maven.plugin.logging.SystemStreamLog;
6 | import org.junit.Rule;
7 | import org.junit.Test;
8 | import org.junit.rules.ExpectedException;
9 | import org.junit.runner.RunWith;
10 | import org.mockito.junit.MockitoJUnitRunner;
11 |
12 | import java.nio.charset.Charset;
13 | import java.nio.file.Paths;
14 |
15 | import static org.assertj.core.api.Assertions.assertThat;
16 |
17 | @RunWith(MockitoJUnitRunner.class)
18 | public class BabelTranspilerTest
19 | {
20 | @Rule
21 | public ExpectedException expectedException = ExpectedException.none();
22 |
23 | private Log log = new SystemStreamLog();
24 |
25 | private ImmutableTranspilationContext.Builder contextBuilder = ImmutableTranspilationContext.builder()
26 | .isVerbose(true)
27 | .log(log)
28 | .babelSource(TestUtils.getBabelPath().toFile())
29 | .charset(Charset.forName("UTF-8"));
30 |
31 |
32 | @Test
33 | public void shouldTranspileEs6File()
34 | {
35 | //given
36 | Transpilation transpilation = ImmutableTranspilation.builder()
37 | .source(TestUtils.getBasePath().resolve(Paths.get("src", "a", "test-es6.js")))
38 | .target(Paths.get("foo"))
39 | .context(contextBuilder.presets("'es2015'").build())
40 | .build();
41 | //when
42 | transpilation = new BabelTranspiler().execute(transpilation);
43 | //then
44 | assertThat(transpilation.getResult()).get().isEqualTo(TestUtils.getResourceAsString("/trans/a/trans-test-es6.js"));
45 | }
46 |
47 | @Test
48 | public void shouldTranspileReactFile()
49 | {
50 | //given
51 | Transpilation transpilation = ImmutableTranspilation.builder()
52 | .source(TestUtils.getBasePath().resolve(Paths.get("src", "a", "test-react.js")))
53 | .target(Paths.get("foo"))
54 | .context(contextBuilder.presets("'react'").build())
55 | .build();
56 | //when
57 | transpilation = new BabelTranspiler().execute(transpilation);
58 | //then
59 | assertThat(transpilation.getResult()).get().isEqualTo(TestUtils.getResourceAsString("/trans/a/trans-test-react.js"));
60 | }
61 |
62 | @Test
63 | public void shouldTranspileAsyncFile()
64 | {
65 | //given
66 | Transpilation transpilation = ImmutableTranspilation.builder()
67 | .source(TestUtils.getBasePath().resolve(Paths.get("src", "a", "test-async.js")))
68 | .target(Paths.get("foo"))
69 | .context(contextBuilder.presets("'es2017'").build())
70 | .build();
71 | //when
72 | transpilation = new BabelTranspiler().execute(transpilation);
73 | //then
74 | assertThat(transpilation.getResult()).get().isEqualTo(TestUtils.getResourceAsString("/trans/a/trans-test-async.js"));
75 | }
76 |
77 | @Test
78 | public void shouldTranspileAsyncFileWithPlugins()
79 | {
80 | //given
81 | Transpilation transpilation = ImmutableTranspilation.builder()
82 | .source(TestUtils.getBasePath().resolve(Paths.get("src", "a", "test-async.js")))
83 | .target(Paths.get("foo"))
84 | .context(contextBuilder
85 | .presets("'es2017'")
86 | .plugins("['transform-runtime', {'regenerator': true}]")
87 | .build())
88 | .build();
89 | //when
90 | transpilation = new BabelTranspiler().execute(transpilation);
91 | //then
92 | assertThat(transpilation.getResult()).get().isEqualTo(TestUtils.getResourceAsString("/trans/a/trans-test-plugin-async.js"));
93 | }
94 | }
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/TranspilationInitializer.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import com.jarslab.maven.babel.plugin.transpiler.ImmutableTranspilation;
4 | import com.jarslab.maven.babel.plugin.transpiler.ImmutableTranspilationContext;
5 | import com.jarslab.maven.babel.plugin.transpiler.Transpilation;
6 | import com.jarslab.maven.babel.plugin.transpiler.TranspilationContext;
7 | import org.codehaus.plexus.util.DirectoryScanner;
8 |
9 | import java.io.File;
10 | import java.nio.charset.Charset;
11 | import java.nio.file.Files;
12 | import java.nio.file.Path;
13 | import java.nio.file.Paths;
14 | import java.util.HashSet;
15 | import java.util.List;
16 | import java.util.Set;
17 | import java.util.stream.Stream;
18 |
19 | import static java.lang.String.format;
20 | import static java.util.Objects.requireNonNull;
21 | import static java.util.stream.Collectors.joining;
22 | import static java.util.stream.Collectors.toSet;
23 |
24 | class TranspilationInitializer
25 | {
26 | private final BabelMojo babelMojo;
27 |
28 | TranspilationInitializer(final BabelMojo babelMojo)
29 | {
30 | this.babelMojo = requireNonNull(babelMojo);
31 | }
32 |
33 | Set getTranspilations()
34 | {
35 | final Set transpilations = new HashSet<>();
36 | final TranspilationContext context = ImmutableTranspilationContext.builder()
37 | .babelSource(babelMojo.getBabelSrc())
38 | .charset(Charset.forName(babelMojo.getEncoding()))
39 | .log(babelMojo.getLog())
40 | .isVerbose(babelMojo.isVerbose())
41 | .presets(babelMojo.isFormatPresets() ?
42 | getFormattedPresets(babelMojo) :
43 | babelMojo.getPresets())
44 | .plugins(babelMojo.getPlugins())
45 | .build();
46 | addStaticFiles(transpilations);
47 | addPatternMatchedFiles(transpilations);
48 | return transpilations.stream()
49 | .map(transpilation -> transpilation.context(context).build())
50 | .collect(toSet());
51 | }
52 |
53 | private void addStaticFiles(final Set sourceFiles)
54 | {
55 | // Add statically added files
56 | babelMojo.getJsSourceFiles().stream()
57 | .map(this::removeLeadingSlash)
58 | .map(this::resolveAgainstSourceDirectory)
59 | .filter(sourcePath -> Files.exists(sourcePath))
60 | .map(this::toTranspilationBuilder)
61 | .forEach(sourceFiles::add);
62 | }
63 |
64 | private Path resolveAgainstSourceDirectory(final String sourcePath)
65 | {
66 | return babelMojo.getSourceDir().toPath().resolve(sourcePath);
67 | }
68 |
69 | private void addPatternMatchedFiles(final Set sourceFiles)
70 | {
71 | // Add pattern matched files
72 | if (!babelMojo.getJsSourceIncludes().isEmpty()) {
73 | Stream.of(getIncludesDirectoryScanner().getIncludedFiles())
74 | .map(this::resolveAgainstSourceDirectory)
75 | .map(this::toTranspilationBuilder)
76 | .forEach(sourceFiles::add);
77 | }
78 | }
79 |
80 | private ImmutableTranspilation.Builder toTranspilationBuilder(final Path sourceFile)
81 | {
82 | return ImmutableTranspilation.builder()
83 | .source(sourceFile)
84 | .target(determineTargetPath(sourceFile));
85 | }
86 |
87 | private String getFormattedPresets(final BabelMojo mojo)
88 | {
89 | return Stream.of(mojo.getPresets().split(","))
90 | .map(String::trim)
91 | .map(preset -> format("'%s'", preset))
92 | .collect(joining(","));
93 | }
94 |
95 | private Path determineTargetPath(final Path sourceFile)
96 | {
97 | final Path relativePath = getRelativePath(sourceFile);
98 | final String prefix = babelMojo.getPrefix() == null ? "" : babelMojo.getPrefix();
99 | return babelMojo.getTargetDir().toPath().resolve(relativePath).resolve(prefix + sourceFile.getFileName());
100 | }
101 |
102 | private String removeLeadingSlash(final String subject)
103 | {
104 | if (subject.startsWith(File.separator) || subject.startsWith("/")) {
105 | return subject.substring(1);
106 | }
107 | return subject;
108 | }
109 |
110 | private DirectoryScanner getIncludesDirectoryScanner()
111 | {
112 | final DirectoryScanner scanner = new DirectoryScanner();
113 | scanner.setIncludes(checkFileSeparator(babelMojo.getJsSourceIncludes()));
114 | scanner.setExcludes(checkFileSeparator(babelMojo.getJsSourceExcludes()));
115 | scanner.addDefaultExcludes();
116 | scanner.setBasedir(babelMojo.getSourceDir());
117 | scanner.scan();
118 | return scanner;
119 | }
120 |
121 | /**
122 | * If '/' is used in the given paths, and the system file separator is not
123 | * '/', replace '/' with the {@link File#separator}. This is required for
124 | * using {@link DirectoryScanner}
125 | */
126 | private String[] checkFileSeparator(final List paths)
127 | {
128 | return paths.stream()
129 | .map(path -> {
130 | if (File.separatorChar != '/' && path.contains("/")) {
131 | return path.replace("/", File.separator);
132 | }
133 | return path;
134 | })
135 | .map(this::removeLeadingSlash)
136 | .toArray(String[]::new);
137 | }
138 |
139 | private Path getRelativePath(final Path sourceFile)
140 | {
141 | return Paths.get(
142 | babelMojo.getSourceDir()
143 | .toURI()
144 | .relativize(sourceFile.getParent()
145 | .toFile()
146 | .toURI())
147 | .getPath());
148 | }
149 | }
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/TranspilationInitializerTest.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import com.jarslab.maven.babel.plugin.transpiler.Transpilation;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 |
7 | import java.io.File;
8 | import java.nio.file.Path;
9 | import java.nio.file.Paths;
10 | import java.util.Set;
11 | import java.util.stream.Stream;
12 |
13 | import static org.assertj.core.api.Assertions.assertThat;
14 |
15 | public class TranspilationInitializerTest
16 | {
17 | private BabelMojo babelMojo;
18 |
19 | @Before
20 | public void setUp()
21 | {
22 | babelMojo = new BabelMojo();
23 | babelMojo.setEncoding("UTF-8");
24 | babelMojo.setBabelSrc(TestUtils.getBabelPath().toFile());
25 | babelMojo.setSourceDir(TestUtils.getBasePath().toFile());
26 | babelMojo.setTargetDir(Paths.get("foo").toFile());
27 | babelMojo.setPresets("es2015");
28 | }
29 |
30 | @Test
31 | public void shouldNotFailForEmptyParameters()
32 | {
33 | //given
34 | //babelMojo
35 | //when
36 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
37 | //then
38 | assertThat(transpilations).isEmpty();
39 | }
40 |
41 | @Test
42 | public void shouldGetFilesFromStaticList()
43 | {
44 | //given
45 | babelMojo.setJsSourceFile("/src/test.js");
46 | //when
47 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
48 | //then
49 | assertThat(getSourceFilesNames(transpilations)).containsOnly("test.js");
50 | }
51 |
52 |
53 | @Test
54 | public void shouldGetFilesFromIncludesList()
55 | {
56 | //given
57 | babelMojo.setJsSourceInclude("/src/a/test-*.js");
58 | //when
59 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
60 | //Then
61 | assertThat(getSourceFilesNames(transpilations)).containsOnly("test-es6.js", "test-react.js", "test-async.js");
62 | }
63 |
64 | @Test
65 | public void shouldGetFilesFromIncludesListUsingFileSeparator()
66 | {
67 | //given
68 | babelMojo.setJsSourceInclude(File.separator + "src" + File.separator + "a" + File.separator + "test-*.js");
69 | //when
70 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
71 | //Then
72 | assertThat(getSourceFilesNames(transpilations)).containsOnly("test-es6.js", "test-react.js", "test-async.js");
73 | }
74 |
75 | @Test
76 | public void shouldGetFilesFromIncludesListApplyingExclude()
77 | {
78 | //Given
79 | babelMojo.setJsSourceInclude("/src/a/test-*.js");
80 | babelMojo.setJsSourceExclude("/src/a/*react*");
81 | //when
82 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
83 | //Then
84 | assertThat(getSourceFilesNames(transpilations)).containsOnly("test-es6.js", "test-async.js");
85 | }
86 |
87 | @Test
88 | public void shouldGetFilesFromAllParameters()
89 | {
90 | //given
91 | babelMojo.setJsSourceFile("/src/test.js");
92 | babelMojo.setJsSourceInclude("/src/a/test-*.js");
93 | babelMojo.setJsSourceExclude("/src/a/*es6.js");
94 | //when
95 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
96 | //then
97 | assertThat(getSourceFilesNames(transpilations)).containsOnly("test.js", "test-react.js", "test-async.js");
98 | }
99 |
100 | @Test
101 | public void shouldMapRelatively()
102 | {
103 | //given
104 | Path targetDirectory = Paths.get("some", "target", "path");
105 | babelMojo.setTargetDir(targetDirectory.toFile());
106 | babelMojo.setJsSourceFile("/src/test.js");
107 | TranspilationInitializer transpilationInitializer = new TranspilationInitializer(babelMojo);
108 | //when
109 | Set transpilations = transpilationInitializer.getTranspilations();
110 | //then
111 | Path targetFile = transpilations.iterator().next().getTarget();
112 | assertThat(targetDirectory.relativize(targetFile)).isEqualTo(Paths.get("src", "test.js"));
113 | }
114 |
115 | @Test
116 | public void shouldAddPrefix()
117 | {
118 | //given
119 | babelMojo.setJsSourceFile("/src/test.js");
120 | babelMojo.setPrefix("some-prefix-");
121 | //when
122 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
123 | //then
124 | String fileName = transpilations.iterator().next().getTarget().getFileName().toString();
125 | assertThat(fileName).isEqualTo("some-prefix-test.js");
126 | }
127 |
128 | @Test
129 | public void shouldFormatPresets()
130 | {
131 | //given
132 | babelMojo.setPresets("test, test,test");
133 | babelMojo.setJsSourceFile("/src/test.js");
134 | //when
135 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
136 | //then
137 | final String presets = transpilations.iterator().next().getContext().getPresets();
138 | assertThat(presets).isEqualTo("'test','test','test'");
139 | }
140 |
141 | @Test
142 | public void shouldNotFormatPresets()
143 | {
144 | //given
145 | babelMojo.setPresets("test without formatting");
146 | babelMojo.setFormatPresets(false);
147 | babelMojo.setJsSourceFile("/src/test.js");
148 | //when
149 | Set transpilations = new TranspilationInitializer(babelMojo).getTranspilations();
150 | //then
151 | final String presets = transpilations.iterator().next().getContext().getPresets();
152 | assertThat(presets).isEqualTo("test without formatting");
153 | }
154 |
155 | private Stream getSourceFilesNames(Set transpilations)
156 | {
157 | return transpilations.parallelStream()
158 | .map(Transpilation::getSource)
159 | .map(Path::getFileName)
160 | .map(Path::toString);
161 | }
162 |
163 | }
--------------------------------------------------------------------------------
/src/test/java/com/jarslab/maven/babel/plugin/ReusableEngineTest.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import org.apache.maven.plugin.logging.Log;
4 | import org.apache.maven.plugin.logging.SystemStreamLog;
5 | import org.graalvm.polyglot.Context;
6 | import org.graalvm.polyglot.Source;
7 | import org.graalvm.polyglot.Value;
8 | import org.junit.Rule;
9 | import org.junit.Test;
10 | import org.junit.rules.ExpectedException;
11 |
12 | import java.io.BufferedReader;
13 | import java.io.InputStream;
14 | import java.io.InputStreamReader;
15 | import java.text.DecimalFormat;
16 | import java.text.DecimalFormatSymbols;
17 | import java.text.NumberFormat;
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Locale;
21 | import java.util.concurrent.ExecutorService;
22 | import java.util.concurrent.Executors;
23 | import java.util.concurrent.TimeUnit;
24 | import java.util.stream.Collectors;
25 |
26 | import static java.lang.String.format;
27 | import static java.nio.charset.StandardCharsets.UTF_8;
28 | import static org.assertj.core.api.Assertions.assertThat;
29 |
30 | public class ReusableEngineTest
31 | {
32 | @Rule
33 | public ExpectedException expectedException = ExpectedException.none();
34 |
35 | private static final String EXPECTED_RESULT = "\"use strict\";\n" +
36 | "\n" +
37 | "var x = function x(_x, y) {\n" +
38 | " return _x * y;\n" +
39 | "};";
40 | private Log log = new SystemStreamLog();
41 |
42 | @Test
43 | public void testBabel() throws Exception
44 | {
45 | Stopwatch stopwatch = new Stopwatch();
46 | InputStream inputStream = ReusableEngineTest.class.getResourceAsStream("/babel-7.8.4.min.js");
47 | InputStreamReader fileReader = new InputStreamReader(inputStream, UTF_8);
48 | final Context engine = Context.newBuilder().allowExperimentalOptions(true).build();
49 | engine.eval(Source.newBuilder("js", fileReader, "babel-7.8.4.min.js").build());
50 |
51 | log.info("Initialized script engine in " + stopwatch.stop());
52 |
53 | stopwatch.start();
54 | String source = new BufferedReader(new InputStreamReader(
55 | ReusableEngineTest.class.getResourceAsStream("/src/test.js")))
56 | .lines().collect(Collectors.joining());
57 | String srcBinding = "transpilationSource";
58 | final Value bindings = engine.getBindings("js");
59 | bindings.putMember(srcBinding, source);
60 | String result = engine.eval("js", "Babel.transform(" + srcBinding + ", { presets: ['es2015'] }).code").asString();
61 |
62 | stopwatch.stop();
63 | log.info("Transpiled source in " + stopwatch);
64 | log.info("Source:");
65 | log.info(source);
66 | log.info("Result:");
67 | log.info(result);
68 |
69 | assertThat(result).isEqualTo(EXPECTED_RESULT);
70 | }
71 |
72 | @Test
73 | /*
74 | * This test shows that re-using an engine to transpile multiple sources in parallel is
75 | * not a good idea. When using a multithreaded executor {@link Executors#newFixedThreadPool(int)},
76 | * errors start to occur while transpiling.
77 | *
78 | * However, because loading the babel library into the engine takes quite some time, it is a good
79 | * idea to eval the minified babel once, and then reuse the engine to transpile each source file.
80 | */
81 | public void testReuseEngine() throws Exception
82 | {
83 |
84 | log.info("Initialize script engine ...");
85 |
86 | Stopwatch stopwatch = new Stopwatch();
87 | InputStream inputStream = ReusableEngineTest.class.getResourceAsStream("/babel-7.8.4.min.js");
88 | InputStreamReader fileReader = new InputStreamReader(inputStream, UTF_8);
89 | final Context engine = Context.newBuilder().allowExperimentalOptions(true).build();
90 | engine.eval(Source.newBuilder("js", fileReader, "babel-7.8.4.min.js").build());
91 |
92 | log.info("Initialized script engine in " + stopwatch.stop());
93 |
94 | final List exc = new ArrayList<>();
95 | Runnable task = () -> {
96 |
97 | Stopwatch sw = new Stopwatch();
98 | try {
99 |
100 | String source = new BufferedReader(new InputStreamReader(
101 | ReusableEngineTest.class.getResourceAsStream("/src/test.js")))
102 | .lines().collect(Collectors.joining());
103 | String srcBinding = "transpilationSrc";
104 | String optBinding = "transpilationOpt";
105 | final Value bindings = engine.getBindings("js");
106 | bindings.putMember(srcBinding, source);
107 | bindings.putMember(optBinding, "{ presets: ['es2015'] }");
108 | String result = engine.eval("js", "Babel.transform(" + srcBinding + ", { presets: ['es2015'] }).code").asString();
109 |
110 | assertThat(result).isEqualTo(EXPECTED_RESULT);
111 |
112 | } catch (Exception e) {
113 | exc.add(e);
114 | }
115 | };
116 |
117 | stopwatch.start();
118 | int n = 100;
119 | log.info(format("Transpiling %d sources ...", n));
120 | ExecutorService executorService = Executors.newSingleThreadExecutor();
121 | for (int i = 0; i < n; i++) {
122 | executorService.submit(task);
123 | }
124 | executorService.shutdown();
125 | executorService.awaitTermination(1, TimeUnit.MINUTES);
126 | log.info(format("Transpiled %d sources in %s", n, stopwatch.stop()));
127 |
128 | assertThat(executorService.isTerminated()).isTrue();
129 |
130 | if (!exc.isEmpty()) {
131 | log.error(format("%d exceptions occurred during multithreaded transpilation.", exc.size()));
132 | throw exc.get(0);
133 | }
134 | }
135 |
136 | static class Stopwatch
137 | {
138 |
139 | private DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.US);
140 |
141 | {
142 | DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols();
143 | decimalFormatSymbols.setGroupingSeparator(' ');
144 | decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols);
145 | }
146 |
147 | private long start;
148 | private long end;
149 |
150 | public Stopwatch()
151 | {
152 | start();
153 | }
154 |
155 | public void start()
156 | {
157 | start = System.nanoTime();
158 | }
159 |
160 | Stopwatch stop()
161 | {
162 | end = System.nanoTime();
163 | return this;
164 | }
165 |
166 | public String toString()
167 | {
168 | return format("%sms", decimalFormat.format((end - start) / 1000000));
169 | }
170 |
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.jarslab.maven
5 | babel-maven-plugin
6 | maven-plugin
7 | 1.7-SNAPSHOT
8 | Babel Maven Plugin
9 | Transpile JavaScript files in Babel in pure Java.
10 | https://github.com/jarslab/babel-maven-plugin
11 |
12 |
13 | MIT License
14 | http://www.opensource.org/licenses/mit-license.php
15 | repo
16 |
17 |
18 |
19 |
20 | Milosz Polak
21 | http://jarslab.com
22 |
23 | Project owner
24 | Developer
25 |
26 | Europe/Warsaw
27 |
28 |
29 | Jonas Koperdraat
30 | http://jonaskoperdraat.nl
31 |
32 | Developer
33 |
34 | Europe/Amsterdam
35 |
36 |
37 |
38 |
39 | ${maven.api.version}
40 |
41 |
42 |
43 | 1.8
44 | 1.8
45 | 2.8.2
46 | 3.0
47 | 3.6.0
48 | UTF-8
49 |
50 |
51 |
52 |
53 | org.apache.maven
54 | maven-plugin-api
55 | ${maven.plugin.version}
56 | provided
57 |
58 |
59 | org.apache.maven.plugin-tools
60 | maven-plugin-annotations
61 | ${maven.plugin.version}
62 | provided
63 |
64 |
65 | org.immutables
66 | value
67 | ${immutables.version}
68 | provided
69 |
70 |
71 | org.graalvm.js
72 | js
73 | 19.3.1
74 |
75 |
76 |
77 | junit
78 | junit
79 | 4.12
80 | test
81 |
82 |
83 | org.assertj
84 | assertj-core
85 | 3.10.0
86 | test
87 |
88 |
89 | org.mockito
90 | mockito-core
91 | 2.21.0
92 | test
93 |
94 |
95 |
96 |
97 |
98 |
99 | org.apache.maven.plugins
100 | maven-plugin-plugin
101 | ${maven.plugin.version}
102 |
103 |
104 | maven-deploy-plugin
105 | ${immutables.version}
106 |
107 |
108 | default-deploy
109 | deploy
110 |
111 | deploy
112 |
113 |
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-release-plugin
119 | 2.5.3
120 |
121 | true
122 | false
123 | forked-path
124 | -Dgpg.passphrase=${gpg.passphrase}
125 |
126 |
127 |
128 | org.apache.maven.scm
129 | maven-scm-provider-gitexe
130 | 1.9.5
131 |
132 |
133 |
134 |
135 | org.apache.maven.plugins
136 | maven-source-plugin
137 | 3.0.1
138 |
139 |
140 | attach-sources
141 |
142 | jar
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | release-sign-artifacts
154 |
155 |
156 | performRelease
157 | true
158 |
159 |
160 |
161 |
162 |
163 | org.apache.maven.plugins
164 | maven-gpg-plugin
165 | 1.6
166 |
167 |
168 | sign-artifacts
169 | verify
170 |
171 | sign
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 | scm:git:git@github.com:jarslab/babel-maven-plugin.git
183 | scm:git:git@github.com:jarslab/babel-maven-plugin.git
184 | https://github.com/jarslab/babel-maven-plugin
185 | HEAD
186 |
187 |
188 |
189 | Github
190 | https://github.com/jarslab/babel-maven-plugin/issues
191 |
192 |
193 |
194 |
195 | ossrh
196 | https://oss.sonatype.org/content/repositories/snapshots
197 |
198 |
199 | ossrh
200 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
201 |
202 |
203 |
204 |
205 |
--------------------------------------------------------------------------------
/src/main/java/com/jarslab/maven/babel/plugin/BabelMojo.java:
--------------------------------------------------------------------------------
1 | package com.jarslab.maven.babel.plugin;
2 |
3 | import com.jarslab.maven.babel.plugin.transpiler.ParallelBabelTranspilerStrategy;
4 | import com.jarslab.maven.babel.plugin.transpiler.Transpilation;
5 | import org.apache.maven.plugin.AbstractMojo;
6 | import org.apache.maven.plugin.MojoExecutionException;
7 | import org.apache.maven.plugin.MojoFailureException;
8 | import org.apache.maven.plugins.annotations.LifecyclePhase;
9 | import org.apache.maven.plugins.annotations.Mojo;
10 | import org.apache.maven.plugins.annotations.Parameter;
11 |
12 | import java.io.File;
13 | import java.nio.charset.Charset;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import java.util.Set;
17 |
18 | import static java.lang.String.format;
19 | import static java.nio.charset.Charset.defaultCharset;
20 |
21 | @Mojo(name = "babel", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, threadSafe = true)
22 | public class BabelMojo extends AbstractMojo
23 | {
24 | @Parameter(property = "verbose", defaultValue = "false")
25 | private boolean verbose = false;
26 |
27 | @Parameter(property = "threads", defaultValue = "1")
28 | private int threads = 1;
29 |
30 | @Parameter(property = "babelSrc", required = true)
31 | private File babelSrc;
32 |
33 | @Parameter(property = "sourceDir", required = true)
34 | private File sourceDir;
35 |
36 | @Parameter(property = "targetDir", required = true)
37 | private File targetDir;
38 |
39 | @Parameter(property = "jsSourceFiles", alias = "jsFiles")
40 | private List jsSourceFiles = new ArrayList<>();
41 |
42 | @Parameter(property = "jsSourceIncludes", alias = "jsIncludes")
43 | private List jsSourceIncludes = new ArrayList<>();
44 |
45 | @Parameter(property = "jsSourceExcludes", alias = "jsExcludes")
46 | private List jsSourceExcludes = new ArrayList<>();
47 |
48 | @Parameter(property = "prefix")
49 | private String prefix;
50 |
51 | @Parameter(property = "formatPresets", defaultValue = "true")
52 | private boolean formatPresets = true;
53 |
54 | @Parameter(property = "presets", defaultValue = "es2015")
55 | private String presets;
56 |
57 | @Parameter(property = "plugins")
58 | private String plugins = "";
59 |
60 | @Parameter(property = "encoding")
61 | private String encoding = defaultCharset().name();
62 |
63 | @Override
64 | public void execute() throws MojoExecutionException, MojoFailureException
65 | {
66 | final Charset charset = Charset.forName(encoding);
67 | if (verbose) {
68 | getLog().info("Run in the verbose mode.");
69 | getLog().info(format("Charset: %s.", charset));
70 | getLog().debug(toString());
71 | }
72 | if (!babelSrc.exists() || !babelSrc.canRead()) {
73 | getLog().error("Given Babel file is not reachable.");
74 | throw new MojoFailureException("Given Babel file is not reachable.");
75 | }
76 | if (presets.isEmpty()) {
77 | throw new MojoFailureException("No Babel presets defined.");
78 | }
79 | if (jsSourceFiles.isEmpty() && jsSourceIncludes.isEmpty()) {
80 | getLog().warn("No source files provided, nothing to do.");
81 | return;
82 | }
83 |
84 | final Set transpilations = new TranspilationInitializer(this).getTranspilations();
85 | if (transpilations.isEmpty()) {
86 | getLog().info("No files found to transpile.");
87 | return;
88 | }
89 | if (verbose) {
90 | getLog().info(format("Found %s files to transpile.", transpilations.size()));
91 | }
92 |
93 | try {
94 | new ParallelBabelTranspilerStrategy(getLog(), threads)
95 | .execute(transpilations)
96 | .parallel()
97 | .forEach(TargetFileWriter::writeTargetFile);
98 | } catch (Exception e) {
99 | throw new MojoExecutionException("Failed on Babel transpile execution.", e);
100 | }
101 | getLog().info("Babel transpile execution successful.");
102 | }
103 |
104 | public boolean isVerbose()
105 | {
106 | return this.verbose;
107 | }
108 |
109 | public int getThreads()
110 | {
111 | return this.threads;
112 | }
113 |
114 | public File getBabelSrc()
115 | {
116 | return this.babelSrc;
117 | }
118 |
119 | public File getSourceDir()
120 | {
121 | return this.sourceDir;
122 | }
123 |
124 | public File getTargetDir()
125 | {
126 | return this.targetDir;
127 | }
128 |
129 | public List getJsSourceFiles()
130 | {
131 | return this.jsSourceFiles;
132 | }
133 |
134 | public List getJsSourceIncludes()
135 | {
136 | return this.jsSourceIncludes;
137 | }
138 |
139 | public List getJsSourceExcludes()
140 | {
141 | return this.jsSourceExcludes;
142 | }
143 |
144 | public String getPrefix()
145 | {
146 | return this.prefix;
147 | }
148 |
149 | public boolean isFormatPresets()
150 | {
151 | return formatPresets;
152 | }
153 |
154 | public String getPresets()
155 | {
156 | return this.presets;
157 | }
158 |
159 | public String getPlugins()
160 | {
161 | return this.plugins;
162 | }
163 |
164 | public String getEncoding()
165 | {
166 | return this.encoding;
167 | }
168 |
169 | public void setVerbose(boolean verbose)
170 | {
171 | this.verbose = verbose;
172 | }
173 |
174 | public void setThreads(int threads)
175 | {
176 | this.threads = threads;
177 | }
178 |
179 | public void setBabelSrc(File babelSrc)
180 | {
181 | this.babelSrc = babelSrc;
182 | }
183 |
184 | public void setSourceDir(File sourceDir)
185 | {
186 | this.sourceDir = sourceDir;
187 | }
188 |
189 | public void setTargetDir(File targetDir)
190 | {
191 | this.targetDir = targetDir;
192 | }
193 |
194 | public void setJsSourceFiles(List jsSourceFiles)
195 | {
196 | this.jsSourceFiles = jsSourceFiles;
197 | }
198 |
199 | public void setJsSourceFile(String jsSourceFile)
200 | {
201 | jsSourceFiles.add(jsSourceFile);
202 | }
203 |
204 | public void setJsSourceIncludes(List jsSourceIncludes)
205 | {
206 | this.jsSourceIncludes = jsSourceIncludes;
207 | }
208 |
209 | public void setJsSourceInclude(String jsSourceInclude)
210 | {
211 | jsSourceIncludes.add(jsSourceInclude);
212 | }
213 |
214 | public void setJsSourceExcludes(List jsSourceExcludes)
215 | {
216 | this.jsSourceExcludes = jsSourceExcludes;
217 | }
218 |
219 | public void setJsSourceExclude(String jsSourceExclude)
220 | {
221 | this.jsSourceExcludes.add(jsSourceExclude);
222 | }
223 |
224 | public void setPrefix(String prefix)
225 | {
226 | this.prefix = prefix;
227 | }
228 |
229 | public void setFormatPresets(final boolean formatPresets)
230 | {
231 | this.formatPresets = formatPresets;
232 | }
233 |
234 | public void setPresets(String presets)
235 | {
236 | this.presets = presets;
237 | }
238 |
239 | public void setPlugins(final String plugins)
240 | {
241 | this.plugins = plugins;
242 | }
243 |
244 | public void setEncoding(String encoding)
245 | {
246 | this.encoding = encoding;
247 | }
248 |
249 | @Override
250 | public String toString()
251 | {
252 | return "BabelMojo{" +
253 | "verbose=" + verbose +
254 | ", threads=" + threads +
255 | ", babelSrc=" + babelSrc +
256 | ", sourceDir=" + sourceDir +
257 | ", targetDir=" + targetDir +
258 | ", jsSourceFiles=" + jsSourceFiles +
259 | ", jsSourceIncludes=" + jsSourceIncludes +
260 | ", jsSourceExcludes=" + jsSourceExcludes +
261 | ", prefix='" + prefix + '\'' +
262 | ", formatPresets=" + formatPresets +
263 | ", presets='" + presets + '\'' +
264 | ", plugins='" + plugins + '\'' +
265 | ", encoding='" + encoding + '\'' +
266 | '}';
267 | }
268 | }
--------------------------------------------------------------------------------