update copyright
[fedora-idea.git] / plugins / devkit / src / run / IdeaLicenseHelper.java
blob84dc5a02f61e1bfd659b4345eea6bffeee430f29
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.devkit.run;
18 import com.intellij.openapi.application.PathManager;
19 import com.intellij.openapi.diagnostic.Logger;
20 import com.intellij.openapi.projectRoots.Sdk;
21 import com.intellij.openapi.util.io.FileUtil;
22 import org.jetbrains.annotations.NonNls;
23 import org.jetbrains.annotations.Nullable;
25 import java.io.File;
26 import java.io.IOException;
28 /**
29 * User: anna
30 * Date: Dec 3, 2004
32 public class IdeaLicenseHelper {
33 @NonNls private static final String LICENSE_PATH_PREFERRED = "idea80.key";
34 @NonNls private static final String LICENSE_PATH_70 = "idea70.key";
35 @NonNls private static final String LICENSE_PATH_60 = "idea60.key";
36 @NonNls private static final String LICENSE_PATH_50 = "idea50.key";
37 @NonNls private static final String LICENSE_PATH_40 = "idea40.key";
38 @NonNls private static final String LICENSE_PATH_SYSTEM = "idea.license";
40 @NonNls private static final String CONFIG_DIR_NAME = "config";
42 private static final Logger LOG = Logger.getInstance("#org.jetbrains.idea.devkit.run.IdeaLicenseHelper");
44 @Nullable
45 public static File isIDEALicenseInSandbox(@NonNls final String configPath, @NonNls final String systemPath, @NonNls final String binPath){
46 final File config = new File(configPath, LICENSE_PATH_PREFERRED);
47 if (config.exists()){
48 return config;
50 final File idea70 = new File(configPath, LICENSE_PATH_70);
51 if (idea70.exists()){
52 return idea70;
54 final File idea60 = new File(configPath, LICENSE_PATH_60);
55 if (idea60.exists()){
56 return idea60;
58 final File idea5 = new File(configPath, LICENSE_PATH_50);
59 if (idea5.exists()){
60 return idea5;
62 final File idea4 = new File(configPath, LICENSE_PATH_40);
63 if (idea4.exists()){
64 return idea4;
66 final File system = new File(systemPath, LICENSE_PATH_SYSTEM);
67 if (system.exists()){
68 return system;
70 final File bin = new File(binPath, LICENSE_PATH_SYSTEM);
71 if (bin.exists()){
72 return bin;
74 return null;
77 public static void copyIDEALicencse(final String sandboxHome, Sdk jdk){
78 if (isIDEALicenseInSandbox(sandboxHome + File.separator + CONFIG_DIR_NAME, sandboxHome + File.separator + "system", jdk.getHomePath() + File.separator + "bin") == null){
79 final File ideaLicense = isIDEALicenseInSandbox(PathManager.getConfigPath(), PathManager.getSystemPath(), PathManager.getBinPath());
80 if (ideaLicense != null){
81 try {
82 FileUtil.copy(ideaLicense, new File(new File(sandboxHome, CONFIG_DIR_NAME), LICENSE_PATH_PREFERRED));
84 catch (IOException e) {
85 LOG.error(e);