Skip to content

Commit

Permalink
Update gdrive location detection
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnotoger committed Oct 13, 2024
1 parent 03e8cbe commit 5cc3645
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![](https://jitpack.io/v/itsnotoger/gradle-plugin.svg)](https://jitpack.io/#itsnotoger/gradle-plugin)

# gradle-plugin

My Gradle plugin for Java projects

It is written in Kotlin, but configures Java projects.
Expand All @@ -21,7 +22,8 @@ If you are able to have all your projects public, you do not need this plugin fu

Secondly, it supports some **application publication modes** that I like.
You can either publish Windows executable files (powered by the launch4j gradle plugin) or a fatjar.
For these, JavaFx support is added as well (namely: pulling the dependencies via JavaFx gradle plugin, and adding the necessary launch options).
For these, JavaFx support is added as well (namely: pulling the dependencies via JavaFx gradle plugin, and adding the
necessary launch options).
Overall, if you wanted to create a JavaFx executable, this makes the gradle code required to do so pretty small.

## Quick use guide for Gradle
Expand Down Expand Up @@ -51,3 +53,6 @@ plugins {
id("com.github.itsnotoger.gradle-plugin") version "XXX" // see jitpack badge at the top of readme for latest version
}
```

It should locate your Google Drive installation automatically, but you can specify a system prop `Gdrive` or env
variable `GDRIVE` if needed.
20 changes: 20 additions & 0 deletions src/main/kotlin/oger/util/java/GDriveLocator.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package oger.util.java

import org.gradle.internal.extensions.stdlib.capitalized
import org.gradle.internal.extensions.stdlib.toDefaultLowerCase
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

object GDriveLocator {
var DEBUG = false

fun locate(): Path? {

val letterDriveCandidates = File.listRoots()
.map { it.toPath() }
.map { it.resolve("My Drive") }
.toCollection(ArrayList())

addIfExists(letterDriveCandidates, "GDRIVE")

letterDriveCandidates.add(Paths.get("${System.getenv("userprofile")}/Google Drive"))
letterDriveCandidates.add(Paths.get("${System.getenv("userprofile")}/My Drive"))

if (DEBUG) letterDriveCandidates.forEach { println("checking location $it: ${Files.exists(it)}") }

return letterDriveCandidates.find { Files.exists(it) }
}

private fun addIfExists(candidates: MutableList<Path>, value: String) {
System.getenv(value)?.let {
candidates.add(0, Paths.get(it))
}
System.getProperty(value.toDefaultLowerCase().capitalized())?.let {
candidates.add(0, Paths.get(it))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ object ConfigureExtraJavaModule {
}

fun disableTestClasspath(project: Project) {
println("configure test classpath for $project")
project.plugins.withType(JavaPlugin::class.java) {
println("configure test classpath for java $project")
listOf("testCompileClasspath", "testRuntimeClasspath").forEach { configName ->
println("configure $configName for java $project")
project.configurations.named(configName).configure {
println("configure $configName for java $project attribute set")
it.attributes.attribute(Attribute.of("javaModule", Boolean::class.javaObjectType), false)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/test/groovy/oger.util.java/GDriveLocatorSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class GDriveLocatorSpec extends Specification {
def "finds gdrive on this system"() {
given:
def locator = GDriveLocator.@INSTANCE
locator.DEBUG = true

when:
def result = locator.locate()
Expand Down

0 comments on commit 5cc3645

Please sign in to comment.