Skip to content

Commit

Permalink
Merge pull request #192 from RepreZen/task/191
Browse files Browse the repository at this point in the history
Task/191 Remove uses of guava
  • Loading branch information
andylowry authored Aug 22, 2018
2 parents 24dce5c + cdc9d3a commit 172ae39
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 109 deletions.
29 changes: 21 additions & 8 deletions kaizen-openapi-parser/p2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,32 @@ Here is the usage message for the script:

```
Usage: ./build.sh <options>
Builds a p2 repo for KZOP, including JsonOverlay and other dependencies, and
Builds a p2 repository for KZOP, including JsonOverlay and other dependencies, and
optionally publishes as an update site.
Options: (* marks required option)
* -k or --kzop-version - specify full version number of KZOP to package
* -j or --jovl-version - specify full version number of JsonOverlay to package
-r or --repo - specify maven repo URL where indicated versions are available, if
they are not in maven central. Defaults to http://localhost:8000
This script will attempt to stage the indicated versions to your
lcoal maven repo cache prior to building the bundle.
Hint: start a web server that delivers files from your .m2.repository
directory, e.g. using "python -m SimpleHTTPServer"
or "python3 -m http.server"
-K or --kzop-repo - specify maven repo URL where indicated KXOP version is
available, if is not in maven central
-J or --jovl-repo - specify maven repo URL where indicated JsonOverlay
version is available, if is not in maven central
-p or --publish - publish the newly built update site
* -b or --build-scripts - speicfy location of RepreZen build scripts, including
the "publish" script. This is required only if "-p" is specified
-h or --help - print this message and do nothing else
Note on repos: Both ---kzop-repo and --jovl-repo default to
http://localhost:8000, so if you already have the needed versions in
your local maven repo cache, you can set up a simple HTTP server to
serve those files and go with these defaults. But you can also explicitly
specify, e.g., staging repository URLs.
To use the defualt repo, you can use either of the following to launch
a local web server, after positioning yourself in the root of your
local maven cacche (typically .m2/repository in your home directory):
* python -m SimpleHTTPServer
* python3 -m http.server
```

To build without publishing, use a command like this, with
Expand Down Expand Up @@ -80,6 +89,10 @@ yet released to central), you can follow this procedure:
the root URL serving your local repo, which defaults to
`http://localhost:8000`.

Alterantively, you can use the `--kzop-repo` (`-K`) and/or
`--jovl-repo` (`-J`) options to specify URLs for staging repositories
that contain the needed versions.

## Publishing

If you use the `-p` option, the script will publish the newly-built
Expand Down
44 changes: 29 additions & 15 deletions kaizen-openapi-parser/p2/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash -e

unset JOVL_VERSION KZOP_VERSION BUILD_SCRIPT_DIR
REPO="http://localhost:8000"
KZOP_REPO="http://localhost:8000"
JOVL_REPO="http://localhost:8000"
PUBLISH=false
HELP=false

function getargs() {
longopts="jovl-version:,kzop-version:,repo:,publish,build-scripts:,help"
shortopts="j:k:r:pb:h"
longopts="jovl-version:,kzop-version:,kzop-repo:,jovl-repo:,publish,build-scripts:,help"
shortopts="j:k:K:J:pb:h"
progname=$(basename "$0")
OPTS=$(getopt -n "$progname" -o "$shortopts" --long "$longopts" -- "$@")
if [[ $? -ne 0 ]] ; then
Expand All @@ -20,8 +21,10 @@ function getargs() {
KZOP_VERSION="$2"; shift 2 ;;
-j|--jovl-version)
JOVL_VERSION="$2"; shift 2 ;;
-r:--repo)
LOCAL_REPO="$2"; shift 2 ;;
-K|--kzop-repo)
KZOP_REPO="$2"; shift 2 ;;
-J|--jovl-repo)
JOVL_REPO="$2"; shift 2 ;;
-p|--publish)
PUBLISH=true ; shift ;;
-b|--build-scripts)
Expand Down Expand Up @@ -62,17 +65,26 @@ function usage() {
Options: (* marks required option)
* -k or --kzop-version - specify full version number of KZOP to package
* -j or --jovl-version - specify full version number of JsonOverlay to package
-r or --repo - specify maven repo URL where indicated versions are available, if
they are not in maven central. Defaults to http://localhost:8000
This script will attempt to stage the indicated versions to your
lcoal maven repo cache prior to building the bundle.
Hint: start a web server that delivers files from your .m2.repository
directory, e.g. using "python -m SimpleHTTPServer"
or "python3 -m http.server"
-K or --kzop-repo - specify maven repo URL where indicated KXOP version is
available, if is not in maven central
-J or --jovl-repo - specify maven repo URL where indicated JsonOverlay
version is available, if is not in maven central
-p or --publish - publish the newly built update site
* -b or --build-scripts - speicfy location of RepreZen build scripts, including
the "publish" script. This is required only if "-p" is specified
-h or --help - print this message and do nothing else
Note on repos: Both ---kzop-repo and --jovl-repo default to
http://localhost:8000, so if you already have the needed versions in
your local maven repo cache, you can set up a simple HTTP server to
serve those files and go with these defaults. But you can also explicitly
specify, e.g., staging repository URLs.
To use the defualt repo, you can use either of the following to launch
a local web server, after positioning yourself in the root of your
local maven cacche (typically .m2/repository in your home directory):
* python -m SimpleHTTPServer
* python3 -m http.server
END_OF_USAGE
}

Expand All @@ -85,14 +97,16 @@ function main() {
}

function retrieveArtifacts() {
mvn dependency:get -DrepoUrl="$REPO" \
mvn dependency:get -DrepoUrl="$KZOP_REPO" \
-Dartifact="com.reprezen.kaizen:openapi-parser:$KZOP_VERSION"
mvn dependency:get -DrepoUrl="$REPO" \
mvn dependency:get -DrepoUrl="$JOVL_REPO" \
-Dartifact="com.reprezen.jsonoverlay:jsonoverlay:$JOVL_VERSION"
}

function buildSite() {
mvn clean p2:site -Dkzop-version="$KZOP_VERSION" -Djovl-version="$JOVL_VERSION"
mvn clean p2:site \
-Dkzop-version="$KZOP_VERSION" -Dkzop-repo="$KZOP_REPO" \
-Djovl-version="$JOVL_VERSION" -Djovl-repo="$JOVL_REPO"
}

function publishSite() {
Expand Down
158 changes: 96 additions & 62 deletions kaizen-openapi-parser/p2/pom.xml
Original file line number Diff line number Diff line change
@@ -1,66 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.reprezen.kaizen</groupId>
<artifactId>com.reprezen.kaizen.openapi-parser.osgi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<local-repo>http://localhost:8000</local-repo>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.reprezen.kaizen</groupId>
<artifactId>com.reprezen.kaizen.openapi-parser.osgi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<kzop-repo>http://localhost:8000</kzop-repo>
<jovl-repo>http://localhost:8000</jovl-repo>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.1.2-SNAPSHOT</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<artifact>
<id>com.reprezen.kaizen:openapi-parser:${kzop-version}</id>
<instructions>
<Import-Package>*;resolution=optional</Import-Package>
<Export-Package>
com.reprezen.kaizen.oasparser,
com.reprezen.kaizen.oasparser.model3,
com.reprezen.kaizen.oasparser.ovl3,
com.reprezen.kaizen.oasparser.val
</Export-Package>
</instructions>
</artifact>
<artifact>
<id>com.reprezen.jsonoverlay:jsonoverlay:${jovl-version}</id>
<instructions>
<Export-Package>
com.reprezen.jsonoverlay,
com.reprezen.jsonoverlay.gen
</Export-Package>
</instructions>
</artifact>
</artifacts>
<compressSite>false</compressSite>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<pluginRepositories>
<pluginRepository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.1.2-SNAPSHOT</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<artifact>
<id>com.reprezen.kaizen:openapi-parser:${kzop-version}</id>
<!-- early verssions of this artifact have bundle manifests that we
now ignore -->
<override>true</override>
<instructions>
<Import-Package>
javax.mail.internet,
com.reprezen.jsonoverlay.gen;resolution:=optional,
*
</Import-Package>
<Export-Package>
com.reprezen.kaizen.oasparser,
com.reprezen.kaizen.oasparser.model3,
com.reprezen.kaizen.oasparser.ovl3,
com.reprezen.kaizen.oasparser.val,
com.reprezen.kaizen.oasparser.val.msg
</Export-Package>
</instructions>
<excludes>
<!-- this is specified
explicitly below -->
<exclude>com.reprezen.jsonoverlay:jsonoverlay</exclude>
<exclude>com.google.guava</exclude>
</excludes>
</artifact>
<artifact>
<id>com.reprezen.jsonoverlay:jsonoverlay:${jovl-version}</id>
<!-- early verssions of this artifact have bundle manifests that
we now ignore -->
<override>true</override>
<instructions>
<Import-Package>
*
</Import-Package>
<Export-Package>
com.reprezen.jsonoverlay
</Export-Package>
</instructions>
<excludes>
<!-- following are only required for model class generation,
which is generally not done at runtime -->
<exclude>commons-cli</exclude>
<exclude>com.github.javaparser</exclude>
<exclude>com.google.guava</exclude>
<exclude>org.eclipse.xtend</exclude>
</excludes>
</artifact>
</artifacts>
<compressSite>false</compressSite>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<pluginRepositories>
<pluginRepository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</pluginRepository>
</pluginRepositories>

<repositories>
<repository>
<id>local-cache</id>
<url>${local-repo}</url>
<layout>default</layout>
</repository>
</repositories>
<repositories>
<repository>
<id>kzop-repo</id>
<url>${kzop-repo}</url>
<layout>default</layout>
</repository>
<repository>
<id>jovl-repo</id>
<url>${jovl-repo}</url>
<layout>default</layout>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -26,8 +28,6 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.ShortNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.reprezen.jsonoverlay.BooleanOverlay;
import com.reprezen.jsonoverlay.IntegerOverlay;
import com.reprezen.jsonoverlay.JsonOverlay;
Expand Down Expand Up @@ -62,7 +62,7 @@ private static String getJsonValueType(Class<? extends JsonNode> node) {
return type.endsWith("Node") ? type.substring(0, type.length() - 4) : type;
}

private static Multimap<Class<?>, Class<? extends JsonNode>> allowedJsonTypes = null;
private static Map<Class<?>, List<Class<? extends JsonNode>>> allowedJsonTypes = null;

private static Collection<Class<? extends JsonNode>> getAllowedJsonTypes(Overlay<?> value) {
if (allowedJsonTypes == null) {
Expand All @@ -74,17 +74,16 @@ private static Collection<Class<? extends JsonNode>> getAllowedJsonTypes(Overlay
}

private static void createAllowedJsonTypes() {
Multimap<Class<?>, Class<? extends JsonNode>> types = ArrayListMultimap
.<Class<?>, Class<? extends JsonNode>>create();
types.put(StringOverlay.class, TextNode.class);
types.put(BooleanOverlay.class, BooleanNode.class);
types.putAll(IntegerOverlay.class, Arrays.asList(IntNode.class, ShortNode.class, BigIntegerNode.class));
types.put(NumberOverlay.class, NumericNode.class);
types.putAll(PrimitiveOverlay.class, Arrays.asList(TextNode.class, NumericNode.class, BooleanNode.class));
types.put(ObjectOverlay.class, JsonNode.class);
types.put(MapOverlay.class, ObjectNode.class);
types.put(ListOverlay.class, ArrayNode.class);
types.put(PropertiesOverlay.class, ObjectNode.class);
Map<Class<?>, List<Class<? extends JsonNode>>> types = new HashMap<>();
types.put(StringOverlay.class, Arrays.asList(TextNode.class));
types.put(BooleanOverlay.class, Arrays.asList(BooleanNode.class));
types.put(IntegerOverlay.class, Arrays.asList(IntNode.class, ShortNode.class, BigIntegerNode.class));
types.put(NumberOverlay.class, Arrays.asList(NumericNode.class));
types.put(PrimitiveOverlay.class, Arrays.asList(TextNode.class, NumericNode.class, BooleanNode.class));
types.put(ObjectOverlay.class, Arrays.asList(JsonNode.class));
types.put(MapOverlay.class, Arrays.asList(ObjectNode.class));
types.put(ListOverlay.class, Arrays.asList(ArrayNode.class));
types.put(PropertiesOverlay.class, Arrays.asList(ObjectNode.class));
allowedJsonTypes = types;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.Maps;

public class NumericUtils {
public static boolean isNumeric(Object obj) {
return NumericType.of(obj) != null;
Expand Down Expand Up @@ -162,7 +161,7 @@ private NumericType(Class<? extends Number> cls) {

private void register(Class<? extends Number> cls, NumericType type) {
if (NumericType.types == null)
NumericType.types = Maps.newHashMap();
NumericType.types = new HashMap<>();
types.put(cls, type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import static com.reprezen.kaizen.oasparser.val.ValidationResults.Severity.NONE;
import static com.reprezen.kaizen.oasparser.val.ValidationResults.Severity.WARNING;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.common.collect.Lists;
import com.reprezen.jsonoverlay.Overlay;
import com.reprezen.jsonoverlay.PositionInfo;

Expand Down Expand Up @@ -82,7 +82,7 @@ public boolean ge(Severity other) {
}
};

List<ValidationItem> items = Lists.newArrayList();
List<ValidationItem> items = new ArrayList<>();

public <V> void addInfo(String msg, Overlay<V> context) {
items.add(new ValidationItem(INFO, msg, context));
Expand Down
Loading

0 comments on commit 172ae39

Please sign in to comment.