Skip to content

Commit 3f37cf8

Browse files
Merge pull request #2 from abhishekmalvadkar/GH-1_create-and-setup-initial-common-utility-java-library
GH-1 : Create and setup initial common utility java library
2 parents 3bfd50c + 5833961 commit 3f37cf8

File tree

11 files changed

+317
-53
lines changed

11 files changed

+317
-53
lines changed

.github/workflows/ci-cd.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- '**' # Runs for all branches
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
name: Build & Test
12+
runs-on: ubuntu-latest
13+
if: github.ref != 'refs/heads/master' # Runs on all branches except master
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Java 21
22+
uses: actions/setup-java@v4
23+
with:
24+
java-version: '21'
25+
distribution: 'temurin'
26+
cache: 'maven'
27+
28+
- name: Make Maven wrapper executable
29+
run: chmod +x mvnw
30+
31+
- name: Build and Run Tests
32+
run: ./mvnw --no-transfer-progress clean verify
33+
34+
- if: ${{ github.ref == 'refs/heads/master' }}
35+
name: Publish to GitHub Packages Apache Maven
36+
run: ./mvnw deploy -s $GITHUB_WORKSPACE/settings.xml
37+
env:
38+
GITHUB_TOKEN: ${{ github.token }}
39+
40+
deploy:
41+
name: Build, Test & Deploy
42+
runs-on: ubuntu-latest
43+
if: github.ref == 'refs/heads/master' # Runs only on master
44+
permissions:
45+
contents: read
46+
packages: write # Needed to publish to GitHub Packages
47+
48+
steps:
49+
- name: Checkout Repository
50+
uses: actions/checkout@v4
51+
52+
- name: Setup Java
53+
uses: actions/setup-java@v4
54+
with:
55+
java-version: '21'
56+
distribution: 'temurin'
57+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
58+
settings-path: ${{ github.workspace }} # location for the settings.xml file
59+
cache: 'maven'
60+
61+
- name: Build and Deploy to GitHub Packages
62+
run: ./mvnw --no-transfer-progress clean deploy -s $GITHUB_WORKSPACE/settings.xml
63+
env:
64+
GITHUB_TOKEN: ${{ github.token }}
65+
66+
- name: Create GitHub Release
67+
uses: softprops/action-gh-release@v2
68+
with:
69+
tag_name: ${{ env.VERSION }}
70+
generate_release_notes: true
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+

.run/All Unit Tests.run.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="All Unit Tests" type="JUnit" factoryName="JUnit">
3+
<module name="am-commons-utils" />
4+
<option name="MAIN_CLASS_NAME" value="" />
5+
<option name="METHOD_NAME" value="" />
6+
<option name="TEST_OBJECT" value="tags" />
7+
<tag value="unit" />
8+
<method v="2">
9+
<option name="Make" enabled="true" />
10+
</method>
11+
</configuration>
12+
</component>

