Skip to content

Commit b11d5be

Browse files
authored
Merge pull request #26 from ical4j/develop
Content builder improvements
2 parents 287a003 + 3b21ace commit b11d5be

File tree

21 files changed

+252
-101
lines changed

21 files changed

+252
-101
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.vcf text eol=crlf

.github/workflows/publish-snapshots.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,39 @@ permissions: read-all
99

1010
jobs:
1111
gradle:
12+
name: Test with Java ${{ matrix.jdk }}
1213
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
jdk: [ '11', '17', '21' ] # removed JDK due to plugin errors
1318

1419
steps:
15-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up JDK ${{ matrix.jdk }}
25+
uses: actions/setup-java@v3
26+
with:
27+
distribution: temurin
28+
java-version: ${{ matrix.jdk }}
29+
cache: 'gradle'
30+
31+
- name: Setup Gradle
32+
uses: gradle/gradle-build-action@v2
33+
34+
- name: Execute Gradle build
35+
run: ./gradlew check -x test --console=plain --warning-mode all
36+
37+
publish:
38+
name: Publish Artifact
39+
needs: gradle
40+
if: ${{ needs.gradle.result == 'success' }}
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@v4
1645
- uses: actions/setup-java@v3
1746
with:
1847
distribution: temurin

.palantir/revapi.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,6 +3205,17 @@ acceptedBreaks:
32053205
\ java.lang.String) throws java.net.URISyntaxException"
32063206
new: "method void net.fortuna.ical4j.vcard.property.Uid::<init>(java.lang.String)"
32073207
justification: "support_text_uid_value"
3208+
- code: "java.method.numberOfParametersChanged"
3209+
old: "method void net.fortuna.ical4j.vcard.property.XProperty::<init>(java.lang.String,\
3210+
\ java.util.List<net.fortuna.ical4j.vcard.Parameter>, java.lang.String)"
3211+
new: "method void net.fortuna.ical4j.vcard.property.XProperty::<init>(java.lang.String)"
3212+
justification: "improved_xproperty_support"
3213+
- code: "java.method.numberOfParametersChanged"
3214+
old: "method void net.fortuna.ical4j.vcard.property.XProperty::<init>(net.fortuna.ical4j.vcard.Group,\
3215+
\ java.lang.String, java.util.List<net.fortuna.ical4j.vcard.Parameter>, java.lang.String)"
3216+
new: "method void net.fortuna.ical4j.vcard.property.XProperty::<init>(java.lang.String,\
3217+
\ net.fortuna.ical4j.model.ParameterList, java.lang.String)"
3218+
justification: "improved_xproperty_support"
32083219
- code: "java.method.parameterTypeChanged"
32093220
old: "parameter <T extends net.fortuna.ical4j.vcard.Property> T net.fortuna.ical4j.vcard.VCard::getProperty(===net.fortuna.ical4j.vcard.Property.Id===)"
32103221
new: "parameter <T extends net.fortuna.ical4j.model.Property> java.util.Optional<T>\

build.gradle

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ plugins {
88
id "pl.allegro.tech.build.axion-release" version "1.13.6"
99
id "com.palantir.revapi" version "1.7.0"
1010
// id "net.ltgt.errorprone" version "2.0.2" apply false
11-
// id "biz.aQute.bnd.builder" version "$bndVersion"
12-
id 'org.javamodularity.moduleplugin' version '1.8.14'
11+
id "biz.aQute.bnd.builder" version "$bndVersion"
12+
id 'org.javamodularity.moduleplugin' version '1.8.15'
1313
}
1414

