Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ Also you can add custom (unsupported by BukkitGradle) attributes like a `depend`
Just create `plugin.yml` file and put custom attributes into.

### Running Dev server
Before running server you should configure path to BuildTools:
```groovy
bukkit {
buildtools = '/path/to/BuildTools.jar' // It can be only local directory
}
Before running server you should configure BuildTools and dev server location.

You can define it in `local.properties` file (that was automatically created in project root on refresh):
```properties
# Absolute path to directory that contains BuildTools.jar
buildtools.dir=/path/to/buildtools/
# Absolute path to dev server
server.dir=/path/to/buildtools/
```
Or you can define it globally (for all projects that uses BukkitGradle) with environment variables `BUKKIT_DEV_SERVER_HOME`
and `BUILDTOOLS_HOME`.

##### On IntelliJ IDEA
Run `:buildIdeaRun` task. To your IDE will be added Run Configuration that will dynamically refreshes when you change server configurations.
Run `:buildIdeaRun` task. To your IDE will be added Run Configuration that will dynamically refreshes when you change
server configurations.

![Run Configuration](http://image.prntscr.com/image/1a12a03b8ac54fccb7d5b70a335fa996.png)

Expand All @@ -138,8 +144,6 @@ bukkit {
eula = false
// Set online-mode flag
onlineMode = false
// Path to deploy server (relative)
dir = "server"
// Debug mode (listen 5005 port, if you use running from IDEA this option will be ignored)
debug = true
// Set server encoding (flag -Dfile.encoding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Bukkit {
private final Project project

String version
String buildtools = ''

final PluginMeta meta
final RunConfiguration run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class RunConfiguration {
boolean onlineMode
boolean debug
String encoding
String dir
String javaArgs
String bukkitArgs

Expand All @@ -29,7 +28,6 @@ class RunConfiguration {
this.onlineMode = false
this.debug = true
this.encoding = 'UTF-8'
this.dir = 'server'

this.javaArgs = '-Xmx1G'
this.bukkitArgs = ''
Expand All @@ -53,15 +51,6 @@ class RunConfiguration {
return bukkitArgs ?: ''
}

/**
* Returns servers dir
*
* @return The directory
*/
Path getDir() {
project.projectDir.toPath().resolve(this.dir)
}

/**
* Builds and writes to file run configuration in IDEA .xml format
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MetaFile {
*/
private void filterMetaLines() {
staticLines.clear()
if (!Files.exists(metaFile)) {
if (Files.notExists(metaFile)) {
return
}

Expand Down
102 changes: 84 additions & 18 deletions src/main/groovy/ru/endlesscode/bukkitgradle/server/ServerCore.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ import ru.endlesscode.bukkitgradle.BukkitGradlePlugin
import ru.endlesscode.bukkitgradle.extension.Bukkit
import ru.endlesscode.bukkitgradle.util.MavenApi

import javax.annotation.Nullable
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

class ServerCore {
public static final String CORE_NAME = "core.jar"
public static final String SERVER_HOME_PROPERTY = "server.dir"
public static final String SERVER_HOME_ENV = "BUKKIT_DEV_SERVER_HOME"
public static final String BUILDTOOLS_NAME = "BuildTools.jar"
public static final String BUILDTOOLS_HOME_PROPERTY = "buildtools.dir"
public static final String BUILDTOOLS_HOME_ENV = "BUILDTOOLS_HOME"

private static final String MAVEN_METADATA = "maven-metadata.xml"

private final Project project

private Path bukkitGradleDir
private boolean forceRebuild = false
private Properties localProps = new Properties()

ServerCore(Project project) {
this.project = project

MavenApi.init(project)

this.initDir()

project.afterEvaluate {
Expand All @@ -47,8 +53,8 @@ class ServerCore {
*/
void registerTasks() {
registerBukkitMetaTask()
registerCoreCopyTask()
registerBuildServerCoreTask()
registerCoreCopyTask()
}

/**
Expand Down Expand Up @@ -83,6 +89,11 @@ class ServerCore {
group = BukkitGradlePlugin.GROUP
description = 'Copy built server core to server directory'

if (!tasks.buildServerCore.enabled) {
enabled = false
return
}

def coreName = getCoreName()
from MavenApi.getSpigotDir(realVersion)
include coreName
Expand All @@ -109,17 +120,23 @@ class ServerCore {
return !MavenApi.hasSpigot(getRealVersion())
}

def path = Paths.get(project.bukkit.buildtools as String)
if (buildToolsPath == null || serverDir == null) {
project.logger.warn("You can't use server running feature.")
enabled = false
return
}

def path = buildToolsPath.resolve(BUILDTOOLS_NAME)
def absolutePath = path.toAbsolutePath().toString()
if (Files.notExists(path) || !Files.isRegularFile(path)) {
if (Files.notExists(path) || Files.isDirectory(path)) {
project.logger.warn("BuildTools not found on path: '$absolutePath'\n" +
'It should be path to .jar file of BuildTools.')
'BuildTools directory should contains BuildTools.jar file.')
enabled = false
return
}

main = '-jar'
args absolutePath, '--rev', getSimpleVersion()
args(absolutePath, '--rev', getSimpleVersion())
workingDir = path.getParent().toAbsolutePath().toString()
standardInput = System.in
}
Expand Down Expand Up @@ -150,6 +167,67 @@ class ServerCore {
return getRealVersion().replace(Bukkit.REVISION_SUFFIX, '')
}

/**
* Returns server directory
*
* @return Server directory or null if dev server location not defined
*/
@Nullable
Path getServerDir() {
return getDirFromPropsOrEnv(SERVER_HOME_PROPERTY, SERVER_HOME_ENV, "Dev server location")
}

private @Nullable
Path getBuildToolsPath() {
return getDirFromPropsOrEnv(BUILDTOOLS_HOME_PROPERTY, BUILDTOOLS_HOME_ENV, "BuildTools location")
}

private @Nullable
Path getDirFromPropsOrEnv(String propertyName, String envVariable, String comment) {
this.initLocalProps()

def localProp = localProps.getProperty(propertyName)
def globalEnv = System.getenv(envVariable)
if (localProp == null && globalEnv == null) {
project.logger.warn("$comment not found. It can be fixed by two ways:\n" +
" 1. Define location with '$propertyName' in the local.properties file\n" +
" 2. Define $envVariable environment variable")
return null
}
def dir = Paths.get(localProp ?: globalEnv)
Files.createDirectories(dir)

return dir
}

private initLocalProps() {
Path propsFile = this.project.file("local.properties").toPath()
if (Files.exists(propsFile)) {
localProps.load(propsFile.newReader())
return
}

project.logger.info("Local properties file not found. Creating...")
Files.createFile(propsFile)
localProps.load(propsFile.newReader())

if (System.getenv(SERVER_HOME_ENV) == null) {
localProps.setProperty(SERVER_HOME_PROPERTY, project.file("build/server").absolutePath)
}

if (System.getenv(BUILDTOOLS_HOME_ENV) == null) {
localProps.setProperty(BUILDTOOLS_HOME_PROPERTY, project.file("build/buildtools").absolutePath)
}

localProps.store(propsFile.newWriter(), " This file should *NOT* be checked into Version Control Systems,\n" +
" as it contains information specific to your local configuration.\n" +
" \n" +
" Location of the dev server and BuildTools.\n" +
" For customization when using a Version Control System, please read the\n" +
" header note."
)
}

/**
* Resolves and returns dynamic version
*
Expand Down Expand Up @@ -178,16 +256,4 @@ class ServerCore {
def metadata = new XmlSlurper().parse(metaFile.toFile())
return metadata.versioning.latest.toString()
}

/**
* Returns server directory
*
* @return Server directory
*/
Path getServerDir() {
Path serverDir = this.project.bukkit.run.dir.resolve(getSimpleVersion())
Files.createDirectories(serverDir)

return serverDir
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class SystemScript {
*/
void buildOn(Path dir) {
Path scriptFile = dir.resolve(getFileName())
if (!Files.exists(scriptFile)) {
if (Files.notExists(scriptFile)) {
Files.createFile(scriptFile)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PrepareServer extends DefaultTask {

void resolveEula() {
Path eulaFile = getServerDir().resolve("eula.txt")
if (!Files.exists(eulaFile)) {
if (Files.notExists(eulaFile)) {
Files.createFile(eulaFile)
}

Expand All @@ -45,7 +45,7 @@ class PrepareServer extends DefaultTask {

void resolveOnlineMode() {
Path propsFile = getServerDir().resolve("server.properties")
if (!Files.exists(propsFile)) {
if (Files.notExists(propsFile)) {
Files.createFile(propsFile)
}

Expand Down
5 changes: 0 additions & 5 deletions src/test/groovy/ru/endlesscode/bukkitgradle/TestBase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class TestBase {
description = "Test project description"
version = "1.0"
ext.url = "https://www.example.ru/"

bukkit {
buildtools = "/path/to/buildtools"
}
}
}

Expand Down Expand Up @@ -78,7 +74,6 @@ command:
eula = true
onlineMode = true
debug = false
dir = 'devServer'
encoding = 'CP866'
javaArgs = '-Xmx2G'
bukkitArgs = '-s 2'
Expand Down