Skip to content

Commit

Permalink
added custom properties file as program argument
Browse files Browse the repository at this point in the history
  • Loading branch information
triptighanghas committed May 29, 2024
1 parent 22733ab commit 3d6f1fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
Expand All @@ -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);
}
}
3 changes: 0 additions & 3 deletions bundleserver/src/main/resources/application.properties

This file was deleted.

4 changes: 2 additions & 2 deletions bundleserver/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <add in external properties file>
db-name: dtn_server_db

server:
port: 8081
bundle-server:
bundle-store-root: "/Users/manaschougule/College/SJSU/DDD-server-storage/"
# bundle-store-root: <add directory path containing key files in external properties file>
bundle-store-shared: "${bundle-server.bundle-store-root}Shared"
registered-app-ids: "${bundle-server.bundle-store-root}Shared/REGISTERED_APP_IDS.txt"
bundle-transmission:
Expand Down

0 comments on commit 3d6f1fe

Please sign in to comment.