Skip to content

Commit 509a5f9

Browse files
regrogAndrea Vencato
authored and
Andrea Vencato
committed
unit test, bump dependencies, added more transpiler options support
1 parent cb2c221 commit 509a5f9

36 files changed

+1079
-225
lines changed

.classpath

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@
1212
<attribute name="gradle_used_by_scope" value="main,test"/>
1313
</attributes>
1414
</classpathentry>
15+
<classpathentry kind="src" output="bin/test" path="src/test/java">
16+
<attributes>
17+
<attribute name="gradle_scope" value="test"/>
18+
<attribute name="gradle_used_by_scope" value="test"/>
19+
<attribute name="test" value="true"/>
20+
</attributes>
21+
</classpathentry>
22+
<classpathentry kind="src" output="bin/test" path="src/test/resources">
23+
<attributes>
24+
<attribute name="gradle_scope" value="test"/>
25+
<attribute name="gradle_used_by_scope" value="test"/>
26+
<attribute name="test" value="true"/>
27+
</attributes>
28+
</classpathentry>
1529
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
1630
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
17-
<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
1831
<classpathentry kind="output" path="bin/default"/>
1932
</classpath>

.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
33
<name>jsweet-gradle-plugin</name>
4-
<comment></comment>
4+
<comment>JSweet Gradle plugin</comment>
55
<projects>
66
</projects>
77
<buildSpec>

build.gradle

