Skip to content

Commit af2ca39

Browse files
Li Xucp2boston
Li Xu
authored andcommitted
RCB-539 (#113)
* Preparing release. Version set to 1.8.0-SNAPSHOT * [maven-release-plugin] prepare release rosette-api-java-binding-1.8.0 * [maven-release-plugin] prepare for next development iteration * [maven-release-plugin] rollback the release of rosette-api-java-binding-1.8.0 * [maven-release-plugin] prepare release rosette-api-java-binding-1.8.0 * [maven-release-plugin] prepare for next development iteration * Tej 1058 linking confidence rosapi 1.8 (#110) * TEJ-1058: added linkingConfidence to EntityMention * TEJ-1058: test data * Tej 1058 sentiment (#112) * [maven-release-plugin] prepare release rosette-api-java-binding-1.8.1 * [maven-release-plugin] prepare for next development iteration * TEJ-1058: added linking confidence in EntitySentiment. * [maven-release-plugin] prepare release rosette-api-java-binding-1.8.2 * [maven-release-plugin] prepare for next development iteration * RCB-539 add missing file * RCB-539: style cleanup javadoc error ignore until delombok is in place * RCB-539: more checkstyle * RCB-539: more perm gen for java7 * NameDeduplicationExample - reverted to string representation of data to comply with slate update scripts * RCB-539: use proper version * Delombok - to generate JavaDoc javadoc modifications - to point to delombok source * RCB-539: purge unused classes * Fixed site:site compile * Potential winner! - Generates model javadoc during mvn clean install - Generates target/site/apidocs during mvn site:site * lombok update to plugin - Address PMD violations by not fully qualifying warning suppression * RCB-539: lombok'ed batch models since the backend uses it even though not public * RCB-539: site/javadoc seems to work * RCB-539: clean up a bit * RCB-539: back to cp2's earlier stage * RCB-539: urgly javadoc:aggreate workaround * RCB-539: work around jackson builder problem * RCB-539: same treatment for AdmReq * RCB-539: bump version * [maven-release-plugin] prepare release rosette-api-java-binding-1.8.104 * [maven-release-plugin] prepare for next development iteration * RCB-539: more updates - changed from org.reflections to guava - updated bnd to embedd bytebuddy, no shaing - bring back a couple mixins * RCB-539: use annotation to generate mixins * RCB-539: fix pmd and checkstyle * RCB-539: allow simple name input
1 parent fdedaf0 commit af2ca39

File tree

157 files changed

+1564
-7929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+1564
-7929
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target/
44
pom.xml.tag
55
pom.xml.releaseBackup
66
pom.xml.next
7+
**/dependency-reduced-pom.xml
78
release.properties
89
mockserver*log
910
**/.DS_Store

annotations/bnd.bnd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bundle-Version: ${osgi-version}
2+
Export-Package: com.basistech.rosette.annotations

annotations/pom.xml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2017 Basis Technology Corp.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<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">
18+
<modelVersion>4.0.0</modelVersion>
19+
<parent>
20+
<groupId>com.basistech.rosette</groupId>
21+
<artifactId>rosette-api-java-binding</artifactId>
22+
<version>1.8.106-SNAPSHOT</version>
23+
</parent>
24+
<artifactId>rosette-api-annotations</artifactId>
25+
<name>rosette-api-annotations</name>
26+
<description>Rosette API Annotations</description>
27+
<dependencies>
28+
<dependency>
29+
<groupId>com.fasterxml.jackson.core</groupId>
30+
<artifactId>jackson-annotations</artifactId>
31+
<scope>provided</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.fasterxml.jackson.core</groupId>
35+
<artifactId>jackson-databind</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.squareup</groupId>
40+
<artifactId>javapoet</artifactId>
41+
<version>1.9.0</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.projectlombok</groupId>
46+
<artifactId>lombok</artifactId>
47+
<version>1.16.18</version>
48+
<scope>provided</scope>
49+
</dependency>
50+
</dependencies>
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>biz.aQute.bnd</groupId>
55+
<artifactId>bnd-maven-plugin</artifactId>
56+
</plugin>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-compiler-plugin</artifactId>
60+
<configuration>
61+
<compilerArgument>-proc:none</compilerArgument>
62+
</configuration>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-jar-plugin</artifactId>
67+
<configuration>
68+
<archive>
69+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
70+
</archive>
71+
</configuration>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
</project>
+9-9
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.basistech.rosette.apimodel.jackson;
17+
package com.basistech.rosette.annotations;
1818

19-
import com.fasterxml.jackson.annotation.JsonCreator;
20-
import com.fasterxml.jackson.annotation.JsonProperty;
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
2123

22-
public class TransliterationOptionsMixin extends BaseMixin {
23-
@JsonCreator
24-
protected TransliterationOptionsMixin(@JsonProperty("reversed") final Boolean reversed) {
25-
//
26-
}
27-
}
24+
@Retention(RetentionPolicy.SOURCE)
25+
@Target(ElementType.TYPE)
26+
public @interface JacksonMixin {
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright 2017 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.annotations;
18+
19+
import com.fasterxml.jackson.annotation.JsonInclude;
20+
import com.fasterxml.jackson.annotation.JsonTypeName;
21+
import com.fasterxml.jackson.databind.Module;
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
24+
import com.squareup.javapoet.AnnotationSpec;
25+
import com.squareup.javapoet.CodeBlock;
26+
import com.squareup.javapoet.JavaFile;
27+
import com.squareup.javapoet.MethodSpec;
28+
import com.squareup.javapoet.TypeSpec;
29+
import lombok.Builder;
30+
31+
import javax.annotation.processing.AbstractProcessor;
32+
import javax.annotation.processing.ProcessingEnvironment;
33+
import javax.annotation.processing.RoundEnvironment;
34+
import javax.lang.model.SourceVersion;
35+
import javax.lang.model.element.Element;
36+
import javax.lang.model.element.ElementKind;
37+
import javax.lang.model.element.Modifier;
38+
import javax.lang.model.element.TypeElement;
39+
import javax.tools.Diagnostic;
40+
import java.io.IOException;
41+
import java.util.Arrays;
42+
import java.util.Collections;
43+
import java.util.HashMap;
44+
import java.util.HashSet;
45+
import java.util.Map;
46+
import java.util.Set;
47+
48+
public class JacksonMixinProcessor extends AbstractProcessor {
49+
50+
private static final String PACKAGE_NAME = "com.basistech.rosette.apimodel.jackson";
51+
52+
private ProcessingEnvironment processingEnvironment;
53+
54+
@Override
55+
public synchronized void init(ProcessingEnvironment processingEnvironment) {
56+
super.init(processingEnvironment);
57+
this.processingEnvironment = processingEnvironment;
58+
}
59+
60+
@Override
61+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
62+
if (roundEnvironment.getElementsAnnotatedWith(JacksonMixin.class).isEmpty()) {
63+
return true;
64+
}
65+
Map<String, String> addMixinCode = new HashMap<>();
66+
for (Element element : roundEnvironment.getElementsAnnotatedWith(JacksonMixin.class)) {
67+
if (element.getKind() != ElementKind.CLASS) {
68+
processingEnvironment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Annotation only available to Class");
69+
continue;
70+
}
71+
TypeElement typeElement = (TypeElement) element;
72+
String elementQualifiedName = typeElement.getQualifiedName().toString();
73+
String elementSimpleName = typeElement.getSimpleName().toString();
74+
if (typeElement.getAnnotation(Builder.class) != null) {
75+
TypeSpec.Builder mixinClassBuilder = TypeSpec
76+
.classBuilder(typeElement.getSimpleName().toString() + "Mixin")
77+
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
78+
.addAnnotation(AnnotationSpec.builder(JsonTypeName.class)
79+
.addMember("value", "$S", typeElement.getSimpleName())
80+
.build())
81+
.addAnnotation(AnnotationSpec.builder(JsonDeserialize.class)
82+
.addMember("builder", CodeBlock.builder()
83+
.add(elementQualifiedName + "." + elementSimpleName + "Builder.class").build())
84+
.build())
85+
.addAnnotation(AnnotationSpec.builder(JsonInclude.class)
86+
.addMember("value", CodeBlock.builder()
87+
.add("JsonInclude.Include.NON_NULL").build())
88+
.build())
89+
.addType(TypeSpec
90+
.classBuilder(typeElement.getSimpleName().toString() + "MixinBuilder")
91+
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
92+
.addAnnotation(AnnotationSpec.builder(JsonPOJOBuilder.class)
93+
.addMember("withPrefix", "$S", "")
94+
.build()).build());
95+
try {
96+
String packageName = elementQualifiedName.substring(0, elementQualifiedName.lastIndexOf("."))
97+
+ ".jackson";
98+
JavaFile.builder(packageName, mixinClassBuilder.build())
99+
.build()
100+
.writeTo(processingEnvironment.getFiler());
101+
addMixinCode.put(elementQualifiedName + ".class",
102+
packageName + "." + typeElement.getSimpleName().toString() + "Mixin" + ".class");
103+
addMixinCode.put(elementQualifiedName + "." + elementSimpleName + "Builder.class",
104+
packageName + "." + typeElement.getSimpleName().toString()
105+
+ "Mixin." + typeElement.getSimpleName().toString() + "MixinBuilder.class");
106+
} catch (IOException e) {
107+
e.printStackTrace();
108+
}
109+
}
110+
}
111+
112+
MethodSpec.Builder methodSpecBuilder = MethodSpec.methodBuilder("addMixins")
113+
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
114+
.addParameter(Module.SetupContext.class, "context");
115+
for (String key : addMixinCode.keySet()) {
116+
methodSpecBuilder.addStatement(" context.setMixInAnnotations($L, $L)", key, addMixinCode.get(key));
117+
}
118+
TypeSpec.Builder mixinUtilClassBuilder = TypeSpec
119+
.classBuilder("MixinUtil")
120+
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
121+
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
122+
.addMember("value", "$S", "PMD")
123+
.build())
124+
.addMethod(methodSpecBuilder.build());
125+
try {
126+
JavaFile.builder(PACKAGE_NAME, mixinUtilClassBuilder.build())
127+
.build()
128+
.writeTo(processingEnvironment.getFiler());
129+
} catch (IOException e) {
130+
e.printStackTrace();
131+
}
132+
133+
return true;
134+
}
135+
136+
@Override
137+
public Set<String> getSupportedAnnotationTypes() {
138+
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(JacksonMixin.class.getCanonicalName())));
139+
}
140+
141+
@Override
142+
public SourceVersion getSupportedSourceVersion() {
143+
return SourceVersion.latestSupported();
144+
}
145+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.basistech.rosette.annotations.JacksonMixinProcessor

