Search in sources :

Example 26 with ProgressMessage

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);
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) File(java.io.File) THashSet(gnu.trove.THashSet)

Example 27 with ProgressMessage

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;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage)

Example 28 with ProgressMessage

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();
        }
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) THashSet(gnu.trove.THashSet) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JarFile(java.util.jar.JarFile)

Example 29 with ProgressMessage

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);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) ResourcesTarget(org.jetbrains.jps.incremental.ResourcesTarget) ResourceRootDescriptor(org.jetbrains.jps.builders.java.ResourceRootDescriptor) File(java.io.File)

Example 30 with ProgressMessage

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;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) InstrumentationClassFinder(com.intellij.compiler.instrumentation.InstrumentationClassFinder) ArrayList(java.util.ArrayList) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) File(java.io.File)

Aggregations

ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)32 File (java.io.File)20 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)17 IOException (java.io.IOException)14 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 THashSet (gnu.trove.THashSet)8 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)7 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 HashMap (com.intellij.util.containers.HashMap)4 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)4 ArrayList (java.util.ArrayList)4 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)4 Pair (com.intellij.openapi.util.Pair)3 HashSet (com.intellij.util.containers.HashSet)3 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)3 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)3 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)3 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)3 JpsProject (org.jetbrains.jps.model.JpsProject)3