修复任务记录删除失败的问题
优化网络连接状态获取的逻辑 修复配置文件的某些配置失效的问题 新增m3u8切片状态注解`@M3U8.onPeerStart`,`@M3U8.onPeerComplete`,`@M3U8.onPeerFail` 新增动态指定m3u8协议视频的下载功能(边下边播)
This commit is contained in:
@@ -17,6 +17,7 @@ package com.arialyy.compiler;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.annotations.M3U8;
|
||||
import com.arialyy.annotations.Upload;
|
||||
import com.google.auto.service.AutoService;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -85,6 +86,10 @@ import javax.lang.model.element.TypeElement;
|
||||
annotataions.add(Upload.onTaskRunning.class.getCanonicalName());
|
||||
annotataions.add(Upload.onTaskStart.class.getCanonicalName());
|
||||
annotataions.add(Upload.onTaskStop.class.getCanonicalName());
|
||||
// M3U8切片事件
|
||||
annotataions.add(M3U8.onPeerStart.class.getCanonicalName());
|
||||
annotataions.add(M3U8.onPeerComplete.class.getCanonicalName());
|
||||
annotataions.add(M3U8.onPeerFail.class.getCanonicalName());
|
||||
return annotataions;
|
||||
}
|
||||
|
||||
@@ -99,6 +104,7 @@ import javax.lang.model.element.TypeElement;
|
||||
mHandler.handleDownloadGroup(roundEnv);
|
||||
mHandler.handleDownloadGroupSub(roundEnv);
|
||||
mHandler.handleUpload(roundEnv);
|
||||
mHandler.handleM3U8(roundEnv);
|
||||
mHandler.createProxyFile();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.compiler;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.FieldSpec;
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/9/6.
|
||||
* 各类注解统计技术类
|
||||
*/
|
||||
@Deprecated final class CountFiler {
|
||||
private Filer mFiler;
|
||||
private ParamObtainUtil mPbUtil;
|
||||
|
||||
CountFiler(Filer filer, ParamObtainUtil pbUtil) {
|
||||
mFiler = filer;
|
||||
mPbUtil = pbUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每一种注解对应的统计类
|
||||
*/
|
||||
void createCountFile() throws IOException {
|
||||
Set<String> keys = mPbUtil.getListenerClass().keySet();
|
||||
if (keys.size() == 0) return;
|
||||
TypeSpec.Builder builder = TypeSpec.classBuilder(
|
||||
ProxyConstance.PROXY_COUNTER_NAME + UUID.randomUUID().toString().replace("-", ""))
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
|
||||
FieldSpec mappingField = FieldSpec.builder(
|
||||
ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class),
|
||||
ParameterizedTypeName.get(ClassName.get(Set.class), ClassName.get(String.class))),
|
||||
ProxyConstance.PROXY_COUNTER_MAP)
|
||||
.addModifiers(Modifier.PRIVATE)
|
||||
.initializer("new $T()", HashMap.class)
|
||||
.build();
|
||||
builder.addField(mappingField);
|
||||
|
||||
//增加构造函数
|
||||
CodeBlock.Builder cb = CodeBlock.builder();
|
||||
cb.add("Set<String> set = null;\n");
|
||||
for (String key : keys) {
|
||||
addTypeData(key, mPbUtil.getListenerClass().get(key), cb);
|
||||
}
|
||||
MethodSpec structure =
|
||||
MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addCode(cb.build()).build();
|
||||
builder.addMethod(structure);
|
||||
|
||||
builder.addMethod(
|
||||
createMethod(ProxyConstance.COUNT_METHOD_DOWNLOAD, ProxyConstance.COUNT_DOWNLOAD));
|
||||
builder.addMethod(
|
||||
createMethod(ProxyConstance.COUNT_METHOD_UPLOAD, ProxyConstance.COUNT_UPLOAD));
|
||||
builder.addMethod(createMethod(ProxyConstance.COUNT_METHOD_DOWNLOAD_GROUP,
|
||||
ProxyConstance.COUNT_DOWNLOAD_GROUP));
|
||||
builder.addMethod(createMethod(ProxyConstance.COUNT_METHOD_DOWNLOAD_GROUP_SUB,
|
||||
ProxyConstance.COUNT_DOWNLOAD_GROUP_SUB));
|
||||
|
||||
JavaFile jf = JavaFile.builder(ProxyConstance.PROXY_COUNTER_PACKAGE, builder.build()).build();
|
||||
createFile(jf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建不同任务类型的代理类集合
|
||||
*
|
||||
* @param key {@link ParamObtainUtil#addListenerMapping(String, String)}
|
||||
*/
|
||||
private MethodSpec createMethod(String methodName, String key) {
|
||||
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName);
|
||||
ParameterizedTypeName returnName =
|
||||
ParameterizedTypeName.get(ClassName.get(Set.class), ClassName.get(String.class));
|
||||
builder.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
||||
.returns(returnName)
|
||||
.addCode("return " + ProxyConstance.PROXY_COUNTER_MAP + ".get(\"" + key + "\");\n");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加每一种注解对应类
|
||||
*
|
||||
* @param type {@link ParamObtainUtil#addListenerMapping(String, String)}
|
||||
*/
|
||||
private void addTypeData(String type, Set<String> clsNames, CodeBlock.Builder cb) {
|
||||
if (clsNames == null || clsNames.isEmpty()) return;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("set = new $T();\n");
|
||||
for (String clsName : clsNames) {
|
||||
sb.append("set.add(\"").append(clsName).append("\");\n");
|
||||
}
|
||||
sb.append("typeMapping.put(\"").append(type).append("\", ").append("set);\n");
|
||||
cb.add(sb.toString(), ClassName.get(HashSet.class));
|
||||
}
|
||||
|
||||
private void createFile(JavaFile jf) throws IOException {
|
||||
//jf.writeTo(System.out);
|
||||
if (ProxyConstance.DEBUG) {
|
||||
// 如果需要在控制台打印生成的文件,则去掉下面的注释
|
||||
jf.writeTo(System.out);
|
||||
} else {
|
||||
jf.writeTo(mFiler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ package com.arialyy.compiler;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.annotations.M3U8;
|
||||
import com.arialyy.annotations.TaskEnum;
|
||||
import com.arialyy.annotations.Upload;
|
||||
import java.io.IOException;
|
||||
import javax.annotation.processing.Filer;
|
||||
@@ -113,7 +115,7 @@ class ElementHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理搜索到的上传注解F
|
||||
* 处理搜索到的上传注解
|
||||
*/
|
||||
void handleUpload(RoundEnvironment roundEnv) {
|
||||
mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onWait.class, ProxyConstance.WAIT);
|
||||
@@ -136,6 +138,18 @@ class ElementHandler {
|
||||
ProxyConstance.TASK_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理搜索到到m3u8切片注解
|
||||
*/
|
||||
void handleM3U8(RoundEnvironment roundEnv) {
|
||||
mPbUtil.saveMethod(TaskEnum.M3U8_PEER, roundEnv, M3U8.onPeerStart.class,
|
||||
ProxyConstance.TASK_START);
|
||||
mPbUtil.saveMethod(TaskEnum.M3U8_PEER, roundEnv, M3U8.onPeerComplete.class,
|
||||
ProxyConstance.TASK_COMPLETE);
|
||||
mPbUtil.saveMethod(TaskEnum.M3U8_PEER, roundEnv, M3U8.onPeerFail.class,
|
||||
ProxyConstance.TASK_FAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在build文件夹中生成代理文件
|
||||
*/
|
||||
@@ -150,6 +164,5 @@ class ElementHandler {
|
||||
|
||||
void clean() {
|
||||
mPbUtil.getMethodParams().clear();
|
||||
mPbUtil.getListenerClass().clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.compiler;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2019/6/25.
|
||||
* 实体信息
|
||||
*/
|
||||
enum EntityInfo {
|
||||
NORMAL("com.arialyy.aria.core.inf", "AbsNormalEntity"),
|
||||
DOWNLOAD("com.arialyy.aria.core.download", "DownloadEntity"),
|
||||
UPLOAD("com.arialyy.aria.core.upload", "UploadEntity");
|
||||
String pkg, className;
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public String getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pkg 包名
|
||||
* @param className 对应到任务类名
|
||||
*/
|
||||
EntityInfo(String pkg, String className) {
|
||||
this.pkg = pkg;
|
||||
this.className = className;
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,10 @@ package com.arialyy.compiler;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.annotations.M3U8;
|
||||
import com.arialyy.annotations.TaskEnum;
|
||||
import com.arialyy.annotations.Upload;
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.FieldSpec;
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
@@ -28,8 +29,6 @@ import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.Filer;
|
||||
@@ -87,18 +86,39 @@ final class EventProxyFiler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建代理方法
|
||||
* 创建M3u8切片的代理方法
|
||||
*
|
||||
* @param taskEnum 任务类型枚举{@link TaskEnum}
|
||||
* @param annotation {@link Download}、{@link Upload}、{@link M3U8}
|
||||
* @param methodInfo 被代理类注解的方法信息
|
||||
*/
|
||||
private MethodSpec createM3U8PeerMethod(TaskEnum taskEnum, Class<? extends Annotation> annotation,
|
||||
MethodInfo methodInfo) {
|
||||
|
||||
String sb = String.format("obj.%s(m3u8Url, peerPath, peerIndex);\n", methodInfo.methodName);
|
||||
|
||||
MethodSpec.Builder builder = MethodSpec.methodBuilder(annotation.getSimpleName())
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(void.class)
|
||||
.addParameter(String.class, "m3u8Url", Modifier.FINAL)
|
||||
.addParameter(String.class, "peerPath", Modifier.FINAL)
|
||||
.addParameter(int.class, "peerIndex", Modifier.FINAL)
|
||||
.addAnnotation(Override.class)
|
||||
.addCode(sb);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务的代理方法
|
||||
*
|
||||
* @param taskEnum 任务类型枚举{@link TaskEnum}
|
||||
* @param annotation {@link Download}、{@link Upload}
|
||||
* @param methodInfo 被代理类注解的方法信息
|
||||
*/
|
||||
private MethodSpec createProxyMethod(TaskEnum taskEnum, Class<? extends Annotation> annotation,
|
||||
private MethodSpec createTaskMethod(TaskEnum taskEnum, Class<? extends Annotation> annotation,
|
||||
MethodInfo methodInfo) {
|
||||
ClassName task = ClassName.get(taskEnum.getPkg(), taskEnum.getClassName());
|
||||
|
||||
ParameterSpec taskParam =
|
||||
ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build();
|
||||
ClassName task = ClassName.get(taskEnum.pkg, taskEnum.className);
|
||||
|
||||
String callCode;
|
||||
|
||||
@@ -125,26 +145,23 @@ final class EventProxyFiler {
|
||||
callCode = "task";
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("obj.")
|
||||
.append(methodInfo.methodName)
|
||||
.append("((")
|
||||
.append(taskEnum.getClassName())
|
||||
.append(")")
|
||||
.append(callCode)
|
||||
.append(");\n");
|
||||
|
||||
String sb = String.format("obj.%s((%s)%s);\n",
|
||||
methodInfo.methodName, taskEnum.className, callCode);
|
||||
|
||||
ParameterSpec taskParam =
|
||||
ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build();
|
||||
MethodSpec.Builder builder = MethodSpec.methodBuilder(annotation.getSimpleName())
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(void.class)
|
||||
.addParameter(taskParam)
|
||||
.addAnnotation(Override.class)
|
||||
.addCode(sb.toString());
|
||||
.addCode(sb);
|
||||
|
||||
//任务组接口
|
||||
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
|
||||
ClassName subTask =
|
||||
ClassName.get(TaskEnum.DOWNLOAD_ENTITY.pkg, TaskEnum.DOWNLOAD_ENTITY.className);
|
||||
ClassName.get(EntityInfo.DOWNLOAD.pkg, EntityInfo.DOWNLOAD.className);
|
||||
ParameterSpec subTaskParam =
|
||||
ParameterSpec.builder(subTask, "subEntity").addModifiers(Modifier.FINAL).build();
|
||||
|
||||
@@ -177,41 +194,22 @@ final class EventProxyFiler {
|
||||
//添加注解方法
|
||||
for (TaskEnum te : entity.methods.keySet()) {
|
||||
Map<Class<? extends Annotation>, MethodInfo> methodInfoMap = entity.methods.get(te);
|
||||
//if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD.proxySuffix)) {
|
||||
// type.add(1);
|
||||
//} else if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD_GROUP.proxySuffix)) {
|
||||
// type.add(2);
|
||||
//} else if (entity.proxyClassName.contains(TaskEnum.UPLOAD.proxySuffix)) {
|
||||
// type.add(3);
|
||||
//} else if (entity.proxyClassName.contains(TaskEnum.UPLOAD_GROUP.proxySuffix)) {
|
||||
// type.add(4);
|
||||
//}
|
||||
if (methodInfoMap != null) {
|
||||
for (Class<? extends Annotation> annotation : methodInfoMap.keySet()) {
|
||||
MethodSpec method = createProxyMethod(te, annotation, methodInfoMap.get(annotation));
|
||||
builder.addMethod(method);
|
||||
if (te == TaskEnum.DOWNLOAD
|
||||
|| te == TaskEnum.DOWNLOAD_GROUP
|
||||
|| te == TaskEnum.DOWNLOAD_GROUP_SUB
|
||||
|| te == TaskEnum.UPLOAD) {
|
||||
MethodSpec method = createTaskMethod(te, annotation, methodInfoMap.get(annotation));
|
||||
builder.addMethod(method);
|
||||
} else if (te == TaskEnum.M3U8_PEER) {
|
||||
MethodSpec method = createM3U8PeerMethod(te, annotation, methodInfoMap.get(annotation));
|
||||
builder.addMethod(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//注册当前类
|
||||
//for (Integer i : type) {
|
||||
// String str = null;
|
||||
// switch (i) {
|
||||
// case 1:
|
||||
// case 2:
|
||||
// str = "$T.download(obj).register();\n";
|
||||
// break;
|
||||
// case 3:
|
||||
// case 4:
|
||||
// str = "$T.upload(obj).register();\n";
|
||||
// break;
|
||||
// }
|
||||
// if (str != null) {
|
||||
// cb.add(str, ClassName.get("com.arialyy.aria.core", "Aria"));
|
||||
// }
|
||||
//}
|
||||
|
||||
MethodSpec structure = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).build();
|
||||
builder.addMethod(structure);
|
||||
|
||||
@@ -228,16 +226,29 @@ final class EventProxyFiler {
|
||||
builder.addJavadoc("该文件为Aria自动生成的代理文件,请不要修改该文件的任何代码!\n");
|
||||
|
||||
//创建父类参数
|
||||
ClassName superClass = ClassName.get("com.arialyy.aria.core.scheduler", "AbsSchedulerListener");
|
||||
//主任务泛型参数
|
||||
ClassName taskTypeVariable =
|
||||
ClassName.get(entity.mainTaskEnum.pkg, entity.mainTaskEnum.className);
|
||||
//子任务泛型参数
|
||||
ClassName subTaskTypeVariable =
|
||||
ClassName.get(entity.subTaskEnum.pkg, entity.subTaskEnum.className);
|
||||
ClassName superClass =
|
||||
ClassName.get("com.arialyy.aria.core.scheduler", entity.mainTaskEnum.proxySuperClass);
|
||||
|
||||
if (entity.mainTaskEnum == TaskEnum.DOWNLOAD
|
||||
|| entity.mainTaskEnum == TaskEnum.UPLOAD
|
||||
|| entity.mainTaskEnum == TaskEnum.DOWNLOAD_GROUP) {
|
||||
ClassName taskTypeVariable =
|
||||
ClassName.get(entity.mainTaskEnum.pkg, entity.mainTaskEnum.className);
|
||||
builder.superclass(ParameterizedTypeName.get(superClass, taskTypeVariable));
|
||||
} else if (entity.mainTaskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
|
||||
|
||||
ClassName taskTypeVariable =
|
||||
ClassName.get(entity.mainTaskEnum.pkg, entity.mainTaskEnum.className);
|
||||
//子任务泛型参数
|
||||
ClassName subTaskTypeVariable =
|
||||
ClassName.get(entity.subTaskEnum.pkg, entity.subTaskEnum.className);
|
||||
|
||||
builder.superclass(
|
||||
ParameterizedTypeName.get(superClass, taskTypeVariable, subTaskTypeVariable));
|
||||
} else if (entity.mainTaskEnum == TaskEnum.M3U8_PEER) {
|
||||
builder.superclass(superClass);
|
||||
}
|
||||
|
||||
builder.superclass(
|
||||
ParameterizedTypeName.get(superClass, taskTypeVariable, subTaskTypeVariable));
|
||||
builder.addMethod(listener);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.arialyy.compiler;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.annotations.TaskEnum;
|
||||
import com.arialyy.annotations.Upload;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collections;
|
||||
@@ -41,20 +42,12 @@ import javax.lang.model.util.Elements;
|
||||
*/
|
||||
class ParamObtainUtil {
|
||||
private Map<String, ProxyClassParam> mMethodParams = new HashMap<>();
|
||||
private Map<String, Set<String>> mListenerClass = new HashMap<>();
|
||||
private Elements mElementUtil;
|
||||
|
||||
ParamObtainUtil(Elements elements) {
|
||||
mElementUtil = elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要创建的代理类参数
|
||||
*/
|
||||
Map<String, Set<String>> getListenerClass() {
|
||||
return mListenerClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取搜索到的代理方法参数
|
||||
*/
|
||||
@@ -75,13 +68,17 @@ class ParamObtainUtil {
|
||||
PackageElement packageElement = mElementUtil.getPackageOf(classElement);
|
||||
|
||||
String methodName = method.getSimpleName().toString();
|
||||
String className = method.getEnclosingElement().toString(); //全类名\
|
||||
String className = method.getEnclosingElement().toString(); //全类名
|
||||
String key = className + taskEnum.proxySuffix;
|
||||
ProxyClassParam proxyEntity = mMethodParams.get(key);
|
||||
MethodInfo methodInfo = new MethodInfo();
|
||||
methodInfo.methodName = methodName;
|
||||
methodInfo.params = (List<VariableElement>) method.getParameters();
|
||||
checkMethod(taskEnum, method, annotationClazz, methodInfo.params);
|
||||
if (taskEnum == TaskEnum.M3U8_PEER) {
|
||||
checkM3U8PeerMethod(method, methodInfo.params);
|
||||
} else {
|
||||
checkTaskMethod(taskEnum, method, annotationClazz, methodInfo.params);
|
||||
}
|
||||
|
||||
if (proxyEntity == null) {
|
||||
proxyEntity = new ProxyClassParam();
|
||||
@@ -91,7 +88,7 @@ class ParamObtainUtil {
|
||||
proxyEntity.proxyClassName = proxyEntity.className + taskEnum.proxySuffix;
|
||||
proxyEntity.mainTaskEnum = taskEnum;
|
||||
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB || taskEnum == TaskEnum.DOWNLOAD_GROUP) {
|
||||
proxyEntity.subTaskEnum = TaskEnum.DOWNLOAD_ENTITY;
|
||||
proxyEntity.subTaskEnum = EntityInfo.DOWNLOAD;
|
||||
}
|
||||
mMethodParams.put(key, proxyEntity);
|
||||
}
|
||||
@@ -110,49 +107,52 @@ class ParamObtainUtil {
|
||||
* 获取注解的内容
|
||||
*/
|
||||
private Set<String> getValues(TaskEnum taskEnum, ExecutableElement method, int annotationType) {
|
||||
String clsName = method.getEnclosingElement().toString();
|
||||
String[] keys = null;
|
||||
switch (taskEnum) {
|
||||
case DOWNLOAD:
|
||||
keys = ValuesUtil.getDownloadValues(method, annotationType);
|
||||
addListenerMapping(clsName, ProxyConstance.COUNT_DOWNLOAD);
|
||||
break;
|
||||
case UPLOAD:
|
||||
keys = ValuesUtil.getUploadValues(method, annotationType);
|
||||
addListenerMapping(clsName, ProxyConstance.COUNT_UPLOAD);
|
||||
break;
|
||||
case DOWNLOAD_GROUP:
|
||||
keys = ValuesUtil.getDownloadGroupValues(method, annotationType);
|
||||
addListenerMapping(clsName, ProxyConstance.COUNT_DOWNLOAD_GROUP);
|
||||
break;
|
||||
case DOWNLOAD_GROUP_SUB:
|
||||
keys = ValuesUtil.getDownloadGroupSubValues(method, annotationType);
|
||||
addListenerMapping(clsName, ProxyConstance.COUNT_DOWNLOAD_GROUP_SUB);
|
||||
break;
|
||||
case M3U8_PEER:
|
||||
keys = ValuesUtil.getM3U8PeerValues(method, annotationType);
|
||||
break;
|
||||
}
|
||||
return keys == null ? null : convertSet(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加方法映射
|
||||
*
|
||||
* @param clsName 注解事件的类
|
||||
* @param key {@link ProxyConstance#COUNT_DOWNLOAD}、{@link ProxyConstance#COUNT_UPLOAD}、{@link
|
||||
* ProxyConstance#COUNT_DOWNLOAD_GROUP}、{@link ProxyConstance#COUNT_DOWNLOAD_GROUP_SUB}
|
||||
* 检查m3u8注解方法参数
|
||||
*/
|
||||
void addListenerMapping(String clsName, String key) {
|
||||
Set<String> cls = mListenerClass.get(key);
|
||||
if (cls == null) {
|
||||
cls = new HashSet<>();
|
||||
mListenerClass.put(key, cls);
|
||||
private void checkM3U8PeerMethod(ExecutableElement method, List<VariableElement> params) {
|
||||
String methodName = method.getSimpleName().toString();
|
||||
String className = method.getEnclosingElement().toString();
|
||||
Set<Modifier> modifiers = method.getModifiers();
|
||||
if (modifiers.contains(Modifier.PRIVATE)) {
|
||||
throw new IllegalAccessError(String.format("%s.%s, 不能为private方法", className, methodName));
|
||||
}
|
||||
|
||||
if (params.size() != 3
|
||||
|| !params.get(0).asType().toString().equals(String.class.getName())
|
||||
|| !params.get(1).asType().toString().equals(String.class.getName())
|
||||
|| !params.get(2).asType().toString().equals("int")) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s 的参数错误,该方法需要的参数为:String, String, int", className,
|
||||
methodName));
|
||||
}
|
||||
cls.add(clsName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查和下载相关的方法,如果被注解的方法为private或参数不合法,则抛异常
|
||||
* 检查任务注解的相关参数,如果被注解的方法为private或参数不合法或参数错误,停止任务
|
||||
*/
|
||||
private void checkMethod(TaskEnum taskEnum, ExecutableElement method,
|
||||
private void checkTaskMethod(TaskEnum taskEnum, ExecutableElement method,
|
||||
Class<? extends Annotation> annotationClazz, List<VariableElement> params) {
|
||||
String methodName = method.getSimpleName().toString();
|
||||
String className = method.getEnclosingElement().toString();
|
||||
@@ -162,7 +162,28 @@ class ParamObtainUtil {
|
||||
}
|
||||
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
|
||||
if (isFailAnnotation(annotationClazz)) {
|
||||
if (params.size() != 3 && params.size() != 2) {
|
||||
if (params.size() < 2 || params.size() > 3) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能是两个或三个,第一个参数是:%s,第二个参数是:%s,第三个参数(可选)是:%s", className,
|
||||
methodName,
|
||||
getCheckParams(taskEnum), getCheckSubParams(taskEnum),
|
||||
Exception.class.getSimpleName()));
|
||||
}
|
||||
|
||||
if (params.size() == 2
|
||||
&& (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))
|
||||
|| !params.get(1).asType().toString().equals(getCheckSubParams(taskEnum)))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能是两个或三个,第一个参数是:%s,第二个参数是:%s,第三个参数(可选)是:%s", className,
|
||||
methodName,
|
||||
getCheckParams(taskEnum), getCheckSubParams(taskEnum),
|
||||
Exception.class.getSimpleName()));
|
||||
}
|
||||
|
||||
if (params.size() == 3
|
||||
&& (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))
|
||||
|| !params.get(1).asType().toString().equals(getCheckSubParams(taskEnum))
|
||||
|| !params.get(2).asType().toString().equals(Exception.class.getName()))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能是两个或三个,第一个参数是:%s,第二个参数是:%s,第三个参数(可选)是:%s", className,
|
||||
methodName,
|
||||
@@ -170,39 +191,46 @@ class ParamObtainUtil {
|
||||
Exception.class.getSimpleName()));
|
||||
}
|
||||
} else {
|
||||
if (params.size() != 2) {
|
||||
if (params.size() == 2
|
||||
&& (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))
|
||||
|| !params.get(1).asType().toString().equals(getCheckSubParams(taskEnum)))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能是两个,第一个参数是:%s,第二个参数是:%s", className, methodName,
|
||||
String.format("%s.%s参数错误, 参数只能是两个或三个,第一个参数是:%s,第二个参数是:%s", className,
|
||||
methodName,
|
||||
getCheckParams(taskEnum), getCheckSubParams(taskEnum)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isFailAnnotation(annotationClazz)) {
|
||||
if (params.size() != 1 && params.size() != 2) {
|
||||
if (params.size() < 1 || params.size() > 2) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能有一个或两个,第一个参数是:%s,第二个参(可选)数是:%s", className, methodName,
|
||||
String.format("%s.%s参数错误, 参数只能有一个或两个,第一个参数是:%s,第二个参数(可选)是:%s", className, methodName,
|
||||
getCheckParams(taskEnum), Exception.class.getSimpleName()));
|
||||
}
|
||||
|
||||
if (params.size() == 1
|
||||
&& (!params.get(0).asType().toString().equals(getCheckParams(taskEnum)))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能有一个或两个,第一个参数是:%s,第二个参数(可选)是:%s", className, methodName,
|
||||
getCheckParams(taskEnum), Exception.class.getSimpleName()));
|
||||
}
|
||||
|
||||
if (params.size() == 2
|
||||
&& (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))
|
||||
|| !params.get(1).asType().toString().equals(Exception.class.getName()))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能有一个或两个,第一个参数是:%s,第二个参数(可选)是:%s", className, methodName,
|
||||
getCheckParams(taskEnum), Exception.class.getSimpleName()));
|
||||
}
|
||||
} else {
|
||||
if (params.size() != 1) {
|
||||
if (params.size() != 1
|
||||
&& !params.get(0).asType().toString().equals(getCheckParams(taskEnum))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数错误, 参数只能有一个,且参数必须是:%s", className, methodName,
|
||||
getCheckParams(taskEnum)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数【%s】类型错误,参数必须是:%s", className, methodName,
|
||||
params.get(0).getSimpleName(), getCheckParams(taskEnum)));
|
||||
}
|
||||
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
|
||||
if (!params.get(1).asType().toString().equals(getCheckSubParams(taskEnum))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("%s.%s参数【%s】类型错误,参数必须是:%s", className, methodName,
|
||||
params.get(0).getSimpleName(), getCheckSubParams(taskEnum)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +269,7 @@ class ParamObtainUtil {
|
||||
*/
|
||||
private String getCheckSubParams(TaskEnum taskEnum) {
|
||||
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
|
||||
return TaskEnum.DOWNLOAD_ENTITY.pkg + "." + TaskEnum.DOWNLOAD_ENTITY.className;
|
||||
return EntityInfo.DOWNLOAD.pkg + "." + EntityInfo.DOWNLOAD.className;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.compiler;
|
||||
|
||||
import com.arialyy.annotations.TaskEnum;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -44,7 +45,7 @@ class ProxyClassParam {
|
||||
/**
|
||||
* 子任务泛型参数
|
||||
*/
|
||||
TaskEnum subTaskEnum = TaskEnum.NORMAL_ENTITY;
|
||||
EntityInfo subTaskEnum = EntityInfo.NORMAL;
|
||||
|
||||
Set<TaskEnum> taskEnums;
|
||||
Map<String, Set<String>> keyMappings = new HashMap<>();
|
||||
|
||||
@@ -26,30 +26,6 @@ interface ProxyConstance {
|
||||
*/
|
||||
String SET_LISTENER = "setListener";
|
||||
|
||||
/**
|
||||
* 代理配置类
|
||||
*/
|
||||
String PROXY_COUNTER_PACKAGE = "com.arialyy.aria";
|
||||
/**
|
||||
* 代理分类统计
|
||||
*/
|
||||
String PROXY_COUNTER_NAME = "ProxyClassCounter";
|
||||
|
||||
/**
|
||||
* 代理分类统计映射表
|
||||
*/
|
||||
String PROXY_COUNTER_MAP = "typeMapping";
|
||||
|
||||
String COUNT_DOWNLOAD = "download";
|
||||
String COUNT_DOWNLOAD_GROUP = "downloadGroup";
|
||||
String COUNT_DOWNLOAD_GROUP_SUB = "downloadGroupSub";
|
||||
String COUNT_UPLOAD = "upload";
|
||||
|
||||
String COUNT_METHOD_DOWNLOAD = "getDownloadCounter";
|
||||
String COUNT_METHOD_DOWNLOAD_GROUP = "getDownloadGroupCounter";
|
||||
String COUNT_METHOD_DOWNLOAD_GROUP_SUB = "getDownloadGroupSubCounter";
|
||||
String COUNT_METHOD_UPLOAD = "getUploadCounter";
|
||||
|
||||
int WAIT = 0X10;
|
||||
int PRE = 0X11;
|
||||
int TASK_PRE = 0X12;
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.compiler;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/7/10.
|
||||
* 任务类型枚举
|
||||
*/
|
||||
enum TaskEnum {
|
||||
DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask",
|
||||
"$$DownloadListenerProxy"), DOWNLOAD_GROUP("com.arialyy.aria.core.download",
|
||||
"DownloadGroupTask", "$$DownloadGroupListenerProxy"), DOWNLOAD_GROUP_SUB(
|
||||
"com.arialyy.aria.core.download", "DownloadGroupTask", "$$DownloadGroupListenerProxy"), UPLOAD(
|
||||
"com.arialyy.aria.core.upload", "UploadTask", "$$UploadListenerProxy"), UPLOAD_GROUP(
|
||||
"com.arialyy.aria.core.upload", "UploadGroupTask",
|
||||
"$$UploadGroupListenerProxy"), NORMAL_ENTITY("com.arialyy.aria.core.inf", "AbsNormalEntity",
|
||||
""), DOWNLOAD_ENTITY("com.arialyy.aria.core.download", "DownloadEntity", "");
|
||||
|
||||
String pkg, className, proxySuffix;
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public String getProxySuffix() {
|
||||
return proxySuffix;
|
||||
}
|
||||
|
||||
public String getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pkg 包名
|
||||
* @param className 任务完整类名
|
||||
* @param proxySuffix 事件代理后缀
|
||||
*/
|
||||
TaskEnum(String pkg, String className, String proxySuffix) {
|
||||
this.pkg = pkg;
|
||||
this.className = className;
|
||||
this.proxySuffix = proxySuffix;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package com.arialyy.compiler;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.annotations.M3U8;
|
||||
import com.arialyy.annotations.Upload;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
|
||||
@@ -25,6 +26,26 @@ import javax.lang.model.element.ExecutableElement;
|
||||
* 获取注解value工具
|
||||
*/
|
||||
final class ValuesUtil {
|
||||
|
||||
/**
|
||||
* 获取m3u8切片注解信息
|
||||
*/
|
||||
static String[] getM3U8PeerValues(ExecutableElement method, int annotationType) {
|
||||
String[] values = null;
|
||||
switch (annotationType) {
|
||||
case ProxyConstance.TASK_START:
|
||||
values = method.getAnnotation(M3U8.onPeerStart.class).value();
|
||||
break;
|
||||
case ProxyConstance.TASK_COMPLETE:
|
||||
values = method.getAnnotation(M3U8.onPeerComplete.class).value();
|
||||
break;
|
||||
case ProxyConstance.TASK_FAIL:
|
||||
values = method.getAnnotation(M3U8.onPeerFail.class).value();
|
||||
break;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载任务组子任务的的注解数据
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user