use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.
the class AndroidPackagingBuildTarget method doComputeRootDescriptors.
@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
final File resPackage = AndroidResourcePackagingBuildTarget.getOutputFile(dataPaths, myModule);
final File classesDexFile = AndroidDexBuildTarget.getOutputFile(dataPaths, myModule);
final List<BuildRootDescriptor> roots = new ArrayList<BuildRootDescriptor>();
roots.add(new BuildRootDescriptorImpl(this, resPackage));
roots.add(new BuildRootDescriptorImpl(this, classesDexFile));
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(myModule, null, null);
if (platform != null) {
for (String jarOrLibDir : AndroidJpsUtil.getExternalLibraries(dataPaths, myModule, platform, false, true, false)) {
roots.add(new BuildRootDescriptorImpl(this, new File(jarOrLibDir), false));
}
}
for (File resourceRoot : AndroidJpsUtil.getJavaOutputRootsForModuleAndDependencies(myModule)) {
roots.add(new MyResourceRootDescriptor(this, resourceRoot));
}
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
assert extension != null;
for (String nativeLibDir : collectNativeLibsFolders(extension, false)) {
roots.add(new BuildRootDescriptorImpl(this, new File(nativeLibDir)));
}
return roots;
}
use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.
the class AndroidResourcePackagingBuildTarget method doComputeRootDescriptors.
@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
assert extension != null;
final String[] resourceDirs = AndroidJpsUtil.collectResourceDirsForCompilation(extension, true, dataPaths, false);
final List<String> assertDirs = new ArrayList<String>();
collectAssetDirs(extension, assertDirs, false);
final File manifestFile = AndroidJpsUtil.getPreprocessedManifestFile(extension, dataPaths);
final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
for (String resourceDir : resourceDirs) {
result.add(new BuildRootDescriptorImpl(this, new File(resourceDir)));
}
for (String assetDir : assertDirs) {
result.add(new BuildRootDescriptorImpl(this, new File(assetDir)));
}
if (manifestFile != null) {
result.add(new BuildRootDescriptorImpl(this, manifestFile));
}
return result;
}
use of org.jetbrains.jps.builders.BuildRootDescriptor 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.builders.BuildRootDescriptor 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.builders.BuildRootDescriptor in project intellij-plugins by JetBrains.
the class FlexResourceBuilder method build.
public void build(@NotNull final FlexResourceBuildTarget target, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexResourceBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject());
final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
try {
holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexResourceBuildTarget>() {
public boolean apply(final FlexResourceBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
if (excludes.isExcluded(file))
return true;
final String relativePath = FileUtil.toSystemIndependentName(FileUtil.getRelativePath(root.getRootFile(), file));
if (target.isTests()) {
if (!FlexCommonUtils.isSourceFile(file.getName())) {
final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(target.getModule(), target.isTests());
if (outputRootUrl == null)
return true;
final String targetPath = JpsPathUtil.urlToPath(outputRootUrl) + '/' + relativePath;
context.processMessage(new ProgressMessage("Copying " + file.getPath()));
copyResource(context, file, Collections.singleton(targetPath), outputConsumer);
}
} else {
final Collection<String> targetPaths = new ArrayList<>();
for (JpsFlexBuildConfiguration bc : target.getModule().getProperties().getBuildConfigurations()) {
if (bc.isSkipCompile() || !FlexCommonUtils.canHaveResourceFiles(bc.getNature()) || bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.None) {
continue;
}
final JpsFlexCompilerOptions.ResourceFilesMode mode = bc.getCompilerOptions().getResourceFilesMode();
if (mode == JpsFlexCompilerOptions.ResourceFilesMode.All && !FlexCommonUtils.isSourceFile(file.getName()) || mode == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns && configuration.isResourceFile(file, root.getRootFile())) {
final String outputFolder = PathUtilRt.getParentPath(bc.getActualOutputFilePath());
targetPaths.add(outputFolder + "/" + relativePath);
}
}
if (!targetPaths.isEmpty()) {
context.processMessage(new ProgressMessage("Copying " + file.getPath()));
copyResource(context, file, targetPaths, outputConsumer);
}
}
return true;
}
});
} catch (Exception e) {
throw new ProjectBuildException(e.getMessage(), e);
}
}
Aggregations