use of org.jetbrains.android.util.AndroidCompilerMessageKind in project android by JetBrains.
the class AndroidDxWrapper method execute.
@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
public static Map<AndroidCompilerMessageKind, List<String>> execute(@NotNull Module module, @NotNull IAndroidTarget target, @NotNull String outputDir, @NotNull String[] compileTargets, @NotNull String additionalVmParams, int maxHeapSize, boolean optimize) {
BuildToolInfo buildToolInfo = target.getBuildToolInfo();
if (buildToolInfo == null) {
return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
}
String outFile = outputDir + File.separatorChar + AndroidCommonUtils.CLASSES_FILE_NAME;
final Map<AndroidCompilerMessageKind, List<String>> messages = new HashMap<AndroidCompilerMessageKind, List<String>>(2);
messages.put(AndroidCompilerMessageKind.ERROR, new ArrayList<String>());
messages.put(AndroidCompilerMessageKind.INFORMATION, new ArrayList<String>());
messages.put(AndroidCompilerMessageKind.WARNING, new ArrayList<String>());
String dxJarPath = buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR);
File dxJar = new File(dxJarPath);
if (!dxJar.isFile()) {
messages.get(AndroidCompilerMessageKind.ERROR).add(AndroidBundle.message("android.file.not.exist.error", dxJarPath));
return messages;
}
JavaParameters parameters = new JavaParameters();
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
// dex runs after simple java compilation, so JDK must be specified
assert sdk != null;
parameters.setJdk(sdk);
parameters.setMainClass(AndroidDxRunner.class.getName());
ParametersList programParamList = parameters.getProgramParametersList();
programParamList.add(dxJarPath);
programParamList.add(outFile);
programParamList.add("--optimize", Boolean.toString(optimize));
programParamList.addAll(compileTargets);
programParamList.add("--exclude");
ParametersList vmParamList = parameters.getVMParametersList();
if (additionalVmParams.length() > 0) {
vmParamList.addParametersString(additionalVmParams);
}
if (!AndroidCommonUtils.hasXmxParam(vmParamList.getParameters())) {
vmParamList.add("-Xmx" + maxHeapSize + "M");
}
final PathsList classPath = parameters.getClassPath();
classPath.add(PathUtil.getJarPathForClass(AndroidDxRunner.class));
classPath.add(PathUtil.getJarPathForClass(FileUtilRt.class));
// delete file to check if it will exist after dex compilation
if (!new File(outFile).delete()) {
LOG.info("Cannot delete file " + outFile);
}
Process process;
try {
parameters.setUseDynamicClasspath(true);
GeneralCommandLine commandLine = parameters.toCommandLine();
LOG.info(commandLine.getCommandLineString());
process = commandLine.createProcess();
AndroidCommonUtils.handleDexCompilationResult(process, commandLine.getCommandLineString(), outFile, messages, false);
} catch (ExecutionException e) {
messages.get(AndroidCompilerMessageKind.ERROR).add("ExecutionException: " + e.getMessage());
LOG.info(e);
return messages;
}
return messages;
}
use of org.jetbrains.android.util.AndroidCompilerMessageKind in project android by JetBrains.
the class AndroidApplicationArtifactProperties method onBuildFinished.
@Override
public void onBuildFinished(@NotNull Artifact artifact, @NotNull CompileContext context) {
if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
return;
}
if (mySigningMode != AndroidArtifactSigningMode.RELEASE_SIGNED && mySigningMode != AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
return;
}
final AndroidFacet facet = AndroidArtifactUtil.getPackagedFacet(context.getProject(), artifact);
if (facet == null) {
return;
}
final String artifactName = artifact.getName();
final String messagePrefix = "[Artifact '" + artifactName + "'] ";
final Module module = facet.getModule();
final AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform == null) {
context.addMessage(CompilerMessageCategory.ERROR, messagePrefix + AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
return;
}
final String sdkLocation = platform.getSdkData().getPath();
final String artifactFilePath = artifact.getOutputFilePath();
final String keyStorePath = myKeyStoreUrl != null ? VfsUtilCore.urlToPath(myKeyStoreUrl) : "";
final String keyStorePassword = myKeyStorePassword != null && myKeyStorePassword.length() > 0 ? getPlainKeystorePassword() : null;
final String keyPassword = myKeyPassword != null && myKeyPassword.length() > 0 ? getPlainKeyPassword() : null;
try {
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidCommonUtils.buildArtifact(artifactName, messagePrefix, sdkLocation, platform.getTarget(), artifactFilePath, keyStorePath, myKeyAlias, keyStorePassword, keyPassword);
AndroidCompileUtil.addMessages(context, AndroidCompileUtil.toCompilerMessageCategoryKeys(messages), null);
} catch (GeneralSecurityException e) {
AndroidCompileUtil.reportException(context, messagePrefix, e);
} catch (IOException e) {
AndroidCompileUtil.reportException(context, messagePrefix, e);
}
}
use of org.jetbrains.android.util.AndroidCompilerMessageKind in project android by JetBrains.
the class AndroidApt method compile.
public static Map<AndroidCompilerMessageKind, List<String>> compile(@NotNull IAndroidTarget target, int platformToolsRevision, @NotNull String manifestFileOsPath, @NotNull String aPackage, @NotNull String outDirOsPath, @NotNull String[] resourceDirsOsPaths, @NotNull List<Pair<String, String>> libRTxtFilesAndPackages, boolean nonConstantFields, @Nullable String proguardCfgOutputFileOsPath, @Nullable String rTxtOutDirOsPath, boolean optimizeRFile) throws IOException {
final Map<AndroidCompilerMessageKind, List<String>> messages = new HashMap<AndroidCompilerMessageKind, List<String>>();
messages.put(AndroidCompilerMessageKind.ERROR, new ArrayList<String>());
messages.put(AndroidCompilerMessageKind.INFORMATION, new ArrayList<String>());
final File outOsDir = new File(outDirOsPath);
if (!outOsDir.exists()) {
if (!outOsDir.mkdirs()) {
messages.get(AndroidCompilerMessageKind.ERROR).add("Unable to create directory " + outDirOsPath);
}
}
final String packageFolderOsPath = FileUtil.toSystemDependentName(outDirOsPath + '/' + aPackage.replace('.', '/'));
/* We actually need to delete the manifest.java as it may become empty and
in this case aapt doesn't generate an empty one, but instead doesn't
touch it */
final File manifestJavaFile = new File(packageFolderOsPath + File.separatorChar + AndroidCommonUtils.MANIFEST_JAVA_FILE_NAME);
if (manifestJavaFile.exists()) {
if (!FileUtil.delete(manifestJavaFile)) {
messages.get(AndroidCompilerMessageKind.ERROR).add("Unable to delete " + manifestJavaFile.getPath());
}
}
final File rJavaFile = new File(packageFolderOsPath + File.separatorChar + AndroidCommonUtils.R_JAVA_FILENAME);
if (rJavaFile.exists()) {
if (!FileUtil.delete(rJavaFile)) {
messages.get(AndroidCompilerMessageKind.ERROR).add("Unable to delete " + rJavaFile.getPath());
}
}
final File[] extraRJavaFiles = new File[libRTxtFilesAndPackages.size()];
for (int i = 0, n = libRTxtFilesAndPackages.size(); i < n; i++) {
final String libPackage = libRTxtFilesAndPackages.get(i).getSecond();
final String libPackageFolderOsPath = FileUtil.toSystemDependentName(outDirOsPath + '/' + libPackage.replace('.', '/'));
extraRJavaFiles[i] = new File(libPackageFolderOsPath + File.separatorChar + AndroidCommonUtils.R_JAVA_FILENAME);
}
for (File extraRJavaFile : extraRJavaFiles) {
if (extraRJavaFile.exists()) {
if (!FileUtil.delete(extraRJavaFile)) {
messages.get(AndroidCompilerMessageKind.ERROR).add("Unable to delete " + extraRJavaFile.getPath());
}
}
}
if (platformToolsRevision < 0 || platformToolsRevision > 7) {
Map<AndroidCompilerMessageKind, List<String>> map = doCompile(target, manifestFileOsPath, outDirOsPath, resourceDirsOsPaths, libRTxtFilesAndPackages, null, nonConstantFields, proguardCfgOutputFileOsPath, rTxtOutDirOsPath, optimizeRFile);
if (map.get(AndroidCompilerMessageKind.ERROR).isEmpty()) {
makeFieldsNotFinal(extraRJavaFiles);
}
AndroidExecutionUtil.addMessages(messages, map);
return messages;
} else {
messages.get(AndroidCompilerMessageKind.ERROR).add("'Platform Tools' package is out of date. Please update it through Android SDK manager");
return messages;
}
}
use of org.jetbrains.android.util.AndroidCompilerMessageKind in project android by JetBrains.
the class AndroidResourceCachingBuilder method runPngCaching.
private static boolean runPngCaching(AndroidResourceCachingBuildTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null;
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, AndroidJpsBundle.message("android.jps.progress.res.caching", module.getName())));
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
return false;
}
final File resCacheDir = target.getOutputDir(context);
// todo: probably it may be done automatically
if (context.getScope().isBuildForced(target) && resCacheDir.exists()) {
if (!FileUtil.delete(resCacheDir)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
if (!resCacheDir.exists()) {
if (!resCacheDir.mkdirs()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
final IAndroidTarget androidTarget = platform.getTarget();
final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
if (roots.size() == 0) {
return true;
}
final List<String> inputDirs = new ArrayList<String>();
for (BuildRootDescriptor root : roots) {
final File f = root.getRootFile();
if (f.exists()) {
inputDirs.add(f.getPath());
}
}
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.crunch(androidTarget, inputDirs, resCacheDir.getPath());
AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
if (success) {
final Map<String, File> outputFiles = new HashMap<String, File>();
FileUtil.processFilesRecursively(resCacheDir, new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile()) {
final String relativePath = FileUtil.getRelativePath(resCacheDir, file);
if (relativePath != null) {
outputFiles.put(relativePath, file);
}
}
return true;
}
});
for (Map.Entry<String, File> entry : outputFiles.entrySet()) {
final String relativePath = entry.getKey();
final File outputFile = entry.getValue();
for (String inputDir : inputDirs) {
final File srcFile = new File(inputDir, relativePath);
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(srcFile.getPath()));
}
}
}
return success;
}
use of org.jetbrains.android.util.AndroidCompilerMessageKind in project android by JetBrains.
the class AndroidResourcePackagingBuilder method doPackageResources.
private static boolean doPackageResources(@NotNull final CompileContext context, @NotNull File manifestFile, @NotNull IAndroidTarget target, @NotNull String[] resourceDirPaths, @NotNull String[] assetsDirPaths, @NotNull String outputPath, boolean releasePackage, @NotNull String moduleName, @NotNull BuildOutputConsumer outputConsumer, @Nullable String customManifestPackage, @Nullable String additionalParameters) {
try {
final IgnoredFileIndex ignoredFileIndex = context.getProjectDescriptor().getIgnoredFileIndex();
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.packageResources(target, -1, manifestFile.getPath(), resourceDirPaths, assetsDirPaths, outputPath, null, !releasePackage, 0, customManifestPackage, additionalParameters, new FileFilter() {
@Override
public boolean accept(File pathname) {
return !ignoredFileIndex.isIgnored(PathUtilRt.getFileName(pathname.getPath()));
}
});
AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, moduleName);
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).size() == 0;
if (success) {
final List<String> srcFiles = new ArrayList<String>();
srcFiles.add(manifestFile.getPath());
fillRecursively(resourceDirPaths, srcFiles);
fillRecursively(assetsDirPaths, srcFiles);
outputConsumer.registerOutputFile(new File(outputPath), srcFiles);
}
return success;
} catch (final IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
return false;
}
}
Aggregations