-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vaidas Pilkauskas
committed
Jan 11, 2021
1 parent
85f9c8c
commit bff248e
Showing
1 changed file
with
20 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 20 additions & 2 deletions
22
test/src/main/scala/scalarules/test/scala_import/ScalaImportExposesJarsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
package scalarules.test.scala_import | ||
|
||
import java.util.jar.JarFile | ||
|
||
import com.google.common.cache.Cache | ||
import org.apache.commons.lang3.ArrayUtils | ||
import org.specs2.mutable.SpecificationWithJUnit | ||
import org.specs2.mutable.SpecWithJUnit | ||
|
||
import scala.reflect.{ClassTag, _} | ||
|
||
class ScalaImportExposesJarsTest extends SpecificationWithJUnit { | ||
class ScalaImportExposesJarsTest extends SpecWithJUnit { | ||
|
||
"scala_import" should { | ||
"enable using the jars it exposes" in { | ||
println(classOf[Cache[String, String]]) | ||
println(classOf[ArrayUtils]) | ||
success | ||
} | ||
|
||
"stamps jars with a target label" in { | ||
val targetLabel = "//test/src/main/scala/scalarules/test/scala_import:guava_and_commons_lang" | ||
findTargetLabel[Cache[String, String]] must beSome(targetLabel) | ||
findTargetLabel[ArrayUtils] must beSome(targetLabel) | ||
} | ||
} | ||
|
||
def findTargetLabel[T: ClassTag]: Option[String] = { | ||
val file = classTag[T].runtimeClass.getProtectionDomain.getCodeSource.getLocation.getFile | ||
val jar = new JarFile(file) | ||
val label = jar.getManifest.getMainAttributes.getValue("Target-Label") | ||
jar.close() | ||
Some(label) | ||
} | ||
|
||
} |