+75-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
buildscript {
22
dependencies {
33
classpath 'org.hibernate.build.gradle:gradle-maven-publish-auth:2.0.1'
4-
classpath 'junit:junit:4.12'
5-
classpath "com.gradle.publish:plugin-publish-plugin:0.9.7"
4+
classpath "com.gradle.publish:plugin-publish-plugin:0.12.0"
65
}
76
repositories {
87
maven { url "http://repository.jboss.org/nexus/content/groups/public/" }
@@ -15,13 +14,14 @@ buildscript {
1514
}
1615

1716
plugins {
18-
id 'java'
17+
id 'java-gradle-plugin'
1918
id 'groovy'
2019
id 'maven'
2120
id 'maven-publish'
2221
id "org.datlowe.maven-publish-auth" version "2.0.2"
23-
id "com.gradle.plugin-publish" version "0.11.0"
22+
id "com.gradle.plugin-publish" version "0.12.0"
2423
id 'signing'
24+
id 'eclipse'
2525
}
2626

2727
defaultTasks 'clean', 'check', 'assemble'
@@ -49,7 +49,22 @@ dependencies {
4949
implementation localGroovy()
5050

5151
implementation group: 'org.jsweet', name: 'jsweet-transpiler', version: project.version
52-
implementation group: 'org.codehaus.plexus', name: 'plexus-utils', version:'3.0.20'
52+
implementation group: 'org.codehaus.plexus', name: 'plexus-utils', version:'3.3.0'
53+
54+
// test kit
55+
testImplementation gradleTestKit()
56+
57+
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"
58+
testImplementation "org.junit.jupiter:junit-jupiter-params:5.7.0"
59+
60+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"
61+
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.7.0"
62+
63+
}
64+
65+
test {
66+
useJUnitPlatform()
67+
testLogging.showStandardStreams = false
5368
}
5469

5570
task sourceJar(type: Jar) {
@@ -122,11 +137,60 @@ pluginBundle {
122137
vcsUrl = 'https://github.com/cincheo/jsweet'
123138
description = 'JSweet Gradle plugin'
124139
tags = ['jsweet', 'transpiler', 'java', 'web', 'typescript', 'typescript', 'gradle']
140+
}
141+
142+
gradlePlugin {
143+
// Define the plugin
144+
plugins {
145+
jsweetPlugin {
146+
id = 'org.jsweet.jsweet-gradle-plugin'
147+
displayName = 'JSweet Gradle plugin'
148+
implementationClass = 'org.jsweet.gradle.JSweetPlugin'
149+
}
150+
}
151+
}
152+
153+
wrapper {
154+
gradleVersion = "6.7.1"
155+
distributionType = Wrapper.DistributionType.ALL
156+
}
125157

126-
plugins {
127-
jsweetPlugin {
128-
id = 'org.jsweet.jsweet-gradle-plugin'
129-
displayName = 'JSweet Gradle plugin'
130-
}
131-
}
158+
// This block is neccessary to get Gradle's source code available when working on this project. This helps the development process tremendously.
159+
// See: http://stackoverflow.com/questions/22694199/gradle-api-sources-and-doc-when-writing-gradle-plugins/25305938#25305938
160+
import org.gradle.plugins.ide.eclipse.model.*
161+
eclipse {
162+
classpath {
163+
file {
164+
whenMerged {Classpath cp ->
165+
File gradleHome = gradle.getGradleHomeDir()
166+
logger.warn "Using Gradle: ${gradleHome}"
167+
168+
AbstractLibrary gradleApiLibrary = cp.entries.find { it.path.contains 'gradle-api' }
169+
if (gradleApiLibrary != null) {
170+
File gradleSrc = new File(gradleHome, 'src')
171+
if (!gradleSrc.exists()) {
172+
// Eclipse launched gradle with the bin distribution, look for the all distribution.
173+
File gradleAll = new File(gradle.getGradleHomeDir().getParentFile().getParentFile().absolutePath.replace('-bin', '-all'))
174+
if (gradleAll.exists()) {
175+
logger.debug "Found gradle-all: ${gradleAll}"
176+
File gradleAllCurrent = gradleAll.listFiles().iterator().next()
177+
if (gradleAllCurrent.exists()) {
178+
logger.debug "Found gradle-all current: ${gradleAllCurrent}"
179+
gradleSrc = new File(gradleAllCurrent, "gradle-${gradle.gradleVersion}/src")
180+
}
181+
}
182+
}
183+
184+
if (gradleSrc.exists()) {
185+
gradleApiLibrary.sourcePath = new org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory().fromFile(gradleSrc)
186+
logger.warn "Gradle's source found and included from: ${gradleSrc}"
187+
logger.debug "Updated library entry: ${gradleApiLibrary}"
188+
} else {
189+
logger.warn "Gradle's source not included as it was not found at: ${gradleSrc}"
190+
logger.warn "Update to the 'all' distribution with:\n> gradlew :wrapper --gradle-version=${gradle.gradleVersion} --distribution-type=all"
191+
}
192+
}
193+
}
194+
}
195+
}
132196
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/org/jsweet/gradle/AbstractJSweetTask.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.log4j.LogManager;
2020
import org.apache.log4j.Logger;
2121
import org.gradle.api.internal.ConventionTask;
22+
import org.gradle.api.tasks.Input;
2223

2324
/**
2425
* Base class for JSweet tasks
@@ -30,8 +31,9 @@ public abstract class AbstractJSweetTask extends ConventionTask {
3031

3132
protected final Logger logger = Logger.getLogger(getClass());
3233

34+
@Input
3335
protected JSweetPluginExtension configuration;
34-
36+
3537
public JSweetPluginExtension getConfiguration() {
3638
return configuration;
3739
}
@@ -41,8 +43,8 @@ public void setConfiguration(JSweetPluginExtension configuration) {
4143
}
4244

4345
protected void logInfo(String content) {
44-
if (configuration.isVerbose() != null && configuration.isVerbose()
45-
|| configuration.isVeryVerbose() != null && configuration.isVeryVerbose()) {
46+
if (configuration.isVerbose() != null && configuration.isVerbose() || configuration.isVeryVerbose() != null
47+
&& configuration.isVeryVerbose()) {
4648
logger.info(content);
4749
}
4850
}

src/main/java/org/jsweet/gradle/JSweetCleanTask.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private void clean(File directory) {
3232
logInfo("cleaning: " + directory);
3333
FileUtils.deleteQuietly(directory);
3434
}
35-
35+
3636
@TaskAction
3737
protected void clean() {
3838
configureLogging();
@@ -55,7 +55,7 @@ protected void clean() {
5555
}
5656

5757
clean(new File(".jsweet"));
58-
58+
5959
logInfo("clean end");
6060
}
6161
}

src/main/java/org/jsweet/gradle/JSweetPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void apply(final Project project) {
5757
task.setConfiguration(extension);
5858
task.setSources(mainSources.getAllJava());
5959
task.setClasspath(mainSources.getCompileClasspath());
60-
60+
6161
JSweetCleanTask cleanTask = project.getTasks().create("jsweetClean", JSweetCleanTask.class);
6262
cleanTask.setConfiguration(extension);
6363
}

src/main/java/org/jsweet/gradle/JSweetPluginExtension.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public void setTargetVersion(EcmaScriptComplianceLevel targetVersion) {
3737
}
3838

3939
public ModuleKind getModule() {
40-
return module;
40+
return module;
4141
}
42-
42+
4343
public void setModule(ModuleKind module) {
44-
this.module = module;
44+
this.module = module;
4545
}
4646

4747
public ModuleResolution getModuleResolution() {
@@ -56,6 +56,11 @@ public File getOutDir() {
5656
return outDir;
5757
}
5858

59+
/**
60+
*
61+
* @param outDir
62+
* the directory where JavaScript files are written
63+
*/
5964
public void setOutDir(File outDir) {
6065
this.outDir = outDir;
6166
}
@@ -212,6 +217,22 @@ public void setIgnoreTypeScriptErrors(Boolean ignoreTypeScriptErrors) {
212217
this.ignoreTypeScriptErrors = ignoreTypeScriptErrors;
213218
}
214219

220+
public Boolean isIgnoreJavaFileNameError() {
221+
return ignoreJavaFileNameError;
222+
}
223+
224+
public void setIgnoreJavaFileNameError(Boolean ignoreJavaFileNameError) {
225+
this.ignoreJavaFileNameError = ignoreJavaFileNameError;
226+
}
227+
228+
public Boolean isTscWatchMode() {
229+
return tscWatchMode;
230+
}
231+
232+
public void setTscWatchMode(Boolean tscWatchMode) {
233+
this.tscWatchMode = tscWatchMode;
234+
}
235+
215236
public File getHeader() {
216237
return header;
217238
}
@@ -243,7 +264,7 @@ public Boolean isVeryVerbose() {
243264
public void setVeryVerbose(Boolean veryVerbose) {
244265
this.veryVerbose = veryVerbose;
245266
}
246-
267+
247268
public File getWorkingDir() {
248269
return workingDir;
249270
}
@@ -287,7 +308,9 @@ public void setWorkingDir(File workingDir) {
287308
protected File header;
288309

289310
protected File workingDir;
290-
311+
291312
private Boolean tsserver;
292313
private Boolean veryVerbose;
314+
private Boolean ignoreJavaFileNameError;
315+
private Boolean tscWatchMode;
293316
}

0 commit comments

Comments
 (0)