From f7dddb7c00d966cf00bb4fb5af986ec0a78dda4f Mon Sep 17 00:00:00 2001 From: Oleg Kopysov Date: Fri, 23 Feb 2024 14:39:18 +0200 Subject: [PATCH] refactor: rename classes and improve application.properties Signed-off-by: Oleg Kopysov --- README.md | 2 + pom.xml | 2 +- ....java => LicensePreValidationService.java} | 8 ++-- .../lpvs/controller/LPVSWebController.java | 4 +- src/main/java/com/lpvs/package-info.java | 2 +- .../application-singlescan.properties | 14 +++---- src/main/resources/application-web.properties | 36 ++++++++++++++++++ src/main/resources/application.properties | 37 ------------------- ...a => LicensePreValidationServiceTest.java} | 8 ++-- 9 files changed, 56 insertions(+), 57 deletions(-) rename src/main/java/com/lpvs/{LicensePreValidationSystem.java => LicensePreValidationService.java} (88%) create mode 100644 src/main/resources/application-web.properties rename src/test/java/com/lpvs/{LicensePreValidationSystemTest.java => LicensePreValidationServiceTest.java} (83%) diff --git a/README.md b/README.md index 47a60095..61aed38b 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ With these features, _LPVS_ assists developers to manage license compliance for The frontend of the _LPVS_ project is implemented using React. The corresponding code can be found in the `frontend` folder. For detailed information about the frontend, please refer to the [Frontend README](frontend/README.md). +To ensure compatibility between the LPVS frontend and backend, it's important to build the backend with the _"web"_ profile. + --- ## License diff --git a/pom.xml b/pom.xml index 8dd648b0..06711d32 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ true - com.lpvs.LicensePreValidationSystem + com.lpvs.LicensePreValidationService false diff --git a/src/main/java/com/lpvs/LicensePreValidationSystem.java b/src/main/java/com/lpvs/LicensePreValidationService.java similarity index 88% rename from src/main/java/com/lpvs/LicensePreValidationSystem.java rename to src/main/java/com/lpvs/LicensePreValidationService.java index 3acc2bfa..08f422db 100644 --- a/src/main/java/com/lpvs/LicensePreValidationSystem.java +++ b/src/main/java/com/lpvs/LicensePreValidationService.java @@ -25,7 +25,7 @@ @SpringBootApplication(scanBasePackages = {"com.lpvs"}) @EnableAutoConfiguration @EnableAsync -public class LicensePreValidationSystem { +public class LicensePreValidationService { /** * The core pool size for the asynchronous task executor. @@ -38,11 +38,11 @@ public class LicensePreValidationSystem { private static LPVSExitHandler exitHandler; /** - * Constructs a new LicensePreValidationSystem with the specified core pool size. + * Constructs a new LicensePreValidationService with the specified core pool size. * * @param corePoolSize The core pool size for the asynchronous task executor. */ - public LicensePreValidationSystem(@Value("${lpvs.cores:8}") int corePoolSize) { + public LicensePreValidationService(@Value("${lpvs.cores:8}") int corePoolSize) { this.corePoolSize = corePoolSize; } @@ -54,7 +54,7 @@ public LicensePreValidationSystem(@Value("${lpvs.cores:8}") int corePoolSize) { public static void main(String[] args) { try { ApplicationContext applicationContext = - SpringApplication.run(LicensePreValidationSystem.class, args); + SpringApplication.run(LicensePreValidationService.class, args); exitHandler = applicationContext.getBean(LPVSExitHandler.class); } catch (IllegalArgumentException e) { System.err.println("An IllegalArgumentException occurred: " + e.getMessage()); diff --git a/src/main/java/com/lpvs/controller/LPVSWebController.java b/src/main/java/com/lpvs/controller/LPVSWebController.java index c4f8f667..ef095ebe 100644 --- a/src/main/java/com/lpvs/controller/LPVSWebController.java +++ b/src/main/java/com/lpvs/controller/LPVSWebController.java @@ -25,6 +25,7 @@ import com.lpvs.util.LPVSWebhookUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.context.annotation.Profile; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -113,8 +114,9 @@ public LPVSWebController( * Controller class for managing public web API endpoints in LPVS. * This class provides endpoints for retrieving user information, login details, and performing user-related actions. */ - @RequestMapping("/api/v1/web") @RestController + @Profile("web") + @RequestMapping("/api/v1/web") class WebApiEndpoints { /** diff --git a/src/main/java/com/lpvs/package-info.java b/src/main/java/com/lpvs/package-info.java index 75cd794b..dc3bf32c 100644 --- a/src/main/java/com/lpvs/package-info.java +++ b/src/main/java/com/lpvs/package-info.java @@ -9,7 +9,7 @@ * Provides the main classes and components for the License Pre-Validation Service (LPVS) application. * LPVS is an open-source tool designed to mitigate license-related risks in open-source projects. * It analyzes the project, identifies components and licenses, and generates potential issue cases. - * The {@link com.lpvs.LicensePreValidationSystem} class is the main entry point for LPVS. + * The {@link com.lpvs.LicensePreValidationService} class is the main entry point for LPVS. * *

