com.ibm.sbt.jslibrary.SBTEnvironment Maven / Gradle / Ivy
/*
* © Copyright IBM Corp. 2012
*
* 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 com.ibm.sbt.jslibrary;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import com.ibm.commons.Platform;
import com.ibm.commons.runtime.Context;
import com.ibm.commons.util.StringUtil;
import com.ibm.commons.util.io.ReaderInputStream;
import com.ibm.sbt.services.endpoints.EndpointFactory;
/**
* SBT Environment
*
* @author Philippe Riand
*/
public class SBTEnvironment {
/**
* Push the context of an environment
*/
public static void push(Context context, String name) {
SBTEnvironment env = SBTEnvironmentFactory.get(name);
if(env!=null) {
push(context,env);
}
}
public static void push(Context context, SBTEnvironment env) {
// Add the aliases as properties
Endpoint[] endpoints = env.getEndpointsArray();
if(endpoints!=null) {
for(int i=0; i0) {
return StringUtil.concatStrings(this.runtimes, ',', false);
}
return "";
}
public void setRuntimes(String sRuntimes){
this.runtimes = StringUtil.splitString(sRuntimes, ',');
}
public boolean hasRuntime(String runtime) {
if(runtimes!=null && runtime.length()>=1) {
for(int i=0; i0) {
Endpoint[] endpoints = new Endpoint[a.length];
for(int i=0; i=0) {
ep.setName(s.substring(0,pos).trim());
ep.setAlias(s.substring(pos+1).trim());
} else {
ep.setName(s);
}
}
return endpoints;
}
}
return null;
}
//
// Utilities to read a list of strings as rows
// These are intended to be used by inheriting classes
//
/**
* Read a list of endpoints from a string and create an array if non empty.
* @param sEndpoints
* @return Array of Endpoint
* @throws IOException
*/
public static Endpoint[] readEndpoints(String sEndpoints) throws IOException {
if(StringUtil.isNotEmpty(sEndpoints)) {
String[] a = splitRows(sEndpoints);
if(a.length>0) {
Endpoint[] endpoints = new Endpoint[a.length];
for(int i=0; i=0) {
ep.setName(s.substring(0,pos).trim());
ep.setAlias(s.substring(pos+1).trim());
} else {
ep.setName(s);
}
}
return endpoints;
}
}
return null;
}
/**
* Read a list of properties from a string and create an array if non empty.
* @param sProperty
* @return Array of Property
* @throws IOException
*/
public static Property[] parseProperties(String sProperty) throws IOException {
if(StringUtil.isNotEmpty(sProperty)) {
Properties props = new Properties();
StringReader r = new StringReader(sProperty);
props.load(new ReaderInputStream(r));
List properties = new ArrayList();
for(Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy