diff --git a/common/source/java/ch/systemsx/cisd/common/spring/Bootstrapper.java b/common/source/java/ch/systemsx/cisd/common/spring/Bootstrapper.java new file mode 100644 index 0000000000000000000000000000000000000000..4f96c2f8e872ed70662265e4cb8d3ebc7c6c0bb4 --- /dev/null +++ b/common/source/java/ch/systemsx/cisd/common/spring/Bootstrapper.java @@ -0,0 +1,101 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.common.spring; + +import java.util.ArrayList; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.support.AbstractRefreshableConfigApplicationContext; + +/** + * Bootstrapper bean responsible for loading resources conditionally basing on property values. + * Normally properties are initialized by Spring after all beans are being instanced - this class + * workarounds this problem by refreshing the application context after properties are being loaded. + * + * @author Pawel Glyzewski + */ +public class Bootstrapper implements ApplicationContextAware, InitializingBean +{ + private AbstractRefreshableConfigApplicationContext context; + + private String[] configLocations; + + private String[] conditionalConfigLocations; + + public void setConfigLocation(final String configLocation) + { + this.configLocations = new String[] + { configLocation }; + } + + public void setConditionalConfigLocations(final String[] conditionalConfigLocations) + { + this.conditionalConfigLocations = conditionalConfigLocations; + } + + @Override + public void setApplicationContext(final ApplicationContext applicationContext) + throws BeansException + { + context = (AbstractRefreshableConfigApplicationContext) applicationContext; + } + + @Override + public void afterPropertiesSet() throws Exception + { + ArrayList<String> allConfigLocations = new ArrayList<String>(); + for (String configLocation : configLocations) + { + allConfigLocations.add(configLocation); + } + + if (conditionalConfigLocations != null) + { + for (String conditionalConfigLocationString : conditionalConfigLocations) + { + int index = conditionalConfigLocationString.indexOf(":"); + if (index != -1) + { + String condition = conditionalConfigLocationString.substring(0, index); + if (evaluateCondition(condition)) + { + allConfigLocations + .add(conditionalConfigLocationString.substring(index + 1)); + } + } + } + } + + context.setConfigLocations(allConfigLocations.toArray(new String[allConfigLocations.size()])); + context.refresh(); + } + + private static boolean evaluateCondition(String condition) + { + if (condition.contains("~")) + { + int index = condition.indexOf("~"); + String property = condition.substring(0, index); + String containedText = condition.substring(index + 1); + return property.contains(containedText); + } + return false; + } +} diff --git a/installation/resource/installer/bin/finish-installation.sh b/installation/resource/installer/bin/finish-installation.sh index 6872072672480e44eb7a1527b6444148add4d4c6..0acf6e627974050e46ad5927de306d8403cc260d 100644 --- a/installation/resource/installer/bin/finish-installation.sh +++ b/installation/resource/installer/bin/finish-installation.sh @@ -31,16 +31,3 @@ if [ -d "$DATA_TMPEXTRACT" ]; then done rm -rf "$DATA_TMPEXTRACT" fi - -APPLICATION_CONTEXT_FILE="$INSTALL_PATH/servers/openBIS-server/jetty/webapps/openbis/WEB-INF/classes/standard-technologies-applicationContext.xml" -if [ -f "$APPLICATION_CONTEXT_FILE" ]; then - tmpFile="$BASE/xxx.xml" - awk '/plugin-applicationContext/{gsub(/!*--/,"")}; 1' "$APPLICATION_CONTEXT_FILE" > "$tmpFile" - mv "$tmpFile" "$APPLICATION_CONTEXT_FILE" - awk '/plugin-applicationContext/{gsub(/import/,"!--import") gsub(/>/,"-->")}; 1' "$APPLICATION_CONTEXT_FILE" > "$tmpFile" - mv "$tmpFile" "$APPLICATION_CONTEXT_FILE" - for technology in $ENABLED_TECHNOLOGIES; do - awk -v technology=${technology/,/} 'index($0, technology){gsub(/!*--/,"")}; 1' "$APPLICATION_CONTEXT_FILE" > "$tmpFile" - mv "$tmpFile" "$APPLICATION_CONTEXT_FILE" - done -fi \ No newline at end of file diff --git a/openbis_standard_technologies/source/java/standard-technologies-applicationContext.xml b/openbis_standard_technologies/source/java/standard-technologies-applicationContext.xml index d20faa6fe2fa6c0f5583d63b2021452f67171a6d..eb620fa2ad5f7479f431e01f8df922e33645036a 100644 --- a/openbis_standard_technologies/source/java/standard-technologies-applicationContext.xml +++ b/openbis_standard_technologies/source/java/standard-technologies-applicationContext.xml @@ -8,14 +8,22 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-2.5.xsd"> + http://www.springframework.org/schema/context/spring-context-2.5.xsd +"> <import resource="applicationContext.xml"/> - <import resource="proteomics-plugin-applicationContext.xml"/> - <import resource="screening-plugin-applicationContext.xml"/> + + <bean name="bootstrap" class="ch.systemsx.cisd.common.spring.Bootstrapper"> + <property name="configLocation" value="classpath:applicationContext.xml" /> + <property name="conditionalConfigLocations"> + <list> + <value>${enabled-technologies}~proteomics:classpath:proteomics-plugin-applicationContext.xml</value> + <value>${enabled-technologies}~screening:classpath:screening-plugin-applicationContext.xml</value> + </list> + </property> + </bean> <plugins:component-scan base-package="ch.systemsx.cisd.openbis" annotation-config="false"> <plugins:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </plugins:component-scan> - </beans> \ No newline at end of file