KT-3120 The compiler should not depend on the file directory of the libs

#KT-3120 In Progress
This commit is contained in:
Andrey Breslav
2012-12-12 17:35:05 +04:00
parent 968a57fa7c
commit e324d3914f
5 changed files with 87 additions and 38 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.jet.cli.jvm.compiler.*;
import org.jetbrains.jet.config.CommonConfigurationKeys;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.KotlinPathsFromHomeDir;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
@@ -199,7 +200,7 @@ public class BytecodeCompiler {
}
private static KotlinPaths getKotlinPathsForAntTask() {
return new KotlinPaths(PathUtil.getJarPathForClass(BytecodeCompiler.class).getParentFile().getParentFile());
return new KotlinPathsFromHomeDir(PathUtil.getJarPathForClass(BytecodeCompiler.class).getParentFile().getParentFile());
}
}
@@ -51,6 +51,7 @@ import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.SlicedMap;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.KotlinPathsFromHomeDir;
import org.junit.Assert;
import javax.tools.*;
@@ -492,7 +493,7 @@ public class JetTestUtils {
}
public static KotlinPaths getPathsForTests() {
return new KotlinPaths(new File("dist/kotlinc"));
return new KotlinPathsFromHomeDir(new File("dist/kotlinc"));
}
public static JetFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException {
@@ -20,46 +20,22 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
public class KotlinPaths {
// kotlinc directory
private final File homePath;
public KotlinPaths(@NotNull File homePath) {
this.homePath = homePath;
}
public interface KotlinPaths {
@NotNull
File getHomePath();
@NotNull
public File getHomePath() {
return homePath;
}
File getLibPath();
@NotNull
public File getLibPath() {
return new File(homePath, "lib");
}
File getRuntimePath();
@NotNull
public File getRuntimePath() {
return getLibraryFile("kotlin-runtime.jar");
}
File getJdkAnnotationsPath();
@NotNull
public File getJdkAnnotationsPath() {
return getLibraryFile(PathUtil.JDK_ANNOTATIONS_JAR);
}
File getJsLibJsPath();
@NotNull
public File getJsLibJsPath() {
return getLibraryFile(PathUtil.JS_LIB_JS_NAME);
}
@NotNull
public File getJsLibJarPath() {
return getLibraryFile(PathUtil.JS_LIB_JAR_NAME);
}
@NotNull
private File getLibraryFile(@NotNull String fileName) {
return new File(getLibPath(), fileName);
}
File getJsLibJarPath();
}
@@ -0,0 +1,71 @@
/*
* Copyright 2010-2012 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.jet.utils;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class KotlinPathsFromHomeDir implements KotlinPaths {
// kotlinc directory
private final File homePath;
public KotlinPathsFromHomeDir(@NotNull File homePath) {
this.homePath = homePath;
}
@Override
@NotNull
public File getHomePath() {
return homePath;
}
@Override
@NotNull
public File getLibPath() {
return new File(homePath, "lib");
}
@Override
@NotNull
public File getRuntimePath() {
return getLibraryFile("kotlin-runtime.jar");
}
@Override
@NotNull
public File getJdkAnnotationsPath() {
return getLibraryFile(PathUtil.JDK_ANNOTATIONS_JAR);
}
@Override
@NotNull
public File getJsLibJsPath() {
return getLibraryFile(PathUtil.JS_LIB_JS_NAME);
}
@Override
@NotNull
public File getJsLibJarPath() {
return getLibraryFile(PathUtil.JS_LIB_JAR_NAME);
}
@NotNull
private File getLibraryFile(@NotNull String fileName) {
return new File(getLibPath(), fileName);
}
}
@@ -39,12 +39,12 @@ public class PathUtil {
@NotNull
public static KotlinPaths getKotlinPathsForIdeaPlugin() {
return new KotlinPaths(getCompilerPathForIdeaPlugin());
return new KotlinPathsFromHomeDir(getCompilerPathForIdeaPlugin());
}
@NotNull
public static KotlinPaths getKotlinPathsForJpsPlugin() {
return new KotlinPaths(getCompilerPathForJpsPlugin());
return new KotlinPathsFromHomeDir(getCompilerPathForJpsPlugin());
}
@NotNull
@@ -61,12 +61,12 @@ public class PathUtil {
// Not running from a jar, i.e. it is it must be a unit test
return getKotlinPathsForDistDirectory();
}
return new KotlinPaths(getCompilerPathForCompilerJar());
return new KotlinPathsFromHomeDir(getCompilerPathForCompilerJar());
}
@NotNull
public static KotlinPaths getKotlinPathsForDistDirectory() {
return new KotlinPaths(new File("dist/kotlinc"));
return new KotlinPathsFromHomeDir(new File("dist/kotlinc"));
}
@NotNull