Search in sources :

Example 31 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-elixir by KronicDeth.

the class MixBuilder method build.

@Override
public void build(@NotNull ElixirTarget target, @NotNull DirtyFilesHolder<ElixirSourceRootDescriptor, ElixirTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
    if (!holder.hasDirtyFiles() && !holder.hasRemovedFiles())
        return;
    JpsModule module = target.getModule();
    JpsProject project = module.getProject();
    ElixirCompilerOptions compilerOptions = JpsElixirCompilerOptionsExtension.getOrCreateExtension(project).getOptions();
    if (!compilerOptions.myUseMixCompiler)
        return;
    String mixPath = getMixExecutablePath(project);
    if (mixPath == null) {
        String errorMessage = "Mix path is not set.";
        context.processMessage(new CompilerMessage(NAME, BuildMessage.Kind.ERROR, errorMessage));
        throw new ProjectBuildException(errorMessage);
    }
    JpsSdk<JpsDummyElement> sdk = ElixirTargetBuilderUtil.getSdk(context, module);
    String elixirPath = JpsElixirSdkType.getScriptInterpreterExecutable(sdk.getHomePath()).getAbsolutePath();
    for (String contentRootUrl : module.getContentRootsList().getUrls()) {
        String contentRootPath = new URL(contentRootUrl).getPath();
        File contentRootDir = new File(contentRootPath);
        File mixConfigFile = new File(contentRootDir, MIX_CONFIG_FILE_NAME);
        if (!mixConfigFile.exists())
            continue;
        runMix(elixirPath, mixPath, contentRootPath, compilerOptions.myAttachDebugInfoEnabled, context);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsModule(org.jetbrains.jps.model.module.JpsModule) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsProject(org.jetbrains.jps.model.JpsProject) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ElixirCompilerOptions(org.elixir_lang.jps.model.ElixirCompilerOptions) File(java.io.File) URL(java.net.URL)

Example 32 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-elixir by KronicDeth.

the class ElixirBuilder method addModuleToCodePath.

private static void addModuleToCodePath(@NotNull GeneralCommandLine commandLine, @NotNull JpsModule module, boolean forTests, @NotNull CompileContext context) throws ProjectBuildException {
    File outputDirectory = getBuildOutputDirectory(module, forTests, context);
    commandLine.addParameters(ADD_PATH_TO_FRONT_OF_CODE_PATH, outputDirectory.getPath());
    for (String rootUrl : module.getContentRootsList().getUrls()) {
        try {
            String path = new URL(rootUrl).getPath();
            commandLine.addParameters(ADD_PATH_TO_FRONT_OF_CODE_PATH, path);
        } catch (MalformedURLException e) {
            context.processMessage(new CompilerMessage(ElIXIRC_NAME, BuildMessage.Kind.ERROR, "Failed to find content root for module: " + module.getName()));
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) File(java.io.File) URL(java.net.URL)

Example 33 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage 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)

Example 34 with CompilerMessage

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

the class FlexBuilder method doCompile.

private static Status doCompile(final CompileContext context, final JpsFlexBuildConfiguration bc, final List<File> configFiles, final String compilerName, final JpsBuiltInFlexCompilerHandler builtInCompilerHandler) {
    final boolean app = bc.getOutputType() != OutputType.Library;
    final JpsSdk<?> sdk = bc.getSdk();
    assert sdk != null;
    final boolean asc20 = bc.isPureAs() && FlexCommonUtils.containsASC20(sdk.getHomePath()) && (JpsFlexCompilerProjectExtension.getInstance(bc.getModule().getProject()).PREFER_ASC_20 || FlexCommonUtils.isAirSdkWithoutFlex(sdk));
    final boolean builtIn = !asc20 && JpsFlexCompilerProjectExtension.getInstance(bc.getModule().getProject()).USE_BUILT_IN_COMPILER && builtInCompilerHandler.canBeUsedForSdk(sdk.getHomePath());
    if (builtIn) {
        return doCompileWithBuiltInCompiler(context, bc, configFiles, compilerName, builtInCompilerHandler);
    }
    final List<String> compilerCommand = asc20 ? getASC20Command(bc.getModule().getProject(), sdk, app) : getMxmlcCompcCommand(bc.getModule().getProject(), sdk, app);
    final List<String> command = buildCommand(compilerCommand, configFiles, bc);
    final ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectErrorStream(true);
    processBuilder.directory(new File(FlexCommonUtils.getFlexCompilerWorkDirPath(bc.getModule().getProject())));
    try {
        final Process process = processBuilder.start();
        final FlexCompilerProcessHandler processHandler = new FlexCompilerProcessHandler(context, process, asc20, compilerName, StringUtil.join(command, " "));
        processHandler.startNotify();
        processHandler.waitFor();
        return processHandler.isCancelled() ? Status.Cancelled : processHandler.isCompilationFailed() ? Status.Failed : Status.Ok;
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, e.getMessage()));
        return Status.Failed;
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) File(java.io.File)

Example 35 with CompilerMessage

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

the class FlexBuilderUtils method handleHtmlWrapper.

private static void handleHtmlWrapper(final CompileContext context, final JpsFlexBuildConfiguration bc, final BuildOutputConsumer outputConsumer) {
    final File templateDir = new File(bc.getWrapperTemplatePath());
    if (!templateDir.isDirectory()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("html.wrapper.dir.not.found", bc.getWrapperTemplatePath())));
        return;
    }
    final File templateFile = new File(templateDir, FlexCommonUtils.HTML_WRAPPER_TEMPLATE_FILE_NAME);
    if (!templateFile.isFile()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("no.index.template.html.file", bc.getWrapperTemplatePath())));
        return;
    }
    final InfoFromConfigFile info = InfoFromConfigFile.getInfoFromConfigFile(bc.getCompilerOptions().getAdditionalConfigFilePath());
    final String outputFolderPath = StringUtil.notNullize(info.getOutputFolderPath(), bc.getOutputFolder());
    final String outputFileName = bc.isTempBCForCompilation() ? bc.getOutputFileName() : StringUtil.notNullize(info.getOutputFileName(), bc.getOutputFileName());
    final String targetPlayer = StringUtil.notNullize(info.getTargetPlayer(), bc.getDependencies().getTargetPlayer());
    final File outputDir = new File(outputFolderPath);
    if (!outputDir.isDirectory()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("output.folder.does.not.exist", outputFolderPath)));
        return;
    }
    for (File file : templateDir.listFiles()) {
        if (FlexCommonUtils.HTML_WRAPPER_TEMPLATE_FILE_NAME.equals(file.getName())) {
            final JpsEncodingProjectConfiguration encodingConfiguration = JpsEncodingConfigurationService.getInstance().getEncodingConfiguration(bc.getModule().getProject());
            final String encoding = encodingConfiguration == null ? null : encodingConfiguration.getEncoding(file);
            String wrapperText;
            try {
                try {
                    wrapperText = FileUtil.loadFile(file, encoding);
                } catch (UnsupportedEncodingException e) {
                    wrapperText = FileUtil.loadFile(file);
                }
            } catch (IOException e) {
                context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.load.template.file", file.getPath(), e.getMessage())));
                return;
            }
            if (!wrapperText.contains(FlexCommonUtils.SWF_MACRO)) {
                context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("no.swf.macro", file.getPath())));
                return;
            }
            final String mainClass = StringUtil.notNullize(info.getMainClass(bc.getModule()), bc.getMainClass());
            final String fixedText = replaceMacros(wrapperText, FileUtil.getNameWithoutExtension(outputFileName), targetPlayer, FlexCommonUtils.getPathToMainClassFile(mainClass, bc.getModule()));
            final String wrapperFileName = FlexCommonUtils.getWrapperFileName(bc);
            try {
                byte[] bytes;
                try {
                    bytes = encoding == null ? fixedText.getBytes() : fixedText.getBytes(encoding);
                } catch (UnsupportedEncodingException e) {
                    bytes = fixedText.getBytes();
                }
                final File outputFile = new File(outputDir, wrapperFileName);
                FileUtil.writeToFile(outputFile, bytes);
                outputConsumer.registerOutputFile(outputFile, Collections.singletonList(file.getPath()));
            } catch (IOException e) {
                context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.create.file.in", wrapperFileName, outputDir.getPath(), e.getMessage())));
            }
        } else {
            try {
                final File outputFile = new File(outputDir, file.getName());
                if (file.isDirectory()) {
                    FileUtil.createDirectory(outputFile);
                    FileUtil.copyDir(file, outputFile);
                } else {
                    FileUtil.copy(file, outputFile);
                }
                outputConsumer.registerOutputFile(outputFile, Collections.singletonList(file.getPath()));
            } catch (IOException e) {
                context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.copy.file", file.getName(), templateDir.getPath(), outputDir.getPath(), e.getMessage())));
            }
        }
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsEncodingProjectConfiguration(org.jetbrains.jps.model.JpsEncodingProjectConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)75 File (java.io.File)34 IOException (java.io.IOException)22 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)18 JpsModule (org.jetbrains.jps.model.module.JpsModule)15 HashMap (com.intellij.util.containers.HashMap)11 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)11 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)9 ArrayList (java.util.ArrayList)9 THashSet (gnu.trove.THashSet)8 Nullable (org.jetbrains.annotations.Nullable)8 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 NotNull (org.jetbrains.annotations.NotNull)7 BuildMessage (org.jetbrains.jps.incremental.messages.BuildMessage)6 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)5 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)4 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 Pair (com.intellij.openapi.util.Pair)3 THashMap (gnu.trove.THashMap)3