android-jps: place classes.jar into system/compiler-server storage

This commit is contained in:
Eugene Kudelevsky
2012-05-25 17:25:38 +04:00
parent e27808ec37
commit ceeaad8934
5 changed files with 54 additions and 56 deletions
@@ -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<String> externalLibraries = AndroidJpsUtil.getExternalLibraries(projectPaths, module, platform);
final Set<String> 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<String> classFilesDirs = new HashSet<String>();
final Set<String> libClassFilesDirs = new HashSet<String>();
final Set<String> outputDirs = new HashSet<String>();
@@ -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) {
@@ -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<String> getExternalLibraries(@NotNull ProjectPaths paths, @NotNull Module module, @NotNull AndroidPlatform platform) {
public static Set<String> getExternalLibraries(@NotNull CompileContext context,
@NotNull Module module,
@NotNull AndroidPlatform platform) {
final Set<String> result = new HashSet<String>();
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<String>(), false);
public static void processClasspath(@NotNull CompileContext context,
@NotNull Module module,
@NotNull AndroidDependencyProcessor processor) {
processClasspath(context, module, processor, new HashSet<String>(), false);
}
private static void processClasspath(@NotNull ProjectPaths paths,
@NotNull final Module module,
@NotNull final AndroidDependencyProcessor processor,
@NotNull final Set<String> visitedModules,
final boolean exportedLibrariesOnly) {
private static void processClasspath(@NotNull CompileContext context,
@NotNull final Module module,
@NotNull final AndroidDependencyProcessor processor,
@NotNull final Set<String> 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);
}
}
}
@@ -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);
@@ -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<String> externalJarsSet = AndroidJpsUtil.getExternalLibraries(paths, module, platform);
final Set<String> 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<String> assetsDirPaths = new ArrayList<String>();
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;
}
@@ -177,10 +177,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder {
private static boolean clearAndroidStorages(@NotNull CompileContext context, @NotNull Collection<Module> 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())));