mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lombok: ensure 2020.3 works with old lombok versions (IDEA-253011)
GitOrigin-RevId: 5e12a0999c3353e11a12e5cc693cf3465de71f78
This commit is contained in:
committed by
intellij-monorepo-bot
parent
48c632942f
commit
e10f0e71c5
@@ -1,9 +1,49 @@
|
||||
package de.plushnikov.intellij.plugin;
|
||||
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public interface Version {
|
||||
String PLUGIN_NAME = "Lombok plugin";
|
||||
/**
|
||||
* Current version of lombok plugin
|
||||
*/
|
||||
String LAST_LOMBOK_VERSION = "1.18.16";
|
||||
|
||||
|
||||
@Nullable
|
||||
static String parseLombokVersion(@Nullable OrderEntry orderEntry) {
|
||||
String result = null;
|
||||
if (orderEntry != null) {
|
||||
final String presentableName = orderEntry.getPresentableName();
|
||||
final Matcher matcher = Pattern.compile("(.*:)([\\d.]+)(.*)").matcher(presentableName);
|
||||
if (matcher.find()) {
|
||||
result = matcher.group(2);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int compareVersionString(@NotNull String firstVersionOne, @NotNull String secondVersion) {
|
||||
String[] firstVersionParts = firstVersionOne.split("\\.");
|
||||
String[] secondVersionParts = secondVersion.split("\\.");
|
||||
int length = Math.max(firstVersionParts.length, secondVersionParts.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
int firstPart = i < firstVersionParts.length && !firstVersionParts[i].isEmpty() ?
|
||||
Integer.parseInt(firstVersionParts[i]) : 0;
|
||||
int secondPart = i < secondVersionParts.length && !secondVersionParts[i].isEmpty() ?
|
||||
Integer.parseInt(secondVersionParts[i]) : 0;
|
||||
if (firstPart < secondPart) {
|
||||
return -1;
|
||||
}
|
||||
if (firstPart > secondPart) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-39
@@ -32,8 +32,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.compiler.AnnotationProcessingConfiguration;
|
||||
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Shows notifications about project setup issues, that make the plugin not working.
|
||||
@@ -41,9 +39,6 @@ import java.util.regex.Pattern;
|
||||
* @author Alexej Kubarev
|
||||
*/
|
||||
public class LombokProjectValidatorActivity implements StartupActivity.DumbAware {
|
||||
|
||||
private static final Pattern LOMBOK_VERSION_PATTERN = Pattern.compile("(.*:)([\\d.]+)(.*)");
|
||||
|
||||
@Override
|
||||
public void runActivity(@NotNull Project project) {
|
||||
// If plugin is not enabled - no point to continue
|
||||
@@ -67,9 +62,9 @@ public class LombokProjectValidatorActivity implements StartupActivity.DumbAware
|
||||
if (hasLombokLibrary && ProjectSettings.isEnabled(project, ProjectSettings.IS_LOMBOK_VERSION_CHECK_ENABLED, false)) {
|
||||
final ModuleManager moduleManager = ModuleManager.getInstance(project);
|
||||
for (Module module : moduleManager.getModules()) {
|
||||
String lombokVersion = parseLombokVersion(findLombokEntry(ModuleRootManager.getInstance(module)));
|
||||
String lombokVersion = Version.parseLombokVersion(findLombokEntry(ModuleRootManager.getInstance(module)));
|
||||
|
||||
if (null != lombokVersion && compareVersionString(lombokVersion, Version.LAST_LOMBOK_VERSION) < 0) {
|
||||
if (null != lombokVersion && Version.compareVersionString(lombokVersion, Version.LAST_LOMBOK_VERSION) < 0) {
|
||||
return getNotificationGroup().createNotification(LombokBundle.message("config.warn.dependency.outdated.title"),
|
||||
LombokBundle
|
||||
.message("config.warn.dependency.outdated.message", project.getName(),
|
||||
@@ -156,36 +151,4 @@ public class LombokProjectValidatorActivity implements StartupActivity.DumbAware
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String parseLombokVersion(@Nullable OrderEntry orderEntry) {
|
||||
String result = null;
|
||||
if (null != orderEntry) {
|
||||
final String presentableName = orderEntry.getPresentableName();
|
||||
final Matcher matcher = LOMBOK_VERSION_PATTERN.matcher(presentableName);
|
||||
if (matcher.find()) {
|
||||
result = matcher.group(2);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int compareVersionString(@NotNull String firstVersionOne, @NotNull String secondVersion) {
|
||||
String[] firstVersionParts = firstVersionOne.split("\\.");
|
||||
String[] secondVersionParts = secondVersion.split("\\.");
|
||||
int length = Math.max(firstVersionParts.length, secondVersionParts.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
int firstPart = i < firstVersionParts.length && !firstVersionParts[i].isEmpty() ?
|
||||
Integer.parseInt(firstVersionParts[i]) : 0;
|
||||
int secondPart = i < secondVersionParts.length && !secondVersionParts[i].isEmpty() ?
|
||||
Integer.parseInt(secondVersionParts[i]) : 0;
|
||||
if (firstPart < secondPart) {
|
||||
return -1;
|
||||
}
|
||||
if (firstPart > secondPart) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package de.plushnikov.intellij.plugin.jps;
|
||||
|
||||
import com.intellij.compiler.server.BuildProcessParametersProvider;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import de.plushnikov.intellij.plugin.LombokClassNames;
|
||||
import de.plushnikov.intellij.plugin.Version;
|
||||
import de.plushnikov.intellij.plugin.activity.LombokProjectValidatorActivity;
|
||||
import de.plushnikov.intellij.plugin.settings.ProjectSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class LombokBuildProcessParametersProvider extends BuildProcessParametersProvider {
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
public LombokBuildProcessParametersProvider(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> getVMArguments() {
|
||||
if (ProjectSettings.isLombokEnabledInProject(myProject) && LombokProjectValidatorActivity.hasLombokLibrary(myProject)) {
|
||||
return CachedValuesManager.getManager(myProject).getCachedValue(myProject,
|
||||
() -> {
|
||||
List<String> disableOptions =
|
||||
ReadAction.compute(() -> disableOptimisation())
|
||||
? Collections.singletonList("-Djps.track.ap.dependencies=false")
|
||||
: Collections.emptyList();
|
||||
return new CachedValueProvider.Result<>(disableOptions, ProjectRootManager.getInstance(myProject));
|
||||
});
|
||||
|
||||
}
|
||||
return super.getVMArguments();
|
||||
}
|
||||
|
||||
private boolean disableOptimisation() {
|
||||
PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass(LombokClassNames.BUILDER, GlobalSearchScope.allScope(myProject));
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(aClass);
|
||||
if (virtualFile != null) {
|
||||
List<OrderEntry> entries = ProjectRootManager.getInstance(myProject).getFileIndex().getOrderEntriesForFile(virtualFile);
|
||||
if (!entries.isEmpty()) {
|
||||
String lombokVersion = Version.parseLombokVersion(entries.get(0));
|
||||
if (lombokVersion != null && Version.compareVersionString(lombokVersion, "1.18.16") < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -256,6 +256,7 @@
|
||||
|
||||
<codeInsight.template.postfixTemplateProvider language="JAVA"
|
||||
implementationClass="de.plushnikov.intellij.plugin.extension.postfix.LombokPostfixTemplateProvider"/>
|
||||
<buildProcess.parametersProvider implementation="de.plushnikov.intellij.plugin.jps.LombokBuildProcessParametersProvider"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
||||
+11
-12
@@ -1,6 +1,7 @@
|
||||
package de.plushnikov.intellij.plugin.activity;
|
||||
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import de.plushnikov.intellij.plugin.Version;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,65 +12,63 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class LombokProjectValidatorActivityTest {
|
||||
|
||||
private LombokProjectValidatorActivity component;
|
||||
private OrderEntry orderEntry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
component = new LombokProjectValidatorActivity();
|
||||
orderEntry = mock(OrderEntry.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLombokVersionFromGradle() {
|
||||
when(orderEntry.getPresentableName()).thenReturn("Gradle: org.projectlombok:lombok:1.16.8");
|
||||
assertEquals("1.16.8", component.parseLombokVersion(orderEntry));
|
||||
assertEquals("1.16.8", Version.parseLombokVersion(orderEntry));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLombokVersionFromMaven() {
|
||||
when(orderEntry.getPresentableName()).thenReturn("Maven: org.projectlombok:lombok:1.16.6");
|
||||
assertEquals("1.16.6", component.parseLombokVersion(orderEntry));
|
||||
assertEquals("1.16.6", Version.parseLombokVersion(orderEntry));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLombokVersionFromUnknown() {
|
||||
when(orderEntry.getPresentableName()).thenReturn("lombok");
|
||||
assertNull(component.parseLombokVersion(orderEntry));
|
||||
assertNull(Version.parseLombokVersion(orderEntry));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString1_2() {
|
||||
assertEquals(-1, component.compareVersionString("1", "2"));
|
||||
assertEquals(-1, Version.compareVersionString("1", "2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString__2() {
|
||||
assertEquals(-1, component.compareVersionString("", "2"));
|
||||
assertEquals(-1, Version.compareVersionString("", "2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString123_121() {
|
||||
assertEquals(1, component.compareVersionString("1.2.3", "1.2.1"));
|
||||
assertEquals(1, Version.compareVersionString("1.2.3", "1.2.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString1166_1168() {
|
||||
assertEquals(-1, component.compareVersionString("1.16.6", "1.16.8"));
|
||||
assertEquals(-1, Version.compareVersionString("1.16.6", "1.16.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString1168_1168() {
|
||||
assertEquals(0, component.compareVersionString("1.16.8", "1.16.8"));
|
||||
assertEquals(0, Version.compareVersionString("1.16.8", "1.16.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString0102_1168() {
|
||||
assertEquals(-1, component.compareVersionString("0.10.2", "1.16.8"));
|
||||
assertEquals(-1, Version.compareVersionString("0.10.2", "1.16.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareVersionString1169_1168() {
|
||||
assertEquals(1, component.compareVersionString("1.16.9", "1.16.8"));
|
||||
assertEquals(1, Version.compareVersionString("1.16.9", "1.16.8"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user