From 3d6f1fe1b0cce5169a8a41d1bb7eafa7c2e2cb83 Mon Sep 17 00:00:00 2001 From: Tripti Ghanghas Date: Wed, 29 May 2024 16:15:27 -0700 Subject: [PATCH] added custom properties file as program argument --- .../ddd/server/BundleServerApplication.java | 30 ++++++++++++++++++- .../src/main/resources/application.properties | 3 -- .../src/main/resources/application.yml | 4 +-- 3 files changed, 31 insertions(+), 6 deletions(-) delete mode 100644 bundleserver/src/main/resources/application.properties diff --git a/bundleserver/src/main/java/com/ddd/server/BundleServerApplication.java b/bundleserver/src/main/java/com/ddd/server/BundleServerApplication.java index 8ea6c4cec7..63cabf0815 100644 --- a/bundleserver/src/main/java/com/ddd/server/BundleServerApplication.java +++ b/bundleserver/src/main/java/com/ddd/server/BundleServerApplication.java @@ -2,16 +2,23 @@ import com.ddd.server.commands.CommandProcessor; import com.ddd.server.commands.bundleuploader.BundleUploader; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import java.io.File; +import java.util.Arrays; +import java.util.Properties; +@Slf4j @SpringBootApplication @EnableJpaRepositories("com.ddd.server") @EntityScan("com.ddd.server.repository.entity") @@ -28,7 +35,7 @@ protected void refresh(ConfigurableApplicationContext applicationContext) { // check for obvious configuration errors var root = applicationContext.getEnvironment().getProperty("bundle-server.bundle-store-root"); if (root == null || !new File(root).isDirectory()) { - System.err.println("bundle-server.bundle-store-root is not a directory or not set: " + root); + log.error("bundle-server.bundle-store-root is not a directory or not set: " + root); System.exit(1); } super.refresh(applicationContext); @@ -42,6 +49,27 @@ protected void refresh(ConfigurableApplicationContext applicationContext) { app.setLogStartupInfo(false); } new BundleUploader().run(args); + + if (args.length > 0) { + Resource resource = new FileSystemResource(args[0]); + if (resource.exists()){ + try { + Properties properties = PropertiesLoaderUtils.loadProperties(resource); + app.setDefaultProperties(properties); + args = Arrays.copyOfRange(args, 1, args.length); + } catch (Exception e){ + log.error("Please enter valid properties file path!"); + System.exit(1); + } + }else { + log.error("Entered properties file path does not exist!"); + System.exit(1); + } + }else { + log.error("Please enter properties file path as argument!"); + System.exit(1); + } + app.run(args); } } \ No newline at end of file diff --git a/bundleserver/src/main/resources/application.properties b/bundleserver/src/main/resources/application.properties deleted file mode 100644 index fbb04f9939..0000000000 --- a/bundleserver/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -#keep custom properties per contributor here -spring.datasource.password = ${DB_PASS} -bundle-server.bundle-store-root = ${BUNDLE_STORE_ROOT} \ No newline at end of file diff --git a/bundleserver/src/main/resources/application.yml b/bundleserver/src/main/resources/application.yml index 2ceada9aaf..ffc4d65ce5 100644 --- a/bundleserver/src/main/resources/application.yml +++ b/bundleserver/src/main/resources/application.yml @@ -13,13 +13,13 @@ spring: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/dtn_server_db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC username: root - password: ddd2024 +# password: db-name: dtn_server_db server: port: 8081 bundle-server: - bundle-store-root: "/Users/manaschougule/College/SJSU/DDD-server-storage/" +# bundle-store-root: bundle-store-shared: "${bundle-server.bundle-store-root}Shared" registered-app-ids: "${bundle-server.bundle-store-root}Shared/REGISTERED_APP_IDS.txt" bundle-transmission: