Skip to content

Commit 64a6d44

Browse files
authored
style: add linter (#84)
1 parent c65ab95 commit 64a6d44

File tree

38 files changed

+853
-763
lines changed

38 files changed

+853
-763
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
name: CI
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
jobs:
610
build:
711

812
runs-on: ubuntu-latest
913

1014
steps:
11-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v4
1216

13-
- name: Start all the environment
14-
run: docker-compose up -d
17+
- name: 🐳 Start all the environment
18+
run: make start
1519

16-
- name: Wait for the environment to get up
20+
- name: 🔦 Lint
21+
run: make lint
22+
23+
- name: 🦭 Wait for the environment to get up
1724
run: |
1825
while ! make ping-mysql &>/dev/null; do
1926
echo "Waiting for database connection..."
2027
sleep 2
2128
done
2229
23-
- name: Run the tests
30+
- name: Run the tests
2431
run: make test

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
FROM openjdk:21-slim-buster
22
WORKDIR /app
3+
4+
RUN apt update && apt install -y curl git
5+
6+
ENV NVM_DIR /usr/local/nvm
7+
ENV NODE_VERSION 18.0.0
8+
9+
RUN mkdir -p $NVM_DIR
10+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
11+
12+
RUN . $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default
13+
14+
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
15+
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

Makefile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
1-
.PHONY: all
21
all: build
32

4-
.PHONY: up
5-
up:
6-
@docker-compose up -d
3+
start:
4+
@docker compose up -d
75

8-
.PHONY: build
96
build:
107
@./gradlew build --warning-mode all
118

12-
.PHONY: run-tests
9+
lint:
10+
@docker exec codelytv-ddd_example-java ./gradlew spotlessCheck
11+
1312
run-tests:
1413
@./gradlew test --warning-mode all
1514

16-
.PHONY: test
1715
test:
1816
@docker exec codelytv-ddd_example-java ./gradlew test --warning-mode all
1917

20-
.PHONY: run
2118
run:
2219
@./gradlew :run
2320

24-
.PHONY: ping-mysql
2521
ping-mysql:
2622
@docker exec codelytv-java_ddd_example-mysql mysqladmin --user=root --password= --host "127.0.0.1" ping --silent
2723

2824
# Start the app
29-
.PHONY: start-mooc_backend
3025
start-mooc_backend:
3126
@./gradlew bootRun --args='mooc_backend server'
3227

33-
.PHONY: start-backoffice_frontend
3428
start-backoffice_frontend:
3529
@./gradlew bootRun --args='backoffice_frontend server'
Lines changed: 84 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,96 @@
11
package tv.codely.apps;
22

3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
36
import org.springframework.boot.SpringApplication;
47
import org.springframework.boot.WebApplicationType;
58
import org.springframework.context.ConfigurableApplicationContext;
9+
610
import tv.codely.apps.backoffice.backend.BackofficeBackendApplication;
711
import tv.codely.apps.backoffice.frontend.BackofficeFrontendApplication;
812
import tv.codely.apps.mooc.backend.MoocBackendApplication;
913
import tv.codely.shared.infrastructure.cli.ConsoleCommand;
1014

11-
import java.util.Arrays;
12-
import java.util.HashMap;
13-
1415
public class Starter {
15-
public static void main(String[] args) {
16-
if (args.length < 2) {
17-
throw new RuntimeException("There are not enough arguments");
18-
}
19-
20-
String applicationName = args[0];
21-
String commandName = args[1];
22-
boolean isServerCommand = commandName.equals("server");
23-
24-
ensureApplicationExist(applicationName);
25-
ensureCommandExist(applicationName, commandName);
26-
27-
Class<?> applicationClass = applications().get(applicationName);
28-
29-
SpringApplication app = new SpringApplication(applicationClass);
30-
31-
if (!isServerCommand) {
32-
app.setWebApplicationType(WebApplicationType.NONE);
33-
}
34-
35-
ConfigurableApplicationContext context = app.run(args);
36-
37-
if (!isServerCommand) {
38-
ConsoleCommand command = (ConsoleCommand) context.getBean(
39-
commands().get(applicationName).get(commandName)
40-
);
41-
42-
command.execute(Arrays.copyOfRange(args, 2, args.length));
43-
}
44-
}
45-
46-
private static void ensureApplicationExist(String applicationName) {
47-
if (!applications().containsKey(applicationName)) {
48-
throw new RuntimeException(String.format(
49-
"The application <%s> doesn't exist. Valids:\n- %s",
50-
applicationName,
51-
String.join("\n- ", applications().keySet())
52-
));
53-
}
54-
}
55-
56-
private static void ensureCommandExist(String applicationName, String commandName) {
57-
if (!"server".equals(commandName) && !existCommand(applicationName, commandName)) {
58-
throw new RuntimeException(String.format(
59-
"The command <%s> for application <%s> doesn't exist. Valids (application.command):\n- api\n- %s",
60-
commandName,
61-
applicationName,
62-
String.join("\n- ", commands().get(applicationName).keySet())
63-
));
64-
}
65-
}
66-
67-
private static HashMap<String, Class<?>> applications() {
68-
HashMap<String, Class<?>> applications = new HashMap<>();
69-
70-
applications.put("mooc_backend", MoocBackendApplication.class);
71-
applications.put("backoffice_backend", BackofficeBackendApplication.class);
72-
applications.put("backoffice_frontend", BackofficeFrontendApplication.class);
73-
74-
return applications;
75-
}
76-
77-
private static HashMap<String, HashMap<String, Class<?>>> commands() {
78-
HashMap<String, HashMap<String, Class<?>>> commands = new HashMap<>();
79-
80-
commands.put("mooc_backend", MoocBackendApplication.commands());
81-
commands.put("backoffice_backend", BackofficeBackendApplication.commands());
82-
commands.put("backoffice_frontend", BackofficeFrontendApplication.commands());
83-
84-
return commands;
85-
}
86-
87-
private static Boolean existCommand(String applicationName, String commandName) {
88-
HashMap<String, HashMap<String, Class<?>>> commands = commands();
89-
90-
return commands.containsKey(applicationName) && commands.get(applicationName).containsKey(commandName);
91-
}
16+
17+
public static void main(String[] args) {
18+
if (args.length < 2) {
19+
throw new RuntimeException("There are not enough arguments");
20+
}
21+
22+
String applicationName = args[0];
23+
String commandName = args[1];
24+
boolean isServerCommand = commandName.equals("server");
25+
26+
ensureApplicationExist(applicationName);
27+
ensureCommandExist(applicationName, commandName);
28+
29+
Class<?> applicationClass = applications().get(applicationName);
30+
31+
SpringApplication app = new SpringApplication(applicationClass);
32+
33+
if (!isServerCommand) {
34+
app.setWebApplicationType(WebApplicationType.NONE);
35+
}
36+
37+
ConfigurableApplicationContext context = app.run(args);
38+
39+
if (!isServerCommand) {
40+
ConsoleCommand command = (ConsoleCommand) context.getBean(commands().get(applicationName).get(commandName));
41+
42+
command.execute(Arrays.copyOfRange(args, 2, args.length));
43+
}
44+
}
45+
46+
private static void ensureApplicationExist(String applicationName) {
47+
if (!applications().containsKey(applicationName)) {
48+
throw new RuntimeException(
49+
String.format(
50+
"The application <%s> doesn't exist. Valids:\n- %s",
51+
applicationName,
52+
String.join("\n- ", applications().keySet())
53+
)
54+
);
55+
}
56+
}
57+
58+
private static void ensureCommandExist(String applicationName, String commandName) {
59+
if (!"server".equals(commandName) && !existCommand(applicationName, commandName)) {
60+
throw new RuntimeException(
61+
String.format(
62+
"The command <%s> for application <%s> doesn't exist. Valids (application.command):\n- api\n- %s",
63+
commandName,
64+
applicationName,
65+
String.join("\n- ", commands().get(applicationName).keySet())
66+
)
67+
);
68+
}
69+
}
70+
71+
private static HashMap<String, Class<?>> applications() {
72+
HashMap<String, Class<?>> applications = new HashMap<>();
73+
74+
applications.put("mooc_backend", MoocBackendApplication.class);
75+
applications.put("backoffice_backend", BackofficeBackendApplication.class);
76+
applications.put("backoffice_frontend", BackofficeFrontendApplication.class);
77+
78+
return applications;
79+
}
80+
81+
private static HashMap<String, HashMap<String, Class<?>>> commands() {
82+
HashMap<String, HashMap<String, Class<?>>> commands = new HashMap<>();
83+
84+
commands.put("mooc_backend", MoocBackendApplication.commands());
85+
commands.put("backoffice_backend", BackofficeBackendApplication.commands());
86+
commands.put("backoffice_frontend", BackofficeFrontendApplication.commands());
87+
88+
return commands;
89+
}
90+
91+
private static Boolean existCommand(String applicationName, String commandName) {
92+
HashMap<String, HashMap<String, Class<?>>> commands = commands();
93+
94+
return commands.containsKey(applicationName) && commands.get(applicationName).containsKey(commandName);
95+
}
9296
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package tv.codely.apps.backoffice.backend;
22

3+
import java.util.HashMap;
4+
35
import org.springframework.boot.autoconfigure.SpringBootApplication;
46
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
57
import org.springframework.context.annotation.ComponentScan;
68
import org.springframework.context.annotation.FilterType;
7-
import tv.codely.shared.domain.Service;
89

9-
import java.util.HashMap;
10+
import tv.codely.shared.domain.Service;
1011

1112
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
1213
@ComponentScan(
13-
includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class),
14-
value = {"tv.codely.shared", "tv.codely.backoffice", "tv.codely.apps.backoffice.backend"}
14+
includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class),
15+
value = { "tv.codely.shared", "tv.codely.backoffice", "tv.codely.apps.backoffice.backend" }
1516
)
1617
public class BackofficeBackendApplication {
17-
public static HashMap<String, Class<?>> commands() {
18-
return new HashMap<String, Class<?>>() {{
19-
}};
20-
}
18+
19+
public static HashMap<String, Class<?>> commands() {
20+
return new HashMap<String, Class<?>>() {
21+
{}
22+
};
23+
}
2124
}

