Skip to content

Commit 01f7ce8

Browse files
committed
Move pluginJars to RunWithPlugins class
1 parent e427c9c commit 01f7ce8

File tree

6 files changed

+68
-34
lines changed

6 files changed

+68
-34
lines changed

src/main/kotlin/xyz/jpenilla/runpaper/task/RunServer.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.gradle.api.provider.Provider
2222
import org.gradle.api.tasks.Input
2323
import org.gradle.api.tasks.Optional
2424
import xyz.jpenilla.runtask.service.DownloadsAPIService
25-
import xyz.jpenilla.runtask.task.AbstractRun
25+
import xyz.jpenilla.runtask.task.RunWithPlugins
2626
import xyz.jpenilla.runtask.util.FileCopyingPluginHandler
2727
import java.io.File
2828
import java.nio.file.Path
@@ -32,7 +32,7 @@ import java.nio.file.Path
3232
*
3333
* Note that configuring [version] is required for this task type.
3434
*/
35-
public abstract class RunServer : AbstractRun() {
35+
public abstract class RunServer : RunWithPlugins() {
3636
/**
3737
* Run Paper makes use of Paper's `add-plugin` command line option in order to
3838
* load the files in [pluginJars] as plugins. This option was implemented during

src/main/kotlin/xyz/jpenilla/runtask/RunPlugin.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.gradle.api.tasks.bundling.AbstractArchiveTask
2828
import org.gradle.kotlin.dsl.named
2929
import org.gradle.kotlin.dsl.withType
3030
import xyz.jpenilla.runtask.task.AbstractRun
31+
import xyz.jpenilla.runtask.task.RunWithPlugins
3132
import xyz.jpenilla.runtask.util.Constants
3233
import xyz.jpenilla.runtask.util.findJavaLauncher
3334
import xyz.jpenilla.runtask.util.maybeRegister
@@ -50,7 +51,7 @@ public abstract class RunPlugin : Plugin<Project> {
5051
}
5152
}
5253

53-
protected fun TaskProvider<out AbstractRun>.setupPluginJarDetection(
54+
protected fun TaskProvider<out RunWithPlugins>.setupPluginJarDetection(
5455
project: Project,
5556
extension: RunExtension
5657
) {

src/main/kotlin/xyz/jpenilla/runtask/task/AbstractRun.kt

-27
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.gradle.api.tasks.Input
2727
import org.gradle.api.tasks.Internal
2828
import org.gradle.api.tasks.JavaExec
2929
import org.gradle.api.tasks.Optional
30-
import xyz.jpenilla.runtask.RunExtension
3130
import xyz.jpenilla.runtask.service.DownloadsAPIService
3231
import xyz.jpenilla.runtask.util.path
3332
import java.io.File
@@ -86,14 +85,6 @@ public abstract class AbstractRun : JavaExec() {
8685
@get:Internal
8786
public abstract val runDirectory: DirectoryProperty
8887

89-
/**
90-
* The collection of plugin jars to load.
91-
*
92-
* @see [RunExtension.detectPluginJar]
93-
*/
94-
@get:Classpath
95-
public abstract val pluginJars: ConfigurableFileCollection
96-
9788
@get:Inject
9889
protected abstract val layout: ProjectLayout
9990

@@ -201,22 +192,4 @@ public abstract class AbstractRun : JavaExec() {
201192
public fun runDirectory(directory: File) {
202193
runDirectory.set(directory)
203194
}
204-
205-
/**
206-
* Convenience method for easily adding jars to [pluginJars].
207-
*
208-
* @param jars jars to add
209-
*/
210-
public fun pluginJars(vararg jars: File) {
211-
pluginJars.from(jars)
212-
}
213-
214-
/**
215-
* Convenience method for easily adding jars to [pluginJars].
216-
*
217-
* @param jars jars to add
218-
*/
219-
public fun pluginJars(vararg jars: Provider<RegularFile>) {
220-
pluginJars.from(jars)
221-
}
222195
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Run Task Gradle Plugins
3+
* Copyright (c) 2021-2022 Jason Penilla
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package xyz.jpenilla.runtask.task
18+
19+
import org.gradle.api.file.ConfigurableFileCollection
20+
import org.gradle.api.file.RegularFile
21+
import org.gradle.api.provider.Provider
22+
import org.gradle.api.tasks.Classpath
23+
import xyz.jpenilla.runtask.RunExtension
24+
import java.io.File
25+
26+
/**
27+
* Base task for runs which load a collection of plugin jars.
28+
*
29+
* Note that this class does not actually do anything to load
30+
* the plugins in [pluginJars], it's expected that subclasses
31+
* will implement this behavior in [preExec].
32+
*/
33+
public abstract class RunWithPlugins : AbstractRun() {
34+
35+
/**
36+
* The collection of plugin jars to load.
37+
*
38+
* @see [RunExtension.detectPluginJar]
39+
*/
40+
@get:Classpath
41+
public abstract val pluginJars: ConfigurableFileCollection
42+
43+
/**
44+
* Convenience method for easily adding jars to [pluginJars].
45+
*
46+
* @param jars jars to add
47+
*/
48+
public fun pluginJars(vararg jars: File) {
49+
pluginJars.from(jars)
50+
}
51+
52+
/**
53+
* Convenience method for easily adding jars to [pluginJars].
54+
*
55+
* @param jars jars to add
56+
*/
57+
public fun pluginJars(vararg jars: Provider<RegularFile>) {
58+
pluginJars.from(jars)
59+
}
60+
}

src/main/kotlin/xyz/jpenilla/runvelocity/task/RunVelocity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
package xyz.jpenilla.runvelocity.task
1818

1919
import xyz.jpenilla.runtask.service.DownloadsAPIService
20-
import xyz.jpenilla.runtask.task.AbstractRun
20+
import xyz.jpenilla.runtask.task.RunWithPlugins
2121
import xyz.jpenilla.runtask.util.FileCopyingPluginHandler
2222
import java.nio.file.Path
2323

2424
/**
2525
* Task to download and run a Velocity server along with plugins.
2626
*/
27-
public abstract class RunVelocity : AbstractRun() {
27+
public abstract class RunVelocity : RunWithPlugins() {
2828
override fun init() {
2929
downloadsApiService.convention(DownloadsAPIService.velocity(project))
3030
displayName.convention("Velocity")

src/main/kotlin/xyz/jpenilla/runwaterfall/task/RunWaterfall.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
package xyz.jpenilla.runwaterfall.task
1818

1919
import xyz.jpenilla.runtask.service.DownloadsAPIService
20-
import xyz.jpenilla.runtask.task.AbstractRun
20+
import xyz.jpenilla.runtask.task.RunWithPlugins
2121
import xyz.jpenilla.runtask.util.FileCopyingPluginHandler
2222
import java.nio.file.Path
2323

2424
/**
2525
* Task to download and run a Waterfall server along with plugins.
2626
*/
27-
public abstract class RunWaterfall : AbstractRun() {
27+
public abstract class RunWaterfall : RunWithPlugins() {
2828
override fun init() {
2929
downloadsApiService.convention(DownloadsAPIService.waterfall(project))
3030
displayName.convention("Waterfall")

0 commit comments

Comments
 (0)