use of org.jetbrains.jps.model.module.JpsModule 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.model.module.JpsModule 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.model.module.JpsModule 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));
}
}
}
}
}
}
use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method checkVersions.
private static boolean checkVersions(@NotNull Map<JpsModule, MyModuleData> dataMap, @NotNull CompileContext context) {
for (Map.Entry<JpsModule, MyModuleData> entry : dataMap.entrySet()) {
final JpsModule module = entry.getKey();
final AndroidPlatform platform = entry.getValue().getPlatform();
boolean success = true;
final int platformToolsRevision = platform.getPlatformToolsRevision();
if (platformToolsRevision >= 0 && platformToolsRevision < MIN_PLATFORM_TOOLS_REVISION) {
final String message = '[' + module.getName() + "] Incompatible version of Android SDK Platform-tools package. Min version is " + MIN_PLATFORM_TOOLS_REVISION + ". Please, update it though SDK manager";
context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
success = false;
}
final int sdkToolsRevision = platform.getSdkToolsRevision();
if (sdkToolsRevision >= 0 && sdkToolsRevision < MIN_SDK_TOOLS_REVISION) {
final String message = '[' + module.getName() + "] Incompatible version " + sdkToolsRevision + " of Android SDK Tools package. Min version is " + MIN_SDK_TOOLS_REVISION + ". Please, update it though SDK manager";
context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
success = false;
}
// show error message only for first module, because all modules usualy have the same sdk specified
if (!success) {
return false;
}
}
return true;
}
use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.
the class AndroidDexBuilder method doDexBuild.
private static boolean doDexBuild(@NotNull AndroidDexBuildTarget target, @NotNull CompileContext context, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null;
assert !extension.isLibrary();
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, DEX_BUILDER_NAME);
if (platform == null) {
return false;
}
File dexOutputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
dexOutputDir = AndroidJpsUtil.createDirIfNotExist(dexOutputDir, context, DEX_BUILDER_NAME);
if (dexOutputDir == null) {
return false;
}
final ProGuardOptions proGuardOptions = AndroidJpsUtil.getProGuardConfigIfShouldRun(context, extension);
if (proGuardOptions != null) {
if (proGuardOptions.getCfgFiles() == null) {
context.processMessage(new CompilerMessage(DEX_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.find.proguard.cfg", module.getName())));
return false;
}
}
final File proguardCfgOutputFile = new File(dexOutputDir, AndroidCommonUtils.PROGUARD_CFG_OUTPUT_FILE_NAME);
final AndroidProGuardStateStorage proGuardOptionsStorage = context.getProjectDescriptor().dataManager.getStorage(target, AndroidProGuardOptionsStorageProvider.INSTANCE);
final AndroidProGuardStateStorage.MyState oldProGuardState = proGuardOptionsStorage.read();
final Set<String> fileSet;
AndroidProGuardStateStorage.MyState newProGuardState = null;
try {
if (proGuardOptions != null) {
final List<String> proguardCfgFilePathsList = new ArrayList<String>();
for (File file : proGuardOptions.getCfgFiles()) {
proguardCfgFilePathsList.add(file.getAbsolutePath());
}
proguardCfgFilePathsList.add(proguardCfgOutputFile.getPath());
final String[] proguardCfgFilePaths = ArrayUtil.toStringArray(proguardCfgFilePathsList);
final String outputJarPath = FileUtil.toSystemDependentName(dexOutputDir.getPath() + '/' + AndroidCommonUtils.PROGUARD_OUTPUT_JAR_NAME);
final Pair<Boolean, AndroidProGuardStateStorage.MyState> pair = runProguardIfNecessary(extension, target, platform, context, outputJarPath, proguardCfgFilePaths, hasDirtyFiles, oldProGuardState);
if (pair == null) {
// error reported
return false;
}
if (!pair.getFirst()) {
// nothing changed
return true;
}
newProGuardState = pair.getSecond();
assert newProGuardState != null;
fileSet = Collections.singleton(outputJarPath);
} else {
if (!hasDirtyFiles && oldProGuardState == null) {
return true;
}
final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
fileSet = new HashSet<String>();
final boolean predexingEnabled = extension.isPreDexingEnabled() && isPredexingInScope(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) {
fileSet.add(rootFile.getPath());
} else if (type == AndroidDexBuildTarget.ClassesDirType.ANDROID_APP) {
AndroidJpsUtil.addSubdirectories(rootFile, fileSet);
}
} else if (root instanceof AndroidDexBuildTarget.MyJarBuildRootDescriptor) {
if (((AndroidDexBuildTarget.MyJarBuildRootDescriptor) root).isPreDexed() == predexingEnabled) {
fileSet.add(rootFile.getPath());
}
}
}
}
final boolean success;
if (fileSet.size() > 0) {
final String[] files = new String[fileSet.size()];
int i = 0;
for (String filePath : fileSet) {
files[i++] = FileUtil.toSystemDependentName(filePath);
}
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.dex", module.getName())));
Arrays.sort(files);
success = runDex(platform, dexOutputDir.getPath(), files, context, module, outputConsumer);
} else {
success = true;
}
if (success) {
proGuardOptionsStorage.update(newProGuardState);
}
return success;
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, DEX_BUILDER_NAME);
return false;
}
}
Aggregations