Skip to content
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

Make mosaic multimodule project. #402

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions mosaic-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>com.databricks.labs</groupId>
<artifactId>mosaic</artifactId>
<version>0.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>mosaic-core</artifactId>
<name>mosaic-core</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>
<!--Test Dependencies-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.compat.version}</artifactId>
</dependency>
<dependency>
<groupId>org.scalamock</groupId>
<artifactId>scalamock_${scala.compat.version}</artifactId>
</dependency>
<!--Runtime Dependencies-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.compat.version}</artifactId>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-catalyst_${scala.compat.version}</artifactId>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.compat.version}</artifactId>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<?m2e execute onConfiguration?>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<!-- Tests will be run with scalatest-maven-plugin instead -->
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/test-reports</reportsDirectory>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<verbose>true</verbose>
<failOnViolation>true</failOnViolation>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
<failOnWarning>false</failOnWarning>
<sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
<configLocation>scalastyle-config.xml</configLocation>
<outputFile>${basedir}/target/scalastyle-output.xml</outputFile>
<inputEncoding>${encoding}</inputEncoding>
<outputEncoding>${encoding}</outputEncoding>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.4.11</version>
<executions>
<execution>
<id>scoverage-report</id>
<phase>package</phase>
<goals>
<goal>check</goal>
<goal>report-only</goal>
</goals>
</execution>
</executions>
<configuration>
<minimumCoverage>0</minimumCoverage>
<failOnMinimumCoverage>true</failOnMinimumCoverage>
<scalaVersion>${scala.version}</scalaVersion>
<additionalForkedProjectProperties>skipTests=false</additionalForkedProjectProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-files-on-build</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/python/mosaic/lib</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/</directory>
<include>*.jar</include>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.databricks.labs.mosaic.geometry.JTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
com.databricks.labs.mosaic.index.H3
com.databricks.labs.mosaic.index.BNG
com.databricks.labs.mosaic.index.CUSTOM
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.databricks.labs.mosaic.raster.GDAL
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.databricks.labs.mosaic.core

import com.databricks.labs.mosaic.core.geometry.api.GeometryAPI
import com.databricks.labs.mosaic.core.index.IndexSystem
import com.databricks.labs.mosaic.core.raster.RasterAPI
import com.databricks.labs.mosaic.core.util.ResourceUtils

import scala.util.Try

/**
* Generic service factory for loading implementations of [[com.databricks.labs.mosaic.core.geometry.api.GeometryAPI]],
* [[com.databricks.labs.mosaic.core.index.IndexSystem]] and [[com.databricks.labs.mosaic.core.raster.RasterAPI]].
* This class implements the interaction with the META-INF/services directory.
* All the implementations are provided via the META-INF/services directory and are loaded at runtime.
*/
abstract class GenericServiceFactory[T](registerName: String) {

private def fetchClasses: Seq[Class[_]] = {
ResourceUtils.readResourceLines(s"/META-INF/services/$registerName")
.map(name => Try(Class.forName(name)))
.filter(_.isSuccess)
.map(_.get)
.toSeq
}

def getService(name: String, params: Array[Object] = Array.empty): T = {
val classes = fetchClasses
val instance = classes
.map(clazz => Try(clazz.getConstructor(params.map(_.getClass): _*)))
.map(_.map(_.newInstance(params: _*).asInstanceOf[T]))
.filter(_.isSuccess)
.map(_.get)
.headOption

instance.getOrElse(
throw new IllegalArgumentException(s"Unable to find service with name $name")
)
}

}

/**
* This object contains the actual factory instances for [[com.databricks.labs.mosaic.core.geometry.api.GeometryAPI]],
* [[com.databricks.labs.mosaic.core.index.IndexSystem]] and [[com.databricks.labs.mosaic.core.raster.RasterAPI]].
*/
object GenericServiceFactory {

object GeometryAPIFactory
extends GenericServiceFactory[GeometryAPI](registerName = "com.databricks.labs.mosaic.GeometryAPIRegister") {
def getGeometryAPI(name: String, params: Array[Object] = Array.empty): GeometryAPI = {
getService(name, params)
}
}

object IndexSystemFactory
extends GenericServiceFactory[IndexSystem](registerName = "com.databricks.labs.mosaic.IndexSystemRegister") {
def getIndexSystem(name: String, params: Array[Object] = Array.empty): IndexSystem = {
getService(name, params)
}
}

object RasterAPIFactory
extends GenericServiceFactory[RasterAPI](registerName = "com.databricks.labs.mosaic.RasterAPIRegister") {
def getRasterAPI(name: String, params: Array[Object] = Array.empty): RasterAPI = {
getService(name, params)
}
}

}
Loading