* The LPVS project aims to assist developers in ensuring license compliance for their open-source code. diff --git a/src/main/resources/application-singlescan.properties b/src/main/resources/application-singlescan.properties index 6cfd8404..b829889f 100644 --- a/src/main/resources/application-singlescan.properties +++ b/src/main/resources/application-singlescan.properties @@ -1,22 +1,18 @@ -debug=false logging.level.org.hibernate=error -spring.sql.init.mode=always -spring.datasource.initialization-mode=always + spring.h2.console.enabled=false +spring.sql.init.mode=always spring.sql.init.platform=h2 -# DB Configuration -# Whether to enable logging of SQL statements. -spring.jpa.show-sql=false +# DB Configuration spring.sql.init.data-locations=classpath*:database_dump.sql - +spring.datasource.initialization-mode=always spring.datasource.url=jdbc:h2:mem:singlescan;DATABASE_TO_UPPER=false;MODE=MySQL;NON_KEYWORDS=USER spring.datasource.username= spring.datasource.password= spring.jpa.properties.hibernate.format_sql=false spring.jpa.properties.hibernate.use_sql_comments=false -spring.jpa.properties.hibernate.show_sql=false spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.defer-datasource-initialization=true \ No newline at end of file +spring.jpa.defer-datasource-initialization=true diff --git a/src/main/resources/application-web.properties b/src/main/resources/application-web.properties new file mode 100644 index 00000000..d370276c --- /dev/null +++ b/src/main/resources/application-web.properties @@ -0,0 +1,36 @@ +# Login Configuration +#Google +spring.security.oauth2.client.registration.google.client-id={YOUR_GOOGLE_CLIENT_ID} +spring.security.oauth2.client.registration.google.client-secret={YOUR_GOOGLE_CLIENT_SECRET} +spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:7896/login/oauth2/code/google +spring.security.oauth2.client.registration.google.scope=profile, email + +#Naver +spring.security.oauth2.client.registration.naver.client-id={YOUR_NAVER_CLIENT_ID} +spring.security.oauth2.client.registration.naver.client-secret={YOUR_NAVER_CLIENT_SECRET} +spring.security.oauth2.client.registration.naver.redirect-uri=http://localhost:7896/login/oauth2/code/naver +spring.security.oauth2.client.registration.naver.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.naver.scope=name, email, profile_image +spring.security.oauth2.client.registration.naver.client-name=Naver +#Provider-Naver +spring.security.oauth2.client.provider.naver.authorization-uri=https://nid.naver.com/oauth2.0/authorize +spring.security.oauth2.client.provider.naver.token-uri=https://nid.naver.com/oauth2.0/token +spring.security.oauth2.client.provider.naver.user-info-uri=https://openapi.naver.com/v1/nid/me +spring.security.oauth2.client.provider.naver.user-name-attribute=response + +#Kakao +spring.security.oauth2.client.registration.kakao.client-id={YOUR_KAKAO_CLIENT_ID} +spring.security.oauth2.client.registration.kakao.redirect-uri=http://localhost:7896/login/oauth2/code/kakao +spring.security.oauth2.client.registration.kakao.client-authentication-method=POST +spring.security.oauth2.client.registration.kakao.authorization-grant-type = authorization_code +spring.security.oauth2.client.registration.kakao.scope=profile_nickname, profile_image, account_email +spring.security.oauth2.client.registration.kakao.client-name=Kakao +#Provider-Kakao +spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize +spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token +spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me +spring.security.oauth2.client.provider.kakao.user-name-attribute=id + +# Frontend Configuration +frontend.main-page.url=/ +cors.allowed-origin= diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d369f44d..4e9c5589 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -46,40 +46,3 @@ spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://localhost:3306/lpvs spring.datasource.username= spring.datasource.password= - -# Login Configuration -#Google -spring.security.oauth2.client.registration.google.client-id={YOUR_GOOGLE_CLIENT_ID} -spring.security.oauth2.client.registration.google.client-secret={YOUR_GOOGLE_CLIENT_SECRET} -spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:7896/login/oauth2/code/google -spring.security.oauth2.client.registration.google.scope=profile, email - -#Naver -spring.security.oauth2.client.registration.naver.client-id={YOUR_NAVER_CLIENT_ID} -spring.security.oauth2.client.registration.naver.client-secret={YOUR_NAVER_CLIENT_SECRET} -spring.security.oauth2.client.registration.naver.redirect-uri=http://localhost:7896/login/oauth2/code/naver -spring.security.oauth2.client.registration.naver.authorization-grant-type=authorization_code -spring.security.oauth2.client.registration.naver.scope=name, email, profile_image -spring.security.oauth2.client.registration.naver.client-name=Naver -#Provider-Naver -spring.security.oauth2.client.provider.naver.authorization-uri=https://nid.naver.com/oauth2.0/authorize -spring.security.oauth2.client.provider.naver.token-uri=https://nid.naver.com/oauth2.0/token -spring.security.oauth2.client.provider.naver.user-info-uri=https://openapi.naver.com/v1/nid/me -spring.security.oauth2.client.provider.naver.user-name-attribute=response - -#Kakao -spring.security.oauth2.client.registration.kakao.client-id={YOUR_KAKAO_CLIENT_ID} -spring.security.oauth2.client.registration.kakao.redirect-uri=http://localhost:7896/login/oauth2/code/kakao -spring.security.oauth2.client.registration.kakao.client-authentication-method=POST -spring.security.oauth2.client.registration.kakao.authorization-grant-type = authorization_code -spring.security.oauth2.client.registration.kakao.scope=profile_nickname, profile_image, account_email -spring.security.oauth2.client.registration.kakao.client-name=Kakao -#Provider-Kakao -spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize -spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token -spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me -spring.security.oauth2.client.provider.kakao.user-name-attribute=id - -# Frontend Configuration -frontend.main-page.url=/ -cors.allowed-origin= diff --git a/src/test/java/com/lpvs/LicensePreValidationSystemTest.java b/src/test/java/com/lpvs/LicensePreValidationServiceTest.java similarity index 83% rename from src/test/java/com/lpvs/LicensePreValidationSystemTest.java rename to src/test/java/com/lpvs/LicensePreValidationServiceTest.java index de7d4f89..667f85bf 100644 --- a/src/test/java/com/lpvs/LicensePreValidationSystemTest.java +++ b/src/test/java/com/lpvs/LicensePreValidationServiceTest.java @@ -15,20 +15,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; -public class LicensePreValidationSystemTest { +public class LicensePreValidationServiceTest { final int testNumCores = 42; - LicensePreValidationSystem licensePreValidationSystem; + LicensePreValidationService licensePreValidationService; @BeforeEach void setUp() { - licensePreValidationSystem = new LicensePreValidationSystem(42); + licensePreValidationService = new LicensePreValidationService(42); } @Test public void testGetAsyncExecutor() { try (MockedConstruction mocked = mockConstruction(ThreadPoolTaskExecutor.class)) { - TaskExecutor executor = licensePreValidationSystem.getAsyncExecutor(); + TaskExecutor executor = licensePreValidationService.getAsyncExecutor(); assertEquals(1, mocked.constructed().size()); ThreadPoolTaskExecutor mocked_constructed_executor = mocked.constructed().get(0);