feat: use @javatypes defiend java type
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
5f0c3bbdd4
commit
ef98c49e1d
@ -1,9 +1,12 @@
|
||||
import { ConnectionFactoryAdapter } from "./connection"
|
||||
import { RabbitTemplateAdapter } from "./template"
|
||||
import { JSClass } from "@ccms/container"
|
||||
|
||||
export const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
|
||||
export class RabbitAdminAdapter {
|
||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
private RabbitAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
constructor(config: RabbitTemplateAdapter | org.springframework.amqp.rabbit.core.RabbitTemplate | ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory) {
|
||||
this._Handler = new RabbitAdmin((config instanceof RabbitTemplateAdapter || config instanceof ConnectionFactoryAdapter) ? config.getHandler() : config)
|
||||
|
@ -2,7 +2,7 @@ import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
|
||||
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
||||
|
||||
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
||||
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
|
||||
export const AcknowledgeMode: org.springframework.amqp.core.AcknowledgeMode = Java.type('org.springframework.amqp.core.AcknowledgeMode')
|
||||
interface ContainerConfig {
|
||||
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
||||
queueNames: string[]
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { JSClass } from "@ccms/container"
|
||||
import { RabbitAdminAdapter, MessageListenerContainerAdapter, AcknowledgeMode, MessageHandler, ChannelAwareMessageListenerAdapter } from "./adapter"
|
||||
|
||||
const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
|
||||
export class AmqpAdmin {
|
||||
@JSClass('org.springframework.amqp.core.TopicExchange')
|
||||
private TopicExchange: typeof org.springframework.amqp.core.TopicExchange
|
||||
@ -10,14 +8,15 @@ export class AmqpAdmin {
|
||||
private Queue: typeof org.springframework.amqp.core.Queue
|
||||
@JSClass('org.springframework.amqp.core.Binding')
|
||||
private Binding: typeof org.springframework.amqp.core.Binding
|
||||
|
||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
private RabbitAdmin: typeof org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
@JSClass('org.springframework.amqp.core.Binding.DestinationType')
|
||||
private DestinationType: typeof org.springframework.amqp.core.Binding.DestinationType
|
||||
private DestinationType: org.springframework.amqp.core.Binding.DestinationType
|
||||
|
||||
private amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
|
||||
constructor(amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin | any) {
|
||||
if (amqpAdmin instanceof RabbitAdmin) {
|
||||
if (amqpAdmin instanceof this.RabbitAdmin) {
|
||||
this.amqpAdmin = amqpAdmin
|
||||
} else if (amqpAdmin instanceof RabbitAdminAdapter) {
|
||||
this.amqpAdmin = amqpAdmin.getHandler()
|
||||
|
@ -1,8 +1,8 @@
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@ccms/types/dist/typings/jdk" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/amqp" />
|
||||
/// <reference types="@ccms/types/dist/typings/rabbitmq" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/spring-amqp" />
|
||||
/// <reference types="@javatypes/spring-rabbit" />
|
||||
/// <reference types="@javatypes/amqp-client" />
|
||||
|
||||
import { amqp } from '@ccms/api'
|
||||
import { getContainer, reduceMetadata } from '@ccms/container'
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/bukkit" />
|
||||
/// <reference types="@javatypes/spigot-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/bungee" />
|
||||
/// <reference types="@javatypes/bungee-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -24,7 +24,8 @@
|
||||
"typescript": "^3.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/nashorn": "^0.7.0"
|
||||
"@ccms/nashorn": "^0.7.0",
|
||||
"@javatypes/jdk": "^1.14.0"
|
||||
},
|
||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/jdk" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
|
||||
/**
|
||||
* 反射工具类
|
||||
@ -11,7 +11,7 @@ const methodCache = []
|
||||
|
||||
class Reflect {
|
||||
private obj: java.lang.Object
|
||||
private class: java.lang.Class
|
||||
private class: java.lang.Class<any>
|
||||
|
||||
constructor(obj: any) {
|
||||
// if (obj === undefined || obj === null) { throw Error(`reflect object can't be ${obj}!`) }
|
||||
@ -26,8 +26,8 @@ class Reflect {
|
||||
}
|
||||
}
|
||||
|
||||
method(name: string, ...args: any[]) {
|
||||
return declaredMethod(this.class, name, args)
|
||||
method(name: string, ...args: java.lang.Class<any>[]) {
|
||||
return declaredMethod(this.class, name, ...args)
|
||||
}
|
||||
|
||||
methods() {
|
||||
@ -90,7 +90,7 @@ function types(values: any[], def?: any) {
|
||||
if (values === null) {
|
||||
return []
|
||||
}
|
||||
let result: java.lang.Class[] = []
|
||||
let result: java.lang.Class<any>[] = []
|
||||
values.forEach(t => result.push((t || def) ? JavaObject.class : t instanceof JavaClass ? t : t.class))
|
||||
return result
|
||||
}
|
||||
@ -119,7 +119,7 @@ function declaredConstructor(clazz, param) {
|
||||
return accessible(constructor)
|
||||
}
|
||||
|
||||
function declaredField(clazz: java.lang.Class, name: string | java.lang.String) {
|
||||
function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.String) {
|
||||
if (!clazz) { throw Error(`target class can't be ${clazz}!`) }
|
||||
let target = clazz
|
||||
let field = null
|
||||
@ -139,17 +139,17 @@ function declaredField(clazz: java.lang.Class, name: string | java.lang.String)
|
||||
return field
|
||||
}
|
||||
|
||||
function declaredMethod(clazz: java.lang.Class, name: string, ...clazzs: any[]): java.lang.reflect.Method {
|
||||
function declaredMethod(clazz: java.lang.Class<any>, name: string, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
|
||||
let key = clazz.getName() + '.' + name + ':' + (clazzs || []).join(':')
|
||||
if (!methodCache[key]) {
|
||||
try {
|
||||
methodCache[key] = clazz.getMethod(name, clazzs as any)
|
||||
methodCache[key] = clazz.getMethod(name, ...clazzs)
|
||||
} catch (ex) {
|
||||
try {
|
||||
methodCache[key] = clazz.getDeclaredMethod(name, clazzs as any)
|
||||
} catch (ex) {
|
||||
for (const m of Java.from(declaredMethods(clazz))) {
|
||||
if (m.name == name) {
|
||||
if (m.getName() == name) {
|
||||
methodCache[key] = m
|
||||
break
|
||||
}
|
||||
@ -160,8 +160,8 @@ function declaredMethod(clazz: java.lang.Class, name: string, ...clazzs: any[]):
|
||||
return methodCache[key]
|
||||
}
|
||||
|
||||
function declaredMethods(clazz) {
|
||||
return clazz.declaredMethods
|
||||
function declaredMethods(clazz: java.lang.Class<any>) {
|
||||
return clazz.getDeclaredMethods()
|
||||
}
|
||||
|
||||
let classMethodsCache: any[] = []
|
||||
|
@ -1,5 +1,3 @@
|
||||
/// <reference types="@ccms/types/dist/typings/spring" />
|
||||
|
||||
import { Model } from './model'
|
||||
|
||||
const HikariDataSource = Java.type('com.zaxxer.hikari.HikariDataSource')
|
||||
@ -69,7 +67,7 @@ export class DataBase {
|
||||
*/
|
||||
query<T>(sql: string, ...args: any[]): Array<T> {
|
||||
let startTime = Date.now()
|
||||
let result = Java.from(this.jdbcTemplate.queryForList(sql, args))
|
||||
let result = Java.from<any>(this.jdbcTemplate.queryForList(sql, args))
|
||||
console.debug(java.lang.String.format(`\n[DB] query \nSQL : ${sql.replace(/\?/ig, '%s')} \nCOST : ${Date.now() - startTime}ms`, args))
|
||||
return result
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@ccms/types/dist/typings/jdk/index" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/spring-jdbc" />
|
||||
|
||||
export * from './database'
|
||||
export * from './manager'
|
@ -13,8 +13,8 @@ declare global {
|
||||
|
||||
namespace Java {
|
||||
function type<T = any>(clazz: string): T
|
||||
function from<T>(javaObj: T[]): T[]
|
||||
function to<T>(array: T[], type?: T): T[]
|
||||
function from<T = any>(javaObj: T[]): T[]
|
||||
function to<T = any>(array: T[], type?: T): T[]
|
||||
function extend(...parentTypes: any[]): any
|
||||
function synchronized(func: () => void, lock: any): Function
|
||||
function asJSONCompatible<T = any>(obj: T): T
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/nukkit" />
|
||||
/// <reference types="@javatypes/nukkit-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -1,9 +1,8 @@
|
||||
/// <reference types="@ccms/types" />
|
||||
/// <reference types="@ccms/types/dist/typings/tomcat/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/index" />
|
||||
/// <reference types="@javatypes/tomcat" />
|
||||
/// <reference types="@javatypes/spring-web" />
|
||||
|
||||
import { constants, database, plugin, web } from "@ccms/api"
|
||||
import { inject, ContainerInstance, Container } from "@ccms/container"
|
||||
import { inject, ContainerInstance, Container, JSClass } from "@ccms/container"
|
||||
import { JSPlugin, interfaces, cmd } from "@ccms/plugin"
|
||||
import { DataBase, DataBaseManager } from '@ccms/database'
|
||||
import { Server, Context, RequestHandler } from '@ccms/web'
|
||||
@ -22,6 +21,9 @@ export class MiaoSpring extends interfaces.Plugin {
|
||||
@inject(web.Server)
|
||||
private webServer: Server
|
||||
|
||||
@JSClass('org.springframework.http.HttpStatus')
|
||||
private HttpStatus: org.springframework.http.HttpStatus
|
||||
|
||||
private ResponseEntity = org.springframework.http.ResponseEntity
|
||||
|
||||
private mainDatabase: DataBase
|
||||
@ -56,7 +58,7 @@ export class MiaoSpring extends interfaces.Plugin {
|
||||
preHandle: (ctx: Context) => {
|
||||
const index = foundMap.indexOf(ctx.request.getRequestURI())
|
||||
if (index != -1) {
|
||||
return this.ResponseEntity.status(org.springframework.http.HttpStatus.FOUND).header('Location', foundMap[index + 1]).build()
|
||||
return this.ResponseEntity.status(this.HttpStatus.FOUND).header('Location', foundMap[index + 1]).build()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1,6 +1,3 @@
|
||||
/// <reference types="@ccms/types/dist/typings/rabbitmq" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/amqp" />
|
||||
|
||||
import { constants, plugin as pluginApi, amqp, server, web } from '@ccms/api'
|
||||
import { plugin, interfaces, cmd } from '@ccms/plugin'
|
||||
import { AmqpAdmin, ConnectionFactoryAdapter, AmqpManager } from '@ccms/amqp'
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/sponge" />
|
||||
/// <reference types="@javatypes/sponge-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -1,18 +1,18 @@
|
||||
import { server, constants } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container';
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
|
||||
import * as reflect from '@ccms/common/dist/reflect'
|
||||
|
||||
const Sponge = org.spongepowered.api.Sponge;
|
||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||
const File = Java.type("java.io.File");
|
||||
const Sponge = org.spongepowered.api.Sponge
|
||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers
|
||||
const File = Java.type("java.io.File")
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class SpongeServer extends server.ReflectServer {
|
||||
private pluginsFolder: string;
|
||||
private pluginsFolder: string
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
super()
|
||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||
}
|
||||
|
||||
@ -35,25 +35,25 @@ export class SpongeServer extends server.ReflectServer {
|
||||
if (typeof sender === 'string') {
|
||||
sender = this.getPlayer(sender)
|
||||
}
|
||||
return Sponge.getCommandManager().process(sender, command).getQueryResult().get()
|
||||
return Sponge.getCommandManager().process(sender, command).getQueryResult().get() != 0
|
||||
}
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult().get()
|
||||
return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult().get() != 0
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return this.pluginsFolder;
|
||||
return this.pluginsFolder
|
||||
}
|
||||
getNativePluginManager() {
|
||||
return Sponge.getPluginManager() as any;
|
||||
return Sponge.getPluginManager() as any
|
||||
}
|
||||
getDedicatedServer() {
|
||||
return reflect.on(Sponge.getServer()).get()
|
||||
}
|
||||
getNettyPipeline() {
|
||||
return this.pipeline;
|
||||
return this.pipeline
|
||||
}
|
||||
getRootLogger() {
|
||||
return this.rootLogger;
|
||||
return this.rootLogger
|
||||
}
|
||||
sendJson(sender: string | any, json: string): void {
|
||||
if (typeof sender === "string") {
|
||||
|
@ -24,6 +24,7 @@
|
||||
"typescript": "^3.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.7.0",
|
||||
"@ccms/container": "^0.7.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
/// <reference types="@ccms/types/dist/typings/jdk/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/tomcat/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/beans/index" />
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/tomcat" />
|
||||
/// <reference types="@javatypes/spring-web" />
|
||||
/// <reference types="@javatypes/spring-core" />
|
||||
/// <reference types="@javatypes/spring-beans" />
|
||||
|
||||
export * from './server'
|
||||
export * from './decorators'
|
||||
|
Loading…
Reference in New Issue
Block a user