Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support environment variables for all supported system properties in a uniform way #126

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
<properties>

<!-- Modules Versions -->
<daisy.calabash-adapter.version>2.0.5</daisy.calabash-adapter.version>
<daisy.calabash-adapter.version>2.0.6-SNAPSHOT</daisy.calabash-adapter.version>
<daisy.calabash-custom-steps.version>2.0.0</daisy.calabash-custom-steps.version>
<daisy.common-utils.version>2.1.3</daisy.common-utils.version>
<daisy.framework-core.version>3.1.1</daisy.framework-core.version>
<daisy.framework-persistence.version>2.0.4</daisy.framework-persistence.version>
<daisy.framework-volatile.version>2.0.2</daisy.framework-volatile.version>
<daisy.framework-core.version>3.2.0-SNAPSHOT</daisy.framework-core.version>
<daisy.framework-persistence.version>2.0.5-SNAPSHOT</daisy.framework-persistence.version>
<daisy.framework-volatile.version>2.0.3-SNAPSHOT</daisy.framework-volatile.version>
<daisy.launcher.version>1.0.0</daisy.launcher.version>
<daisy.logging-activator.version>2.0.2</daisy.logging-activator.version>
<daisy.logging-appender.version>1.1.1</daisy.logging-appender.version>
<daisy.modules-registry.version>2.0.1</daisy.modules-registry.version>
<daisy.persistence-derby.version>2.0.1</daisy.persistence-derby.version>
<daisy.persistence-mysql.version>2.0.0</daisy.persistence-mysql.version>
<daisy.persistence-derby.version>2.0.2-SNAPSHOT</daisy.persistence-derby.version>
<daisy.persistence-mysql.version>2.0.1-SNAPSHOT</daisy.persistence-mysql.version>
<daisy.push-notifier.version>2.0.1</daisy.push-notifier.version>
<daisy.updater-wrapper.version>1.0.1</daisy.updater-wrapper.version>
<daisy.webservice.version>2.1.2</daisy.webservice.version>
<daisy.webservice-utils.version>2.2.2</daisy.webservice-utils.version>
<daisy.updater-wrapper.version>1.0.2-SNAPSHOT</daisy.updater-wrapper.version>
<daisy.webservice.version>2.1.3-SNAPSHOT</daisy.webservice.version>
<daisy.webservice-utils.version>3.0.0-SNAPSHOT</daisy.webservice-utils.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see API change in the webservice module, am I correct that the major change is due to change in the web service payload?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember TBH. Might be a mistake.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember now. It's because I changed the Properties class into an enum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!

