Skip to content

Commit 5d0b7aa

Browse files
committed
typo in MavenProps utility, constant GROUP_ID value is "gropupId" should be "groupId" #97
1 parent 4ad9d7a commit 5d0b7aa

File tree

3 files changed

+72
-12
lines changed

3 files changed

+72
-12
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +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+
1014
### Changed
1115

16+
- new method MavenProps.getPropertyOptional()
1217
- fj-bom version set to 2.0.2
1318

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+
1423
## [8.6.9] - 2025-04-27
1524

1625
### Changed
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
}

fj-core/src/test/java/test/org/fugerit/java/core/util/mvn/TestMavenProps.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66

77
import lombok.extern.slf4j.Slf4j;
88

9+
import java.util.Optional;
10+
911
@Slf4j
1012
class TestMavenProps {
1113

1214
@Test
1315
void testMavenOk() {
14-
String prop = MavenProps.getPropery( "org.fugerit.java", "fj-core", "artifactId" );
15-
log.info( "version {}", prop );
16-
Assertions.assertEquals( "fj-core" , prop );
16+
Optional prop = MavenProps.getPropertyOptional( "org.fugerit.java", "fj-core", "artifactId" );
17+
log.info( "version ok {}", prop.get() );
18+
Assertions.assertEquals( "fj-core" , prop.get() );
1719
}
1820

1921
@Test
2022
void testMavenKo() {
23+
// use deprecated method for coverage
2124
String prop = MavenProps.getPropery( "org.fugerit.java.no.exists", "fj-core", "artifactId" );
22-
log.info( "version {}", prop );
25+
log.info( "version ko {}", prop );
2326
Assertions.assertNull( prop );
2427
}
2528

0 commit comments

Comments
 (0)