use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runAaptCompiler.
private static MyExitStatus runAaptCompiler(@NotNull final CompileContext context, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) throws IOException {
boolean success = true;
boolean didSomething = false;
for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
final JpsModule module = entry.getKey();
final ModuleBuildTarget moduleTarget = new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION);
final AndroidAptStateStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidAptStateStorage.PROVIDER);
final MyModuleData moduleData = entry.getValue();
final JpsAndroidModuleExtension extension = moduleData.getAndroidExtension();
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, context.getProjectDescriptor().dataManager);
final File aptOutputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.AAPT_GENERATED_SOURCE_ROOT_NAME);
final IAndroidTarget target = moduleData.getPlatform().getTarget();
try {
final String[] resPaths = AndroidJpsUtil.collectResourceDirsForCompilation(extension, false, context, true);
if (resPaths.length == 0) {
// there is no resources in the module
if (!clearDirectoryIfNotEmpty(aptOutputDirectory, context, ANDROID_APT_COMPILER)) {
success = false;
}
continue;
}
final String packageName = moduleData.getPackage();
final File manifestFile;
if (extension.isLibrary() || !extension.isManifestMergingEnabled()) {
manifestFile = moduleData.getManifestFileForCompiler();
} else {
manifestFile = new File(AndroidJpsUtil.getPreprocessedManifestDirectory(module, context.getProjectDescriptor().dataManager.getDataPaths()), SdkConstants.FN_ANDROID_MANIFEST_XML);
}
if (isLibraryWithBadCircularDependency(extension)) {
if (!clearDirectoryIfNotEmpty(aptOutputDirectory, context, ANDROID_APT_COMPILER)) {
success = false;
}
continue;
}
final Map<JpsModule, String> packageMap = getDepLibPackages(module);
packageMap.put(module, packageName);
final JpsModule circularDepLibWithSamePackage = findCircularDependencyOnLibraryWithSamePackage(extension, packageMap);
if (circularDepLibWithSamePackage != null && !extension.isLibrary()) {
final String message = "Generated fields in " + packageName + ".R class in module '" + module.getName() + "' won't be final, because of circular dependency on module '" + circularDepLibWithSamePackage.getName() + "'";
context.processMessage(new CompilerMessage(ANDROID_APT_COMPILER, BuildMessage.Kind.WARNING, message));
}
final boolean generateNonFinalFields = extension.isLibrary() || circularDepLibWithSamePackage != null;
AndroidAptValidityState oldState;
try {
oldState = storage.getState(module.getName());
} catch (IOException e) {
LOG.info(e);
oldState = null;
}
final Map<String, ResourceFileData> resources = new HashMap<String, ResourceFileData>();
final TObjectLongHashMap<String> valueResFilesTimestamps = new TObjectLongHashMap<String>();
collectResources(resPaths, resources, valueResFilesTimestamps, oldState);
final List<ResourceEntry> manifestElements = collectManifestElements(manifestFile);
final List<Pair<String, String>> libRTextFilesAndPackages = new ArrayList<Pair<String, String>>(packageMap.size());
for (Map.Entry<JpsModule, String> entry1 : packageMap.entrySet()) {
final String libPackage = entry1.getValue();
if (!packageName.equals(libPackage)) {
final String libRTxtFilePath = new File(new File(AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, entry1.getKey()), R_TXT_OUTPUT_DIR_NAME), SdkConstants.FN_RESOURCE_TEXT).getPath();
libRTextFilesAndPackages.add(Pair.create(libRTxtFilePath, libPackage));
}
}
AndroidJpsUtil.collectRTextFilesFromAarDeps(module, libRTextFilesAndPackages);
final File outputDirForArtifacts = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
final String proguardOutputCfgFilePath;
if (AndroidJpsUtil.getProGuardConfigIfShouldRun(context, extension) != null) {
if (AndroidJpsUtil.createDirIfNotExist(outputDirForArtifacts, context, BUILDER_NAME) == null) {
success = false;
continue;
}
proguardOutputCfgFilePath = new File(outputDirForArtifacts, AndroidCommonUtils.PROGUARD_CFG_OUTPUT_FILE_NAME).getPath();
} else {
proguardOutputCfgFilePath = null;
}
String rTxtOutDirOsPath = null;
if (extension.isLibrary() || libRTextFilesAndPackages.size() > 0) {
final File rTxtOutDir = new File(outputDirForArtifacts, R_TXT_OUTPUT_DIR_NAME);
if (AndroidJpsUtil.createDirIfNotExist(rTxtOutDir, context, BUILDER_NAME) == null) {
success = false;
continue;
}
rTxtOutDirOsPath = rTxtOutDir.getPath();
}
final AndroidAptValidityState newState = new AndroidAptValidityState(resources, valueResFilesTimestamps, manifestElements, libRTextFilesAndPackages, packageName, proguardOutputCfgFilePath, rTxtOutDirOsPath, extension.isLibrary());
if (newState.equalsTo(oldState)) {
// we need to update state, because it also contains myValueResFilesTimestamps not taking into account by equalsTo()
storage.update(module.getName(), newState);
continue;
}
didSomething = true;
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aapt", module.getName())));
File tmpOutputDir = null;
try {
tmpOutputDir = FileUtil.createTempDirectory("android_apt_output", "tmp");
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.compile(target, -1, manifestFile.getPath(), packageName, tmpOutputDir.getPath(), resPaths, libRTextFilesAndPackages, generateNonFinalFields, proguardOutputCfgFilePath, rTxtOutDirOsPath, !extension.isLibrary());
AndroidJpsUtil.addMessages(context, messages, ANDROID_APT_COMPILER, module.getName());
if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
success = false;
storage.update(module.getName(), null);
} else {
if (!AndroidCommonUtils.directoriesContainSameContent(tmpOutputDir, aptOutputDirectory, JAVA_FILE_FILTER)) {
if (!deleteAndMarkRecursively(aptOutputDirectory, context, ANDROID_APT_COMPILER)) {
success = false;
continue;
}
final File parent = aptOutputDirectory.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_APT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", parent.getPath())));
success = false;
continue;
}
// we use copyDir instead of moveDirWithContent here, because tmp directory may be located on other disk and
// moveDirWithContent doesn't work for such case
FileUtil.copyDir(tmpOutputDir, aptOutputDirectory);
markDirtyRecursively(aptOutputDirectory, context, ANDROID_APT_COMPILER, true);
}
storage.update(module.getName(), newState);
}
} finally {
if (tmpOutputDir != null) {
FileUtil.delete(tmpOutputDir);
}
}
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_APT_COMPILER);
success = false;
}
}
if (!success) {
return MyExitStatus.FAIL;
} else if (didSomething) {
return MyExitStatus.OK;
}
return MyExitStatus.NOTHING_CHANGED;
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runBuildConfigGeneration.
private static MyExitStatus runBuildConfigGeneration(@NotNull CompileContext context, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) throws IOException {
boolean success = true;
boolean didSomething = false;
for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
final JpsModule module = entry.getKey();
final ModuleBuildTarget moduleTarget = new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION);
final AndroidBuildConfigStateStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidBuildConfigStateStorage.PROVIDER);
final MyModuleData moduleData = entry.getValue();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, context.getProjectDescriptor().dataManager);
final File outputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.BUILD_CONFIG_GENERATED_SOURCE_ROOT_NAME);
try {
if (extension == null || isLibraryWithBadCircularDependency(extension)) {
if (!clearDirectoryIfNotEmpty(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR)) {
success = false;
}
continue;
}
final String packageName = moduleData.getPackage();
final boolean debug = !AndroidJpsUtil.isReleaseBuild(context);
final Set<String> libPackages = new HashSet<String>(getDepLibPackages(module).values());
libPackages.remove(packageName);
final AndroidBuildConfigState newState = new AndroidBuildConfigState(packageName, libPackages, debug);
final AndroidBuildConfigState oldState = storage.getState(module.getName());
if (newState.equalsTo(oldState)) {
continue;
}
didSomething = true;
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.build.config", module.getName())));
// clear directory, because it may contain obsolete files (ex. if package name was changed)
if (!clearDirectory(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR)) {
success = false;
continue;
}
if (doBuildConfigGeneration(packageName, libPackages, debug, outputDirectory, context)) {
storage.update(module.getName(), newState);
markDirtyRecursively(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR, true);
} else {
storage.update(module.getName(), null);
success = false;
}
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_BUILD_CONFIG_GENERATOR);
success = false;
}
}
if (!success) {
return MyExitStatus.FAIL;
} else if (didSomething) {
return MyExitStatus.OK;
}
return MyExitStatus.NOTHING_CHANGED;
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage 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.incremental.messages.ProgressMessage in project android by JetBrains.
the class AndroidLibraryPackagingBuilder method doBuild.
private static boolean doBuild(CompileContext context, JpsModule module, BuildOutputConsumer outputConsumer) throws IOException {
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension == null || !extension.isLibrary()) {
return true;
}
File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
if (outputDir == null) {
return false;
}
final File classesDir = ProjectPaths.getModuleOutputDir(module, false);
if (classesDir == null || !classesDir.isDirectory()) {
return true;
}
final Set<String> subdirs = new HashSet<String>();
AndroidJpsUtil.addSubdirectories(classesDir, subdirs);
if (subdirs.size() > 0) {
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.library.packaging", module.getName())));
final File outputJarFile = new File(outputDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME);
final List<String> srcFiles;
try {
srcFiles = AndroidCommonUtils.packClassFilesIntoJar(ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.toStringArray(subdirs), outputJarFile);
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
return false;
}
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null && outputJarFile.isFile()) {
testingManager.getCommandExecutor().checkJarContent("library_package_jar", outputJarFile.getPath());
}
if (srcFiles.size() > 0) {
outputConsumer.registerOutputFile(outputJarFile, srcFiles);
}
}
return true;
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.
the class AndroidPreDexBuilder method doBuild.
private static boolean doBuild(@NotNull AndroidPreDexBuildTarget target, @NotNull DirtyFilesHolder<AndroidPreDexBuildTarget.MyRootDescriptor, AndroidPreDexBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws IOException, ProjectBuildException {
final List<Pair<File, String>> filesToPreDex = new ArrayList<Pair<File, String>>();
holder.processDirtyFiles(new FileProcessor<AndroidPreDexBuildTarget.MyRootDescriptor, AndroidPreDexBuildTarget>() {
@Override
public boolean apply(AndroidPreDexBuildTarget target, File file, AndroidPreDexBuildTarget.MyRootDescriptor root) throws IOException {
if (canBePreDexed(file) && file.isFile()) {
filesToPreDex.add(Pair.create(file, root.getModuleName()));
}
return true;
}
});
final JpsProject project = target.getProject();
AndroidPlatform platform = null;
for (JpsModule module : project.getModules()) {
if (AndroidJpsUtil.getExtension(module) != null) {
platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
break;
}
}
if (platform == null) {
return false;
}
if (!filesToPreDex.isEmpty()) {
final File outputDir = target.getOutputFile(context);
for (Pair<File, String> pair : filesToPreDex) {
context.checkCanceled();
final File srcFile = pair.getFirst();
final String moduleName = pair.getSecond();
final String srcFilePath = srcFile.getAbsolutePath();
final File outputFile;
if (moduleName != null) {
context.processMessage(new ProgressMessage("Pre-dex [" + moduleName + "]"));
outputFile = new File(new File(outputDir, moduleName), srcFile.getName());
} else {
context.processMessage(new ProgressMessage("Pre-dex: " + srcFile.getName()));
final String outputFileName = getOutputFileNameForExternalJar(srcFile);
if (outputFileName == null) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot pre-dex file " + srcFilePath + ": incorrect path", srcFilePath));
return false;
}
outputFile = new File(outputDir, outputFileName);
}
if (AndroidJpsUtil.createDirIfNotExist(outputFile.getParentFile(), context, BUILDER_NAME) == null) {
return false;
}
if (!AndroidDexBuilder.runDex(platform, outputFile.getPath(), new String[] { srcFilePath }, context, project, outputConsumer, BUILDER_NAME, srcFile.getName(), null)) {
return false;
}
}
}
return true;
}
Aggregations