Skip to content

Commit

Permalink
Merge pull request #574 from alibaba/develop
Browse files Browse the repository at this point in the history
Provide Android Studio plugin.
  • Loading branch information
zhi1ong committed Dec 14, 2018
2 parents 2fddd53 + 1bdd1b5 commit a264776
Show file tree
Hide file tree
Showing 16 changed files with 966 additions and 759 deletions.
724 changes: 365 additions & 359 deletions README.md

Large diffs are not rendered by default.

741 changes: 374 additions & 367 deletions README_CN.md

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

annotationProcessor project(':arouter-compiler')
compile project(':arouter-api')
compile project(':module-java')
compile project(':module-kotlin')
compile project(':arouter-annotation')
implementation project(':arouter-api')
implementation project(':module-java')
implementation project(':module-kotlin')
implementation project(':arouter-annotation')

compile 'com.alibaba:fastjson:1.2.9'
implementation 'com.alibaba:fastjson:1.2.48'

compile "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
implementation "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
implementation "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
}
4 changes: 2 additions & 2 deletions arouter-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {

dependencies {
annotationProcessor 'com.alibaba:arouter-compiler:1.2.0'
compile 'com.alibaba:arouter-annotation:1.0.6'
compile "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
implementation 'com.alibaba:arouter-annotation:1.0.6'
implementation "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
}

apply from: '../install.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DefaultPoolExecutor extends ThreadPoolExecutor {
private static final int MAX_THREAD_COUNT = INIT_THREAD_COUNT;
private static final long SURPLUS_THREAD_LIFE = 30L;

private static DefaultPoolExecutor instance;
private static volatile DefaultPoolExecutor instance;

public static DefaultPoolExecutor getInstance() {
if (null == instance) {
Expand Down
12 changes: 6 additions & 6 deletions arouter-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ compileJava {
}

dependencies {
compile 'com.alibaba:arouter-annotation:1.0.6'
implementation 'com.alibaba:arouter-annotation:1.0.6'

compile 'com.google.auto.service:auto-service:1.0-rc2'
compile 'com.squareup:javapoet:1.7.0'
implementation 'com.google.auto.service:auto-service:1.0-rc3'
implementation 'com.squareup:javapoet:1.8.0'

compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.apache.commons:commons-collections4:4.1'
implementation 'org.apache.commons:commons-lang3:3.5'
implementation 'org.apache.commons:commons-collections4:4.1'

compile 'com.alibaba:fastjson:1.2.48'
implementation 'com.alibaba:fastjson:1.2.48'
}

apply from: '../install.gradle'
Expand Down
38 changes: 38 additions & 0 deletions arouter-idea-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id "org.jetbrains.intellij" version '0.3.12'
}

intellij {
version support_idea_version
updateSinceUntilBuild false
plugins 'coverage'
}

patchPluginXml {
changeNotes """
1.0.0
First Release
"""
}

publishPlugin {
username intellijPublishUsername
password intellijPublishPassword
channels "beta"
}

dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.alibaba.android.arouter.idea.extensions

import com.intellij.codeHighlighting.Pass
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor
import com.intellij.navigation.NavigationItem
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.openapi.util.IconLoader
import com.intellij.psi.*
import com.intellij.psi.impl.source.tree.java.PsiMethodCallExpressionImpl
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.AnnotatedMembersSearch
import java.awt.event.MouseEvent

/**
* Mark navigation target.
*
* @author zhilong <a href="mailto:zhilong.liu@aliyun.com">Contact me.</a>
* @version 1.0
* @since 2018/12/13 12:30 PM
*/
class NavigationLineMarker : LineMarkerProviderDescriptor(), GutterIconNavigationHandler<PsiElement> {
override fun getName(): String? {
return "ARouter Location"
}

override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
return if (isNavigationCall(element)) {
LineMarkerInfo<PsiElement>(element, element.textRange, navigationOnIcon,
Pass.UPDATE_ALL, null, this,
GutterIconRenderer.Alignment.LEFT)
} else {
null
}
}

override fun navigate(e: MouseEvent?, psiElement: PsiElement?) {
if (psiElement is PsiMethodCallExpression) {
val psiExpressionList = (psiElement as PsiMethodCallExpressionImpl).argumentList
if (psiExpressionList.expressions.size == 1) {
// Support `build(path)` only now.

val targetPath = psiExpressionList.expressions[0].text.replace("\"", "")
val fullScope = GlobalSearchScope.allScope(psiElement.project)
val routeAnnotationWrapper = AnnotatedMembersSearch.search(getAnnotationWrapper(psiElement, fullScope)
?: return, fullScope).findAll()
val target = routeAnnotationWrapper.find {
it.modifierList?.annotations?.map { it.findAttributeValue("path")?.text?.replace("\"", "") }?.contains(targetPath)
?: false
}

if (null != target) {
// Redirect to target.
NavigationItem::class.java.cast(target).navigate(true)
return
}
}
}

notifyNotFound()
}

private fun notifyNotFound() {
Notifications.Bus.notify(Notification(NOTIFY_SERVICE_NAME, NOTIFY_TITLE, NOTIFY_NO_TARGET_TIPS, NotificationType.WARNING))
}

private fun getAnnotationWrapper(psiElement: PsiElement?, scope: GlobalSearchScope): PsiClass? {
if (null == routeAnnotationWrapper) {
routeAnnotationWrapper = JavaPsiFacade.getInstance(psiElement?.project).findClass(ROUTE_ANNOTATION_NAME, scope)
}

return routeAnnotationWrapper
}

override fun collectSlowLineMarkers(elements: MutableList<PsiElement>, result: MutableCollection<LineMarkerInfo<PsiElement>>) {}

/**
* Judge whether the code used for navigation.
*/
private fun isNavigationCall(psiElement: PsiElement): Boolean {
if (psiElement is PsiCallExpression) {
val method = psiElement.resolveMethod() ?: return false
val parent = method.parent

if (method.name == "build" && parent is PsiClass) {
if (isClassOfARouter(parent)) {
return true
}
}
}
return false
}

/**
* Judge whether the caller was ARouter
*/
private fun isClassOfARouter(psiClass: PsiClass): Boolean {
// It was ARouter
if (psiClass.name.equals(SDK_NAME)) {
return true
}

// It super class was ARouter
psiClass.supers.find { it.name == SDK_NAME } ?: return false

return true
}

companion object {
const val ROUTE_ANNOTATION_NAME = "com.alibaba.android.arouter.facade.annotation.Route"
const val SDK_NAME = "ARouter"

// Notify
const val NOTIFY_SERVICE_NAME = "ARouter Plugin Tips"
const val NOTIFY_TITLE = "Road Sign"
const val NOTIFY_NO_TARGET_TIPS = "No destination found or unsupported type."

val navigationOnIcon = IconLoader.getIcon("/icon/outline_my_location_black_18dp.png")
}

// I'm 100% sure this point can not made memory leak.
private var routeAnnotationWrapper: PsiClass? = null
}
16 changes: 16 additions & 0 deletions arouter-idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<idea-plugin>
<id>arouter-roadsign</id>
<name>ARouter Helper</name>
<version>1.0.0</version>
<vendor email="zhilong.liu@aliyun.com" url="https://www.alibaba.com">Alibaba</vendor>
<idea-version since-build="162.0"/>

<description><![CDATA[
Support to track navigation target.
]]></description>

<extensions defaultExtensionNs="com.intellij">
<codeInsight.lineMarkerProvider language="JAVA"
implementationClass="com.alibaba.android.arouter.idea.extensions.NavigationLineMarker"/>
</extensions>
</idea-plugin>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
buildscript {
ext.kotlin_version = '1.1.3-2'
ext.kotlin_version = '1.2.71'
ext.arouter_register_version = '1.0.2'

repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url 'http://dl.bintray.com/jetbrains/intellij-plugin-service'
}
mavenCentral()
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Expand All @@ -19,5 +27,6 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}
13 changes: 8 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
org.gradle.daemon=true
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

