Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java codegen: upgrade deps #669

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
150 changes: 3 additions & 147 deletions schema_salad/java/main_utils/YamlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,163 +11,19 @@
import org.snakeyaml.engine.v2.api.LoadSettings;
import org.snakeyaml.engine.v2.nodes.Tag;
import org.snakeyaml.engine.v2.resolver.ScalarResolver;

// Copied from org.snakeyaml.engine.v2.resolver.ResolverTuple because it was marked non-public
/**
* Copyright (c) 2018, http://www.snakeyaml.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
final class ResolverTuple {
private final Tag tag;
private final Pattern regexp;

public ResolverTuple(Tag tag, Pattern regexp) {
Objects.requireNonNull(tag, "Tag must be provided");
Objects.requireNonNull(regexp, "regexp must be provided");
this.tag = tag;
this.regexp = regexp;
}

public Tag getTag() {
return tag;
}

public Pattern getRegexp() {
return regexp;
}

@Override
public String toString() {
return "Tuple tag=" + tag + " regexp=" + regexp;
}
}


// Adapted from org.snakeyaml.engine.v2.resolver.JsonScalarResolver
// Not guaranteed to be complete coverage of the YAML 1.2 Core Schema
// 2021-02-03 Supports 'True'/'False'/'TRUE','FALSE' as boolean; 'Null', 'NULL', an '~' as null
/**
* Copyright (c) 2018, http://www.snakeyaml.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
class CoreScalarResolver implements ScalarResolver {
public final Pattern BOOL = Pattern.compile("^(?:true|false|True|False|TRUE|FALSE)$");
public static final Pattern FLOAT = Pattern
.compile("^(-?(0?\\.[0-9]+|[1-9][0-9]*(\\.[0-9]*)?)(e[-+]?[0-9]+)?)|-?\\.(?:inf)|\\.(?:nan)$"); // NOSONAR
public static final Pattern INT = Pattern.compile("^(?:-?(?:0|[1-9][0-9]*))$");
public static final Pattern NULL = Pattern.compile("^(?:null|Null|NULL|~)$");
public static final Pattern EMPTY = Pattern.compile("^$");

public static final Pattern ENV_FORMAT = Pattern
.compile("^\\$\\{\\s*((?<name>\\w+)((?<separator>:?(-|\\?))(?<value>\\w+)?)?)\\s*\\}$");

protected Map<Character, List<ResolverTuple>> yamlImplicitResolvers = new HashMap<Character, List<ResolverTuple>>();

public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
if (first == null) {
List<ResolverTuple> curr = yamlImplicitResolvers.computeIfAbsent(null, c -> new ArrayList<ResolverTuple>());
curr.add(new ResolverTuple(tag, regexp));
} else {
char[] chrs = first.toCharArray();
for (int i = 0, j = chrs.length; i < j; i++) {
Character theC = Character.valueOf(chrs[i]);
if (theC == 0) {
// special case: for null
theC = null;
}
List<ResolverTuple> curr = yamlImplicitResolvers.get(theC);
if (curr == null) {
curr = new ArrayList<ResolverTuple>();
yamlImplicitResolvers.put(theC, curr);
}
curr.add(new ResolverTuple(tag, regexp));
}
}
}

protected void addImplicitResolvers() {
addImplicitResolver(Tag.NULL, EMPTY, null);
addImplicitResolver(Tag.BOOL, BOOL, "tfTF");
/*
* INT must be before FLOAT because the regular expression for FLOAT matches INT
* (see issue 130) http://code.google.com/p/snakeyaml/issues/detail?id=130
*/
addImplicitResolver(Tag.INT, INT, "-0123456789");
addImplicitResolver(Tag.FLOAT, FLOAT, "-0123456789.");
addImplicitResolver(Tag.NULL, NULL, "nN~\u0000");
addImplicitResolver(Tag.ENV_TAG, ENV_FORMAT, "$");
}

public CoreScalarResolver() {
addImplicitResolvers();
}

@Override
public Tag resolve(String value, Boolean implicit) {
if (!implicit) {
return Tag.STR;
}
final List<ResolverTuple> resolvers;
if (value.length() == 0) {
resolvers = yamlImplicitResolvers.get('\0');
} else {
resolvers = yamlImplicitResolvers.get(value.charAt(0));
}
if (resolvers != null) {
for (ResolverTuple v : resolvers) {
Tag tag = v.getTag();
Pattern regexp = v.getRegexp();
if (regexp.matcher(value).matches()) {
return tag;
}
}
}
if (yamlImplicitResolvers.containsKey(null)) {
for (ResolverTuple v : yamlImplicitResolvers.get(null)) {
Tag tag = v.getTag();
Pattern regexp = v.getRegexp();
if (regexp.matcher(value).matches()) {
return tag;
}
}
}
return Tag.STR;
}
}
import org.snakeyaml.engine.v2.schema.CoreSchema;

public class YamlUtils {

public static Map<String, Object> mapFromString(final String text) {
LoadSettings settings = LoadSettings.builder().setScalarResolver(new CoreScalarResolver()).build();
LoadSettings settings = LoadSettings.builder().setSchema(new CoreSchema()).build();
Load load = new Load(settings);
final Map<String, Object> result = (Map<String, Object>) load.loadFromString(text);
return result;
}

public static List<Object> listFromString(final String text) {
LoadSettings settings = LoadSettings.builder().setScalarResolver(new CoreScalarResolver()).build();
LoadSettings settings = LoadSettings.builder().setSchema(new CoreSchema()).build();
Load load = new Load(settings);
final List<Object> result = (List<Object>) load.loadFromString(text);
return result;
Expand Down
20 changes: 10 additions & 10 deletions schema_salad/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<configuration>
<release>11</release>
<showDeprecation>true</showDeprecation>
Expand All @@ -58,14 +58,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<version>3.4.1</version>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
Expand Down Expand Up @@ -117,25 +117,25 @@
<dependency>
<groupId>org.snakeyaml</groupId>
<artifactId>snakeyaml-engine</artifactId>
<version>2.3</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>[2.13.2.1,)</version>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.10.4</version>
<version>2.14.2</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>travis</id>
<id>github</id>
<activation>
<property>
<name>env.TRAVIS</name>
<name>env.CI</name>
<value>true</value>
</property>
</activation>
Expand All @@ -144,7 +144,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.8</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down