1515
sourceCompatibility = 11
@@ -35,8 +35,7 @@ java {
3535
sourcesJar.dependsOn ':compileModuleInfoJava'
3636

3737
dependencies {
38-
api "org.mnode.ical4j:ical4j:$ical4jVersion", "commons-io:commons-io:$commonsIoVersion",
39-
"org.slf4j:slf4j-api:$slf4jVersion"
38+
api "org.mnode.ical4j:ical4j:$ical4jVersion", "commons-io:commons-io:$commonsIoVersion"
4039

4140
groovyDslImplementation "org.codehaus.groovy:groovy:$groovyVersion"
4241

@@ -49,17 +48,20 @@ dependencies {
4948
// spock
5049
testImplementation platform("org.spockframework:spock-bom:$spockVersion"),
5150
"org.spockframework:spock-core",
52-
"org.slf4j:slf4j-log4j12:$slf4jVersion",
53-
"org.apache.logging.log4j:log4j:$log4jVersion"
51+
"org.apache.logging.log4j:log4j-core:$log4jVersion"
5452

55-
testRuntimeOnly "org.jparsec:jparsec:$jparsecVersion"
53+
testRuntimeOnly("org.mnode.ical4j:ical4j:$ical4jVersion") {
54+
capabilities {
55+
requireCapability("org.mnode.ical4j:ical4j-filter-expressions")
56+
}
57+
}
5658
}
5759

58-
//compileTestJava {
59-
// moduleOptions {
60-
// compileOnClasspath = true
61-
// }
62-
//}
60+
compileTestJava {
61+
moduleOptions {
62+
compileOnClasspath = true
63+
}
64+
}
6365

6466
test {
6567
moduleOptions {
@@ -130,6 +132,8 @@ jar {
130132
'Implementation-Vendor': 'Ben Fortuna'
131133
)
132134
}
135+
136+
duplicatesStrategy = DuplicatesStrategy.WARN
133137
}
134138

135139
revapi {

gradle.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
ical4jVersion=4.0.0-rc4
1+
ical4jVersion=4.0.0-rc6
22

3-
slf4jVersion=2.0.9
43
log4jVersion=2.22.1
54
commonsIoVersion=2.15.1
65
groovyVersion=3.0.20
7-
jparsecVersion=3.1
86
bndVersion=6.3.1
97
junitVintageVersion=5.10.2
108
spockVersion=2.4-M1-groovy-3.0

src/main/groovy/net/fortuna/ical4j/vcard/ContentBuilder.groovy

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,24 @@ class ContentBuilder extends FactoryBuilderSupport {
4949
ContentBuilder(boolean init = true) {
5050
super(init)
5151
}
52-
52+
53+
@Override
54+
protected Factory resolveFactory(name, Map attributes, value) {
55+
def prefix = name.substring(0, Math.max(0, name.lastIndexOf('.')))
56+
def propName = name.split('\\.')[-1]
57+
def factory = super.resolveFactory(propName, attributes, value)
58+
if (!factory) {
59+
factory = new XPropertyFactory(propName)
60+
}
61+
62+
if (factory.class.isAssignableFrom(net.fortuna.ical4j.model.property.AbstractPropertyFactory) ||
63+
factory.class.equals(PropertyFactoryWrapper) ||
64+
factory.class.equals(XPropertyFactory)) {
65+
factory.propertyPrefix = !prefix.empty ? prefix : null
66+
}
67+
return factory
68+
}
69+
5370
def registerVCard() {
5471
registerFactory('vcard', new VCardFactory())
5572
}
@@ -103,6 +120,8 @@ class ContentBuilder extends FactoryBuilderSupport {
103120
new net.fortuna.ical4j.vcard.property.Version.Factory()))
104121
// RFC2426 factories..
105122
registerFactory('mailer', new PropertyFactoryWrapper(Mailer, new Mailer.Factory()))
123+
124+
registerFactory('xproperty', new XPropertyFactory())
106125
}
107126

108127
def registerParameters() {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright (c) 2012, Ben Fortuna
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* o Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* o Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* o Neither the name of Ben Fortuna nor the names of any other contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package net.fortuna.ical4j.vcard.property
33+
34+
35+
import net.fortuna.ical4j.model.ParameterList
36+
37+
/**
38+
* $Id$
39+
*
40+
* Created on: 02/08/2009
41+
*
42+
* @author fortuna
43+
*
44+
*/
45+
class XPropertyFactory extends net.fortuna.ical4j.model.property.AbstractPropertyFactory {
46+
47+
final def propertyName
48+
49+
XPropertyFactory(propertyName) {
50+
this.propertyName = propertyName
51+
}
52+
53+
@Override
54+
Object newInstance(FactoryBuilderSupport builder, name, value, Map attributes) throws InstantiationException,
55+
IllegalAccessException {
56+
def property
57+
if (FactoryBuilderSupport.checkValueIsTypeNotString(value, name, XProperty)) {
58+
property = value.copy()
59+
} else if (attributes['value']) {
60+
property = super.newInstance(builder, name, attributes.remove('value'), attributes)
61+
} else {
62+
property = super.newInstance(builder, name, value, attributes)
63+
}
64+
return property
65+
}
66+
67+
@Override
68+
protected Object newInstance(parameters, value) {
69+
def property = new XProperty(propertyName, new ParameterList((List) parameters), value)
70+
property.prefix = propertyPrefix
71+
return property
72+
}
73+
}

src/main/java/module-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
exports net.fortuna.ical4j.vcard.property.immutable;
1717
exports net.fortuna.ical4j.vcard.filter;
1818
exports net.fortuna.ical4j.vcard.parameter;
19+
20+
uses net.fortuna.ical4j.vcard.ParameterFactory;
21+
uses net.fortuna.ical4j.vcard.PropertyFactory;
1922
}

src/main/java/net/fortuna/ical4j/vcard/GroupProperty.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ default void setGroup(Group group) {
5151
}
5252

5353
default Group getGroup() {
54-
// return Group.Id.valueOf(getPrefix());
54+
if (getPrefix() != null) {
55+
switch (Group.Id.valueOf(getPrefix())) {
56+
case WORK:
57+
return Group.WORK;
58+
case HOME:
59+
return Group.HOME;
60+
}
61+
}
5562
return null;
5663
}
5764
}

src/main/java/net/fortuna/ical4j/vcard/VCard.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.io.Serializable;
4545
import java.util.List;
4646
import java.util.function.BiFunction;
47+
import java.util.stream.Collectors;
4748

4849
import static net.fortuna.ical4j.vcard.property.immutable.ImmutableKind.GROUP;
4950

@@ -161,6 +162,11 @@ private void assertOne(final PropertyName propertyId) throws ValidationException
161162
}
162163
}
163164

165+
public VCard copy() {
166+
return new VCard(new PropertyList(getProperties().parallelStream()
167+
.map(Property::copy).collect(Collectors.toList())));
168+
}
169+
164170
/**
165171
* @return a vCard-compliant string representation of the vCard object
166172
*/

0 commit comments

Comments
 (0)