use of org.jetbrains.jps.android.model.JpsAndroidModuleExtension in project android by JetBrains.
the class AndroidAarDepsBuilder method doBuild.
private static boolean doBuild(final CompileContext context, AndroidAarDepsBuildTarget target, BuildOutputConsumer outputConsumer) {
final JpsModule module = target.getModule();
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 List<String> srcJarFiles = new ArrayList<String>();
for (BuildRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
final File file = descriptor.getRootFile();
if (file.exists()) {
srcJarFiles.add(file.getPath());
}
}
if (srcJarFiles.size() == 0) {
return true;
}
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aar.dependencies.packaging", module.getName())));
File tempDir = null;
try {
tempDir = FileUtil.createTempDirectory("extracted_aar_deps", "tmp");
for (int i = srcJarFiles.size() - 1; i >= 0; i--) {
ZipUtil.extract(new File(srcJarFiles.get(i)), tempDir, null, true);
}
final File outputJarFile = new File(outputDir, AndroidCommonUtils.AAR_DEPS_JAR_FILE_NAME);
if (!packDirectoryIntoJar(tempDir, outputJarFile, context)) {
return false;
}
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null && outputJarFile.isFile()) {
testingManager.getCommandExecutor().checkJarContent("aar_dependencies_package_jar", outputJarFile.getPath());
}
outputConsumer.registerOutputFile(outputJarFile, srcJarFiles);
return true;
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
return false;
} finally {
if (tempDir != null) {
FileUtil.delete(tempDir);
}
}
}
use of org.jetbrains.jps.android.model.JpsAndroidModuleExtension 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.jps.android.model.JpsAndroidModuleExtension in project android by JetBrains.
the class AndroidResourcePackagingBuilder method packageResources.
private static boolean packageResources(@NotNull AndroidResourcePackagingBuildTarget target, @NotNull CompileContext context, @NotNull BuildOutputConsumer outputConsumer, boolean releaseBuild) {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null && !extension.isLibrary();
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.packaging.resources", module.getName())));
final File manifestFile = AndroidJpsUtil.getPreprocessedManifestFile(extension, context.getProjectDescriptor().dataManager.getDataPaths());
if (manifestFile == null || !manifestFile.exists()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.manifest.not.found", module.getName())));
return false;
}
final ArrayList<String> assetsDirPaths = new ArrayList<String>();
AndroidResourcePackagingBuildTarget.collectAssetDirs(extension, assetsDirPaths, true);
final String outputFilePath = target.getOutputFile(context).getPath();
File outputDir = new File(outputFilePath).getParentFile();
assert outputDir != null;
outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
if (outputDir == null) {
return false;
}
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
return false;
}
final IAndroidTarget androidTarget = platform.getTarget();
final String[] resourceDirPaths = AndroidJpsUtil.collectResourceDirsForCompilation(extension, true, context, true);
final String customManifestPackage = extension.isUseCustomManifestPackage() ? extension.getCustomManifestPackage() : null;
final String additionalParameters = extension.getAdditionalPackagingCommandLineParameters();
return doPackageResources(context, manifestFile, androidTarget, resourceDirPaths, ArrayUtil.toStringArray(assetsDirPaths), outputFilePath, releaseBuild, module.getName(), outputConsumer, customManifestPackage, additionalParameters);
}
use of org.jetbrains.jps.android.model.JpsAndroidModuleExtension in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method computeModuleDatas.
@Nullable
private static Map<JpsModule, MyModuleData> computeModuleDatas(@NotNull Collection<JpsModule> modules, @NotNull CompileContext context) throws IOException {
final Map<JpsModule, MyModuleData> moduleDataMap = new HashMap<JpsModule, MyModuleData>();
boolean success = true;
for (JpsModule module : modules) {
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension == null) {
continue;
}
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
success = false;
continue;
}
final File manifestFile = AndroidJpsUtil.getManifestFileForCompilationPath(extension);
if (manifestFile == null || !manifestFile.exists()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.manifest.not.found", module.getName())));
success = false;
continue;
}
final String packageName = AndroidJpsUtil.parsePackageNameFromManifestFile(manifestFile);
if (packageName == null || packageName.length() == 0) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.package.not.specified", module.getName())));
success = false;
continue;
}
if (!AndroidCommonUtils.contains2Identifiers(packageName)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, extension.isLibrary() ? BuildMessage.Kind.WARNING : BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.incorrect.package.name", module.getName())));
success = false;
continue;
}
moduleDataMap.put(module, new MyModuleData(platform, extension, manifestFile, packageName));
}
return success ? moduleDataMap : null;
}
use of org.jetbrains.jps.android.model.JpsAndroidModuleExtension in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method checkAndroidDependencies.
private static void checkAndroidDependencies(@NotNull Map<JpsModule, MyModuleData> moduleDataMap, @NotNull CompileContext context) {
for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
final JpsModule module = entry.getKey();
final MyModuleData moduleData = entry.getValue();
final JpsAndroidModuleExtension extension = moduleData.getAndroidExtension();
if (extension.isLibrary()) {
continue;
}
for (JpsDependencyElement item : JpsJavaExtensionService.getInstance().getDependencies(module, JpsJavaClasspathKind.PRODUCTION_RUNTIME, false)) {
if (item instanceof JpsModuleDependency) {
final JpsModule depModule = ((JpsModuleDependency) item).getModule();
if (depModule != null) {
final JpsAndroidModuleExtension depExtension = AndroidJpsUtil.getExtension(depModule);
if (depExtension != null && !depExtension.isLibrary()) {
String message = "Suspicious module dependency " + module.getName() + " -> " + depModule.getName() + ": Android application module depends on other application module. Possibly, you should " + "change type of module '" + depModule.getName() + "' to 'Library' or change the dependency scope to 'Provided'.";
context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.WARNING, message));
}
}
}
}
}
}
Aggregations