Skip to content

Commit e568c6c

Browse files
committed
Moved "Common practices" doc here (from dans-module-archetype)
1 parent c09fefe commit e568c6c

4 files changed

Lines changed: 211 additions & 0 deletions

File tree

docs/dev-common-practices.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
Common Practices
2+
================
3+
4+
Here are some miscellaneous common practices to follow when developing for the DANS Data Station Architecture. It is assumed that you are using IntelliJ. If
5+
this is not the case, please adapt accordingly.
6+
7+
Code Style
8+
----------
9+
10+
* Install the IntelliJ [code style] and [inspections]. Format the source code with these settings in our own projects. Resolve the warnings
11+
indicated by the inspections.
12+
* In Dataverse try to minimize code changes due to reformatting, so only apply formatting to code that you have changed anyway.
13+
* In the POM file keep the order the of the elements as follows (note that some are optional):
14+
* `modelVersion`
15+
* `parent`
16+
* `groupId`
17+
* `artifactId`
18+
* `version`
19+
* `name`
20+
* `url`
21+
* `description`
22+
* `inceptionYear`
23+
* `properties`
24+
* `scm`
25+
* `dependencyManagement`
26+
* `dependencies`
27+
* `build`
28+
* `repositories`
29+
* `distributionManagement`
30+
* `profiles`
31+
32+
### Lombok
33+
34+
Use [Lombok]{:target=_blank} for:
35+
36+
* Adding loggers with the `@Slf4j` annotation (this names the logger after the fully qualified class name automatically).
37+
* Creating getters, setters and constructors on value objects (i.e. the main purpose of the object is to store values and not to perform operations).
38+
39+
Dependency Management
40+
---------------------
41+
Dependency management of Java projects is done with Maven. Projects should inherit from `dd-parent`. The first thing that most projects will include is
42+
`io.dropwizard:dropwizard-core`.
43+
44+
Testing
45+
-------
46+
47+
* Unit test names should be as descriptive as possible. Since this will often involve creating long test names, use `snake_case` instead of `camelCase` here.
48+
* Unit tests will often need to write some temporary data to disk. The location for this is `<project-dir>/target/test/<ClassNameOfUnitTest>`. By working under
49+
`target` we make sure the unit tests don't interfere with the project itself or the test files we are using for [debugging](#debugging).
50+
* Unit tests should clear their temporary directory **before** the tests start, but leave everything on disk after finishing. This allows you to diagnose
51+
any problems with a test by running it and inspecting its temporary directory.
52+
53+
Debugging
54+
---------
55+
56+
For debugging use the scripts in [dans-dev-scripts]{:target=_blank}. Start the environment with `start-env.sh`. This sets up configuration files under
57+
`<project-dir>/etc/` for use during debugging and create directory to store input and output files under `<project-dir>/data/`. Start the program with the
58+
`start-*debug.sh` helper scripts and then attach IntelliJ to the VM.
59+
60+
Documentation
61+
-------------
62+
Each module has its associated documentation site, which is published at `dans-knaw.github.io`. The archetype sets up the project with a skeleton site. Use
63+
the `start-mkdocs.sh` script in [dans-dev-scripts]{:target=_blank} to start the site locally and see what it looks like after you have made your changes.
64+
65+
Each documentation site follows a common structure which depends on the type of module: library, microservice, or command-line application. See existing
66+
documentation sites for examples.
67+
68+
### JavaDocs
69+
70+
If the project is a library it should include JavaDocs. Extensive code examples are best relegated to separated pages, outside
71+
the JavaDocs, so that you can make full use of the extended Markdown support of mkdocs. You can then link to those from the JavaDocs.
72+
73+
74+
[code style]: dev/dans-intellij-codestyles.xml
75+
76+
[inspections]: dev/dans-intellij-inspections.xml
77+
78+
[dans-dev-scripts]: {{ dans_dev_scripts_repo }}
79+
80+
[Lombok]: https://projectlombok.org/
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<code_scheme name="dans-intellij-codestyles" version="173">
2+
<option name="RIGHT_MARGIN" value="1000" />
3+
<option name="FORMATTER_TAGS_ENABLED" value="true" />
4+
<DBN-PSQL>
5+
<case-options enabled="false">
6+
<option name="KEYWORD_CASE" value="lower" />
7+
<option name="FUNCTION_CASE" value="lower" />
8+
<option name="PARAMETER_CASE" value="lower" />
9+
<option name="DATATYPE_CASE" value="lower" />
10+
<option name="OBJECT_CASE" value="preserve" />
11+
</case-options>
12+
<formatting-settings enabled="false" />
13+
</DBN-PSQL>
14+
<DBN-SQL>
15+
<case-options enabled="false">
16+
<option name="KEYWORD_CASE" value="lower" />
17+
<option name="FUNCTION_CASE" value="lower" />
18+
<option name="PARAMETER_CASE" value="lower" />
19+
<option name="DATATYPE_CASE" value="lower" />
20+
<option name="OBJECT_CASE" value="preserve" />
21+
</case-options>
22+
<formatting-settings enabled="false">
23+
<option name="STATEMENT_SPACING" value="one_line" />
24+
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
25+
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
26+
</formatting-settings>
27+
</DBN-SQL>
28+
<JavaCodeStyleSettings>
29+
<option name="SPACE_AFTER_CLOSING_ANGLE_BRACKET_IN_TYPE_ARGUMENT" value="true" />
30+
<option name="ALIGN_MULTILINE_ANNOTATION_PARAMETERS" value="true" />
31+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
32+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
33+
<option name="JD_P_AT_EMPTY_LINES" value="false" />
34+
</JavaCodeStyleSettings>
35+
<ScalaCodeStyleSettings>
36+
<option name="ALIGN_IF_ELSE" value="true" />
37+
<option name="INDENT_BRACED_FUNCTION_ARGS" value="false" />
38+
<option name="USE_SCALADOC2_FORMATTING" value="false" />
39+
<option name="SPACES_IN_ONE_LINE_BLOCKS" value="true" />
40+
<option name="SPACES_IN_IMPORTS" value="true" />
41+
<option name="SPACES_AROUND_AT_IN_PATTERNS" value="true" />
42+
<option name="KEEP_XML_FORMATTING" value="true" />
43+
</ScalaCodeStyleSettings>
44+
<XML>
45+
<option name="XML_TEXT_WRAP" value="0" />
46+
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
47+
</XML>
48+
<yaml>
49+
<option name="SEQUENCE_ON_NEW_LINE" value="true" />
50+
<option name="AUTOINSERT_SEQUENCE_MARKER" value="false" />
51+
</yaml>
52+
<codeStyleSettings language="JAVA">
53+
<option name="RIGHT_MARGIN" value="200" />
54+
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
55+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
56+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
57+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
58+
<option name="KEEP_BLANK_LINES_BETWEEN_PACKAGE_DECLARATION_AND_HEADER" value="1" />
59+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
60+
<option name="BLANK_LINES_AFTER_ANONYMOUS_CLASS_HEADER" value="1" />
61+
<option name="ELSE_ON_NEW_LINE" value="true" />
62+
<option name="WHILE_ON_NEW_LINE" value="true" />
63+
<option name="CATCH_ON_NEW_LINE" value="true" />
64+
<option name="FINALLY_ON_NEW_LINE" value="true" />
65+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
66+
<option name="ALIGN_MULTILINE_RESOURCES" value="false" />
67+
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
68+
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
69+
<option name="CALL_PARAMETERS_WRAP" value="1" />
70+
<option name="METHOD_PARAMETERS_WRAP" value="1" />
71+
<option name="RESOURCE_LIST_WRAP" value="5" />
72+
<option name="EXTENDS_LIST_WRAP" value="1" />
73+
<option name="THROWS_LIST_WRAP" value="1" />
74+
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
75+
<option name="THROWS_KEYWORD_WRAP" value="1" />
76+
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
77+
<option name="BINARY_OPERATION_WRAP" value="1" />
78+
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
79+
<option name="TERNARY_OPERATION_WRAP" value="5" />
80+
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
81+
<option name="WRAP_COMMENTS" value="true" />
82+
<option name="VARIABLE_ANNOTATION_WRAP" value="2" />
83+
<indentOptions>
84+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
85+
</indentOptions>
86+
</codeStyleSettings>
87+
<codeStyleSettings language="Markdown">
88+
<option name="RIGHT_MARGIN" value="160" />
89+
</codeStyleSettings>
90+
<codeStyleSettings language="Scala">
91+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
92+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
93+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
94+
<option name="BLANK_LINES_AROUND_CLASS" value="0" />
95+
<option name="ELSE_ON_NEW_LINE" value="true" />
96+
<option name="METHOD_PARAMETERS_WRAP" value="1" />
97+
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
98+
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
99+
</codeStyleSettings>
100+
<codeStyleSettings language="XML">
101+
<option name="RIGHT_MARGIN" value="200" />
102+
</codeStyleSettings>
103+
<codeStyleSettings language="yaml">
104+
<option name="SOFT_MARGINS" value="200" />
105+
</codeStyleSettings>
106+
</code_scheme>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
3+
Copyright (C) 2018 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
-->
18+
<profile version="1.0">
19+
<option name="myName" value="dans-intellij-inspections" />
20+
<inspection_tool class="BashSimpleVarUsage" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
21+
<inspection_tool class="NonSerializableWithSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true" />
22+
<inspection_tool class="SerialVersionUIDNotStaticFinal" enabled="true" level="WARNING" enabled_by_default="true" />
23+
</profile>

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ nav:
4848
- Data Archive (SURF): data-archive.md
4949
- Development:
5050
- Overview: dev.md
51+
- Common practices: dev-common-practices.md
5152
- Build status: status.md
5253
plugins:
5354
- markdownextradata
@@ -94,6 +95,7 @@ extra:
9495
data_archive_url: https://www.surf.nl/diensten/opslag-datamanagement/data-archive
9596
surf_url: https://www.surf.nl/en
9697
ghm_registration_service_url: https://persistent-identifier.nl/gmh-registration-service/api/v1/openapi.yaml
98+
dans_dev_scripts_repo: https://github.com/DANS-KNAW/dans-dev-scripts
9799

98100
markdown_extensions:
99101
- attr_list

0 commit comments

Comments
 (0)