/* * Copyright 2000-2009 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.intellij.openapi.projectRoots; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.impl.SdkVersionUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.io.File; /** * @author Gregory.Shrago */ public class SimpleJavaSdkType extends SdkType implements JavaSdkType { // do not use javaw.exe for Windows because of issues with encoding @NonNls private static final String VM_EXE_NAME = "java"; public SimpleJavaSdkType() { super("SimpleJavaSdkType"); } public Sdk createJdk(final String jdkName, final String home) { final Sdk jdk = SdkTable.getInstance().createSdk(jdkName, this); SdkModificator sdkModificator = jdk.getSdkModificator(); String path = home.replace(File.separatorChar, '/'); sdkModificator.setHomePath(path); sdkModificator.commitChanges(); return jdk; } @NotNull @Override public String getPresentableName() { return ProjectBundle.message("sdk.java.name"); } @Nullable @Override public Icon getIcon() { return null; } @Override public String getBinPath(Sdk sdk) { return getConvertedHomePath(sdk) + "bin"; } @Override @NonNls public String getToolsPath(Sdk sdk) { final String versionString = sdk.getVersionString(); final boolean isJdk1_x = versionString != null && (versionString.contains("1.0") || versionString.contains("1.1")); return getConvertedHomePath(sdk) + "lib" + File.separator + (isJdk1_x? "classes.zip" : "tools.jar"); } @Override public void setupCommandLine(@NotNull GeneralCommandLine commandLine, @NotNull Sdk sdk) { commandLine.setExePath(getBinPath(sdk) + File.separator + VM_EXE_NAME); } private static String getConvertedHomePath(Sdk sdk) { String path = sdk.getHomePath().replace('/', File.separatorChar); if (!path.endsWith(File.separator)) { path += File.separator; } return path; } @Override public boolean isValidSdkHome(String path) { return JdkUtil.checkForJdk(new File(path)); } @Override public String suggestSdkName(String currentSdkName, String sdkHome) { return currentSdkName; } @Override public final String getVersionString(final String sdkHome) { return SdkVersionUtil.detectJdkVersion(sdkHome); } }