Search in sources :

Example 1 with JpsEncodingProjectConfiguration

use of org.jetbrains.jps.model.JpsEncodingProjectConfiguration in project intellij-community by JetBrains.

the class JpsProjectSerializationTest method testLoadEncoding.

public void testLoadEncoding() {
    loadProject(SAMPLE_PROJECT_PATH);
    JpsEncodingConfigurationService service = JpsEncodingConfigurationService.getInstance();
    assertEquals("UTF-8", service.getProjectEncoding(myModel));
    JpsEncodingProjectConfiguration configuration = service.getEncodingConfiguration(myProject);
    assertNotNull(configuration);
    assertEquals("UTF-8", configuration.getProjectEncoding());
    assertEquals("windows-1251", configuration.getEncoding(new File(getAbsolutePath("util"))));
    assertEquals("windows-1251", configuration.getEncoding(new File(getAbsolutePath("util/foo/bar/file.txt"))));
    assertEquals("UTF-8", configuration.getEncoding(new File(getAbsolutePath("other"))));
}
Also used : JpsEncodingConfigurationService(org.jetbrains.jps.model.JpsEncodingConfigurationService) JpsEncodingProjectConfiguration(org.jetbrains.jps.model.JpsEncodingProjectConfiguration) File(java.io.File)

Example 2 with JpsEncodingProjectConfiguration

use of org.jetbrains.jps.model.JpsEncodingProjectConfiguration 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

File (java.io.File)2 JpsEncodingProjectConfiguration (org.jetbrains.jps.model.JpsEncodingProjectConfiguration)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ZipFile (java.util.zip.ZipFile)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1 JpsEncodingConfigurationService (org.jetbrains.jps.model.JpsEncodingConfigurationService)1