Skip to content

Commit

Permalink
Ajoute spotless au projet
Browse files Browse the repository at this point in the history
Change-Id: Iae4b61de0e37243c1661d862cf0baff6e4e6e01d
  • Loading branch information
Renaud-Kieffer committed Sep 22, 2023
1 parent 682bbdd commit 238adcb
Show file tree
Hide file tree
Showing 622 changed files with 41,096 additions and 37,013 deletions.
28 changes: 28 additions & 0 deletions api-remocra/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<db.pass>postgres</db.pass>
<db.name>remocra</db.name>
<db.schema>remocra</db.schema>
<!-- Spotless-->
<spotless.version>2.39.0</spotless.version>
<googleJavaFormat.version>1.17.0</googleJavaFormat.version>

</properties>

<dependencies>
Expand Down Expand Up @@ -393,6 +397,30 @@
</execution>
</executions>
</plugin>



<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
<configuration>
<java>
<googleJavaFormat>
<version>${googleJavaFormat.version}</version>
</googleJavaFormat>
<removeUnusedImports />
</java>
</configuration>
</plugin>
</plugins>
</build>
</project>
117 changes: 56 additions & 61 deletions api-remocra/api/src/main/java/fr/sdis83/remocra/WebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,68 @@
import fr.sdis83.remocra.db.DatabaseModule;
import fr.sdis83.remocra.http.HttpServer;
import fr.sdis83.remocra.http.HttpServerWebappModule;

import fr.sdis83.remocra.jvm.JvmInitializer;
import fr.sdis83.remocra.jvm.JvmModule;
import fr.sdis83.remocra.tools.CommandLineTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WebApp extends CommandLineTool {

// logger is not a static field to be initialized once log4j is configured
@Override
protected Logger logger() {
return LoggerFactory.getLogger(WebApp.class);
}

@Inject
HttpServer httpServer;

@Inject
JvmInitializer jvmInitializer;

@Inject
PersistService persistService;


public static void main(String[] args) throws Throwable {
new WebApp().run(args);
}

public void run(String[] args) throws Throwable {
final Config config = init(args);

// Identification des modules à initialiser en fonction de la conf
final Injector injector = Guice.createInjector(getModules(config));
injector.injectMembers(this);

jvmInitializer.initialize();

Runtime.getRuntime()
.addShutdownHook(new Thread(() -> {
try {
httpServer.stop();
} catch (Exception exception) {
logger().error("Error stopping HttpServer", exception);
}
persistService.stop();
}));
persistService.start();
httpServer.start();
httpServer.waitTillInterrupt();
}

private List<AbstractModule> getModules(final Config config) throws Throwable {
List<AbstractModule> res = new ArrayList<>();

// Common modules
res.add(new ServletModule());
res.add(AuthnModule.create(config.getConfig("api-remocra.authn")));
res.add(DatabaseModule.create(config.getConfig("api-remocra.database")));
res.add(JvmModule.create(config.getConfig("api-remocra.jvm")));
res.add(AppModule.create(config.getConfig("api-remocra.app")));
res.add(HttpServerWebappModule.create(config.getConfig("api-remocra.http")));
return res;
}

// logger is not a static field to be initialized once log4j is configured
@Override
protected Logger logger() {
return LoggerFactory.getLogger(WebApp.class);
}

@Inject HttpServer httpServer;

@Inject JvmInitializer jvmInitializer;

@Inject PersistService persistService;

public static void main(String[] args) throws Throwable {
new WebApp().run(args);
}

public void run(String[] args) throws Throwable {
final Config config = init(args);

// Identification des modules à initialiser en fonction de la conf
final Injector injector = Guice.createInjector(getModules(config));
injector.injectMembers(this);

jvmInitializer.initialize();

Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
try {
httpServer.stop();
} catch (Exception exception) {
logger().error("Error stopping HttpServer", exception);
}
persistService.stop();
}));
persistService.start();
httpServer.start();
httpServer.waitTillInterrupt();
}

