-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge internal:refactor refer-checker,add ByteXBuildListener
- Loading branch information
yangzhiqian
committed
Aug 31, 2020
1 parent
4fa5445
commit b367178
Showing
38 changed files
with
1,765 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
common/src/main/java/com/ss/android/ugc/bytex/common/builder/ByteXBuildListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.ss.android.ugc.bytex.common.builder; | ||
|
||
import com.android.build.api.transform.Transform; | ||
import com.android.build.api.transform.TransformInvocation; | ||
import com.ss.android.ugc.bytex.common.IPlugin; | ||
import com.ss.android.ugc.bytex.common.flow.TransformFlowListener; | ||
|
||
import org.gradle.api.Project; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/8/26<br/> | ||
* Desc: | ||
*/ | ||
public interface ByteXBuildListener extends TransformFlowListener { | ||
void onByteXPluginApply(Project project, IPlugin plugin); | ||
|
||
void onByteXPluginApplied(IPlugin plugin); | ||
|
||
void onProjectBuildStart(Project project); | ||
|
||
void onByteXPluginTransformStart(Transform transform, TransformInvocation transformInvocation); | ||
|
||
void onByteXPluginStart(IPlugin plugin); | ||
|
||
void onByteXPluginFinished(IPlugin plugin); | ||
|
||
void onByteXPluginTransformFinished(Transform transform, @Nullable Exception exception); | ||
|
||
void onProjectBuildFinished(Project project, @Nullable Throwable throwable); | ||
} |
44 changes: 44 additions & 0 deletions
44
common/src/main/java/com/ss/android/ugc/bytex/common/builder/ByteXBuildListenerManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.ss.android.ugc.bytex.common.builder | ||
|
||
import com.android.build.gradle.internal.utils.toImmutableList | ||
import com.ss.android.ugc.bytex.common.builder.internal.DefaultByteXBuildListener | ||
import com.ss.android.ugc.bytex.common.flow.main.MainProcessHandlerListener | ||
import com.ss.android.ugc.bytex.common.flow.main.MainProcessHandlerListenerManager | ||
import java.util.* | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/8/26<br/> | ||
*/ | ||
object ByteXBuildListenerManager { | ||
private val listeners: MutableList<ByteXBuildListener> = LinkedList() | ||
|
||
init { | ||
registerByteXBuildListener(DefaultByteXBuildListener) | ||
registerMainProcessHandlerListener(DefaultByteXBuildListener) | ||
} | ||
|
||
@Synchronized | ||
fun registerByteXBuildListener(listener: ByteXBuildListener) { | ||
if (listener !in listeners) { | ||
listeners.add(listener) | ||
} | ||
} | ||
|
||
@Synchronized | ||
fun unRegisterByteXBuildListener(listener: ByteXBuildListener) { | ||
listeners.remove(listener) | ||
} | ||
|
||
fun registerMainProcessHandlerListener(listener: MainProcessHandlerListener) { | ||
MainProcessHandlerListenerManager.registerMainProcessHandlerListener(listener) | ||
} | ||
|
||
fun unregisterMainProcessHandlerListener(listener: MainProcessHandlerListener) { | ||
MainProcessHandlerListenerManager.unregisterMainProcessHandlerListener(listener) | ||
} | ||
|
||
@Synchronized | ||
internal fun getByteXBuildListeners(): List<ByteXBuildListener> { | ||
return listeners.toImmutableList() | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
common/src/main/java/com/ss/android/ugc/bytex/common/builder/internal/BuildRecorder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.ss.android.ugc.bytex.common.builder.internal | ||
|
||
import com.google.common.reflect.TypeToken | ||
import com.google.gson.GsonBuilder | ||
import com.ss.android.ugc.bytex.common.IPlugin | ||
import org.gradle.api.Project | ||
import org.gradle.util.GFileUtils | ||
import java.io.File | ||
import java.io.FileWriter | ||
import java.util.* | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/8/27<br/> | ||
*/ | ||
internal class BuildRecorder { | ||
private val gson = GsonBuilder().setPrettyPrinting().create() | ||
private lateinit var outputDir: File | ||
private val transformInfoRecords = LinkedList<TransformInfoRecord>() | ||
fun start(project: Project) { | ||
outputDir = File(project.buildDir, "ByteX/build") | ||
// GFileUtils.deleteDirectory(outputDir) | ||
outputDir.mkdirs() | ||
} | ||
|
||
fun recordTransform(transformInfo: DefaultByteXBuildListener.TransformInfo, pluginStatuses: Map<IPlugin, PluginStatus>) { | ||
transformInfoRecords.add(TransformInfoRecord(transformInfo, pluginStatuses)) | ||
} | ||
|
||
fun recordPluginStatuses(pluginStatuses: Collection<PluginStatus>) { | ||
val file = File(outputDir, "pluginStatuses.json") | ||
if (!file.exists()) { | ||
file.parentFile.mkdirs() | ||
} | ||
FileWriter(file).use { | ||
gson.toJson(pluginStatuses.sorted(), object : TypeToken<List<PluginStatus>>() {}.type, it) | ||
} | ||
} | ||
|
||
fun stop() { | ||
val file = File(outputDir, "transformInfo.json") | ||
if (!file.exists()) { | ||
file.parentFile.mkdirs() | ||
} | ||
FileWriter(file).use { | ||
gson.toJson(transformInfoRecords, object : TypeToken<List<TransformInfoRecord>>() {}.type, it) | ||
} | ||
transformInfoRecords.clear() | ||
} | ||
|
||
|
||
private class TransformInfoRecord(transformInfo: DefaultByteXBuildListener.TransformInfo, pluginStatuses: Map<IPlugin, PluginStatus>) { | ||
val name = transformInfo.transform.name | ||
val className = transformInfo.transform::class.java.name | ||
val taskName = transformInfo.getTaskName() | ||
var startTime = transformInfo.startTime | ||
var endTime = transformInfo.endTime | ||
var exception = transformInfo.exception?.message | ||
var flowInfos = transformInfo.flowInfos.values.map { TransformFlowInfoRecord(it, pluginStatuses) }.sortedBy { | ||
it.startRunningTime | ||
} | ||
|
||
class TransformFlowInfoRecord(flowInfo: DefaultByteXBuildListener.TransformFlowInfo, pluginStatuses: Map<IPlugin, PluginStatus>) { | ||
val handlers = flowInfo.handlers.map { it.value } | ||
val plugins = flowInfo.plugins.map { pluginStatuses[it]!! } | ||
var startPrepareTime = flowInfo.startPrepareTime | ||
var finishPrepareTime = flowInfo.finishPrepareTime | ||
var startRunningTime = flowInfo.startRunningTime | ||
var finishRunningTime = flowInfo.finishRunningTime | ||
} | ||
} | ||
} |
Oops, something went wrong.