Skip to content

Commit

Permalink
(feat) minimum viable implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Jun 19, 2024
1 parent 2af7d9e commit b71f2b6
Show file tree
Hide file tree
Showing 44 changed files with 4,709 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8

[*.json]
indent_size = 2

[*.{yml,yaml}]
indent_size = 2
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Gradle Wrapper script for Linux should use lf
/gradlew text eol=lf

# Gradle Wrapper script for Windows should use crlf
/gradlew.bat text eol=crlf
57 changes: 57 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Pull Request

on:
pull_request:
branches:
- main

jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest ]
java-distribution:
- temurin
- zulu
- adopt-hotspot
- adopt-openj9
- liberica
- microsoft
- corretto
- semeru
- oracle
- dragonwell
fail-fast: false

runs-on: ${{ matrix.os }}

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

- name: Set up "${{ matrix.java-distribution }}" JDK 21
uses: actions/setup-java@v4
with:
distribution: ${{ matrix.java-distribution }}
java-version: 21

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}

- name: Install PCRE (Ubuntu)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get install -y libpcre2-8-0

- name: Build with Gradle (Ubuntu)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: ./gradlew build -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu

- name: Run tests (Ubuntu)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: ./gradlew test -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,25 @@ fabric.properties
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
## Origin: https://github.com/github/gitignore/blob/main/Gradle.gitignore
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
# PCRE4J: [PCRE](https://www.pcre.org) for Java
# PCRE4J: PCRE for Java

The PCRE4J project is a Java wrapper for the [Perl Compatible Regular Expressions](https://github.com/PCRE2Project/pcre2) library.
The PCRE4J project's goal is to bring the power of the [PCRE](https://www.pcre.org) library to Java.

This project is brought to you by [Alexey Pelykh](https://github.com/alexey-pelykh) with a great gratitude to the PCRE
library author [Philip Hazel](https://github.com/PhilipHazel) and its contributors.

## Usage

```java
import org.pcre4j.Pcre2Code;
import org.pcre4j.Pcre2CompileOption;
import org.pcre4j.Pcre2MatchData;
import org.pcre4j.Pcre2MatchOption;
import org.pcre4j.Pcre4j;
import org.pcre4j.Pcre4jUtils;
// TODO: Select one of the following imports for the backend you want to use:
import org.pcre4j.jna.Pcre2;
// import org.pcre4j.ffm.Pcre2;

public class Usage {
static {
Pcre4j.setup(new Pcre2());
}

public static String[] example(String pattern, String subject) {
final var code = new Pcre2Code(
pattern,
EnumSet.noneOf(Pcre2CompileOption.class),
null
);
final var matchData = new Pcre2MatchData(code);
code.match(
subject,
0,
EnumSet.noneOf(Pcre2MatchOption.class),
matchData,
null
);
return Pcre4jUtils.getMatchGroups(code, subject, matchData);
}
}
```

## Backends

The PCRE4J library supports several backends to invoke the `pcre2` API.

### `jna`

The `jna` backend uses the [Java Native Access](https://github.com/java-native-access/jna) library to invoke the `pcre2`
shared library. For this backend to work, the `pcre2` shared library must be installed on the system and be visible to
the JNA.

### `ffm`

The `ffm` backend uses the [Foreign Functions and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html)
to invoke the `pcre2` shared library. For this backend to work, the `pcre2` shared library must be installed on the
system and be visible via `java.library.path`.

Note that `--enable-preview` must be passed to the Java compiler to enable the preview features for this backend to be
used.
83 changes: 83 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2024 Oleksii PELYKH
*
* This file is a part of the PCRE4J. The PCRE4J is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
plugins {
`java-library`
`maven-publish`
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

configurations {
implementation {
resolutionStrategy.failOnVersionConflict()
}
}

sourceSets {
main {
java.srcDir("src/main/java")
}
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

toolchain {
languageVersion = JavaLanguageVersion.of(21)
}

withSourcesJar()
withJavadocJar()
}

tasks.withType<Test> {
useJUnitPlatform()
}

tasks.named<Jar>("sourcesJar") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])

artifact(tasks.named("sourcesJar"))
artifact(tasks.named("javadocJar"))

groupId = "org.pcre4j"
artifactId = project.name
version = findProperty("pcre4j.version") as String? ?: "0.0.0-SNAPSHOT"
}
}

repositories {
mavenCentral {
credentials {
username = findProperty("pcre4j.mavenCentral.user") as String? ?: ""
password = findProperty("pcre4j.mavenCentral.password") as String? ?: ""
}
}
}
}
Loading

0 comments on commit b71f2b6

Please sign in to comment.