支持component升降级处理,新增pins模块样式,优化pins工程逻辑
This commit is contained in:
@@ -29,9 +29,16 @@ dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
/**
|
||||
* component 会自动根据插件配置情况进行降级处理
|
||||
* component(':libraryKotlin') 由于配置了sdk,所以会编译时依赖sdk
|
||||
* component(':pins') 由于配置了子项目,所以编译时会处理子工程,同时降级为 project(':pins')
|
||||
* component(':libraryWithoutPlugin') 什么都没有配置,直接降级为 project(':libraryWithoutPlugin')
|
||||
*/
|
||||
implementation component(':library')
|
||||
implementation component(':libraryKotlin')
|
||||
implementation project(':libraryWithoutPlugin')
|
||||
implementation component(':libraryKotlin') //需要如此申明才能享受编译时依赖sdk,打包时包括sdk及实现
|
||||
implementation component(':pins') //等价 project(':libraryWithoutPlugin')
|
||||
implementation component(':libraryWithoutPlugin') //等价 project(':libraryWithoutPlugin')
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,12 +4,17 @@ import android.os.Bundle;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.library.LibraryWithoutPlugin;
|
||||
import com.plugin.library.IProvideFromLibrary;
|
||||
import com.plugin.library.ISdk;
|
||||
import com.plugin.library.ISdk2;
|
||||
import com.plugin.librarykotlin.IGetFromLibrary;
|
||||
import com.plugin.librarykotlin.IProvideFromKotlin;
|
||||
import com.plugin.module.R;
|
||||
import com.plugin.pin.MainBase;
|
||||
import com.plugin.pin.base.PBase;
|
||||
import com.plugin.pin.common.PCommon;
|
||||
import com.plugin.pin.home.PHome;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@@ -42,12 +47,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
stringBuilder.append("ISdk ->" + SdkManager.getSdk(ISdk.class).getSdkName() + "\n");
|
||||
stringBuilder.append("ISdk2 ->" + SdkManager.getSdk(ISdk2.class).getSdk2Name() + "\n");
|
||||
stringBuilder.append("libraryKotlin 提供 sdk:" + "\n");
|
||||
stringBuilder.append("IProvideFromKotlin ->" + SdkManager.getSdk(IProvideFromKotlin.class).provideString() + "\n");
|
||||
stringBuilder.append("IGetFromLibrary ->" + SdkManager.getSdk(IGetFromLibrary.class).provideString() + "\n");
|
||||
stringBuilder.append("IProvideFromKotlin ->" + SdkManager.getSdk(IProvideFromKotlin.class).provideString() + "\n");
|
||||
stringBuilder.append("IGetFromLibrary ->" + SdkManager.getSdk(IGetFromLibrary.class).provideString() + "\n");
|
||||
stringBuilder.append("pin子工程测试 \n");
|
||||
stringBuilder.append("main -> " + new MainBase().getString() + "\n");
|
||||
stringBuilder.append("base -> " + new PBase().getString() + "\n");
|
||||
stringBuilder.append("home -> " + new PHome().getString() + "\n");
|
||||
stringBuilder.append("common -> " + new PCommon().getString() + "\n");
|
||||
stringBuilder.append("普通模块测试 -> " + new LibraryWithoutPlugin().getString() + "\n");
|
||||
((TextView) findViewById(R.id.text)).setText(stringBuilder);
|
||||
}
|
||||
|
||||
public void initComponent(){
|
||||
public void initComponent() {
|
||||
ComponentManager.init(getApplication());
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class PinConfiguration {
|
||||
throw new GradleException("PinInfo with path '${name}' could not be found in ${project.getDisplayName()}.")
|
||||
}
|
||||
addIncludePin(pin)
|
||||
PinUtils.addMicroModuleSourceSet(project, pin, productFlavorInfo)
|
||||
PinUtils.addPinModuleSourceSet(project, pin, productFlavorInfo)
|
||||
}
|
||||
|
||||
for (String name : export) {
|
||||
@@ -57,13 +57,13 @@ class PinConfiguration {
|
||||
throw new GradleException("PinInfo with path '${name}' could not be found in ${project.getDisplayName()}.")
|
||||
}
|
||||
addExportPin(pin)
|
||||
PinUtils.addMicroModuleSourceSet(project, pin, productFlavorInfo)
|
||||
PinUtils.addPinModuleSourceSet(project, pin, productFlavorInfo)
|
||||
}
|
||||
|
||||
if (mainPath != null && !mainPath.isEmpty()) {
|
||||
PinInfo pin = PinUtils.buildPin(project, mainPath)
|
||||
setMainPin(pin)
|
||||
PinUtils.addMicroModuleSourceSet(project, pin, productFlavorInfo)
|
||||
PinUtils.addPinModuleSourceSet(project, pin, productFlavorInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class PinPlugin extends BasePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
project.dependencies.metaClass.microModule { String path ->
|
||||
project.dependencies.metaClass.pinProject { String path ->
|
||||
if (currentPin == null || applyScriptState == APPLY_NORMAL_MICRO_MODULE_SCRIPT) {
|
||||
return []
|
||||
}
|
||||
@@ -93,13 +93,13 @@ class PinPlugin extends BasePlugin {
|
||||
return []
|
||||
}
|
||||
|
||||
PinInfo microModule = pinConfiguration.getIncludePin(path)
|
||||
PinInfo pin = pinConfiguration.getIncludePin(path)
|
||||
|
||||
def result = []
|
||||
if (startTaskState == ASSEMBLE_OR_GENERATE) {
|
||||
PinUtils.addMicroModuleSourceSet(project, microModule, pinConfiguration.productFlavorInfo)
|
||||
PinUtils.applyMicroModuleScript(project, microModule, currentPin)
|
||||
microModule.appliedScript = true
|
||||
PinUtils.addPinModuleSourceSet(project, pin, pinConfiguration.productFlavorInfo)
|
||||
applyPinProjectScript(project, pin)
|
||||
pin.appliedScript = true
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -166,9 +166,9 @@ class PinPlugin extends BasePlugin {
|
||||
appliedLibraryPlugin = project.pluginManager.hasPlugin('com.android.library')
|
||||
applyScriptState = APPLY_INCLUDE_MICRO_MODULE_SCRIPT
|
||||
pinConfiguration.includePins.each {
|
||||
PinInfo microModule = it.value
|
||||
pinConfiguration.dependencyGraph.add(microModule.name)
|
||||
applyMicroModuleScript(project, microModule)
|
||||
PinInfo pin = it.value
|
||||
pinConfiguration.dependencyGraph.add(pin.name)
|
||||
applyPinProjectScript(project, pin)
|
||||
}
|
||||
|
||||
//清除所有 srouceSet 信息
|
||||
@@ -178,37 +178,37 @@ class PinPlugin extends BasePlugin {
|
||||
if (startTaskState == ASSEMBLE_OR_GENERATE) {
|
||||
//读取所有 export 配置
|
||||
applyScriptState = APPLY_EXPORT_MICRO_MODULE_SCRIPT
|
||||
boolean hasExportMainMicroModule = false
|
||||
boolean hasExportMainPinModule = false
|
||||
boolean isEmpty = pinConfiguration.exportPins.isEmpty()
|
||||
List<String> dependencySort = pinConfiguration.dependencyGraph.topSort()
|
||||
dependencySort.each {
|
||||
if (isEmpty || pinConfiguration.exportPins.containsKey(it)) {
|
||||
PinInfo microModule = pinConfiguration.getIncludePin(it)
|
||||
if (microModule == null) {
|
||||
PinInfo pin = pinConfiguration.getIncludePin(it)
|
||||
if (pin == null) {
|
||||
throw new GradleException("PinInfo with path '${it}' could not be found in ${project.getDisplayName()}.")
|
||||
}
|
||||
|
||||
if (microModule == pinConfiguration.mainPin) {
|
||||
hasExportMainMicroModule = true
|
||||
if (pin == pinConfiguration.mainPin) {
|
||||
hasExportMainPinModule = true
|
||||
}
|
||||
|
||||
if (microModule.appliedScript) return
|
||||
if (pin.appliedScript) return
|
||||
|
||||
PinUtils.addMicroModuleSourceSet(project, microModule, pinConfiguration.productFlavorInfo)
|
||||
applyMicroModuleScript(project, microModule)
|
||||
microModule.appliedScript = true
|
||||
PinUtils.addPinModuleSourceSet(project, pin, pinConfiguration.productFlavorInfo)
|
||||
applyPinProjectScript(project, pin)
|
||||
pin.appliedScript = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasExportMainMicroModule) {
|
||||
if (!hasExportMainPinModule) {
|
||||
throw new GradleException("the main PinInfo '${pinConfiguration.mainPin.name}' is not in the export list.")
|
||||
}
|
||||
} else {
|
||||
applyScriptState = APPLY_NORMAL_MICRO_MODULE_SCRIPT
|
||||
pinConfiguration.includePins.each {
|
||||
PinInfo microModule = it.value
|
||||
PinUtils.addMicroModuleSourceSet(project, microModule, pinConfiguration.productFlavorInfo)
|
||||
applyMicroModuleScript(project, microModule)
|
||||
PinInfo pin = it.value
|
||||
PinUtils.addPinModuleSourceSet(project, pin, pinConfiguration.productFlavorInfo)
|
||||
applyPinProjectScript(project, pin)
|
||||
}
|
||||
}
|
||||
currentPin = null
|
||||
@@ -221,12 +221,12 @@ class PinPlugin extends BasePlugin {
|
||||
pinConfiguration.includePins.each {
|
||||
PinInfo pin = it.value
|
||||
if (pin.appliedScript) {
|
||||
PinUtils.addMicroModuleSourceSet(project, pin, pinConfiguration.productFlavorInfo)
|
||||
PinUtils.addPinModuleSourceSet(project, pin, pinConfiguration.productFlavorInfo)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pinConfiguration.includePins.each {
|
||||
PinUtils.addMicroModuleSourceSet(project, it.value, pinConfiguration.productFlavorInfo)
|
||||
PinUtils.addPinModuleSourceSet(project, it.value, pinConfiguration.productFlavorInfo)
|
||||
}
|
||||
}
|
||||
PinUtils.generateAndroidManifest(project, pinConfiguration, startTaskState)
|
||||
@@ -290,11 +290,11 @@ class PinPlugin extends BasePlugin {
|
||||
}
|
||||
|
||||
|
||||
void applyMicroModuleScript(Project project, PinInfo microModule) {
|
||||
def pinBuild = new File(microModule.pinDir, 'build.gradle')
|
||||
void applyPinProjectScript(Project project, PinInfo pin) {
|
||||
def pinBuild = new File(pin.pinDir, 'build.gradle')
|
||||
if (pinBuild.exists()) {
|
||||
PinInfo tempMicroModule = currentPin
|
||||
currentPin = microModule
|
||||
currentPin = pin
|
||||
project.apply from: pinBuild.absolutePath
|
||||
currentPin = tempMicroModule
|
||||
}
|
||||
|
||||
@@ -94,11 +94,14 @@ class SdkPlugin extends BasePlugin {
|
||||
while (!currentDependencies.isEmpty()) {
|
||||
for (String string : currentDependencies) {
|
||||
ProjectInfo projectInfo = Runtimes.getProjectInfo(string)
|
||||
if (projectInfo == null) {
|
||||
continue
|
||||
}
|
||||
String name = projectInfo.name
|
||||
if (!hasResolve.contains(name)) {
|
||||
hasResolve.add(name)
|
||||
nextDependencies.addAll(projectInfo.componentDependencies)
|
||||
mutLineLog.build4("project[" + projectInfo.name + "] component 依赖 = " + projectInfo.getComponentDependenciesString())
|
||||
mutLineLog.build4("project[" + projectInfo.name + "] component 依赖 = " + projectInfo.getComponentDependenciesString())
|
||||
}
|
||||
}
|
||||
currentDependencies.clear()
|
||||
|
||||
@@ -128,7 +128,7 @@ class PinUtils {
|
||||
obj.manifest.srcFile project.projectDir.absolutePath + "/build/pin/merge-manifest/${variantName}/AndroidManifest.xml"
|
||||
}
|
||||
|
||||
static void addMicroModuleSourceSet(Project project, PinInfo pin, ProductFlavorInfo productFlavorInfo) {
|
||||
static void addPinModuleSourceSet(Project project, PinInfo pin, ProductFlavorInfo productFlavorInfo) {
|
||||
addVariantSourceSet(project, pin, 'main')
|
||||
|
||||
productFlavorInfo.buildTypes.each {
|
||||
|
||||
@@ -43,7 +43,12 @@ class PublicationUtil {
|
||||
String key = ProjectUtil.getComponentValue(value)
|
||||
projectInfo.componentDependencies.add(key)
|
||||
PublicationOption publication = Runtimes.getSdkPublication(key)
|
||||
return getPublication(publication)
|
||||
//对于依赖的模块,其使用插件但没有配置sdk,则直接依赖该项目
|
||||
if (publication == null) {
|
||||
return projectInfo.project.project(":" + key)
|
||||
} else {
|
||||
return getPublication(publication)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ component {
|
||||
|
||||
//申明插件的作用域,用于有 include 和 exclude
|
||||
//生效的模块会自动添加组件依赖 core,可使用 component(:{projectName}) 使用其他组件提供的sdk,同时可在 componentSdks 中配置自己模块暴露的sdk
|
||||
exclude 'libraryWithoutPlugin','component-core'
|
||||
exclude 'libraryWithoutPlugin', 'component-core'
|
||||
|
||||
// 上述 语句等价于下面语句
|
||||
// include ':app','library','libraryKotlin','debugModule'
|
||||
@@ -49,11 +49,10 @@ component {
|
||||
configuration {
|
||||
'pins' {
|
||||
codeCheckEnabled true
|
||||
include ':p_base'
|
||||
include ':p_common'
|
||||
include ':p_home'
|
||||
export ':main', ':p_home'
|
||||
export ':p_common'
|
||||
//参与编译的模块
|
||||
include ':p_base',':p_common',":p_home"
|
||||
//对外把暴露的模块
|
||||
export ':main'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.library
|
||||
|
||||
class LibraryWithoutPlugin {
|
||||
fun getString() = "I'am form LibraryWithoutPlugin"
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'main/libs', include: ['*.jar'])
|
||||
implementation pinProject(':p_common')
|
||||
implementation pinProject(':p_home')
|
||||
implementation pinProject(':p_base')
|
||||
}
|
||||
|
||||
10
pins/main/src/main/java/com/plugin/pin/MainBase.kt
Normal file
10
pins/main/src/main/java/com/plugin/pin/MainBase.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.plugin.pin
|
||||
|
||||
import com.plugin.pin.base.PBase
|
||||
import com.plugin.pin.common.PCommon
|
||||
import com.plugin.pin.home.PHome
|
||||
|
||||
class MainBase {
|
||||
|
||||
fun getString() = PBase().getString() + PCommon().getString() + PHome().getString()
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package com.plugin.pin.base;
|
||||
class Base {
|
||||
}
|
||||
6
pins/p_base/src/main/java/com/plugin/pin/base/PBase.kt
Normal file
6
pins/p_base/src/main/java/com/plugin/pin/base/PBase.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.plugin.pin.base
|
||||
|
||||
class PBase {
|
||||
|
||||
fun getString() = "p_base"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package com.plugin.pin.common;
|
||||
class Common {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.plugin.pin.common
|
||||
|
||||
class PCommon {
|
||||
|
||||
fun getString() = "p_common"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package com.plugin.pin.home;
|
||||
class Home {
|
||||
}
|
||||
6
pins/p_home/src/main/java/com/plugin/pin/home/PHome.kt
Normal file
6
pins/p_home/src/main/java/com/plugin/pin/home/PHome.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.plugin.pin.home
|
||||
|
||||
class PHome {
|
||||
|
||||
fun getString() = "p_home"
|
||||
}
|
||||
Reference in New Issue
Block a user