Skip to content

Commit

Permalink
Merge pull request #2 from F1reb0lt/java17
Browse files Browse the repository at this point in the history
Java 17 & dw 2.x upgrade
  • Loading branch information
MISBMS authored Dec 13, 2022
2 parents e1b6ee9 + 02ea07a commit cb481df
Show file tree
Hide file tree
Showing 44 changed files with 1,802 additions and 588 deletions.
753 changes: 753 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .github/workflows/sonarcloud-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
Expand All @@ -33,4 +33,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify sonar:sonar org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=PhonePe_mustang
run: mvn -Pcoverage -B verify sonar:sonar org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=PhonePe_mustang
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ crashlytics-build.properties
## Directory-based project format:
/.idea/
/target/
benchmarking/.idea/
benchmarking/target/
*.iml
*.ipr
*.iws
Expand Down
3 changes: 2 additions & 1 deletion lombok.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
config.stopBubbling = true
lombok.anyConstructor.addConstructorProperties=true
111 changes: 70 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.phonepe</groupId>
<artifactId>mustang</artifactId>
<version>2.2.3-SNAPSHOT</version>
<artifactId>mustang</artifactId><version>2.3.2-SNAPSHOT</version>
<name>Mustang</name>
<url>https://github.com/PhonePe/mustang</url>
<description>Search Engine for Rules</description>
Expand Down Expand Up @@ -46,6 +45,14 @@
<role>developer</role>
</roles>
</developer>
<developer>
<id>F1reb0lt</id>
<name>Sidharth</name>
<email>[email protected]</email>
<roles>
<role>developer</role>
</roles>
</developer>
</developers>

<issueManagement>
Expand All @@ -70,20 +77,33 @@
</distributionManagement>

<properties>
<!-- Java related properties -->
<jdk.source.version>17</jdk.source.version>
<jdk.target.version>17</jdk.target.version>
<jdk.release.version>17</jdk.release.version>
<!-- Maven related properties -->
<maven.compiler.plugin.version>3.9.0</maven.compiler.plugin.version>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>false</maven.deploy.skip>
<maven.artifact.version>3.8.5</maven.artifact.version>
<maven.source.plugin.version>3.2.0</maven.source.plugin.version>
<maven.javadoc.plugin.version>3.3.1</maven.javadoc.plugin.version>
<maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version>
<jacoco.maven.plugin.version>0.8.7</jacoco.maven.plugin.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lombok.version>1.16.16</lombok.version>
<jackson.version>2.9.9</jackson.version>
<dropwizard-validation.version>1.3.13</dropwizard-validation.version>
<lombok.version>1.18.22</lombok.version>
<jackson.version>2.13.0</jackson.version>
<dropwizard-validation.version>2.0.23</dropwizard-validation.version>
<guava.version>30.1.1-jre</guava.version>
<commons-lang3.version>3.5</commons-lang3.version>
<commons-lang3.version>3.11</commons-lang3.version>
<json-path.version>2.7.0</json-path.version>
<maven-artifact.version>3.8.3</maven-artifact.version>
<!-- Test related dependencies -->
<mockito.version>4.3.1</mockito.version>
<junit.version>4.12</junit.version>
<mockito-all.version>1.10.19</mockito-all.version>
<hamcrest.version>2.2</hamcrest.version>
</properties>


<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -142,7 +162,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven-artifact.version}</version>
<version>${maven.artifact.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -152,8 +172,9 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito-all.version}</version>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -163,23 +184,25 @@
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${jdk.source.version}</source>
<target>${jdk.target.version}</target>
<release>${jdk.release.version}</release>
<showWarnings>true</showWarnings>
<debug>false</debug>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<version>${maven.source.plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -192,7 +215,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<version>${maven.javadoc.plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -205,30 +228,8 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
<version>${maven.surefire.plugin.version}</version>
</plugin>

<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down Expand Up @@ -277,5 +278,33 @@
</plugins>
</build>
</profile>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.maven.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
13 changes: 1 addition & 12 deletions src/main/java/com/phonepe/mustang/composition/Composition.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import com.phonepe.mustang.common.RequestContext;
import com.phonepe.mustang.composition.impl.Conjunction;
import com.phonepe.mustang.composition.impl.Disjunction;
Expand Down Expand Up @@ -56,13 +54,4 @@ public abstract class Composition {

public abstract double getScore(RequestContext context);

protected int getWeigthFromContext(RequestContext context, Predicate predicate) {
try {
JsonPath.read(context.getNode()
.toString(), predicate.getLhs());
return 1;
} catch (PathNotFoundException e) {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum CompositionType {
public static final String OR_TEXT = "OR";

@Getter
private String value;
private final String value;

private CompositionType(String value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.phonepe.mustang.composition.impl;

import java.util.List;
import java.util.stream.Collectors;
import static com.phonepe.mustang.predicate.Predicate.NO_MATCH_SCORE;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -26,8 +24,8 @@
import com.phonepe.mustang.composition.CompositionType;
import com.phonepe.mustang.debug.CompositionDebugResult;
import com.phonepe.mustang.predicate.Predicate;
import com.phonepe.mustang.predicate.PredicateType;

import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -64,10 +62,15 @@ public CompositionDebugResult debug(RequestContext context) {

@Override
public double getScore(RequestContext context) {
return getPredicates().stream()
.filter(predicate -> PredicateType.INCLUDED.equals(predicate.getType()))
.mapToDouble(predicate -> predicate.getWeight() * getWeigthFromContext(context, predicate))
.sum();
double sum = 0.0;
for (Predicate predicate : getPredicates()) {
final double score = predicate.getWeightFromContext(context);
if (score == NO_MATCH_SCORE) {
return NO_MATCH_SCORE;
}
sum += score;
}
return sum;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.phonepe.mustang.composition.CompositionType;
import com.phonepe.mustang.debug.CompositionDebugResult;
import com.phonepe.mustang.predicate.Predicate;
import com.phonepe.mustang.predicate.PredicateType;

import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -65,8 +64,7 @@ public CompositionDebugResult debug(RequestContext context) {
@Override
public double getScore(RequestContext context) {
return getPredicates().stream()
.filter(predicate -> PredicateType.INCLUDED.equals(predicate.getType()))
.mapToDouble(predicate -> predicate.getWeight() * getWeigthFromContext(context, predicate))
.mapToDouble(predicate -> predicate.getWeightFromContext(context))
.max()
.orElse(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/phonepe/mustang/criteria/Criteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;
import javax.validation.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSubTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public <T> T accept(Visitor<T> visitor) {
public static final String DNF_TEXT = "DNF"; // Disjunctive Normal Form
public static final String CNF_TEXT = "CNF"; // Conjunctive Normal Form
@Getter
private String value;
private final String value;

private CriteriaForm(String value) {
this.value = value;
Expand Down
Loading

0 comments on commit cb481df

Please sign in to comment.