Use build template

This commit is contained in:
2022-05-01 13:35:19 +00:00
parent 2c55d926c9
commit 9d2b4cd5ab
10 changed files with 464 additions and 48 deletions
+50 -15
View File
@@ -1,20 +1,55 @@
Create Application: before_script:
- source "/home/gitlab-runner/.sdkman/bin/sdkman-init.sh"
- sdk u java 11.0.12-open
stages:
- build
- test
- analysis
- publish
Build Application:
stage: build stage: build
script: script: ./gradlew --build-cache build
- chmod +x gradlew cache:
- ./gradlew build key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
Create Documentation: Create Documentation:
stage: build stage: build
script: script: ./gradlew asciidoctorPdf
- chmod +x gradlew
- ./gradlew asciidoctor
artifacts:
paths:
- build/docs/asciidocPdf/generations.pdf
Build Library: Test Application:
stage: build stage: test
script: script: ./gradlew check
- chmod +x gradlew cache:
- ./gradlew publish key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
sonarqube-check:
stage: analysis
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script: ./gradlew sonarqube
allow_failure: true
Publish Artifacts:
stage: publish
script: ./gradlew publish
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
+117 -33
View File
@@ -1,40 +1,75 @@
plugins { plugins {
id 'application'
id 'jacoco'
id 'checkstyle'
id 'pmd'
id "com.github.spotbugs" version "4.8.0"
id "org.sonarqube" version "3.3"
id 'org.asciidoctor.jvm.pdf' version '3.3.0' id 'org.asciidoctor.jvm.pdf' version '3.3.0'
id 'org.asciidoctor.jvm.gems' version '3.3.0' id 'org.asciidoctor.jvm.gems' version '3.3.0'
id 'java'
id 'maven-publish' id 'maven-publish'
} }
description = 'Anwendung Generations' repositories {
group = 'de.thpeetz.generations'
repositories {
jcenter() jcenter()
ruby.gems() ruby.gems()
mavenLocal()
mavenCentral()
maven { maven {
url "https://gitlab.thpeetz.de/api/v4/packages/maven" url "https://gitlab.thpeetz.de/api/v4/packages/maven"
name "GitLab" name "GitLab"
} }
} }
build.dependsOn(['asciidoctor'])
dependencies { dependencies {
asciidoctorGems 'rubygems:rouge:3.15.0' asciidoctorGems 'rubygems:rouge:3.15.0'
implementation 'org.slf4j:slf4j-api:1.7.22' implementation 'org.slf4j:slf4j-api:1.7.30'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.9.5' testImplementation 'org.mockito:mockito-all:1.9.5'
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
implementation 'ch.qos.logback:logback-core:1.2.6'
implementation 'ch.qos.logback:logback-classic:1.2.6'
} }
final BUILD_DATE = new Date().format('dd.MM.yyyy').toString()
def pdfFileEntwicklung = layout.buildDirectory.file("docs/asciidocPdf/Entwicklungshandbuch.pdf")
def pdfArtifactEntwicklung = artifacts.add('archives', pdfFileEntwicklung.get().asFile) {
type 'pdf'
builtBy asciidoctorPdf
}
def pdfFileProjekt = layout.buildDirectory.file("docs/asciidocPdf/Projekthandbuch.pdf")
def pdfArtifactProjekt = artifacts.add('archives', pdfFileProjekt.get().asFile) {
type 'pdf'
builtBy asciidoctorPdf
}
def pdfFilePflichtenheft = layout.buildDirectory.file("docs/asciidocPdf/Pflichtenheft.pdf")
def pdfArtifactPflichtenheft = artifacts.add('archives', pdfFilePflichtenheft.get().asFile) {
type 'pdf'
builtBy asciidoctorPdf
}
final MAIN_CLASS_NAME = 'com.thpeetz.versabundus.VersabundusApp'
publishing { publishing {
publications { publications {
library(MavenPublication) { mavenEntwicklung(MavenPublication) {
artifactId = "Entwicklungshandbuch"
artifact pdfArtifactEntwicklung
}
mavenProjekt(MavenPublication) {
artifactId = "Projekthandbuch"
artifact pdfArtifactProjekt
}
mavenPflichtenheft(MavenPublication) {
artifactId = "Pflichtenheft"
artifact pdfArtifactPflichtenheft
}
application(MavenPublication) {
from components.java from components.java
} }
} }
repositories { repositories {
maven { maven {
url "https://gitlab.thpeetz.de/api/v4/projects/27/packages/maven" url "https://gitlab.thpeetz.de/api/v4/projects/${projectId}/packages/maven"
credentials(HttpHeaderCredentials) { credentials(HttpHeaderCredentials) {
name = "Private-Token" name = "Private-Token"
value = gitLabPrivateToken value = gitLabPrivateToken
@@ -46,12 +81,8 @@ publishing {
} }
} }
final BUILD_DATE = new Date().format('dd.MM.yyyy').toString() application {
mainClassName = MAIN_CLASS_NAME
jar {
manifest {
attributes 'Implementation-Title': 'Generations', 'Implementation-Version': version
}
} }
java { java {
@@ -59,31 +90,84 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
jar {
manifest {
attributes('Implementation-Title': 'Versabundus Application', 'Implementation-Version': version, 'Main-Class': MAIN_CLASS_NAME)
}
}
tasks.named('test') {
useJUnitPlatform()
}
jacocoTestReport {
reports {
xml.enabled true
}
}
spotbugs {
ignoreFailures = false
showStackTraces = true
showProgress = true
effort = 'default'
reportLevel = 'default'
}
tasks.withType(Checkstyle) {
ignoreFailures = true
showViolations = false
reports {
xml.enabled true
}
}
pmd {
ignoreFailures = true
}
test.finalizedBy jacocoTestReport
sonarqube {
properties {
property "sonar.projectKey", "tpeetz_generations_AYB--ei2Uw4Nr911AV3u"
property "sonar.host.url", "https://sonar.thpeetz.de"
property "sonar.login", "92ff8e7c02747a905df2c49de874ce3db001bd37"
property "sonar.qualitygate.wait", true
property "sonar.sourceEncoding", "UTF-8"
}
}
tasks.named('sonarqube').configure {
dependsOn test
}
asciidoctorPdf { asciidoctorPdf {
dependsOn asciidoctorGemsPrepare dependsOn asciidoctorGemsPrepare
baseDirFollowsSourceFile() baseDirFollowsSourceFile()
asciidoctorj { asciidoctorj {
requires 'rouge' requires 'rouge'
attributes 'build-gradle': file('build.gradle'), attributes 'build-gradle': file('build.gradle'),
'endpoint-url': 'http://www.thpeetz.de', 'endpoint-url': 'https://www.thpeetz.de',
'source-highlighter': 'rouge', 'source-highlighter': 'rouge',
'revdate': BUILD_DATE, 'imagesdir': './images',
'revnumber': '1.0.0', 'toc': 'left',
'revremark': 'Entwurf', 'toc-title': 'Inhaltsverzeichnis',
'imagesdir': './images', 'revdate': BUILD_DATE,
'toc': 'left', 'revnumber': { project.version.toString() },
'toc-title': 'Inhaltsverzeichnis', 'revremark': 'Entwurf',
'chapter-label': '', 'chapter-label': '',
'icons': 'font', 'icons': 'font',
'idprefix': 'id_', 'idprefix': 'id_',
'idseparator': '-', 'idseparator': '-',
'docinfo1': '' 'docinfo1': ''
} }
} }
task asciidoctor(dependsOn: asciidoctorPdf) build.dependsOn(['asciidoctorPdf'])
build.dependsOn(['asciidoctor'])
wrapper { wrapper {
gradleVersion = "6.3" gradleVersion = "6.3"
+197
View File
@@ -0,0 +1,197 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the sun coding conventions from:
- the Java Language Specification at
https://docs.oracle.com/javase/specs/jls/se11/html/index.html
- the Sun Code Conventions at https://www.oracle.com/java/technologies/javase/codeconventions-contents.html
- the Javadoc guidelines at
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html
- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
- some best practices
Checkstyle is very configurable. Be sure to read the documentation at
https://checkstyle.org (or in your downloaded distribution).
Most Checks are configurable, be sure to consult the documentation.
To completely disable a check, just comment it out or delete it from the file.
To suppress certain violations please review suppression filters.
Finally, it is worth reading the documentation.
-->
<module name="Checker">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
https://checkstyle.org/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>
<!-- Checks that a package-info.java file exists for each package. -->
<!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage"/>
<!-- Checks whether files end with a new line. -->
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>
<!-- Checks that property files contain the same keys. -->
<!-- See https://checkstyle.org/config_misc.html#Translation -->
<module name="Translation"/>
<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="FileLength"/>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
</module>
<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="FileTabCharacter"/>
<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>
<!-- Checks for Headers -->
<!-- See https://checkstyle.org/config_header.html -->
<!-- <module name="Header"> -->
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
<!-- <property name="fileExtensions" value="java"/> -->
<!-- </module> -->
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See https://checkstyle.org/config_javadoc.html -->
<module name="InvalidJavadocPosition"/>
<module name="JavadocMethod"/>
<module name="JavadocType"/>
<module name="JavadocVariable"/>
<module name="JavadocStyle"/>
<module name="MissingJavadocMethod"/>
<!-- Checks for Naming Conventions. -->
<!-- See https://checkstyle.org/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>
<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<!-- Modifier Checks -->
<!-- See https://checkstyle.org/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See https://checkstyle.org/config_design.html -->
<module name="DesignForExtension"/>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="TodoComment"/>
<module name="UpperEll"/>
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" />
<property name="optional" value="true"/>
</module>
</module>
</module>
+4
View File
@@ -1 +1,5 @@
description = 'Anwendung Generations'
group=de.thpeetz.generations
version=1.0.0-SNAPSHOT version=1.0.0-SNAPSHOT
gitLabPrivateToken=bFcsw1ebNhoFgKysksU1
projectId=27
@@ -0,0 +1,33 @@
package de.thpeetz.generations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Example App class.
* @author tpeetz
*
*/
public class App {
/**
* Standard logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(App.class);
/**
* Returns greeting.
* @return greeting
*/
public String getGreeting() {
return "Hello world.";
}
/**
* Main entry point for application Generations.
* @param args Arguments
*/
public static void main(final String[] args) {
LOG.info("Greeting {}", new App().getGreeting());
}
}
@@ -0,0 +1,8 @@
/**
* Domain classes used to implement application Generations.
*
* @author Thomas Peetz
* @since 1.0.0
* @version 1.0.0
*/
package de.thpeetz.generations;
+11
View File
@@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
@@ -0,0 +1,36 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package de.thpeetz.generations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
class AppTest {
@Test
void appHasAGreeting() {
App classUnderTest = new App();
assertNotNull(classUnderTest.getGreeting(),
"app should have a greeting");
}
@Test
void checkGreeting() {
App classUnderTest = new App();
assertEquals("Hello world.", classUnderTest.getGreeting());
}
@Test
void checkMainWithoutArguments() {
try {
String[] args = {};
App.main(args);
} catch (Exception e) {
fail("Exception thrown");
}
}
}
@@ -0,0 +1,8 @@
/**
* Test classes for application Generations.
*
* @author Thomas Peetz
* @since 1.0.0
* @version 1.0.0
*/
package de.thpeetz.generations;