Skip to content

Commit 2b3b04c

Browse files
authored
Improve classpath detection and logs (#11)
* 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 * Upgrade com.gradle.plugin-publish plugin * Bump 1.2.0
1 parent 921929f commit 2b3b04c

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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"
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"
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
plugins {
2-
id 'com.gradle.plugin-publish' version '0.15.0'
2+
id 'com.gradle.plugin-publish' version '0.19.0'
33
id 'maven-publish'
44
id 'groovy'
55
id 'java-library'
66
}
77

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

1111
sourceCompatibility = 9
1212
targetCompatibility = 9

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

Lines changed: 17 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,26 @@ 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 could not find the classpath, adding ' +
58+
'the following paths from project sourceSets: {}', classesPaths)
59+
pathSet.addAll(classesPaths)
60+
List<String> depsPaths = project.configurations.compileClasspath.collect { it.getPath() }
61+
depsPaths.addAll(project.configurations.runtimeClasspath.collect { it.getPath() })
62+
jshellTask.logger.info(":jshell could not find the dependencies' classpath, adding " +
63+
'the following paths from project configurations: {}', depsPaths)
64+
pathSet.addAll(depsPaths)
65+
}
5266
def path = pathSet.join(System.getProperty("path.separator"))
53-
jshellTask.logger.info(":jshell executing with --class-path \"{}\"", path)
67+
jshellTask.logger.info(":jshell executing with --class-path {}", path)
5468
shellArgs += [
5569
"--class-path", path,
5670
"--startup", "DEFAULT",
5771
"--startup", "PRINTING"
5872
]
5973
if (project.findProperty("jshell.startup") == "") {
60-
// Nothing, just avoid to run the startup.jsh if exists
74+
jshellTask.logger.info ':jshell "jshell.startup" set to empty, skipping "startup.jsh" execution'
6175
}
6276
else if (project.findProperty("jshell.startup")) {
6377
def jshellStartup = project.findProperty("jshell.startup")

0 commit comments

Comments
 (0)