diff --git a/.gitignore b/.gitignore index 3d70538..66fb1f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,80 +1,7 @@ -# Created by .ignore support plugin (hsz.mobi) -### Gradle template .gradle /build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties -### Kotlin template -# Compiled class file - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # *.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -### JetBrains template .idea - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/modules.xml -# .idea/*.iml -# .idea/modules - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - +*.iml diff --git a/.travis.yml b/.travis.yml index 94203b7..ae3232d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ sudo: true before_install: # 赋予执行权限 - chmod a+x gradlew +- chmod a+x deploy.sh script: # 清理、生成、测试、文档 @@ -32,7 +33,7 @@ deploy: tags: true - provider: script - script: ./gradlew clean build dokka bintrayUpload -PbintrayUser $bintrayUser -PbintrayKey $bintrayKey -PdryRun=false + script: bash ./deploy.sh on: tags: true diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..f68479e --- /dev/null +++ b/deploy.sh @@ -0,0 +1 @@ +./gradlew clean build dokka bintrayUpload -PbintrayUser $bintrayUser -PbintrayKey $bintrayKey -PdryRun=false \ No newline at end of file diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 29e08e8..0000000 --- a/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -kotlin.code.style=official \ No newline at end of file diff --git a/src/main/kotlin/org/mechdancer/dependency/ComponentNotExistException.kt b/src/main/kotlin/org/mechdancer/dependency/ComponentNotExistException.kt index c239557..8cb2061 100644 --- a/src/main/kotlin/org/mechdancer/dependency/ComponentNotExistException.kt +++ b/src/main/kotlin/org/mechdancer/dependency/ComponentNotExistException.kt @@ -7,4 +7,4 @@ import kotlin.reflect.KClass * @param which 要找的组件类型 */ class ComponentNotExistException(which: KClass) : - RuntimeException("cannot find this org.mechdancer.dependency: ${which.qualifiedName}") \ No newline at end of file + RuntimeException("Cannot find this component: ${which.qualifiedName}") \ No newline at end of file diff --git a/src/main/kotlin/org/mechdancer/dependency/unique/UniqueComponent.kt b/src/main/kotlin/org/mechdancer/dependency/unique/UniqueComponent.kt index eabc5e6..0c2608d 100644 --- a/src/main/kotlin/org/mechdancer/dependency/unique/UniqueComponent.kt +++ b/src/main/kotlin/org/mechdancer/dependency/unique/UniqueComponent.kt @@ -1,6 +1,7 @@ package org.mechdancer.dependency.unique import org.mechdancer.dependency.Component +import java.lang.reflect.ParameterizedType import kotlin.reflect.KClass import kotlin.reflect.full.safeCast @@ -11,7 +12,14 @@ import kotlin.reflect.full.safeCast * 泛型 [T] 可保证此类型来自这个实现类 */ abstract class UniqueComponent> - (private val type: KClass) : Component { + (type: KClass? = null) : Component { + + private val type = type ?: (javaClass.genericSuperclass as? ParameterizedType) + ?.let { type -> + type.actualTypeArguments + .find { t -> t is Class<*> && UniqueComponent::class.java.isAssignableFrom(t) } + ?.let { it as Class<*> } + }?.kotlin ?: throw RuntimeException("Unable to find component type.") override fun equals(other: Any?) = this === other || type.safeCast(other) !== null