api/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@
160160
</execution>
161161
</executions>
162162
</plugin>
163+
<plugin>
164+
<groupId>org.apache.maven.plugins</groupId>
165+
<artifactId>maven-surefire-plugin</artifactId>
166+
<configuration>
167+
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
168+
</configuration>
169+
</plugin>
163170
</plugins>
164171
<resources>
165172
<resource>

api/src/main/java/com/basistech/rosette/api/HttpRosetteAPI.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Basis Technology Corp.
2+
* Copyright 2017 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -374,9 +374,9 @@ private <T extends Response> void responseHeadersToExtendedInformation(T resp, H
374374
currentSetValue = new HashSet<>(Collections.singletonList(resp.getExtendedInformation().get(header.getName())));
375375
}
376376
currentSetValue.add(header.getValue());
377-
resp.setExtendedInformation(header.getName(), currentSetValue);
377+
resp.addExtendedInformation(header.getName(), currentSetValue);
378378
} else {
379-
resp.setExtendedInformation(header.getName(), header.getValue());
379+
resp.addExtendedInformation(header.getName(), header.getValue());
380380
}
381381
}
382382
}
@@ -529,7 +529,8 @@ private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> cla
529529
errorContent = "(no body)";
530530
}
531531
// something not from us at all
532-
throw new HttpRosetteAPIException("Invalid error response (not json)", new ErrorResponse("invalidErrorResponse", errorContent), status);
532+
throw new HttpRosetteAPIException("Invalid error response (not json)",
533+
ErrorResponse.builder().code("invalidErrorResponse").message(errorContent).build(), status);
533534
}
534535
} else {
535536
return mapper.readValue(inputStream, clazz);

0 commit comments

Comments
 (0)