Search in sources :

Example 31 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class MavenResourcesBuilder method build.

@Override
public void build(@NotNull final MavenResourcesTarget target, @NotNull final DirtyFilesHolder<MavenResourceRootDescriptor, MavenResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
    final MavenProjectConfiguration projectConfig = JpsMavenExtensionService.getInstance().getMavenProjectConfiguration(dataPaths);
    if (projectConfig == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Maven project configuration required for module '" + target.getModule().getName() + "' isn't available. Compilation of Maven projects is supported only if external build is started from an IDE."));
        throw new StopBuildException();
    }
    final MavenModuleResourceConfiguration config = target.getModuleResourcesConfiguration(dataPaths);
    if (config == null) {
        return;
    }
    final Map<MavenResourceRootDescriptor, List<File>> files = new HashMap<>();
    holder.processDirtyFiles(new FileProcessor<MavenResourceRootDescriptor, MavenResourcesTarget>() {

        @Override
        public boolean apply(MavenResourcesTarget t, File file, MavenResourceRootDescriptor rd) throws IOException {
            assert target == t;
            List<File> fileList = files.get(rd);
            if (fileList == null) {
                fileList = new ArrayList<>();
                files.put(rd, fileList);
            }
            fileList.add(file);
            return true;
        }
    });
    MavenResourceRootDescriptor[] roots = files.keySet().toArray(new MavenResourceRootDescriptor[files.keySet().size()]);
    Arrays.sort(roots, (r1, r2) -> {
        int res = r1.getIndexInPom() - r2.getIndexInPom();
        if (r1.isOverwrite()) {
            // 'overwrite' parameters is common for all roots in module.
            assert r2.isOverwrite();
            return res;
        }
        if (r1.getConfiguration().isFiltered && !r2.getConfiguration().isFiltered)
            return 1;
        if (!r1.getConfiguration().isFiltered && r2.getConfiguration().isFiltered)
            return -1;
        if (!r1.getConfiguration().isFiltered) {
            res = -res;
        }
        return res;
    });
    MavenResourceFileProcessor fileProcessor = new MavenResourceFileProcessor(projectConfig, target.getModule().getProject(), config);
    context.processMessage(new ProgressMessage("Copying resources... [" + target.getModule().getName() + "]"));
    for (MavenResourceRootDescriptor rd : roots) {
        for (File file : files.get(rd)) {
            String relPath = FileUtil.getRelativePath(rd.getRootFile(), file);
            if (relPath == null) {
                continue;
            }
            final String outputDirectory = target.isTests() ? config.testOutputDirectory : config.outputDirectory;
            final File outputDir = MavenResourcesTarget.getOutputDir(target.getModuleOutputDir(), rd.getConfiguration(), outputDirectory);
            if (outputDir == null) {
                continue;
            }
            File outputFile = new File(outputDir, relPath);
            String sourcePath = file.getPath();
            try {
                fileProcessor.copyFile(file, outputFile, rd.getConfiguration(), context, FileUtilRt.ALL_FILES);
                outputConsumer.registerOutputFile(outputFile, Collections.singleton(sourcePath));
            } catch (UnsupportedEncodingException e) {
                context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, "Resource was not copied: " + e.getMessage(), sourcePath));
            } catch (IOException e) {
                context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Failed to copy '" + sourcePath + "' to '" + outputFile.getAbsolutePath() + "': " + e.getMessage()));
                LOG.info(e);
            }
            if (context.getCancelStatus().isCanceled()) {
                return;
            }
        }
    }
    context.checkCanceled();
    context.processMessage(new ProgressMessage(""));
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) File(java.io.File) StopBuildException(org.jetbrains.jps.incremental.StopBuildException)

Example 32 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class DependencyResolvingBuilder method getRepositoryManager.

private static ArtifactRepositoryManager getRepositoryManager(final CompileContext context) {
    ArtifactRepositoryManager manager = MANAGER_KEY.get(context);
    if (manager == null) {
        manager = new ArtifactRepositoryManager(getLocalRepoDir(context), new ProgressConsumer() {

            public void consume(String message) {
                context.processMessage(new ProgressMessage(message));
            }
        });
        // further init manager here
        MANAGER_KEY.set(context, manager);
    }
    return manager;
}
Also used : ProgressConsumer(org.jetbrains.idea.maven.aether.ProgressConsumer) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) ArtifactRepositoryManager(org.jetbrains.idea.maven.aether.ArtifactRepositoryManager)

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