Skip to content

Commit

Permalink
Fix corss-build
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Nov 15, 2023
1 parent 741d112 commit 168c252
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2023 Spotify AB
*
* 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.spotify.scio.coders.instances

import java.lang.{Iterable => JIterable}

private[coders] object JavaCollectionWrappers {

// private classes
val JIterableWrapperClass: Class[_] =
Class.forName("scala.collection.convert.Wrappers.JIterableWrapper")
val JCollectionWrapperClass: Class[_] =
Class.forName("scala.collection.convert.Wrappers.JCollectionWrapper")
val JListWrapperClass: Class[_] =
Class.forName("scala.collection.convert.Wrappers.JListWrapper")

object JIterableWrapper {
def unapply(arg: Any): Option[JIterable[_]] = arg match {
case arg if arg.getClass == JListWrapperClass =>
val underlying = JListWrapperClass
.getField("underlying")
.get(arg)
.asInstanceOf[JIterable[_]]
Some(underlying)
case _ => None
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.spotify.scio.coders.instances

import java.lang.{Iterable => JIterable}
private[coders] object JavaCollectionWrappers {

// private classes
val JIterableWrapperClass: Class[_] =
Class.forName("scala.collection.convert.JavaCollectionWrappers.JIterableWrapper")
val JCollectionWrapperClass: Class[_] =
Class.forName("scala.collection.convert.JavaCollectionWrappers.JCollectionWrapper")
val JListWrapperClass: Class[_] =
Class.forName("scala.collection.convert.JavaCollectionWrappers.JListWrapper")

object JIterableWrapper {
def unapply(arg: Any): Option[JIterable[_]] = arg match {
case arg if arg.getClass == JListWrapperClass =>
val underlying = JListWrapperClass
.getField("underlying")
.get(arg)
.asInstanceOf[JIterable[_]]
Some(underlying)
case _ => None
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.reflect.ClassPat
import org.joda.time.{DateTime, LocalDate, LocalDateTime, LocalTime}
import org.slf4j.LoggerFactory

import _root_.java.lang.{Iterable => JIterable}
import scala.jdk.CollectionConverters._
import scala.collection.mutable
import scala.collection.convert.JavaCollectionWrappers

private object KryoRegistrarLoader {
private[this] val logger = LoggerFactory.getLogger(this.getClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,6 @@ import scala.jdk.CollectionConverters._
import java.util.{List => JList}
import java.lang.{Iterable => JIterable}

private[coders] object JavaCollectionWrappers {

// private classes
val JIterableWrapperClass: Class[_] =
Class.forName("scala.collection.convert.JavaCollectionWrappers.JIterableWrapper")
val JCollectionWrapperClass: Class[_] =
Class.forName("scala.collection.convert.JavaCollectionWrappers.JCollectionWrapper")
val JListWrapperClass: Class[_] =
Class.forName("scala.collection.convert.JavaCollectionWrappers.JListWrapper")

object JIterableWrapper {
def unapply(arg: Any): Option[JIterable[_]] = arg match {
case arg if arg.getClass == JListWrapperClass =>
val underlying = JListWrapperClass
.getField("underlying")
.get(arg)
.asInstanceOf[JIterable[_]]
Some(underlying)
case _ => None
}
}
}

private[coders] object UnitCoder extends AtomicCoder[Unit] {
override def encode(value: Unit, os: OutputStream): Unit = ()
override def decode(is: InputStream): Unit = ()
Expand Down

0 comments on commit 168c252

Please sign in to comment.