Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e44b30e
Optimized Utils.name() to reduce number of String objects created
r0goyal Apr 14, 2025
5533039
Reduced number of iterations in HomePageControllerTest
r0goyal Apr 14, 2025
8d0ec06
Replaced String.format() with varargs
r0goyal Apr 14, 2025
63e19fa
Reverted build.yml changes
r0goyal Apr 15, 2025
b867a82
Separated out jacoco coverage report task
r0goyal Apr 15, 2025
5bb6d1a
Made Map static
r0goyal Apr 15, 2025
84b6367
Upgraded cache action version since v1 is now removed
r0goyal Apr 15, 2025
f32c901
Dummy
r0goyal Apr 15, 2025
049b24b
Optimized trace log line
r0goyal Apr 15, 2025
b1c2724
Changed String.format() everywhere
r0goyal Apr 15, 2025
2424d6d
Changed Collections.synchronizedSet() to normal HashSet<>()
r0goyal Apr 15, 2025
e81cc7a
Changed ConcurrentHashMap to Map in definition. Moved to release version
r0goyal Apr 16, 2025
5a72d4c
Added method to remove from DataSet
r0goyal Apr 17, 2025
72ed696
Moved all write operations through a single lock method
r0goyal Apr 17, 2025
3be93c5
Added method to remove data from DataSet
r0goyal Apr 17, 2025
e438479
Moved to release version
r0goyal Apr 17, 2025
f187eeb
Fixed node ranking
r0goyal Apr 18, 2025
46ade13
Fixed ranking infinite loop issue
r0goyal Apr 18, 2025
b874747
Disabled sonar for testing purposes
r0goyal Apr 18, 2025
cd57ccf
Disabled sonar for testing purposes
r0goyal Apr 18, 2025
515aef4
Disabled sonar for testing purposes
r0goyal Apr 18, 2025
2e3fb20
Slight changes in jacoco plugin
r0goyal Apr 18, 2025
7a9fd2c
Slight changes in jacoco plugin
r0goyal Apr 18, 2025
7c9680b
Update build.yml
santanusinha Apr 19, 2025
6ae59fa
Updated pom version
r0goyal Apr 19, 2025
2fd9332
Removed unnecessary method
r0goyal Apr 19, 2025
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
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: SonarQube
on:
push:
branches:
Expand All @@ -7,30 +7,30 @@ on:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=appform-io_databuilderframework
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=appform-io_databuilderframework
53 changes: 53 additions & 0 deletions .github/workflows/jacoco-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: JaCoCo Coverage
on:
pull_request:
branches: [ master ] # Adjust branches as needed

permissions:
# Required for checking out the code
contents: read
# Required for posting comments and status checks
pull-requests: write
# Required for reading report files
actions: read # Optional, often implicitly available

jobs:
build-and-report:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: 11 # Or your project's Java version
distribution: temurin

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify

- name: Check for JaCoCo Report File
run: |
echo "Searching for JaCoCo reports..."
find ${{ github.workspace }} -name 'jacoco*.xml' # General search
echo "--- Listing Maven default ---"
ls -l ${{ github.workspace }}/target/site/jacoco/jacoco.xml || echo "Maven default not found"
# --- Coverage Reporting Step ---
- name: JaCoCo Report to PR Comment
id: jacoco
uses: madrapps/jacoco-report@v1.7.1 # Use the latest version
with:
paths: |
${{ github.workspace }}/**/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 95 # Example value
min-coverage-changed-files: 95 # Example value
update-comment: true
title: "📊 JaCoCo Code Coverage"
37 changes: 18 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<groupId>io.appform.databuilderframework</groupId>
<version>1.1.0</version>
<version>1.1.1</version>
<modelVersion>4.0.0</modelVersion>

<artifactId>databuilderframework</artifactId>
Expand Down Expand Up @@ -68,6 +68,11 @@
<name>Vinay Varma</name>
<email>vinay.varma@flipkart.com</email>
</developer>
<developer>
<id>r0goyal</id>
<name>Rishabh Goyal</name>
<email>rgoyal2191@gmail.com</email>
</developer>
</developers>

