diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /scalalib |
Publish
Diffstat (limited to 'scalalib')
-rw-r--r-- | scalalib/OWNERS | 1 | ||||
-rw-r--r-- | scalalib/README | 1 | ||||
-rw-r--r-- | scalalib/pom.xml | 83 | ||||
-rw-r--r-- | scalalib/src/main/scala/com/yahoo/vespa/scalalib/arm/Using.scala | 17 | ||||
-rw-r--r-- | scalalib/src/main/scala/com/yahoo/vespa/scalalib/java/function/FunctionConverters.scala | 20 | ||||
-rw-r--r-- | scalalib/src/main/scala/com/yahoo/vespa/scalalib/osgi/maven/ProjectBundleClassPaths.scala | 44 |
6 files changed, 166 insertions, 0 deletions
diff --git a/scalalib/OWNERS b/scalalib/OWNERS new file mode 100644 index 00000000000..3b2ba1ede81 --- /dev/null +++ b/scalalib/OWNERS @@ -0,0 +1 @@ +gjoranv diff --git a/scalalib/README b/scalalib/README new file mode 100644 index 00000000000..9c622c66ec0 --- /dev/null +++ b/scalalib/README @@ -0,0 +1 @@ +Module for shared Scala utility code in Vespa. diff --git a/scalalib/pom.xml b/scalalib/pom.xml new file mode 100644 index 00000000000..a9b0cade639 --- /dev/null +++ b/scalalib/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0"?> +<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>6-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + <artifactId>scalalib</artifactId> + <packaging>jar</packaging> + <version>6-SNAPSHOT</version> + <name>${project.artifactId}</name> + <description>Library for use in Scala components of Vespa.</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.scala-lang</groupId> + <artifactId>scala-library</artifactId> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>annotations</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.json4s</groupId> + <artifactId>json4s-native_${scala.major-version}</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.scala-tools</groupId> + <artifactId>maven-scala-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>add-source</goal> + <goal>compile</goal> + <goal>testCompile</goal> + </goals> + </execution> + </executions> + <configuration> + <args> + <arg>-unchecked</arg> + <arg>-deprecation</arg> + <arg>-feature</arg> + </args> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <compilerArgs> + <arg>-Xlint:rawtypes</arg> + <arg>-Xlint:unchecked</arg> + <arg>-Xlint:deprecation</arg> + </compilerArgs> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>once</forkMode> + <systemPropertyVariables> + <expectedDefaultConfigGenVersion>${project.version}</expectedDefaultConfigGenVersion> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/scalalib/src/main/scala/com/yahoo/vespa/scalalib/arm/Using.scala b/scalalib/src/main/scala/com/yahoo/vespa/scalalib/arm/Using.scala new file mode 100644 index 00000000000..41585b193cf --- /dev/null +++ b/scalalib/src/main/scala/com/yahoo/vespa/scalalib/arm/Using.scala @@ -0,0 +1,17 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.scalalib.arm + +import scala.language.reflectiveCalls + +/** + * @author tonytv + */ +object Using { + def using[RESOURCE <: { def close() }, RETURN](resource: RESOURCE)(f: RESOURCE => RETURN) = { + try { + f(resource) + } finally { + if (resource != null) resource.close() + } + } +} diff --git a/scalalib/src/main/scala/com/yahoo/vespa/scalalib/java/function/FunctionConverters.scala b/scalalib/src/main/scala/com/yahoo/vespa/scalalib/java/function/FunctionConverters.scala new file mode 100644 index 00000000000..012f9b4bbe5 --- /dev/null +++ b/scalalib/src/main/scala/com/yahoo/vespa/scalalib/java/function/FunctionConverters.scala @@ -0,0 +1,20 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.scalalib.java.function + +import java.util.function.Predicate + +import scala.language.implicitConversions + +/** + * For using scala functions in Java APIs, such as the stream API. + * @author tonytv + */ +object FunctionConverters { + implicit class JavaPredicate[T](f: T => Boolean) extends Predicate[T] { + override def test(t: T): Boolean = f(t) + } + + implicit class JavaFunction[T, R](f: T => R) extends java.util.function.Function[T, R] { + override def apply(t: T): R = f(t) + } +} diff --git a/scalalib/src/main/scala/com/yahoo/vespa/scalalib/osgi/maven/ProjectBundleClassPaths.scala b/scalalib/src/main/scala/com/yahoo/vespa/scalalib/osgi/maven/ProjectBundleClassPaths.scala new file mode 100644 index 00000000000..9bf35e06ce5 --- /dev/null +++ b/scalalib/src/main/scala/com/yahoo/vespa/scalalib/osgi/maven/ProjectBundleClassPaths.scala @@ -0,0 +1,44 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.scalalib.osgi.maven + +import java.nio.charset.StandardCharsets +import java.nio.file.{Files, Path} + +import org.json4s.NoTypeHints +import org.json4s.native.Serialization + +import ProjectBundleClassPaths._ + +/** + * Represents the bundles in a maven project and the classpath elements + * corresponding to code that would end up in the bundle. + * @author tonytv + */ +case class ProjectBundleClassPaths(mainBundle: BundleClasspathMapping, + providedDependencies: List[BundleClasspathMapping]) + + +object ProjectBundleClassPaths { + //Written by bundle-plugin in the test classes directory. + val classPathMappingsFileName = "bundle-plugin.bundle-classpath-mappings.json" + + case class BundleClasspathMapping(bundleSymbolicName: String, classPathElements: List[String]) + + //Used by Serialization.* methods. See https://github.com/json4s/json4s + private implicit val serializationFormat = Serialization.formats(NoTypeHints) + + def save(path: Path, mappings: ProjectBundleClassPaths) { + Files.createDirectories(path.getParent) + val outputFile = Files.newBufferedWriter(path, StandardCharsets.UTF_8) + try { + Serialization.write(mappings, outputFile) + } finally { + outputFile.close() + } + } + + def load(path: Path): ProjectBundleClassPaths = { + val inputFile = Files.newBufferedReader(path, StandardCharsets.UTF_8) + Serialization.read[ProjectBundleClassPaths](inputFile) + } +} |