mirror of https://github.com/apache/druid.git
make defaultVersion configurable for non-jar testing
This commit is contained in:
parent
0ca23d7d0b
commit
d914afe1cd
|
@ -187,7 +187,7 @@ public class HadoopIndexTask extends AbstractTask
|
|||
final List<URL> extensionURLs = Lists.newArrayList();
|
||||
for (String coordinate : extensionsConfig.getCoordinates()) {
|
||||
final ClassLoader coordinateLoader = Initialization.getClassLoaderForCoordinates(
|
||||
aetherClient, coordinate
|
||||
aetherClient, coordinate, extensionsConfig.getDefaultVersion()
|
||||
);
|
||||
extensionURLs.addAll(Arrays.asList(((URLClassLoader) coordinateLoader).getURLs()));
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ public class HadoopIndexTask extends AbstractTask
|
|||
// put hadoop dependencies last to avoid jets3t & apache.httpcore version conflicts
|
||||
for (String hadoopDependencyCoordinate : finalHadoopDependencyCoordinates) {
|
||||
final ClassLoader hadoopLoader = Initialization.getClassLoaderForCoordinates(
|
||||
aetherClient, hadoopDependencyCoordinate
|
||||
aetherClient, hadoopDependencyCoordinate, extensionsConfig.getDefaultVersion()
|
||||
);
|
||||
driverURLs.addAll(Arrays.asList(((URLClassLoader) hadoopLoader).getURLs()));
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.List;
|
|||
*/
|
||||
public class ExtensionsConfig
|
||||
{
|
||||
public static final String PACKAGE_VERSION = ExtensionsConfig.class.getPackage().getImplementationVersion();
|
||||
|
||||
@JsonProperty
|
||||
@NotNull
|
||||
private boolean searchCurrentClassloader = true;
|
||||
|
@ -37,6 +39,10 @@ public class ExtensionsConfig
|
|||
@NotNull
|
||||
private List<String> coordinates = ImmutableList.of();
|
||||
|
||||
// default version to use for extensions without version info
|
||||
@JsonProperty
|
||||
private String defaultVersion;
|
||||
|
||||
@JsonProperty
|
||||
@NotNull
|
||||
private String localRepository = String.format("%s/%s", System.getProperty("user.home"), ".m2/repository");
|
||||
|
@ -58,6 +64,11 @@ public class ExtensionsConfig
|
|||
return coordinates;
|
||||
}
|
||||
|
||||
public String getDefaultVersion()
|
||||
{
|
||||
return defaultVersion != null ? defaultVersion : PACKAGE_VERSION;
|
||||
}
|
||||
|
||||
public String getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
|
@ -74,6 +85,7 @@ public class ExtensionsConfig
|
|||
return "ExtensionsConfig{" +
|
||||
"searchCurrentClassloader=" + searchCurrentClassloader +
|
||||
", coordinates=" + coordinates +
|
||||
", defaultVersion='" + getDefaultVersion() + '\'' +
|
||||
", localRepository='" + localRepository + '\'' +
|
||||
", remoteRepositories=" + remoteRepositories +
|
||||
'}';
|
||||
|
|
|
@ -93,9 +93,6 @@ import java.util.Set;
|
|||
*/
|
||||
public class Initialization
|
||||
{
|
||||
// default version to use for extensions without version info
|
||||
private static final String DEFAULT_VERSION = Initialization.class.getPackage().getImplementationVersion();
|
||||
|
||||
private static final Logger log = new Logger(Initialization.class);
|
||||
private static final Map<String, URLClassLoader> loadersMap = Maps.newHashMap();
|
||||
|
||||
|
@ -143,7 +140,7 @@ public class Initialization
|
|||
for (String coordinate : config.getCoordinates()) {
|
||||
log.info("Loading extension[%s] for class[%s]", coordinate, clazz.getName());
|
||||
try {
|
||||
URLClassLoader loader = getClassLoaderForCoordinates(aether, coordinate);
|
||||
URLClassLoader loader = getClassLoaderForCoordinates(aether, coordinate, config.getDefaultVersion());
|
||||
|
||||
final ServiceLoader<T> serviceLoader = ServiceLoader.load(clazz, loader);
|
||||
|
||||
|
@ -163,7 +160,7 @@ public class Initialization
|
|||
return retVal;
|
||||
}
|
||||
|
||||
public static URLClassLoader getClassLoaderForCoordinates(TeslaAether aether, String coordinate)
|
||||
public static URLClassLoader getClassLoaderForCoordinates(TeslaAether aether, String coordinate, String defaultVersion)
|
||||
throws DependencyResolutionException, MalformedURLException
|
||||
{
|
||||
URLClassLoader loader = loadersMap.get(coordinate);
|
||||
|
@ -177,8 +174,8 @@ public class Initialization
|
|||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// try appending the default version so we can specify artifacts without versions
|
||||
if (DEFAULT_VERSION != null) {
|
||||
versionedArtifact = new DefaultArtifact(coordinate + ":" + DEFAULT_VERSION);
|
||||
if (defaultVersion != null) {
|
||||
versionedArtifact = new DefaultArtifact(coordinate + ":" + defaultVersion);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class CliHadoopIndexer implements Runnable
|
|||
final List<URL> extensionURLs = Lists.newArrayList();
|
||||
for (String coordinate : extensionsConfig.getCoordinates()) {
|
||||
final ClassLoader coordinateLoader = Initialization.getClassLoaderForCoordinates(
|
||||
aetherClient, coordinate
|
||||
aetherClient, coordinate, extensionsConfig.getDefaultVersion()
|
||||
);
|
||||
extensionURLs.addAll(Arrays.asList(((URLClassLoader) coordinateLoader).getURLs()));
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class CliHadoopIndexer implements Runnable
|
|||
// put hadoop dependencies last to avoid jets3t & apache.httpcore version conflicts
|
||||
for (String coordinate : allCoordinates) {
|
||||
final ClassLoader hadoopLoader = Initialization.getClassLoaderForCoordinates(
|
||||
aetherClient, coordinate
|
||||
aetherClient, coordinate, extensionsConfig.getDefaultVersion()
|
||||
);
|
||||
driverURLs.addAll(Arrays.asList(((URLClassLoader) hadoopLoader).getURLs()));
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class PullDependencies implements Runnable
|
|||
try {
|
||||
final DefaultTeslaAether aetherClient = Initialization.getAetherClient(extensionsConfig);
|
||||
for (final String coordinate : allCoordinates) {
|
||||
Initialization.getClassLoaderForCoordinates(aetherClient, coordinate);
|
||||
Initialization.getClassLoaderForCoordinates(aetherClient, coordinate, extensionsConfig.getDefaultVersion());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue