Skip to content

97 bug typo in mavenprops utility constant group id value is gropupid should be groupid #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Deprecated

- MavenProps.getPropery() method. (flagged for removal in future versions)

### Changed

- new method MavenProps.getPropertyOptional()
- fj-bom version set to 2.0.2

### Fixed

- typo in MavenProps utility, constant GROUP_ID value is "gropupId" should be "groupId" <https://github.com/fugerit-org/fj-lib/issues/97>

## [8.6.9] - 2025-04-27

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.fugerit.java.core.util.mvn;

import java.util.Optional;

public class FJCoreMaven {

private FJCoreMaven() {}

public static final String FJ_CORE_GROUP_ID = "org.fugerit.java";

public static final String FJ_CORE_ARTIFACT_ID = "fj-core";

public static Optional<String> getFJCoreVersion() {
return MavenProps.getPropertyOptional( FJ_CORE_GROUP_ID, FJ_CORE_ARTIFACT_ID, MavenProps.VERSION );
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package org.fugerit.java.core.util.mvn;

import java.util.Optional;
import java.util.Properties;

import org.fugerit.java.core.util.PropsIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility class for loading Maven artifact metadata from the classpath.
* <p>
* This class provides access to standard Maven properties such as {@code groupId}, {@code artifactId},
* and {@code version}, as defined in the {@code pom.properties} file bundled with each artifact.
* </p>
*
* @since 8.7.0
*/
public class MavenProps {

private MavenProps() {}
Expand All @@ -14,27 +24,65 @@ private MavenProps() {}

public static final String VERSION = "version";

public static final String GROUP_ID = "gropupId";
public static final String GROUP_ID = "groupId";

public static final String ARTIFACT_ID = "artifactId";


/**
* @deprecated It is substituted by {@link #getProperty(String, String, String)} method.
* @since 8.7.0
*/
@Deprecated
public static String getPropery( String groupId, String artifactId, String propertyName ) {
return getProperty( groupId, artifactId, propertyName );
}

/**
* Loads the specified Maven property from the classpath.
*
* @param groupId the Maven groupId of the dependency
* @param artifactId the Maven artifactId of the dependency
* @param propertyName the name of the property to retrieve (e.g. {@code version})
* @return the property value, or {@code null} if not found
* @see #getPropertyOptional(String, String, String)
*/
public static String getProperty( String groupId, String artifactId, String propertyName ) {
return loadMavenProps(groupId, artifactId).getProperty( propertyName );
}

/**
* Loads the specified Maven property from the classpath and returns it as an {@link Optional}.
*
* @param groupId the Maven groupId of the dependency
* @param artifactId the Maven artifactId of the dependency
* @param propertyName the name of the property to retrieve (e.g. {@code version})
* @return an {@code Optional} containing the property value if found, or {@code Optional.empty()} otherwise
* @see #getProperty(String, String, String)
*/
public static Optional<String> getPropertyOptional(String groupId, String artifactId, String propertyName ) {
return Optional.ofNullable( loadMavenProps(groupId, artifactId).getProperty( propertyName ) );
}

private static final String SEP = "/";


/**
* Loads the {@code pom.properties} file for the specified Maven dependency from the classpath.
*
* @param groupId the Maven groupId of the dependency
* @param artifactId the Maven artifactId of the dependency
* @return a {@link Properties} object containing the loaded properties,
* or an empty {@code Properties} object if the file could not be found or loaded
*/
public static Properties loadMavenProps( String groupId, String artifactId ) {
Properties props = null;
try {
String path = "META-INF/maven/"+groupId+SEP+artifactId+"/pom.properties";
props = PropsIO.loadFromClassLoader( path );
String path = String.join(SEP, "META-INF", "maven", groupId, artifactId, "pom.properties");
Properties props = PropsIO.loadFromClassLoader( path );
logger.debug( "Maven Properties : {}", props );
return props;
} catch (Exception e) {
logger.warn( "Failed to load props : "+e, e );
props = new Properties();
return new Properties();
}
return props;
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
package test.org.fugerit.java.core.util.mvn;

import org.fugerit.java.core.util.mvn.FJCoreMaven;
import org.fugerit.java.core.util.mvn.MavenProps;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

@Slf4j
class TestMavenProps {

@Test
void testMavenOk() {
String prop = MavenProps.getPropery( "org.fugerit.java", "fj-core", "artifactId" );
log.info( "version {}", prop );
Assertions.assertEquals( "fj-core" , prop );
Optional prop = MavenProps.getPropertyOptional(FJCoreMaven.FJ_CORE_GROUP_ID, FJCoreMaven.FJ_CORE_ARTIFACT_ID, MavenProps.ARTIFACT_ID );
log.info( "version ok {}", prop.get() );
Assertions.assertEquals( "fj-core" , prop.get() );
}

@Test
void testMavenKo() {
String prop = MavenProps.getPropery( "org.fugerit.java.no.exists", "fj-core", "artifactId" );
log.info( "version {}", prop );
// use deprecated method for coverage
String prop = MavenProps.getPropery( "org.fugerit.java.no.exists", FJCoreMaven.FJ_CORE_ARTIFACT_ID, MavenProps.ARTIFACT_ID );
log.info( "version ko {}", prop );
Assertions.assertNull( prop );
}

@Test
void testFjCoreVersion() {
Optional fjCoreVersion = FJCoreMaven.getFJCoreVersion();
Assertions.assertTrue( fjCoreVersion.isPresent() );
log.info( "fjCoreVersion ok {}", fjCoreVersion.get() );
}

}