private List<AbstractModule> getModules(final Config config) throws Throwable {
List<AbstractModule> res = new ArrayList<>();

// Common modules
res.add(new ServletModule());
res.add(AuthnModule.create(config.getConfig("api-remocra.authn")));
res.add(DatabaseModule.create(config.getConfig("api-remocra.database")));
res.add(JvmModule.create(config.getConfig("api-remocra.jvm")));
res.add(AppModule.create(config.getConfig("api-remocra.app")));
res.add(HttpServerWebappModule.create(config.getConfig("api-remocra.http")));
return res;
}
}
53 changes: 28 additions & 25 deletions api-remocra/api/src/main/java/fr/sdis83/remocra/app/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@
@Value.Enclosing
public class AppModule extends AbstractModule {

@Value.Immutable
interface Settings {
String title();

String version();
}

public static AppModule create(Config config) {
return new AppModule(ImmutableAppModule.Settings.builder().title(config.getString("title"))
.version(config.getString("version")).build());
}

private final Settings settings;

public AppModule(Settings settings) {
this.settings = settings;
}

@Override
protected void configure() {
bind(javax.ws.rs.core.Application.class).to(Application.class);

bind(String.class).annotatedWith(ApplicationTitle.class).toInstance(settings.title());
bind(String.class).annotatedWith(ApplicationVersion.class).toInstance(settings.version());
}
@Value.Immutable
interface Settings {
String title();

String version();
}

public static AppModule create(Config config) {
return new AppModule(
ImmutableAppModule.Settings.builder()
.title(config.getString("title"))
.version(config.getString("version"))
.build());
}

private final Settings settings;

public AppModule(Settings settings) {
this.settings = settings;
}

@Override
protected void configure() {
bind(javax.ws.rs.core.Application.class).to(Application.class);

bind(String.class).annotatedWith(ApplicationTitle.class).toInstance(settings.title());
bind(String.class).annotatedWith(ApplicationVersion.class).toInstance(settings.version());
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package fr.sdis83.remocra.app;

import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

@Qualifier
@Target({FIELD, PARAMETER, METHOD})
@Retention(RUNTIME)
public @interface ApplicationTitle {
}
public @interface ApplicationTitle {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package fr.sdis83.remocra.app;

import javax.inject.Qualifier;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.RUNTIME;
import javax.inject.Qualifier;

@Qualifier
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RUNTIME)
public @interface ApplicationVersion {
}
public @interface ApplicationVersion {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface AuthDevice {
}
public @interface AuthDevice {}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ UserInfo provideUserInfo(@CurrentUser Provider<UserPrincipal> currentUserPrincip
}
return principal.getUserInfo();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@
*/
public class CompatibleVersions {

// Versions autorisées pour l'appli mobile
private final List<String> mobileCompatibleVersions = Collections.singletonList(MobileVersion.M1_0.version);

public CompatibleVersions() {
// Versions autorisées pour l'appli mobile
private final List<String> mobileCompatibleVersions =
Collections.singletonList(MobileVersion.M1_0.version);

public CompatibleVersions() {}

/**
* Permet de savoir si la version de l'application mobile est compatible avec celle du serveur
*
* @param mobileVersionString : la version de la tablette
*/
public void checkCompat(String mobileVersionString) {
if (mobileVersionString == null || mobileVersionString.isEmpty()) {
throw new IllegalArgumentException("MobileVersion nulle");
}

/**
* Permet de savoir si la version de l'application mobile est compatible avec celle du serveur
*
* @param mobileVersionString : la version de la tablette
*/
public void checkCompat(String mobileVersionString) {
if (mobileVersionString == null || mobileVersionString.isEmpty()) {
throw new IllegalArgumentException("MobileVersion nulle");
}

if (!mobileCompatibleVersions.contains(mobileVersionString)) {
throw new IllegalArgumentException(
"Version non compatible : " + mobileVersionString);
}
if (!mobileCompatibleVersions.contains(mobileVersionString)) {
throw new IllegalArgumentException("Version non compatible : " + mobileVersionString);
}
}

enum MobileVersion {
M1_0("1.0");
enum MobileVersion {
M1_0("1.0");

public final String version;
public final String version;

MobileVersion(String s) {
this.version = s;
}
MobileVersion(String s) {
this.version = s;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
@Qualifier
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RUNTIME)
public @interface CurrentUser {}
public @interface CurrentUser {}
Loading

0 comments on commit 238adcb

Please sign in to comment.