blob: ca8e3115547fb1e3c2724f4f00a1014df0c43652 [file] [log] [blame]
/*
* 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 org.jetbrains.idea.devkit.run;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
/**
* User: anna
* Date: Dec 3, 2004
*/
public class IdeaLicenseHelper {
@NonNls private static final String LICENSE_PATH_PREFERRED = "idea80.key";
@NonNls private static final String LICENSE_PATH_70 = "idea70.key";
@NonNls private static final String LICENSE_PATH_60 = "idea60.key";
@NonNls private static final String LICENSE_PATH_50 = "idea50.key";
@NonNls private static final String LICENSE_PATH_40 = "idea40.key";
@NonNls private static final String LICENSE_PATH_SYSTEM = "idea.license";
@NonNls private static final String CONFIG_DIR_NAME = "config";
private static final Logger LOG = Logger.getInstance("#org.jetbrains.idea.devkit.run.IdeaLicenseHelper");
@Nullable
public static File isIDEALicenseInSandbox(@NonNls final String configPath, @NonNls final String systemPath, @NonNls final String binPath){
final File config = new File(configPath, LICENSE_PATH_PREFERRED);
if (config.exists()){
return config;
}
final File idea70 = new File(configPath, LICENSE_PATH_70);
if (idea70.exists()){
return idea70;
}
final File idea60 = new File(configPath, LICENSE_PATH_60);
if (idea60.exists()){
return idea60;
}
final File idea5 = new File(configPath, LICENSE_PATH_50);
if (idea5.exists()){
return idea5;
}
final File idea4 = new File(configPath, LICENSE_PATH_40);
if (idea4.exists()){
return idea4;
}
final File system = new File(systemPath, LICENSE_PATH_SYSTEM);
if (system.exists()){
return system;
}
final File bin = new File(binPath, LICENSE_PATH_SYSTEM);
if (bin.exists()){
return bin;
}
return null;
}
public static void copyIDEALicense(final String sandboxHome, Sdk jdk){
if (isIDEALicenseInSandbox(sandboxHome + File.separator + CONFIG_DIR_NAME, sandboxHome + File.separator + "system", jdk.getHomePath() + File.separator + "bin") == null){
final File ideaLicense = isIDEALicenseInSandbox(PathManager.getConfigPath(), PathManager.getSystemPath(), PathManager.getBinPath());
if (ideaLicense != null){
try {
FileUtil.copy(ideaLicense, new File(new File(sandboxHome, CONFIG_DIR_NAME), LICENSE_PATH_PREFERRED));
}
catch (IOException e) {
LOG.error(e);
}
}
}
}
}