Move modules into their own packages.

This sets the Automatic-Module-Name for moshi, moshi-adapters, and moshi-kotlin.
It moves moshi-adapters into its own .adapters package and forwards the existing
adapter. It moves the moshi-kotlin into its own .kotlin package and forwards the
existing adapter.

I'm not certain this is necessary or sufficient, but I think it's the right idea
for JPMS compatibility.
This commit is contained in:
Jesse Wilson
2018-02-07 04:33:40 -05:00
parent d26b2a151f
commit 5ad9d31bd8
20 changed files with 391 additions and 261 deletions

View File

@@ -33,4 +33,20 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.squareup.moshi</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -15,6 +15,7 @@
*/
package com.squareup.moshi;
import com.squareup.moshi.internal.Util;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
@@ -26,7 +27,7 @@ import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import static com.squareup.moshi.Util.jsonAnnotations;
import static com.squareup.moshi.internal.Util.jsonAnnotations;
final class AdapterMethodsFactory implements JsonAdapter.Factory {
private final List<AdapterMethod> toAdapters;

View File

@@ -15,6 +15,7 @@
*/
package com.squareup.moshi;
import com.squareup.moshi.internal.Util;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
@@ -48,7 +49,7 @@ final class ClassJsonAdapter<T> extends JsonAdapter<T> {
if (!(type instanceof Class)) return null;
Class<?> rawType = (Class<?>) type;
if (rawType.isInterface() || rawType.isEnum()) return null;
if (isPlatformType(rawType) && !Types.isAllowedPlatformType(rawType)) {
if (Util.isPlatformType(rawType) && !Types.isAllowedPlatformType(rawType)) {
throw new IllegalArgumentException("Platform "
+ type
+ " annotated "
@@ -83,7 +84,7 @@ final class ClassJsonAdapter<T> extends JsonAdapter<T> {
private void createFieldBindings(
Moshi moshi, Type type, Map<String, FieldBinding<?>> fieldBindings) {
Class<?> rawType = Types.getRawType(type);
boolean platformType = isPlatformType(rawType);
boolean platformType = Util.isPlatformType(rawType);
for (Field field : rawType.getDeclaredFields()) {
if (!includeField(platformType, field.getModifiers())) continue;
@@ -115,19 +116,6 @@ final class ClassJsonAdapter<T> extends JsonAdapter<T> {
}
};
/**
* Returns true if {@code rawType} is built in. We don't reflect on private fields of platform
* types because they're unspecified and likely to be different on Java vs. Android.
*/
static boolean isPlatformType(Class<?> rawType) {
String name = rawType.getName();
return name.startsWith("android.")
|| name.startsWith("java.")
|| name.startsWith("javax.")
|| name.startsWith("kotlin.")
|| name.startsWith("scala.");
}
private final ClassFactory<T> classFactory;
private final FieldBinding<?>[] fieldsArray;
private final JsonReader.Options options;

View File

@@ -15,6 +15,7 @@
*/
package com.squareup.moshi;
import com.squareup.moshi.internal.Util;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

View File

@@ -15,6 +15,7 @@
*/
package com.squareup.moshi;
import com.squareup.moshi.internal.Util;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

View File

@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.moshi;
package com.squareup.moshi.internal;
import com.squareup.moshi.JsonQualifier;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
@@ -22,7 +23,7 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
final class Util {
public final class Util {
public static final Set<Annotation> NO_ANNOTATIONS = Collections.emptySet();
private Util() {
@@ -66,4 +67,17 @@ final class Util {
}
return false;
}
/**
* Returns true if {@code rawType} is built in. We don't reflect on private fields of platform
* types because they're unspecified and likely to be different on Java vs. Android.
*/
public static boolean isPlatformType(Class<?> rawType) {
String name = rawType.getName();
return name.startsWith("android.")
|| name.startsWith("java.")
|| name.startsWith("javax.")
|| name.startsWith("kotlin.")
|| name.startsWith("scala.");
}
}

View File

@@ -15,6 +15,7 @@
*/
package com.squareup.moshi;
import com.squareup.moshi.internal.Util;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;

View File

@@ -25,7 +25,7 @@ import okio.Buffer;
import org.junit.Test;
import static com.squareup.moshi.TestUtil.newReader;
import static com.squareup.moshi.Util.NO_ANNOTATIONS;
import static com.squareup.moshi.internal.Util.NO_ANNOTATIONS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;

View File

@@ -26,7 +26,7 @@ import org.assertj.core.data.MapEntry;
import org.junit.Test;
import static com.squareup.moshi.TestUtil.newReader;
import static com.squareup.moshi.Util.NO_ANNOTATIONS;
import static com.squareup.moshi.internal.Util.NO_ANNOTATIONS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;

View File

@@ -16,6 +16,7 @@
package com.squareup.moshi;
import android.util.Pair;
import com.squareup.moshi.internal.Util;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;