This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-sbt.git
The following commit(s) were added to refs/heads/main by this push:
new 80a06bd Add setting to enable flattened directory layout
80a06bd is described below
commit 80a06bd01da0de356b1148c986b7bbd68d913ea0
Author: Steve Lawrence <[email protected]>
AuthorDate: Wed Jan 24 11:19:36 2024 -0500
Add setting to enable flattened directory layout
- Add new "daffodilFlatLayout" setting--if true the plugin configures
SBT so project files are in root "src/" or "test/" directories, and
sources vs. resources is determined by file extension.
- Scripted uses a file called "test" for scripted commands, but this
conflicts with the "test/" directory if daffodilFlatLayout is true.
Fortunately, scripted supports "test.script" as an alternative, so
scripted "test" files are renamed to this.
Closes #8
---
README.md | 16 +++++++++
.../scala/org/apache/daffodil/DaffodilPlugin.scala | 41 ++++++++++++++++++++++
src/sbt-test/sbt-daffodil/flat-layout-01/build.sbt | 26 ++++++++++++++
.../flat-layout-01/project/plugins.sbt | 20 +++++++++++
.../sbt-daffodil/flat-layout-01/src/test.dfdl.xsd | 37 +++++++++++++++++++
.../test => flat-layout-01/test.script} | 15 ++------
.../sbt-daffodil/flat-layout-01/test/test.scala | 34 ++++++++++++++++++
.../sbt-daffodil/flat-layout-01/test/test.tdml | 34 ++++++++++++++++++
.../saved-parsers-01/{test => test.script} | 0
9 files changed, 210 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index 2cc0906..86630ac 100644
--- a/README.md
+++ b/README.md
@@ -94,6 +94,22 @@ If used, one may want to use the first value of this setting
to configure
daffodilVersion := daffodilPackageBinVersions.value.head
```
+## Flat Directory Layout
+
+Instead of using the standard `src/{main,test}/{scala,resources}/` directory
+layout that SBT defaults to, a flatter layout can be used for simple schemas,
+like when testing or creating examples. One can set `daffodilFlatLayout` to
+enable this:
+
+```scala
+daffodilFlatLayout := true
+```
+
+This configures SBT to expect all compile source and resource files to be in a
+root `src/` directory, and all test source and resource files to be in a root
+`test/` directory. Source files are those that end with `*.scala` or `*.java`,
+and resource files are anything else.
+
# License
Apache Daffodil SBT Plugin is licensed under the [Apache License, v2.0].
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index 7e17f86..3bc06ef 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -39,6 +39,9 @@ object DaffodilPlugin extends AutoPlugin {
val daffodilVersion = settingKey[String](
"Version of daffodil to add as a dependency",
)
+ val daffodilFlatLayout = settingKey[Boolean](
+ "Whether or not to use a flat schema project layout that uses src/ and
test/ root directories containing a mix of sources and resources",
+ )
}
import autoImport._
@@ -104,6 +107,11 @@ object DaffodilPlugin extends AutoPlugin {
*/
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v"),
+ /**
+ * Disable the flat layout by default
+ */
+ daffodilFlatLayout := false,
+
/**
* Default to building no saved parsers and supporting no versions of
daffodil
*/
@@ -261,6 +269,39 @@ object DaffodilPlugin extends AutoPlugin {
}
updatedPackagedArtifacts
},
+ ) ++
+ inConfig(Compile)(flatLayoutSettings("src")) ++
+ inConfig(Test)(flatLayoutSettings("test"))
+
+ /**
+ * If daffodilFlatLayout is true, returns settings to make a flat directory
layout. All
+ * sources and resources for a configuration are expected to be in the
directory specified by
+ * the "dir" parameter. Files that end in *.scala or *.java are treated as
sources, and all
+ * other files are treated as resources. This should be used inside a
Compile or Test
+ * configuration, like this:
+ *
+ * inConfig(Compile)(flatLayoutSettings("src"))
+ * inConfig(Test)(flatLayoutSettings("test"))
+ *
+ * If daffodilFlatLayout is false, this returns each of the settings
unchanged.
+ */
+ def flatLayoutSettings(dir: String) = Seq(
+ unmanagedSourceDirectories := {
+ if (!daffodilFlatLayout.value) unmanagedSourceDirectories.value
+ else Seq(baseDirectory.value / dir)
+ },
+ unmanagedResourceDirectories := {
+ if (!daffodilFlatLayout.value) unmanagedResourceDirectories.value
+ else unmanagedSourceDirectories.value
+ },
+ unmanagedSources / includeFilter := {
+ if (!daffodilFlatLayout.value) (unmanagedSources / includeFilter).value
+ else "*.java" | "*.scala"
+ },
+ unmanagedResources / excludeFilter := {
+ if (!daffodilFlatLayout.value) (unmanagedResources / excludeFilter).value
+ else (unmanagedSources / includeFilter).value,
+ },
)
}
diff --git a/src/sbt-test/sbt-daffodil/flat-layout-01/build.sbt
b/src/sbt-test/sbt-daffodil/flat-layout-01/build.sbt
new file mode 100644
index 0000000..07df203
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/flat-layout-01/build.sbt
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+version := "0.1"
+
+name := "test"
+
+organization := "com.example"
+
+daffodilVersion := "3.6.0"
+
+daffodilFlatLayout := true
diff --git a/src/sbt-test/sbt-daffodil/flat-layout-01/project/plugins.sbt
b/src/sbt-test/sbt-daffodil/flat-layout-01/project/plugins.sbt
new file mode 100644
index 0000000..eaf249b
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/flat-layout-01/project/plugins.sbt
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+addSbtPlugin("org.apache.daffodil" % "sbt-daffodil" %
sys.props("plugin.version"))
diff --git a/src/sbt-test/sbt-daffodil/flat-layout-01/src/test.dfdl.xsd
b/src/sbt-test/sbt-daffodil/flat-layout-01/src/test.dfdl.xsd
new file mode 100644
index 0000000..dbab88c
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/flat-layout-01/src/test.dfdl.xsd
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:ex="http://example.com"
+ targetNamespace="http://example.com"
+ elementFormDefault="unqualified">
+
+ <include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+ <annotation>
+ <appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:format ref="ex:GeneralFormat" />
+ </appinfo>
+ </annotation>
+
+ <element name="test01" type="xs:string" dfdl:lengthKind="delimited" />
+
+</schema>
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-01/test
b/src/sbt-test/sbt-daffodil/flat-layout-01/test.script
similarity index 55%
copy from src/sbt-test/sbt-daffodil/saved-parsers-01/test
copy to src/sbt-test/sbt-daffodil/flat-layout-01/test.script
index c2e7033..8d94745 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/test
+++ b/src/sbt-test/sbt-daffodil/flat-layout-01/test.script
@@ -16,16 +16,5 @@
## under the License.
##
-> packageDaffodilBin
-$ exists target/test-0.1-daffodil350.bin
-$ exists target/test-0.1-daffodil360.bin
-$ exists target/test-0.1-two-daffodil350.bin
-$ exists target/test-0.1-two-daffodil360.bin
-
-> set publishTo := Some(Resolver.file("file", new File("target/ivy-publish/")))
-> publish
-$ exists target/ivy-publish/com/example/test/0.1/test-0.1.jar
-$ exists target/ivy-publish/com/example/test/0.1/test-0.1-daffodil350.bin
-$ exists target/ivy-publish/com/example/test/0.1/test-0.1-daffodil360.bin
-$ exists target/ivy-publish/com/example/test/0.1/test-0.1-two-daffodil350.bin
-$ exists target/ivy-publish/com/example/test/0.1/test-0.1-two-daffodil360.bin
+> compile
+> test
diff --git a/src/sbt-test/sbt-daffodil/flat-layout-01/test/test.scala
b/src/sbt-test/sbt-daffodil/flat-layout-01/test/test.scala
new file mode 100644
index 0000000..6f8f20d
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/flat-layout-01/test/test.scala
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.example
+
+import org.junit.Test
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
+
+object TestExample {
+ lazy val runner = Runner("/", "test.tdml")
+
+ @AfterClass def shutdown: Unit = { runner.reset }
+}
+
+class TestExample {
+ import TestExample._
+
+ @Test def test_test01() { runner.runOneTest("test01") }
+}
diff --git a/src/sbt-test/sbt-daffodil/flat-layout-01/test/test.tdml
b/src/sbt-test/sbt-daffodil/flat-layout-01/test/test.tdml
new file mode 100644
index 0000000..4906b7a
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/flat-layout-01/test/test.tdml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<testSuite
+ xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:ex="http://example.com">
+
+ <parserTestCase name="test01" root="test01" model="test.dfdl.xsd">
+ <document>test data</document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:test01>test data</ex:test01>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+</testSuite>
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-01/test
b/src/sbt-test/sbt-daffodil/saved-parsers-01/test.script
similarity index 100%
rename from src/sbt-test/sbt-daffodil/saved-parsers-01/test
rename to src/sbt-test/sbt-daffodil/saved-parsers-01/test.script