Skip to content

Commit

Permalink
Merge pull request #21 from jamezp/formatting
Browse files Browse the repository at this point in the history
Mass reformat and introduce maven plugin to format code when the sour…
  • Loading branch information
jamezp authored Nov 2, 2021
2 parents 64c1bbb + b4417bf commit d33992a
Show file tree
Hide file tree
Showing 101 changed files with 965 additions and 363 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ nbproject
# VS Code
**/.vscode/

.cache/

# macOS Files
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletContext;

import org.jboss.resteasy.core.ResteasyContext;
Expand Down
38 changes: 38 additions & 0 deletions ide-config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~
~ Copyright 2021 Red Hat, Inc., and individual contributors
~ as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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">

<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>38</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.resteasy.microprofile</groupId>
<artifactId>ide-config</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>RESTEasy MicroProfile IDE Configuration</name>
<packaging>jar</packaging>

</project>
390 changes: 390 additions & 0 deletions ide-config/src/main/resources/eclipse-format.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions ide-config/src/main/resources/eclipse.importorder
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Organize Import Order
0=java
1=javax
2=org
3=com
55 changes: 55 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<!-- Plugin Versions -->
<version.org.jboss.galleon>4.2.8.Final</version.org.jboss.galleon>
<version.org.wildfly.galleon-plugins>5.2.0.Final</version.org.wildfly.galleon-plugins>
<version.formatter-maven-plugin>2.17.0</version.formatter-maven-plugin>
<version.impsort-maven-plugin>1.6.2</version.impsort-maven-plugin>

<!-- Plugin Versions, please keep in alphabetical order -->
<version.org.jboss.resteasy.checkstyle>1.0.0.Final</version.org.jboss.resteasy.checkstyle>
Expand All @@ -98,6 +100,7 @@

<maven.test.skip>false</maven.test.skip>
<skipTests>${maven.test.skip}</skipTests>
<skip.format>false</skip.format>

<!-- Galleon -->
<galleon.fork.embedded>true</galleon.fork.embedded>
Expand All @@ -106,6 +109,7 @@
</properties>

<modules>
<module>ide-config</module>
<module>resteasy-microprofile-bom</module>
<module>resteasy-microprofile-test-bom</module>
<module>config</module>
Expand Down Expand Up @@ -207,6 +211,57 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${version.formatter-maven-plugin}</version>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ide-config</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<configFile>eclipse-format.xml</configFile>
<lineEnding>LF</lineEnding>
<removeTrailingWhitespace>true</removeTrailingWhitespace>
<skip>${skip.format}</skip>
</configuration>
<executions>
<execution>
<id>format</id>
<goals>
<goal>format</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${version.impsort-maven-plugin}</version>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<groups>java.,javax.,org.,com.</groups>
<staticGroups>*</staticGroups>
<skip>${skip.format}</skip>
<removeUnused>true</removeUnused>
</configuration>
<executions>
<execution>
<id>sort-imports</id>
<goals>
<goal>sort</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>

</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Feature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public Throwable toThrowable(Response response) {
response.bufferEntity();
} catch (Exception ignored) {
}
return WebApplicationExceptionWrapper.wrap(new WebApplicationException("Unknown error, status code " + response.getStatus(), response));
return WebApplicationExceptionWrapper
.wrap(new WebApplicationException("Unknown error, status code " + response.getStatus(), response));
}

