Author: rmannibucau
Date: Sun Aug 24 11:56:59 2014
New Revision: 1620124
URL: http://svn.apache.org/r1620124
Log:
TOMEE-1331 new resolver API - extensible now
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ArchiveResolver.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/HttpResolver.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisiningResolverCreated.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisioningResolver.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/SimpleUrlResolver.java
Modified:
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/ServiceClasspathTest.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/loader/ProvisioningUtilTest.java
tomee/tomee/trunk/maven/jarstxt-maven-plugin/src/main/java/org/apache/openejb/maven/jarstxt/JarsTxtMojo.java
tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
Modified:
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
(original)
+++
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
Sun Aug 24 11:56:59 2014
@@ -18,13 +18,13 @@ package org.apache.openejb.arquillian.co
import org.apache.openejb.loader.ProvisioningUtil;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.loader.provisining.HttpResolver;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URI;
import java.util.Properties;
import java.util.logging.Logger;
@@ -36,13 +36,15 @@ public class MavenCache {
// initializing the SystemInstance because we'll need it for
configuration
try {
- SystemInstance.get().init(new Properties());
+ if (!SystemInstance.isInitialized()) {
+ SystemInstance.init(new Properties());
+ }
} catch (final Exception e) {
// no-op
}
try {
- return new
File(ProvisioningUtil.realLocation(artifactInfo.startsWith("mvn") ? "" : "mvn:"
+ artifactInfo));
+ return new
File(ProvisioningUtil.realLocation(artifactInfo.startsWith("mvn") ? "" : "mvn:"
+ artifactInfo).iterator().next());
} catch (final Exception e) {
// ignored
}
@@ -64,7 +66,7 @@ public class MavenCache {
InputStream is = null;
OutputStream os = null;
try {
- is = ProvisioningUtil.inputStreamTryingProxies(new URI(source));
+ is = new HttpResolver().resolve(source);
try {
file = File.createTempFile("dload", ".fil");
} catch (final Throwable e) {
@@ -84,7 +86,8 @@ public class MavenCache {
os.write(buffer, 0, bytesRead);
}
} catch (final Exception e) {
- throw new DownloadException("Unable to download " + source + " to
" + file.getAbsolutePath(), e);
+ throw new DownloadException("Unable to download " + source + " to "
+ + (file == null ? "null" : file.getAbsolutePath()), e);
} finally {
if (is != null) {
try {
Modified:
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
(original)
+++
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
Sun Aug 24 11:56:59 2014
@@ -18,6 +18,7 @@ package org.apache.openejb.arquillian.co
import org.apache.openejb.loader.ProvisioningUtil;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
import org.apache.tomee.util.QuickServerXmlParser;
import org.codehaus.swizzle.stream.ReplaceStringsInputStream;
import org.jboss.arquillian.container.spi.client.container.LifecycleException;
@@ -37,6 +38,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -86,7 +88,7 @@ public class Setup {
return; // in this case we don't want to override the conf
}
- final Map<String, String> replacements = new HashMap<String, String>();
+ final Map<String, String> replacements = new HashMap<>();
replacements.put(ports.http(),
String.valueOf(configuration.getHttpPort()));
replacements.put(ports.https(),
String.valueOf(configuration.getHttpsPort()));
replacements.put(ports.stop(),
String.valueOf(configuration.getStopPort()));
@@ -151,9 +153,9 @@ public class Setup {
}
public static File downloadFile(final String artifactName, final String
altUrl) {
- final String cache =
SystemInstance.get().getOptions().get(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER,
(String) null);
+ final String cache =
SystemInstance.get().getOptions().get(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER,
(String) null);
if (cache == null) { // let the user override it
- System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER,
"target");
+
System.setProperty(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER,
"target");
}
try {
@@ -164,7 +166,7 @@ public class Setup {
return artifact.getAbsoluteFile();
} finally {
if (cache == null) {
-
System.clearProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
+
System.clearProperty(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER);
}
}
}
@@ -193,7 +195,7 @@ public class Setup {
InputStream in = IO.read(file);
if (escape) {
- final Map<String, String> escaped = new HashMap<String, String>();
+ final Map<String, String> escaped = new HashMap<>();
for (final Map.Entry<String, String> entry :
replacements.entrySet()) {
final String key = entry.getKey();
final String value = entry.getValue();
@@ -351,14 +353,24 @@ public class Setup {
return;
}
+ try { // initializing the SystemInstance because we'll need it for
configuration
+ if (!SystemInstance.isInitialized()) {
+ SystemInstance.init(new Properties());
+ }
+ } catch (final Exception e) {
+ // no-op
+ }
+
final File libFolder = new File(tomeeHome, "lib");
for (final String lib : libs.split("\n")) {
- final String location = ProvisioningUtil.realLocation(lib.trim());
- final File from = new File(location);
- try {
- org.apache.openejb.loader.IO.copy(from, new File(libFolder,
from.getName()));
- } catch (final IOException e) {
- throw new IllegalArgumentException(e);
+ final Set<String> locations =
ProvisioningUtil.realLocation(lib.trim());
+ for (final String location : locations) {
+ final File from = new File(location);
+ try {
+ org.apache.openejb.loader.IO.copy(from, new
File(libFolder, from.getName()));
+ } catch (final IOException e) {
+ throw new IllegalArgumentException(e);
+ }
}
}
}
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
Sun Aug 24 11:56:59 2014
@@ -34,8 +34,8 @@ import org.apache.openejb.config.sys.Dep
import org.apache.openejb.config.sys.JaxbOpenejb;
import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.IO;
-import org.apache.openejb.loader.ProvisioningUtil;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
@@ -77,7 +77,7 @@ public class DeployerEjb implements Depl
public static final String OPENEJB_VALUE_BINARIES =
"openejb.deployer.binaries.value";
public static final String OPENEJB_APP_AUTODEPLOY =
"openejb.app.autodeploy";
- public static final ThreadLocal<Boolean> AUTO_DEPLOY = new
ThreadLocal<Boolean>();
+ public static final ThreadLocal<Boolean> AUTO_DEPLOY = new ThreadLocal<>();
private static final File uniqueFile;
private static final boolean oldWarDeployer =
"old".equalsIgnoreCase(SystemInstance.get().getOptions().get("openejb.deployer.war",
"new"));
@@ -163,7 +163,7 @@ public class DeployerEjb implements Depl
if
("true".equalsIgnoreCase(properties.getProperty(OPENEJB_USE_BINARIES,
"false"))) {
file = copyBinaries(properties);
} else {
- file = new File(realLocation(rawLocation));
+ file = new File(realLocation(rawLocation).iterator().next());
}
final boolean autoDeploy =
Boolean.parseBoolean(properties.getProperty(OPENEJB_APP_AUTODEPLOY, "false"));
@@ -185,7 +185,7 @@ public class DeployerEjb implements Depl
appModule = deploymentLoader.load(file);
// Add any alternate deployment descriptors to the modules
- final Map<String, DeploymentModule> modules = new TreeMap<String,
DeploymentModule>();
+ final Map<String, DeploymentModule> modules = new TreeMap<>();
for (final DeploymentModule module : appModule.getEjbModules()) {
modules.put(module.getModuleId(), module);
}
@@ -274,7 +274,7 @@ public class DeployerEjb implements Depl
}
private static File copyBinaries(final Properties props) throws
OpenEJBException {
- final File dump =
ProvisioningUtil.cacheFile(props.getProperty(OPENEJB_PATH_BINARIES,
"dump.war"));
+ final File dump =
ProvisioningResolver.cacheFile(props.getProperty(OPENEJB_PATH_BINARIES,
"dump.war"));
if (dump.exists()) {
Files.delete(dump);
final String name = dump.getName();
@@ -363,11 +363,11 @@ public class DeployerEjb implements Depl
public void undeploy(final String moduleId) throws UndeployException,
NoSuchApplicationException {
AppInfo appInfo = assembler.getAppInfo(moduleId);
if (appInfo == null) {
- appInfo = assembler.getAppInfo(realLocation(moduleId));
+ appInfo =
assembler.getAppInfo(realLocation(moduleId).iterator().next());
if (appInfo == null) {
appInfo = assembler.getAppInfo(new
File(moduleId).getAbsolutePath());
if (appInfo == null) {
- appInfo = assembler.getAppInfo(new
File(realLocation(moduleId)).getAbsolutePath());
+ appInfo = assembler.getAppInfo(new
File(realLocation(moduleId).iterator().next()).getAbsolutePath());
}
}
}
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
Sun Aug 24 11:56:59 2014
@@ -551,11 +551,11 @@ public class Assembler extends Assembler
}
public AppInfo getAppInfo(final String path) {
- return deployedApplications.get(ProvisioningUtil.realLocation(path));
+ return
deployedApplications.get(ProvisioningUtil.realLocation(path).iterator().next());
}
public boolean isDeployed(final String path) {
- return
deployedApplications.containsKey(ProvisioningUtil.realLocation(path));
+ return
deployedApplications.containsKey(ProvisioningUtil.realLocation(path).iterator().next());
}
public Collection<AppInfo> getDeployedApplications() {
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
Sun Aug 24 11:56:59 2014
@@ -30,9 +30,11 @@ import org.apache.xbean.finder.filter.Fi
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -107,7 +109,7 @@ public class ProvisioningClassLoaderConf
}
- final Set<URL> repos =
Files.listJars(ProvisioningUtil.realLocation(location));
+ final Set<URL> repos =
toUrls(ProvisioningUtil.realLocation(location));
toAdd.addAll(repos);
if (validJar) {
@@ -130,4 +132,16 @@ public class ProvisioningClassLoaderConf
excluded = Filters.prefixes(toExclude.toArray(new
String[toExclude.size()]));
}
}
+
+ private static Set<URL> toUrls(final Set<String> strings) {
+ final Set<URL> urls = new HashSet<>();
+ for (final String s : strings) {
+ try {
+ urls.add(new File(s).toURI().toURL());
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ return urls;
+ }
}
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
Sun Aug 24 11:56:59 2014
@@ -114,6 +114,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -784,7 +785,10 @@ public class ConfigurationFactory implem
final String[] paths = cp.split(File.pathSeparator);
final List<URL> urls = new ArrayList<>();
for (final String path : paths) {
- urls.add(new
File(PropertyPlaceHolderHelper.value(ProvisioningUtil.realLocation(path))).toURI().normalize().toURL());
+ final Set<String> values =
ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.value(path));
+ for (final String v : values) {
+ urls.add(new File(v).toURI().normalize().toURL());
+ }
}
deployments.setClasspath(new
URLClassLoaderFirst(urls.toArray(new URL[urls.size()]),
ParentClassLoaderFinder.Helper.get()));
}
@@ -1254,16 +1258,17 @@ public class ConfigurationFactory implem
final FileUtils base = SystemInstance.get().getBase();
final String[] strings = rawstring.split(File.pathSeparator);
- final URI[] classpath = new URI[strings.length];
+ final Collection<URI> classpath = new LinkedList<>();
- for (int i = 0; i < strings.length; i++) {
- final String string = strings[i];
- final String pathname =
ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.simpleValue(string));
- final File file = base.getFile(pathname, false);
- classpath[i] = file.toURI();
+ for (final String string : strings) {
+ final Set<String> locations =
ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.simpleValue(string));
+ for (final String location : locations) {
+ final File file = base.getFile(location, false);
+ classpath.add(file.toURI());
+ }
}
- return classpath;
+ return classpath.toArray(new URI[classpath.size()]);
}
private String overrideKey(final org.apache.openejb.config.Service
service) {
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
Sun Aug 24 11:56:59 2014
@@ -17,7 +17,6 @@
package org.apache.openejb.config;
-import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.ProvisioningUtil;
import org.apache.openejb.util.PropertyPlaceHolderHelper;
import org.xml.sax.Attributes;
@@ -27,6 +26,7 @@ import org.xml.sax.helpers.DefaultHandle
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.LinkedHashSet;
@@ -57,7 +57,7 @@ public class QuickContextXmlParser exten
}
public Collection<URL> getAdditionalURLs() {
- final Set<URL> set = new LinkedHashSet<URL>();
+ final Set<URL> set = new LinkedHashSet<>();
if (virtualClasspath != null) {
final StringTokenizer tkn = new StringTokenizer(virtualClasspath,
";");
@@ -67,7 +67,14 @@ public class QuickContextXmlParser exten
continue;
}
-
set.addAll(Files.listJars(ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.simpleValue(token))));
+ final Set<String> locations =
ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.simpleValue(token));
+ for (final String location : locations) {
+ try {
+ set.add(new File(location).toURI().toURL());
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
}
}
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalContextManager.java
Sun Aug 24 11:56:59 2014
@@ -43,7 +43,8 @@ public class ThreadLocalContextManager {
public static final ThreadLocalSecurityContext SECURITY_CONTEXT = new
ThreadLocalSecurityContext();
public static final ThreadLocalContextResolver CONTEXT_RESOLVER = new
ThreadLocalContextResolver();
public static final ThreadLocalProviders PROVIDERS = new
ThreadLocalProviders();
- public static final ThreadLocal<Application> APPLICATION = new
ThreadLocal<Application>();
+ public static final ThreadLocal<Application> APPLICATION = new
ThreadLocal<>();
+ public static final ThreadLocal<Application> CONFIGURATION = new
ThreadLocal<Application>();
public static final ThreadLocal<Map<String, Object>> OTHERS = new
ThreadLocal<Map<String, Object>>();
public static void reset() {
Modified:
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/ServiceClasspathTest.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/ServiceClasspathTest.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/ServiceClasspathTest.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/ServiceClasspathTest.java
Sun Aug 24 11:56:59 2014
@@ -27,6 +27,7 @@ import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.ProvisioningUtil;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
import org.apache.openejb.util.Join;
import org.apache.openejb.util.PropertyPlaceHolderHelper;
import org.apache.xbean.asm5.ClassWriter;
@@ -111,7 +112,7 @@ public class ServiceClasspathTest extend
}
private void createEnvrt() {
- new File(SystemInstance.get().getBase().getDirectory(),
ProvisioningUtil.cache()).mkdirs();
+ new File(SystemInstance.get().getBase().getDirectory(),
ProvisioningResolver.cache()).mkdirs();
}
@Test
Modified:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
(original)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
Sun Aug 24 11:56:59 2014
@@ -340,7 +340,7 @@ public class Files {
// return the token as url if simply a path otheriwse if ending by *.jar
returning the list of
// files in the folder
public static Set<URL> listJars(final String path) {
- final Set<URL> set = new HashSet<URL>();
+ final Set<URL> set = new HashSet<>();
String token = path;
if (token.endsWith("*.jar")) {
Modified:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java
(original)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java
Sun Aug 24 11:56:59 2014
@@ -16,289 +16,30 @@
*/
package org.apache.openejb.loader;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
+
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.Proxy;
-import java.net.ProxySelector;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
-import java.util.logging.Logger;
+import java.util.Set;
+// Note: maybe you want to use
org.apache.openejb.loader.provisining.ProvisioningResolver now
+// instead of this class
public final class ProvisioningUtil {
- private static final SAXParserFactory FACTORY =
SAXParserFactory.newInstance();
-
- static {
- FACTORY.setNamespaceAware(false);
- FACTORY.setValidating(false);
- }
-
- public static final String OPENEJB_DEPLOYER_CACHE_FOLDER =
"openejb.deployer.cache.folder";
- public static final String HTTP_PREFIX = "http";
- public static final String MVN_PREFIX = "mvn:";
- public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
-
- private static final int CONNECT_TIMEOUT = 10000;
-
private static final String ADDITIONAL_LIB_CONFIG =
"provisioning.properties";
- private static final String REPO1 = "http://repo1.maven.org/maven2/";
- private static final String APACHE_SNAPSHOT =
"https://repository.apache.org/snapshots/";
private static final String ZIP_KEY = "zip";
private static final String DESTINATION_KEY = "destination";
private static final String JAR_KEY = "jar";
- public static final String TEMP_DIR = "temp";
-
private ProvisioningUtil() {
// no-op
}
- public static String cache() {
- return System.getProperty(OPENEJB_DEPLOYER_CACHE_FOLDER, TEMP_DIR);
- }
-
- public static File cacheFile(final String path) {
- return new File(SystemInstance.get().getBase().getDirectory(), cache()
+ File.separator + path);
- }
-
- public static String copyTryingProxies(final URI source, final File
destination) throws Exception {
- final InputStream is = inputStreamTryingProxies(source);
- if (is == null) {
- return null;
- }
-
- try {
- IO.copy(is, destination);
- } finally {
- IO.close(is);
- }
- return destination.getAbsolutePath();
- }
-
- public static InputStream inputStreamTryingProxies(final URI source)
throws Exception {
- final URL url = source.toURL();
- for (final Proxy proxy : ProxySelector.getDefault().select(source)) {
- // try to connect
- try {
- final URLConnection urlConnection = url.openConnection(proxy);
- urlConnection.setConnectTimeout(CONNECT_TIMEOUT);
- return new BufferedInputStream(urlConnection.getInputStream());
- } catch (final IOException e) {
- // ignored
- }
- }
- return null;
- }
-
- public static String lastPart(final String location) {
- final int idx = location.lastIndexOf('/');
- if (idx <= 0) {
- return location;
- }
- return location.substring(idx + 1, location.length());
- }
-
- public static String realLocation(final String rawLocation) {
- if (rawLocation.startsWith(HTTP_PREFIX)) {
- final File file = cacheFile(lastPart(rawLocation));
- if (file.exists()) {
- return file.getAbsolutePath();
- }
-
- String path = null;
- try {
- path = copyTryingProxies(new URI(rawLocation), file);
- } catch (final Exception e1) {
- // ignored
- }
-
- if (path != null) {
- return path;
- }
- }
- try { // full maven resolution
- final Class<?> clazz =
ProvisioningUtil.class.getClassLoader().loadClass("org.apache.openejb.resolver.Resolver");
- final LocationResolver instance = (LocationResolver)
clazz.newInstance();
- return instance.resolve(rawLocation);
- } catch (final Throwable e) { // NoClassDefFoundError is not an
exception
- return fallback(rawLocation);
- }
- }
-
- private static String fallback(final String rawLocation) {
- if (rawLocation.startsWith(MVN_PREFIX)) {
- try {
- final String repo1Url =
quickMvnUrl(rawLocation.substring(MVN_PREFIX.length()).replace(":", "/"));
- return realLocation(repo1Url);
- } catch (final MalformedURLException e1) {
-
Logger.getLogger(ProvisioningUtil.class.getName()).severe("Can't find " +
rawLocation);
- }
- } else { // try url
- try {
- final File file = cacheFile(lastPart(rawLocation));
- final File local = new File(rawLocation);
- if (local.exists()) {
- return local.getAbsolutePath();
- }
-
- final URL url = new URL(rawLocation);
- InputStream is = null;
- try {
- is = new BufferedInputStream(url.openStream());
- IO.copy(is, file);
- return file.getAbsolutePath();
- } catch (final IOException ioe) {
- throw new IllegalArgumentException(ioe);
- } finally {
- IO.close(is);
- }
- } catch (final IllegalArgumentException iae) {
- throw iae;
- } catch (final Exception e1) {
- throw new IllegalArgumentException(e1);
- }
- }
-
- // if it was not an url that's just a file path
- return rawLocation;
- }
-
- public static String quickMvnUrl(final String raw) throws
MalformedURLException {
- final String base;
- if (raw.contains(SNAPSHOT_SUFFIX) && raw.contains("apache")) {
- base = APACHE_SNAPSHOT;
- } else {
- base = REPO1;
- }
-
- StringBuilder builder = new StringBuilder();
- final String toParse;
- if (!raw.contains("!")) {
- // try first local file with default maven settings
- final File file = new File(m2Home() + mvnArtifactPath(raw, null));
- if (file.exists()) {
- return file.getAbsolutePath();
- }
-
- // else use repo1
- builder = new StringBuilder();
- builder.append(base);
- toParse = raw;
-
- // try first locally
- } else {
- final int repoIdx = raw.lastIndexOf("!");
- toParse = raw.substring(repoIdx + 1);
- final String repo = raw.substring(0, repoIdx);
- builder.append(repo);
- if (!repo.endsWith("/")) {
- builder.append("/");
- }
- }
-
- builder.append(mvnArtifactPath(toParse, base));
-
- return builder.toString();
- }
-
- private static String m2Home() {
- return SystemInstance.get().getProperty("openejb.m2.home",
System.getProperty("user.home") + "/.m2/repository/");
- }
-
- private static String mvnArtifactPath(final String toParse, final String
snapshotBase) throws MalformedURLException {
- final StringBuilder builder = new StringBuilder();
- final String[] segments = toParse.split("/");
- if (segments.length < 3) {
- throw new MalformedURLException("Invalid path. " + toParse);
- }
-
- final String group = segments[0];
- if (group.trim().isEmpty()) {
- throw new MalformedURLException("Invalid groupId. " + toParse);
- }
- builder.append(group.replace('.', '/')).append("/");
-
- final String artifact = segments[1];
- if (artifact.trim().isEmpty()) {
- throw new MalformedURLException("Invalid artifactId. " + toParse);
- }
- builder.append(artifact).append("/");
-
- final String version = segments[2];
- if (version.trim().isEmpty()) {
- throw new MalformedURLException("Invalid artifactId. " + toParse);
- }
-
- builder.append(version).append("/");
-
- String artifactVersion;
- if (snapshotBase != null && snapshotBase.startsWith(HTTP_PREFIX) &&
version.endsWith(SNAPSHOT_SUFFIX)) {
- final String meta = new
StringBuilder(snapshotBase).append(builder.toString()).append("maven-metadata.xml").toString();
- final URL url = new URL(meta);
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- InputStream is = null;
- try {
- is = inputStreamTryingProxies(url.toURI());
- IO.copy(is, out);
- artifactVersion = extractLastSnapshotVersion(version, new
ByteArrayInputStream(out.toByteArray()));
- } catch (final Exception e) {
- artifactVersion = version;
- } finally {
- IO.close(is);
- }
- } else {
- artifactVersion = version;
- }
-
- String type = "jar";
- if (segments.length >= 4 && segments[3].trim().length() > 0) {
- type = segments[3];
- }
-
- String fullClassifier = null;
- if (segments.length >= 5 && segments[4].trim().length() > 0) {
- fullClassifier = "-" + segments[4];
- }
-
- builder.append(artifact).append("-").append(artifactVersion);
-
- if (fullClassifier != null) {
- builder.append(fullClassifier);
- }
-
- return builder.append(".").append(type).toString();
- }
-
- private static String extractLastSnapshotVersion(final String
defaultVersion, final InputStream metadata) {
- final QuickMvnMetadataParser handler = new QuickMvnMetadataParser();
- try {
- final SAXParser parser = FACTORY.newSAXParser();
- parser.parse(metadata, handler);
- if (handler.timestamp != null && handler.buildNumber != null) {
- return defaultVersion.substring(0, defaultVersion.length() -
SNAPSHOT_SUFFIX.length()) + "-" + handler.timestamp.toString() + "-" +
handler.buildNumber.toString();
- }
- } catch (final Exception e) {
- // no-op: not parseable so ignoring
- }
- return defaultVersion;
- }
-
public static Collection<File> addAdditionalLibraries() throws IOException
{
final File conf = SystemInstance.get().getConf(ADDITIONAL_LIB_CONFIG);
if (conf == null || !conf.exists()) {
@@ -307,17 +48,26 @@ public final class ProvisioningUtil {
final Properties additionalLibProperties = IO.readProperties(conf);
- final List<String> libToCopy = new ArrayList<String>();
+ final ProvisioningResolver resolver =
SystemInstance.get().getComponent(ProvisioningResolver.class);
+ if (resolver == null) {
+ throw new IllegalStateException("SystemInstance not ready");
+ }
+
+ final List<String> libToCopy = new LinkedList<>();
final String toCopy = additionalLibProperties.getProperty(JAR_KEY);
if (toCopy != null) {
for (final String lib : toCopy.split(",")) {
- libToCopy.add(realLocation(lib.trim()));
+ libToCopy.addAll(resolver.realLocation(lib.trim()));
}
}
final String toExtract = additionalLibProperties.getProperty(ZIP_KEY);
if (toExtract != null) {
for (final String zip : toExtract.split(",")) {
- libToCopy.addAll(extract(realLocation(zip)));
+ final Set<String> strings = resolver.realLocation(zip);
+ if (strings.size() != 1) {
+ throw new IllegalArgumentException("Didnt find a single
zip: " + strings);
+ }
+ libToCopy.addAll(extract(strings.iterator().next()));
}
}
@@ -331,7 +81,7 @@ public final class ProvisioningUtil {
Files.mkdirs(destination);
}
- final Collection<File> newFiles = new
ArrayList<File>(libToCopy.size());
+ final Collection<File> newFiles = new ArrayList<>(libToCopy.size());
for (final String lib : libToCopy) {
newFiles.add(copy(new File(lib), destination));
}
@@ -348,7 +98,7 @@ public final class ProvisioningUtil {
}
private static Collection<String> extract(final String zip) throws
IOException {
- final File tmp = new
File(SystemInstance.get().getBase().getDirectory(), TEMP_DIR);
+ final File tmp = new
File(SystemInstance.get().getBase().getDirectory(),
ProvisioningResolver.TEMP_DIR);
if (!tmp.exists()) {
try {
Files.mkdirs(tmp);
@@ -357,7 +107,7 @@ public final class ProvisioningUtil {
}
}
- final File zipFile = new File(realLocation(zip));
+ final File zipFile = new File(zip);
final File extracted = new File(tmp, zipFile.getName().replace(".zip",
""));
if (extracted.exists()) {
return list(extracted);
@@ -374,7 +124,7 @@ public final class ProvisioningUtil {
return Collections.emptyList();
}
- final Collection<String> libs = new ArrayList<String>();
+ final Collection<String> libs = new ArrayList<>();
final File[] files = dir.listFiles();
if (files == null) {
return Collections.emptyList();
@@ -390,39 +140,7 @@ public final class ProvisioningUtil {
return libs;
}
- private static class QuickMvnMetadataParser extends DefaultHandler {
- private boolean readTs;
- private boolean readBn;
- private StringBuilder timestamp;
- private StringBuilder buildNumber;
-
- @Override
- public void startElement(final String uri, final String localName,
- final String qName, final Attributes
attributes) throws SAXException {
- if ("timestamp".equalsIgnoreCase(qName)) {
- readTs = true;
- timestamp = new StringBuilder();
- } else if ("buildNumber".equalsIgnoreCase(qName)) {
- readBn = true;
- buildNumber = new StringBuilder();
- }
- }
-
- @Override
- public void characters(final char[] ch, final int start, final int
length) throws SAXException {
- if (readBn && buildNumber != null) {
- buildNumber.append(new String(ch, start, length));
- } else if (readTs && timestamp != null) {
- timestamp.append(new String(ch, start, length));
- }
- }
-
- public void endElement(final String uri, final String localName, final
String qName) throws SAXException {
- if ("timestamp".equalsIgnoreCase(qName)) {
- readTs = false;
- } else if ("buildNumber".equalsIgnoreCase(qName)) {
- readBn = false;
- }
- }
+ public static Set<String> realLocation(final String location) {
+ return
SystemInstance.get().getComponent(ProvisioningResolver.class).realLocation(location);
}
}
Modified:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
(original)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
Sun Aug 24 11:56:59 2014
@@ -18,6 +18,7 @@ package org.apache.openejb.loader;
import org.apache.openejb.loader.event.ComponentAdded;
import org.apache.openejb.loader.event.ComponentRemoved;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
import org.apache.openejb.observer.ObserverManager;
import java.io.File;
@@ -287,6 +288,13 @@ public final class SystemInstance {
System.getProperties().putAll(system.getProperties()); // if the user
read System.getProperties() instead of our properties, used in bval-tomee tck
for instance
initialized = true;
get().setProperty("openejb.profile.custom",
Boolean.toString(!get().isDefaultProfile()));
+
+ initDefaultComponents();
+ }
+
+ private static void initDefaultComponents() {
+ final SystemInstance systemInstance = get();
+ systemInstance.components.put(ProvisioningResolver.class, new
ProvisioningResolver());
}
private static void readUserSystemProperties() {
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ArchiveResolver.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ArchiveResolver.java?rev=1620124&view=auto
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ArchiveResolver.java
(added)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ArchiveResolver.java
Sun Aug 24 11:56:59 2014
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.loader.provisining;
+
+import java.io.InputStream;
+
+/**
+ * Intended to be used with ProvisioningResolver component
+ */
+public interface ArchiveResolver {
+ /**
+ * @return the prefix this resolver handles
+ */
+ String prefix();
+
+ /**
+ * @param url the archive location
+ * @return null if can't resolve or the inputstream to use to copy the
archive (isLocal() == false otherwise not called)
+ */
+ InputStream resolve(String url);
+
+ /**
+ * @param rawLocation input url
+ * @return name of the cached jar
+ */
+ String name(String rawLocation);
+}
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/HttpResolver.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/HttpResolver.java?rev=1620124&view=auto
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/HttpResolver.java
(added)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/HttpResolver.java
Sun Aug 24 11:56:59 2014
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.loader.provisining;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class HttpResolver implements ArchiveResolver {
+ private static final int CONNECT_TIMEOUT = 10000;
+
+ @Override
+ public String prefix() {
+ return "http";
+ }
+
+ @Override
+ public InputStream resolve(final String location) {
+ try {
+ final URL url = new URL(location);
+ for (final Proxy proxy :
ProxySelector.getDefault().select(url.toURI())) {
+ try {
+ final URLConnection urlConnection =
url.openConnection(proxy);
+ urlConnection.setConnectTimeout(CONNECT_TIMEOUT);
+ return urlConnection.getInputStream();
+ } catch (final IOException e) {
+ // ignored
+ }
+ }
+ } catch (final MalformedURLException | URISyntaxException e) {
+ // no-op
+ }
+ return null;
+ }
+
+ @Override
+ public String name(final String rawLocation) {
+ return lastPart(rawLocation.replace(':', '/'));
+ }
+
+ public static String lastPart(final String location) {
+ int idx = location.lastIndexOf('/');
+ if (idx <= 0) {
+ idx = location.lastIndexOf(':');
+ if (idx <= 0) {
+ return location;
+ }
+ }
+ return location.substring(idx + 1, location.length());
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[timeout=" + CONNECT_TIMEOUT +
"ms]";
+ }
+}
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java?rev=1620124&view=auto
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
(added)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
Sun Aug 24 11:56:59 2014
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.loader.provisining;
+
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.SystemInstance;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class MavenResolver implements ArchiveResolver {
+ private static final String REPO1 = "http://repo1.maven.org/maven2/";
+ private static final String APACHE_SNAPSHOT =
"https://repository.apache.org/snapshots/";
+ private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
+
+ private static final SAXParserFactory FACTORY =
SAXParserFactory.newInstance();
+ static {
+ FACTORY.setNamespaceAware(false);
+ FACTORY.setValidating(false);
+ }
+
+ @Override
+ public String prefix() {
+ return "mvn";
+ }
+
+ @Override
+ public InputStream resolve(final String url) {
+ try {
+ final String sanitized = sanitize(url);
+ final String repo1Url = quickMvnUrl(sanitized);
+ return resolveStream(repo1Url);
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ private String sanitize(final String url) {
+ return url.substring(prefix().length() + 1).replace(":", "/");
+ }
+
+ @Override
+ public String name(final String rawLocation) {
+ try {
+ final String s = mvnArtifactPath(sanitize(rawLocation), "");
+ return s.substring(s.lastIndexOf('/') + 1);
+ } catch (final MalformedURLException e) {
+ return rawLocation + ".jar";
+ }
+ }
+
+ private InputStream resolveStream(final String repo1Url) throws
MalformedURLException {
+ return
SystemInstance.get().getComponent(ProvisioningResolver.class).resolveStream(repo1Url);
+ }
+
+ public String quickMvnUrl(final String raw) throws MalformedURLException {
+ final String base;
+ if (raw.contains(SNAPSHOT_SUFFIX) && raw.contains("apache")) {
+ base = APACHE_SNAPSHOT;
+ } else {
+ base = REPO1;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ final String toParse;
+ if (!raw.contains("!")) {
+ // try first local file with default maven settings
+ final File file = new File(m2Home() + mvnArtifactPath(raw, null));
+ if (file.exists()) {
+ return file.getAbsolutePath();
+ }
+
+ // else use repo1
+ builder = new StringBuilder();
+ builder.append(base);
+ toParse = raw;
+
+ // try first locally
+ } else {
+ final int repoIdx = raw.lastIndexOf("!");
+ toParse = raw.substring(repoIdx + 1);
+ final String repo = raw.substring(0, repoIdx);
+ builder.append(repo);
+ if (!repo.endsWith("/")) {
+ builder.append("/");
+ }
+ }
+
+ builder.append(mvnArtifactPath(toParse, base));
+
+ return builder.toString();
+ }
+
+ private static String m2Home() {
+ return SystemInstance.get().getProperty("openejb.m2.home",
System.getProperty("user.home") + "/.m2/repository/");
+ }
+
+ private String mvnArtifactPath(final String toParse, final String
snapshotBase) throws MalformedURLException {
+ final StringBuilder builder = new StringBuilder();
+ final String[] segments = toParse.split("/");
+ if (segments.length < 3) {
+ throw new MalformedURLException("Invalid path. " + toParse);
+ }
+
+ final String group = segments[0];
+ if (group.trim().isEmpty()) {
+ throw new MalformedURLException("Invalid groupId. " + toParse);
+ }
+ builder.append(group.replace('.', '/')).append("/");
+
+ final String artifact = segments[1];
+ if (artifact.trim().isEmpty()) {
+ throw new MalformedURLException("Invalid artifactId. " + toParse);
+ }
+ builder.append(artifact).append("/");
+
+ final String version = segments[2];
+ if (version.trim().isEmpty()) {
+ throw new MalformedURLException("Invalid artifactId. " + toParse);
+ }
+
+ builder.append(version).append("/");
+
+ String artifactVersion;
+ if (snapshotBase != null && snapshotBase.startsWith("http") &&
version.endsWith(SNAPSHOT_SUFFIX)) {
+ final String meta = snapshotBase + builder.toString() +
"maven-metadata.xml";
+ final URL url = new URL(meta);
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ InputStream is = null;
+ try {
+ is = resolveStream(url.toExternalForm());
+ if (is == null) {
+ throw new IllegalArgumentException("can't resolve " + url);
+ }
+ IO.copy(is, out);
+ artifactVersion = extractLastSnapshotVersion(version, new
ByteArrayInputStream(out.toByteArray()));
+ } catch (final Exception e) {
+ artifactVersion = version;
+ } finally {
+ IO.close(is);
+ }
+ } else {
+ artifactVersion = version;
+ }
+
+ String type = "jar";
+ if (segments.length >= 4 && segments[3].trim().length() > 0) {
+ type = segments[3];
+ }
+
+ String fullClassifier = null;
+ if (segments.length >= 5 && segments[4].trim().length() > 0) {
+ fullClassifier = "-" + segments[4];
+ }
+
+ builder.append(artifact).append("-").append(artifactVersion);
+
+ if (fullClassifier != null) {
+ builder.append(fullClassifier);
+ }
+
+ return builder.append(".").append(type).toString();
+ }
+
+ private static String extractLastSnapshotVersion(final String
defaultVersion, final InputStream metadata) {
+ final QuickMvnMetadataParser handler = new QuickMvnMetadataParser();
+ try {
+ final SAXParser parser = FACTORY.newSAXParser();
+ parser.parse(metadata, handler);
+ if (handler.timestamp != null && handler.buildNumber != null) {
+ return defaultVersion.substring(0, defaultVersion.length() -
SNAPSHOT_SUFFIX.length()) + "-" + handler.timestamp.toString() + "-" +
handler.buildNumber.toString();
+ }
+ } catch (final Exception e) {
+ // no-op: not parseable so ignoring
+ }
+ return defaultVersion;
+ }
+
+ private static class QuickMvnMetadataParser extends DefaultHandler {
+ private boolean readTs;
+ private boolean readBn;
+ private StringBuilder timestamp;
+ private StringBuilder buildNumber;
+
+ @Override
+ public void startElement(final String uri, final String localName,
+ final String qName, final Attributes
attributes) throws SAXException {
+ if ("timestamp".equalsIgnoreCase(qName)) {
+ readTs = true;
+ timestamp = new StringBuilder();
+ } else if ("buildNumber".equalsIgnoreCase(qName)) {
+ readBn = true;
+ buildNumber = new StringBuilder();
+ }
+ }
+
+ @Override
+ public void characters(final char[] ch, final int start, final int
length) throws SAXException {
+ if (readBn && buildNumber != null) {
+ buildNumber.append(new String(ch, start, length));
+ } else if (readTs && timestamp != null) {
+ timestamp.append(new String(ch, start, length));
+ }
+ }
+
+ public void endElement(final String uri, final String localName, final
String qName) throws SAXException {
+ if ("timestamp".equalsIgnoreCase(qName)) {
+ readTs = false;
+ } else if ("buildNumber".equalsIgnoreCase(qName)) {
+ readBn = false;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[]";
+ }
+}
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisiningResolverCreated.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisiningResolverCreated.java?rev=1620124&view=auto
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisiningResolverCreated.java
(added)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisiningResolverCreated.java
Sun Aug 24 11:56:59 2014
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.loader.provisining;
+
+import org.apache.openejb.observer.Event;
+
+@Event
+public class ProvisiningResolverCreated {
+ private final ProvisioningResolver resolver;
+
+ public ProvisiningResolverCreated(final ProvisioningResolver
provisioningResolver) {
+ resolver = provisioningResolver;
+ }
+
+ public ProvisiningResolverCreated register(final ArchiveResolver resolver)
{
+ this.resolver.addResolver(resolver);
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "ProvisiningResolverCreated{" +
+ "resolver=" + resolver +
+ '}';
+ }
+}
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisioningResolver.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisioningResolver.java?rev=1620124&view=auto
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisioningResolver.java
(added)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/ProvisioningResolver.java
Sun Aug 24 11:56:59 2014
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.loader.provisining;
+
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.SystemInstance;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+import static java.util.Collections.singleton;
+
+public class ProvisioningResolver {
+ public static final String TEMP_DIR = "temp";
+ public static final String OPENEJB_DEPLOYER_CACHE_FOLDER =
"openejb.deployer.cache.folder";
+
+ private final Map<String, ArchiveResolver> resolvers = new
ConcurrentHashMap<>();
+ private final ArchiveResolver fallbackResolver = new SimpleUrlResolver();
+
+ public ProvisioningResolver() {
+ resolvers.put("mvn", new MavenResolver());
+ resolvers.put("http", new HttpResolver());
+ resolvers.put("https", new HttpResolver());
+
+ final String userOnes =
SystemInstance.get().getProperty("openejb.provisinig.archive-resolvers");
+ if (userOnes != null) {
+ for (final String u : userOnes.split(" *, *")) {
+ final String c = u.trim();
+ if (!c.isEmpty()) {
+ continue;
+ }
+ try {
+ final ArchiveResolver instance =
ArchiveResolver.class.cast(ProvisioningResolver.class.getClassLoader().loadClass(c));
+ addResolver(instance);
+ } catch (final ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ }
+
+ SystemInstance.get().fireEvent(new ProvisiningResolverCreated(this));
+ }
+
+ public void addResolver(final ArchiveResolver resolver) {
+ if (resolvers.put(resolver.prefix(), resolver) != null) {
+
Logger.getLogger(ProvisioningResolver.class.getName()).warning("Overriding
resolver " + resolver.prefix() + " with " + resolver);
+ }
+ }
+
+ public void removeResolver(final ArchiveResolver resolver) {
+ resolvers.remove(resolver.prefix());
+ }
+
+ public Set<String> realLocation(final String rawLocation) {
+ // if direct file path then use it
+ final File file = new File(rawLocation);
+ if (file.exists()) {
+ return singleton(file.getAbsolutePath());
+ }
+ if (rawLocation.endsWith("*.jar")) {
+ final File dir = new File(rawLocation.substring(0,
rawLocation.length() - "*.jar".length()));
+ if (dir.exists()) {
+ final File[] files = dir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return name.endsWith(".jar") || name.endsWith(".zip");
+ }
+ });
+ final Set<String> paths = new HashSet<>(files == null ? 1 :
files.length + 1);
+ if (files != null) {
+ for (final File f : files) {
+ paths.add(f.getAbsolutePath());
+ }
+ }
+ paths.add(dir.getAbsolutePath()); // for config it is nice
+ return paths;
+ } else {
+ throw new IllegalArgumentException(dir.getAbsolutePath() + "
doesn't exist, *.jar is only supported locally");
+ }
+ }
+
+ final String protocol = protocol(rawLocation);
+ ArchiveResolver resolver = resolvers.get(protocol);
+ if (resolver == null) {
+ resolver = fallbackResolver;
+ }
+
+ final File destination = cacheFile(resolver.name(rawLocation));
+ if (destination.exists()) {
+ return singleton(destination.getAbsolutePath());
+ }
+
+ return singleton(doResolve(rawLocation, destination, resolver));
+ }
+
+ // don't use new URL() since that's really just a prefix
+ private String protocol(final String rawLocation) {
+ final int sep = rawLocation.indexOf(':');
+ if (sep < 1) {
+ throw new IllegalArgumentException("Not a local file but no prefix
specified: " + rawLocation + ". So can't resolve");
+ }
+ return rawLocation.substring(0, sep);
+ }
+
+ private String doResolve(final String rawLocation, final File file, final
ArchiveResolver resolver) {
+ final InputStream resolverStream = resolver.resolve(rawLocation);
+ if (LocalInputStream.class.isInstance(resolverStream)) {
+ return LocalInputStream.class.cast(resolverStream).path;
+ }
+
+ if (resolverStream != null) {
+ BufferedInputStream is = null;
+ try {
+ is = new BufferedInputStream(resolverStream);
+ IO.copy(is, file);
+ return file.getAbsolutePath();
+ } catch (final IOException ioe) {
+ throw new IllegalArgumentException(ioe);
+ } finally {
+ IO.close(is);
+ }
+ } else {
+ throw new IllegalArgumentException("Can't resolver (" +
rawLocation + ')');
+ }
+ }
+
+ public InputStream resolveStream(final String rawLocation) throws
MalformedURLException {
+ final File file = new File(rawLocation);
+ if (file.exists()) {
+ return new LocalInputStream(file.getAbsolutePath());
+ }
+
+ final String protocol = protocol(rawLocation);
+ final ArchiveResolver resolver = resolvers.get(protocol);
+ if (resolver != null) {
+ return resolver.resolve(rawLocation);
+ }
+ return null;
+ }
+
+ public static String cache() {
+ return System.getProperty(OPENEJB_DEPLOYER_CACHE_FOLDER, TEMP_DIR);
+ }
+
+ public static File cacheFile(final String path) {
+ return new File(SystemInstance.get().getBase().getDirectory(), cache()
+ File.separator + path);
+ }
+
+ @Override
+ public String toString() {
+ return "ProvisioningResolver{" +
+ "resolvers=" + resolvers +
+ ", fallbackResolver=" + fallbackResolver +
+ '}';
+ }
+
+ // used when a resolver wants to use a local file by calling back this
facade resolver
+ public static class LocalInputStream extends InputStream {
+ private final String path;
+
+ private LocalInputStream(final String path) {
+ this.path = path;
+ }
+
+ @Override
+ public int read() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Added:
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/SimpleUrlResolver.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/SimpleUrlResolver.java?rev=1620124&view=auto
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/SimpleUrlResolver.java
(added)
+++
tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/SimpleUrlResolver.java
Sun Aug 24 11:56:59 2014
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.loader.provisining;
+
+import java.io.InputStream;
+import java.net.URL;
+
+public class SimpleUrlResolver implements ArchiveResolver {
+ @Override
+ public String prefix() {
+ return "simple-url";
+ }
+
+ @Override
+ public InputStream resolve(final String url) {
+ try {
+ final URL u = new URL(url);
+ return u.openStream();
+ } catch (final Exception e) {
+ return null;
+ }
+ }
+
+ @Override
+ public String name(final String rawLocation) {
+ return rawLocation.replace(":", "_").replace('/', '_') + ".jar";
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[]";
+ }
+}
Modified:
tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/loader/ProvisioningUtilTest.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/loader/ProvisioningUtilTest.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/loader/ProvisioningUtilTest.java
(original)
+++
tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/loader/ProvisioningUtilTest.java
Sun Aug 24 11:56:59 2014
@@ -16,16 +16,40 @@
*/
package org.apache.openejb.loader;
+import org.apache.openejb.loader.provisining.MavenResolver;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.net.MalformedURLException;
+import java.util.Properties;
+import java.util.Set;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+// needs http to work
public class ProvisioningUtilTest {
+ @Before
+ public void init() throws Exception {
+ SystemInstance.init(new Properties() {{
+ setProperty(ProvisioningResolver.OPENEJB_DEPLOYER_CACHE_FOLDER,
"target");
+ }});
+ new File("target/temp").mkdirs();
+ }
+
+ @After
+ public void reset() {
+ SystemInstance.reset();
+ }
+
@Test
public void mvnUrl() throws MalformedURLException {
- final String url =
ProvisioningUtil.quickMvnUrl("org.apache.openejb/apache-tomee/x.y.z-SNAPSHOT");
+ final String url = new
MavenResolver().quickMvnUrl("org.apache.openejb/apache-tomee/x.y.z-SNAPSHOT");
assertEquals("https://repository.apache.org/snapshots/org/apache/openejb/apache-tomee/x.y.z-SNAPSHOT/apache-tomee-x.y.z-SNAPSHOT.jar",
url);
}
@@ -33,8 +57,45 @@ public class ProvisioningUtilTest {
public void missingShouldFail() throws Exception {
ProvisioningUtil.realLocation("mvn:missing:artifact:c56dfhrvfjc");
}
+
@Test(expected = IllegalArgumentException.class)
public void missingShouldFailEvenWhenResolvedLocally() throws Exception {
ProvisioningUtil.realLocation("file:///target/cigcrdyicexbeoeoc is not
here.jar");
}
+
+ @Test
+ public void wildcard() throws IOException {
+ final File folder = new File("target/jars");
+ folder.mkdirs();
+ write(folder, "jar1.jar");
+ write(folder, "jar2.jar");
+ final Set<String> urls =
ProvisioningUtil.realLocation(folder.getAbsolutePath() + "/*.jar");
+ assertEquals(3, urls.size());
+ }
+
+ @Test
+ public void localMaven() {
+ final Set<String> urls =
ProvisioningUtil.realLocation("mvn:junit:junit:4.11");
+ assertEquals(1, urls.size());
+ }
+
+ @Test
+ public void remoteMaven() { // not sure it is remote but at least not in
tomee build
+ final Set<String> urls =
ProvisioningUtil.realLocation("mvn:com.google.guava:guava-io:r03");
+ assertEquals(1, urls.size());
+ assertTrue(urls.iterator().next().replace("\\",
"/").endsWith("target/guava-io-r03.jar"));
+ }
+
+ @Test
+ public void http() {
+ final Set<String> urls =
ProvisioningUtil.realLocation("http://repo1.maven.org/maven2/org/apache/batchee/batchee-test/0.2-incubating/batchee-test-0.2-incubating.jar");
+ assertEquals(1, urls.size());
+ assertTrue(urls.iterator().next().replace("\\",
"/").endsWith("target/batchee-test-0.2-incubating.jar"));
+ }
+
+ private void write(final File folder, final String name) throws
IOException {
+ final FileWriter w = new FileWriter(new File(folder, name));
+ w.write("empty");
+ w.close();
+ }
}
Modified:
tomee/tomee/trunk/maven/jarstxt-maven-plugin/src/main/java/org/apache/openejb/maven/jarstxt/JarsTxtMojo.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/jarstxt-maven-plugin/src/main/java/org/apache/openejb/maven/jarstxt/JarsTxtMojo.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/maven/jarstxt-maven-plugin/src/main/java/org/apache/openejb/maven/jarstxt/JarsTxtMojo.java
(original)
+++
tomee/tomee/trunk/maven/jarstxt-maven-plugin/src/main/java/org/apache/openejb/maven/jarstxt/JarsTxtMojo.java
Sun Aug 24 11:56:59 2014
@@ -42,8 +42,10 @@ import org.codehaus.plexus.util.FileUtil
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -93,7 +95,7 @@ public class JarsTxtMojo extends Abstrac
try {
writer = new FileWriter(outputFile);
- final TreeSet<String> set = new TreeSet<String>();
+ final TreeSet<String> set = new TreeSet<>();
for (final Artifact a : (Set<Artifact>) project.getArtifacts()) {
if (!acceptScope(a.getScope()) || !acceptType(a.getType())) {
@@ -138,7 +140,7 @@ public class JarsTxtMojo extends Abstrac
if (additionals != null) {
if (placeHolders == null) {
- placeHolders = new HashMap<String, String>();
+ placeHolders = new HashMap<>();
}
final StrSubstitutor lookup = new
StrSubstitutor(StrLookup.mapLookup(placeHolders));
@@ -174,7 +176,15 @@ public class JarsTxtMojo extends Abstrac
}
private Set<URL> urls(final String line, final StrSubstitutor lookup) {
- return
Files.listJars(ProvisioningUtil.realLocation(lookup.replace(line)));
+ final Set<URL> urls = new HashSet<>();
+ for (final String location :
ProvisioningUtil.realLocation(lookup.replace(line))) { // should have 1 item
+ try {
+ urls.add(new File(location).toURI().toURL());
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ return urls;
}
private String version(final Artifact a) {
Modified:
tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java?rev=1620124&r1=1620123&r2=1620124&view=diff
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
(original)
+++
tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
Sun Aug 24 11:56:59 2014
@@ -17,6 +17,8 @@
package org.apache.tomee.embedded;
import java.io.File;
+import java.util.Set;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
@@ -60,17 +62,20 @@ public class Main {
}
int i = 0;
for (final String path : line.getOptionValues(PATH)) {
- final File file = new
File(ProvisioningUtil.realLocation(path));
- if (!file.exists()) {
- System.err.println(file.getAbsolutePath() + " does not
exist, skipping");
- continue;
- }
-
- String name = file.getName().replaceAll("\\.[A-Za-z]+$",
"");
- if (contexts != null) {
- name = contexts[i++];
+ final Set<String> locations =
ProvisioningUtil.realLocation(path);
+ for (final String location : locations) {
+ final File file = new File(location);
+ if (!file.exists()) {
+ System.err.println(file.getAbsolutePath() + " does
not exist, skipping");
+ continue;
+ }
+
+ String name =
file.getName().replaceAll("\\.[A-Za-z]+$", "");
+ if (contexts != null) {
+ name = contexts[i++];
+ }
+ container.deploy(name, file, true);
}
- container.deploy(name, file, true);
}
}