Skip to content

Commit

Permalink
Merge pull request iqiyi#6 from iqiyi/removeLog
Browse files Browse the repository at this point in the history
remove useless log and upgrade to 1.0.6
  • Loading branch information
HiWong authored Apr 22, 2018
2 parents 2fefe47 + 5767764 commit 53250fb
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 767 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@ import org.qiyi.video.svg.plugin.extension.DispatcherExtension
import org.qiyi.video.svg.plugin.service.IServiceGenerator
import org.qiyi.video.svg.plugin.service.StubServiceGenerator

public class AndromedaPlugin implements Plugin<Project> {
class AndromedaPlugin implements Plugin<Project> {

private IServiceGenerator stubServiceGenerator = new StubServiceGenerator()

public static final String DISPATCHER_EXTENSION_NAME = "dispatcher"

@Override
void apply(Project project) {

project.extensions.create("dispatcher",DispatcherExtension)
project.extensions.create(DISPATCHER_EXTENSION_NAME, DispatcherExtension)

def android = project.extensions.getByType(AppExtension)

stubServiceGenerator.injectStubServiceToManifest(project)

//注册一个Transform
def classTransform = new AndromedaTransform(project,stubServiceGenerator)
def classTransform = new AndromedaTransform(project, stubServiceGenerator)

android.registerTransform(classTransform)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,23 @@ package org.qiyi.video.svg.plugin
import com.android.build.api.transform.*
import com.android.build.gradle.internal.pipeline.TransformManager
import javassist.ClassPool
import javassist.CtClass
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.FileUtils
import org.gradle.api.Project
import org.qiyi.video.svg.plugin.service.ServiceMatchInjector
import org.qiyi.video.svg.plugin.injector.StubServiceMatchInjector
import org.qiyi.video.svg.plugin.service.IServiceGenerator
import org.qiyi.video.svg.plugin.utils.CtUtils

public class AndromedaTransform extends Transform {
class AndromedaTransform extends Transform {

private Project project

private StubServiceMatchInjector stubServiceMatchInjector

private ServiceMatchInjector serviceMatchInjector

private IServiceGenerator serviceGenerator

public AndromedaTransform(Project project, IServiceGenerator serviceGenerator) {
AndromedaTransform(Project project, IServiceGenerator serviceGenerator) {
this.project = project
this.serviceGenerator = serviceGenerator
//this.serviceMatchInjector=new ServiceMatchInjector(serviceGenerator)
}

@Override
Expand Down Expand Up @@ -77,9 +71,6 @@ public class AndromedaTransform extends Transform {

println "AndromedaTransform-->transform"

//newTransform(transformInvocation)


//step1:将所有类的路径加入到ClassPool中
ClassPool classPool = new ClassPool()
project.android.bootClasspath.each {
Expand Down Expand Up @@ -110,7 +101,6 @@ public class AndromedaTransform extends Transform {
input.jarInputs.each { JarInput jarInput ->
//重命名输出文件(同目录copyFile会冲突)
def jarName = jarInput.name
println("jar=" + jarInput.file.getAbsolutePath())

stubServiceMatchInjector.injectMatchCode(jarInput)

Expand All @@ -123,27 +113,6 @@ public class AndromedaTransform extends Transform {
FileUtils.copyFile(jarInput.file, dest)
}
}

}

private void newTransform(TransformInvocation transformInvocation){
TransformOutputProvider outputProvider=transformInvocation.outputProvider
outputProvider.deleteAll()
File jarFile=outputProvider.getContentLocation("main",getOutputTypes(),getScopes(),Format.JAR)
if(!jarFile.getParentFile().exists()){
jarFile.getParentFile().mkdirs()
}
if(jarFile.exists()){
jarFile.delete()
}

ClassPool classPool=new ClassPool()
project.android.bootClasspath.each{
classPool.appendClassPath((String)it.absolutePath)
}

List<CtClass> allClasses=CtUtils.getCtClasses(transformInvocation.inputs,classPool)
serviceMatchInjector.injectMatchCode(allClasses,jarFile)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ClassAppender {
it.jarInputs.each {
classPool.insertClassPath(it.file.absolutePath)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import org.qiyi.video.svg.plugin.utils.JarUtils
import java.util.jar.JarEntry
import java.util.jar.JarFile

public class StubServiceMatchInjector {
class StubServiceMatchInjector {

private static final String STUB_SERVICE_MATCHER = "org.qiyi.video.svg.utils.StubServiceMatcher"

Expand All @@ -49,13 +49,13 @@ public class StubServiceMatchInjector {

private IServiceGenerator serviceGenerator

private Map<String,String>matchedServices
private Map<String, String> matchedServices
private boolean found = false

public StubServiceMatchInjector(ClassPool classPool, IServiceGenerator serviceGenerator, String rootDirPath) {
StubServiceMatchInjector(ClassPool classPool, IServiceGenerator serviceGenerator, String rootDirPath) {
this.classPool = classPool
this.serviceGenerator=serviceGenerator
this.rootDirPath=rootDirPath
this.serviceGenerator = serviceGenerator
this.rootDirPath = rootDirPath
}

private void readMatchedServices(String dirPath, String fileName) {
Expand All @@ -74,15 +74,15 @@ public class StubServiceMatchInjector {
while ((content = reader.readLine()) != null) {
String[] matchKeyValues = content.split(",")
if (matchKeyValues != null) {
println "read key:"+matchKeyValues[0]+",value:"+matchKeyValues[1]
println "read key:" + matchKeyValues[0] + ",value:" + matchKeyValues[1]
matchedServices.put(matchKeyValues[0], matchKeyValues[1])
}
}
reader.close()
ism.close()
}

public void injectMatchCode(JarInput jarInput) {
void injectMatchCode(JarInput jarInput) {
if (found) {
return
}
Expand All @@ -99,8 +99,6 @@ public class StubServiceMatchInjector {
JarEntry jarEntry = (JarEntry) enumeration.nextElement()
String entryName = jarEntry.getName()

//println "jarEntryName:"+entryName

if (entryName.endsWith(STUB_SERVICE_MATCHER_CLASS)) {
prepareInjectMatchCode(filePath)
found = true
Expand All @@ -113,16 +111,11 @@ public class StubServiceMatchInjector {

private void prepareInjectMatchCode(String filePath) {

//filePath是类似../ServiceManager/StarBridge-Lib/build/intermediates/intermediate-jars/debug/classes.jar这样的路径
//TODO 但是遇到/Users/wangallen/.gradle/caches/transforms-1/files-1.1/core-0.9.3.aar/c57f58254c75aebebc28c22661fd8042/jars/classes.jar这样的,就会出现如下异常:
//TODO java.io.FileNotFoundException: /Users/wangallen/.gradle/caches/transforms-1/files-1.1/core-0.9.3.aar/c57f58254c75aebebc28c22661fd8042/jars/classes/org/qiyi (Not a directory)
println "StubServiceMatchInjector-->prepareInjectMatchCode,filePath:" + filePath
println "prepareInjectMatchCode"

File jarFile = new File(filePath)
String jarDir = jarFile.getParent() + File.separator + jarFile.getName().replace('.jar', '')

println "jarDir:"+jarDir

//解压jar包,解压之后就是.class文件
List<String> classNameList = JarUtils.unzipJar(filePath, jarDir)

Expand All @@ -148,10 +141,10 @@ public class StubServiceMatchInjector {

}

private void fetchServiceInfo(){
matchedServices=serviceGenerator.getMatchServices()
private void fetchServiceInfo() {
matchedServices = serviceGenerator.getMatchServices()
if (matchedServices == null) {
this.matchedServices=new HashMap<>()
this.matchedServices = new HashMap<>()
readMatchedServices(rootDirPath + File.separator + StubServiceGenerator.MATCH_DIR, StubServiceGenerator.MATCH_FILE_NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,46 @@
package org.qiyi.video.svg.plugin.manifest


public class ComponentReader implements IComponentReader {
class ComponentReader implements IComponentReader {

def manifest

public ComponentReader(String filePath) {
ComponentReader(String filePath) {
manifest = new XmlSlurper().parse(filePath)
}

@Override
void readActivities(Set<String> processNames) {
manifest.application.activity.each {
addProcess(processNames,it)
addProcess(processNames, it)
}
}

@Override
void readServices(Set<String> processNames) {
manifest.application.service.each {
addProcess(processNames,it)
addProcess(processNames, it)
}
}

private void addProcess(Set<String>processNames,def it) {
private void addProcess(Set<String> processNames, def it) {
String processName = it.'@android:process'
if (processName!=null&&processName.length()>0) {
if (processName != null && processName.length() > 0) {
processNames.add(processName)
}
}

@Override
void readBroadcastReceivers(Set<String> processNames) {
manifest.application.receiver.each {
addProcess(processNames,it)
addProcess(processNames, it)
}
}

@Override
void readProviders(Set<String> processNames) {
manifest.application.provider.each {
addProcess(processNames,it)
addProcess(processNames, it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package org.qiyi.video.svg.plugin.manifest

public interface IComponentReader {
interface IComponentReader {

void readActivities(Set<String> processNames)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
*/
package org.qiyi.video.svg.plugin.manifest

public interface IManifestParser {
interface IManifestParser {
Set<String> getCustomProcessNames(String manifestPath)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ public interface IServiceGenerator {
* @return
*/
Map<String,String>getMatchServices()

//其实是applicationId
String getPkgName()
}

This file was deleted.

Loading

0 comments on commit 53250fb

Please sign in to comment.