use of org.jetbrains.jps.android.model.JpsAndroidDexCompilerConfiguration in project android by JetBrains.
the class AndroidDexBuilder method runDex.
public static boolean runDex(@NotNull AndroidPlatform platform, @NotNull String outFilePath, @NotNull String[] compileTargets, @NotNull CompileContext context, @NotNull JpsProject project, @NotNull BuildOutputConsumer outputConsumer, @NotNull String builderName, @NotNull String srcTargetName, @Nullable JpsModule module) throws IOException {
BuildToolInfo buildToolInfo = platform.getTarget().getBuildToolInfo();
if (buildToolInfo == null) {
return false;
}
final String dxJarPath = FileUtil.toSystemDependentName(buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR));
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
final File dxJar = new File(dxJarPath);
if (testingManager == null && !dxJar.isFile()) {
context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.find.file", dxJarPath)));
return false;
}
boolean multiDex = false;
if (module != null) {
JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension != null && extension.isMultiDexEnabled()) {
outFilePath = new File(outFilePath).getParent();
multiDex = true;
}
}
final List<String> programParamList = new ArrayList<String>();
programParamList.add(dxJarPath);
programParamList.add(outFilePath);
final JpsAndroidDexCompilerConfiguration configuration = JpsAndroidExtensionService.getInstance().getDexCompilerConfiguration(project);
final List<String> vmOptions;
if (configuration != null) {
vmOptions = new ArrayList<String>();
vmOptions.addAll(ParametersListUtil.parse(configuration.getVmOptions()));
if (!AndroidCommonUtils.hasXmxParam(vmOptions)) {
vmOptions.add("-Xmx" + configuration.getMaxHeapSize() + "M");
}
programParamList.addAll(Arrays.asList("--optimize", Boolean.toString(configuration.isOptimize())));
if (configuration.isForceJumbo()) {
programParamList.addAll(Arrays.asList("--forceJumbo", Boolean.TRUE.toString()));
}
if (configuration.isCoreLibrary()) {
programParamList.add("--coreLibrary");
}
} else {
vmOptions = Collections.singletonList("-Xmx1024M");
}
if (multiDex) {
JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension != null) {
programParamList.add("--multi-dex");
if (!StringUtil.isEmpty(extension.getMainDexList())) {
programParamList.add("--main-dex-list");
programParamList.add(extension.getMainDexList());
}
if (extension.isMinimalMainDex()) {
programParamList.add("--minimal-main-dex");
}
}
}
programParamList.addAll(Arrays.asList(compileTargets));
programParamList.add("--exclude");
final List<String> classPath = new ArrayList<String>();
classPath.add(ClasspathBootstrap.getResourcePath(AndroidDxRunner.class));
classPath.add(ClasspathBootstrap.getResourcePath(FileUtilRt.class));
final File outFile = new File(outFilePath);
if (outFile.exists() && !outFile.isDirectory() && !outFile.delete()) {
context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.WARNING, AndroidJpsBundle.message("android.jps.cannot.delete.file", outFilePath)));
}
final String javaExecutable = getJavaExecutable(platform, context, builderName);
if (javaExecutable == null) {
return false;
}
final List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(javaExecutable, AndroidDxRunner.class.getName(), Collections.<String>emptyList(), classPath, vmOptions, programParamList);
LOG.info(AndroidCommonUtils.command2string(commandLine));
final String[] commands = ArrayUtil.toStringArray(commandLine);
final Process process;
if (testingManager != null) {
process = testingManager.getCommandExecutor().createProcess(commands, Collections.<String, String>emptyMap());
} else {
process = Runtime.getRuntime().exec(commands);
}
final HashMap<AndroidCompilerMessageKind, List<String>> messages = new HashMap<AndroidCompilerMessageKind, List<String>>(3);
messages.put(AndroidCompilerMessageKind.ERROR, new ArrayList<String>());
messages.put(AndroidCompilerMessageKind.WARNING, new ArrayList<String>());
messages.put(AndroidCompilerMessageKind.INFORMATION, new ArrayList<String>());
AndroidCommonUtils.handleDexCompilationResult(process, StringUtil.join(commandLine, " "), outFilePath, messages, multiDex);
AndroidJpsUtil.addMessages(context, messages, builderName, srcTargetName);
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).size() == 0;
if (success) {
final List<String> srcFiles = new ArrayList<String>();
for (String compileTargetPath : compileTargets) {
final File compileTarget = new File(compileTargetPath);
if (compileTarget.isFile()) {
srcFiles.add(compileTargetPath);
} else if (compileTarget.isDirectory()) {
AndroidJpsUtil.processClassFilesAndJarsRecursively(compileTarget, new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile()) {
srcFiles.add(file.getPath());
}
return true;
}
});
}
}
outputConsumer.registerOutputFile(outFile, srcFiles);
}
return success;
}
use of org.jetbrains.jps.android.model.JpsAndroidDexCompilerConfiguration in project android by JetBrains.
the class AndroidDexBuilder method runProguardIfNecessary.
private static Pair<Boolean, AndroidProGuardStateStorage.MyState> runProguardIfNecessary(@NotNull JpsAndroidModuleExtension extension, @NotNull AndroidDexBuildTarget target, @NotNull AndroidPlatform platform, @NotNull CompileContext context, @NotNull String outputJarPath, @NotNull String[] proguardCfgPaths, boolean hasDirtyFiles, @Nullable AndroidProGuardStateStorage.MyState oldState) throws IOException {
final JpsModule module = extension.getModule();
final File[] proguardCfgFiles = new File[proguardCfgPaths.length];
for (int i = 0; i < proguardCfgFiles.length; i++) {
proguardCfgFiles[i] = new File(proguardCfgPaths[i]);
if (!proguardCfgFiles[i].exists()) {
context.processMessage(new CompilerMessage(PRO_GUARD_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.find.file", proguardCfgPaths[i])));
return null;
}
}
final File mainContentRoot = AndroidJpsUtil.getMainContentRoot(extension);
if (mainContentRoot == null) {
context.processMessage(new CompilerMessage(PRO_GUARD_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.main.content.root.not.found", module.getName())));
return null;
}
final String javaExecutable = getJavaExecutable(platform, context, PRO_GUARD_BUILDER_NAME);
if (javaExecutable == null) {
return null;
}
final File proguardLogsDir = extension.getProguardLogsDir();
final File logsDir;
if (proguardLogsDir != null) {
logsDir = proguardLogsDir;
} else {
logsDir = new File(mainContentRoot.getPath() + '/' + AndroidCommonUtils.DIRECTORY_FOR_LOGS_NAME);
}
final AndroidProGuardStateStorage.MyState newState = new AndroidProGuardStateStorage.MyState(proguardCfgFiles);
if (!hasDirtyFiles && newState.equals(oldState)) {
return Pair.create(false, null);
}
final List<String> classesDirs = new ArrayList<String>();
final List<String> libClassesDirs = new ArrayList<String>();
final List<String> externalJars = new ArrayList<String>();
final List<String> providedJars = new ArrayList<String>();
final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
for (BuildRootDescriptor root : roots) {
final File rootFile = root.getRootFile();
if (!rootFile.exists()) {
continue;
}
if (root instanceof AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) {
final AndroidDexBuildTarget.ClassesDirType type = ((AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) root).getClassesDirType();
if (type == AndroidDexBuildTarget.ClassesDirType.JAVA || type == AndroidDexBuildTarget.ClassesDirType.ANDROID_APP) {
AndroidJpsUtil.addSubdirectories(rootFile, classesDirs);
} else {
AndroidJpsUtil.addSubdirectories(rootFile, libClassesDirs);
}
} else if (root instanceof AndroidDexBuildTarget.MyJarBuildRootDescriptor) {
final AndroidDexBuildTarget.MyJarBuildRootDescriptor jarRoot = (AndroidDexBuildTarget.MyJarBuildRootDescriptor) root;
if (!jarRoot.isLibPackage() && !jarRoot.isPreDexed()) {
externalJars.add(rootFile.getPath());
}
} else if (root instanceof AndroidDexBuildTarget.MyProvidedJarBuildRootDescriptor) {
providedJars.add(rootFile.getPath());
}
}
final String[] classFilesDirOsPaths = ArrayUtil.toStringArray(classesDirs);
final String[] libClassFilesDirOsPaths = ArrayUtil.toStringArray(libClassesDirs);
final String[] externalJarOsPaths = ArrayUtil.toStringArray(externalJars);
final String[] providedJarOsPaths = ArrayUtil.toStringArray(providedJars);
final String inputJarOsPath = AndroidCommonUtils.buildTempInputJar(classFilesDirOsPaths, libClassFilesDirOsPaths);
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null) {
testingManager.getCommandExecutor().checkJarContent("proguard_input_jar", inputJarOsPath);
}
if (!logsDir.exists()) {
if (!logsDir.mkdirs()) {
context.processMessage(new CompilerMessage(PRO_GUARD_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", FileUtil.toSystemDependentName(logsDir.getPath()))));
return null;
}
}
final JpsAndroidDexCompilerConfiguration configuration = JpsAndroidExtensionService.getInstance().getDexCompilerConfiguration(module.getProject());
String proguardVmOptions = configuration != null ? configuration.getProguardVmOptions() : null;
if (proguardVmOptions == null) {
proguardVmOptions = "";
}
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.proguard", module.getName())));
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidCommonUtils.launchProguard(platform.getTarget(), platform.getSdkToolsRevision(), platform.getSdk().getHomePath(), javaExecutable, proguardVmOptions, proguardCfgPaths, inputJarOsPath, externalJarOsPaths, providedJarOsPaths, outputJarPath, logsDir.getPath());
AndroidJpsUtil.addMessages(context, messages, PRO_GUARD_BUILDER_NAME, module.getName());
return messages.get(AndroidCompilerMessageKind.ERROR).isEmpty() ? Pair.create(true, newState) : null;
}
use of org.jetbrains.jps.android.model.JpsAndroidDexCompilerConfiguration in project android by JetBrains.
the class AndroidDexBuildTarget method writeConfiguration.
@Override
public void writeConfiguration(ProjectDescriptor pd, PrintWriter out) {
super.writeConfiguration(pd, out);
final JpsAndroidDexCompilerConfiguration c = JpsAndroidExtensionService.getInstance().getDexCompilerConfiguration(getModule().getProject());
if (c != null) {
out.println(c.getVmOptions());
out.println(c.getMaxHeapSize());
out.println(c.isOptimize());
out.println(c.isForceJumbo());
out.println(c.isCoreLibrary());
out.println(c.getProguardVmOptions());
}
}
Aggregations