-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from gastaldi/FORGE-1651
FORGE-1651: Created parser-json addon
- Loading branch information
Showing
17 changed files
with
652 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,53 @@ | ||
== parser-json | ||
:idprefix: id_ | ||
This addon provides *standalone* functionality, and *exports services* for use in other addons. | ||
It enables usage of JSR 353 - Java API for Json Processing in your addons | ||
|
||
=== Depends on | ||
[options="header"] | ||
|=== | ||
|Addon |Exported |Optional | ||
|resources | ||
|yes | ||
|yes | ||
|
||
|simple | ||
|yes | ||
|no | ||
|
||
|=== | ||
|
||
== Setup | ||
This Addon requires the following installation steps. | ||
=== Add configuration to pom.xml | ||
To use this addon, you must add it as a dependency in the *pom.xml* of your `forge-addon` classified artifact: | ||
(Make sure the dependency is put all the way to the left, and uses 3 spaces for indentation of GAV) | ||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<version>${version}</version> | ||
</dependency> | ||
---- | ||
== Features | ||
JsonResource for Json files:: | ||
Allows easy manipulation of json data | ||
+ | ||
[source,java] | ||
---- | ||
@Inject private ResourceFactory factory; | ||
JsonResource resource = factory.createResource(new File("abc.json")).reify(JsonResource.class); | ||
javax.json.JsonObject model = resource.getJsonObject(); | ||
.... | ||
JsonArray array = ...; | ||
resource.setContents(array); | ||
or | ||
JsonObject obj = ...; | ||
resource.setContents(obj); | ||
---- |
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,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json-parent</artifactId> | ||
<version>2.1.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>parser-json</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.container</groupId> | ||
<artifactId>simple</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>resources</artifactId> | ||
<classifier>forge-addon</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json-impl</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jboss.forge.furnace</groupId> | ||
<artifactId>furnace-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>generate-dot</id> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>generate-dot</goal> | ||
</goals> | ||
<configuration> | ||
<attach>true</attach> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>create-forge-addon</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>forge-addon</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
1 change: 1 addition & 0 deletions
1
parser-json/addon/src/main/java/org/jboss/forge/addon/parser/json/package-info.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 @@ | ||
package org.jboss.forge.addon.parser.json; |
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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json-parent</artifactId> | ||
<version>2.1.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>parser-json-api</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.json</groupId> | ||
<artifactId>javax.json-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>resources</artifactId> | ||
<classifier>forge-addon</classifier> | ||
</dependency> | ||
</dependencies> | ||
</project> |
1 change: 1 addition & 0 deletions
1
parser-json/api/src/main/java/org/jboss/forge/addon/parser/json/package-info.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 @@ | ||
package org.jboss.forge.addon.parser.json; |
46 changes: 46 additions & 0 deletions
46
parser-json/api/src/main/java/org/jboss/forge/addon/parser/json/resource/JsonResource.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 @@ | ||
/** | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.parser.json.resource; | ||
|
||
import javax.json.JsonArray; | ||
import javax.json.JsonObject; | ||
import javax.json.JsonStructure; | ||
|
||
import org.jboss.forge.addon.resource.FileResource; | ||
import org.jboss.forge.addon.resource.Resource; | ||
|
||
/** | ||
* A {@link Resource} that represents a {@link JsonObject} | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface JsonResource extends FileResource<JsonResource> | ||
{ | ||
/** | ||
* Returns a JSON array or object that is represented in the input source | ||
* | ||
* Use this method if you are unsure of the json data format | ||
*/ | ||
JsonStructure getJsonStructure(); | ||
|
||
/** | ||
* Return the {@link JsonArray} representing the underlying Json data | ||
*/ | ||
JsonArray getJsonArray(); | ||
|
||
/** | ||
* Return the {@link JsonObject} representing the underlying Json data | ||
*/ | ||
JsonObject getJsonObject(); | ||
|
||
/** | ||
* Sets the content to this {@link JsonStructure} (could be an array or object) | ||
*/ | ||
JsonResource setContents(JsonStructure structure); | ||
|
||
} |
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,2 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bean-discovery-mode="all" version="1.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"/> |
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json-parent</artifactId> | ||
<version>2.1.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>parser-json-impl</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.container</groupId> | ||
<artifactId>simple</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>parser-json-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish</groupId> | ||
<artifactId>javax.json</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
1 change: 1 addition & 0 deletions
1
parser-json/impl/src/main/java/org/jboss/forge/addon/parser/json/package-info.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 @@ | ||
package org.jboss.forge.addon.parser.json; |
35 changes: 35 additions & 0 deletions
35
.../impl/src/main/java/org/jboss/forge/addon/parser/json/resource/JsonResourceGenerator.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,35 @@ | ||
package org.jboss.forge.addon.parser.json.resource; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.forge.addon.resource.Resource; | ||
import org.jboss.forge.addon.resource.ResourceFactory; | ||
import org.jboss.forge.addon.resource.ResourceGenerator; | ||
import org.jboss.forge.furnace.container.simple.Service; | ||
|
||
public class JsonResourceGenerator implements ResourceGenerator<JsonResource, File>, Service | ||
{ | ||
@Override | ||
public boolean handles(Class<?> type, Object resource) | ||
{ | ||
if (resource instanceof File && ((File) resource).getName().endsWith(".json")) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T extends Resource<File>> T getResource(ResourceFactory factory, Class<JsonResource> type, File resource) | ||
{ | ||
return (T) new JsonResourceImpl(factory, resource); | ||
} | ||
|
||
@Override | ||
public <T extends Resource<File>> Class<?> getResourceType(ResourceFactory factory, Class<JsonResource> type, | ||
File resource) | ||
{ | ||
return JsonResource.class; | ||
} | ||
} |
Oops, something went wrong.