Search in sources :

Example 1 with StopBuildException

use of org.jetbrains.jps.incremental.StopBuildException 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 2 with StopBuildException

use of org.jetbrains.jps.incremental.StopBuildException in project intellij-plugins by JetBrains.

the class FlexBuilder method build.

@Override
public void build(@NotNull final FlexBuildTarget buildTarget, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final Collection<String> dirtyFilePaths = new ArrayList<>();
    holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexBuildTarget>() {

        @Override
        public boolean apply(final FlexBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
            assert target == buildTarget;
            dirtyFilePaths.add(file.getPath());
            return true;
        }
    });
    if (LOG.isDebugEnabled()) {
        final StringBuilder b = new StringBuilder();
        b.append(buildTarget.getId()).append(", ").append("dirty files: ").append(dirtyFilePaths.size());
        if (dirtyFilePaths.size() < 10) {
            for (String path : dirtyFilePaths) {
                b.append('\n').append(path);
            }
        }
        LOG.debug(b.toString());
    }
    final JpsFlexBuildConfiguration mainBC = buildTarget.getBC();
    final List<JpsFlexBuildConfiguration> bcsToCompile = getAllBCsToCompile(mainBC);
    if (!FlexCommonUtils.isFlexUnitBC(mainBC) && !isFlexmojosBCWithUpdatedConfigFile(mainBC)) {
        if (dirtyFilePaths.isEmpty()) {
            boolean outputFilesExist = true;
            for (JpsFlexBuildConfiguration bc : bcsToCompile) {
                if (!new File(bc.getActualOutputFilePath()).isFile()) {
                    outputFilesExist = false;
                    LOG.debug("recompile because output file doesn't exist: " + bc.getActualOutputFilePath());
                    break;
                }
            }
            if (outputFilesExist) {
                return;
            }
        } else if (mainBC.getNature().isApp() && isOnlyWrapperFilesDirty(mainBC, dirtyFilePaths)) {
            LOG.debug("only wrapper files dirty");
            FlexBuilderUtils.performPostCompileActions(context, mainBC, dirtyFilePaths, outputConsumer);
            return;
        }
    }
    for (JpsFlexBuildConfiguration bc : bcsToCompile) {
        final Status status = compileBuildConfiguration(context, bc, myBuiltInCompilerHandler);
        switch(status) {
            case Ok:
                outputConsumer.registerOutputFile(new File(mainBC.getActualOutputFilePath()), dirtyFilePaths);
                FlexBuilderUtils.performPostCompileActions(context, bc, dirtyFilePaths, outputConsumer);
                context.processMessage(new CompilerMessage(FlexBuilderUtils.getCompilerName(bc), BuildMessage.Kind.INFO, FlexCommonBundle.message("compilation.successful")));
                break;
            case Failed:
                final String message = bc.getOutputType() == OutputType.Application ? FlexCommonBundle.message("compilation.failed") : FlexCommonBundle.message("compilation.failed.dependent.will.be.skipped");
                context.processMessage(new CompilerMessage(FlexBuilderUtils.getCompilerName(bc), BuildMessage.Kind.INFO, message));
                throw new StopBuildException();
            case Cancelled:
                context.processMessage(new CompilerMessage(FlexBuilderUtils.getCompilerName(bc), BuildMessage.Kind.INFO, FlexCommonBundle.message("compilation.cancelled")));
                return;
        }
    }
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FlexBuildTarget(com.intellij.flex.build.FlexBuildTarget) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) File(java.io.File) StopBuildException(org.jetbrains.jps.incremental.StopBuildException)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 StopBuildException (org.jetbrains.jps.incremental.StopBuildException)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 FlexBuildTarget (com.intellij.flex.build.FlexBuildTarget)1 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)1 BuildDataPaths (org.jetbrains.jps.builders.storage.BuildDataPaths)1 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)1