<daisy.woodstox-osgi-adapter.version>2.0.1</daisy.woodstox-osgi-adapter.version>
<daisy.xmlcatalog.version>2.0.2</daisy.xmlcatalog.version>
<daisy.xpath-registry.version>1.0.2</daisy.xpath-registry.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.daisy.common.xproc.XProcResult;
import org.daisy.common.xproc.calabash.XProcConfigurationFactory;
import org.daisy.pipeline.event.EventBusProvider;
import org.daisy.pipeline.properties.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
Expand Down Expand Up @@ -124,7 +126,7 @@ public void setEventBusProvider(EventBusProvider eventBusProvider){
public void setPropertyPublisherFactory(PropertyPublisherFactory propertyPublisherFactory){
PropertyPublisher propertyPublisher=propertyPublisherFactory.newPropertyPublisher();
//the property publishing step goes here
propertyPublisher.publish("org.daisy.pipeline.xproc.configuration" ,System.getProperty("org.daisy.pipeline.xproc.configuration" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.xproc.configuration" ,Properties.getProperty("org.daisy.pipeline.xproc.configuration" ),this.getClass());
propertyPublisher.publish("com.xmlcalabash.config.jar" ,System.getProperty("com.xmlcalabash.config.jar","true" ),this.getClass());
propertyPublisher.publish("com.xmlcalabash.config.home" ,System.getProperty("com.xmlcalabash.config.home","true" ),this.getClass());
propertyPublisher.publish("com.xmlcalabash.config.cwd" ,System.getProperty("com.xmlcalabash.config.cwd","true" ),this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/
public class EventBusMessageListener implements XProcMessageListener {

private static boolean LOG_DEBUG = Boolean.parseBoolean(System.getProperty("org.daisy.pipeline.calabash.logDebug","false"));
private static boolean LOG_DEBUG = Boolean.parseBoolean(
org.daisy.pipeline.properties.Properties.getProperty("org.daisy.pipeline.calabash.logDebug","false"));

/** The listener. */
EventBusProvider eventBus;
MessageBuliderFactory messageBuilderFactory;
Expand Down
4 changes: 2 additions & 2 deletions framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<relativePath>../parent</relativePath>
</parent>
<artifactId>framework-core</artifactId>
<version>3.1.2-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>DAISY Pipeline 2 :: Framework Core</name>
<dependencies>
Expand Down Expand Up @@ -76,4 +76,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.daisy.common.properties.PropertyPublisherFactory;
import org.daisy.pipeline.clients.Client;
import org.daisy.pipeline.job.impl.DefaultJobManager;
import org.daisy.pipeline.properties.Properties;

public class JobManagerFactory {
private JobStorage storage;
Expand Down Expand Up @@ -47,10 +48,10 @@ public void setRuntimeConfigurator(RuntimeConfigurator configurator){
public void setPropertyPublisherFactory(PropertyPublisherFactory propertyPublisherFactory){
PropertyPublisher propertyPublisher=propertyPublisherFactory.newPropertyPublisher();
//the property publishing step goes here
propertyPublisher.publish("org.daisy.pipeline.iobase" ,System.getProperty("org.daisy.pipeline.iobase","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.home" ,System.getProperty("org.daisy.pipeline.home","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.logdir",System.getProperty("org.daisy.pipeline.logdir","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.procs",System.getProperty("org.daisy.pipeline.procs","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.iobase" ,Properties.getProperty("org.daisy.pipeline.iobase","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.home" ,Properties.getProperty("org.daisy.pipeline.home","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.logdir",Properties.getProperty("org.daisy.pipeline.logdir","" ),this.getClass());
propertyPublisher.publish("org.daisy.pipeline.procs",Properties.getProperty("org.daisy.pipeline.procs","" ),this.getClass());
}

public void unsetPropertyPublisherFactory(PropertyPublisherFactory propertyPublisherFactory){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.daisy.pipeline.job.JobExecutionService;
import org.daisy.pipeline.job.JobQueue;
import org.daisy.pipeline.job.impl.fuzzy.FuzzyJobFactory;
import org.daisy.pipeline.properties.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
Expand Down Expand Up @@ -39,7 +41,7 @@ static PriorityThreadPoolExecutor<Job> configureExecutor(){
int procs=2;

try{
String confProcs=System.getProperty(NUM_PROCS,"2");
String confProcs=Properties.getProperty(NUM_PROCS,"2");
procs=Integer.parseInt(confProcs);
}catch(NumberFormatException e){
logger.info(String.format("Error parsing %s %s",NUM_PROCS,procs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.daisy.pipeline.job.JobId;
import org.daisy.pipeline.job.URIMapper;
import org.daisy.pipeline.properties.Properties;

public class JobURIUtils {
/** The Constant ORG_DAISY_PIPELINE_IOBASE. */
Expand Down Expand Up @@ -80,9 +81,9 @@ public static boolean cleanJobBase(JobId id){
}
}
private static String frameworkBase(){
if (System.getProperty(ORG_DAISY_PIPELINE_IOBASE) == null) {
if (Properties.getProperty(ORG_DAISY_PIPELINE_IOBASE) == null) {
throw new IllegalStateException(String.format("The property %s is not set",ORG_DAISY_PIPELINE_IOBASE ));
}
return System.getProperty(ORG_DAISY_PIPELINE_IOBASE);
return Properties.getProperty(ORG_DAISY_PIPELINE_IOBASE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.daisy.pipeline.properties;

import java.util.Map;

public final class Properties {

private Properties() {
}

// System.getProperties() returns an object that is always up to date
private final static java.util.Properties systemProperties = System.getProperties();
private final static Map<String,String> systemEnv = System.getenv();

/**
* Gets the system property or environment variable indicated by the specified key.
*
* If the key starts with "org.daisy.pipeline", the function first looks for an
* environment variable and falls back to a system property. Otherwise it looks only
* for a system property. The name of the environment variable is derived from the
* name of the system property.
*
* For example, if the key is "org.daisy.pipeline.ws.host", an environment variable
* "PIPELINE2_WS_HOST" will have precedence over the system property.
*
* @param key The name of the system property.
* @return The string value of the system property or environment variable, or null if
* there is no property or variable with that key.
*/
public static String getProperty(String key) {
return getProperty(key, null);
}

/**
* @param key The name of the system property.
* @param defaultValue A default value.
* @return The string value of the system property or environment variable, or the
* default value if there is no property or variable with that key.
*/
public static String getProperty(String key, String defaultValue) {
if (key == null)
throw new NullPointerException();
if (key.startsWith("org.daisy.pipeline.")) {
String envKey = "PIPELINE2_" + key.substring(19).replace('.', '_').toUpperCase();
if (systemEnv.containsKey(envKey))
return systemEnv.get(envKey);
}
return systemProperties.getProperty(key, defaultValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import org.daisy.common.messaging.Message;
import org.daisy.common.messaging.Message.Level;
import org.daisy.pipeline.properties.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,7 +31,7 @@ public final class VolatileMessageStorage {
*
*/
private VolatileMessageStorage() {
int timeout = Integer.valueOf(System.getProperty(
int timeout = Integer.valueOf(Properties.getProperty(
CACHE_TIMEOUT_PROPERTY, "60"));
cache = CacheBuilder.newBuilder()
.expireAfterAccess(timeout, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import org.daisy.common.properties.PropertyPublisher;
import org.daisy.common.properties.PropertyPublisherFactory;
import org.daisy.pipeline.persistence.ForwardingEntityManagerFactory;
import org.daisy.pipeline.properties.Properties;

import org.osgi.service.jpa.EntityManagerFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DerbyEntityManagerFactory extends ForwardingEntityManagerFactory{

private static final String DERBY_JDBC_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
private static final String DERBY_DB_URL = "jdbc:derby:"+System.getProperty("org.daisy.pipeline.data")+"/db;create=true";
private static final String DERBY_DB_URL = "jdbc:derby:"+Properties.getProperty("org.daisy.pipeline.data")+"/db;create=true";

protected static Logger logger = LoggerFactory
.getLogger(DerbyEntityManagerFactory.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Map;

import org.daisy.pipeline.persistence.ForwardingEntityManagerFactory;
import org.daisy.pipeline.properties.Properties;

import org.osgi.service.jpa.EntityManagerFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,11 +24,11 @@ public class MySQLEntityManagerFactory extends ForwardingEntityManagerFactory{
props.put(JAVAX_PERSISTENCE_JDBC_DRIVER,
COM_MYSQL_JDBC_DRIVER);
props.put(JAVAX_PERSISTENCE_JDBC_URL,
System.getProperty(ORG_DAISY_PERSISTENCE_URL));
Properties.getProperty(ORG_DAISY_PERSISTENCE_URL));
props.put(JAVAX_PERSISTENCE_JDBC_USER,
System.getProperty(ORG_DAISY_PERSISTENCE_USER));
Properties.getProperty(ORG_DAISY_PERSISTENCE_USER));
props.put(JAVAX_PERSISTENCE_JDBC_PASSWORD,
System.getProperty(ORG_DAISY_PERSISTENCE_PASSWORD));
Properties.getProperty(ORG_DAISY_PERSISTENCE_PASSWORD));
}

public void setBuilder(EntityManagerFactoryBuilder builder){
Expand Down
4 changes: 4 additions & 0 deletions updater-wrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<packaging>bundle</packaging>
<name>DAISY Pipeline 2 :: Updater</name>
<dependencies>
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.io.InputStream;

import org.daisy.pipeline.properties.Properties;

public class Updater {

private static String UPDATER_BIN="org.pipeline.updater.bin";
Expand All @@ -14,10 +16,10 @@ public class Updater {

//launches the pipeline and waits it to be up
public void update(UpdaterObserver obs) throws IOException {
String bin=System.getProperty(UPDATER_BIN,"");
String deployPath=System.getProperty(DEPLOY_PATH,"");
String updateSite=System.getProperty(UPDATE_SITE,"");
String releaseDescriptor=System.getProperty(RELEASE_DESCRIPTOR,"");
String bin=Properties.getProperty(UPDATER_BIN,"");
String deployPath=Properties.getProperty(DEPLOY_PATH,"");
String updateSite=Properties.getProperty(UPDATE_SITE,"");
String releaseDescriptor=Properties.getProperty(RELEASE_DESCRIPTOR,"");
if (bin.isEmpty()){
throw new IllegalArgumentException(String.format(ERROR,UPDATER_BIN));
}
Expand Down
4 changes: 2 additions & 2 deletions webservice-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>webservice-utils</artifactId>
<version>2.2.3-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>DAISY Pipeline 2 :: Web Service Utils</name>
Expand Down Expand Up @@ -54,4 +54,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
package org.daisy.pipeline.webserviceutils;

public interface Properties {
public static final String MAX_REQUEST_TIME = "org.daisy.pipeline.ws.maxrequesttime";
public static final String TMPDIR = "org.daisy.pipeline.ws.tmpdir";
public static final String AUTHENTICATION = "org.daisy.pipeline.ws.authentication";
public static final String LOCALFS= "org.daisy.pipeline.ws.localfs";
public static final String FRAMEWORK_VERSION="org.daisy.pipeline.version";
public static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
public static final String PORT = "org.daisy.pipeline.ws.port";
public static final String PATH = "org.daisy.pipeline.ws.path";
public static final String HOST = "org.daisy.pipeline.ws.host";
public static final String SSL= "org.daisy.pipeline.ws.ssl";
public static final String SSL_KEYSTORE= "org.daisy.pipeline.ws.ssl.keystore";
public static final String SSL_KEYSTOREPASSWORD= "org.daisy.pipeline.ws.ssl.keystorepassword";
public static final String CLEAN_UP_ON_START_UP = "org.daisy.pipeline.ws.cleanuponstartup";
public enum Properties {

public static final String SSL_KEYPASSWORD= "org.daisy.pipeline.ws.ssl.keypassword";
public static final String CLIENT_KEY= "org.daisy.pipeline.ws.authentication.key";
public static final String CLIENT_SECRET= "org.daisy.pipeline.ws.authentication.secret";
MAX_REQUEST_TIME("org.daisy.pipeline.ws.maxrequesttime"),
TMPDIR("org.daisy.pipeline.ws.tmpdir"),
AUTHENTICATION("org.daisy.pipeline.ws.authentication"),
LOCALFS("org.daisy.pipeline.ws.localfs"),
FRAMEWORK_VERSION("org.daisy.pipeline.version"),
PORT("org.daisy.pipeline.ws.port"),
PATH("org.daisy.pipeline.ws.path"),
HOST("org.daisy.pipeline.ws.host"),
SSL("org.daisy.pipeline.ws.ssl"),
SSL_KEYSTORE("org.daisy.pipeline.ws.ssl.keystore"),
SSL_KEYSTOREPASSWORD("org.daisy.pipeline.ws.ssl.keystorepassword"),
CLEAN_UP_ON_START_UP("org.daisy.pipeline.ws.cleanuponstartup"),
SSL_KEYPASSWORD("org.daisy.pipeline.ws.ssl.keypassword"),
CLIENT_KEY("org.daisy.pipeline.ws.authentication.key"),
CLIENT_SECRET("org.daisy.pipeline.ws.authentication.secret");

private final String key;

private Properties(String key) {
this.key = key;
}

public String get() {
return org.daisy.pipeline.properties.Properties.getProperty(key);
}

public String get(String defaultValue) {
return org.daisy.pipeline.properties.Properties.getProperty(key, defaultValue);
}

public String getName() {
return key;
}

@Override
public String toString() {
return key;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ public String getBaseUri() {
}

private void readOptions() {
String path = System.getProperty(Properties.PATH);
String path = Properties.PATH.get();
if (path != null) {
if (!path.startsWith("/")) {
path = "/" + path;
}
this.path = path;
}

String hostname = System.getProperty(Properties.HOST);
String hostname = Properties.HOST.get();
if (hostname != null) {
host = hostname;
}
if (System.getProperty(Properties.SSL)!=null&&System.getProperty(Properties.SSL).equalsIgnoreCase("true")){
if (Properties.SSL.get()!=null&&Properties.SSL.get().equalsIgnoreCase("true")){
proto="https://";
}

String port = System.getProperty(Properties.PORT);
String port = Properties.PORT.get();
if (port != null) {
try {
int portnum = Integer.parseInt(port);
Expand Down