From d7dc3f3ea9597ea855b0f30bc1d00e6ede98373b Mon Sep 17 00:00:00 2001 From: Michail Plushnikov Date: Wed, 27 Feb 2019 12:23:50 +0100 Subject: [PATCH] Implementing LombokProjectValidator as StartupActivity catched ProcessCanceledException fixed #560 --- .travis.yml | 2 +- gradle.properties | 2 +- parts/pluginChanges.html | 1 + ...LombokPluginProjectValidatorActivity.java} | 69 +++++++++---------- .../LombokPluginUpdateProjectComponent.java | 17 +++-- .../plushnikov/intellij/plugin/Version.java | 2 +- src/main/resources/META-INF/plugin.xml | 5 +- .../messages/lombokBundle.properties | 9 +-- ...okPluginProjectValidatorActivityTest.java} | 6 +- test-manual/pom.xml | 2 +- 10 files changed, 61 insertions(+), 54 deletions(-) rename src/main/java/de/plushnikov/intellij/plugin/{LombokPluginProjectValidatorComponent.java => LombokPluginProjectValidatorActivity.java} (74%) rename src/test/java/de/plushnikov/intellij/plugin/{LombokPluginProjectValidatorComponentTest.java => LombokPluginProjectValidatorActivityTest.java} (91%) diff --git a/.travis.yml b/.travis.yml index 7b0c2c7af..3c90ff219 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ cache: env: - IDEA_VERSION=LATEST-EAP-SNAPSHOT UPLOAD_BUILD=true - - IDEA_VERSION=2018.3.4 UPLOAD_BUILD=false + - IDEA_VERSION=2018.3.5 UPLOAD_BUILD=false - IDEA_VERSION=2018.3 UPLOAD_BUILD=true - IDEA_VERSION=2018.2 UPLOAD_BUILD=true - IDEA_VERSION=2018.1 UPLOAD_BUILD=true diff --git a/gradle.properties b/gradle.properties index 15d9aa80d..bda151300 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ ideaVersion=2018.1 #ideaVersion=2018.1.6 #ideaVersion=2018.2 #ideaVersion=2018.2.6 -#ideaVersion=2018.3.4 +#ideaVersion=2018.3.5 #ideaVersion=191.5109.14 #ideaVersion=LATEST-EAP-SNAPSHOT #ideaVersion = LATEST-TRUNK-SNAPSHOT diff --git a/parts/pluginChanges.html b/parts/pluginChanges.html index 9da145e6c..3eba03a65 100644 --- a/parts/pluginChanges.html +++ b/parts/pluginChanges.html @@ -3,6 +3,7 @@
  1. Fixed #353: Support for fieldDefaults in lombok.config
  2. Fixed #547: Updated support for FieldNameConstants
  3. +
  4. Fixed #560: ProcessCanceledException when opening project
  5. Fixed #577: 'SIMPLE_BAD_CHARACTER' error thrown during IntelliJ startup
  6. Fixed #584: AccessLevel not being respected for staticConstructorMethod by @All/@RequiredArgsConstructor
  7. Fixed #593: Constructor body context is not set properly
  8. diff --git a/src/main/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorComponent.java b/src/main/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorActivity.java similarity index 74% rename from src/main/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorComponent.java rename to src/main/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorActivity.java index 17f9e1695..e940e526e 100644 --- a/src/main/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorComponent.java +++ b/src/main/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorActivity.java @@ -2,14 +2,20 @@ import com.intellij.compiler.CompilerConfiguration; import com.intellij.compiler.options.AnnotationProcessorsConfigurable; -import com.intellij.notification.*; -import com.intellij.openapi.components.AbstractProjectComponent; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.startup.StartupActivity; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiPackage; import de.plushnikov.intellij.plugin.settings.ProjectSettings; @@ -25,70 +31,59 @@ * * @author Alexej Kubarev */ -public class LombokPluginProjectValidatorComponent extends AbstractProjectComponent { - - public LombokPluginProjectValidatorComponent(Project project) { - super(project); - } - - @NotNull - @Override - public String getComponentName() { - return "lombok.ProjectValidatorComponent"; - } +public class LombokPluginProjectValidatorActivity implements StartupActivity { @Override - public void projectOpened() { + public void runActivity(@NotNull Project project) { // If plugin is not enabled - no point to continue - if (!ProjectSettings.isLombokEnabledInProject(myProject)) { + if (!ProjectSettings.isLombokEnabledInProject(project)) { return; } + final boolean hasLombokLibrary = hasLombokLibrary(project); + NotificationGroup group = NotificationGroup.findRegisteredGroup(Version.PLUGIN_NAME); if (group == null) { group = new NotificationGroup(Version.PLUGIN_NAME, NotificationDisplayType.BALLOON, true); } - // Lombok dependency check - boolean hasLombokLibrary = hasLombokLibrary(myProject); - // If dependency is missing and missing dependency notification setting is enabled (defaults to disabled) - if (!hasLombokLibrary && ProjectSettings.isEnabled(myProject, ProjectSettings.IS_MISSING_LOMBOK_CHECK_ENABLED, false)) { + if (!hasLombokLibrary && ProjectSettings.isEnabled(project, ProjectSettings.IS_MISSING_LOMBOK_CHECK_ENABLED, false)) { Notification notification = group.createNotification(LombokBundle.message("config.warn.dependency.missing.title"), - LombokBundle.message("config.warn.dependency.missing.message", myProject.getName()), + LombokBundle.message("config.warn.dependency.missing.message", project.getName()), NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER); - Notifications.Bus.notify(notification, myProject); + Notifications.Bus.notify(notification, project); } // If dependency is present and out of date notification setting is enabled (defaults to disabled) - if (hasLombokLibrary && ProjectSettings.isEnabled(myProject, ProjectSettings.IS_LOMBOK_VERSION_CHECK_ENABLED, false)) { - final ModuleManager moduleManager = ModuleManager.getInstance(myProject); + 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))); if (null != lombokVersion && compareVersionString(lombokVersion, Version.LAST_LOMBOK_VERSION) < 0) { Notification notification = group.createNotification(LombokBundle.message("config.warn.dependency.outdated.title"), - LombokBundle.message("config.warn.dependency.outdated.message", myProject.getName(), module.getName(), lombokVersion, Version.LAST_LOMBOK_VERSION), + LombokBundle.message("config.warn.dependency.outdated.message", project.getName(), module.getName(), lombokVersion, Version.LAST_LOMBOK_VERSION), NotificationType.WARNING, NotificationListener.URL_OPENING_LISTENER); - Notifications.Bus.notify(notification, myProject); + Notifications.Bus.notify(notification, project); } } } // Annotation Processing check - boolean annotationProcessorsEnabled = hasAnnotationProcessorsEnabled(myProject); + boolean annotationProcessorsEnabled = hasAnnotationProcessorsEnabled(project); if (hasLombokLibrary && !annotationProcessorsEnabled) { - String annotationProcessorsConfigName = new AnnotationProcessorsConfigurable(myProject).getDisplayName(); + String annotationProcessorsConfigName = new AnnotationProcessorsConfigurable(project).getDisplayName(); Notification notification = group.createNotification(LombokBundle.message("config.warn.annotation-processing.disabled.title"), - LombokBundle.message("config.warn.annotation-processing.disabled.message", myProject.getName()), + LombokBundle.message("config.warn.annotation-processing.disabled.message", project.getName()), NotificationType.ERROR, - new SettingsOpeningListener(myProject, annotationProcessorsConfigName)); + new SettingsOpeningListener(project, annotationProcessorsConfigName)); - Notifications.Bus.notify(notification, myProject); + Notifications.Bus.notify(notification, project); } } @@ -107,8 +102,12 @@ private boolean hasAnnotationProcessorsEnabled(Project project) { } private boolean hasLombokLibrary(Project project) { - PsiPackage lombokPackage = JavaPsiFacade.getInstance(project).findPackage("lombok"); - + PsiPackage lombokPackage; + try { + lombokPackage = JavaPsiFacade.getInstance(project).findPackage("lombok"); + } catch (ProcessCanceledException ex) { + lombokPackage = null; + } return lombokPackage != null; } @@ -124,11 +123,11 @@ private OrderEntry findLombokEntry(@NotNull ModuleRootManager moduleRootManager) } @Nullable - protected String parseLombokVersion(@Nullable OrderEntry orderEntry) { + String parseLombokVersion(@Nullable OrderEntry orderEntry) { String result = null; if (null != orderEntry) { final String presentableName = orderEntry.getPresentableName(); - Pattern pattern = Pattern.compile("(.*:)([\\d\\.]+)(.*)"); + Pattern pattern = Pattern.compile("(.*:)([\\d.]+)(.*)"); final Matcher matcher = pattern.matcher(presentableName); if (matcher.find()) { result = matcher.group(2); @@ -137,7 +136,7 @@ protected String parseLombokVersion(@Nullable OrderEntry orderEntry) { return result; } - protected int compareVersionString(@NotNull String firstVersionOne, @NotNull String secondVersion) { + int compareVersionString(@NotNull String firstVersionOne, @NotNull String secondVersion) { String[] firstVersionParts = firstVersionOne.split("\\."); String[] secondVersionParts = secondVersion.split("\\."); int length = Math.max(firstVersionParts.length, secondVersionParts.length); diff --git a/src/main/java/de/plushnikov/intellij/plugin/LombokPluginUpdateProjectComponent.java b/src/main/java/de/plushnikov/intellij/plugin/LombokPluginUpdateProjectComponent.java index 486f85ec7..6fb34fef3 100644 --- a/src/main/java/de/plushnikov/intellij/plugin/LombokPluginUpdateProjectComponent.java +++ b/src/main/java/de/plushnikov/intellij/plugin/LombokPluginUpdateProjectComponent.java @@ -1,7 +1,12 @@ package de.plushnikov.intellij.plugin; -import com.intellij.notification.*; -import com.intellij.openapi.components.AbstractProjectComponent; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; +import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.project.Project; import de.plushnikov.intellij.plugin.settings.LombokSettings; import org.jetbrains.annotations.NotNull; @@ -9,10 +14,12 @@ /** * Shows update notification */ -public class LombokPluginUpdateProjectComponent extends AbstractProjectComponent { +public class LombokPluginUpdateProjectComponent implements ProjectComponent { - protected LombokPluginUpdateProjectComponent(Project project) { - super(project); + private final Project myProject; + + public LombokPluginUpdateProjectComponent(Project project) { + myProject = project; } @NotNull diff --git a/src/main/java/de/plushnikov/intellij/plugin/Version.java b/src/main/java/de/plushnikov/intellij/plugin/Version.java index 22814932f..fc938a983 100644 --- a/src/main/java/de/plushnikov/intellij/plugin/Version.java +++ b/src/main/java/de/plushnikov/intellij/plugin/Version.java @@ -9,5 +9,5 @@ public interface Version { /** * Current version of lombok plugin */ - String LAST_LOMBOK_VERSION = "1.18.4"; + String LAST_LOMBOK_VERSION = "1.18.6"; } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index a9d784f7a..e54fc73e5 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -18,9 +18,6 @@ de.plushnikov.intellij.plugin.LombokPluginUpdateProjectComponent - - de.plushnikov.intellij.plugin.LombokPluginProjectValidatorComponent - @@ -29,6 +26,8 @@ + + \ This plugin does not provide it and will not function correctly without.
    \ Please make sure to add it manually and refresh your project.
    \
    \ - Click here to see how to add it to your project. + Click here to see how to add it to your project. config.warn.annotation-processing.disabled.title=Lombok Requires Annotation Processing config.warn.annotation-processing.disabled.message=
    \ - Annotation processing seems to be disabled for the project "{0}".
    \ - For the plugin to function correctly, please enable it under
    \ + Annotation processing seems to be disabled for the project "{0}". But lombok is on classpath.
    \ + For the lombok plugin to function correctly, please enable it under
    \ "Settings > Build > Compiler > Annotation Processors"
    config.warn.dependency.outdated.title=Lombok Dependency is possibly outdated config.warn.dependency.outdated.message=
    \ Project "{0}" and Module "{1}" seem to have outdated lombok dependency added.
    \ Configured version "{2}", but there is at least version "{3}" already released
    \ - Maybe you want to update?
    + Maybe you want to update?
    daemon.donate.title=Lombok support plugin updated to v{0} daemon.donate.content=
    \ @@ -24,6 +24,7 @@ Helpful? Donate with PayPal\ - Fixed (#353): Support for fieldDefaults in lombok.config
    \ - Fixed (#547): Updated support for FieldNameConstants
    \ +- Fixed (#560): ProcessCanceledException when opening project
    \ - Fixed (#577): 'SIMPLE_BAD_CHARACTER' error thrown during IntelliJ startup
    \ - Fixed (#584): AccessLevel not being respected for staticConstructorMethod by @All/@RequiredArgsConstructor
    \ - Fixed (#593): Constructor body context is not set properly
    \ diff --git a/src/test/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorComponentTest.java b/src/test/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorActivityTest.java similarity index 91% rename from src/test/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorComponentTest.java rename to src/test/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorActivityTest.java index db11c2ff0..dcf7cdfc4 100644 --- a/src/test/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorComponentTest.java +++ b/src/test/java/de/plushnikov/intellij/plugin/LombokPluginProjectValidatorActivityTest.java @@ -9,14 +9,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class LombokPluginProjectValidatorComponentTest { +public class LombokPluginProjectValidatorActivityTest { - private LombokPluginProjectValidatorComponent component; + private LombokPluginProjectValidatorActivity component; private OrderEntry orderEntry; @Before public void setUp() { - component = new LombokPluginProjectValidatorComponent(null); + component = new LombokPluginProjectValidatorActivity(); orderEntry = mock(OrderEntry.class); } diff --git a/test-manual/pom.xml b/test-manual/pom.xml index 049820067..b9b5d82f9 100644 --- a/test-manual/pom.xml +++ b/test-manual/pom.xml @@ -22,7 +22,7 @@ org.projectlombok lombok - 1.18.4 + 1.18.6 provided