<ciManagement>
Expand All @@ -78,8 +83,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jackson.version>2.13.1</jackson.version>
<lombok.version>1.18.22</lombok.version>
<lombok.maven.version>1.16.6.1</lombok.maven.version>
<lombok.version>1.18.30</lombok.version>
<hibernate.validator.version>5.2.5.Final</hibernate.validator.version>
<junit.version>4.13.2</junit.version>
<logback.version>1.2.10</logback.version>
Expand Down Expand Up @@ -137,21 +141,14 @@
<build>
<plugins>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<version>${lombok.maven.version}</version>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>5.1.0.4751</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -160,24 +157,26 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<version>0.8.13</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public DataContainer call() throws Exception {
executePostListenersSuccess(response);
if (null != response) {
Preconditions.checkArgument(response.getData().equalsIgnoreCase(builderMeta.getProduces()),
String.format("Builder is supposed to produce %s but produces %s",
builderMeta.getProduces(), response.getData()));
"Builder is supposed to produce %s but produces %s",
builderMeta.getProduces(), response.getData());
response.setGeneratedBy(builderMeta.getName());
}
return new DataContainer(builderMeta, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public <T extends Data> T get(Class<T> tClass) {
public <T extends Data> T get(String key, Class<T> tClass) {
val data = dataSet.get(key);
return null == data
? null
: tClass.cast(data);
? null
: tClass.cast(data);
}

/**
Expand All @@ -53,9 +53,9 @@ public <T extends Data> T get(String key, Class<T> tClass) {
*/
public <B extends DataBuilder, T extends Data> T getAccessibleData(String key, B builder, Class<T> tClass) {
Preconditions.checkArgument(!builder.getDataBuilderMeta().getAccessibleDataSet().contains(key),
String.format("Builder %s can access only %s",
builder.getDataBuilderMeta().getName(),
builder.getDataBuilderMeta().getConsumes()));
"Builder %s can access only %s",
builder.getDataBuilderMeta().getName(),
builder.getDataBuilderMeta().getConsumes());
return get(key, tClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ private int rankNodes(DependencyNode root, int currentNode, Set<String> processe
}

val childNode = currentNode + 1;
return root.getIncoming()
val ret = root.getIncoming()
.stream()
.mapToInt(child -> Math.max(rankNodes(child, childNode, processedNodes), childNode))
.max()
.orElse(childNode);
processedNodes.add(data);
return ret;
}

private DependencyNode generateDependencyTree(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ protected DataExecutionResponse run(
}
if (null != response) {
Preconditions.checkArgument(response.getData().equalsIgnoreCase(data),
String.format(
"Builder is supposed to produce %s but produces %s",
data,
response.getData()));
response.getData());
dataSetAccessor.merge(response);
responseData.put(response.getData(), response);
activeDataSet.add(response.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ protected DataExecutionResponse run(
}
if (null != response) {
Preconditions.checkArgument(response.getData().equalsIgnoreCase(data),
String.format(
"Builder is supposed to produce %s but produces %s",
data,
response.getData()));
response.getData());
dataSetAccessor.merge(response);
responseData.put(response.getData(), response);
activeDataSet.add(response.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Supplier;

/**
* The executor for a {@link io.appform.databuilderframework.model.DataFlow}.
Expand Down Expand Up @@ -42,7 +43,7 @@ protected DataExecutionResponse run(
val activeDataSet = new HashSet<String>();
val dependencyHierarchy = executionGraph.getDependencyHierarchy();
val newlyGeneratedData = new HashSet<String>();
val processedBuilders = Collections.synchronizedSet(new HashSet<DataBuilderMeta>());
val processedBuilders = new HashSet<DataBuilderMeta>();

dataSetAccessor.merge(dataDelta);
dataDelta.getDelta().forEach(data -> activeDataSet.add(data.getData()));
Expand Down Expand Up @@ -80,10 +81,9 @@ protected DataExecutionResponse run(
dataSet.accessor().getAccesibleDataSetFor(builder)));
if (null != response) {
Preconditions.checkArgument(response.getData().equalsIgnoreCase(builderMeta.getProduces()),
String.format(
"Builder is supposed to produce %s but produces %s",
builderMeta.getProduces(),
response.getData()));
"Builder is supposed to produce %s but produces %s",
builderMeta.getProduces(),
response.getData());
dataSetAccessor.merge(response);
responseData.put(response.getData(), response);
response.setGeneratedBy(builderMeta.getName());
Expand All @@ -93,7 +93,7 @@ protected DataExecutionResponse run(
newlyGeneratedData.add(response.getData());
}
}
log.trace("Ran " + builderMeta.getName());
log.trace("Ran {}", builderMeta.getName());
processedBuilders.add(builderMeta);
for (DataBuilderExecutionListener listener : dataBuilderExecutionListener) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.appform.databuilderframework.model.DataBuilderMeta;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ConcurrentHashMap;

import java.util.*;

Expand All @@ -20,12 +21,15 @@
@Slf4j
public final class Utils {

private static final Map<Class<?>, String> CLASS_TO_NAME_MAPPING = new ConcurrentHashMap<>();

public static String name(Object object) {
return name(object.getClass());
}

public static String name(Class<?> clazz) {
return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, clazz.getSimpleName());
return CLASS_TO_NAME_MAPPING.computeIfAbsent(clazz,
aClass -> CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, clazz.getSimpleName()));
}

public static<T> boolean isEmpty(Collection<T> collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public void register(DataBuilder dataBuilder) {

public DataBuilder create(DataBuilderMeta dataBuilderMeta) throws DataBuilderFrameworkException {
val builderName = dataBuilderMeta.getName();
if (builderInstances.containsKey(builderName)) {
return builderInstances.get(builderName);
val builderInstance = builderInstances.get(builderName);
if (builderInstance != null) {
return builderInstance;
}
val dataBuilderClass = dataBuilderMetadataManager.getDataBuilderClass(builderName);
if (null == dataBuilderClass) {
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/io/appform/databuilderframework/model/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.google.common.collect.Maps;
import io.appform.databuilderframework.engine.DataSetAccessor;
import io.appform.databuilderframework.engine.Utils;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
import org.hibernate.validator.constraints.NotEmpty;

Expand Down Expand Up @@ -39,25 +41,17 @@ public DataSet(Map<String, Data> availableData) {
}

public DataSet add(String dataName, Data data) {
val stamp = lock.writeLock();
try {
this.availableData.put(dataName, data);
return this;
}
finally {
lock.unlockWrite(stamp);
}
return safeWriteOp(() -> {
availableData.put(dataName, data);
return DataSet.this;
});
}

public DataSet add(final Collection<Data> data) {
val stamp = lock.writeLock();
try {
return safeWriteOp(() -> {
data.forEach(d -> availableData.put(d.getData(), d));
return this;
}
finally {
lock.unlockWrite(stamp);
}
return DataSet.this;
});
}

public <T extends Data> DataSet add(T data) {
Expand Down Expand Up @@ -118,4 +112,14 @@ private <T> T safeOp(Supplier<T> operation) {
lock.unlockRead(stamp);
}
}

private <T> T safeWriteOp(Supplier<T> operation) {
val stamp = lock.writeLock();
try {
return operation.get();
}
finally {
lock.unlockWrite(stamp);
}
}
}