Search in sources :

Example 1 with EncodingManager

use of com.intellij.openapi.vfs.encoding.EncodingManager in project intellij-community by JetBrains.

the class FilePathImpl method getCharset.

@Override
@NotNull
public Charset getCharset(@Nullable Project project) {
    VirtualFile file = getVirtualFile();
    String path = myPath;
    while ((file == null || !file.isValid()) && !path.isEmpty()) {
        path = PathUtil.getParentPath(path);
        file = LocalFileSystem.getInstance().findFileByPath(path);
    }
    if (file != null) {
        return file.getCharset();
    }
    EncodingManager e = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project);
    return e.getDefaultCharset();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EncodingManager(com.intellij.openapi.vfs.encoding.EncodingManager) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with EncodingManager

use of com.intellij.openapi.vfs.encoding.EncodingManager in project intellij-community by JetBrains.

the class VcsHistoryUtil method loadRevisionContentGuessEncoding.

public static String loadRevisionContentGuessEncoding(@NotNull final VcsFileRevision revision, @Nullable final VirtualFile file, @Nullable final Project project) throws VcsException, IOException {
    final byte[] bytes = loadRevisionContent(revision);
    if (file != null) {
        return new String(bytes, file.getCharset());
    }
    EncodingManager e = project != null ? EncodingProjectManager.getInstance(project) : null;
    if (e == null) {
        e = EncodingManager.getInstance();
    }
    return CharsetToolkit.bytesToString(bytes, e.getDefaultCharset());
}
Also used : EncodingManager(com.intellij.openapi.vfs.encoding.EncodingManager)

Example 3 with EncodingManager

use of com.intellij.openapi.vfs.encoding.EncodingManager in project intellij-community by JetBrains.

the class LocalFilePath method getCharset.

@Override
@NotNull
public Charset getCharset(@Nullable Project project) {
    VirtualFile file = getVirtualFile();
    String path = myPath;
    while ((file == null || !file.isValid()) && !path.isEmpty()) {
        path = PathUtil.getParentPath(path);
        file = LocalFileSystem.getInstance().findFileByPath(path);
    }
    if (file != null) {
        return file.getCharset();
    }
    EncodingManager e = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project);
    return e.getDefaultCharset();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EncodingManager(com.intellij.openapi.vfs.encoding.EncodingManager) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with EncodingManager

use of com.intellij.openapi.vfs.encoding.EncodingManager in project intellij-community by JetBrains.

the class MavenExternalParameters method createJavaParameters.

/**
   * @param project
   * @param parameters
   * @param coreSettings
   * @param runnerSettings
   * @param runConfiguration used to creation fix if maven home not found
   * @return
   * @throws ExecutionException
   */
public static JavaParameters createJavaParameters(@Nullable final Project project, @NotNull final MavenRunnerParameters parameters, @Nullable MavenGeneralSettings coreSettings, @Nullable MavenRunnerSettings runnerSettings, @Nullable MavenRunConfiguration runConfiguration) throws ExecutionException {
    final JavaParameters params = new JavaParameters();
    ApplicationManager.getApplication().assertReadAccessAllowed();
    if (coreSettings == null) {
        coreSettings = project == null ? new MavenGeneralSettings() : MavenProjectsManager.getInstance(project).getGeneralSettings();
    }
    if (runnerSettings == null) {
        runnerSettings = project == null ? new MavenRunnerSettings() : MavenRunner.getInstance(project).getState();
    }
    params.setWorkingDirectory(parameters.getWorkingDirFile());
    Sdk jdk = getJdk(project, runnerSettings, project != null && MavenRunner.getInstance(project).getState() == runnerSettings);
    params.setJdk(jdk);
    final String mavenHome = resolveMavenHome(coreSettings, project, runConfiguration);
    final String mavenVersion = MavenUtil.getMavenVersion(mavenHome);
    String sdkConfigLocation = "Settings | Build, Execution, Deployment | Build Tools | Maven | Runner | JRE";
    verifyMavenSdkRequirements(jdk, mavenVersion, sdkConfigLocation);
    params.getProgramParametersList().add("-Didea.version=" + MavenUtil.getIdeaVersionToPassToMavenProcess());
    if (StringUtil.compareVersionNumbers(mavenVersion, "3.3") >= 0) {
        params.getVMParametersList().addProperty("maven.multiModuleProjectDirectory", MavenServerUtil.findMavenBasedir(parameters.getWorkingDirFile()).getPath());
    }
    addVMParameters(params.getVMParametersList(), mavenHome, runnerSettings);
    File confFile = MavenUtil.getMavenConfFile(new File(mavenHome));
    if (!confFile.isFile()) {
        throw new ExecutionException("Configuration file is not exists in maven home: " + confFile.getAbsolutePath());
    }
    if (project != null && parameters.isResolveToWorkspace()) {
        try {
            String resolverJar = getArtifactResolverJar(mavenVersion);
            confFile = patchConfFile(confFile, resolverJar);
            File modulesPathsFile = dumpModulesPaths(project);
            params.getVMParametersList().addProperty(MavenModuleMap.PATHS_FILE_PROPERTY, modulesPathsFile.getAbsolutePath());
        } catch (IOException e) {
            LOG.error(e);
            throw new ExecutionException("Failed to run maven configuration", e);
        }
    }
    params.getVMParametersList().addProperty("classworlds.conf", confFile.getPath());
    for (String path : getMavenClasspathEntries(mavenHome)) {
        params.getClassPath().add(path);
    }
    params.setEnv(new HashMap<>(runnerSettings.getEnvironmentProperties()));
    params.setPassParentEnvs(runnerSettings.isPassParentEnv());
    params.setMainClass(MAVEN_LAUNCHER_CLASS);
    EncodingManager encodingManager = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project);
    params.setCharset(encodingManager.getDefaultCharset());
    addMavenParameters(params.getProgramParametersList(), mavenHome, coreSettings, runnerSettings, parameters);
    return params;
}
Also used : EncodingManager(com.intellij.openapi.vfs.encoding.EncodingManager) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) JavaParameters(com.intellij.execution.configurations.JavaParameters) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

EncodingManager (com.intellij.openapi.vfs.encoding.EncodingManager)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionException (com.intellij.execution.ExecutionException)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 MavenGeneralSettings (org.jetbrains.idea.maven.project.MavenGeneralSettings)1