use of org.jetbrains.jps.incremental.messages.ProgressMessage 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.ProgressMessage in project intellij-community by JetBrains.
the class JarsBuilder method buildJars.
public boolean buildJars() throws IOException, ProjectBuildException {
myContext.processMessage(new ProgressMessage("Building archives..."));
final JarInfo[] sortedJars = sortJars();
if (sortedJars == null) {
return false;
}
myBuiltJars = new HashMap<>();
try {
for (JarInfo jar : sortedJars) {
myContext.checkCanceled();
buildJar(jar);
}
myContext.processMessage(new ProgressMessage("Copying archives..."));
copyJars();
} finally {
deleteTemporaryJars();
}
return true;
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage 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();
}
}
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.
the class ResourcesBuilder method build.
@Override
public void build(@NotNull ResourcesTarget target, @NotNull DirtyFilesHolder<ResourceRootDescriptor, ResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
if (!isResourceProcessingEnabled(target.getModule())) {
return;
}
try {
holder.processDirtyFiles(new FileProcessor<ResourceRootDescriptor, ResourcesTarget>() {
private final Map<ResourceRootDescriptor, Boolean> mySkippedRoots = new HashMap<>();
public boolean apply(ResourcesTarget target, final File file, final ResourceRootDescriptor sourceRoot) throws IOException {
Boolean isSkipped = mySkippedRoots.get(sourceRoot);
if (isSkipped == null) {
final File outputDir = target.getOutputDir();
isSkipped = Boolean.valueOf(outputDir == null || FileUtil.filesEqual(outputDir, sourceRoot.getRootFile()));
mySkippedRoots.put(sourceRoot, isSkipped);
}
if (isSkipped.booleanValue()) {
return true;
}
try {
copyResource(context, sourceRoot, file, outputConsumer);
} catch (IOException e) {
LOG.info(e);
context.processMessage(new CompilerMessage("resources", BuildMessage.Kind.ERROR, e.getMessage(), FileUtil.toSystemIndependentName(file.getPath())));
return false;
}
return !context.getCancelStatus().isCanceled();
}
});
context.checkCanceled();
context.processMessage(new ProgressMessage(""));
} catch (BuildDataCorruptedException | ProjectBuildException e) {
throw e;
} catch (Exception e) {
throw new ProjectBuildException(e.getMessage(), e);
}
}
use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.
the class ClassProcessingBuilder method build.
@Override
public final ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
if (outputConsumer.getCompiledClasses().isEmpty() || !isEnabled(context, chunk)) {
return ExitCode.NOTHING_DONE;
}
final String progress = getProgressMessage();
final boolean shouldShowProgress = !StringUtil.isEmptyOrSpaces(progress);
if (shouldShowProgress) {
context.processMessage(new ProgressMessage(progress + " [" + chunk.getPresentableShortName() + "]"));
}
ExitCode exitCode = ExitCode.NOTHING_DONE;
try {
// try using shared finder
InstrumentationClassFinder finder = CLASS_FINDER.get(context);
if (finder == null) {
final Collection<File> platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false);
final Collection<File> classpath = new ArrayList<>();
classpath.addAll(ProjectPaths.getCompilationClasspath(chunk, false));
classpath.addAll(ProjectPaths.getSourceRootsWithDependents(chunk).keySet());
final JpsSdk<JpsDummyElement> sdk = chunk.representativeTarget().getModule().getSdk(JpsJavaSdkType.INSTANCE);
finder = createInstrumentationClassFinder(sdk, platformCp, classpath, outputConsumer);
CLASS_FINDER.set(context, finder);
}
exitCode = performBuild(context, chunk, finder, outputConsumer);
} finally {
if (shouldShowProgress) {
// cleanup progress
context.processMessage(new ProgressMessage(""));
}
}
return exitCode;
}
Aggregations