use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runRenderscriptCompiler.
private static boolean runRenderscriptCompiler(@NotNull final CompileContext context, @NotNull Map<File, ModuleBuildTarget> files, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) {
if (files.size() > 0) {
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.renderscript")));
}
boolean success = true;
for (Map.Entry<File, ModuleBuildTarget> entry : files.entrySet()) {
final File file = entry.getKey();
final ModuleBuildTarget buildTarget = entry.getValue();
final MyModuleData moduleData = moduleDataMap.get(buildTarget.getModule());
if (!LOG.assertTrue(moduleData != null)) {
context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.internal.error")));
success = false;
continue;
}
final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataManager);
final File rsOutputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.RENDERSCRIPT_GENERATED_SOURCE_ROOT_NAME);
if (!rsOutputDirectory.exists() && !rsOutputDirectory.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", rsOutputDirectory.getPath())));
success = false;
continue;
}
final File generatedResourcesDir = AndroidJpsUtil.getGeneratedResourcesStorage(buildTarget.getModule(), dataManager);
final File rawDir = new File(generatedResourcesDir, "raw");
if (!rawDir.exists() && !rawDir.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_RENDERSCRIPT_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", rawDir.getPath())));
success = false;
continue;
}
final AndroidPlatform platform = moduleData.getPlatform();
final IAndroidTarget target = platform.getTarget();
final String sdkLocation = platform.getSdk().getHomePath();
final String filePath = file.getPath();
File tmpOutputDirectory = null;
try {
tmpOutputDirectory = FileUtil.createTempDirectory("generated-rs-temp", null);
final String depFolderPath = getDependencyFolder(context, file, tmpOutputDirectory);
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidRenderscript.execute(sdkLocation, target, filePath, tmpOutputDirectory.getPath(), depFolderPath, rawDir.getPath());
addMessages(context, messages, filePath, ANDROID_RENDERSCRIPT_COMPILER);
if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
success = false;
} else {
final List<File> newFiles = new ArrayList<File>();
AndroidCommonUtils.moveAllFiles(tmpOutputDirectory, rsOutputDirectory, newFiles);
final File bcFile = new File(rawDir, FileUtil.getNameWithoutExtension(file) + ".bc");
if (bcFile.exists()) {
newFiles.add(bcFile);
}
final List<String> newFilePaths = Arrays.asList(AndroidJpsUtil.toPaths(newFiles.toArray(new File[newFiles.size()])));
final SourceToOutputMapping sourceToOutputMap = dataManager.getSourceToOutputMap(buildTarget);
sourceToOutputMap.setOutputs(filePath, newFilePaths);
for (File newFile : newFiles) {
FSOperations.markDirty(context, CompilationRound.CURRENT, newFile);
}
}
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, filePath, e, ANDROID_RENDERSCRIPT_COMPILER);
success = false;
} finally {
if (tmpOutputDirectory != null) {
FileUtil.delete(tmpOutputDirectory);
}
}
}
return success;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class IncArtifactBuilder method build.
@Override
public void build(@NotNull ArtifactBuildTarget target, @NotNull DirtyFilesHolder<ArtifactRootDescriptor, ArtifactBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException {
JpsArtifact artifact = target.getArtifact();
String outputFilePath = artifact.getOutputFilePath();
if (StringUtil.isEmpty(outputFilePath)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: output path is not specified"));
return;
}
final ProjectDescriptor pd = context.getProjectDescriptor();
final ArtifactSorter sorter = new ArtifactSorter(pd.getModel());
final Map<JpsArtifact, JpsArtifact> selfIncludingNameMap = sorter.getArtifactToSelfIncludingNameMap();
final JpsArtifact selfIncluding = selfIncludingNameMap.get(artifact);
if (selfIncluding != null) {
String name = selfIncluding.equals(artifact) ? "it" : "'" + selfIncluding.getName() + "' artifact";
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: " + name + " includes itself in the output layout"));
return;
}
try {
final Collection<String> deletedFiles = holder.getRemovedFiles(target);
String messageText = "Building artifact '" + artifact.getName() + "'...";
context.processMessage(new ProgressMessage(messageText));
LOG.debug(messageText);
runArtifactTasks(context, target.getArtifact(), ArtifactBuildTaskProvider.ArtifactBuildPhase.PRE_PROCESSING);
final SourceToOutputMapping srcOutMapping = pd.dataManager.getSourceToOutputMap(target);
final ArtifactOutputToSourceMapping outSrcMapping = pd.dataManager.getStorage(target, ArtifactOutToSourceStorageProvider.INSTANCE);
final TIntObjectHashMap<Set<String>> filesToProcess = new TIntObjectHashMap<>();
final MultiMap<String, String> filesToDelete = new MultiMap<>();
final Set<String> deletedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
for (String sourcePath : deletedFiles) {
final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
if (outputPaths != null) {
for (String outputPath : outputPaths) {
if (deletedOutputPaths.add(outputPath)) {
collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
}
}
}
}
final Set<String> changedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
holder.processDirtyFiles(new FileProcessor<ArtifactRootDescriptor, ArtifactBuildTarget>() {
@Override
public boolean apply(ArtifactBuildTarget target, File file, ArtifactRootDescriptor root) throws IOException {
int rootIndex = root.getRootIndex();
String sourcePath = FileUtil.toSystemIndependentName(file.getPath());
addFileToProcess(filesToProcess, rootIndex, sourcePath, deletedFiles);
final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
if (outputPaths != null) {
for (String outputPath : outputPaths) {
if (changedOutputPaths.add(outputPath)) {
collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
}
}
}
return true;
}
});
BuildOperations.cleanOutputsCorrespondingToChangedFiles(context, holder);
for (String outputPath : changedOutputPaths) {
outSrcMapping.remove(outputPath);
}
if (filesToDelete.isEmpty() && filesToProcess.isEmpty()) {
return;
}
deleteOutdatedFiles(filesToDelete, context, srcOutMapping, outSrcMapping);
context.checkCanceled();
context.processMessage(new ProgressMessage("Building artifact '" + artifact.getName() + "': copying files..."));
final Set<JarInfo> changedJars = new THashSet<>();
for (ArtifactRootDescriptor descriptor : pd.getBuildRootIndex().getTargetRoots(target, context)) {
context.checkCanceled();
final Set<String> sourcePaths = filesToProcess.get(descriptor.getRootIndex());
if (sourcePaths == null)
continue;
for (String sourcePath : sourcePaths) {
if (!descriptor.getFilter().shouldBeCopied(sourcePath, pd)) {
if (LOG.isDebugEnabled()) {
LOG.debug("File " + sourcePath + " will be skipped because it isn't accepted by filter");
}
continue;
}
DestinationInfo destination = descriptor.getDestinationInfo();
if (destination instanceof ExplodedDestinationInfo) {
descriptor.copyFromRoot(sourcePath, descriptor.getRootIndex(), destination.getOutputPath(), context, outputConsumer, outSrcMapping);
} else {
List<ArtifactOutputToSourceMapping.SourcePathAndRootIndex> sources = outSrcMapping.getState(destination.getOutputFilePath());
if (sources == null || sources.size() > 0 && sources.get(0).getRootIndex() == descriptor.getRootIndex()) {
outSrcMapping.update(destination.getOutputFilePath(), Collections.<ArtifactOutputToSourceMapping.SourcePathAndRootIndex>emptyList());
changedJars.add(((JarDestinationInfo) destination).getJarInfo());
}
}
}
}
context.checkCanceled();
JarsBuilder builder = new JarsBuilder(changedJars, context, outputConsumer, outSrcMapping);
builder.buildJars();
runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.FINISHING_BUILD);
runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.POST_PROCESSING);
} catch (IOException e) {
throw new ProjectBuildException(e);
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class IncArtifactBuilder method deleteOutdatedFiles.
private static void deleteOutdatedFiles(MultiMap<String, String> filesToDelete, CompileContext context, SourceToOutputMapping srcOutMapping, ArtifactOutputToSourceMapping outSrcMapping) throws IOException {
if (filesToDelete.isEmpty())
return;
context.processMessage(new ProgressMessage("Deleting outdated files..."));
int notDeletedFilesCount = 0;
final THashSet<String> notDeletedPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
final THashSet<String> deletedPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
for (String filePath : filesToDelete.keySet()) {
if (notDeletedPaths.contains(filePath)) {
continue;
}
boolean deleted = deletedPaths.contains(filePath);
if (!deleted) {
deleted = FileUtil.delete(new File(filePath));
}
if (deleted) {
if (LOG.isDebugEnabled()) {
LOG.debug("Outdated output file deleted: " + filePath);
}
outSrcMapping.remove(filePath);
deletedPaths.add(filePath);
for (String sourcePath : filesToDelete.get(filePath)) {
srcOutMapping.removeOutput(sourcePath, filePath);
}
} else {
notDeletedPaths.add(filePath);
if (notDeletedFilesCount++ > 50) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.WARNING, "Deletion of outdated files stopped because too many files cannot be deleted"));
break;
}
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.WARNING, "Cannot delete file '" + filePath + "'"));
}
}
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logDeletedFiles(deletedPaths);
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class JarsBuilder method sortJars.
@Nullable
private JarInfo[] sortJars() {
final DFSTBuilder<JarInfo> builder = new DFSTBuilder<>(GraphGenerator.generate(CachingSemiGraph.cache(new JarsGraph())));
if (!builder.isAcyclic()) {
final Pair<JarInfo, JarInfo> dependency = builder.getCircularDependency();
String message = "Cannot build: circular dependency found between '" + dependency.getFirst().getPresentableDestination() + "' and '" + dependency.getSecond().getPresentableDestination() + "'";
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.ERROR, message));
return null;
}
JarInfo[] jars = myJarsToBuild.toArray(new JarInfo[myJarsToBuild.size()]);
Arrays.sort(jars, builder.comparator());
jars = ArrayUtil.reverseArray(jars);
return jars;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class JarsBuilder method buildJar.
private void buildJar(final JarInfo jar) throws IOException {
final String emptyArchiveMessage = "Archive '" + jar.getPresentableDestination() + "' doesn't contain files so it won't be created";
if (jar.getContent().isEmpty()) {
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, emptyArchiveMessage));
return;
}
myContext.processMessage(new ProgressMessage("Building " + jar.getPresentableDestination() + "..."));
File jarFile = FileUtil.createTempFile("artifactCompiler", "tmp");
myBuiltJars.put(jar, jarFile);
FileUtil.createParentDirs(jarFile);
final String targetJarPath = jar.getDestination().getOutputFilePath();
List<String> packedFilePaths = new ArrayList<>();
Manifest manifest = loadManifest(jar, packedFilePaths);
final JarOutputStream jarOutputStream = createJarOutputStream(jarFile, manifest);
final THashSet<String> writtenPaths = new THashSet<>();
try {
if (manifest != null) {
writtenPaths.add(JarFile.MANIFEST_NAME);
}
for (Pair<String, Object> pair : jar.getContent()) {
final String relativePath = pair.getFirst();
if (pair.getSecond() instanceof ArtifactRootDescriptor) {
final ArtifactRootDescriptor descriptor = (ArtifactRootDescriptor) pair.getSecond();
final int rootIndex = descriptor.getRootIndex();
if (descriptor instanceof FileBasedArtifactRootDescriptor) {
addFileToJar(jarOutputStream, jarFile, descriptor.getRootFile(), descriptor.getFilter(), relativePath, targetJarPath, writtenPaths, packedFilePaths, rootIndex);
} else {
final String filePath = FileUtil.toSystemIndependentName(descriptor.getRootFile().getAbsolutePath());
packedFilePaths.add(filePath);
myOutSrcMapping.appendData(targetJarPath, rootIndex, filePath);
extractFileAndAddToJar(jarOutputStream, (JarBasedArtifactRootDescriptor) descriptor, relativePath, writtenPaths);
}
} else {
JarInfo nestedJar = (JarInfo) pair.getSecond();
File nestedJarFile = myBuiltJars.get(nestedJar);
if (nestedJarFile != null) {
addFileToJar(jarOutputStream, jarFile, nestedJarFile, SourceFileFilter.ALL, relativePath, targetJarPath, writtenPaths, packedFilePaths, -1);
} else {
LOG.debug("nested JAR file " + relativePath + " for " + jar.getPresentableDestination() + " not found");
}
}
}
if (writtenPaths.isEmpty()) {
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, emptyArchiveMessage));
return;
}
final ProjectBuilderLogger logger = myContext.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logCompiledPaths(packedFilePaths, IncArtifactBuilder.BUILDER_NAME, "Packing files:");
}
myOutputConsumer.registerOutputFile(new File(targetJarPath), packedFilePaths);
} finally {
if (writtenPaths.isEmpty()) {
try {
jarOutputStream.close();
} catch (IOException ignored) {
}
FileUtil.delete(jarFile);
myBuiltJars.remove(jar);
} else {
jarOutputStream.close();
}
}
}
Aggregations