diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java index 206848243705..412989ddb4fa 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java @@ -110,7 +110,8 @@ public class AndroidDexBuilder extends ProjectLevelBuilder { } final ProjectPaths projectPaths = context.getProjectPaths(); - final File dexOutputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module, true, BUILDER_NAME); + File dexOutputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module); + dexOutputDir = AndroidJpsUtil.createDirIfNotExist(dexOutputDir, context, BUILDER_NAME); if (dexOutputDir == null) { success = false; continue; @@ -122,7 +123,7 @@ public class AndroidDexBuilder extends ProjectLevelBuilder { .message("android.jps.warnings.dex.no.compiled.files", module.getName()))); continue; } - final Set externalLibraries = AndroidJpsUtil.getExternalLibraries(projectPaths, module, platform); + final Set externalLibraries = AndroidJpsUtil.getExternalLibraries(context, module, platform); boolean includeSystemProguardCfg = false; String proguardCfgPath = context.getBuilderParameter(AndroidCommonUtils.PROGUARD_CFG_PATH_OPTION); @@ -172,7 +173,7 @@ public class AndroidDexBuilder extends ProjectLevelBuilder { fileSet.addAll(externalLibraries); jars.addAll(externalLibraries); - AndroidJpsUtil.processClasspath(projectPaths, module, new AndroidDependencyProcessor() { + AndroidJpsUtil.processClasspath(context, module, new AndroidDependencyProcessor() { @Override public void processExternalLibrary(@NotNull File file) { fileSet.add(file.getPath()); @@ -369,7 +370,6 @@ public class AndroidDexBuilder extends ProjectLevelBuilder { return false; } - final ProjectPaths paths = context.getProjectPaths(); final Set classFilesDirs = new HashSet(); final Set libClassFilesDirs = new HashSet(); final Set outputDirs = new HashSet(); @@ -377,7 +377,7 @@ public class AndroidDexBuilder extends ProjectLevelBuilder { AndroidJpsUtil.addSubdirectories(classesDir, classFilesDirs); outputDirs.add(classesDir.getPath()); - AndroidJpsUtil.processClasspath(paths, module, new AndroidDependencyProcessor() { + AndroidJpsUtil.processClasspath(context, module, new AndroidDependencyProcessor() { @Override public void processAndroidLibraryOutputDirectory(@NotNull File dir) { diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java index 19de15164b06..746f5ab387a4 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidJpsUtil.java @@ -143,23 +143,19 @@ class AndroidJpsUtil { return result; } - @Nullable + @NotNull public static File getDirectoryForIntermediateArtifacts(@NotNull CompileContext context, - @NotNull Module module, - boolean createIfNotExist, - @NotNull String compilerName) { + @NotNull Module module) { final File androidStorage = new File(context.getDataManager().getDataStorageRoot(), ANDROID_STORAGE_DIR); - final File dir = new File(new File(androidStorage, INTERMEDIATE_ARTIFACTS_STORAGE), module.getName()); + return new File(new File(androidStorage, INTERMEDIATE_ARTIFACTS_STORAGE), module.getName()); + } + @Nullable + public static File createDirIfNotExist(@NotNull File dir, @NotNull CompileContext context, @NotNull String compilerName) { if (!dir.exists()) { - if (createIfNotExist) { - if (!dir.mkdirs()) { - context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, - AndroidJpsBundle.message("android.jps.cannot.create.directory", dir.getPath()))); - return null; - } - } - else { + if (!dir.mkdirs()) { + context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, + AndroidJpsBundle.message("android.jps.cannot.create.directory", dir.getPath()))); return null; } } @@ -186,7 +182,9 @@ class AndroidJpsUtil { } @NotNull - public static Set getExternalLibraries(@NotNull ProjectPaths paths, @NotNull Module module, @NotNull AndroidPlatform platform) { + public static Set getExternalLibraries(@NotNull CompileContext context, + @NotNull Module module, + @NotNull AndroidPlatform platform) { final Set result = new HashSet(); final AndroidDependencyProcessor processor = new AndroidDependencyProcessor() { @Override @@ -199,7 +197,7 @@ class AndroidJpsUtil { return type == AndroidDependencyType.EXTERNAL_LIBRARY; } }; - processClasspath(paths, module, processor); + processClasspath(context, module, processor); addAnnotationsJarIfNecessary(platform, result); return result; } @@ -215,18 +213,21 @@ class AndroidJpsUtil { } } - public static void processClasspath(@NotNull ProjectPaths paths, @NotNull Module module, @NotNull AndroidDependencyProcessor processor) { - processClasspath(paths, module, processor, new HashSet(), false); + public static void processClasspath(@NotNull CompileContext context, + @NotNull Module module, + @NotNull AndroidDependencyProcessor processor) { + processClasspath(context, module, processor, new HashSet(), false); } - private static void processClasspath(@NotNull ProjectPaths paths, - @NotNull final Module module, - @NotNull final AndroidDependencyProcessor processor, - @NotNull final Set visitedModules, - final boolean exportedLibrariesOnly) { + private static void processClasspath(@NotNull CompileContext context, + @NotNull final Module module, + @NotNull final AndroidDependencyProcessor processor, + @NotNull final Set visitedModules, + final boolean exportedLibrariesOnly) { if (!visitedModules.add(module.getName())) { return; } + final ProjectPaths paths = context.getProjectPaths(); if (processor.isToProcess(AndroidDependencyType.EXTERNAL_LIBRARY)) { for (ClasspathItem item : module.getClasspath(ClasspathKind.PRODUCTION_RUNTIME, exportedLibrariesOnly)) { @@ -256,25 +257,29 @@ class AndroidJpsUtil { final boolean depLibrary = depFacet != null && depFacet.isLibrary(); final File depClassDir = paths.getModuleOutputDir(depModule, false); - if (depClassDir != null) { - if (depLibrary) { - if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_PACKAGE)) { - final File packagedClassesJar = new File(depClassDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME); + if (depLibrary) { + if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_PACKAGE)) { + final File intArtifactsDir = getDirectoryForIntermediateArtifacts(context, depModule); + final File packagedClassesJar = new File(intArtifactsDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME); - if (packagedClassesJar.isFile()) { - processor.processAndroidLibraryPackage(packagedClassesJar); - } + if (packagedClassesJar.isFile()) { + processor.processAndroidLibraryPackage(packagedClassesJar); } - if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_OUTPUT_DIRECTORY)) { + } + if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_OUTPUT_DIRECTORY)) { + if (depClassDir != null && depClassDir.isDirectory()) { processor.processAndroidLibraryOutputDirectory(depClassDir); } } - else if (processor.isToProcess(AndroidDependencyType.JAVA_MODULE_OUTPUT_DIR) && depFacet == null && depClassDir.isDirectory()) { - // do not support android-app->android-app compile dependencies - processor.processJavaModuleOutputDirectory(depClassDir); - } } - processClasspath(paths, depModule, processor, visitedModules, !depLibrary || exportedLibrariesOnly); + else if (processor.isToProcess(AndroidDependencyType.JAVA_MODULE_OUTPUT_DIR) && + depFacet == null && + depClassDir != null && + depClassDir.isDirectory()) { + // do not support android-app->android-app compile dependencies + processor.processJavaModuleOutputDirectory(depClassDir); + } + processClasspath(context, depModule, processor, visitedModules, !depLibrary || exportedLibrariesOnly); } } } diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java index bb7a5de6b39b..ef0c0a770bb3 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java @@ -11,8 +11,6 @@ import org.jetbrains.jps.incremental.BuilderCategory; import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.ModuleLevelBuilder; import org.jetbrains.jps.incremental.ProjectBuildException; -import org.jetbrains.jps.incremental.messages.BuildMessage; -import org.jetbrains.jps.incremental.messages.CompilerMessage; import org.jetbrains.jps.incremental.messages.ProgressMessage; import java.io.File; @@ -54,11 +52,9 @@ public class AndroidLibraryPackagingBuilder extends ModuleLevelBuilder { } final ProjectPaths projectPaths = context.getProjectPaths(); - final File outputDirectoryForPackagedFiles = AndroidJpsUtil.getDirectoryForFinalPackage(projectPaths, module); - - if (outputDirectoryForPackagedFiles == null) { - context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle - .message("android.jps.errors.output.dir.not.specified", module.getName()))); + File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module); + outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME); + if (outputDir == null) { success = false; continue; } @@ -80,7 +76,7 @@ public class AndroidLibraryPackagingBuilder extends ModuleLevelBuilder { if (subdirs.size() > 0) { context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.library.packaging", module.getName()))); - final File outputJarFile = new File(outputDirectoryForPackagedFiles, AndroidCommonUtils.CLASSES_JAR_FILE_NAME); + final File outputJarFile = new File(outputDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME); doneSomething = true; try { AndroidCommonUtils.packClassFilesIntoJar(ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.toStringArray(subdirs), outputJarFile); diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java index d63bf2bd4b6c..8867687286da 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java @@ -333,8 +333,7 @@ public class AndroidPackagingBuilder extends ProjectLevelBuilder { final String[] sourceRoots = AndroidJpsUtil.toPaths(AndroidJpsUtil.getSourceRootsForModuleAndDependencies(module)); final ProjectPaths paths = context.getProjectPaths(); - final File intArtifactsDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module, false, BUILDER_NAME); - assert intArtifactsDir != null; + final File intArtifactsDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module); final File outputDir = AndroidJpsUtil.getDirectoryForFinalPackage(paths, module); if (outputDir == null) { @@ -348,7 +347,7 @@ public class AndroidPackagingBuilder extends ProjectLevelBuilder { return false; } - final Set externalJarsSet = AndroidJpsUtil.getExternalLibraries(paths, module, platform); + final Set externalJarsSet = AndroidJpsUtil.getExternalLibraries(context, module, platform); final File resPackage = getPackagedResourcesFile(module, intArtifactsDir); final File classesDexFile = new File(intArtifactsDir.getPath(), AndroidCommonUtils.CLASSES_FILE_NAME); @@ -477,7 +476,8 @@ public class AndroidPackagingBuilder extends ProjectLevelBuilder { final ArrayList assetsDirPaths = new ArrayList(); collectAssetDirs(facet, assetsDirPaths); - final File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module, true, BUILDER_NAME); + File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module); + outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME); if (outputDir == null) { return false; } diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java index e33d147e23b0..de9770c665f8 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java @@ -177,10 +177,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder { private static boolean clearAndroidStorages(@NotNull CompileContext context, @NotNull Collection modules) { for (Module module : modules) { - final File dir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module, false, BUILDER_NAME); - if (dir == null) { - return true; - } + final File dir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module); if (dir.exists() && !FileUtil.delete(dir)) { context.processMessage( new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.delete", dir.getPath())));