Skip to content

Commit

Permalink
✨ Add @file:MavenDepends
Browse files Browse the repository at this point in the history
🔒 Add Support for Java11
👽 update LibraryManager to v1.3.2
🍱 Add .gitprefix
  • Loading branch information
way-zer committed Mar 2, 2020
1 parent a59cf45 commit d1ec7c3
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 204 deletions.
31 changes: 31 additions & 0 deletions .gitprefix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//By way_zer, references:
// Angular Conventions
// http://gitmoji.surge.sh/

|$| ===Type 类型
//Follow Angular,May different
:sparkles: NewOrImprove | 新功能或外部改善
:bug: BugFix | bug修复
:memo: Documentation | 添加文档
:art: Style | 自动优化(Lint,Reformat)
:hammer: InteralChange | 内部重构,不外部变化
:white_check_mark: Test | 测试效果修改
:bento: Chore | 其他代码无关的杂事

|$| ===Reason 原因===
:alien: DueToApi | 外界导致变更
:globe_with_meridians: Globalization | 国际化
:lock: Safe | 安全
:zap: Proformance | 优化性能
|$| ===Operate 操作===
:fire: Remove | 删除xxx
:truck: Move | 移动或重命名
|$| ===Other 结果,变更,备注===
:construction: UnderConstruct | 建设中
:bookmark: NewVersion | 版本号更新
:boom: BreakChange | 重大修改
:ok_hand: Closes | 关闭Issue或Pull

merge {
:twisted_rightwards_arrows: Merge From
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ shadowJar {
//start

dependencies{
shadow 'cf.wayzer:LibraryManager:1.3'
shadow 'cf.wayzer:LibraryManager:1.3.2'
shadow(files("$rootDir/lib/PowerNBT.jar"))
compile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlin_version"
Expand Down
188 changes: 0 additions & 188 deletions gradlew

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/cf/wayzer/SuperItem/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Main : JavaPlugin() {
require(Dependency("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"))
require(Dependency("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"))
require(Dependency("org.jetbrains:annotations:13.0"))
loadToClasspath()
loadToClassLoader(Main::class.java.classLoader)
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/cf/wayzer/SuperItem/features/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import cf.wayzer.SuperItem.Main
import org.bukkit.metadata.FixedMetadataValue
import org.bukkit.metadata.Metadatable

object DataStore {
interface DataStore<T>{
fun set(o: Metadatable,value: T?)
fun <T> get(o:Metadatable,defaultValue:T):T
}
interface DataStore<T>{
fun set(o: Metadatable,value: T?)
fun <T> get(o:Metadatable,defaultValue:T):T

class MetaStore<T>(override val defaultData: Nothing) :Feature<Nothing>(),DataStore<T>{
private val key:String
get() = "SIMS_${item.name}"
Expand All @@ -25,4 +24,4 @@ object DataStore {
}
}
//TODO other Store: SQL and File
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package cf.wayzer.SuperItem.scripts

import cf.wayzer.SuperItem.Item
import cf.wayzer.libraryManager.Dependency
import cf.wayzer.libraryManager.LibraryManager
import org.bukkit.Bukkit
import org.bukkit.Material
import java.io.File
import java.nio.file.Paths
import kotlin.reflect.KClass
import kotlin.script.experimental.api.*
import kotlin.script.experimental.jvm.JvmScriptCompilationConfigurationBuilder
import kotlin.script.experimental.jvm.dependenciesFromClassloader
import kotlin.script.experimental.jvm.jvm
import kotlin.script.experimental.jvm.updateClasspath
import kotlin.script.experimental.jvm.util.classpathFromClass

object CompilationConfiguration: ScriptCompilationConfiguration({
jvm {
dependenciesFromClassloader(
"kotlin-stdlib"
,classLoader = ScriptLoader::class.java.classLoader)
dependenciesFromClass(Bukkit::class, Item::class)
}
defaultImports(Item::class, ImportClass::class,Material::class)
defaultImports(Item::class, ImportClass::class,MavenDepends::class,Material::class)
defaultImports.append("cf.wayzer.SuperItem.features.*")
refineConfiguration{
onAnnotations(ImportClass::class){ context->
Expand All @@ -28,6 +35,23 @@ object CompilationConfiguration: ScriptCompilationConfiguration({
}
}.asSuccess(diagnostics)
}
onAnnotations(MavenDepends::class){ context->
val annotations = context.collectedData?.get(ScriptCollectedData.foundAnnotations)?.filter { it.annotationClass== MavenDepends::class }?: listOf()
val dependencies = annotations.map {Dependency((it as MavenDepends).name,it.repo)}
val diagnostics = dependencies.map { ScriptDiagnostic("[Info]MavenDependency: $it",ScriptDiagnostic.Severity.INFO) }
ScriptCompilationConfiguration(context.compilationConfiguration) {
jvm {
LibraryManager(Paths.get("lib")).apply {
addAliYunMirror()
dependencies.forEach {
require(it)
}
loadToClassLoader(javaClass.classLoader)
updateClasspath(loadFiles())
}
}
}.asSuccess(diagnostics)
}
}
})
private fun JvmScriptCompilationConfigurationBuilder.dependenciesFromClass(vararg classes: KClass<out Any>) {
Expand All @@ -39,4 +63,4 @@ private fun JvmScriptCompilationConfigurationBuilder.dependenciesFromClass(varar
url?.toURI()?.schemeSpecificPart?.let { listOf(File(it.removePrefix("file:").split("!")[0])) }
}?: emptyList()
}.let(this::updateClasspath)
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/cf/wayzer/SuperItem/scripts/ImportClass.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cf.wayzer.SuperItem.scripts

@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class ImportClass(
val name:String
)
val name:String
)
11 changes: 11 additions & 0 deletions src/main/kotlin/cf/wayzer/SuperItem/scripts/MavenDepends.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cf.wayzer.SuperItem.scripts

import cf.wayzer.libraryManager.Repository

@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class MavenDepends(
val name: String,
val repo: String = Repository.DEFAULT
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ScriptLoader {
private fun load0(f: File):ResultWithDiagnostics<EvaluationResult>{
return BasicJvmScriptingHost(hostConfiguration).eval(f.toScriptSource(),compilationConfiguration, ScriptEvaluationConfiguration {
jvm {
baseClassLoader(ScriptSupporter::class.java.classLoader)
baseClassLoader(ScriptLoader::class.java.classLoader)
}
constructorArgs(f.name.split(".")[0].toUpperCase())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cf.wayzer.SuperItem.Main
import cf.wayzer.libraryManager.Dependency
import cf.wayzer.libraryManager.LibraryManager
import java.io.File
import java.net.URLClassLoader
import java.nio.file.Paths
import java.util.logging.Logger

Expand All @@ -26,8 +25,8 @@ object ScriptSupporter {
require(Dependency("org.jetbrains.kotlin:kotlin-scripting-compiler-impl:${Main.kotlinVersion}"))
require(Dependency("org.jetbrains.kotlin:kotlin-compiler:${Main.kotlinVersion}"))
require(Dependency("org.jetbrains.kotlin:kotlin-script-util:${Main.kotlinVersion}"))
}.loadToClassLoader(Main::class.java.classLoader as URLClassLoader)
loader = ScriptLoader()
}.loadToClassLoader(Main::class.java.classLoader)
loader = Class.forName("cf.wayzer.SuperItem.scripts.ScriptLoader").newInstance() as ScriptLoader
loader.logger=logger
inited =true
}
Expand Down

0 comments on commit d1ec7c3

Please sign in to comment.