Skip to content

Commit

Permalink
renjinlong:Upgrade Gradle7.5; Adapt to target34 reviewer:yuxueting&ra…
Browse files Browse the repository at this point in the history
…otao
  • Loading branch information
renjinlong committed Sep 4, 2024
1 parent a71dba2 commit fa9cdb2
Show file tree
Hide file tree
Showing 67 changed files with 1,408 additions and 625 deletions.
41 changes: 14 additions & 27 deletions replugin-host-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,28 @@
* the License.
*/

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
plugins {
id 'java'
id 'groovy'
id 'maven-publish'
}

repositories {
jcenter()
mavenCentral()
google()
}

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}

dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
mavenCentral()
}

dependencies {
compile 'com.android.tools.build:gradle:3.5.4'
compile 'org.json:json:20160212'
compile 'org.codehaus.groovy:groovy:2.4.7'
compile 'com.squareup:javapoet:1.5.1'
implementation 'com.android.tools.build:gradle:7.4.2'
implementation 'org.json:json:20160212'
implementation 'org.codehaus.groovy:groovy:2.4.7'
implementation 'com.squareup:javapoet:1.5.1'

compile gradleApi()
compile localGroovy()
implementation gradleApi()
implementation localGroovy()

compile 'com.google.gradle:osdetector-gradle-plugin:1.2.1'
compile 'net.dongliu:apk-parser:2.2.0'
implementation 'com.google.gradle:osdetector-gradle-plugin:1.2.1'
implementation 'net.dongliu:apk-parser:2.2.0'
}

project.ext.RP_ARTIFACT_ID = 'replugin-host-gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.qihoo360.replugin.gradle.compat

import com.android.sdklib.IAndroidTarget

