Compare commits

...

9 Commits

Author SHA1 Message Date
hummel 355fbdf042 Update Ignores 2025-05-20 19:41:56 +02:00
hummel 0d310adf01 add Surefire config in POM 2025-05-15 14:37:48 +02:00
hummel 129954d556 fix typo 2025-05-15 09:40:49 +02:00
hummel 4263c8c85c Fixe Log-Ausgabe und Laden von Resource-Dateien 2025-01-08 00:30:39 +01:00
hummel 3ee0bc95bd update PMD config in POM 2024-12-19 12:37:31 +01:00
hummel 6da1bde969 update plugin versions in POM 2024-12-16 07:01:44 +01:00
hummel 2cb172971a Gitea + Jenkins working? 2024-12-13 13:46:01 +01:00
hummel 241a7ddd2c fix broken build on Jenkins by updating PMD plugin
(also reconfigure shade plugin)
2024-12-13 10:23:29 +01:00
hummel 969f301be9 Add log4j logging example 2024-12-12 11:07:32 +01:00
11 changed files with 93 additions and 12 deletions

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/.DS_Store

1
MvnDemo/.gitignore vendored
View File

@ -2,3 +2,4 @@
/.DS_Store
/.classpath
/.project
/.settings

View File

@ -1,3 +0,0 @@
/org.eclipse.core.resources.prefs
/org.eclipse.jdt.core.prefs
/org.eclipse.m2e.core.prefs

View File

@ -26,6 +26,12 @@
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.2</version>
</dependency>
</dependencies>
<build>
@ -35,18 +41,38 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<!-- Testing -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/IntegrationTest.java</exclude>
</excludes>
<parallel>classes</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>
<!-- JAR creation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
@ -91,7 +117,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.22.0</version>
<version>3.26.0</version>
<configuration>
<failOnViolation>false</failOnViolation>
<printFailingErrors>true</printFailingErrors>
</configuration>
<executions>
<execution>
<phase>verify</phase>
@ -107,15 +137,13 @@
</build>
<reporting>
<plugins>
<!-- generate Javadocs via "mvn site" and find them in the site
folder-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.1</version>
<version>3.11.2</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
@ -125,7 +153,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<version>3.6.0</version>
</plugin>
</plugins>

1
MvnDemo/src/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/.DS_Store

1
MvnDemo/src/main/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/.DS_Store

View File

@ -1,14 +1,41 @@
package de.hs_mannheim.informatik.mvn;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Main {
// Aufruf mit externer Log-Config im gleichen Pfad wie das JAR:
// java -Dlog4j.configurationFile=log4j2.xml -jar MvnDemo-0.0.1-SNAPSHOT.jar
private static final Logger LOG = LogManager.getLogger(Main.class);
public static void main(String[] args) {
System.out.println("Hallo Maven!");
LOG.info("Hallo Log4J");
System.out.println("Hello!");
System.out.println(loadText("someText.txt"));
System.out.println(new Main().add(3, 4));
}
public int add(int a, int b) {
LOG.info("a = {}, b = {}", a, b);
return a + b;
}
public static String loadText(String filename) {
try (InputStream in = Main.class.getClassLoader().getResourceAsStream(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
return reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-config-2.xsd">
<Appenders>
<!-- Console appender configuration -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</Console>
</Appenders>
<Loggers>
<!-- Root logger referring to console appender -->
<Root level="INFO" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1 @@
Hallo Maven!

View File

@ -6,8 +6,13 @@ import org.junit.jupiter.api.Test;
class AddTest {
@Test
void test() {
void testAdd() {
assertEquals(7, new Main().add(3, 4));
}
@Test
void testLoader() {
assertEquals("Test Text", Main.loadText("test.txt"));
}
}

View File

@ -0,0 +1 @@
Test Text