Skip to content

Commit 6bfc715

Browse files
leftstickphilwebb
authored andcommitted
Create Visual Studio Code extension
Add Visual Studio Code extension to apply spring-javaformat conventions. See gh-142
1 parent c7fa27d commit 6bfc715

31 files changed

+1224
-0
lines changed

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/bin
2323
build.log
2424
pid
2525
.factorypath
26+
27+
# npm
28+
node_modules/
29+
30+
# vscode
31+
spring-javaformat-vscode/spring-javaformat/out/
32+
spring-javaformat-vscode/spring-javaformat/runtime/
33+
*.vsix

Diff for: README.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ Once the configuration file is created, configure your IDE to use it:
268268

269269

270270

271+
=== Visual Studio Code
272+
The vscode extension provides custom formatter support for Visual Studio Code.
273+
The extension is automatically activated whenever a `.java` file is opened. And it requires a few seconds to warm-up while you start with the first workspace.
274+
275+
276+
271277
=== About the Conventions
272278
Most of the coding conventions and style comes from the Spring Framework and Spring Boot projects.
273279
Spring Framework manually formats code, where as Spring Boot uses automatic formatting.

Diff for: spring-javaformat-vscode/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# spring-javaformat-vscode
2+
3+
`spring-javaformat` extension for visual studio code.
4+
5+
![](./format.gif)
6+
7+
## Prerequisites
8+
9+
* Install [node.js](https://nodejs.org/en/download/)
10+
* Install [yarn](https://yarnpkg.com/en/docs/install)
11+
* Install [vsce](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#vsce)
12+
13+
## Generate extension
14+
15+
Just `mvn clean package`
16+
17+
18+
> `spring-javaformat-1.0.0.vsix` will be generated there
19+

Diff for: spring-javaformat-vscode/format.gif

1.75 MB
Loading

Diff for: spring-javaformat-vscode/pom.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.spring.javaformat</groupId>
8+
<artifactId>spring-javaformat-build</artifactId>
9+
<version>0.0.36-SNAPSHOT</version>
10+
</parent>
11+
<artifactId>spring-javaformat-vscode</artifactId>
12+
<packaging>pom</packaging>
13+
<name>Spring JavaFormat Visual Studio Code</name>
14+
<properties>
15+
<main.basedir>${basedir}/..</main.basedir>
16+
</properties>
17+
<modules>
18+
<module>spring-javaformat-format-service</module>
19+
</modules>
20+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "java",
5+
"name": "CodeLens (Launch) - FormatterWebApplication",
6+
"request": "launch",
7+
"mainClass": "io.spring.format.FormatterWebApplication",
8+
"projectName": "spring-javaformat-format-service"
9+
}
10+
]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"java.format.enabled": false
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>io.spring.javaformat</groupId>
7+
<artifactId>spring-javaformat-vscode</artifactId>
8+
<version>0.0.36-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>spring-javaformat-format-service</artifactId>
11+
<packaging>jar</packaging>
12+
<name>Spring JavaFormat format-service</name>
13+
<properties>
14+
<main.basedir>${basedir}/../..</main.basedir>
15+
</properties>
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-maven-plugin</artifactId>
21+
<version>2.1.8.RELEASE</version>
22+
<configuration>
23+
<outputDirectory>${main.basedir}/spring-javaformat-vscode/spring-javaformat/runtime/</outputDirectory>
24+
</configuration>
25+
<executions>
26+
<execution>
27+
<goals>
28+
<goal>repackage</goal>
29+
</goals>
30+
</execution>
31+
</executions>
32+
</plugin>
33+
<plugin>
34+
<groupId>org.codehaus.mojo</groupId>
35+
<artifactId>exec-maven-plugin</artifactId>
36+
<configuration>
37+
<workingDirectory>${main.basedir}/spring-javaformat-vscode/spring-javaformat</workingDirectory>
38+
</configuration>
39+
<executions>
40+
<execution>
41+
<id>exec-yarn-install</id>
42+
<phase>compile</phase>
43+
<configuration>
44+
<executable>yarn</executable>
45+
</configuration>
46+
<goals>
47+
<goal>exec</goal>
48+
</goals>
49+
</execution>
50+
<execution>
51+
<id>exec-package</id>
52+
<phase>package</phase>
53+
<configuration>
54+
<executable>vsce</executable>
55+
<arguments>
56+
<argument>package</argument>
57+
</arguments>
58+
</configuration>
59+
<goals>
60+
<goal>exec</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-checkstyle-plugin</artifactId>
68+
<executions>
69+
<execution>
70+
<id>checkstyle-validation</id>
71+
<phase>validate</phase>
72+
<configuration>
73+
<excludes>**/*/FormatterWebApplication.java</excludes>
74+
</configuration>
75+
</execution>
76+
</executions>
77+
</plugin>
78+
<plugin>
79+
<groupId>io.spring.javaformat</groupId>
80+
<artifactId>spring-javaformat-maven-plugin</artifactId>
81+
<version>0.0.16-SNAPSHOT</version>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
<dependencyManagement>
86+
<dependencies>
87+
<dependency>
88+
<groupId>org.springframework.boot</groupId>
89+
<artifactId>spring-boot-dependencies</artifactId>
90+
<version>2.1.6.RELEASE</version>
91+
<type>pom</type>
92+
<scope>import</scope>
93+
</dependency>
94+
</dependencies>
95+
</dependencyManagement>
96+
<dependencies>
97+
<!-- Compile -->
98+
<dependency>
99+
<groupId>org.springframework.boot</groupId>
100+
<artifactId>spring-boot-starter</artifactId>
101+
<version>2.1.6.RELEASE</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.springframework.boot</groupId>
105+
<artifactId>spring-boot-starter-web</artifactId>
106+
<version>2.1.6.RELEASE</version>
107+
</dependency>
108+
<dependency>
109+
<groupId>io.spring.javaformat</groupId>
110+
<artifactId>spring-javaformat-formatter</artifactId>
111+
<version>${project.version}</version>
112+
</dependency>
113+
<!-- Provided -->
114+
<dependency>
115+
<groupId>io.spring.javaformat</groupId>
116+
<artifactId>spring-javaformat-formatter-eclipse-runtime</artifactId>
117+
<version>${project.version}</version>
118+
<scope>provided</scope>
119+
</dependency>
120+
</dependencies>
121+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2017-2019 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;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.scheduling.annotation.EnableScheduling;
22+
23+
@EnableScheduling
24+
@SpringBootApplication
25+
public class FormatterWebApplication {
26+
27+
public FormatterWebApplication() {
28+
29+
}
30+
31+
public static void main(String[] args) {
32+
SpringApplication.run(FormatterWebApplication.class, args);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2017-2019 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.controllers;
18+
19+
import org.springframework.web.bind.annotation.RequestBody;
20+
import org.springframework.web.bind.annotation.RequestMapping;
21+
import org.springframework.web.bind.annotation.RequestMethod;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
import io.spring.format.request.FormatRequest;
25+
import io.spring.format.tools.FormatContent;
26+
27+
/**
28+
* .
29+
*
30+
* @author Howard Zuo
31+
*/
32+
@RestController
33+
public class FormatController {
34+
35+
@RequestMapping(method = RequestMethod.POST, value = "/format/code")
36+
String formatSource(@RequestBody FormatRequest req) {
37+
38+
return FormatContent.formatContent(req.getSource());
39+
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2017-2019 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.controllers;
18+
19+
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.springframework.web.bind.annotation.RequestMapping;
21+
import org.springframework.web.bind.annotation.RequestMethod;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
import io.spring.format.services.HealthService;
25+
26+
/**
27+
* .
28+
*
29+
* @author Howard Zuo
30+
*/
31+
@RestController
32+
public class HealthController {
33+
34+
@Autowired
35+
private HealthService service;
36+
37+
@RequestMapping(method = RequestMethod.GET, value = "/health")
38+
String heartbeat() {
39+
this.service.setLastHeartbeat(System.currentTimeMillis());
40+
return "";
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2017-2019 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.request;
18+
19+
/**
20+
* .
21+
*
22+
* @author Howard Zuo
23+
*/
24+
public class FormatRequest {
25+
26+
private String source = "";
27+
28+
public void setSource(String source) {
29+
this.source = source;
30+
}
31+
32+
public String getSource() {
33+
return this.source;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)