apps/main/tv/codely/apps/backoffice/backend/config/BackofficeBackendServerConfiguration.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
import org.springframework.boot.web.servlet.FilterRegistrationBean;
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
6+
67
import tv.codely.apps.backoffice.backend.middleware.BasicHttpAuthMiddleware;
78
import tv.codely.shared.domain.bus.command.CommandBus;
89

910
@Configuration
1011
public class BackofficeBackendServerConfiguration {
11-
private final CommandBus bus;
1212

13-
public BackofficeBackendServerConfiguration(CommandBus bus) {
14-
this.bus = bus;
15-
}
13+
private final CommandBus bus;
14+
15+
public BackofficeBackendServerConfiguration(CommandBus bus) {
16+
this.bus = bus;
17+
}
1618

17-
@Bean
18-
public FilterRegistrationBean<BasicHttpAuthMiddleware> basicHttpAuthMiddleware() {
19-
FilterRegistrationBean<BasicHttpAuthMiddleware> registrationBean = new FilterRegistrationBean<>();
19+
@Bean
20+
public FilterRegistrationBean<BasicHttpAuthMiddleware> basicHttpAuthMiddleware() {
21+
FilterRegistrationBean<BasicHttpAuthMiddleware> registrationBean = new FilterRegistrationBean<>();
2022

21-
registrationBean.setFilter(new BasicHttpAuthMiddleware(bus));
22-
registrationBean.addUrlPatterns("/health-check");
23+
registrationBean.setFilter(new BasicHttpAuthMiddleware(bus));
24+
registrationBean.addUrlPatterns("/health-check");
2325

24-
return registrationBean;
25-
}
26+
return registrationBean;
27+
}
2628
}

