Skip to content

Commit b642f92

Browse files
committed
Migrate from deprecated IntelliJ plugin components
Closes gh-219
1 parent 20bcdca commit b642f92

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import com.intellij.ide.util.PropertiesComponent;
2626
import com.intellij.openapi.application.ApplicationInfo;
2727
import com.intellij.openapi.application.ApplicationManager;
28-
import com.intellij.openapi.components.ProjectComponent;
2928
import com.intellij.openapi.diagnostic.Logger;
3029
import com.intellij.openapi.extensions.PluginDescriptor;
3130
import com.intellij.openapi.extensions.PluginId;
3231
import com.intellij.openapi.project.Project;
32+
import com.intellij.openapi.util.Disposer;
3333
import com.intellij.psi.codeStyle.CodeStyleManager;
3434
import com.intellij.serviceContainer.ComponentManagerImpl;
3535
import org.picocontainer.MutablePicoContainer;
@@ -42,15 +42,17 @@
4242
import io.spring.format.formatter.intellij.codestyle.monitor.Trigger.State;
4343

4444
/**
45-
* {@link ProjectComponent} to add Spring Java Format IntelliJ support.
45+
* Spring Java Format IntelliJ support added to a {@link Project}.
4646
*
4747
* @author Phillip Webb
4848
*/
49-
public class SpringFormatComponent implements ProjectComponent {
49+
public class SpringFormat {
5050

5151
private static final String CODE_STYLE_MANAGER_KEY = CodeStyleManager.class.getName();
5252

53-
private static final String ACTIVE_PROPERTY = SpringFormatComponent.class.getName() + ".ACTIVE";
53+
private static final String ACTIVE_PROPERTY = SpringFormat.class.getName() + ".ACTIVE";
54+
55+
private static final Logger logger = Logger.getInstance(SpringFormat.class);
5456

5557
private final Project project;
5658

@@ -60,27 +62,21 @@ public class SpringFormatComponent implements ProjectComponent {
6062

6163
private Monitors monitors;
6264

63-
private static final Logger logger = Logger.getInstance(SpringFormatComponent.class);
64-
6565
private PropertiesComponent properties;
6666

67-
protected SpringFormatComponent(Project project) {
67+
protected SpringFormat(Project project) {
6868
this.project = project;
6969
this.statusIndicator = new StatusIndicator(project);
7070
this.properties = PropertiesComponent.getInstance(project);
71-
}
72-
73-
@Override
74-
public void initComponent() {
7571
if (this.properties.getBoolean(ACTIVE_PROPERTY, false)) {
7672
update(State.ACTIVE);
7773
}
7874
this.monitors = new Monitors(this.project, this::update, FileMonitor.factory(), MavenMonitor.factory(),
7975
GradleMonitor.factory());
76+
Disposer.register(project, this::dispose);
8077
}
8178

82-
@Override
83-
public void disposeComponent() {
79+
private void dispose() {
8480
if (this.monitors != null) {
8581
this.monitors.stop();
8682
this.monitors = null;
@@ -158,4 +154,5 @@ private void invokeRegisterServiceInstanceMethod(CodeStyleManager manager, IdeaP
158154
throw new IllegalStateException(ex);
159155
}
160156
}
157+
161158
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2017-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.format.formatter.intellij;
18+
19+
import com.intellij.openapi.project.Project;
20+
import com.intellij.openapi.startup.StartupActivity;
21+
22+
/**
23+
* {@link StartupActivity} hook for {@link SpringFormat}.
24+
*
25+
* @author Phillip Webb
26+
*/
27+
public class SpringFormatStartupActivity implements StartupActivity {
28+
29+
@Override
30+
public void runActivity(Project project) {
31+
new SpringFormat(project);
32+
}
33+
34+
}

spring-javaformat-intellij/spring-javaformat-intellij-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
<vendor url="https://spring.io">Spring Team</vendor>
99
<depends>org.jetbrains.idea.maven</depends>
1010
<depends>org.jetbrains.plugins.gradle</depends>
11-
<project-components>
12-
<component>
13-
<implementation-class>io.spring.format.formatter.intellij.SpringFormatComponent</implementation-class>
14-
<loadForDefaultProject/>
15-
</component>
16-
</project-components>
11+
<extensions defaultExtensionNs="com.intellij">
12+
<postStartupActivity implementation="io.spring.format.formatter.intellij.SpringFormatStartupActivity" />
13+
</extensions>
1714
</idea-plugin>

0 commit comments

Comments
 (0)