Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
merged with backported changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
mplushnikov committed Oct 3, 2019
1 parent a92e6fb commit 3f685ef
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions src/test/java/de/plushnikov/intellij/plugin/LombokTestUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.plushnikov.intellij.plugin;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.Sdk;
Expand All @@ -11,25 +9,21 @@
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
import com.intellij.util.PathUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class LombokTestUtil {
private static final String LOMBOK_LIBRARY_DIRECTORY = "lib";
private static final String LOMBOK_JAR_NAME = "lombok-1.18.10.jar";

public static void loadLombokLibrary(@NotNull JavaCodeInsightTestFixture projectDisposable, @NotNull Module module) {
public static void loadLombokLibrary(@NotNull JavaCodeInsightTestFixture fixture, @NotNull Module module) {
final String lombokLibPath = PathUtil.toSystemIndependentName(new File(LOMBOK_LIBRARY_DIRECTORY).getAbsolutePath());
addLibrary(projectDisposable, module, "Lombok Library", lombokLibPath, LOMBOK_JAR_NAME);
addLibrary(fixture, module, "Lombok Library", lombokLibPath, LOMBOK_JAR_NAME);
}

public static LightProjectDescriptor getProjectDescriptor() {
Expand All @@ -46,31 +40,12 @@ public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel
};
}

@NotNull
public static String getTestDataPathRelativeToIdeaHome(@NotNull String relativePath) {
File homePath = new File(PathManager.getHomePath());
File testDir = new File(getTestDataRoot(), relativePath);

String relativePathToIdeaHome = FileUtil.getRelativePath(homePath, testDir);
if (relativePathToIdeaHome == null) {
throw new RuntimeException("getTestDataPathRelativeToIdeaHome: FileUtil.getRelativePath('" + homePath +
"', '" + testDir + "') returned null");
}

return relativePathToIdeaHome;
}

/*
* For IntelliJ >= 2017.3 we need to call PsiTestUtil.addLibrary with Disposable parameter
* For IntelliJ <2017.3 we can use default PsiTestUtil.addLibrary version
*/
public static void addLibrary(JavaCodeInsightTestFixture parent, Module module, String libName, String libPath, String jarArr) {
private static void addLibrary(JavaCodeInsightTestFixture parent, Module module, String libName, String libPath, String jarArr) {
VfsRootAccess.allowRootAccess(libPath);
PsiTestUtil.addLibrary(module, libName, libPath, jarArr);
}

public static void addLibrary(Disposable projectDisposable, Module module, String libName, String libPath, String jarArr) {
PsiTestUtil.addLibrary(module, libName, libPath, jarArr);
}

}

0 comments on commit 3f685ef

Please sign in to comment.