-
Notifications
You must be signed in to change notification settings - Fork 267
Add Java Platform Module System (JPMS) support #1601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c04ad9e
ad1f8d1
2659b4f
b78c9a0
8aead27
5760bfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| <parent> | ||
| <groupId>com.google.truth</groupId> | ||
| <artifactId>truth-parent</artifactId> | ||
| <version>HEAD-SNAPSHOT</version> | ||
| <version>999.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>truth</artifactId> | ||
| <name>Truth Core</name> | ||
|
|
@@ -110,6 +110,13 @@ | |
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <configuration> | ||
| <archive> | ||
| <manifestEntries> | ||
| <Multi-Release>true</Multi-Release> | ||
| </manifestEntries> | ||
| </archive> | ||
| </configuration> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error #2 from That should just be a matter of loosening the assertion to accept either style. Of course, another option for this (and for Error #1) is to see if we can keep |
||
| <executions> | ||
| <execution> | ||
| <id>attach-gwt-sources</id> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| /* | ||||||
| * Copyright (c) 2025 Google, Inc. | ||||||
| * | ||||||
| * Licensed 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. | ||||||
| */ | ||||||
|
|
||||||
| module com.google.truth { | ||||||
| requires com.google.common; | ||||||
| requires static junit; | ||||||
| requires java.compiler; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that this is for If I were more ambitious, I would think about this more and possibly open an issue against AutoValue or AutoCommon or something. It might be that we could avoid this by not performing a "real" Java 9 build, instead only using Java 9 for the I think I'm tentatively in favor of leaving this line here but tweaking it to
Suggested change
|
||||||
|
|
||||||
| requires static org.jspecify; | ||||||
| requires static com.google.errorprone.annotations; | ||||||
| requires static org.objectweb.asm; | ||||||
| requires static auto.value.annotations; | ||||||
cowwoc marked this conversation as resolved.
Show resolved
Hide resolved
cowwoc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| requires static com.google.j2objc.annotations; | ||||||
|
|
||||||
| exports com.google.common.truth; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| <parent> | ||
| <groupId>com.google.truth.extensions</groupId> | ||
| <artifactId>truth-extensions-parent</artifactId> | ||
| <version>HEAD-SNAPSHOT</version> | ||
| <version>999.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>truth-liteproto-extension</artifactId> | ||
| <name>Truth Extension for Lite Protocol Buffers</name> | ||
|
|
@@ -97,6 +97,16 @@ | |
| </annotationProcessorPaths> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <configuration> | ||
| <archive> | ||
| <manifestEntries> | ||
| <Multi-Release>true</Multi-Release> | ||
| </manifestEntries> | ||
| </archive> | ||
| </configuration> | ||
| </plugin> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error from I haven't thought about that one, but it might be a matter of moving more stuff or updating more references. I'd encourage you not to worry about it until we discuss the proto/liteproto business more, but I'm noting it here as a record of potential remaining work. |
||
| </plugins> | ||
| </build> | ||
| </project> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,18 +14,19 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.common.truth.extensions.proto; | ||
| package com.google.common.truth.extensions.liteproto; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have thought of this, too. It serves me right for saying how "unlikely" it was that we'd need to release a Truth 2.0.0... :) Changing the package is a tough sell. We might still be able to pull it off, but it would take some effort for both us and our users, including an internal migration that would probably be mostly straightforward but would take some time. I'm wondering about a potential alternative: What if we were to put both ProtoTruth and LiteProtoTruth into a single artifact with a dependency on Ideally we'd call that artifact This would be roughly the approach that we already used when merging the Java 8 extensions into the core of Truth. The difference would be that, in our previous merge, we could reasonably expect for users of the Java 8 extension to also already declare a dependency on core Truth (or, failing that, to be using a build tool that was happy to let them rely on transitive dependencies). Here, we wouldn't expect a project that uses ProtoTruth to also declare a dependency on LiteProtoTruth. Again, though, that won't be a problem unless the user uses a build tool that is strict about transitive deps. (Could we have Maven redirect things automatically? I think I saw that done for GWT, but maybe that can be done only for a change to The other option, of course, is to give up on modularizing the protobuf extensions. I don't know if you're modularizing them because you have a need for that or just because you want to be an even better citizen as you work to modularize the core. Let me know if you have thoughts on the approach. I can think about it more before encouraging you to redo things yet again.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, the fact that we're not able to make any traction at modularizing the protobuf library is a real pain. Putting aside the protobuf library for a minute, would this approach work for the truth library? protocolbuffers/protobuf#16133 (comment) Or do you have a similar hierarchy problem as they do?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, of course, we can't modularize "for real" until Protobuf does :( I would really like to avoid duplicating all the existing classes, even those just in the protobuf extensions. Truth (especially ProtoTruth) doesn't get extended the way that Protobuf does, but it would still mean two parallel mini-ecosystems. I'd like to think that we can work out the merging of the two protobuf artifacts if it comes to that. |
||
|
|
||
| import static com.google.common.base.Strings.lenientFormat; | ||
| import static com.google.common.truth.Fact.fact; | ||
| import static com.google.common.truth.Fact.simpleFact; | ||
| import static com.google.common.truth.extensions.proto.Platform.getTrimmedToString; | ||
| import static com.google.common.truth.extensions.liteproto.Platform.getTrimmedToString; | ||
|
|
||
| import com.google.common.annotations.GwtIncompatible; | ||
| import com.google.common.annotations.J2ktIncompatible; | ||
| import com.google.common.truth.FailureMetadata; | ||
| import com.google.common.truth.IntegerSubject; | ||
| import com.google.common.truth.Subject; | ||
| import com.google.common.truth.extensions.liteproto.internal.LiteProtoSubjectAccess; | ||
| import com.google.errorprone.annotations.CheckReturnValue; | ||
| import com.google.j2objc.annotations.J2ObjCIncompatible; | ||
| import com.google.protobuf.MessageLite; | ||
|
|
@@ -44,6 +45,16 @@ | |
| @NullMarked | ||
| public class LiteProtoSubject extends Subject { | ||
|
|
||
| // Static initializer to register SharedSecrets accessor | ||
| static { | ||
| LiteProtoSubjectAccess.setAccessor(new LiteProtoSubjectAccess.Accessor() { | ||
| @Override | ||
| public String getCustomStringRepresentation(LiteProtoSubject subject) { | ||
| return subject.actualCustomStringRepresentationForProtoPackageMembersToCall(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a {@code Subject.Factory} for {@link MessageLite} subjects which you can use to assert | ||
| * things about Lite Protobuf properties. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright (c) 2025 Google, Inc. | ||
| * | ||
| * Licensed 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 com.google.common.truth.extensions.liteproto.internal; | ||
|
|
||
| import com.google.common.truth.extensions.liteproto.LiteProtoSubject; | ||
|
|
||
| /** | ||
| * Provides access to package-private methods in LiteProtoSubject for use by | ||
| * other Truth extensions. | ||
| * | ||
| * <p><b>This is an internal API and should not be used by client code.</b> | ||
| * This class may be removed or changed at any time without notice. | ||
| */ | ||
| public final class LiteProtoSubjectAccess { | ||
|
|
||
| /** | ||
| * Accessor interface for LiteProtoSubject internal methods. | ||
| * Set by LiteProtoSubject during class initialization. | ||
| */ | ||
| public interface Accessor { | ||
| String getCustomStringRepresentation(LiteProtoSubject subject); | ||
| } | ||
|
|
||
| private static Accessor accessor; | ||
|
|
||
| /** | ||
| * Sets the accessor. This is called by LiteProtoSubject during class initialization. | ||
| * | ||
| * @param accessor the accessor implementation | ||
| * @throws IllegalStateException if the accessor is already set | ||
| */ | ||
| public static void setAccessor(Accessor accessor) { | ||
| if (LiteProtoSubjectAccess.accessor != null) { | ||
| throw new IllegalStateException("Accessor already set"); | ||
| } | ||
| LiteProtoSubjectAccess.accessor = accessor; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the custom string representation for the given LiteProtoSubject. | ||
| * | ||
| * @param subject the LiteProtoSubject instance | ||
| * @return the custom string representation | ||
| * @throws IllegalStateException if no accessor has been set | ||
| */ | ||
| public static String getCustomStringRepresentation(LiteProtoSubject subject) { | ||
| if (accessor == null) { | ||
| throw new IllegalStateException("No accessor set"); | ||
| } | ||
| return accessor.getCustomStringRepresentation(subject); | ||
| } | ||
|
|
||
| private LiteProtoSubjectAccess() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright (c) 2016 Google, Inc. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Custom subjects for testing <a href="https://developers.google.com/protocol-buffers/">Protocol | ||
| * Buffer Lite</a> instances. | ||
| * | ||
| * <p>This package provides Truth extensions specifically for protobuf-lite, which is a | ||
| * lighter-weight version of Protocol Buffers with reduced functionality but smaller | ||
| * binary size and better performance for resource-constrained environments. | ||
| * | ||
| * <p>This package is a part of the open-source <a href="https://github.com/google/truth">Truth</a> | ||
| * project. | ||
| */ | ||
| @CheckReturnValue | ||
| package com.google.common.truth.extensions.liteproto; | ||
|
|
||
| import com.google.errorprone.annotations.CheckReturnValue; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2025 Google, Inc. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| module com.google.truth.extensions.liteproto { | ||
| requires com.google.truth; | ||
| requires com.google.common; | ||
| requires java.compiler; | ||
|
|
||
| requires static org.jspecify; | ||
| requires static com.google.errorprone.annotations; | ||
| requires static protobuf.lite; | ||
| requires static auto.value.annotations; | ||
| requires static com.google.j2objc.annotations; | ||
|
|
||
| exports com.google.common.truth.extensions.liteproto; | ||
| exports com.google.common.truth.extensions.liteproto.internal to com.google.truth.extensions.proto; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current configuration, I don't think we actually end up producing a multi-release jar, so I think we can get by without this.