apps/main/tv/codely/apps/backoffice/backend/config/BackofficeBackendServerPortCustomizer.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
44
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
55
import org.springframework.stereotype.Component;
6+
67
import tv.codely.shared.infrastructure.config.Parameter;
78
import tv.codely.shared.infrastructure.config.ParameterNotExist;
89

910
@Component
10-
public final class BackofficeBackendServerPortCustomizer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
11-
private final Parameter param;
11+
public final class BackofficeBackendServerPortCustomizer
12+
implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
13+
14+
private final Parameter param;
1215

13-
public BackofficeBackendServerPortCustomizer(Parameter param) {
14-
this.param = param;
15-
}
16+
public BackofficeBackendServerPortCustomizer(Parameter param) {
17+
this.param = param;
18+
}
1619

17-
@Override
18-
public void customize(ConfigurableWebServerFactory factory) {
19-
try {
20-
factory.setPort(param.getInt("BACKOFFICE_BACKEND_SERVER_PORT"));
21-
} catch (ParameterNotExist parameterNotExist) {
22-
parameterNotExist.printStackTrace();
23-
}
24-
}
20+
@Override
21+
public void customize(ConfigurableWebServerFactory factory) {
22+
try {
23+
factory.setPort(param.getInt("BACKOFFICE_BACKEND_SERVER_PORT"));
24+
} catch (ParameterNotExist parameterNotExist) {
25+
parameterNotExist.printStackTrace();
26+
}
27+
}
2528
}

0 commit comments

Comments
 (0)