use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.
the class OutputFilesSink method save.
public void save(@NotNull final OutputFileObject fileObject) {
final BinaryContent content = fileObject.getContent();
final File srcFile = fileObject.getSourceFile();
boolean isTemp = false;
final JavaFileObject.Kind outKind = fileObject.getKind();
if (srcFile != null && content != null) {
final String sourcePath = FileUtil.toSystemIndependentName(srcFile.getPath());
final JavaSourceRootDescriptor rootDescriptor = myContext.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(myContext, srcFile);
try {
if (rootDescriptor != null) {
isTemp = rootDescriptor.isTemp;
if (!isTemp) {
// first, handle [src->output] mapping and register paths for files_generated event
if (outKind == JavaFileObject.Kind.CLASS) {
// todo: avoid array copying?
myOutputConsumer.registerCompiledClass(rootDescriptor.target, new CompiledClass(fileObject.getFile(), srcFile, fileObject.getClassName(), content));
} else {
myOutputConsumer.registerOutputFile(rootDescriptor.target, fileObject.getFile(), Collections.<String>singleton(sourcePath));
}
}
} else {
// was not able to determine the source root descriptor or the source root is excluded from compilation (e.g. for annotation processors)
if (outKind == JavaFileObject.Kind.CLASS) {
myOutputConsumer.registerCompiledClass(null, new CompiledClass(fileObject.getFile(), srcFile, fileObject.getClassName(), content));
}
}
} catch (IOException e) {
myContext.processMessage(new CompilerMessage(JavaBuilder.BUILDER_NAME, e));
}
if (!isTemp && outKind == JavaFileObject.Kind.CLASS) {
// register in mappings any non-temp class file
try {
final ClassReader reader = new FailSafeClassReader(content.getBuffer(), content.getOffset(), content.getLength());
myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader);
} catch (Throwable e) {
// need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation
final String message = "Class dependency information may be incomplete! Error parsing generated class " + fileObject.getFile().getPath();
LOG.info(message, e);
myContext.processMessage(new CompilerMessage(JavaBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath));
}
}
}
if (outKind == JavaFileObject.Kind.CLASS) {
myContext.processMessage(new ProgressMessage("Writing classes... " + myChunkName));
if (!isTemp && srcFile != null) {
mySuccessfullyCompiled.add(srcFile);
}
}
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.
the class ResourcesBuilder method copyResource.
private static void copyResource(CompileContext context, ResourceRootDescriptor rd, File file, BuildOutputConsumer outputConsumer) throws IOException {
final File outputRoot = rd.getTarget().getOutputDir();
if (outputRoot == null) {
return;
}
final String sourceRootPath = FileUtil.toSystemIndependentName(rd.getRootFile().getAbsolutePath());
final String relativePath = FileUtil.getRelativePath(sourceRootPath, FileUtil.toSystemIndependentName(file.getPath()), '/');
final String prefix = rd.getPackagePrefix();
final StringBuilder targetPath = new StringBuilder();
targetPath.append(FileUtil.toSystemIndependentName(outputRoot.getPath()));
if (prefix.length() > 0) {
targetPath.append('/').append(prefix.replace('.', '/'));
}
targetPath.append('/').append(relativePath);
context.processMessage(new ProgressMessage("Copying resources... [" + rd.getTarget().getModule().getName() + "]"));
final String outputPath = targetPath.toString();
final File targetFile = new File(outputPath);
FileUtil.copyContent(file, targetFile);
try {
outputConsumer.registerOutputFile(targetFile, Collections.singletonList(file.getPath()));
} catch (Exception e) {
context.processMessage(new CompilerMessage(BUILDER_NAME, e));
}
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.
the class AndroidGradleTargetBuilder method build.
/**
* Builds a Gradle-based Android project using Gradle.
*/
@Override
public void build(@NotNull AndroidGradleBuildTarget target, @NotNull DirtyFilesHolder<AndroidGradleBuildTarget.RootDescriptor, AndroidGradleBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
JpsProject project = target.getProject();
checkUnsupportedModules(project, context);
BuilderExecutionSettings executionSettings;
try {
executionSettings = new BuilderExecutionSettings();
} catch (RuntimeException e) {
throw new ProjectBuildException(e);
}
LOG.info("Using execution settings: " + executionSettings);
List<String> buildTasks = executionSettings.getGradleTasksToInvoke();
if (buildTasks.isEmpty()) {
String format = "No build tasks found for project '%1$s'. Nothing done.";
LOG.info(String.format(format, project.getName()));
return;
}
context.processMessage(AndroidGradleJps.createCompilerMessage(BuildMessage.Kind.INFO, "Executing tasks: " + buildTasks));
String msg = "Gradle build using tasks: " + buildTasks;
context.processMessage(new ProgressMessage(msg));
LOG.info(msg);
ensureTempDirExists();
String androidHome = null;
if (!AndroidGradleSettings.isAndroidSdkDirInLocalPropertiesFile(executionSettings.getProjectDir())) {
androidHome = getAndroidHomeFromModuleSdk(project);
}
String format = "About to build project '%1$s' located at %2$s";
LOG.info(String.format(format, project.getName(), executionSettings.getProjectDir().getAbsolutePath()));
doBuild(context, buildTasks, executionSettings, androidHome);
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage 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.incremental.messages.ProgressMessage 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);
}
Aggregations