Skip to content

Commit

Permalink
fix for ninja, making some sysouts configurable using midpoint.silent…
Browse files Browse the repository at this point in the history
… system option, by default they are still printed out
  • Loading branch information
1azyman committed Dec 18, 2017
1 parent 79b4f7d commit c113d61
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Expand Up @@ -29,15 +29,27 @@ public class ApplicationHomeSetup {

private static final Trace LOGGER = TraceManager.getTrace(ApplicationHomeSetup.class);

private boolean silent = false;

public void init(String midpointHomeSystemPropertyName) {
this.silent = Boolean.getBoolean(StartupConfiguration.MIDPOINT_SILENT_PROPERTY_NAME);

LOGGER.info(midpointHomeSystemPropertyName + " = " + System.getProperty(midpointHomeSystemPropertyName));
System.out.println(midpointHomeSystemPropertyName + " = " + System.getProperty(midpointHomeSystemPropertyName));
printToSysout(midpointHomeSystemPropertyName + " = " + System.getProperty(midpointHomeSystemPropertyName));

String midpointHomePath = System.getProperty(midpointHomeSystemPropertyName);

createMidpointHomeDirectories(midpointHomePath);
setupMidpointHomeDirectory(midpointHomePath);
}

private void printToSysout(String message) {
if (silent) {
return;
}

System.out.println(message);
}

/**
* Creates directory structure under root
Expand Down
Expand Up @@ -41,6 +41,8 @@

public class StartupConfiguration implements MidpointConfiguration {

public static final String MIDPOINT_SILENT_PROPERTY_NAME = "midpoint.silent";

private static final String USER_HOME_SYSTEM_PROPERTY_NAME = "user.home";
private static final String MIDPOINT_HOME_SYSTEM_PROPERTY_NAME = "midpoint.home";
private static final String MIDPOINT_CONFIGURATION_SECTION = "midpoint";
Expand All @@ -53,6 +55,8 @@ public class StartupConfiguration implements MidpointConfiguration {

private static final Trace LOGGER = TraceManager.getTrace(StartupConfiguration.class);

private boolean silent = false;

private CompositeConfiguration config = null;
private Document xmlConfigAsDocument = null; // just in case when we need to access original XML document
private String midPointHomePath = null;
Expand Down Expand Up @@ -128,6 +132,7 @@ public Configuration getConfiguration(String componentName) {
* Initialize system configuration
*/
public void init() {
this.silent = Boolean.getBoolean(MIDPOINT_SILENT_PROPERTY_NAME);

if (midPointHomePath == null) {

Expand Down Expand Up @@ -191,7 +196,7 @@ private void loadConfiguration(File midpointHome) {
ah.init(MIDPOINT_HOME_SYSTEM_PROPERTY_NAME);

File configFile = new File(midpointHome, this.getConfigFilename());
System.out.println("Loading midPoint configuration from file " + configFile);
printToSysout("Loading midPoint configuration from file " + configFile);
LOGGER.info("Loading midPoint configuration from file {}", configFile);
try {
if (!configFile.exists()) {
Expand All @@ -200,7 +205,7 @@ private void loadConfiguration(File midpointHome) {
if (!success || !configFile.exists()) {
String message = "Unable to extract configuration file " + this.getConfigFilename() + " from classpath";
LOGGER.error(message);
System.out.println(message);
printToSysout(message);
throw new SystemException(message);
}
}
Expand All @@ -211,12 +216,12 @@ private void loadConfiguration(File midpointHome) {
} catch (ConfigurationException e) {
String message = "Unable to read configuration file [" + configFile + "]: " + e.getMessage();
LOGGER.error(message);
System.out.println(message);
printToSysout(message);
throw new SystemException(message, e); // there's no point in continuing with midpoint initialization
} catch (IOException e) {
String message = "Unable to set permissions for configuration file [" + configFile + "]: " + e.getMessage();
LOGGER.warn(message);
System.out.println(message);
printToSysout(message);
// Non-critical, continue
}

Expand All @@ -227,12 +232,20 @@ private void loadConfiguration(File midpointHome) {
} catch (ConfigurationException e) {
String message = "Unable to read configuration file [" + this.getConfigFilename() + "]: " + e.getMessage();
LOGGER.error(message);
System.out.println(message);
printToSysout(message);
throw new SystemException(message, e);
}
}
}

private void printToSysout(String message) {
if (silent) {
return;
}

System.out.println(message);
}

private void setupInitialLogging(File midpointHome) {
File logbackConfigFile = new File(midpointHome, LOGBACK_CONFIG_FILENAME);
boolean clear = false;
Expand Down
Expand Up @@ -33,6 +33,7 @@
*/
public class NinjaContext {

private static final String MIDPOINT_SILENT_PROPERTY_NAME = "midpoint.silent";
private static final String MIDPOINT_HOME_OPTION = "midpoint.home";

private static final String REPOSITORY_SERVICE_BEAN = "repositoryService";
Expand Down Expand Up @@ -86,6 +87,8 @@ public void destroy() {
}

private RepositoryService setupRepositoryViaMidPointHome(ConnectionOptions options) {
System.setProperty(MIDPOINT_SILENT_PROPERTY_NAME, "true");

String midpointHome = options.getMidpointHome();

String jdbcUrl = options.getUrl();
Expand Down

0 comments on commit c113d61

Please sign in to comment.