Skip to content

Commit

Permalink
Merge branch 'release/1.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lanarimarco committed Nov 4, 2024
2 parents 6066632 + ac85626 commit c1518a5
Show file tree
Hide file tree
Showing 267 changed files with 19,936 additions and 1,024 deletions.
6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "weekly"
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/workflows/publish-smeup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
with:
java-version: 11
distribution: zulu
- uses: gradle/actions/setup-gradle@v3
- uses: gradle/actions/setup-gradle@v4
# save private key to file (private.gpg)
- run: echo "${{ secrets.GPG_KEY_BASE64 }}" | base64 -d > ~/private.gpg
# create gradle.properties file
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
java-version: 11
distribution: zulu
- uses: gradle/actions/setup-gradle@v3
- uses: gradle/actions/setup-gradle@v4
# save private key to file (private.gpg)
- run: echo "${{ secrets.GPG_KEY_BASE64 }}" | base64 -d > ~/private.gpg
# create gradle.properties file
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
java-version: 11
distribution: zulu
- uses: gradle/actions/setup-gradle@v3
- uses: gradle/actions/setup-gradle@v4
- name: Checking kotlin formatting
run: ./gradlew ktlintCheck
- name: Compiling and test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ To use Jariko in a Gradle application, add the following lines to your `build.gr
```
dependencies {
...
implementation 'io.github.smeup:jariko:vx.y.z'
implementation 'io.github.smeup.jariko:rpgJavaInterpreter-core:vx.y.z'
}
```
### Samples
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*
*/

//-----------------
Expand Down Expand Up @@ -40,7 +41,7 @@ buildscript {

plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id "org.ajoberstar.grgit" version "5.0.0-rc.3"
id "org.ajoberstar.grgit" version "5.3.0"
}

project.group = jarikoGroupId
Expand All @@ -58,6 +59,10 @@ subprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
name 'Smeup Nexus'
url 'https://repo.smeup.cloud/nexus/repository/public/'
}
maven { url 'https://jitpack.io' }
// the sonatype repo inclusion allows to work with the reload snapshot version
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
Expand Down
2 changes: 1 addition & 1 deletion docs/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# default code owners
* marco.lanari@smeup.com marco.benetti@smeup.com mattiabonardi99@gmail.com fiorenza.busi@smeup.com antonio.cosentino@smeup.com
* marco.lanari@smeup.com marco.benetti@smeup.com mattiabonardi99@gmail.com fiorenza.busi@smeup.com antonio.cosentino@smeup.com d.foresti@gmail.com
12 changes: 7 additions & 5 deletions docs/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
## Description

Include a summary of the change.
Include a summary of the changes.

Related to # (issue)

## Checklist:
- [ ] There are tests regarding this feature
- [ ] The code follows the Kotlin conventions (run `./gradlew ktlintCheck`)
- [ ] The code passes all tests (run `./gradlew check`)
- [ ] There is a specific documentation in the `docs` directory
- [ ] If this feature involves RPGLE fixes or improvements, they are well-described in the summary.
- [ ] There are tests for this feature.
- [ ] RPGLE code used for tests is easily understandable and includes comments that clarify the purpose of this feature.
- [ ] The code follows Kotlin conventions (run `./gradlew ktlintCheck`).
- [ ] The code passes all tests (run `./gradlew check`).
- [ ] Relevant documentation is included in the `docs` directory.
2 changes: 1 addition & 1 deletion dspfparser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
testImplementation 'junit:junit:4.13.1'
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"

implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$serializationVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.smeup.dspfparser.linesclassifier

import kotlinx.serialization.Serializable

@Serializable
data class ConstantField(
val value: ConstantValue?,
override val x: Int?,
override val y: Int?
) : DSPFField
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.smeup.dspfparser.linesclassifier

import kotlinx.serialization.Serializable
import kotlinx.serialization.modules.SerializersModule

/**
* Unlike variable fields, a constant field should be initialized with its value in the
* parser phase since it is hardwired into the display file.
* This [DSPFValue] implementation allows the value to be passed into Jariko.
* Importing Jariko's [DSPFValue] implementations is not a good choice because Jariko depends on this
* module and not the vice versa.
* To make serialization / deserialization work proper declarations in [SerializersModule] is needed
* because [DSPFValue] is not sealed (its implementers are in another package,
* in rpgJavaInterpreter-core module).
*/
@Serializable
data class ConstantValue(val value: String) : DSPFValue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ sealed interface DSPF {
fun getRecord(name: String): DSPFRecord

/**
* Retrieve a list of [DSPFField] given its record's name.
* Retrieve a list of [MutableField] given its record's name.
* @param name the name of the record
* @return [List]<[DSPFField]>
* @return [List]<[MutableField]>
*/
fun getFieldsFromRecord(name: String): List<DSPFField>
fun getMutableFieldsFromRecord(name: String): List<MutableField>

/**
* Retrieve a list of [ConstantField] given its record's name.
* @param name the name of the record
* @return [List]<[ConstantField]>
*/
fun getConstantFieldsFromRecord(name: String): List<ConstantField>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ package com.smeup.dspfparser.linesclassifier
import kotlinx.serialization.Serializable

/**
* Models a [DSPFRecord] field (that can be seen as a variable, with its record as scope).
* Models a [DSPFRecord] field, that can be seen as a variable or a constant, with its record as scope.
*/
@Serializable
sealed interface DSPFField {
val name: String
var value: DSPFValue?
val isNumeric: Boolean
val length: Int?
val precision: Int?
val type: DSPFFieldType
val x: Int?
val y: Int?
val hasError: Boolean
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
package com.smeup.dspfparser.linesclassifier

import com.smeup.dspfparser.linesprocessor.DSPFLine
import com.smeup.dspfparser.linesprocessor.LineType
import com.smeup.dspfparser.positionals.FieldType
import kotlinx.serialization.Serializable

@Serializable
internal data class DSPFFieldSpecifications private constructor(
override val name: String,
override var value: DSPFValue? = null,
override val isNumeric: Boolean,
override val length: Int? = null,
override val precision: Int? = null,
override val type: DSPFFieldType,
override val x: Int?,
override val y: Int?,
override var hasError: Boolean = false
override val y: Int?
) : DSPFField {

companion object {
fun fromLine(declaration: DSPFLine): DSPFFieldSpecifications {
val isNumeric = declaration.decimalsPositions != null
fun fromLine(declaration: DSPFLine): DSPFField {
if (declaration.type == LineType.CONSTANT) {
return ConstantField(
value = ConstantValue(declaration.keywords!!.getConstantValue()),
x = declaration.x,
y = declaration.y
)
} else {
val isNumeric = declaration.decimalsPositions != null

return DSPFFieldSpecifications(
name = declaration.fieldName,
value = null,
isNumeric = isNumeric,
length = declaration.length,
precision = declaration.decimalsPositions,
type = this.getType(declaration),
x = declaration.x,
y = declaration.y
)
return MutableField(
name = declaration.fieldName,
value = null,
isNumeric = isNumeric,
length = declaration.length,
precision = declaration.decimalsPositions,
type = this.getType(declaration),
x = declaration.x,
y = declaration.y
)
}
}

private fun getType(declaration: DSPFLine): DSPFFieldType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import kotlinx.serialization.Serializable
@Serializable
sealed interface DSPFRecord {
val name: String
val fields: List<DSPFField>
val mutables: List<MutableField>
val constants: List<ConstantField>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import kotlinx.serialization.Serializable
internal data class DSPFRecordSpecifications private constructor(
override val name: String
) : DSPFRecord {
override val fields: MutableList<DSPFFieldSpecifications> = mutableListOf()
override val mutables: MutableList<MutableField> = mutableListOf()
override val constants: MutableList<ConstantField> = mutableListOf()

companion object {
fun fromLine(declaration: DSPFLine): DSPFRecordSpecifications {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.smeup.dspfparser.linesclassifier

import com.smeup.dspfparser.linesprocessor.DSPFLine
import com.smeup.dspfparser.linesprocessor.LineType
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -19,22 +20,24 @@ internal data class DSPFSpecifications(
return this.records.first { it.name == name.uppercase() }
}

override fun getFieldsFromRecord(name: String): MutableList<DSPFFieldSpecifications> {
return this.records.first { it.name == name.uppercase() }.fields
override fun getMutableFieldsFromRecord(name: String): MutableList<MutableField> {
return this.records.first { it.name == name.uppercase() }.mutables
}

override fun getConstantFieldsFromRecord(name: String): List<ConstantField> {
return this.records.first { it.name == name.uppercase() }.constants
}
}

private enum class CurrentContext {
FILE,
RECORD,
FIELD,
FIELD
}

private class DSPFSpecificationsFactory {
private var context: CurrentContext = CurrentContext.FILE
private var isLineNone: Boolean = false
private var isLineRecord: Boolean = false
private var isLineField: Boolean = false
private var currentLineType: LineType = LineType.NULL
private var result: DSPFSpecifications = DSPFSpecifications()

constructor(lines: MutableList<DSPFLine>) {
Expand All @@ -46,35 +49,50 @@ private class DSPFSpecificationsFactory {
}

private fun tryInsertNewRecord(line: DSPFLine) {
if (this.isLineRecord) {
if (this.currentLineType == LineType.RECORD) {
this.result.records.add(DSPFRecordSpecifications.fromLine(line))
this.context = CurrentContext.RECORD
}
}

private fun tryInsertNewFieldOnRecordContext(line: DSPFLine) {
if (this.context == CurrentContext.RECORD && this.isLineField) {
this.result.records.last().fields.add(DSPFFieldSpecifications.fromLine(line))
if (this.context == CurrentContext.RECORD && this.currentLineType == LineType.FIELD) {
this.result.records.last().mutables.add(DSPFFieldSpecifications.fromLine(line) as MutableField)
this.context = CurrentContext.FIELD
}
}

private fun tryInsertNewFieldOnFieldContext(line: DSPFLine) {
if (this.context == CurrentContext.FIELD && this.isLineField) {
this.result.records.last().fields.add(DSPFFieldSpecifications.fromLine(line))
if (this.context == CurrentContext.FIELD && this.currentLineType == LineType.FIELD) {
this.result.records.last().mutables.add(DSPFFieldSpecifications.fromLine(line) as MutableField)
}
}

private fun tryInsertNewConstantOnFieldContext(line: DSPFLine) {
if (this.context == CurrentContext.FIELD && this.currentLineType == LineType.CONSTANT) {
this.result.records.last().constants.add(DSPFFieldSpecifications.fromLine(line) as ConstantField)
}
}

private fun tryInsertNewConstantOnRecordContext(line: DSPFLine) {
if (this.context == CurrentContext.RECORD && this.currentLineType == LineType.CONSTANT) {
this.result.records.last().constants.add(DSPFFieldSpecifications.fromLine(line) as ConstantField)
this.context = CurrentContext.FIELD
}
}

private fun updateResultWith(lines: MutableList<DSPFLine>) {
lines.forEach {
this.isLineNone = it.isNone()
this.isLineField = it.isField()
this.isLineRecord = it.isRecord()
this.currentLineType = it.type

// order is important, do not change it
this.tryInsertNewRecord(it)
// try with field context before record context because after matching
// record context, context is switched to field leading to a double match
this.tryInsertNewFieldOnFieldContext(it)
this.tryInsertNewFieldOnRecordContext(it)
this.tryInsertNewConstantOnFieldContext(it)
this.tryInsertNewConstantOnRecordContext(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.smeup.dspfparser.linesclassifier

import kotlinx.serialization.Serializable

@Serializable
data class MutableField(
val name: String,
var value: DSPFValue?,
val isNumeric: Boolean,
val length: Int?,
val precision: Int?,
val type: DSPFFieldType,
override val x: Int?,
override val y: Int?
) : DSPFField
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal data class DSPFKeyword private constructor(
}

private fun getConstantMessage(text: String): String? {
return Regex("^'[^']*'\$").find(text.trim())?.value?.removeFirst('\'')?.removeLast('\'')
return Regex("^'.*'\$").find(text.trim())?.value?.removeFirst('\'')?.removeLast('\'')
}

private fun getName(text: String): String? {
Expand Down
Loading

0 comments on commit c1518a5

Please sign in to comment.