-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f89586c
commit c47fdaf
Showing
13 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "maven" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 执行这个 Actions 可以发布代码带中央仓库 | ||
name: deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
release: | ||
types: | ||
- created | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3.9.0 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '8' | ||
|
||
- name: Build | ||
run: mvn -B clean package | ||
|
||
- name: Set up Apache Maven Central | ||
uses: actions/setup-java@v3.9.0 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '8' | ||
server-id: ossrh | ||
server-username: MAVEN_USERNAME | ||
server-password: MAVEN_PASSWORD | ||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY}} | ||
gpg-passphrase: MAVEN_GPG_PASSPHRASE | ||
|
||
- name: Publish to Apache Maven Central | ||
run: mvn clean deploy -Dgpg.skip=false | ||
env: | ||
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | ||
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | ||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: push | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3.9.0 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '8' | ||
|
||
- name: Build | ||
run: mvn -B clean package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target/ | ||
.idea/ | ||
.project | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pull_request_rules: | ||
- name: automatic merge for dependeabot | ||
conditions: | ||
- and: | ||
- "author=dependabot[bot]" | ||
- or: | ||
- "title~=Bump super-pom from" | ||
- "title~=Bump super-version from" | ||
actions: | ||
merge: | ||
method: rebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.panosen</groupId> | ||
<artifactId>panosen-plain-schema</artifactId> | ||
<version>0.1.0</version> | ||
|
||
<parent> | ||
<groupId>com.panosen</groupId> | ||
<artifactId>super-pom</artifactId> | ||
<version>1.6.0</version> | ||
</parent> | ||
|
||
<name>Panosen Plain Schema</name> | ||
<packaging>jar</packaging> | ||
<url>https://github.com/panosen/panosen-x-plain-schema</url> | ||
<description>Panosen plain schema</description> | ||
|
||
<licenses> | ||
<license> | ||
<name>MIT</name> | ||
<url>https://github.com/panosen/panosen-x-plain-schema/blob/master/LICENSE</url> | ||
</license> | ||
</licenses> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.panosen</groupId> | ||
<artifactId>super-version</artifactId> | ||
<version>1.6.2</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.panosen.plainschema; | ||
|
||
public abstract class Plain { | ||
public abstract String type(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.panosen.plainschema; | ||
|
||
import java.util.List; | ||
|
||
public class PlainArray extends Plain { | ||
@Override | ||
public String type() { | ||
return "array"; | ||
} | ||
|
||
private List<Plain> items; | ||
|
||
public List<Plain> getItems() { | ||
return items; | ||
} | ||
|
||
public void setItems(List<Plain> items) { | ||
this.items = items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.panosen.plainschema; | ||
|
||
import java.util.Map; | ||
|
||
public class PlainMap extends Plain { | ||
@Override | ||
public String type() { | ||
return "map"; | ||
} | ||
|
||
private Map<String, Plain> map; | ||
|
||
public Map<String, Plain> getMap() { | ||
return map; | ||
} | ||
|
||
public void setMap(Map<String, Plain> map) { | ||
this.map = map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.panosen.plainschema; | ||
|
||
import com.google.gson.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class PlainParser { | ||
|
||
private static final Gson GSON = new Gson(); | ||
|
||
public Plain parse(String json) { | ||
JsonObject jsonObject = GSON.fromJson(json, JsonObject.class); | ||
|
||
return parse(jsonObject); | ||
} | ||
|
||
private Plain parse(JsonElement jsonElement) { | ||
if (jsonElement.isJsonNull()) { | ||
return null; | ||
} | ||
|
||
if (jsonElement.isJsonObject()) { | ||
return parseMap((JsonObject) jsonElement); | ||
} | ||
|
||
if (jsonElement.isJsonArray()) { | ||
return parseArray((JsonArray) jsonElement); | ||
} | ||
|
||
if (jsonElement.isJsonPrimitive()) { | ||
return parseValue((JsonPrimitive) jsonElement); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private PlainArray parseArray(JsonArray jsonArray) { | ||
PlainArray sampleArray = new PlainArray(); | ||
sampleArray.setItems(new ArrayList<>()); | ||
for (int index = 0, length = jsonArray.size(); index < length; index++) { | ||
sampleArray.getItems().add(parse(jsonArray.get(index))); | ||
} | ||
return sampleArray; | ||
} | ||
|
||
private PlainMap parseMap(JsonObject jsonObject) { | ||
PlainMap sampleMap = new PlainMap(); | ||
sampleMap.setMap(new LinkedHashMap<>()); | ||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { | ||
sampleMap.getMap().putIfAbsent(entry.getKey(), parse(entry.getValue())); | ||
} | ||
return sampleMap; | ||
} | ||
|
||
private PlainValue parseValue(JsonPrimitive jsonPrimitive) { | ||
PlainValue sampleValue = new PlainValue(); | ||
sampleValue.setValue(jsonPrimitive); | ||
return sampleValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.panosen.plainschema; | ||
|
||
import com.google.gson.JsonPrimitive; | ||
|
||
public class PlainValue extends Plain { | ||
@Override | ||
public String type() { | ||
return "value"; | ||
} | ||
|
||
private JsonPrimitive value; | ||
|
||
public JsonPrimitive getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(JsonPrimitive value) { | ||
this.value = value; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/com/panosen/localconfig/mysql/PlainParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.panosen.localconfig.mysql; | ||
|
||
import com.panosen.plainschema.*; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
public class PlainParserTest { | ||
|
||
@Test | ||
public void test() throws URISyntaxException, IOException { | ||
|
||
URL mm = this.getClass().getClassLoader().getResource("sample.json"); | ||
Path path = Paths.get(mm.toURI()); | ||
List<String> lines = Files.readAllLines(path); | ||
String json1 = String.join("", lines); | ||
|
||
Plain plain = new PlainParser().parse(json1); | ||
|
||
PlainMap plainMap = (PlainMap) plain; | ||
|
||
Assert.assertEquals(5, plainMap.getMap().size()); | ||
Assert.assertEquals("tom", ((PlainValue) plainMap.getMap().get("name")).getValue().getAsString()); | ||
Assert.assertEquals(17, ((PlainValue) plainMap.getMap().get("age")).getValue().getAsInt()); | ||
Assert.assertNull(plainMap.getMap().get("other")); | ||
|
||
PlainArray plainArray = (PlainArray) plainMap.getMap().get("scores"); | ||
Assert.assertEquals(3, plainArray.getItems().size()); | ||
Assert.assertEquals(1, ((PlainValue) plainArray.getItems().get(0)).getValue().getAsInt()); | ||
Assert.assertNull(plainArray.getItems().get(1)); | ||
Assert.assertEquals("2", ((PlainValue) plainArray.getItems().get(2)).getValue().getAsString()); | ||
|
||
|
||
PlainMap plainMap1 = (PlainMap) plainMap.getMap().get("items"); | ||
Assert.assertEquals(2, plainMap1.getMap().size()); | ||
Assert.assertEquals("a1",((PlainValue)plainMap1.getMap().get("a")).getValue().getAsString()); | ||
Assert.assertEquals(11,((PlainValue)plainMap1.getMap().get("b")).getValue().getAsInt()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "tom", | ||
"age": 17, | ||
"other": null, | ||
"scores": [ | ||
1, | ||
null, | ||
2 | ||
], | ||
"items": { | ||
"a": "a1", | ||
"b": 11 | ||
} | ||
} |