Author: rareddy
Date: 2009-04-09 19:08:13 -0400 (Thu, 09 Apr 2009)
New Revision: 743
Modified:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleWriter.java
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
Log:
TEIID-479: Made Embedded load using the delegating class loader, and "lib"
configurable, and option to chain the extension directories.
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java 2009-04-09
21:30:19 UTC (rev 742)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDriver.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.URL;
+import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
@@ -362,22 +363,25 @@
// a non-delegating class loader will be created from where all third party
dependent jars can be loaded
ArrayList<URL> runtimeClasspath = new ArrayList<URL>();
+ String libLocation = info.getProperty("dqp.lib",
"./lib/"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (!libLocation.endsWith("/")) { //$NON-NLS-1$
+ libLocation = libLocation + "/"; //$NON-NLS-1$
+ }
// find jars in the "lib" directory; patches is reverse alpaha and
not case sensitive so small letters then capitals
if (!EmbeddedDriver.getDefaultConnectionURL().equals(dqpURL.toString())) {
- runtimeClasspath.addAll(libClassPath(dqpURL, "lib/patches/",
MMURLConnection.REVERSEALPHA)); //$NON-NLS-1$
- runtimeClasspath.addAll(libClassPath(dqpURL, "lib/",
MMURLConnection.DATE)); //$NON-NLS-1$
+ runtimeClasspath.addAll(libClassPath(dqpURL,
libLocation+"patches/", MMURLConnection.REVERSEALPHA)); //$NON-NLS-1$
+ runtimeClasspath.addAll(libClassPath(dqpURL, libLocation,
MMURLConnection.DATE));
}
URL[] dqpClassPath = runtimeClasspath.toArray(new
URL[runtimeClasspath.size()]);
- this.classLoader = new NonDelegatingClassLoader(dqpClassPath,
Thread.currentThread().getContextClassLoader(), new MetaMatrixURLStreamHandlerFactory());
+ this.classLoader = new URLClassLoader(dqpClassPath,
Thread.currentThread().getContextClassLoader(), new MetaMatrixURLStreamHandlerFactory());
String logMsg =
BaseDataSource.getResourceMessage("EmbeddedDriver.use_classpath");
//$NON-NLS-1$
DriverManager.println(logMsg);
for (int i = 0; i < dqpClassPath.length; i++) {
DriverManager.println(dqpClassPath[i].toString());
}
-
// Now using this class loader create the connection factory to the dqp.
ClassLoader current = null;
try {
Modified:
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java
===================================================================
---
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java 2009-04-09
21:30:19 UTC (rev 742)
+++
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleReader.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -46,19 +46,25 @@
* @since 4.3
*/
public class ExtensionModuleReader {
- private static final String MM_JAR_PROTOCOL = "extensionjar";
//$NON-NLS-1$
+ public static final String MM_JAR_PROTOCOL = "extensionjar"; //$NON-NLS-1$
/**
* Load the extension module from the file system
* @return
* @since 4.3
*/
- public static ExtensionModule loadExtensionModule(String extModuleName, URL
extModuleURL) throws MetaMatrixComponentException{
+ public static ExtensionModule loadExtensionModule(String extModuleName, URL[]
contexts) throws MetaMatrixComponentException{
byte[] contents = null;
InputStream in = null;
try {
- in = extModuleURL.openStream();
- contents = ByteArrayHelper.toByteArray(in);
+ URL extModuleURL =
resolveExtensionModule(MM_JAR_PROTOCOL+":"+extModuleName, contexts);
//$NON-NLS-1$
+ if (extModuleURL != null) {
+ in = extModuleURL.openStream();
+ contents = ByteArrayHelper.toByteArray(in);
+ }
+ else {
+ throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("ExtensionModuleReader.ext_module_does_not_exist",
extModuleName)); //$NON-NLS-1$
+ }
} catch (FileNotFoundException e) {
throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("ExtensionModuleReader.ext_module_does_not_exist",
extModuleName)); //$NON-NLS-1$
} catch (IOException e) {
@@ -77,39 +83,44 @@
* @return list of Extension Modules {@link
com.metamatrix.common.config.api.ExtensionModule}
* @since 4.3
*/
- public static List loadExtensionModules(URL extensionPathURL) throws
MetaMatrixComponentException{
+ public static List<ExtensionModule> loadExtensionModules(URL[] contexts) throws
MetaMatrixComponentException{
ObjectInputStream in = null;
- List extModuleList = new ArrayList();
- String extensionPath =
extensionPathURL.toString()+"?action=list&filter=.jar"; //$NON-NLS-1$
+ List<ExtensionModule> extModuleList = new
ArrayList<ExtensionModule>();
+
+ for (URL extensionPathURL: contexts) {
+ String extensionPath =
extensionPathURL.toString()+"?action=list&filter=.jar"; //$NON-NLS-1$
- try {
- extensionPathURL = URLHelper.buildURL(extensionPath);
- in = new ObjectInputStream(extensionPathURL.openStream());
- String[] jarFiles = (String[])in.readObject();
- for (int i = 0; i < jarFiles.length; i++) {
- String jarName = jarFiles[i];
- jarName = jarName.substring(jarName.lastIndexOf('/')+1);
- byte[] contents = null;
- try {
- URL jarFileURL = URLHelper.buildURL(jarFiles[i]);
- InputStream jarStream = jarFileURL.openStream();
- contents = ByteArrayHelper.toByteArray(jarStream);
- jarStream.close();
- } catch (IOException e) {
- throw new MetaMatrixComponentException(e,
DQPEmbeddedPlugin.Util.getString("ExtensionModuleReader.ext_module_failed_to_read",
new Object[] {jarFiles[i]})); //$NON-NLS-1$
- }
- extModuleList.add(new BasicExtensionModule(jarName,
ExtensionModule.JAR_FILE_TYPE, "Jar File", contents)); //$NON-NLS-1$
- }
- } catch (FileNotFoundException e) {
- // if the file not found then it means no extensions directory and no
extension
- // modules, just return a empty list.
- } catch (Exception e) {
- throw new MetaMatrixComponentException(e);
- }finally {
- if (in != null) {
- try{in.close();}catch(IOException e) {}
- }
+ try {
+ extensionPathURL = URLHelper.buildURL(extensionPath);
+ in = new ObjectInputStream(extensionPathURL.openStream());
+ String[] jarFiles = (String[])in.readObject();
+ for (int i = 0; i < jarFiles.length; i++) {
+ String jarName = jarFiles[i];
+ jarName = jarName.substring(jarName.lastIndexOf('/')+1);
+ byte[] contents = null;
+ try {
+ URL jarFileURL = URLHelper.buildURL(jarFiles[i]);
+ InputStream jarStream = jarFileURL.openStream();
+ contents = ByteArrayHelper.toByteArray(jarStream);
+ jarStream.close();
+ } catch (IOException e) {
+ throw new MetaMatrixComponentException(e,
DQPEmbeddedPlugin.Util.getString("ExtensionModuleReader.ext_module_failed_to_read",
new Object[] {jarFiles[i]})); //$NON-NLS-1$
+ }
+ extModuleList.add(new BasicExtensionModule(jarName,
ExtensionModule.JAR_FILE_TYPE, "Jar File", contents)); //$NON-NLS-1$
+ }
+ } catch (FileNotFoundException e) {
+ // if the file not found then it means no extensions directory and no
extension
+ // modules, just return a empty list.
+ } catch (IOException e) {
+ throw new MetaMatrixComponentException(e);
+ } catch(ClassNotFoundException e){
+ throw new MetaMatrixComponentException(e);
+ } finally {
+ if (in != null) {
+ try{in.close();}catch(IOException e) {}
+ }
+ }
}
return extModuleList;
}
@@ -124,31 +135,45 @@
* @throws MalformedURLException
* @since 4.3
*/
- public static URL[] resolveExtensionClasspath(String extClassPath, URL context)
+ public static List<URL> resolveExtensionClasspath(String extClassPath, URL[]
contexts)
throws IOException {
- List urls = new ArrayList();
+ List<URL> urls = new ArrayList<URL>();
StringTokenizer st = new StringTokenizer(extClassPath, ";");
//$NON-NLS-1$
while (st.hasMoreTokens()) {
- URL entry = null;
- String temp = st.nextToken();
- int idx = temp.indexOf(MM_JAR_PROTOCOL);
- if (idx != -1) {
- entry = URLHelper.buildURL(context, temp.substring(idx +
MM_JAR_PROTOCOL.length() + 1));
- InputStream in = null;
- try {
- in = entry.openStream();
- in.close();
- } catch (IOException e) {
- // do nothing as this is just a test to see if the resource is
available
- // Defect 22736 - Change message from warning to detail so this
doesn't look as scary.
- LogManager.logDetail(LogConstants.CTX_DQP,
DQPEmbeddedPlugin.Util.getString("DataService.ext_module_not_found", entry));
//$NON-NLS-1$
- }
- } else {
- entry = new URL(temp);
+ String extModule = st.nextToken();
+ URL entry = resolveExtensionModule(extModule, contexts);
+ if (entry != null) {
+ urls.add(entry);
}
- urls.add(entry);
}
- return (URL[])urls.toArray(new URL[urls.size()]);
- }
+ return urls;
+ }
+
+ public static URL resolveExtensionModule(String extModule, URL[] contexts) throws
IOException {
+ int idx = extModule.indexOf(MM_JAR_PROTOCOL);
+ if (idx != -1) {
+ for (URL context : contexts) {
+ URL entry = URLHelper.buildURL(context, extModule.substring(idx +
MM_JAR_PROTOCOL.length() + 1));
+ if (urlExists(entry)) {
+ return entry;
+ }
+ }
+
+ } else {
+ return new URL(extModule);
+ }
+ return null;
+ }
+
+ private static boolean urlExists(URL url) {
+ InputStream in = null;
+ try {
+ in = url.openStream();
+ in.close();
+ return true;
+ } catch (IOException e) {
+ }
+ return false;
+ }
}
Modified:
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleWriter.java
===================================================================
---
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleWriter.java 2009-04-09
21:30:19 UTC (rev 742)
+++
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/configuration/ExtensionModuleWriter.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -41,11 +41,12 @@
*/
public class ExtensionModuleWriter {
- public static void write(ExtensionModule extModule, URL extModuleURL) throws
MetaMatrixComponentException {
+ public static void write(ExtensionModule extModule, URL[] contexts) throws
MetaMatrixComponentException {
OutputStream out = null;
try {
- String extFile = extModuleURL.toString()+"?action=write";
//$NON-NLS-1$
- extModuleURL = URLHelper.buildURL(extFile);
+ String extFile = extModule.getFullName()+"?action=write";
//$NON-NLS-1$
+ // NOTE: only write to the very first context.
+ URL extModuleURL = URLHelper.buildURL(contexts[0], extFile);
URLConnection conn = extModuleURL.openConnection();
out = conn.getOutputStream();
@@ -65,27 +66,38 @@
* @param extModule
* @since 4.3
*/
- public static void deleteModule(URL extModuleURL) throws
MetaMatrixComponentException{
- String extensionPath = extModuleURL.toString()+"?action=delete";
//$NON-NLS-1$
+ public static void deleteModule(String extModuleName, URL[] contexts) throws
MetaMatrixComponentException{
+ URL extModuleURL = null;
+ try {
+ extModuleURL =
ExtensionModuleReader.resolveExtensionModule(ExtensionModuleReader.MM_JAR_PROTOCOL+":"+extModuleName,
contexts); //$NON-NLS-1$
+ if (extModuleURL == null) {
+ throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("ExtensionModuleReader.ext_module_does_not_exist",
extModuleName)); //$NON-NLS-1$
+ }
+ } catch (IOException e) {
+ throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("ExtensionModuleReader.ext_module_does_not_exist",
extModuleName)); //$NON-NLS-1$
+ }
+
+ String extFile = extModuleURL.toString()+"?action=delete";
//$NON-NLS-1$
+
InputStream in = null;
try {
- extModuleURL = URLHelper.buildURL(extensionPath);
+ extModuleURL = URLHelper.buildURL(extFile);
in = extModuleURL.openStream();
if (in != null) {
// now delete file from the extensions directory..
throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("ExtensionModuleWriter.ext_module_delete_failed",
new Object[] {extModuleURL})); //$NON-NLS-1$
}
-
DQPEmbeddedPlugin.logInfo("ExtensionModuleWriter.ext_module_delete", new
Object[] {extModuleURL.getPath(), extModuleURL}); //$NON-NLS-1$
+
DQPEmbeddedPlugin.logInfo("ExtensionModuleWriter.ext_module_delete", new
Object[] {extModuleName, extModuleURL}); //$NON-NLS-1$
}catch(FileNotFoundException e) {
// this is what we should expect if open the stream.
-
DQPEmbeddedPlugin.logInfo("ExtensionModuleWriter.ext_module_delete", new
Object[] {extModuleURL.getPath(), extModuleURL}); //$NON-NLS-1$
+
DQPEmbeddedPlugin.logInfo("ExtensionModuleWriter.ext_module_delete", new
Object[] {extModuleName, extModuleURL}); //$NON-NLS-1$
}catch(IOException e) {
throw new
MetaMatrixComponentException(DQPEmbeddedPlugin.Util.getString("ExtensionModuleWriter.ext_module_delete_failed",
new Object[] {extModuleURL})); //$NON-NLS-1$
} finally {
if (in != null) {
try {in.close();}catch(IOException e) {}
}
- }
+ }
}
}
Modified:
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
---
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-04-09
21:30:19 UTC (rev 742)
+++
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -207,43 +207,47 @@
* @since 4.3
*/
public URL getUDFFile() {
- String udfFile =
userPreferences.getProperty(DQPEmbeddedProperties.USER_DEFINED_FUNCTIONS);
- if (valid(udfFile)) {
- return getFullyQualifiedPath(udfFile);
- }
try {
- return getFullyQualifiedPath(getDefaultExtensionPath(),
USER_DEFINED_FUNCTION_MODEL);
- } catch (MetaMatrixComponentException e) {
- return null;
- }
+ String udfFile =
userPreferences.getProperty(DQPEmbeddedProperties.USER_DEFINED_FUNCTIONS);
+ if (valid(udfFile)) {
+ return ExtensionModuleReader.resolveExtensionModule(udfFile, getExtensionPath());
+ }
+ return
ExtensionModuleReader.resolveExtensionModule(ExtensionModuleReader.MM_JAR_PROTOCOL+":"+USER_DEFINED_FUNCTION_MODEL,
getExtensionPath()); //$NON-NLS-1$
+ } catch (IOException e) {
+ return null;
+ }
}
/**
* @see
com.metamatrix.dqp.service.ConfigurationService#getCommonExtensionClasspath()
*/
- public URL[] getCommonExtensionClasspath() {
+ public List<URL> getCommonExtensionClasspath() {
String classpath=
userPreferences.getProperty(DQPEmbeddedProperties.COMMON_EXTENSION_CLASPATH);
if (valid(classpath)) {
try {
- URL context = getExtensionPath();
- return ExtensionModuleReader.resolveExtensionClasspath(classpath,
context);
+ return ExtensionModuleReader.resolveExtensionClasspath(classpath,
getExtensionPath());
} catch (IOException e) {
DQPEmbeddedPlugin.logError(e,
"EmbeddedConfigurationService.udf_classspath_failure", new Object[] {});
//$NON-NLS-1$
}
}
+ /*
else {
try {
StringBuffer sb = new StringBuffer();
- List extModules = getExtensionModules();
+ List<ExtensionModule> extModules = getExtensionModules();
boolean valid = false;
- for (Iterator i = extModules.iterator(); i.hasNext();) {
- ExtensionModule module = (ExtensionModule)i.next();
+ for (ExtensionModule module:extModules) {
sb.append("extensionjar:").append(module.getFullName()).append(";");
//$NON-NLS-1$ //$NON-NLS-2$
valid = true;
}
if (valid) {
- URL context = getExtensionPath();
- return ExtensionModuleReader.resolveExtensionClasspath(sb.toString(),
context);
+ classpath = sb.toString();
+ ArrayList<URL> allExtensionModules = new ArrayList<URL>();
+ URL[] contexts = getExtensionPath();
+ for (URL context:contexts) {
+
allExtensionModules.addAll(ExtensionModuleReader.resolveExtensionClasspath(classpath,
context));
+ }
+ return allExtensionModules;
}
} catch (MetaMatrixComponentException e) {
// ok to return null
@@ -251,6 +255,7 @@
DQPEmbeddedPlugin.logError(e,
"EmbeddedConfigurationService.udf_classspath_failure", new Object[] {});
//$NON-NLS-1$
}
}
+ */
return null;
}
@@ -323,7 +328,7 @@
return fileToSave;
}
- URL getVDBSaveLocation() throws MetaMatrixComponentException {
+ URL getVDBSaveLocation() {
URL[] urls = getVDBLocations();
for (int i = 0; i < urls.length; i++) {
String vdblocation = urls[i].toString().toLowerCase();
@@ -634,7 +639,7 @@
*/
public ConnectorBinding getConnectorBinding(String deployedBindingName)
throws MetaMatrixComponentException {
- return (ConnectorBinding)loadedConnectorBindings.get(deployedBindingName);
+ return loadedConnectorBindings.get(deployedBindingName);
}
/**
@@ -803,10 +808,15 @@
* @see com.metamatrix.dqp.service.ConfigurationService#getExtensionPath()
* @since 4.3
*/
- public URL getExtensionPath() {
- String path = userPreferences.getProperty(DQPEmbeddedProperties.DQP_EXTENSIONS);
+ public URL[] getExtensionPath() {
+ String path = userPreferences.getProperty(DQPEmbeddedProperties.DQP_EXTENSIONS,
"./extensions/"); //$NON-NLS-1$
if (valid(path)) {
- return getFullyQualifiedPath(path);
+ ArrayList<URL> urlPaths = new ArrayList<URL>();
+ StringTokenizer st = new StringTokenizer(path, ";"); //$NON-NLS-1$
+ while(st.hasMoreElements()) {
+ urlPaths.add(getFullyQualifiedPath(st.nextToken()));
+ }
+ return urlPaths.toArray(new URL[urlPaths.size()]);
}
return null;
}
@@ -815,46 +825,32 @@
* @see com.metamatrix.dqp.service.ConfigurationService#useExtensionClasspath()
*/
public boolean useExtensionClasspath() {
- return (getExtensionPath() != null);
+ String path = userPreferences.getProperty(DQPEmbeddedProperties.DQP_EXTENSIONS);
+ return valid(path);
}
- /**
- * @return - returns a non null default path if the extension path is not defined
- * @throws MetaMatrixComponentException
- */
- URL getDefaultExtensionPath() throws MetaMatrixComponentException{
- URL extPath = getExtensionPath();
- if (extPath != null) {
- return extPath;
- }
- return getFullyQualifiedPath("./extensions/"); //$NON-NLS-1$
- }
-
/**
* @see
com.metamatrix.dqp.service.ConfigurationService#getExtensionModule(java.lang.String)
* @since 4.3
*/
public ExtensionModule getExtensionModule(String extModuleName) throws
MetaMatrixComponentException {
- URL extModulePath = getFullyQualifiedPath(getDefaultExtensionPath(),
extModuleName);
- return ExtensionModuleReader.loadExtensionModule(extModuleName, extModulePath);
+ return ExtensionModuleReader.loadExtensionModule(extModuleName,
getExtensionPath());
}
/**
* @see com.metamatrix.dqp.service.ConfigurationService#getExtensionModules()
* @since 4.3
*/
- public List getExtensionModules() throws MetaMatrixComponentException {
- URL extPath = getDefaultExtensionPath();
- return ExtensionModuleReader.loadExtensionModules(extPath);
+ public List<ExtensionModule> getExtensionModules() throws
MetaMatrixComponentException {
+ return ExtensionModuleReader.loadExtensionModules(getExtensionPath());
}
/**
* @see
com.metamatrix.dqp.service.ConfigurationService#saveExtensionModule(com.metamatrix.common.config.api.ExtensionModule)
* @since 4.3
*/
- public void saveExtensionModule(ExtensionModule extModule) throws
MetaMatrixComponentException {
- URL extModuleURL = getFullyQualifiedPath(getDefaultExtensionPath(),
extModule.getFullName());
- ExtensionModuleWriter.write(extModule, extModuleURL);
+ public void saveExtensionModule(ExtensionModule extModule) throws
MetaMatrixComponentException {
+ ExtensionModuleWriter.write(extModule, getExtensionPath());
}
/**
@@ -862,8 +858,7 @@
* @since 4.3
*/
public void deleteExtensionModule(String extModuleName) throws
MetaMatrixComponentException {
- URL extModuleURL = getFullyQualifiedPath(getDefaultExtensionPath(),
extModuleName);
- ExtensionModuleWriter.deleteModule(extModuleURL);
+ ExtensionModuleWriter.deleteModule(extModuleName, getExtensionPath());
}
/**
@@ -930,9 +925,9 @@
public void loadUDF() throws MetaMatrixComponentException {
URL udfFile = getUDFFile();
if(udfFile != null && exists(udfFile)) {
- URL[] urls = getCommonExtensionClasspath();
+ List<URL> urls = getCommonExtensionClasspath();
try {
- this.udfSource = new UDFSource(udfFile, urls);
+ this.udfSource = new UDFSource(udfFile, urls.toArray(new URL[urls.size()]));
FunctionLibraryManager.registerSource(this.udfSource);
DQPEmbeddedPlugin.logInfo("EmbeddedConfigurationService.udf_load", new
Object[] {udfFile, urls}); //$NON-NLS-1$
} catch (IOException e) {
Modified:
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
===================================================================
---
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java 2009-04-09
21:30:19 UTC (rev 742)
+++
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -452,7 +452,7 @@
}
private void removeConnectorBinding(String connectorBindingName)
- throws MetaMatrixComponentException, ApplicationLifecycleException{
+ throws MetaMatrixComponentException {
// do house cleanup of the objects.
ConnectorID id = selectConnector(connectorBindingName);
connectorMgrs.remove(id);
@@ -565,17 +565,17 @@
}
DQPEmbeddedPlugin.logInfo("DataService.useClassloader", new
Object[] {classPath}); //$NON-NLS-1$
- URL context = getConfigurationService().getExtensionPath();
- URL[] userPath = ExtensionModuleReader.resolveExtensionClasspath(classPath,
context);
+ List<URL> userPath =
ExtensionModuleReader.resolveExtensionClasspath(classPath,
getConfigurationService().getExtensionPath());
// since we are using the extensions, get the common extension path
- URL[] commonExtensionPath =
getConfigurationService().getCommonExtensionClasspath();
- ArrayList<URL> urlPath = new ArrayList<URL>();
+ List<URL> commonExtensionPath =
getConfigurationService().getCommonExtensionClasspath();
- urlPath.addAll(Arrays.asList(userPath));
+ ArrayList<URL> urlPath = new ArrayList<URL>();
+ urlPath.addAll(userPath);
+
if (commonExtensionPath != null) {
- urlPath.addAll(Arrays.asList(commonExtensionPath));
+ urlPath.addAll(commonExtensionPath);
}
ClassLoader classLoader = new URLFilteringClassLoader(urlPath.toArray(new
URL[urlPath.size()]), Thread.currentThread().getContextClassLoader(), new
MetaMatrixURLStreamHandlerFactory());
Modified:
trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java
===================================================================
---
trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java 2009-04-09
21:30:19 UTC (rev 742)
+++
trunk/embedded/src/test/java/com/metamatrix/dqp/embedded/services/TestEmbeddedConfigurationService.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -22,6 +22,8 @@
package com.metamatrix.dqp.embedded.services;
+import java.io.File;
+import java.io.FileWriter;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
@@ -39,8 +41,10 @@
import com.metamatrix.common.config.api.ConfigurationID;
import com.metamatrix.common.config.api.ConnectorBinding;
import com.metamatrix.common.config.api.ConnectorBindingID;
+import com.metamatrix.common.config.api.ExtensionModule;
import com.metamatrix.common.config.model.BasicConnectorBinding;
import com.metamatrix.common.config.model.BasicConnectorBindingType;
+import com.metamatrix.common.config.model.BasicExtensionModule;
import com.metamatrix.common.util.crypto.CryptoUtil;
import com.metamatrix.common.util.crypto.NullCryptor;
import com.metamatrix.common.vdb.api.VDBArchive;
@@ -128,7 +132,7 @@
Properties p = EmbeddedTestUtil.getProperties();
p.remove(DQPEmbeddedProperties.DQP_EXTENSIONS);
service.userPreferences = p;
-
assertTrue(service.getDefaultExtensionPath().toString().endsWith("dqp/extensions/"));
//$NON-NLS-1$
+
assertTrue(service.getExtensionPath()[0].toString().endsWith("dqp/extensions/"));
//$NON-NLS-1$
}
public void testGetDirectoryToStoreVDBS() throws Exception {
@@ -320,11 +324,39 @@
assertNotNull(service.getSystemVdb());
}
- public void testGetUDFFileName() throws Exception{
+ public void testUDF() throws Exception{
Properties p = EmbeddedTestUtil.getProperties();
- p.setProperty(DQPEmbeddedProperties.USER_DEFINED_FUNCTIONS,
"./lib/foo.txt"); //$NON-NLS-1$
+ p.setProperty(DQPEmbeddedProperties.USER_DEFINED_FUNCTIONS,
"extensionjar:foo.xmi"); //$NON-NLS-1$
+ p.setProperty("dqp.extensions", "./foo/;./bar/");
//$NON-NLS-1$ //$NON-NLS-2$
service.userPreferences = p;
-
assertTrue(service.getUDFFile().toString().endsWith(UnitTestUtil.getTestScratchPath()+"/dqp/lib/foo.txt"));
//$NON-NLS-1$
+
+ assertNull(service.getUDFFile());
+
+ File f = new File("target/scratch/dqp/bar"); //$NON-NLS-1$
+ f.mkdirs();
+ File xmiFile = new File("target/scratch/dqp/bar/foo.xmi");
//$NON-NLS-1$
+ FileWriter fw = new FileWriter(xmiFile);
+ fw.write("testing extension modules"); //$NON-NLS-1$
+ fw.flush();
+ fw.close();
+
+
+
assertTrue(service.getUDFFile().toString().endsWith(UnitTestUtil.getTestScratchPath()+"/dqp/bar/foo.xmi"));
//$NON-NLS-1$
+
+ p.setProperty(DQPEmbeddedProperties.USER_DEFINED_FUNCTIONS,
xmiFile.toURL().toString());
+ assertEquals(xmiFile.toURL().toString(), service.getUDFFile().toString());
+
+ xmiFile.delete();
+
+ // now look for the default
+ p.remove(DQPEmbeddedProperties.USER_DEFINED_FUNCTIONS);
+ assertNull(service.getUDFFile());
+
+ service.saveExtensionModule(new
BasicExtensionModule(ConfigurationService.USER_DEFINED_FUNCTION_MODEL, "adding
extension module", "xmi", "testing extension
modules".getBytes())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+
assertTrue(service.getUDFFile().toString().endsWith("/dqp/foo/"+ConfigurationService.USER_DEFINED_FUNCTION_MODEL));
//$NON-NLS-1$
+
+ f.delete();
}
public void testGetVDBs() throws Exception{
@@ -461,4 +493,65 @@
assertEquals(23, service.loadedConnectorTypes.size());
}
+ public void testUseMultipleExtensionPath() throws Exception {
+ Properties p = EmbeddedTestUtil.getProperties();
+ p.setProperty("dqp.extensions", "/foo/;../x/bar/");
//$NON-NLS-1$ //$NON-NLS-2$
+ service.userPreferences = p;
+ assertEquals("mmfile:/foo/",
service.getExtensionPath()[0].toExternalForm()); //$NON-NLS-1$
+ assertEquals("mmfile:target/scratch/x/bar/",
service.getExtensionPath()[1].toExternalForm()); //$NON-NLS-1$
+ }
+
+ public void testGetExtensionModule() throws Exception {
+ Properties p = EmbeddedTestUtil.getProperties();
+
+ File f = new File("target/scratch/dqp/bar"); //$NON-NLS-1$
+ f.mkdirs();
+ FileWriter fw = new FileWriter("target/scratch/dqp/bar/extfile.jar");
//$NON-NLS-1$
+ fw.write("testing extension modules"); //$NON-NLS-1$
+ fw.flush();
+ fw.close();
+
+ p.setProperty("dqp.extensions", "./foo/;./bar/");
//$NON-NLS-1$ //$NON-NLS-2$
+ service.userPreferences = p;
+
+ // get all the modules in the system.
+ List<ExtensionModule> modules = service.getExtensionModules();
+ assertEquals("extfile.jar", modules.get(0).getID().getFullName());
//$NON-NLS-1$
+ assertEquals("testing extension modules", new
String(modules.get(0).getFileContents())); //$NON-NLS-1$
+
+ // get individual module
+ ExtensionModule m = service.getExtensionModule("extfile.jar");
//$NON-NLS-1$
+ assertEquals("testing extension modules", new
String(m.getFileContents())); //$NON-NLS-1$
+
+ // test adding of the extension module
+ service.saveExtensionModule(new BasicExtensionModule("added-ext.jar",
"adding extension module", "jar", "testing extension
modules".getBytes())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ modules = service.getExtensionModules();
+ assertEquals(2, modules.size());
+
+ m = service.getExtensionModule("added-ext.jar"); //$NON-NLS-1$
+ assertEquals("testing extension modules", new
String(m.getFileContents())); //$NON-NLS-1$
+
+ modules = service.getExtensionModules();
+ assertEquals(2, modules.size());
+
+ // test common class path; also makes sure that the conect in position (1) has
the newly added module
+ service.userPreferences.setProperty("dqp.extension.CommonClasspath",
"extensionjar:added-ext.jar;extensionjar:extfile.jar"); //$NON-NLS-1$
//$NON-NLS-2$
+ assertEquals("mmfile:target/scratch/dqp/foo/added-ext.jar",
service.getCommonExtensionClasspath().get(0).toString()); //$NON-NLS-1$
+ assertEquals("mmfile:target/scratch/dqp/bar/extfile.jar",
service.getCommonExtensionClasspath().get(1).toString()); //$NON-NLS-1$
+
+ // test delete
+ service.deleteExtensionModule("added-ext.jar"); //$NON-NLS-1$
+ modules = service.getExtensionModules();
+ assertEquals(1, modules.size());
+
+ // test for non-existent module
+ try {
+ m = service.getExtensionModule("added-ext.jar"); //$NON-NLS-1$
+ fail("must have failed to find"); //$NON-NLS-1$
+ } catch (MetaMatrixComponentException e) {
+ }
+
+ f.delete();
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java 2009-04-09
21:30:19 UTC (rev 742)
+++
trunk/engine/src/main/java/com/metamatrix/dqp/service/ConfigurationService.java 2009-04-09
23:08:13 UTC (rev 743)
@@ -102,7 +102,7 @@
* files are loaded usually as the extension modules.
* @return URL[] - Classpath for the UDF jar files
*/
- public URL[] getCommonExtensionClasspath();
+ public List<URL> getCommonExtensionClasspath();
/**
* URL to Log file name
@@ -262,7 +262,7 @@
* @return String URL - url to extension path; null if extensions are not used
* @since 4.3
*/
- public URL getExtensionPath();
+ public URL[] getExtensionPath();
/**
* Get the list of extension modules available in the store
@@ -270,7 +270,7 @@
* @throws MetaMatrixComponentException
* @since 4.3
*/
- public List getExtensionModules() throws MetaMatrixComponentException;
+ public List<ExtensionModule> getExtensionModules() throws
MetaMatrixComponentException;
/**
* Get the extension module by the given identifier