Search in sources :

Example 71 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)

Example 72 with CompilerMessage

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

the class CompilerMessageHandlerBase method handleLine.

private void handleLine(final String text) {
    if (StringUtil.isEmptyOrSpaces(text)) {
        reportPreviousInfoMessage();
        return;
    }
    if (text.equals("^")) {
        // don't report previous line, it contains a line of source code with warning/error
        myPreviousUnreportedInfoMessage = null;
        return;
    }
    if ("command line".equals(text)) {
        // ignore this line and print previous if any
        reportPreviousInfoMessage();
        return;
    }
    if (text.startsWith("Exception in thread \"") || text.contains(FlexCommonUtils.COULD_NOT_CREATE_JVM)) {
        reportPreviousInfoMessage();
        myContext.processMessage(new CompilerMessage(myCompilerName, BuildMessage.Kind.ERROR, text));
        myCompilationFailed = true;
        return;
    }
    if (myAsc20) {
        // see messages_en.properties from Falcon sources
        if (text.startsWith("Warning: ") || text.startsWith("Error: ") || text.startsWith("Syntax error: ") || text.startsWith("Internal error: ")) {
            final BuildMessage.Kind kind = text.startsWith("Warning: ") ? BuildMessage.Kind.WARNING : BuildMessage.Kind.ERROR;
            final int index = text.indexOf(": ");
            final String usefulMessage = text.substring(index + ": ".length());
            final Pair<String, Integer> sourcePathAndLine = FlexCommonUtils.getSourcePathAndLineFromASC20Message(myPreviousUnreportedInfoMessage);
            if (sourcePathAndLine == null) {
                reportPreviousInfoMessage();
                myContext.processMessage(new CompilerMessage(myCompilerName, kind, usefulMessage));
            } else {
                myPreviousUnreportedInfoMessage = null;
                if (!isNotSupportedOptionFromGeneratedConfig(usefulMessage, sourcePathAndLine.first)) {
                    myContext.processMessage(new CompilerMessage(myCompilerName, kind, usefulMessage, sourcePathAndLine.first, -1, -1, -1, sourcePathAndLine.second, 0));
                }
            }
            myCompilationFailed |= kind == BuildMessage.Kind.ERROR;
            return;
        }
    } else {
        final Matcher matcher = FlexCommonUtils.ERROR_PATTERN.matcher(text);
        if (matcher.matches()) {
            final String sourceFilePath = matcher.group(1);
            final String additionalInfo = matcher.group(2);
            final String line = matcher.group(3);
            final String column = matcher.group(4);
            final String type = matcher.group(5);
            final String message = matcher.group(6);
            final BuildMessage.Kind kind = "Warning".equals(type) ? BuildMessage.Kind.WARNING : BuildMessage.Kind.ERROR;
            final File file = new File(sourceFilePath);
            final boolean sourceFileExists = file.exists();
            final StringBuilder fullMessage = new StringBuilder();
            if (!sourceFileExists)
                fullMessage.append(sourceFilePath).append(": ");
            if (additionalInfo != null)
                fullMessage.append(additionalInfo).append(' ');
            fullMessage.append(message);
            reportPreviousInfoMessage();
            myContext.processMessage(new CompilerMessage(myCompilerName, kind, fullMessage.toString(), sourceFileExists ? sourceFilePath : null, -1, -1, -1, line != null ? Integer.parseInt(line) : 0, column != null ? Integer.parseInt(column) : 0));
            myCompilationFailed |= kind == BuildMessage.Kind.ERROR;
            return;
        }
    }
    if (text.startsWith(ERROR_PREFIX)) {
        reportPreviousInfoMessage();
        myContext.processMessage(new CompilerMessage(myCompilerName, BuildMessage.Kind.ERROR, text.substring(ERROR_PREFIX.length())));
        myCompilationFailed = true;
        return;
    }
    reportPreviousInfoMessage();
    myPreviousUnreportedInfoMessage = text;
    if (text.contains(FlexCommonUtils.OUT_OF_MEMORY) || text.contains(FlexCommonUtils.JAVA_HEAP_SPACE)) {
        myContext.processMessage(new CompilerMessage(myCompilerName, BuildMessage.Kind.ERROR, FlexCommonBundle.message("increase.flex.compiler.heap", CommonBundle.settingsActionPath())));
        myCompilationFailed = true;
    }
}
Also used : BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Matcher(java.util.regex.Matcher) File(java.io.File)

Example 73 with CompilerMessage

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

the class FlexBuilder method doCompileWithBuiltInCompiler.

private static Status doCompileWithBuiltInCompiler(final CompileContext context, final JpsFlexBuildConfiguration bc, final List<File> configFiles, final String compilerName, final JpsBuiltInFlexCompilerHandler builtInCompilerHandler) {
    try {
        builtInCompilerHandler.startCompilerIfNeeded(bc.getSdk(), context, compilerName);
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, e.toString()));
        return Status.Failed;
    }
    final List<String> mxmlcOrCompc = Collections.singletonList(bc.getOutputType() == OutputType.Library ? "compc" : "mxmlc");
    final List<String> command = buildCommand(mxmlcOrCompc, configFiles, bc);
    final String plainCommand = StringUtil.join(command, s -> s.indexOf(' ') >= 0 && !(s.startsWith("\"") && s.endsWith("\"")) ? '\"' + s + '\"' : s, " ");
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.INFO, plainCommand));
    final BuiltInCompilerListener listener = new BuiltInCompilerListener(context, compilerName, () -> semaphore.up());
    builtInCompilerHandler.sendCompilationCommand(plainCommand, listener);
    semaphore.waitFor();
    builtInCompilerHandler.removeListener(listener);
    return listener.isCompilationCancelled() ? Status.Cancelled : listener.isCompilationFailed() ? Status.Failed : Status.Ok;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 74 with CompilerMessage

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

the class FlexBuilder method compileBuildConfiguration.

private static Status compileBuildConfiguration(final CompileContext context, final JpsFlexBuildConfiguration bc, final JpsBuiltInFlexCompilerHandler builtInCompilerHandler) {
    setProgressMessage(context, bc);
    final String compilerName = FlexBuilderUtils.getCompilerName(bc);
    try {
        final List<File> configFiles = createConfigFiles(bc, context.getProjectDescriptor());
        final String outputFilePath = bc.getActualOutputFilePath();
        if (!ensureCanCreateFile(new File(outputFilePath))) {
            context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.create.file", bc.getActualOutputFilePath())));
            return Status.Failed;
        }
        return doCompile(context, bc, configFiles, compilerName, builtInCompilerHandler);
    } 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 75 with CompilerMessage

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

the class OsgiBuildSession method process.

private void process(BuildMessage.Kind kind, String text, Throwable t, String path, int line) {
    LOG.warn(text, t);
    myContext.processMessage(new CompilerMessage(OsmorcBuilder.ID, kind, myMessagePrefix + text, coalesce(path, mySourceToReport), -1, -1, -1, line, -1));
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage)

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