Skip to content

Commit 64a95a9

Browse files
authored
Merge pull request #98 from fugerit-org/97-bug-typo-in-mavenprops-utility-constant-group_id-value-is-gropupid-should-be-groupid
97 bug typo in mavenprops utility constant group id value is gropupid should be groupid
2 parents b5f108d + 7f06c61 commit 64a95a9

File tree

4 files changed

+102
-13
lines changed

4 files changed

+102
-13
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Deprecated
11+
12+
- MavenProps.getPropery() method. (flagged for removal in future versions)
13+
14+
### Changed
15+
16+
- new method MavenProps.getPropertyOptional()
17+
- fj-bom version set to 2.0.2
18+
19+
### Fixed
20+
21+
- typo in MavenProps utility, constant GROUP_ID value is "gropupId" should be "groupId" <https://github.com/fugerit-org/fj-lib/issues/97>
22+
1023
## [8.6.9] - 2025-04-27
1124

1225
### Changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.fugerit.java.core.util.mvn;
2+
3+
import java.util.Optional;
4+
5+
public class FJCoreMaven {
6+
7+
private FJCoreMaven() {}
8+
9+
public static final String FJ_CORE_GROUP_ID = "org.fugerit.java";
10+
11+
public static final String FJ_CORE_ARTIFACT_ID = "fj-core";
12+
13+
public static Optional<String> getFJCoreVersion() {
14+
return MavenProps.getPropertyOptional( FJ_CORE_GROUP_ID, FJ_CORE_ARTIFACT_ID, MavenProps.VERSION );
15+
}
16+
17+
}
Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
package org.fugerit.java.core.util.mvn;
22

3+
import java.util.Optional;
34
import java.util.Properties;
45

56
import org.fugerit.java.core.util.PropsIO;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
89

10+
/**
11+
* Utility class for loading Maven artifact metadata from the classpath.
12+
* <p>
13+
* This class provides access to standard Maven properties such as {@code groupId}, {@code artifactId},
14+
* and {@code version}, as defined in the {@code pom.properties} file bundled with each artifact.
15+
* </p>
16+
*
17+
* @since 8.7.0
18+
*/
919
public class MavenProps {
1020

1121
private MavenProps() {}
@@ -14,27 +24,65 @@ private MavenProps() {}
1424

1525
public static final String VERSION = "version";
1626

17-
public static final String GROUP_ID = "gropupId";
27+
public static final String GROUP_ID = "groupId";
1828

1929
public static final String ARTIFACT_ID = "artifactId";
20-
30+
31+
/**
32+
* @deprecated It is substituted by {@link #getProperty(String, String, String)} method.
33+
* @since 8.7.0
34+
*/
35+
@Deprecated
2136
public static String getPropery( String groupId, String artifactId, String propertyName ) {
37+
return getProperty( groupId, artifactId, propertyName );
38+
}
39+
40+
/**
41+
* Loads the specified Maven property from the classpath.
42+
*
43+
* @param groupId the Maven groupId of the dependency
44+
* @param artifactId the Maven artifactId of the dependency
45+
* @param propertyName the name of the property to retrieve (e.g. {@code version})
46+
* @return the property value, or {@code null} if not found
47+
* @see #getPropertyOptional(String, String, String)
48+
*/
49+
public static String getProperty( String groupId, String artifactId, String propertyName ) {
2250
return loadMavenProps(groupId, artifactId).getProperty( propertyName );
2351
}
52+
53+
/**
54+
* Loads the specified Maven property from the classpath and returns it as an {@link Optional}.
55+
*
56+
* @param groupId the Maven groupId of the dependency
57+
* @param artifactId the Maven artifactId of the dependency
58+
* @param propertyName the name of the property to retrieve (e.g. {@code version})
59+
* @return an {@code Optional} containing the property value if found, or {@code Optional.empty()} otherwise
60+
* @see #getProperty(String, String, String)
61+
*/
62+
public static Optional<String> getPropertyOptional(String groupId, String artifactId, String propertyName ) {
63+
return Optional.ofNullable( loadMavenProps(groupId, artifactId).getProperty( propertyName ) );
64+
}
2465

2566
private static final String SEP = "/";
26-
67+
68+
/**
69+
* Loads the {@code pom.properties} file for the specified Maven dependency from the classpath.
70+
*
71+
* @param groupId the Maven groupId of the dependency
72+
* @param artifactId the Maven artifactId of the dependency
73+
* @return a {@link Properties} object containing the loaded properties,
74+
* or an empty {@code Properties} object if the file could not be found or loaded
75+
*/
2776
public static Properties loadMavenProps( String groupId, String artifactId ) {
28-
Properties props = null;
2977
try {
30-
String path = "META-INF/maven/"+groupId+SEP+artifactId+"/pom.properties";
31-
props = PropsIO.loadFromClassLoader( path );
78+
String path = String.join(SEP, "META-INF", "maven", groupId, artifactId, "pom.properties");
79+
Properties props = PropsIO.loadFromClassLoader( path );
3280
logger.debug( "Maven Properties : {}", props );
81+
return props;
3382
} catch (Exception e) {
3483
logger.warn( "Failed to load props : "+e, e );
35-
props = new Properties();
84+
return new Properties();
3685
}
37-
return props;
3886
}
3987

4088
}
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
package test.org.fugerit.java.core.util.mvn;
22

3+
import org.fugerit.java.core.util.mvn.FJCoreMaven;
34
import org.fugerit.java.core.util.mvn.MavenProps;
45
import org.junit.jupiter.api.Assertions;
56
import org.junit.jupiter.api.Test;
67

78
import lombok.extern.slf4j.Slf4j;
89

10+
import java.util.Optional;
11+
912
@Slf4j
1013
class TestMavenProps {
1114

1215
@Test
1316
void testMavenOk() {
14-
String prop = MavenProps.getPropery( "org.fugerit.java", "fj-core", "artifactId" );
15-
log.info( "version {}", prop );
16-
Assertions.assertEquals( "fj-core" , prop );
17+
Optional prop = MavenProps.getPropertyOptional(FJCoreMaven.FJ_CORE_GROUP_ID, FJCoreMaven.FJ_CORE_ARTIFACT_ID, MavenProps.ARTIFACT_ID );
18+
log.info( "version ok {}", prop.get() );
19+
Assertions.assertEquals( "fj-core" , prop.get() );
1720
}
1821

1922
@Test
2023
void testMavenKo() {
21-
String prop = MavenProps.getPropery( "org.fugerit.java.no.exists", "fj-core", "artifactId" );
22-
log.info( "version {}", prop );
24+
// use deprecated method for coverage
25+
String prop = MavenProps.getPropery( "org.fugerit.java.no.exists", FJCoreMaven.FJ_CORE_ARTIFACT_ID, MavenProps.ARTIFACT_ID );
26+
log.info( "version ko {}", prop );
2327
Assertions.assertNull( prop );
2428
}
29+
30+
@Test
31+
void testFjCoreVersion() {
32+
Optional fjCoreVersion = FJCoreMaven.getFJCoreVersion();
33+
Assertions.assertTrue( fjCoreVersion.isPresent() );
34+
log.info( "fjCoreVersion ok {}", fjCoreVersion.get() );
35+
}
2536

2637
}

0 commit comments

Comments
 (0)