-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* kotlin_transition: Use lateinit for plugin fields Reduce null complexity better tests for plugin init Added coveralls sourceDirs for kotlin files Converted mocks to infix syntax Converted code to kotlin and fixed tests to work with it Converted Tests to kotlin First test in kotlin Added kotlin feature
- Loading branch information
Showing
22 changed files
with
497 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ out | |
.gradle | ||
.idea | ||
*.iml | ||
build | ||
build | ||
classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#Plugin version | ||
version=1.1-SNAPSHOT | ||
#Dependency versions | ||
bukkit_version=1.7.9-R0.2 | ||
bukkit_version=1.7.9-R0.2 | ||
kotlin_version=1.0.5 |
58 changes: 0 additions & 58 deletions
58
src/main/java/de/poeschl/bukkit/logcleaner/LogCleanerPlugin.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
src/main/java/de/poeschl/bukkit/logcleaner/helper/FileHelper.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/main/java/de/poeschl/bukkit/logcleaner/managers/SettingManager.java
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
src/main/java/de/poeschl/bukkit/logcleaner/threads/LogCleanerThread.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
src/main/java/de/poeschl/bukkit/logcleaner/utils/InstanceFactory.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
src/main/kotlin/de/poeschl/bukkit/logcleaner/LogCleanerPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package de.poeschl.bukkit.logcleaner | ||
|
||
import de.poeschl.bukkit.logcleaner.helper.FileHelper | ||
import de.poeschl.bukkit.logcleaner.managers.SettingsManager | ||
import de.poeschl.bukkit.logcleaner.threads.LogCleanerRunnable | ||
import de.poeschl.bukkit.logcleaner.utils.InstanceFactory | ||
import org.bukkit.plugin.PluginDescriptionFile | ||
import org.bukkit.plugin.java.JavaPlugin | ||
import java.io.File | ||
import java.util.* | ||
import java.util.logging.Logger | ||
|
||
open class LogCleanerPlugin : JavaPlugin() { | ||
|
||
internal lateinit var instanceFactory: InstanceFactory | ||
internal lateinit var pluginLogger: Logger | ||
internal lateinit var settingManager: SettingsManager | ||
internal lateinit var fileHelper: FileHelper | ||
internal lateinit var logCleanerRunnable: LogCleanerRunnable | ||
|
||
override fun onEnable() { | ||
super.onEnable() | ||
val pdfFile = info | ||
|
||
if (config.getKeys(false).size == 0) { | ||
config | ||
saveDefaultConfig() | ||
} | ||
initFields() | ||
|
||
pluginLogger.info(pdfFile.name + " version " + pdfFile.version + " is enabled!") | ||
|
||
activateLogCleaner() | ||
} | ||
|
||
open internal val info: PluginDescriptionFile | ||
get() = description | ||
|
||
open internal fun initFields() { | ||
instanceFactory = createInstanceFactory() | ||
pluginLogger = instanceFactory.getLogger(this) | ||
settingManager = instanceFactory.createSettingsManager(config, pluginLogger) | ||
fileHelper = instanceFactory.createFileHelper(pluginLogger) | ||
logCleanerRunnable = instanceFactory.createLogCleanerRunnable(fileHelper, settingManager, LOG_FOLDER) | ||
} | ||
|
||
open internal fun createInstanceFactory(): InstanceFactory { | ||
return InstanceFactory() | ||
} | ||
|
||
open internal fun activateLogCleaner() { | ||
pluginLogger.info("Starting LogCleanerPlugin Thread") | ||
logCleanerRunnable.setNow(Date()) | ||
Thread(logCleanerRunnable).start() | ||
} | ||
|
||
companion object { | ||
private val LOG_FOLDER = File("./" + FileHelper.LOGS_FOLDER_NAME) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/de/poeschl/bukkit/logcleaner/helper/FileHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.poeschl.bukkit.logcleaner.helper | ||
|
||
import java.io.File | ||
import java.io.FilenameFilter | ||
import java.util.* | ||
import java.util.logging.Logger | ||
|
||
interface FileHelper { | ||
fun getLogArchives(logFolder: File): List<File> | ||
|
||
fun getLogArchiveDate(file: File): Date | ||
|
||
fun delete(file: File): Boolean | ||
|
||
companion object { | ||
val LOGS_FOLDER_NAME = "logs" | ||
} | ||
} | ||
|
||
class FileHelperImpl(private val logger: Logger) : FileHelper { | ||
|
||
override fun getLogArchives(logFolder: File): List<File> { | ||
val archiveFilter = FilenameFilter { dir, name -> name.endsWith(".gz") } | ||
|
||
return logFolder.listFiles(archiveFilter).asList() | ||
} | ||
|
||
override fun getLogArchiveDate(file: File): Date { | ||
val splitedName = file.name.split("-") | ||
|
||
val cal = Calendar.getInstance() | ||
cal.set(Integer.parseInt(splitedName[0]), Integer.parseInt(splitedName[1]) - 1, Integer.parseInt(splitedName[2])) | ||
return cal.time | ||
} | ||
|
||
override fun delete(file: File): Boolean { | ||
logger.info("Deleted log:" + file.name) | ||
return file.delete() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/de/poeschl/bukkit/logcleaner/managers/SettingManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.poeschl.bukkit.logcleaner.managers | ||
|
||
import de.poeschl.bukkit.logcleaner.managers.SettingsManager.Companion.KEEP_DAYS_KEY | ||
import org.bukkit.configuration.file.FileConfiguration | ||
|
||
import java.util.logging.Logger | ||
|
||
interface SettingsManager { | ||
|
||
val keepDays: Int | ||
|
||
fun updateConfig(config: FileConfiguration) | ||
|
||
companion object { | ||
val KEEP_DAYS_KEY = "keepLogsFromLastDays" | ||
} | ||
} | ||
|
||
class SettingsManagerImpl(private var config: FileConfiguration, private val logger: Logger) : SettingsManager { | ||
|
||
override val keepDays: Int | ||
get() { | ||
return config.getInt(KEEP_DAYS_KEY) | ||
} | ||
|
||
override fun updateConfig(config: FileConfiguration) { | ||
this.config = config | ||
} | ||
} |
Oops, something went wrong.