Skip to content

Commit

Permalink
EASY-2438: Convert to maven multi-module (#149)
Browse files Browse the repository at this point in the history
* convert to maven multi-module
* use DANS formatting
* remove .idea folder
  • Loading branch information
pfrolke authored and janvanmansum committed Dec 10, 2019
1 parent f2ceef3 commit 61d642d
Show file tree
Hide file tree
Showing 128 changed files with 767 additions and 490 deletions.
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
/release.properties
/dependency-reduced-pom.xml
/buildNumber.properties
/*/target/
/*/pom.xml.tag
/*/pom.xml.releaseBackup
/*/pom.xml.versionsBackup
/*/pom.xml.next
/*/release.properties
/*/dependency-reduced-pom.xml
/*/buildNumber.properties
/init-project.sh
*.class
*~
*.swp
/*.iml
*.iml
*.sc
/.idea/
.DS_Store
/apphome.sh
/home/
/data/
/data-*/
/command/home/
/command/data/
/command/data-*/
/.vagrant/
/.yum-repo
/.dans.knaw.nl-yum-repo
Expand Down
File renamed without changes.
144 changes: 144 additions & 0 deletions command/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<!--
Copyright (C) 2015 DANS - Data Archiving and Networked Services ([email protected])
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.
-->
<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>nl.knaw.dans.shared</groupId>
<artifactId>dans-scala-app-project</artifactId>
<version>5.1.0</version>
<relativePath />
</parent>

<groupId>nl.knaw.dans.easy</groupId>
<artifactId>easy-stage-dataset</artifactId>
<version>1.8.6-SNAPSHOT</version>

<name>EASY Stage Dataset Command</name>
<inceptionYear>2015</inceptionYear>

<properties>
<main-class>nl.knaw.dans.easy.stage.command.Command</main-class>
<easy.licenses.version>1.0.5</easy.licenses.version>
</properties>

<dependencies>
<dependency>
<groupId>nl.knaw.dans.easy</groupId>
<artifactId>easy-stage-dataset-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.rogach</groupId>
<artifactId>scallop_2.12</artifactId>
</dependency>
</dependencies>

<repositories>
<repository>
<id>dans-releases</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.dans.knaw.nl/releases/</url>
</repository>
<repository>
<id>dans-snapshots</id>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>https://maven.dans.knaw.nl/snapshots/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>resources</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>nl.knaw.dans.easy</groupId>
<artifactId>easy-licenses</artifactId>
<version>${easy.licenses.version}</version>
<outputDirectory>${project.build.directory}/easy-licenses</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>rpm</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>/usr/local/bin/rpm</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<configuration>
<group>Applications/Archiving</group>
<mappings combine.children="append">
<mapping>
<directory>/opt/${dans-provider-name}/${project.artifactId}/bin</directory>
<filemode>755</filemode>
<sources>
<source>
<location>src/main/assembly/dist/bin/easy-stage-file-item</location>
</source>
</sources>
</mapping>
<mapping>
<directory>/etc/opt/${dans-provider-name}/${project.artifactId}/lic</directory>
<configuration>${rpm-replace-configuration}</configuration>
<sources>
<source>
<location>target/easy-licenses/licenses</location>
</source>
</sources>
</mapping>
</mappings>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.easy.stage
package nl.knaw.dans.easy.stage.command

import java.io.File
import java.nio.file.Paths
Expand All @@ -23,6 +23,8 @@ import nl.knaw.dans.lib.error._
import org.apache.commons.configuration.PropertiesConfiguration
import org.joda.time.DateTime

import nl.knaw.dans.easy.stage.{ Settings, EasyStageDataset }

object Command extends App {

val configuration = Configuration(Paths.get(System.getProperty("app.home")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.easy.stage
package nl.knaw.dans.easy.stage.command

import java.io.File
import java.net.URI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.easy.stage
package nl.knaw.dans.easy.stage.command

import java.io.File
import java.nio.file.{ Files, Path, Paths }
Expand All @@ -31,7 +31,9 @@ object Configuration {
def apply(home: Path): Configuration = {
val cfgPath = Seq(Paths.get(s"/etc/opt/dans.knaw.nl/easy-stage-dataset/"), home.resolve("cfg"))
.find(Files.exists(_))
.getOrElse { throw new IllegalStateException("No configuration directory found") }
.getOrElse {
throw new IllegalStateException("No configuration directory found")
}

new Configuration(
version = managed(Source.fromFile(home.resolve("bin/version").toFile)).acquireAndGet(_.mkString),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright (C) 2015 DANS - Data Archiving and Networked Services ([email protected])
*
* 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 nl.knaw.dans.easy.stage.command.fileitem

import java.nio.file.Paths
import java.sql.SQLException

import com.yourmediashelf.fedora.client.FedoraClientException
import nl.knaw.dans.easy.stage.command.Configuration
import nl.knaw.dans.easy.stage.fileitem.{ EasyFilesAndFoldersImpl, EasyStageFileItem, FileItemSettings }
import nl.knaw.dans.easy.stage.lib._
import nl.knaw.dans.lib.logging.DebugEnhancedLogging
import resource._

import scala.util.{ Success, Try }

object EasyStageFileItemCommand extends DebugEnhancedLogging {

def main(args: Array[String]) {
val configuration = Configuration(Paths.get(System.getProperty("app.home")))
val clo = new FileItemCommandLineOptions(args, configuration)
Fedora.setFedoraConnectionSettings(
configuration.properties.getString("fcrepo.url"),
configuration.properties.getString("fcrepo.user"),
configuration.properties.getString("fcrepo.password"))
getSettingsRows(clo, configuration)
.map(seqOfSettings =>
for (settings <- seqOfSettings;
s <- settings) {
EasyStageFileItem.run(s)
.map(_ => logger.info(s"Staging SUCCESS of $settings"))
.recover { case t: Throwable =>
logger.error(s"Staging FAIL of $settings", t)
if (t.isInstanceOf[SQLException] || t.isInstanceOf[FedoraClientException]) return
}
})
.recover { case t: Throwable => logger.error(s"Staging FAIL of $clo with repo url ${ configuration.properties.getString("fcrepo.url") }", t) }
}

def getSettingsRows(clo: FileItemCommandLineOptions, configuration: Configuration): Try[Seq[ManagedResource[FileItemSettings]]] = {
if (clo.datasetId.isDefined)
Success(
managed(new EasyFilesAndFoldersImpl(
databaseUrl = configuration.properties.getString("db-connection-url"),
databaseUser = configuration.properties.getString("db-connection-user"),
databasePassword = configuration.properties.getString("db-connection-password")))
.map(FileItemApplySettings(clo, _)) :: Nil)
else {
val trailArgs = Seq(clo.sdoSetDir().toString)
CSV(clo.csvFile(), clo.longOptionNames)
.map {
case (csv, warning) =>
for (w <- warning)
logger.warn(w)

val rows = csv.getRows
if (rows.isEmpty) logger.warn("Empty CSV file")
rows.map(options => {
logger.info(s"Options: ${ options.mkString(" ") }")
managed(new EasyFilesAndFoldersImpl(
databaseUrl = configuration.properties.getString("db-connection-url"),
databaseUser = configuration.properties.getString("db-connection-user"),
databasePassword = configuration.properties.getString("db-connection-password")))
.map(FileItemApplySettings(new FileItemCommandLineOptions(options ++ trailArgs, configuration), _))
})
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (C) 2015 DANS - Data Archiving and Networked Services ([email protected])
*
* 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 nl.knaw.dans.easy.stage.command.fileitem

import nl.knaw.dans.easy.stage.fileitem.{ EasyFilesAndFolders, FileItemSettings }
import nl.knaw.dans.easy.stage.lib.FedoraRelationObject

object FileItemApplySettings {
/** new file or folder for an existing dataset */
def apply(conf: FileItemCommandLineOptions, easyFilesAndFolders: EasyFilesAndFolders) =
new FileItemSettings(
sdoSetDir = conf.sdoSetDir.toOption,
file = conf.file.toOption,
datastreamLocation = conf.dsLocation.toOption,
size = conf.size.toOption,
accessibleTo = conf.accessibleTo(),
visibleTo = conf.visibleTo(),
creatorRole = conf.creatorRole(),
ownerId = conf.ownerId.toOption.map(_.trim).filter(_.nonEmpty),
datasetId = conf.datasetId.toOption,
pathInDataset = conf.pathInDataset.toOption,
format = conf.format.toOption,
subordinate = FedoraRelationObject(conf.datasetId()),
easyFilesAndFolders = easyFilesAndFolders) {
override def toString: String = conf.toString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.easy.stage.fileitem
package nl.knaw.dans.easy.stage.command.fileitem

import java.io.File
import java.net.URL

import nl.knaw.dans.easy.stage.Configuration
import nl.knaw.dans.easy.stage.fileitem.FileAccessRights.UserCategory
import nl.knaw.dans.easy.stage.fileitem.FileItemSettings._
import nl.knaw.dans.easy.stage.fileitem.FileAccessRights
import nl.knaw.dans.easy.stage.command.Configuration
import org.rogach.scallop._

class FileItemCommandLineOptions(args: Seq[String], configuration: Configuration) extends ScallopConf(args) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.easy.stage
package nl.knaw.dans.easy.stage.command

import java.io.{ ByteArrayOutputStream, File }

Expand All @@ -40,7 +40,7 @@ abstract class AbstractConfSpec extends FlatSpec with Matchers {
val lineSeparators = s"(${ System.lineSeparator() })+"
val options = helpInfo.split(s"${ lineSeparators }Options:$lineSeparators")(1)
options.trim should not be empty
new File("README.md") should containTrimmed(options)
new File("../README.md") should containTrimmed(options)
}

"distributed default properties" should "be valid options" in {
Expand Down
Loading

0 comments on commit 61d642d

Please sign in to comment.