@Override
public boolean handles(int status, MultivaluedMap headers) {
final Config config = ConfigProvider.getConfig();
final boolean originalBehavior = config.getOptionalValue(ResteasyContextParameters.RESTEASY_ORIGINAL_WEBAPPLICATIONEXCEPTION_BEHAVIOR, boolean.class)
final boolean originalBehavior = config
.getOptionalValue(ResteasyContextParameters.RESTEASY_ORIGINAL_WEBAPPLICATIONEXCEPTION_BEHAVIOR, boolean.class)
.orElse(false);
final boolean serverSide = ResteasyDeployment.onServer();
return status >= (originalBehavior || !serverSide ? 400 : 300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
Expand All @@ -38,7 +39,7 @@
* This implementation is a bit of a hack and dependent on Resteasy internals.
* We throw a ResponseProcessingExceptoin that hides the Response object
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ExceptionMapping implements ClientResponseFilter {
public static class HandlerException extends ResponseProcessingException {
private static final Logger LOGGER = Logger.getLogger(HandlerException.class);
Expand All @@ -57,8 +58,10 @@ public void mapException(final Method method) throws Exception {
handled.bufferEntity();
for (ResponseExceptionMapper mapper : candidates) {
Throwable exception = mapper.toThrowable(handled);
if (exception instanceof RuntimeException) throw (RuntimeException) exception;
if (exception instanceof Error) throw (Error) exception;
if (exception instanceof RuntimeException)
throw (RuntimeException) exception;
if (exception instanceof Error)
throw (Error) exception;
for (Class exc : method.getExceptionTypes()) {
if (exception != null && exc.isAssignableFrom(exception.getClass())) {
throw (Exception) exception;
Expand Down Expand Up @@ -91,11 +94,11 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re
}
}
}
if (candidates.isEmpty()) return;
if (candidates.isEmpty())
return;

candidates.sort(
(m1, m2) -> Integer.compare(m1.getPriority(), m2.getPriority())
);
(m1, m2) -> Integer.compare(m1.getPriority(), m2.getPriority()));
throw new HandlerException(responseContext, candidates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionException;

import javax.enterprise.inject.spi.InterceptionType;
import javax.enterprise.inject.spi.Interceptor;
import javax.interceptor.InvocationContext;
Expand All @@ -46,12 +47,12 @@ public class InvocationContextImpl implements InvocationContext {
private final List<InterceptorInvocation> chain;

public InvocationContextImpl(final Object target, final Method method, final Object[] args,
final List<InterceptorInvocation> chain) {
final List<InterceptorInvocation> chain) {
this(target, method, args, chain, 0);
}

private InvocationContextImpl(final Object target, final Method method, final Object[] args,
final List<InterceptorInvocation> chain, final int position) {
final List<InterceptorInvocation> chain, final int position) {
this.target = target;
this.method = method;
this.args = args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import static org.jboss.resteasy.microprofile.client.utils.ClientRequestContextUtils.getMethod;

import java.lang.reflect.Method;

import javax.annotation.Priority;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;


@Priority(Integer.MIN_VALUE)
public class MethodInjectionFilter implements ClientRequestFilter {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.core.EntityTag;
Expand Down Expand Up @@ -72,7 +73,6 @@ private RuntimeException notSupported() {
return ex;
}


@SuppressWarnings("unchecked")
@Override
public synchronized <T> T readEntity(Class<T> entityType) {
Expand All @@ -94,7 +94,6 @@ public static String readStringEntity(InputStream input) {
}
}


@Override
public <T> T readEntity(GenericType<T> entityType) {
throw notSupported();
Expand Down Expand Up @@ -206,7 +205,7 @@ public Link.Builder getLinkBuilder(String relation) {
}

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings({ "unchecked", "rawtypes" })
public MultivaluedMap<String, Object> getMetadata() {
return (MultivaluedMap) responseContext.getHeaders();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.jboss.resteasy.microprofile.client;


import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -36,6 +35,7 @@
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.CDI;
Expand Down Expand Up @@ -68,9 +68,9 @@ public class ProxyInvocationHandler implements InvocationHandler {
private final AtomicBoolean closed;

public ProxyInvocationHandler(final Class<?> restClientInterface,
final Object target,
final Set<Object> providerInstances,
final ResteasyClient client, final BeanManager beanManager) {
final Object target,
final Set<Object> providerInstances,
final ResteasyClient client, final BeanManager beanManager) {
this.target = target;
this.providerInstances = providerInstances;
this.client = client;
Expand Down Expand Up @@ -114,7 +114,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}

if (parameterAnnotations[index].length > 0) { // does a parameter converter apply?
ParamConverter<?> converter = ((ParamConverterProvider) p).getConverter(arg.getClass(), null, parameterAnnotations[index]);
ParamConverter<?> converter = ((ParamConverterProvider) p).getConverter(arg.getClass(), null,
parameterAnnotations[index]);
if (converter != null) {
Type[] genericTypes = getGenericTypes(converter.getClass());
if (genericTypes.length == 1) {
Expand Down Expand Up @@ -243,7 +244,8 @@ private static BeanManager getBeanManager(Class<?> restClientInterface) {
CDI<Object> current = CDI.current();
return current != null ? current.getBeanManager() : null;
} catch (IllegalStateException e) {
LOGGER.warnf("CDI container is not available - interceptor bindings declared on %s will be ignored", restClientInterface.getSimpleName());
LOGGER.warnf("CDI container is not available - interceptor bindings declared on %s will be ignored",
restClientInterface.getSimpleName());
return null;
}
}
Expand All @@ -267,12 +269,14 @@ private static Map<Method, List<InvocationContextImpl.InterceptorInvocation>> in

Annotation[] interceptorBindings = merge(methodLevelBindings, classLevelBindings);

List<Interceptor<?>> interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, interceptorBindings);
List<Interceptor<?>> interceptors = beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE,
interceptorBindings);
if (!interceptors.isEmpty()) {
List<InvocationContextImpl.InterceptorInvocation> chain = new ArrayList<>();
for (Interceptor<?> interceptor : interceptors) {
chain.add(new InvocationContextImpl.InterceptorInvocation(interceptor,
interceptorInstances.computeIfAbsent(interceptor, i -> beanManager.getReference(i, i.getBeanClass(), creationalContext))));
interceptorInstances.computeIfAbsent(interceptor,
i -> beanManager.getReference(i, i.getBeanClass(), creationalContext))));
}
chains.put(method, chain);
}
Expand Down
Loading

0 comments on commit d33992a

Please sign in to comment.