/**
* @author hyongbai
*/
Expand All @@ -27,14 +25,14 @@ class ScopeCompat {
// return globalScope.getAndroidBuilder().getTarget().getPath(IAndroidTarget.ANDROID_JAR)
// }

static def getAndroidJar(def scope){
final MetaClass scopeClz = scope.metaClass

if (scopeClz.hasProperty(scope, "androidBuilder")) {
return scope.getAndroidBuilder().getTarget().getPath(IAndroidTarget.ANDROID_JAR)
}
if (scopeClz.hasProperty(scope, "sdkComponents")) {
return scope.sdkComponents.androidJarProvider.get().getAbsolutePath()
}
}
// static def getAndroidJar(def scope){
// final MetaClass scopeClz = scope.metaClass
//
// if (scopeClz.hasProperty(scope, "androidBuilder")) {
// return scope.getAndroidBuilder().getTarget().getPath(IAndroidTarget.ANDROID_JAR)
// }
// if (scopeClz.hasProperty(scope, "sdkComponents")) {
// return scope.sdkComponents.androidJarProvider.get().getAbsolutePath()
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,56 +44,38 @@ public class Replugin implements Plugin<Project> {

/* Extensions */
project.extensions.create(AppConstant.USER_CONFIG, RepluginConfig)

if (project.plugins.hasPlugin(AppPlugin)) {

def android = project.extensions.getByType(AppExtension)
android.applicationVariants.all { variant ->

addShowPluginTask(variant)

if (config == null) {
config = project.extensions.getByName(AppConstant.USER_CONFIG)
checkUserConfig(config)
}

def generateBuildConfigTask = VariantCompat.getGenerateBuildConfigTask(variant)
def appID = generateBuildConfigTask.appPackageName
def appID = [variant.getApplicationId(), variant.buildType.applicationIdSuffix].findAll().join()

def newManifest = ComponentsGenerator.generateComponent(appID, config)
println "${TAG} countTask=${config.countTask}"

def variantData = variant.variantData
def scope = variantData.scope

//host generate task
def generateHostConfigTaskName = scope.getTaskName(AppConstant.TASK_GENERATE, "HostConfig")
def generateHostConfigTask = project.task(generateHostConfigTaskName)

def generateHostConfigTaskName = getTaskName(variant, AppConstant.TASK_GENERATE, "HostConfig")
def generateHostConfigTask = project.task(generateHostConfigTaskName)
generateHostConfigTask.doLast {
FileCreators.createHostConfig(project, variant, config)
FileCreators.createHostConfig(project, generateBuildConfigTask, config)
}
generateHostConfigTask.group = AppConstant.TASKS_GROUP

//depends on build config task
if (generateBuildConfigTask) {
generateHostConfigTask.dependsOn generateBuildConfigTask
generateBuildConfigTask.finalizedBy generateHostConfigTask
}

//json generate task
def generateBuiltinJsonTaskName = scope.getTaskName(AppConstant.TASK_GENERATE, "BuiltinJson")
def generateBuiltinJsonTask = project.task(generateBuiltinJsonTaskName)

generateBuiltinJsonTask.doLast {
FileCreators.createBuiltinJson(project, variant, config)
}
generateBuiltinJsonTask.group = AppConstant.TASKS_GROUP

//depends on mergeAssets Task
def mergeAssetsTask = VariantCompat.getMergeAssetsTask(variant)
if (mergeAssetsTask) {
generateBuiltinJsonTask.dependsOn mergeAssetsTask
mergeAssetsTask.finalizedBy generateBuiltinJsonTask
mergeAssetsTask.doLast{
FileCreators.createBuiltinJson(project, variant, config)
}
}

variant.outputs.each { output ->
Expand Down Expand Up @@ -130,57 +112,44 @@ public class Replugin implements Plugin<Project> {
appendManifest(file, newManifest)
}
}

def appendManifest(def file, def content) {
if (file == null || !file.exists()) return
println "${AppConstant.TAG} appendManifest: ${file}"
def updatedContent = file.getText("UTF-8").replaceAll("</application>", content + "</application>")
file.write(updatedContent, 'UTF-8')
}

// 添加 【查看所有插件信息】 任务
def addShowPluginTask(def variant) {
def variantData = variant.variantData
def scope = variantData.scope
def showPluginsTaskName = scope.getTaskName(AppConstant.TASK_SHOW_PLUGIN, "")
def showPluginsTaskName = getTaskName(variant, AppConstant.TASK_SHOW_PLUGIN, "")
def showPluginsTask = project.task(showPluginsTaskName)

showPluginsTask.doLast {
IFileCreator creator = new PluginBuiltinJsonCreator(project, variant, config)
def dir = creator.getFileDir()

if (!dir.exists()) {
println "${AppConstant.TAG} The ${dir.absolutePath} does not exist "
println "${AppConstant.TAG} pluginsInfo=null"
return
}

String fileContent = creator.getFileContent()
if (null == fileContent) {
return
}

new File(dir, creator.getFileName()).write(fileContent, 'UTF-8')
}
showPluginsTask.group = AppConstant.TASKS_GROUP

//get mergeAssetsTask name, get real gradle task
def mergeAssetsTask = VariantCompat.getMergeAssetsTask(variant)

//depend on mergeAssetsTask so that assets have been merged
if (mergeAssetsTask) {
showPluginsTask.dependsOn mergeAssetsTask
}

}

/**
* 检查用户配置项
*/
def checkUserConfig(config) {
/*
def persistentName = config.persistentName
if (persistentName == null || persistentName.trim().equals("")) {
project.logger.log(LogLevel.ERROR, "\n---------------------------------------------------------------------------------")
project.logger.log(LogLevel.ERROR, " ERROR: persistentName can'te be empty, please set persistentName in replugin. ")
Expand All @@ -198,14 +167,26 @@ public class Replugin implements Plugin<Project> {
doCheckConfig("countNotTranslucentSingleTop", config.countNotTranslucentSingleTop)
doCheckConfig("countNotTranslucentSingleTask", config.countNotTranslucentSingleTask)
doCheckConfig("countNotTranslucentSingleInstance", config.countNotTranslucentSingleInstance)

// 横屏
doCheckConfig("countTranslucentStandardLand", config.countTranslucentStandardLand)
doCheckConfig("countTranslucentSingleTopLand", config.countTranslucentSingleTopLand)
doCheckConfig("countTranslucentSingleTaskLand", config.countTranslucentSingleTaskLand)
doCheckConfig("countTranslucentSingleInstanceLand", config.countTranslucentSingleInstanceLand)
doCheckConfig("countNotTranslucentStandardLand", config.countNotTranslucentStandardLand)
doCheckConfig("countNotTranslucentSingleTopLand", config.countNotTranslucentSingleTopLand)
doCheckConfig("countNotTranslucentSingleTaskLand", config.countNotTranslucentSingleTaskLand)
doCheckConfig("countNotTranslucentSingleInstanceLand", config.countNotTranslucentSingleInstanceLand)

doCheckConfig("countTask", config.countTask)

println '--------------------------------------------------------------------------'
// println "${TAG} appID=${appID}"
println "${TAG} useAppCompat=${config.useAppCompat}"

println "${TAG} useOccupyLand=${config.useOccupyLand}"
println "${TAG} useAndroidX=${config.useAndroidX}"
// println "${TAG} persistentName=${config.persistentName}"

println "${TAG} countProcess=${config.countProcess}"

println "${TAG} countTranslucentStandard=${config.countTranslucentStandard}"
Expand All @@ -217,6 +198,16 @@ public class Replugin implements Plugin<Project> {
println "${TAG} countNotTranslucentSingleTask=${config.countNotTranslucentSingleTask}"
println "${TAG} countNotTranslucentSingleInstance=${config.countNotTranslucentSingleInstance}"

// 横屏
println "${TAG} countTranslucentStandardLand=${config.countTranslucentStandardLand()}"
println "${TAG} countTranslucentSingleTopLand=${config.countTranslucentSingleTopLand()}"
println "${TAG} countTranslucentSingleTaskLand=${config.countTranslucentSingleTaskLand()}"
println "${TAG} countTranslucentSingleInstanceLand=${config.countTranslucentSingleInstanceLand()}"
println "${TAG} countNotTranslucentStandardLand=${config.countNotTranslucentStandardLand()}"
println "${TAG} countNotTranslucentSingleTopLand=${config.countNotTranslucentSingleTopLand()}"
println "${TAG} countNotTranslucentSingleTaskLand=${config.countNotTranslucentSingleTaskLand()}"
println "${TAG} countNotTranslucentSingleInstanceLand=${config.countNotTranslucentSingleInstanceLand()}"

println "${TAG} countTask=${config.countTask}"
println '--------------------------------------------------------------------------'
}
Expand All @@ -234,6 +225,9 @@ public class Replugin implements Plugin<Project> {
System.exit(0)
}
}
String getTaskName(def variant, def prefix, def suffix){
return prefix + variant.name + suffix
}
}

class RepluginConfig {
Expand All @@ -247,6 +241,11 @@ class RepluginConfig {
/** 常驻进程名称(也就是上面说的 Persistent 进程,开发者可自定义)*/
def persistentName = ':GuardService'

/**
* 是否使用 横屏坑位
*/
def useOccupyLand = false

/** 背景不透明的坑的数量 */
def countNotTranslucentStandard = 6
def countNotTranslucentSingleTop = 2
Expand All @@ -259,6 +258,26 @@ class RepluginConfig {
def countTranslucentSingleTask = 2
def countTranslucentSingleInstance = 3

/** 背景不透明的坑的数量 横屏 */
def countNotTranslucentStandardLand = 1
def countNotTranslucentSingleTopLand = 1
def countNotTranslucentSingleTaskLand = 1
def countNotTranslucentSingleInstanceLand = 1
def countNotTranslucentStandardLand(){useOccupyLand ? countNotTranslucentStandardLand : 0}
def countNotTranslucentSingleTopLand(){useOccupyLand ? countNotTranslucentSingleTopLand : 0}
def countNotTranslucentSingleTaskLand(){useOccupyLand ? countNotTranslucentSingleTaskLand : 0}
def countNotTranslucentSingleInstanceLand(){useOccupyLand ? countNotTranslucentSingleInstanceLand : 0}

/** 背景透明的坑的数量 横屏*/
def countTranslucentStandardLand = 1
def countTranslucentSingleTopLand = 1
def countTranslucentSingleTaskLand = 1
def countTranslucentSingleInstanceLand = 1
def countTranslucentStandardLand(){useOccupyLand ? countTranslucentStandardLand : 0}
def countTranslucentSingleTopLand(){useOccupyLand ? countTranslucentSingleTopLand : 0}
def countTranslucentSingleTaskLand(){useOccupyLand ? countTranslucentSingleTaskLand : 0}
def countTranslucentSingleInstanceLand(){useOccupyLand ? countTranslucentSingleInstanceLand : 0}

/** 宿主中声明的 TaskAffinity 的组数 */
def countTask = 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class FileCreators {
println "${AppConstant.TAG} rewrite ${targetFile.getAbsoluteFile()}"
}

static def createHostConfig(project, variant, config) {
def creator = new RePluginHostConfigCreator(project, variant, config)
static def createHostConfig(project, generateBuildConfigTask, config) {
def creator = new RePluginHostConfigCreator(project, generateBuildConfigTask, config)
create(creator)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ public class RePluginHostConfigCreator implements IFileCreator {

def config
def project
def variant
def generateBuildConfigTask
def fileDir
def fileName

def RePluginHostConfigCreator(def project, def variant, def cfg) {
def RePluginHostConfigCreator(def project, def generateBuildConfigTask, def cfg) {
this.project = project
this.variant = variant;
this.generateBuildConfigTask = generateBuildConfigTask
this.config = cfg
//make it generated in buildConfig output dir so that we don't need to hook anything
File buildConfigGeneratedDir = this.variant.getVariantData().getScope().getBuildConfigSourceOutputDir()
File buildConfigGeneratedDir = this.generateBuildConfigTask.sourceOutputDir.asFile.get()
fileName = HOST_CONFIG_NAME;
fileDir = new File(buildConfigGeneratedDir, HOST_CONFIG_PATH)
}
Expand Down Expand Up @@ -76,6 +75,14 @@ public class RePluginHostConfig {
config.countTranslucentSingleInstance
};
// 背景透明的坑的数量(每种 launchMode 不同)横屏
public static int ACTIVITY_PIT_COUNT_TS_STANDARD_LAND = ${config.countTranslucentStandardLand()};
public static int ACTIVITY_PIT_COUNT_TS_SINGLE_TOP_LAND = ${config.countTranslucentSingleTopLand()};
public static int ACTIVITY_PIT_COUNT_TS_SINGLE_TASK_LAND = ${config.countTranslucentSingleTaskLand()};
public static int ACTIVITY_PIT_COUNT_TS_SINGLE_INSTANCE_LAND = ${
config.countTranslucentSingleInstanceLand()
};
// 背景不透明的坑的数量(每种 launchMode 不同)
public static int ACTIVITY_PIT_COUNT_NTS_STANDARD = ${config.countNotTranslucentStandard};
public static int ACTIVITY_PIT_COUNT_NTS_SINGLE_TOP = ${config.countNotTranslucentSingleTop};
Expand All @@ -84,6 +91,14 @@ public class RePluginHostConfig {
config.countNotTranslucentSingleInstance
};
// 背景不透明的坑的数量(每种 launchMode 不同)横屏
public static int ACTIVITY_PIT_COUNT_NTS_STANDARD_LAND = ${config.countNotTranslucentStandardLand()};
public static int ACTIVITY_PIT_COUNT_NTS_SINGLE_TOP_LAND = ${config.countNotTranslucentSingleTopLand()};
public static int ACTIVITY_PIT_COUNT_NTS_SINGLE_TASK_LAND = ${config.countNotTranslucentSingleTaskLand()};
public static int ACTIVITY_PIT_COUNT_NTS_SINGLE_INSTANCE_LAND = ${
config.countNotTranslucentSingleInstanceLand()
};
// TaskAffinity 组数
public static int ACTIVITY_PIT_COUNT_TASK = ${config.countTask};
Expand All @@ -93,6 +108,9 @@ public class RePluginHostConfig {
// HOST 是否使用 androidx 库
public static boolean HOST_USE_ANDROIDX = ${config.useAndroidX};
// 是否使用 横屏坑位
public static boolean HOST_USE_OCCUPYLAND = ${config.useOccupyLand};
//------------------------------------------------------------
// 主程序支持的插件版本范围
//------------------------------------------------------------
Expand Down
Loading

0 comments on commit fa9cdb2

Please sign in to comment.