Skip to content
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
73 changes: 73 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CI/CD Pipeline

on:
push:
branches:
- '**' # Runs for all branches
workflow_dispatch:

jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/master' # Runs on all branches except master
permissions:
contents: read

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Java 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'

- name: Make Maven wrapper executable
run: chmod +x mvnw

- name: Build and Run Tests
run: ./mvnw --no-transfer-progress clean verify

- if: ${{ github.ref == 'refs/heads/master' }}
name: Publish to GitHub Packages Apache Maven
run: ./mvnw deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

deploy:
name: Build, Test & Deploy
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' # Runs only on master
permissions:
contents: read
packages: write # Needed to publish to GitHub Packages

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
cache: 'maven'

- name: Build and Deploy to GitHub Packages
run: ./mvnw --no-transfer-progress clean deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSION }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

12 changes: 12 additions & 0 deletions .run/All Unit Tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Unit Tests" type="JUnit" factoryName="JUnit">
<module name="am-commons-utils" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="tags" />
<tag value="unit" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
100 changes: 74 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.amalvadkar</groupId>
<artifactId>am-commons-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>am-commons-utils</name>
<description>Common Utilities</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<description>Common Utility Library</description>

<properties>
<!-- Dependency versions -->
<java.version>21</java.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<assertj-core.version>3.25.3</assertj-core.version>

<!-- Plugin versions -->
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
</properties>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/abhishekmalvadkar/${project.artifactId}</url>
</repository>
</distributionManagement>


<dependencies>
<!-- JUnit 5 API for writing tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

<!-- JUnit 5 Engine for running tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

<!-- AssertJ for fluent assertions -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Compiler Plugin to Ensure Java 21 Compatibility -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<!-- JAR Plugin for Packaging the Library -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>

<!-- Surefire Plugin for Running JUnit 5 Tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</plugin>

<!-- Deploy Plugin for GitHub Packages -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
</plugin>
</plugins>
</build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.amalvadkar.commons.utils.constants;

public class StringConstants {

public static final String EMPTY_STRING = "";

private StringConstants() {
throw new UnsupportedOperationException("Constants class");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.amalvadkar.commons.utils.exceptions;

/**
* Custom exception for invalid string operations.
*/
public class InvalidStringException extends RuntimeException {
public InvalidStringException(String message) {
super(message);
}
}
71 changes: 71 additions & 0 deletions src/main/java/com/amalvadkar/commons/utils/string/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.amalvadkar.commons.utils.string;

import com.amalvadkar.commons.utils.constants.StringConstants;
import com.amalvadkar.commons.utils.exceptions.InvalidStringException;

/**
* Utility class for common string operations.
*/
public final class StringUtils {

private StringUtils() {
throw new UnsupportedOperationException("Utility class");
}

/**
* Capitalizes the first letter of the input string.
*
* @param input The string to capitalize.
* @return Capitalized string or an empty string if input is null/empty.
* @throws InvalidStringException if the input is null or empty.
*/
public static String capitalize(String input) {
if (isEmpty(input)) {
throw new InvalidStringException("Input string cannot be null or empty.");
}
return input.substring(0, 1).toUpperCase() + input.substring(1);
}

/**
* Checks if a string is null or empty.
*
* @param input The string to check.
* @return True if the string is null or empty, otherwise false.
*/
public static boolean isEmpty(String input) {
return input == null || input.trim().isEmpty();
}

/**
* Reverses a given string.
*
* @param input The string to reverse.
* @return The reversed string.
*/
public static String reverse(String input) {
if (isEmpty(input)) {
return StringConstants.EMPTY_STRING;
}
return new StringBuilder(input).reverse().toString();
}

/**
* Trims spaces from both ends of the string.
*
* @param input The string to trim.
* @return The trimmed string.
*/
public static String trim(String input) {
return isEmpty(input) ? StringConstants.EMPTY_STRING : input.trim();
}

/**
* Checks if a string contains only letters.
*
* @param input The string to check.
* @return True if the string contains only letters, otherwise false.
*/
public static boolean containsOnlyLetters(String input) {
return !isEmpty(input) && input.matches("[a-zA-Z]+");
}
}
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

This file was deleted.

Loading
Loading