Skip to content

Commit

Permalink
PMD (#424)
Browse files Browse the repository at this point in the history
* code quality: add PMD profile (not enabled by default)

* code quality: fix PMD findings
  • Loading branch information
lburgazzoli authored Aug 17, 2020
1 parent def39b9 commit f82ef43
Show file tree
Hide file tree
Showing 49 changed files with 1,202 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.k.loader.groovy.dsl;
package org.apache.camel.k.loader.groovy.dsl

import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.CamelContext
import org.apache.camel.Component

public class Components {
private CamelContext context;
class Components {
private final CamelContext context

public Components(CamelContext context) {
this.context = context;
Components(CamelContext context) {
this.context = context
}

public Component get(String scheme) {
return context.getComponent(scheme, true);
Component get(String scheme) {
return context.getComponent(scheme, true)
}

public Component put(String scheme, Component instance) {
context.addComponent(scheme, instance);
Component put(String scheme, Component instance) {
context.addComponent(scheme, instance)

return instance;
}

public Component make(String scheme, String type) {
final Class<?> clazz = context.getClassResolver().resolveClass(type);
final Component instance = (Component)context.getInjector().newInstance(clazz);
Component make(String scheme, String type) {
final Class<?> clazz = context.getClassResolver().resolveClass(type)
final Component instance = (Component)context.getInjector().newInstance(clazz)

context.addComponent(scheme, instance);
context.addComponent(scheme, instance)

return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ private static void doLoad(Reader reader, EndpointRouteBuilder builder) {
//
// Expose IntegrationConfiguration methods to global scope.
//
context.eval(LANGUAGE_ID, ""
+ "Object.setPrototypeOf(globalThis, new Proxy(Object.prototype, {"
context.eval(
LANGUAGE_ID,
"Object.setPrototypeOf(globalThis, new Proxy(Object.prototype, {"
+ " has(target, key) {"
+ " return key in __dsl || key in target;"
+ " },"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.camel.Component;

public class Components {
private CamelContext context;
private final CamelContext context;

public Components(CamelContext context) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void configure() throws Exception {
LOGGER.debug("Loaded {} routes from {}", definitions.getRoutes().size(), source);
setRouteCollection(definitions);
}
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException ignored) {
// ignore
} catch (XmlPullParserException e) {
LOGGER.debug("Unable to load RoutesDefinition: {}", e.getMessage());
Expand All @@ -73,7 +73,7 @@ public void configure() throws Exception {
LOGGER.debug("Loaded {} rests from {}", definitions.getRests().size(), source);
setRestCollection(definitions);
}
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException ignored) {
// ignore
} catch (XmlPullParserException e) {
LOGGER.debug("Unable to load RestsDefinition: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public StepParserException(String message, String... properties) {
this.properties = Arrays.asList(properties);
}

public String getProcessor() {
return processor;
}

public List<String> getProperties() {
return properties;
}
Expand Down
5 changes: 5 additions & 0 deletions camel-k-main/camel-k-runtime-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
<artifactId>camel-k-runtime-knative</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-knative-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void afterConfigure(BaseMainSupport main) {

@Override
public void configure(CamelContext context) {
// no-op
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.camel.component.knative.KnativeComponent;
import org.apache.camel.component.knative.spi.Knative;
import org.apache.camel.component.knative.spi.KnativeEnvironment;
import org.apache.camel.component.knative.test.KnativeEnvironmentSupport;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.http.PlatformHttpServiceContextCustomizer;
import org.apache.camel.k.listener.ContextConfigurer;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void testLoadJavaSource() throws Exception {
public void testLoadJavaSourceWrap() throws Exception {
KnativeComponent component = new KnativeComponent();
component.setEnvironment(KnativeEnvironment.on(
KnativeEnvironment.endpoint(Knative.EndpointKind.sink, "sink", "localhost", AvailablePortFinder.getNextAvailable())
KnativeEnvironmentSupport.endpoint(Knative.EndpointKind.sink, "sink", "localhost", AvailablePortFinder.getNextAvailable())
));

PlatformHttpServiceContextCustomizer phsc = new PlatformHttpServiceContextCustomizer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.camel.k.quarkus.knative.deployment;

import java.util.Locale;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -64,7 +65,7 @@ public RouteBuilder routes() {
@Override
public void configure() throws Exception {
from("knative:endpoint/from")
.transform().body(String.class, b -> b.toUpperCase());
.transform().body(String.class, b -> b.toUpperCase(Locale.US));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.quarkus.ApplicationRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination;
import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem;
import org.apache.camel.quarkus.main.CamelMainApplication;
import org.apache.camel.quarkus.main.deployment.spi.CamelMainListenerBuildItem;
import org.apache.camel.spi.HasId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void afterConfigure(BaseMainSupport main) {

@Override
public void configure(CamelContext context) {
// no-op
}

@Override
Expand Down Expand Up @@ -103,20 +104,6 @@ private static void invokeListeners(List<Runtime.Listener> listeners, Runtime ru
});
}

private static Runtime on(CamelContext context) {
return new Runtime() {
@Override
public CamelContext getCamelContext() {
return context;
}

@Override
public void stop() throws Exception {
Quarkus.asyncExit();
}
};
}

private static Runtime on(BaseMainSupport main) {
return new Runtime() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
import org.apache.camel.k.support.PropertiesSupport;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ApplicationRuntimeConfigSourceProvider implements ConfigSourceProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationRuntimeConfigSourceProvider.class);

@Override
public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
final Properties applicationProperties = PropertiesSupport.loadProperties();
Expand Down
5 changes: 5 additions & 0 deletions camel-k-runtime-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
<artifactId>camel-knative-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-knative-test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CompositeClassloader extends ClassLoader {
private final List<ClassLoader> loaders = new CopyOnWriteArrayList<>();

public CompositeClassloader() {
// no parent
}

public CompositeClassloader(ClassLoader parent) {
Expand All @@ -38,8 +39,8 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
for (ClassLoader loader: loaders) {
try {
return loader.loadClass(name);
} catch (ClassNotFoundException e) {
// ignore
} catch (ClassNotFoundException ignored) {
// ignored
}
}

Expand Down
20 changes: 8 additions & 12 deletions camel-k-runtime-core/src/main/java/org/apache/camel/k/Sources.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public InMemory(String name, String language, String loader, byte[] content) {
this.language = language;
this.loader = loader;
this.interceptors = Collections.emptyList();
this.content = content;
this.content = Arrays.copyOf(content, content.length);
}

public InMemory(String name, String language, String loader, List<String> interceptors, byte[] content) {
this.name = name;
this.language = language;
this.loader = loader;
this.interceptors = new ArrayList<>(interceptors);
this.content = content;
this.content = Arrays.copyOf(content, content.length);
}

@Override
Expand Down Expand Up @@ -113,7 +113,7 @@ private static final class URI implements Source {
private final String name;
private final String language;
private final String loader;
private final List<String> interceptors;
private final String interceptors;
private final boolean compressed;

private URI(String uri) throws Exception {
Expand All @@ -125,12 +125,8 @@ private URI(String uri) throws Exception {

final String query = StringSupport.substringAfter(uri, "?");
final Map<String, Object> params = URISupport.parseQuery(query);
final String languageName = (String) params.get("language");
final String compression = (String) params.get("compression");
final String loader = (String) params.get("loader");
final String interceptors = (String) params.get("interceptors");

String language = languageName;
String language = (String) params.get("language");
if (ObjectHelper.isEmpty(language)) {
language = StringSupport.substringAfterLast(location, ":");
language = StringSupport.substringAfterLast(language, ".");
Expand All @@ -152,9 +148,9 @@ private URI(String uri) throws Exception {
this.location = location;
this.name = name;
this.language = language;
this.loader = loader;
this.interceptors = interceptors != null ? Arrays.asList(interceptors.split(",", -1)) : Collections.emptyList();
this.compressed = Boolean.parseBoolean(compression);
this.loader = (String) params.get("loader");
this.interceptors = (String) params.get("interceptors");
this.compressed = Boolean.parseBoolean((String) params.get("compression"));
}

@Override
Expand All @@ -174,7 +170,7 @@ public Optional<String> getLoader() {

@Override
public List<String> getInterceptors() {
return interceptors;
return interceptors != null ? Arrays.asList(interceptors.split(",", -1)) : Collections.emptyList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void accept(Runtime runtime) {
load(runtime, routes.split(",", -1));
}

protected void load(Runtime runtime, String[] routes) {
protected void load(Runtime runtime, String... routes) {
for (String route: routes) {
if (ObjectHelper.isEmpty(route)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;

import org.apache.camel.spi.PropertiesFunction;
import org.apache.camel.util.StringHelper;
Expand Down Expand Up @@ -54,7 +55,7 @@ public String apply(String remainder) {
return defaultValue;
}

Path file = this.root.resolve(name.toLowerCase()).resolve(property);
Path file = this.root.resolve(name.toLowerCase(Locale.US)).resolve(property);
if (Files.exists(file) && !Files.isDirectory(file)) {
try {
return Files.readString(file, StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Runtime getRuntime() {

@Override
public void beforeLoad(SourceLoader loader, Source source) {
// no-op
}

@Override
Expand Down Expand Up @@ -111,7 +112,7 @@ public Optional<Object> configuration() {
};
}

private static boolean shouldBeOverridden(String uri, String[] components) {
private static boolean shouldBeOverridden(String uri, String... components) {
if (uri == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

@Customizer("platform-http")
public class PlatformHttpServiceContextCustomizer extends VertxPlatformHttpServerConfiguration implements ContextCustomizer {
public PlatformHttpServiceContextCustomizer() {
}

@Override
public int getOrder() {
return Ordered.HIGHEST;
Expand Down
5 changes: 5 additions & 0 deletions camel-k-runtime-knative/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<artifactId>camel-k-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-knative-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel.k</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class KnativeSourceLoaderInterceptor implements SourceLoader.Interceptor

@Override
public void beforeLoad(SourceLoader loader, Source source) {
// no-op
}

@Override
Expand Down
Loading

0 comments on commit f82ef43

Please sign in to comment.