Skip to content

Commit

Permalink
Implementing LombokProjectValidator as StartupActivity
Browse files Browse the repository at this point in the history
catched ProcessCanceledException
fixed projectlombok#560
  • Loading branch information
mplushnikov committed Feb 27, 2019
1 parent 6aa7d36 commit d7dc3f3
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions parts/pluginChanges.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ol>
<li>Fixed #353: Support for fieldDefaults in lombok.config</li>
<li>Fixed #547: Updated support for FieldNameConstants</li>
<li>Fixed #560: ProcessCanceledException when opening project</li>
<li>Fixed #577: 'SIMPLE_BAD_CHARACTER' error thrown during IntelliJ startup</li>
<li>Fixed #584: AccessLevel not being respected for staticConstructorMethod by @All/@RequiredArgsConstructor</li>
<li>Fixed #593: Constructor body context is not set properly</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
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;

/**
* 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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/plushnikov/intellij/plugin/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
5 changes: 2 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
<component>
<implementation-class>de.plushnikov.intellij.plugin.LombokPluginUpdateProjectComponent</implementation-class>
</component>
<component>
<implementation-class>de.plushnikov.intellij.plugin.LombokPluginProjectValidatorComponent</implementation-class>
</component>
</project-components>

<extensionPoints>
Expand All @@ -29,6 +26,8 @@
</extensionPoints>

<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="de.plushnikov.intellij.plugin.LombokPluginProjectValidatorActivity"/>

<applicationService serviceImplementation="de.plushnikov.intellij.plugin.processor.handler.BuilderHandler"/>
<applicationService serviceImplementation="de.plushnikov.intellij.plugin.processor.handler.DelegateHandler"/>
<applicationService
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/messages/lombokBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ config.warn.dependency.missing.message=<br>\
This plugin <b>does not</b> provide it and will not function correctly without.<br>\
Please make sure to add it manually and refresh your project.<br>\
<br>\
<b><a href="https://projectlombok.org/mavenrepo/index.html">Click here to see how to add it to your project.</a></b>
<b><a href="https://projectlombok.org/setup/overview">Click here to see how to add it to your project.</a></b>

config.warn.annotation-processing.disabled.title=Lombok Requires Annotation Processing
config.warn.annotation-processing.disabled.message=<br>\
Annotation processing seems to be disabled for the project "{0}".<br>\
For the plugin to function correctly, please enable it under<br>\
Annotation processing seems to be disabled for the project "{0}". But lombok is on classpath.<br>\
For the lombok plugin to function correctly, please enable it under<br>\
<a href="#">"Settings > Build > Compiler > Annotation Processors"</a><br>

config.warn.dependency.outdated.title=Lombok Dependency is possibly outdated
config.warn.dependency.outdated.message=<br>\
Project "{0}" and Module "{1}" seem to have outdated lombok dependency added.<br>\
Configured version "{2}", but there is at least version "{3}" already released<br>\
<a href="https://projectlombok.org/download.html">Maybe you want to update?</a> <br>
<a href="https://projectlombok.org/download">Maybe you want to update?</a> <br>

daemon.donate.title=Lombok support plugin updated to v{0}
daemon.donate.content=<br/>\
Helpful? <b><a href="https://www.paypal.me/mplushnikov">Donate with PayPal</a></b><br/><br/>\
Fixes:<br/>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/353">#353</a>): Support for fieldDefaults in lombok.config<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/547">#547</a>): Updated support for FieldNameConstants<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/560">#560</a>): ProcessCanceledException when opening project<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/577">#577</a>): 'SIMPLE_BAD_CHARACTER' error thrown during IntelliJ startup<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/584">#584</a>): AccessLevel not being respected for staticConstructorMethod by @All/@RequiredArgsConstructor<br>\
- Fixed (<a href="https://github.com/mplushnikov/lombok-intellij-plugin/issues/593">#593</a>): Constructor body context is not set properly<br>\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test-manual/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>

Expand Down

0 comments on commit d7dc3f3

Please sign in to comment.