Skip to content

Commit ed42746

Browse files
SeunMattmaibin
authored andcommitted
added example code for BAEL-2487 (eugenp#6383)
* added example code for BAEL-2366 * moved example code for BAEL-2366 * example code for BAEL-1961 * moved example code into integration test * updated the test assertions * refactor the spring boot persistence mongodb module * remove redundant example code * declared the spring boot persistence module in the root pom * fixed issue with non-imported file * added example code for BAEL-2418 * added example code for BAEL-2549 * added example code for BAEL-2487 * refactor the maven module * updated the example code * updated the example code * updated the pom files * updated the pom files for verifier plugin
1 parent 326bfbe commit ed42746

5 files changed

Lines changed: 194 additions & 3 deletions

File tree

‎maven/.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/output-resources
1+
/output-resources
2+
/.idea/

‎maven/custom-rule/pom.xml‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>maven</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<artifactId>custom-rule</artifactId>
12+
13+
<properties>
14+
<api.version>3.0.0-M2</api.version>
15+
<maven.version>2.0.9</maven.version>
16+
</properties>
17+
18+
19+
<dependencies>
20+
<!-- dependencies for maven plugin-->
21+
<dependency>
22+
<groupId>org.apache.maven.enforcer</groupId>
23+
<artifactId>enforcer-api</artifactId>
24+
<version>${api.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.maven</groupId>
28+
<artifactId>maven-project</artifactId>
29+
<version>${maven.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.apache.maven</groupId>
33+
<artifactId>maven-core</artifactId>
34+
<version>${maven.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.maven</groupId>
38+
<artifactId>maven-artifact</artifactId>
39+
<version>${maven.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.maven</groupId>
43+
<artifactId>maven-plugin-api</artifactId>
44+
<version>${maven.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.codehaus.plexus</groupId>
48+
<artifactId>plexus-container-default</artifactId>
49+
<version>1.0-alpha-9</version>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<artifactId>maven-verifier-plugin</artifactId>
57+
<version>${maven.verifier.version}</version>
58+
<configuration>
59+
<verificationFile>../input-resources/verifications.xml</verificationFile>
60+
<failOnError>false</failOnError>
61+
</configuration>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
67+
68+
69+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2019 PloyRef
3+
* Created by Seun Matt <smatt382@gmail.com>
4+
* on 19 - 2 - 2019
5+
*/
6+
7+
package com.baeldung.enforcer;
8+
9+
import org.apache.maven.enforcer.rule.api.EnforcerRule;
10+
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
11+
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
12+
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
13+
14+
public class MyCustomRule implements EnforcerRule {
15+
16+
public void execute(EnforcerRuleHelper enforcerRuleHelper) throws EnforcerRuleException {
17+
18+
try {
19+
20+
String groupId = (String) enforcerRuleHelper.evaluate("${project.groupId}");
21+
22+
if (groupId == null || !groupId.startsWith("org.baeldung")) {
23+
throw new EnforcerRuleException("Project group id does not start with org.baeldung");
24+
}
25+
26+
}
27+
catch (ExpressionEvaluationException ex ) {
28+
throw new EnforcerRuleException( "Unable to lookup an expression " + ex.getLocalizedMessage(), ex );
29+
}
30+
}
31+
32+
public boolean isCacheable() {
33+
return false;
34+
}
35+
36+
public boolean isResultValid(EnforcerRule enforcerRule) {
37+
return false;
38+
}
39+
40+
public String getCacheId() {
41+
return null;
42+
}
43+
}

‎maven/maven-enforcer/pom.xml‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>maven</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<artifactId>maven-enforcer</artifactId>
12+
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.apache.maven.plugins</groupId>
17+
<artifactId>maven-enforcer-plugin</artifactId>
18+
<version>3.0.0-M2</version>
19+
<!--<dependencies>-->
20+
<!--<dependency>-->
21+
<!--<groupId>com.baeldung</groupId>-->
22+
<!--<artifactId>custom-rule</artifactId>-->
23+
<!--<version>1.0</version>-->
24+
<!--</dependency>-->
25+
<!--</dependencies>-->
26+
<executions>
27+
<execution>
28+
<id>enforce</id>
29+
<goals>
30+
<goal>enforce</goal>
31+
</goals>
32+
<configuration>
33+
<rules>
34+
<banDuplicatePomDependencyVersions/>
35+
<requireMavenVersion>
36+
<version>3.0</version>
37+
<message>Invalid Maven version. It should, at least, be 3.0</message>
38+
</requireMavenVersion>
39+
<requireJavaVersion>
40+
<version>1.8</version>
41+
</requireJavaVersion>
42+
<requireEnvironmentVariable>
43+
<variableName>ui</variableName>
44+
<level>WARN</level>
45+
</requireEnvironmentVariable>
46+
<requireEnvironmentVariable>
47+
<variableName>cook</variableName>
48+
<level>WARN</level>
49+
</requireEnvironmentVariable>
50+
<requireActiveProfile>
51+
<profiles>local,base</profiles>
52+
<message>Missing active profiles</message>
53+
<level>WARN</level>
54+
</requireActiveProfile>
55+
<!--other rules -->
56+
<!--<myCustomRule implementation="com.baeldung.enforcer.MyCustomRule"/>-->
57+
</rules>
58+
</configuration>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
<plugin>
63+
<artifactId>maven-verifier-plugin</artifactId>
64+
<version>${maven.verifier.version}</version>
65+
<configuration>
66+
<verificationFile>../input-resources/verifications.xml</verificationFile>
67+
<failOnError>false</failOnError>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
74+
</project>

‎maven/pom.xml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
<groupId>com.baeldung</groupId>
55
<artifactId>maven</artifactId>
66
<version>0.0.1-SNAPSHOT</version>
7-
<name>maven</name>
8-
<packaging>war</packaging>
7+
<modules>
8+
<module>custom-rule</module>
9+
<module>maven-enforcer</module>
10+
</modules>
11+
<name>maven</name>
12+
<packaging>pom</packaging>
913

1014
<dependencies>
1115
<dependency>

0 commit comments

Comments
 (0)