COMPILE_SDK_VERSION=25
BUILDTOOLS_VERSION=25.0.0
SUPPORT_LIB_VERSION=25.2.0
MIN_SDK_VERSION=12
TARGET_SDK_VERSION=25
COMPILE_SDK_VERSION=28
BUILDTOOLS_VERSION=28.0.3
SUPPORT_LIB_VERSION=28.0.0
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=28

arouter_compiler_version=1.2.2
arouter_api_version=1.4.1
arouter_annotation_version=1.0.6
arouter_register_version=1.0.2
arouter_idea_plugin_version=1.0.0
support_idea_version=2016.2.5
arouter_idea_plugin_name=ARouter Road Sign

bintrayRepo=maven
publishedGroupId=com.alibaba
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
5 changes: 3 additions & 2 deletions module-java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
apply plugin: 'com.android.library'

dependencies {
compile project(':arouter-api')
implementation project(':arouter-annotation')
implementation project(':arouter-api')
implementation "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
annotationProcessor project(':arouter-compiler')
compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
}
android {
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
Expand Down
9 changes: 5 additions & 4 deletions module-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ kapt {
}

dependencies {
compile project(':arouter-api')
implementation project(':arouter-api')
implementation project(':arouter-annotation')
kapt project(':arouter-compiler')
compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
android {
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ include ':arouter-compiler'
include ':arouter-annotation'
include ':module-java'
include ':module-kotlin'
include ':arouter-gradle-plugin'
include ':arouter-gradle-plugin'
include ':arouter-idea-plugin'

0 comments on commit a264776

Please sign in to comment.