diff --git a/core/pom.xml b/core/pom.xml
index 2236c04e04..759a3dd22c 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -365,14 +365,9 @@ THE SOFTWARE.
- com.google.inject
+ org.jvnet.hudson
guice
- 2.0
-
-
- com.google.inject.extensions
- guice-multibindings
- 2.0
+ 3.0-rc1
diff --git a/core/src/main/java/hudson/ExtensionFinder.java b/core/src/main/java/hudson/ExtensionFinder.java
index 317803677e..2b24548616 100644
--- a/core/src/main/java/hudson/ExtensionFinder.java
+++ b/core/src/main/java/hudson/ExtensionFinder.java
@@ -42,6 +42,8 @@ import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.lang.annotation.Annotation;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
import java.util.logging.Level;
@@ -147,6 +149,11 @@ public abstract class ExtensionFinder implements ExtensionPoint {
protected boolean isOptional(Extension annotation) {
return annotation.optional();
}
+
+ @Override
+ protected double getOrdinal(Extension annotation) {
+ return annotation.ordinal();
+ }
}
/**
@@ -155,6 +162,8 @@ public abstract class ExtensionFinder implements ExtensionPoint {
public static abstract class AbstractGuiceFinder extends ExtensionFinder {
private Injector container;
+ private final Map annotations = new HashMap();
+
public AbstractGuiceFinder(final Class annotationType) {
List modules = new ArrayList();
modules.add(new AbstractModule() {
@@ -169,9 +178,12 @@ public abstract class ExtensionFinder implements ExtensionPoint {
try {
AnnotatedElement e = item.element();
if (!isActive(e)) continue;
+ T a = item.annotation();
if (e instanceof Class) {
- bind((Class>)e).in(FAULT_TOLERANT_SCOPE);
+ Key key = Key.get((Class)e);
+ annotations.put(key,a);
+ bind(key).in(FAULT_TOLERANT_SCOPE);
} else {
Class extType;
if (e instanceof Field) {
@@ -183,8 +195,9 @@ public abstract class ExtensionFinder implements ExtensionPoint {
throw new AssertionError();
// use arbitrary
- bind(extType).annotatedWith(Names.named(String.valueOf(id)))
- .toProvider(new Provider() {
+ Key key = Key.get(extType, Names.named(String.valueOf(id)));
+ annotations.put(key,a);
+ bind(key).toProvider(new Provider() {
public Object get() {
return instantiate(item);
}
@@ -210,6 +223,8 @@ public abstract class ExtensionFinder implements ExtensionPoint {
container = Guice.createInjector(modules);
}
+ protected abstract double getOrdinal(T annotation);
+
/**
* Hook to enable subtypes to control which ones to pick up and which ones to ignore.
*/
@@ -234,15 +249,15 @@ public abstract class ExtensionFinder implements ExtensionPoint {
return null;
}
- public Collection> find(Class type, Hudson hudson) {
- List> result = new ArrayList>();
+ public Collection> find(Class type, Hudson hudson) {
+ List> result = new ArrayList>();
for (Entry, Binding>> e : container.getBindings().entrySet()) {
if (type.isAssignableFrom(e.getKey().getTypeLiteral().getRawType())) {
- // TODO: how do we get ordinal?
+ T a = annotations.get(e.getKey());
Object o = e.getValue().getProvider().get();
if (o!=null)
- result.add(new ExtensionComponent(type.cast(o)));
+ result.add(new ExtensionComponent(type.cast(o),a!=null?getOrdinal(a):0));
}
}
diff --git a/core/src/test/java/foo/Driver.java b/core/src/test/java/foo/Driver.java
index af245ef019..e4dff3b66d 100644
--- a/core/src/test/java/foo/Driver.java
+++ b/core/src/test/java/foo/Driver.java
@@ -8,7 +8,7 @@ import com.google.inject.Key;
import com.google.inject.Scope;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
-import com.google.inject.multibindings.Multibinder;
+//import com.google.inject.multibindings.Multibinder;
import java.util.Set;
@@ -28,25 +28,25 @@ public class Driver {
*/
public static void main(String[] args) {
- Injector i = Guice.createInjector(new AbstractModule() {
- @Override
- protected void configure() {
- bind(Cat.class).in(Singleton.class);
-
- Multibinder ab = Multibinder.newSetBinder(binder(), Animal.class);
- ab.addBinding().to(Dog.class);
- ab.addBinding().to(Cat.class);
-
- Multibinder cb = Multibinder.newSetBinder(binder(), Cute.class);
- cb.addBinding().to(Cat.class);
- cb.addBinding().to(Banana.class);
- }
- });
- i.getInstance(Driver.class).run();
-
- // Dog isn't singleton scoped, so you get a different instance, but Cat is singleton,
- // so you get the same value
- System.out.println(i.getInstance(Key.get(new TypeLiteral>(){})));
+// Injector i = Guice.createInjector(new AbstractModule() {
+// @Override
+// protected void configure() {
+// bind(Cat.class).in(Singleton.class);
+//
+// Multibinder ab = Multibinder.newSetBinder(binder(), Animal.class);
+// ab.addBinding().to(Dog.class);
+// ab.addBinding().to(Cat.class);
+//
+// Multibinder cb = Multibinder.newSetBinder(binder(), Cute.class);
+// cb.addBinding().to(Cat.class);
+// cb.addBinding().to(Banana.class);
+// }
+// });
+// i.getInstance(Driver.class).run();
+//
+// // Dog isn't singleton scoped, so you get a different instance, but Cat is singleton,
+// // so you get the same value
+// System.out.println(i.getInstance(Key.get(new TypeLiteral>(){})));
}
public void run() {
diff --git a/test/src/main/java/org/jvnet/hudson/test/TestExtensionLoader.java b/test/src/main/java/org/jvnet/hudson/test/TestExtensionLoader.java
index 0f571fe03b..b4687215b3 100644
--- a/test/src/main/java/org/jvnet/hudson/test/TestExtensionLoader.java
+++ b/test/src/main/java/org/jvnet/hudson/test/TestExtensionLoader.java
@@ -1,7 +1,7 @@
/*
* The MIT License
*
- * Copyright (c) 2004-2010, Sun Microsystems, Inc.
+ * Copyright (c) 2004-2010, Sun Microsystems, Inc., CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,21 +24,11 @@
package org.jvnet.hudson.test;
import hudson.Extension;
-import hudson.ExtensionComponent;
-import hudson.ExtensionFinder;
import hudson.ExtensionFinder.AbstractGuiceFinder;
-import hudson.model.Hudson;
-import net.java.sezpoz.Index;
-import net.java.sezpoz.IndexItem;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* Loads {@link TestExtension}s.
@@ -56,6 +46,11 @@ public class TestExtensionLoader extends AbstractGuiceFinder {
return false;
}
+ @Override
+ protected double getOrdinal(TestExtension annotation) {
+ return 0;
+ }
+
@Override
protected boolean isActive(AnnotatedElement e) {
TestEnvironment env = TestEnvironment.get();
diff --git a/test/src/test/java/hudson/ExtensionFinderTest.java b/test/src/test/java/hudson/ExtensionFinderTest.java
index 3e4b3fa6f9..c16cf5055a 100644
--- a/test/src/test/java/hudson/ExtensionFinderTest.java
+++ b/test/src/test/java/hudson/ExtensionFinderTest.java
@@ -24,15 +24,13 @@
package hudson;
import com.google.inject.AbstractModule;
-import com.google.inject.Binder;
-import com.google.inject.BindingAnnotation;
-import com.google.inject.Inject;
-import com.google.inject.Module;
import hudson.model.PageDecorator;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestEnvironment;
import org.jvnet.hudson.test.TestExtension;
+import javax.inject.Inject;
+import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -88,7 +86,7 @@ public class ExtensionFinderTest extends HudsonTestCase {
}
- @Retention(RetentionPolicy.RUNTIME) @BindingAnnotation
+ @Retention(RetentionPolicy.RUNTIME) @Qualifier
public static @interface LionKing {}
@Extension