pom.xml

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,99 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>org.springframework.boot</groupId>
7-
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.4.3</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10-
</parent>
5+
116
<groupId>com.amalvadkar</groupId>
127
<artifactId>am-commons-utils</artifactId>
138
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
1410
<name>am-commons-utils</name>
15-
<description>Common Utilities</description>
16-
<url/>
17-
<licenses>
18-
<license/>
19-
</licenses>
20-
<developers>
21-
<developer/>
22-
</developers>
23-
<scm>
24-
<connection/>
25-
<developerConnection/>
26-
<tag/>
27-
<url/>
28-
</scm>
11+
<description>Common Utility Library</description>
12+
2913
<properties>
14+
<!-- Dependency versions -->
3015
<java.version>21</java.version>
16+
<junit-jupiter.version>5.10.2</junit-jupiter.version>
17+
<assertj-core.version>3.25.3</assertj-core.version>
18+
19+
<!-- Plugin versions -->
20+
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
21+
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
22+
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
23+
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
3124
</properties>
25+
26+
<distributionManagement>
27+
<repository>
28+
<id>github</id>
29+
<name>GitHub Packages</name>
30+
<url>https://maven.pkg.github.com/abhishekmalvadkar/${project.artifactId}</url>
31+
</repository>
32+
</distributionManagement>
33+
34+
3235
<dependencies>
36+
<!-- JUnit 5 API for writing tests -->
3337
<dependency>
34-
<groupId>org.springframework.boot</groupId>
35-
<artifactId>spring-boot-starter</artifactId>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter-api</artifactId>
40+
<version>${junit-jupiter.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
44+
<!-- JUnit 5 Engine for running tests -->
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-engine</artifactId>
48+
<version>${junit-jupiter.version}</version>
49+
<scope>test</scope>
3650
</dependency>
3751

52+
<!-- AssertJ for fluent assertions -->
3853
<dependency>
39-
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-test</artifactId>
54+
<groupId>org.assertj</groupId>
55+
<artifactId>assertj-core</artifactId>
56+
<version>${assertj-core.version}</version>
4157
<scope>test</scope>
4258
</dependency>
59+
4360
</dependencies>
4461

4562
<build>
63+
<finalName>${project.artifactId}</finalName>
4664
<plugins>
65+
<!-- Compiler Plugin to Ensure Java 21 Compatibility -->
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-compiler-plugin</artifactId>
69+
<version>${maven-compiler-plugin.version}</version>
70+
<configuration>
71+
<source>${java.version}</source>
72+
<target>${java.version}</target>
73+
</configuration>
74+
</plugin>
75+
76+
<!-- JAR Plugin for Packaging the Library -->
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-jar-plugin</artifactId>
80+
<version>${maven-jar-plugin.version}</version>
81+
</plugin>
82+
83+
<!-- Surefire Plugin for Running JUnit 5 Tests -->
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-surefire-plugin</artifactId>
87+
<version>${maven-surefire-plugin.version}</version>
88+
<configuration>
89+
<useModulePath>false</useModulePath>
90+
</configuration>
91+
</plugin>
92+
93+
<!-- Deploy Plugin for GitHub Packages -->
4794
<plugin>
48-
<groupId>org.springframework.boot</groupId>
49-
<artifactId>spring-boot-maven-plugin</artifactId>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-deploy-plugin</artifactId>
97+
<version>${maven-deploy-plugin.version}</version>
5098
</plugin>
5199
</plugins>
52100
</build>

src/main/java/com/amalvadkar/commons/utils/AmCommonsUtilsApplication.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.amalvadkar.commons.utils.constants;
2+
3+
public class StringConstants {
4+
5+
public static final String EMPTY_STRING = "";
6+
7+
private StringConstants() {
8+
throw new UnsupportedOperationException("Constants class");
9+
}
10+
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.amalvadkar.commons.utils.exceptions;
2+
3+
/**
4+
* Custom exception for invalid string operations.
5+
*/
6+
public class InvalidStringException extends RuntimeException {
7+
public InvalidStringException(String message) {
8+
super(message);
9+
}
10+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.amalvadkar.commons.utils.string;
2+
3+
import com.amalvadkar.commons.utils.constants.StringConstants;
4+
import com.amalvadkar.commons.utils.exceptions.InvalidStringException;
5+
6+
/**
7+
* Utility class for common string operations.
8+
*/
9+
public final class StringUtils {
10+
11+
private StringUtils() {
12+
throw new UnsupportedOperationException("Utility class");
13+
}
14+
15+
/**
16+
* Capitalizes the first letter of the input string.
17+
*
18+
* @param input The string to capitalize.
19+
* @return Capitalized string or an empty string if input is null/empty.
20+
* @throws InvalidStringException if the input is null or empty.
21+
*/
22+
public static String capitalize(String input) {
23+
if (isEmpty(input)) {
24+
throw new InvalidStringException("Input string cannot be null or empty.");
25+
}
26+
return input.substring(0, 1).toUpperCase() + input.substring(1);
27+
}
28+
29+
/**
30+
* Checks if a string is null or empty.
31+
*
32+
* @param input The string to check.
33+
* @return True if the string is null or empty, otherwise false.
34+
*/
35+
public static boolean isEmpty(String input) {
36+
return input == null || input.trim().isEmpty();
37+
}
38+
39+
/**
40+
* Reverses a given string.
41+
*
42+
* @param input The string to reverse.
43+
* @return The reversed string.
44+
*/
45+
public static String reverse(String input) {
46+
if (isEmpty(input)) {
47+
return StringConstants.EMPTY_STRING;
48+
}
49+
return new StringBuilder(input).reverse().toString();
50+
}
51+
52+
/**
53+
* Trims spaces from both ends of the string.
54+
*
55+
* @param input The string to trim.
56+
* @return The trimmed string.
57+
*/
58+
public static String trim(String input) {
59+
return isEmpty(input) ? StringConstants.EMPTY_STRING : input.trim();
60+
}
61+
62+
/**
63+
* Checks if a string contains only letters.
64+
*
65+
* @param input The string to check.
66+
* @return True if the string contains only letters, otherwise false.
67+
*/
68+
public static boolean containsOnlyLetters(String input) {
69+
return !isEmpty(input) && input.matches("[a-zA-Z]+");
70+
}
71+
}

src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/java/com/amalvadkar/commons/utils/AmCommonsUtilsApplicationTests.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)