Skip to content

Commit 3d8da1d

Browse files
committed
Improve classpath detection and logs
* When classpath is not detected, use alternative sources to get the paths * Better logging of jshell execution withing the console when `--info` argument is passed * Minor docs improvement
1 parent 921929f commit 3d8da1d

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ To use this plugin, add the following to your `build.gradle`:
2323

2424
```groovy
2525
plugins {
26-
id "com.github.mrsarm.jshell.plugin" version "1.1.0"
26+
id "com.github.mrsarm.jshell.plugin" version "1.2.0-RC1"
2727
}
2828
```
2929

@@ -341,13 +341,15 @@ buildscript {
341341
}
342342
}
343343
dependencies {
344-
classpath "com.github.mrsarm:jshell-plugin:1.1.0"
344+
classpath "com.github.mrsarm:jshell-plugin:1.2.0-RC1"
345345
}
346346
}
347347
348348
apply plugin: "com.github.mrsarm.jshell.plugin"
349349
```
350350

351+
Also, when launching the plugin from another project, to see the ":jshell" logs
352+
add the `--info` argument in the command line, e.g.: `gradle --console plain jshell --info`.
351353

352354
About
353355
-----
@@ -372,4 +374,4 @@ and this version solves some issues and adds the following features:
372374

373375
### License
374376

375-
- (2020-2021) [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
377+
- (2020-2022) [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0).

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'com.github.mrsarm'
9-
version '1.1.0'
9+
version '1.2.0-RC1'
1010

1111
sourceCompatibility = 9
1212
targetCompatibility = 9

src/main/groovy/com/github/mrsarm/jshell/plugin/JShellPlugin.groovy

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,10 @@ class JShellPlugin implements Plugin<Project> {
3333
Task jshellTask = project.tasks.create('jshellSetup')
3434
def classesTask = project.tasks.find { it.name == "classes" }
3535
if (classesTask) {
36+
jshellTask.logger.info 'Task "classes" found.'
3637
jshellTask.dependsOn classesTask
38+
} else {
39+
jshellTask.logger.warn 'Task "classes" NOT found.'
3740
}
3841
jshellTask.doLast {
3942
if (!jshellTask.dependsOn) {
@@ -49,15 +52,25 @@ class JShellPlugin implements Plugin<Project> {
4952
pathSet.addAll(classpath.findAll { it.exists() })
5053
}
5154
}
55+
if (pathSet.isEmpty()) {
56+
List<String> classesPaths = project.sourceSets.main.output.getClassesDirs().collect { it.getPath() }
57+
jshellTask.logger.info(":jshell couldn't find the classpath, adding " +
58+
'the following paths from project sourceSets: {}', classesPaths)
59+
pathSet.addAll(classesPaths)
60+
List<String> depsPaths = project.configurations.default.collect { it.getPath() }
61+
jshellTask.logger.info(":jshell couldn't find the dependencies' classpath, adding " +
62+
'the following paths from project configurations: {}', depsPaths)
63+
pathSet.addAll(depsPaths)
64+
}
5265
def path = pathSet.join(System.getProperty("path.separator"))
53-
jshellTask.logger.info(":jshell executing with --class-path \"{}\"", path)
66+
jshellTask.logger.info(":jshell executing with --class-path {}", path)
5467
shellArgs += [
5568
"--class-path", path,
5669
"--startup", "DEFAULT",
5770
"--startup", "PRINTING"
5871
]
5972
if (project.findProperty("jshell.startup") == "") {
60-
// Nothing, just avoid to run the startup.jsh if exists
73+
jshellTask.logger.info ':jshell "jshell.startup" set to empty, skipping "startup.jsh" execution'
6174
}
6275
else if (project.findProperty("jshell.startup")) {
6376
def jshellStartup = project.findProperty("jshell.startup")

0 commit comments

Comments
 (0)