use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.
the class AndroidPackagingBuilder method doPackagingForModule.
private static boolean doPackagingForModule(@NotNull CompileContext context, @NotNull JpsModule module, @NotNull AndroidApkBuilderConfigStateStorage apkBuilderConfigStateStorage, @NotNull AndroidPackagingStateStorage packagingStateStorage, boolean release, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension == null || extension.isLibrary()) {
return true;
}
final String[] resourceRoots = AndroidJpsUtil.toPaths(AndroidJpsUtil.getJavaOutputRootsForModuleAndDependencies(module));
Arrays.sort(resourceRoots);
final File moduleOutputDir = ProjectPaths.getModuleOutputDir(module, false);
if (moduleOutputDir == null) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.output.dir.not.specified", module.getName())));
return false;
}
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
return false;
}
final Set<String> externalJarsSet = new HashSet<String>();
for (String jarPath : AndroidJpsUtil.getExternalLibraries(context, module, platform)) {
if (new File(jarPath).exists()) {
externalJarsSet.add(jarPath);
}
}
final BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
final File resPackage = AndroidResourcePackagingBuildTarget.getOutputFile(dataPaths, module);
final File classesDexFile = AndroidDexBuildTarget.getOutputFile(dataPaths, module);
final String sdkPath = platform.getSdk().getHomePath();
final String outputPath = AndroidJpsUtil.getApkPath(extension, moduleOutputDir);
if (outputPath == null) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.compute.output.apk", module.getName())));
return false;
}
final String customKeyStorePath = FileUtil.toSystemDependentName(extension.getCustomDebugKeyStorePath());
final String[] nativeLibDirs = AndroidPackagingBuildTarget.collectNativeLibsFolders(extension, true);
final String resPackagePath = resPackage.getPath();
final String classesDexFilePath = classesDexFile.getPath();
final String[] externalJars = ArrayUtil.toStringArray(externalJarsSet);
Arrays.sort(externalJars);
final List<AndroidNativeLibData> additionalNativeLibs = extension.getAdditionalNativeLibs();
final AndroidApkBuilderConfigState currentApkBuilderConfigState = new AndroidApkBuilderConfigState(outputPath, customKeyStorePath, additionalNativeLibs);
if (!hasDirtyFiles) {
final AndroidApkBuilderConfigState savedApkBuilderConfigState = apkBuilderConfigStateStorage.getState(module.getName());
final AndroidPackagingStateStorage.MyState packagingState = packagingStateStorage.read();
if (currentApkBuilderConfigState.equalsTo(savedApkBuilderConfigState) && packagingState != null && packagingState.isRelease() == release) {
return true;
}
}
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.packaging", AndroidJpsUtil.getApkName(module))));
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApkBuilder.execute(resPackagePath, classesDexFilePath, resourceRoots, externalJars, nativeLibDirs, additionalNativeLibs, outputPath, release, sdkPath, platform.getTarget(), customKeyStorePath, new MyExcludedSourcesFilter(context.getProjectDescriptor().getProject()));
if (messages.get(AndroidCompilerMessageKind.ERROR).size() == 0) {
final List<String> srcFiles = new ArrayList<String>();
srcFiles.add(resPackagePath);
srcFiles.add(classesDexFilePath);
for (String resourceRoot : resourceRoots) {
FileUtil.processFilesRecursively(new File(resourceRoot), new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile() && AndroidApkBuilder.checkFileForPackaging(file)) {
srcFiles.add(file.getPath());
}
return true;
}
});
}
Collections.addAll(srcFiles, externalJars);
for (String nativeLibDir : nativeLibDirs) {
FileUtil.processFilesRecursively(new File(nativeLibDir), new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile()) {
srcFiles.add(file.getPath());
}
return true;
}
});
}
outputConsumer.registerOutputFile(new File(outputPath), srcFiles);
}
AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
apkBuilderConfigStateStorage.update(module.getName(), success ? currentApkBuilderConfigState : null);
packagingStateStorage.saveState(new AndroidPackagingStateStorage.MyState(release));
return success;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage 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;
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.
the class AndroidDexBuilder method getJavaExecutable.
@Nullable
private static String getJavaExecutable(@NotNull AndroidPlatform platform, @NotNull CompileContext context, @NotNull String builderName) {
final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk = platform.getSdk();
final String jdkName = sdk.getSdkProperties().getData().getJdkName();
final JpsLibrary javaSdk = context.getProjectDescriptor().getModel().getGlobal().getLibraryCollection().findLibrary(jdkName);
if (javaSdk == null || !javaSdk.getType().equals(JpsJavaSdkType.INSTANCE)) {
context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.java.sdk.not.specified", jdkName)));
return null;
}
return JpsJavaSdkType.getJavaExecutable((JpsSdk<?>) javaSdk.getProperties());
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.
the class AndroidJpsUtil method reportExceptionError.
public static void reportExceptionError(@NotNull CompileContext context, @Nullable String filePath, @NotNull Exception exception, @NotNull String builderName) {
final String message = exception.getMessage();
if (message != null) {
context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, message, filePath));
LOG.debug(exception);
} else {
context.processMessage(new CompilerMessage(builderName, exception));
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.
the class AndroidJpsUtil method getAndroidTarget.
@Nullable
public static Pair<IAndroidTarget, AndroidSdkHandler> getAndroidTarget(@NotNull JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk, @Nullable CompileContext context, String builderName) {
JpsAndroidSdkProperties sdkProperties = sdk.getSdkProperties().getData();
final String targetHashString = sdkProperties.getBuildTargetHashString();
if (targetHashString == null) {
if (context != null) {
context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, "Cannot parse SDK " + sdk.getParent().getName() + ": build target is not specified"));
}
return null;
}
final AndroidSdkHandler sdkHandler = AndroidSdkHandler.getInstance(new File(sdk.getHomePath()));
RepoLogger log = new RepoLogger();
final IAndroidTarget target = sdkHandler.getAndroidTargetManager(log).getTargetFromHashString(targetHashString, log);
if (target == null) {
if (context != null) {
context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, "Cannot parse SDK '" + sdk.getParent().getName() + "': unknown target " + targetHashString));
}
return null;
}
return Pair.create(target, sdkHandler);
}
Aggregations