|
|
@@ -0,0 +1,57 @@
|
|
|
+package cn.seecoder.fdroidrepository.Pipeline;
|
|
|
+
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.ApplicationProperties;
|
|
|
+import cn.seecoder.fdroidrepository.DataObject.PO.BuildTaskPO;
|
|
|
+import cn.seecoder.fdroidrepository.Pipeline.Config.HandlerConfigTable;
|
|
|
+import cn.seecoder.fdroidrepository.Pipeline.Handlers.AbstractHandler;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class PipelineFactory {
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建流水线任务
|
|
|
+ * @param id 流水线任务的id,即BuildTaskPO的id
|
|
|
+ * @param projectName 构建出的应用名称
|
|
|
+ * @param buildTaskPO 对应的创建的构建任务
|
|
|
+ * @param applicationProperties 构建过程中需要的相关信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Pipeline init(Integer id, String projectName,
|
|
|
+ BuildTaskPO buildTaskPO,
|
|
|
+ ApplicationProperties applicationProperties) throws PipelineException {
|
|
|
+ Context context = Context.builder()
|
|
|
+ .pipelineId(id)
|
|
|
+ .projectName(projectName)
|
|
|
+ .applicationProperties(applicationProperties)
|
|
|
+ .build();
|
|
|
+ Handler firstHandler = initHandlerChain(buildTaskPO);
|
|
|
+ return new PipelineImpl(firstHandler, context);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建流水线Handler链
|
|
|
+ * @param buildTaskPO
|
|
|
+ * @return
|
|
|
+ * @throws PipelineException
|
|
|
+ */
|
|
|
+ public static Handler initHandlerChain(BuildTaskPO buildTaskPO) throws PipelineException {
|
|
|
+ Handler headHandler = new AbstractHandler() {
|
|
|
+ @Override
|
|
|
+ public void process(Context context) throws PipelineException {
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Handler current = headHandler;
|
|
|
+ List<String> handlers = buildTaskPO.getBuildType().getHandlers();
|
|
|
+ for (String key : handlers) {
|
|
|
+ Handler next = HandlerConfigTable.getHandler(key);
|
|
|
+ if (next != null) {
|
|
|
+ current.setNextHandler(next);
|
|
|
+ current = next;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return headHandler;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|