Skip to content

Commit

Permalink
Improve classpath detection and logs
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mrsarm committed Jan 2, 2022
1 parent 921929f commit 3d8da1d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To use this plugin, add the following to your `build.gradle`:

```groovy
plugins {
id "com.github.mrsarm.jshell.plugin" version "1.1.0"
id "com.github.mrsarm.jshell.plugin" version "1.2.0-RC1"
}
```

Expand Down Expand Up @@ -341,13 +341,15 @@ buildscript {
}
}
dependencies {
classpath "com.github.mrsarm:jshell-plugin:1.1.0"
classpath "com.github.mrsarm:jshell-plugin:1.2.0-RC1"
}
}
apply plugin: "com.github.mrsarm.jshell.plugin"
```

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

About
-----
Expand All @@ -372,4 +374,4 @@ and this version solves some issues and adds the following features:

### License

- (2020-2021) [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
- (2020-2022) [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'com.github.mrsarm'
version '1.1.0'
version '1.2.0-RC1'

sourceCompatibility = 9
targetCompatibility = 9
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 the original author or authors.
* Copyright 2020-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,10 @@ class JShellPlugin implements Plugin<Project> {
Task jshellTask = project.tasks.create('jshellSetup')
def classesTask = project.tasks.find { it.name == "classes" }
if (classesTask) {
jshellTask.logger.info 'Task "classes" found.'
jshellTask.dependsOn classesTask
} else {
jshellTask.logger.warn 'Task "classes" NOT found.'
}
jshellTask.doLast {
if (!jshellTask.dependsOn) {
Expand All @@ -49,15 +52,25 @@ class JShellPlugin implements Plugin<Project> {
pathSet.addAll(classpath.findAll { it.exists() })
}
}
if (pathSet.isEmpty()) {
List<String> classesPaths = project.sourceSets.main.output.getClassesDirs().collect { it.getPath() }
jshellTask.logger.info(":jshell couldn't find the classpath, adding " +
'the following paths from project sourceSets: {}', classesPaths)
pathSet.addAll(classesPaths)
List<String> depsPaths = project.configurations.default.collect { it.getPath() }
jshellTask.logger.info(":jshell couldn't find the dependencies' classpath, adding " +
'the following paths from project configurations: {}', depsPaths)
pathSet.addAll(depsPaths)
}
def path = pathSet.join(System.getProperty("path.separator"))
jshellTask.logger.info(":jshell executing with --class-path \"{}\"", path)
jshellTask.logger.info(":jshell executing with --class-path {}", path)
shellArgs += [
"--class-path", path,
"--startup", "DEFAULT",
"--startup", "PRINTING"
]
if (project.findProperty("jshell.startup") == "") {
// Nothing, just avoid to run the startup.jsh if exists
jshellTask.logger.info ':jshell "jshell.startup" set to empty, skipping "startup.jsh" execution'
}
else if (project.findProperty("jshell.startup")) {
def jshellStartup = project.findProperty("jshell.startup")
Expand Down

0 comments on commit 3d8da1d

Please sign in to comment.