Skip to content

Commit

Permalink
Remove redundant references to javax.{inject,persistence,servlet} and…
Browse files Browse the repository at this point in the history
… replace the rest with their jakarta variants.

This required upgrading some test dependencies, because the tests need some impls of the APIs which only exist in newer releases.

This also removes the struts2 extension from the maven & bazel build (although it keeps the now-unused source), because struts2 has no release that supports jakarta. For users that want to continue using the struts2 extension, please continue to use the Guice 6.0 release (instead of the 7.0+ line, which will only support the jakarta dependencies).

Fixes #1383.

(I'll cut the 6.0 candidates/releases from before this commit, and if we need to make further 6.0 changes, I'll manually merge those into the 6.0 branch.)

PiperOrigin-RevId: 529504991
  • Loading branch information
sameb authored and Guice Team committed May 4, 2023
1 parent 5a58425 commit 49b1a33
Show file tree
Hide file tree
Showing 184 changed files with 542 additions and 1,962 deletions.
8 changes: 5 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ javadoc_library(
"//extensions/persist/src/com/google/inject/persist:javadoc-srcs",
"//extensions/servlet/src/com/google/inject/servlet:javadoc-srcs",
"//extensions/spring/src/com/google/inject/spring:javadoc-srcs",
"//extensions/struts2/src/com/google/inject/struts2:javadoc-srcs",
# struts2 doesn't work with jakarta.servlet, so we don't include it.
# We leave the commented out line as a bread-crumb for the future.
# "//extensions/struts2/src/com/google/inject/struts2:javadoc-srcs",
"//extensions/testlib/src/com/google/inject/testing/fieldbinder:javadoc-srcs",
"//extensions/testlib/src/com/google/inject/testing/throwingproviders:javadoc-srcs",
"//extensions/throwingproviders/src/com/google/inject/throwingproviders:javadoc-srcs",
Expand Down Expand Up @@ -62,7 +64,7 @@ javadoc_library(
],
"Servlet Extension": ["com.google.inject.servlet"],
"Spring Extension": ["com.google.inject.spring"],
"Struts2 Extension": ["com.google.inject.struts2"],
# "Struts2 Extension": ["com.google.inject.struts2"],
"Test Libraries Extension": ["com.google.inject.testing.*"],
"ThrowingProviders Extension": ["com.google.inject.throwingproviders"],
},
Expand All @@ -77,7 +79,7 @@ javadoc_library(
"//extensions/persist/src/com/google/inject/persist",
"//extensions/servlet/src/com/google/inject/servlet",
"//extensions/spring/src/com/google/inject/spring",
"//extensions/struts2/src/com/google/inject/struts2",
# "//extensions/struts2/src/com/google/inject/struts2",
"//extensions/testlib/src/com/google/inject/testing/fieldbinder",
"//extensions/testlib/src/com/google/inject/testing/throwingproviders",
"//extensions/throwingproviders/src/com/google/inject/throwingproviders",
Expand Down
21 changes: 4 additions & 17 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ maven_install(
"com.google.errorprone:error_prone_annotations:2.18.0",
"com.google.guava:guava:31.0.1-jre",
"commons-logging:commons-logging:1.2",
"javax.inject:javax.inject:1",
"jakarta.inject:jakarta.inject-api:2.0.1",
"javax.persistence:javax.persistence-api:2.2",
"javax.servlet:servlet-api:2.5",
"jakarta.persistence:jakarta.persistence-api:3.0.0",
"jakarta.servlet:jakarta.servlet-api:5.0.0",
"org.apache.struts:struts2-core:2.5.30",
"org.apache.struts.xwork:xwork-core:2.3.37",
"org.ow2.asm:asm:9.5",
Expand Down Expand Up @@ -70,12 +69,6 @@ maven_install(
"1.1.3",
testonly = True,
),
maven.artifact(
"javax.inject",
"javax.inject-tck",
"1",
testonly = True,
),
maven.artifact(
"jakarta.inject",
"jakarta.inject-tck",
Expand Down Expand Up @@ -106,16 +99,10 @@ maven_install(
"2.2",
testonly = True,
),
maven.artifact(
"org.hibernate.javax.persistence",
"hibernate-jpa-2.0-api",
"1.0.0.Final",
testonly = True,
),
maven.artifact(
"org.hibernate",
"hibernate-core",
"5.6.3.Final",
"hibernate-core-jakarta",
"5.6.15.Final",
testonly = True,
),
maven.artifact(
Expand Down
4 changes: 3 additions & 1 deletion bom/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ java_library(
"//extensions/persist/src/com/google/inject/persist",
"//extensions/servlet/src/com/google/inject/servlet",
"//extensions/spring/src/com/google/inject/spring",
"//extensions/struts2/src/com/google/inject/struts2",
# struts2 doesn't work with jakarta.servlet, so we don't include it.
# We leave the commented out line as a bread-crumb for the future.
# "//extensions/struts2/src/com/google/inject/struts2",
"//extensions/testlib/src/com/google/inject/testing:testlib",
"//extensions/throwingproviders/src/com/google/inject/throwingproviders",
],
Expand Down
2 changes: 2 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@
<artifactId>guice-spring</artifactId>
<version>${project.version}</version>
</dependency>
<!-- struts2 doesn't support jakarta.servlet yet, so we don't include it.
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-struts2</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-testlib</artifactId>
Expand Down
18 changes: 2 additions & 16 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<name>Google Guice - Core Library</name>

<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
Expand Down Expand Up @@ -46,8 +42,8 @@
| Test dependencies
-->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject-tck</artifactId>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-tck</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -98,16 +94,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<testExcludes>
<!--
Don't compile the jakarta TCK b/c it would clash w/ the javax.inject TCK.
We test it with the Bazel build for now, and basic jakarta functionality is tested
with the JakartaTest in the same package.
-->
<testExclude>**/GuiceJakartaTck.java</testExclude>
</testExcludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions core/src/com/google/inject/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ java_library(
srcs = PROVIDED_BY_SRCS,
javacopts = JAVAC_OPTS,
deps = [
"//third_party/java/jsr330_inject",
"//third_party/java/jakarta_inject",
],
)

Expand Down Expand Up @@ -96,7 +96,6 @@ java_library(
"//third_party/java/asm",
"//third_party/java/error_prone:annotations",
"//third_party/java/jsr305_annotations",
"//third_party/java/jsr330_inject",
"//third_party/java/jakarta_inject",
],
)
Expand All @@ -109,7 +108,7 @@ java_library(
],
deps = [
"//third_party/java/error_prone:annotations",
"//third_party/java/jsr330_inject",
"//third_party/java/jakarta_inject",
],
)

Expand Down
2 changes: 1 addition & 1 deletion core/src/com/google/inject/Inject.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* The Injector then proceeds to perform field and method injections.
* <li>Pre-constructed instances passed to {@link Injector#injectMembers}, {@link
* com.google.inject.binder.LinkedBindingBuilder#toInstance(Object)} and {@link
* com.google.inject.binder.LinkedBindingBuilder#toProvider(javax.inject.Provider)}. In this
* com.google.inject.binder.LinkedBindingBuilder#toProvider(jakarta.inject.Provider)}. In this
* case all constructors are, of course, ignored.
* <li>Static fields and methods of classes which any {@link Module} has specifically requested
* static injection for, using {@link Binder#requestStaticInjection}.
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/google/inject/ProvidedBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
public @interface ProvidedBy {

/** The implementation type. */
Class<? extends javax.inject.Provider<?>> value();
Class<? extends jakarta.inject.Provider<?>> value();
}
4 changes: 3 additions & 1 deletion core/src/com/google/inject/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
* @param <T> the type of object this provides
* @author [email protected] (Bob Lee)
*/
public interface Provider<T> extends javax.inject.Provider<T>, jakarta.inject.Provider<T> {
public interface Provider<T>
extends
jakarta.inject.Provider<T> {

/**
* Provides an instance of {@code T}.
Expand Down
1 change: 0 additions & 1 deletion core/src/com/google/inject/Scopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public Boolean visitNoScoping() {
@Override
public Boolean visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
return scopeAnnotation == Singleton.class
|| scopeAnnotation == javax.inject.Singleton.class
|| scopeAnnotation == jakarta.inject.Singleton.class;
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/com/google/inject/binder/LinkedBindingBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ public interface LinkedBindingBuilder<T> extends ScopedBindingBuilder {
* @see com.google.inject.Injector#injectMembers
* @since 4.0
*/
ScopedBindingBuilder toProvider(javax.inject.Provider<? extends T> provider);
ScopedBindingBuilder toProvider(jakarta.inject.Provider<? extends T> provider);

/** See the EDSL examples at {@link com.google.inject.Binder}. */
ScopedBindingBuilder toProvider(Class<? extends javax.inject.Provider<? extends T>> providerType);
ScopedBindingBuilder toProvider(Class<? extends jakarta.inject.Provider<? extends T>> providerType);

/** See the EDSL examples at {@link com.google.inject.Binder}. */
ScopedBindingBuilder toProvider(
TypeLiteral<? extends javax.inject.Provider<? extends T>> providerType);
TypeLiteral<? extends jakarta.inject.Provider<? extends T>> providerType);

/** See the EDSL examples at {@link com.google.inject.Binder}. */
ScopedBindingBuilder toProvider(Key<? extends javax.inject.Provider<? extends T>> providerKey);
ScopedBindingBuilder toProvider(Key<? extends jakarta.inject.Provider<? extends T>> providerKey);

/**
* See the EDSL examples at {@link com.google.inject.Binder}.
Expand Down
26 changes: 12 additions & 14 deletions core/src/com/google/inject/internal/Annotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import javax.inject.Qualifier;

/**
* Annotation utilities.
Expand Down Expand Up @@ -347,7 +346,8 @@ boolean hasAnnotations(Class<? extends Annotation> annotated) {
private static final AnnotationChecker scopeChecker =
new AnnotationChecker(
Arrays.asList(
ScopeAnnotation.class, javax.inject.Scope.class, jakarta.inject.Scope.class));
ScopeAnnotation.class,
jakarta.inject.Scope.class));

public static boolean isScopeAnnotation(Class<? extends Annotation> annotationType) {
return scopeChecker.hasAnnotations(annotationType);
Expand Down Expand Up @@ -405,39 +405,37 @@ public static Annotation findBindingAnnotation(

private static final AnnotationChecker bindingAnnotationChecker =
new AnnotationChecker(
Arrays.asList(BindingAnnotation.class, Qualifier.class, jakarta.inject.Qualifier.class));
Arrays.asList(
BindingAnnotation.class,
jakarta.inject.Qualifier.class));

/** Returns true if annotations of the specified type are binding annotations. */
public static boolean isBindingAnnotation(Class<? extends Annotation> annotationType) {
return bindingAnnotationChecker.hasAnnotations(annotationType);
}

/**
* If the annotation is an instance of {@code javax.inject.Named}, canonicalizes to
* If the annotation is an instance of {@code jakarta.inject.Named}, canonicalizes to
* com.google.guice.name.Named. Returns the given annotation otherwise.
*/
public static Annotation canonicalizeIfNamed(Annotation annotation) {
if (annotation instanceof javax.inject.Named) {
return Names.named(((javax.inject.Named) annotation).value());
} else if (annotation instanceof jakarta.inject.Named) {
if (annotation instanceof jakarta.inject.Named) {
return Names.named(((jakarta.inject.Named) annotation).value());
} else {
return annotation;
}
return annotation;
}

/**
* If the annotation is the class {@code javax.inject.Named}, canonicalizes to
* If the annotation is the class {@code jakarta.inject.Named}, canonicalizes to
* com.google.guice.name.Named. Returns the given annotation class otherwise.
*/
public static Class<? extends Annotation> canonicalizeIfNamed(
Class<? extends Annotation> annotationType) {
if (annotationType == javax.inject.Named.class
|| annotationType == jakarta.inject.Named.class) {
if (
annotationType == jakarta.inject.Named.class) {
return Named.class;
} else {
return annotationType;
}
return annotationType;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions core/src/com/google/inject/internal/BindingBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public void toInstance(T instance) {

@Override
public BindingBuilder<T> toProvider(Provider<? extends T> provider) {
return toProvider((javax.inject.Provider<? extends T>) provider);
return toProvider((jakarta.inject.Provider<? extends T>) provider);
}

@Override
public BindingBuilder<T> toProvider(javax.inject.Provider<? extends T> provider) {
public BindingBuilder<T> toProvider(jakarta.inject.Provider<? extends T> provider) {
checkNotNull(provider, "provider");
checkNotTargetted();

Expand All @@ -130,19 +130,19 @@ public BindingBuilder<T> toProvider(javax.inject.Provider<? extends T> provider)

@Override
public BindingBuilder<T> toProvider(
Class<? extends javax.inject.Provider<? extends T>> providerType) {
Class<? extends jakarta.inject.Provider<? extends T>> providerType) {
return toProvider(Key.get(providerType));
}

@Override
public BindingBuilder<T> toProvider(
TypeLiteral<? extends javax.inject.Provider<? extends T>> providerType) {
TypeLiteral<? extends jakarta.inject.Provider<? extends T>> providerType) {
return toProvider(Key.get(providerType));
}

@Override
public BindingBuilder<T> toProvider(
Key<? extends javax.inject.Provider<? extends T>> providerKey) {
Key<? extends jakarta.inject.Provider<? extends T>> providerKey) {
checkNotNull(providerKey, "providerKey");
checkNotTargetted();

Expand Down
8 changes: 4 additions & 4 deletions core/src/com/google/inject/internal/BindingProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ public Boolean visit(InstanceBinding<? extends T> binding) {
@Override
public Boolean visit(ProviderInstanceBinding<? extends T> binding) {
prepareBinding();
javax.inject.Provider<? extends T> provider = binding.getUserSuppliedProvider();
jakarta.inject.Provider<? extends T> provider = binding.getUserSuppliedProvider();
if (provider instanceof InternalProviderInstanceBindingImpl.Factory) {
@SuppressWarnings("unchecked")
InternalProviderInstanceBindingImpl.Factory<T> asProviderMethod =
(InternalProviderInstanceBindingImpl.Factory<T>) provider;
return visitInternalProviderInstanceBindingFactory(asProviderMethod);
}
Set<InjectionPoint> injectionPoints = binding.getInjectionPoints();
Initializable<? extends javax.inject.Provider<? extends T>> initializable =
initializer.<javax.inject.Provider<? extends T>>requestInjection(
Initializable<? extends jakarta.inject.Provider<? extends T>> initializable =
initializer.<jakarta.inject.Provider<? extends T>>requestInjection(
injector, /* type= */ null, provider, null, source, injectionPoints, errors);
// always visited with Binding<T>
@SuppressWarnings("unchecked")
Expand All @@ -157,7 +157,7 @@ public Boolean visit(ProviderInstanceBinding<? extends T> binding) {
@Override
public Boolean visit(ProviderKeyBinding<? extends T> binding) {
prepareBinding();
Key<? extends javax.inject.Provider<? extends T>> providerKey =
Key<? extends jakarta.inject.Provider<? extends T>> providerKey =
binding.getProviderKey();
// always visited with Binding<T>
@SuppressWarnings("unchecked")
Expand Down
10 changes: 5 additions & 5 deletions core/src/com/google/inject/internal/BoundProviderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
import com.google.inject.Key;
import com.google.inject.internal.InjectorImpl.JitLimitation;
import com.google.inject.spi.Dependency;
import javax.inject.Provider;
import jakarta.inject.Provider;

/** Delegates to a custom factory which is also bound in the injector. */
final class BoundProviderFactory<T> extends ProviderInternalFactory<T> implements CreationListener {

private final ProvisionListenerStackCallback<T> provisionCallback;
private final InjectorImpl injector;
final Key<? extends javax.inject.Provider<? extends T>> providerKey;
private InternalFactory<? extends javax.inject.Provider<? extends T>> providerFactory;
final Key<? extends jakarta.inject.Provider<? extends T>> providerKey;
private InternalFactory<? extends jakarta.inject.Provider<? extends T>> providerFactory;

BoundProviderFactory(
InjectorImpl injector,
Key<? extends javax.inject.Provider<? extends T>> providerKey,
Key<? extends jakarta.inject.Provider<? extends T>> providerKey,
Object source,
ProvisionListenerStackCallback<T> provisionCallback) {
super(source);
Expand All @@ -55,7 +55,7 @@ public void notify(Errors errors) {
public T get(InternalContext context, Dependency<?> dependency, boolean linked)
throws InternalProvisionException {
try {
javax.inject.Provider<? extends T> provider = providerFactory.get(context, dependency, true);
jakarta.inject.Provider<? extends T> provider = providerFactory.get(context, dependency, true);
return circularGet(provider, context, dependency, provisionCallback);
} catch (InternalProvisionException ipe) {
throw ipe.addSource(providerKey);
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/google/inject/internal/InjectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
<T> BindingImpl<T> createProvidedByBinding(
Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors) throws ErrorsException {
Class<?> rawType = key.getTypeLiteral().getRawType();
Class<? extends javax.inject.Provider<?>> providerType = providedBy.value();
Class<? extends jakarta.inject.Provider<?>> providerType = providedBy.value();

// Make sure it's not the same type. TODO: Can we check for deeper loops?
if (providerType == rawType) {
Expand Down
Loading

0 comments on commit 49b1a33

Please sign in to comment.