use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.
the class PackageAwbsTask method createAwbPackages.
/**
* 生成so的目录
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
final ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
final AtomicLong dexTotalTime = new AtomicLong(0);
final AtomicLong packageTotalTime = new AtomicLong(0);
final Map<String, Long[]> monitors = new HashMap<String, Long[]>();
long startTime = System.currentTimeMillis();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
long start = System.currentTimeMillis();
//create dex
File dexOutputFile = appVariantContext.getAwbDexOutput(awbBundle.getName());
emptyFolder(dexOutputFile);
// if some of our .jar input files exist, just reset the inputDir to null
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
List<File> inputFiles = new ArrayList<File>();
inputFiles.addAll(awbTransform.getInputFiles());
inputFiles.addAll(awbTransform.getInputLibraries());
if (null != awbTransform.getInputDir()) {
inputFiles.add(awbTransform.getInputDir());
}
AtlasBuildContext.androidBuilder.convertByteCode(inputFiles, dexOutputFile, appVariantContext.getVariantData().getVariantConfiguration().isMultiDexEnabled(), null, androidConfig.getDexOptions(), true, outputHandler);
//create package
long endDex = System.currentTimeMillis();
//PACKAGE APP:
File resourceFile = appVariantOutputContext.getAwbAndroidResourcesMap().get(awbBundle.getName()).getPackageOutputFile();
Set<File> dexFolders = new HashSet<File>();
dexFolders.add(dexOutputFile);
Set<File> jniFolders = Sets.newHashSet();
if (appVariantOutputContext.getAwbJniFolder(awbBundle) != null && appVariantOutputContext.getAwbJniFolder(awbBundle).exists()) {
jniFolders.add(appVariantOutputContext.getAwbJniFolder(awbBundle));
}
Set<File> javaResourcesLocations = Sets.newHashSet();
if (appVariantContext.getAtlasExtension().getTBuildConfig().getMergeAwbJavaRes()) {
javaResourcesLocations.addAll(awbBundle.getLibraryJars());
}
//getBuilder().packageCodeSplitApk();
getBuilder().oldPackageApk(resourceFile.getAbsolutePath(), dexFolders, javaResourcesLocations, jniFolders, null, getAbiFilters(), config.getBuildType().isJniDebuggable(), null, getOutputFile(awbBundle), config.getMinSdkVersion().getApiLevel(), new Predicate<String>() {
@Override
public boolean apply(@Nullable String s) {
return false;
}
});
long endPackage = System.currentTimeMillis();
dexTotalTime.addAndGet(endDex - start);
packageTotalTime.addAndGet(endPackage - endDex);
monitors.put(awbBundle.getName(), new Long[] { endDex - start, endPackage - endDex });
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("package " + awbBundle.getName() + " failed");
}
}
});
}
executorServicesHelper.execute(runnables);
if (getLogger().isInfoEnabled()) {
getLogger().info(">>>>> packageAwbs >>>>>>>>>>>>");
getLogger().info("totalTime is " + (System.currentTimeMillis() - startTime));
getLogger().info("dexTotalTime is " + dexTotalTime);
getLogger().info("packageTotalTime is " + packageTotalTime);
String format = "[packageawb] bundle:%50s dexTime: %10d packageTime: %10d ";
for (String bundle : monitors.keySet()) {
Long[] value = monitors.get(bundle);
getLogger().info(String.format(format, bundle, value[0], value[1]));
}
getLogger().info(">>>>> packageAwbs >>>>>>>>>>>>");
}
}
use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.
the class MtlParallelTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException {
if (null == parallelTask || parallelTask.isEmpty()) {
return;
}
if (concurrent) {
String taskName = uniqueTaskName;
if (StringUtils.isEmpty(taskName)) {
taskName = parallelTask.get(0).getClass().getSimpleName();
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final DefaultTask task : parallelTask) {
runnables.add(new Runnable() {
@Override
public void run() {
task.execute();
}
});
}
executorServicesHelper.execute(runnables);
} else {
for (final DefaultTask task : parallelTask) {
task.execute();
}
}
}
use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.
the class JavacAwbsTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
AwbJavaCompileConfigAction awbJavaCompileConfigAction = new AwbJavaCompileConfigAction(awbBundle, appVariantOutputContext);
JavaCompile awbJavaCompile = TaskCreater.create(getProject(), awbJavaCompileConfigAction.getName(), awbJavaCompileConfigAction.getType());
awbJavaCompileConfigAction.execute(awbJavaCompile);
awbJavaCompile.execute();
AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
awbTransform.setInputDir(awbJavaCompile.getDestinationDir());
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("javac " + awbBundle.getName() + " failed");
}
}
});
}
executorServicesHelper.execute(runnables);
}
use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.
the class PrepareAwbTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException, IOException, DocumentException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
Set<SoLibrary> soLibraries = androidDependencyTree.getALLSoLibDependencies();
for (final SoLibrary soLibrary : soLibraries) {
runnables.add(new Runnable() {
@Override
public void run() {
prepare(soLibrary.getSoLibFile(), soLibrary.getFolder(), false);
}
});
}
executorServicesHelper.execute(runnables);
runnables.clear();
List<AwbBundle> awbBundles = androidDependencyTree.getAwbBundles();
for (final AwbBundle awbBundle : awbBundles) {
runnables.add(new Runnable() {
@Override
public void run() {
prepare(awbBundle.getBundle(), awbBundle.getFolder(), true);
}
});
}
executorServicesHelper.execute(runnables);
runnables.clear();
Set<AarBundle> aarBundles = androidDependencyTree.getALLAarDependencies();
for (final AarBundle aarBundle : aarBundles) {
runnables.add(new Runnable() {
@Override
public void run() {
prepare(aarBundle.getBundle(), aarBundle.getFolder(), true);
}
});
}
executorServicesHelper.execute(runnables);
runnables.clear();
}
use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.
the class PreProcessManifestTask method preProcess.
@TaskAction
public void preProcess() throws IOException, DocumentException, InterruptedException {
getLogger().info("[MTLPlugin]Start PreProcess Lib manifest files,main manifestFile is:" + getMainManifestFile());
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("preProcessDex", getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
ManifestFileObject mainManifestFileObject = ManifestFileUtils.getManifestFileObject(mainManifestFile);
mainManifestFileObject.init();
for (File file : getLibraryManifests()) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
ManifestFileUtils.updatePreProcessManifestFile(file, mainManifestFileObject, true);
} catch (Throwable e) {
throw new GradleException("preprocess manifest", e);
}
}
});
}
executorServicesHelper.execute(runnables);
//ManifestFileUtils.preProcessManifests(getMainManifestFile(), getLibraryManifests(), true);
//BundleInfoUtils.setupAwbBundleInfos(appVariantOutputContext.getVariantContext());
//collectBundleInfo();
addAwbManifest2Merge();
}
Aggregations