Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
kgough committed Aug 24, 2017
2 parents 950f487 + db75338 commit 4c7d1a6
Show file tree
Hide file tree
Showing 86 changed files with 3,012 additions and 1,004 deletions.
Expand Up @@ -46,7 +46,7 @@
*/
@Path(AccountResource.SERVICE_PATH)
@ResourceLabel("User Account")
public interface AccountResource extends RestResource {
public interface AccountResource {
public static final String SERVICE_PATH =
"/accounts/u/{username:[a-z\\d_]{3,20}}";

Expand Down
Expand Up @@ -58,7 +58,7 @@
@ResponseCode(code = 500,
condition = "If there is an unexpected error in the server while performing this operation")
})
public interface AsynchronousProcessResource extends RestResource {
public interface AsynchronousProcessResource {
public static final String SERVICE_PATH = "/async";

/**
Expand Down
Expand Up @@ -45,7 +45,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Copy Trans")
public interface CopyTransResource extends RestResource {
public interface CopyTransResource {
public static final String SERVICE_PATH = "/copytrans";

/**
Expand Down
Expand Up @@ -50,7 +50,7 @@
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
@ResourceLabel("Files")
public interface FileResource extends RestResource {
public interface FileResource {
public static final String SERVICE_PATH = "/file";
@Deprecated
public static final String FILE_RESOURCE = SERVICE_PATH;
Expand Down
Expand Up @@ -69,7 +69,7 @@
@ResponseCode(code = 500,
condition = "If there is an unexpected error in the server while performing this operation")
})
public interface GlossaryResource extends RestResource {
public interface GlossaryResource {
public static final String SERVICE_PATH = "/glossary";

/**
Expand Down
Expand Up @@ -24,7 +24,7 @@
*/
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public interface LocalesResource extends RestResource {
public interface LocalesResource {

public static final String SERVICE_PATH = "/locales";

Expand Down
Expand Up @@ -43,7 +43,7 @@
@Path(ProjectIterationLocalesResource.SERVICE_PATH)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Version Locales")
public interface ProjectIterationLocalesResource extends RestResource {
public interface ProjectIterationLocalesResource {
@SuppressWarnings("deprecation")
public static final String SERVICE_PATH = ProjectIterationResource.SERVICE_PATH
+ "/locales";
Expand Down
Expand Up @@ -49,7 +49,7 @@
@Deprecated
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public interface ProjectIterationResource extends RestResource {
public interface ProjectIterationResource {
public static final String ITERATION_SLUG_TEMPLATE = "{iterationSlug:"
+ RestConstants.SLUG_PATTERN + "}";
public static final String SERVICE_PATH = ProjectResource.SERVICE_PATH
Expand Down
Expand Up @@ -43,7 +43,7 @@
@Path(ProjectLocalesResource.SERVICE_PATH)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Project locales")
public interface ProjectLocalesResource extends RestResource {
public interface ProjectLocalesResource {
public static final String SERVICE_PATH = ProjectResource.SERVICE_PATH
+ "/locales";

Expand Down
Expand Up @@ -50,7 +50,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Project")
public interface ProjectResource extends RestResource {
public interface ProjectResource {
public static final String PROJECT_SLUG_TEMPLATE = "{projectSlug:"
+ RestConstants.SLUG_PATTERN + "}";
public static final String SERVICE_PATH = "/projects/p/"
Expand Down
Expand Up @@ -54,7 +54,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Project Version")
public interface ProjectVersionResource extends RestResource {
public interface ProjectVersionResource {
public static final String PROJECT_SERVICE_PATH = "/project";

public static final String VERSION_SLUG_TEMPLATE = "/{versionSlug:"
Expand Down
Expand Up @@ -47,7 +47,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Project List")
public interface ProjectsResource extends RestResource {
public interface ProjectsResource {
public static final String SERVICE_PATH = "/projects";

/**
Expand Down
Expand Up @@ -28,7 +28,9 @@
*
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
* @deprecated REST Resource implementations are discovered by the presence of
* {@code @Path} only (not inherited), as per spec.
*/
@Deprecated
public interface RestResource extends Serializable {
}
Expand Up @@ -56,7 +56,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Source Documents")
public interface SourceDocResource extends RestResource {
public interface SourceDocResource {
@SuppressWarnings("deprecation")
String SERVICE_PATH = ProjectIterationResource.SERVICE_PATH;
String RESOURCE_PATH = "/r";
Expand Down
Expand Up @@ -47,7 +47,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("Statistics")
public interface StatisticsResource extends RestResource {
public interface StatisticsResource {
public static final String DATE_FORMAT = "yyyy-MM-dd";

public static final String SERVICE_PATH = "/stats";
Expand Down
Expand Up @@ -67,7 +67,7 @@
@ResponseCode(code = 500,
condition = "If there is an unexpected error in the server while performing this operation")
})
public interface TranslatedDocResource extends RestResource {
public interface TranslatedDocResource {
@SuppressWarnings("deprecation")
public static final String SERVICE_PATH = ProjectIterationResource.SERVICE_PATH;

Expand Down
Expand Up @@ -49,7 +49,7 @@
@Produces({ MediaType.APPLICATION_XML /* , "application/x-tmx" */})
@Consumes({ MediaType.APPLICATION_XML /* , "application/x-tmx" */})
@ResourceLabel("Translation Memory")
public interface TranslationMemoryResource extends RestResource {
public interface TranslationMemoryResource {
public static final String SERVICE_PATH = "/tm";

public static final String PREFERRED_MEDIA_TYPE = MediaType.APPLICATION_XML;
Expand Down
Expand Up @@ -41,7 +41,7 @@
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ResourceLabel("System Version")
public interface VersionResource extends RestResource {
public interface VersionResource {
public static final String SERVICE_PATH = "/version";

/**
Expand Down
8 changes: 1 addition & 7 deletions server/pom.xml
Expand Up @@ -476,12 +476,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.atteo.classindex</groupId>
<artifactId>classindex</artifactId>
<version>3.4</version>
</dependency>

<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman</artifactId>
Expand Down Expand Up @@ -1378,7 +1372,7 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.19.0-GA</version>
<version>3.21.0-GA</version>
</dependency>

<dependency>
Expand Down
18 changes: 1 addition & 17 deletions server/services/pom.xml
Expand Up @@ -191,16 +191,6 @@
<configuration>
<sourceJar>true</sourceJar>
<testJar>true</testJar>

<!-- Recompile all sources if any source is recompiled! Hurts
incremental build performance.
Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=447546
If this proves too expensive, we could remove
org.atteo.classindex, return null in JaxRSApplication and
just let RESTEasy scan for @Path and @Provider classes at runtime.
-->
<proc>procEX</proc>
<annotationProcessors>org.zanata.util.JaxRSClassIndexProcessor</annotationProcessors>
</configuration>
</plugin>

Expand Down Expand Up @@ -404,11 +394,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.atteo.classindex</groupId>
<artifactId>classindex</artifactId>
</dependency>

<!-- Zanata-specific dependencies -->

<dependency>
Expand Down Expand Up @@ -992,8 +977,7 @@
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
<scope>test</scope>
<version>0.9.11</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
Expand Down
57 changes: 35 additions & 22 deletions server/services/src/main/java/org/zanata/rest/JaxRSApplication.java
@@ -1,16 +1,19 @@
package org.zanata.rest;

import com.google.common.collect.ImmutableSet;
import org.atteo.classindex.ClassIndex;
import org.zanata.rest.service.RestResource;
import org.jboss.resteasy.util.PickConstructor;
import org.reflections.Reflections;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static java.lang.System.currentTimeMillis;
import static java.lang.reflect.Modifier.isAbstract;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.Stream.concat;

@ApplicationPath("/rest")
Expand All @@ -19,40 +22,50 @@ public class JaxRSApplication extends javax.ws.rs.core.Application {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(JaxRSApplication.class);

private Set<Class<?>> classes = buildClassesSet();
private static final Set<Class<?>> classes = buildClassesSet();
private static final String PACKAGE_PREFIX = "org.zanata";

@Override
public Set<Class<?>> getClasses() {
return classes;
}

/**
* Collect all classes annotated with {@code @Path} or {@code @Provider},
* except in the packages {@code org.zanata.rest.client} and
* {@code org.zanata.rest.enunciate}.
* Collect all non-abstract Zanata classes annotated with {@code @Path} or
* {@code @Provider}, except in the package {@code org.zanata.rest.client}.
*
* @return resource and provider classes
*/
private static Set<Class<?>> buildClassesSet() {
Iterable<Class<? extends RestResource>> resourceClasses =
ClassIndex.getSubclasses(RestResource.class);
log.debug("Indexed RestResource classes: {}", resourceClasses);
Iterable<Class<?>> pathClasses = ClassIndex.getAnnotated(Path.class);
long start = currentTimeMillis();
Reflections reflections = new Reflections(PACKAGE_PREFIX);
Set<Class<?>> pathClasses =
reflections.getTypesAnnotatedWith(Path.class);
log.debug("Indexed @Path classes: {}", pathClasses);
Iterable<Class<?>> providerClasses =
ClassIndex.getAnnotated(Provider.class);
Set<Class<?>> providerClasses =
reflections.getTypesAnnotatedWith(Provider.class);
log.debug("Indexed @Provider classes: {}", providerClasses);
ImmutableSet<Class<?>> classes = concat(stream(resourceClasses), concat(
stream(pathClasses),
stream(providerClasses))).filter(clazz -> !clazz.getName()
Stream<Class<?>> concatStream = concat(
pathClasses.stream(),
providerClasses.stream());
ImmutableSet<Class<?>> classes = concatStream
// we don't want to pick up our JAX-RS client proxies
.filter(clazz -> !clazz.getName()
.startsWith("org.zanata.rest.client."))
.collect(Collectors.collectingAndThen(
Collectors.toSet(), ImmutableSet::copyOf));
log.info("Found {} JAX-RS classes in total", classes.size());
.filter(JaxRSApplication::canConstruct)
.collect(collectingAndThen(toSet(), ImmutableSet::copyOf));
long timeTaken = currentTimeMillis() - start;
log.info("Found {} JAX-RS classes in total; took {} ms", classes.size(),
timeTaken);
log.debug("JAX-RS classes: {}", classes);
return classes;
}

private static <T> Stream<T> stream(Iterable<T> iterable) {
return StreamSupport.stream(iterable.spliterator(), false);
private static boolean canConstruct(Class<?> clazz) {
return !isAbstract(clazz.getModifiers()) &&
// RESTEasy can use no-args constructor, or any constructor
// with @Context args. This method should find either, but not
// org.zanata.rest.service.raw.SourceAndTranslationResourceRestBase.TestSourceDocResource.
PickConstructor.pickPerRequestConstructor(clazz) != null;
}
}
Expand Up @@ -10,14 +10,13 @@

import org.zanata.rest.service.RestConstants;
import org.zanata.rest.editor.MediaTypes;
import org.zanata.rest.service.RestResource;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public interface ProjectResource extends RestResource {
public interface ProjectResource {

public static final String PROJECT_SLUG_TEMPLATE = "/{projectSlug:"
+ RestConstants.SLUG_PATTERN + "}";
Expand Down
@@ -1,7 +1,5 @@
package org.zanata.rest.editor.service.resource;

import org.zanata.rest.service.RestResource;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -16,7 +14,7 @@

@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public interface StatisticResource extends RestResource {
public interface StatisticResource {
public static final String SERVICE_PATH = "/stats";

/**
Expand Down
Expand Up @@ -21,7 +21,6 @@
package org.zanata.rest.editor.service.resource;

import org.zanata.rest.editor.MediaTypes;
import org.zanata.rest.service.RestResource;
import org.zanata.webtrans.shared.rest.TransMemoryMergeResource;

import javax.ws.rs.*;
Expand All @@ -34,7 +33,7 @@
*/
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public interface SuggestionsResource extends RestResource,
public interface SuggestionsResource extends
TransMemoryMergeResource {

String SERVICE_PATH = "/suggestions";
Expand Down
Expand Up @@ -8,14 +8,13 @@
import javax.ws.rs.core.Response;

import org.zanata.rest.editor.MediaTypes;
import org.zanata.rest.service.RestResource;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public interface TextFlowResource extends RestResource {
public interface TextFlowResource {

public static final String SERVICE_PATH = "/source";

Expand Down
Expand Up @@ -9,14 +9,13 @@
import javax.ws.rs.core.Response;

import org.zanata.rest.editor.MediaTypes;
import org.zanata.rest.service.RestResource;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public interface TransUnitResource extends RestResource {
public interface TransUnitResource {

public static final String SERVICE_PATH = "/source+trans/{localeId}";

Expand Down

0 comments on commit 4c7d1a6

Please sign in to comment.