Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc runtime fixes and improvements #191

Merged
merged 3 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime/dependency-lister/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.5.2</version>
<version>3.5.4</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down Expand Up @@ -72,7 +72,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.5.2</version>
<version>3.5.4</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
*/
package org.apache.camel.k.tooling.maven.dependency;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -45,16 +45,10 @@
@Mojo(
name = "generate-dependency-list",
defaultPhase = LifecyclePhase.PREPARE_PACKAGE,
requiresProject = true,
threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
@SuppressWarnings({ "PMD.GodClass", "PMD.TooManyFields", "PMD.TooManyMethods" })
public class DependencyListerMojo extends AbstractMojo {

@Component
private ArtifactFactory artifactFactory;

@Parameter(readonly = true, defaultValue = "${project}")
private MavenProject project;

Expand All @@ -63,26 +57,21 @@ public class DependencyListerMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
List<Map<String, String>> deps = new ArrayList<>();

project.getArtifacts().stream().filter(this::isCompileOrRuntime).forEach(artifact -> {
Map<String, String> dep = new HashMap<>();
dep.put("id", artifact.getId());
final Path output = Paths.get(this.destination);

if (artifact.getFile() != null) {
dep.put("location", artifact.getFile().getAbsolutePath());
}

deps.add(dep);
try {
if (Files.notExists(output.getParent())) {
Files.createDirectories(output.getParent());
}
);

File dest = new File(destination);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
} catch (IOException e) {
throw new MojoExecutionException("Exception while generating dependencies list", e);
}

try (Writer writer = new FileWriter(dest)) {
try (Writer writer = Files.newBufferedWriter(output, StandardCharsets.UTF_8)) {
List<Map<String, String>> deps = project.getArtifacts().stream()
.filter(this::isCompileOrRuntime)
.map(this::artifactToMap)
.collect(Collectors.toList());

DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Expand All @@ -98,4 +87,15 @@ private boolean isCompileOrRuntime(Artifact artifact) {
return StringUtils.equals(artifact.getScope(), DefaultArtifact.SCOPE_COMPILE)
|| StringUtils.equals(artifact.getScope(), DefaultArtifact.SCOPE_RUNTIME);
}

private Map<String, String> artifactToMap(Artifact artifact) {
Map<String, String> dep = new HashMap<>();
dep.put("id", artifact.getId());

if (artifact.getFile() != null) {
dep.put("location", artifact.getFile().getAbsolutePath());
}

return dep;
}
}
4 changes: 2 additions & 2 deletions runtime/examples/kotlin-routes.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ from("timer:kotlin?period=1s")
.setBody()
.constant("Hello Camel K!")
.process().message {
m -> m.headers["RandomValue"] = rnd.nextInt()
it.headers["RandomValue"] = rnd.nextInt()
}
.to("log:info?showHeaders=true")
.to("log:info?showAll=true&multiline=true")
14 changes: 11 additions & 3 deletions runtime/groovy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@
*/
package org.apache.camel.k.groovy.dsl


import org.apache.camel.util.IntrospectionSupport

import java.lang.reflect.Array

class ComponentConfiguration {
private final org.apache.camel.Component component

ComponentConfiguration(org.apache.camel.Component component) {
this.component = component
}

def methodMissing(String name, args) {
def methodMissing(String name, arguments) {
final Object value
final Object[] args = arguments as Object[]

if (args == null) {
value = null
} else if (!args.getClass().isArray()) {
value = args
} else if (Array.getLength(args) == 1) {
value = Array.get(args, 0)
} else if (args.length == 1) {
value = args[0]
} else {
throw new IllegalArgumentException("Unable to set property \"" + name + "\" on component \"" + name + "\"")
}
Expand All @@ -52,13 +48,13 @@ class ComponentConfiguration {
}

if (!IntrospectionSupport.setProperty(component, name, value, true)) {
throw new MissingMethodException("Missing method \"" + name + "\" on component: \"" + this.component.class.name + "\"")
throw new MissingMethodException(name, this.component.class, args as Object[])
}
}

def propertyMissing(String name, value) {
if (!IntrospectionSupport.setProperty(component, name, value, true)) {
throw new MissingMethodException("Missing method \"" + name + "\" on component: \"" + this.component.class.name + "\"")
throw new MissingMethodException(name, this.component.class, value)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package org.apache.camel.k.groovy.dsl
import org.apache.camel.CamelContext
import org.apache.camel.Component

import java.lang.reflect.Array

class ComponentsConfiguration {
private final CamelContext context

Expand Down Expand Up @@ -60,25 +58,27 @@ class ComponentsConfiguration {
throw new IllegalArgumentException("Type mismatch, expected: " + type + ", got: " + component.class)
}

def methodMissing(String name, args) {
if (args != null && args.getClass().isArray()) {
if (Array.getLength(args) == 1) {
def clos = Array.get(args, 0)
def methodMissing(String name, arguments) {
final Object[] args = arguments as Object[]

if (args != null) {
if (args.length == 1) {
def clos = args[0]

if (clos instanceof Closure) {
return component(name, clos)
}
}
if (Array.getLength(args) == 2) {
def type = Array.get(args, 0)
def clos = Array.get(args, 1)
if (args.length == 2) {
def type = args[0]
def clos = args[1]

if (type instanceof Class && Component.class.isAssignableFrom(type) && clos instanceof Closure) {
return component(name,type, clos)
}
}
}

throw new MissingMethodException("Missing method: \"$name\", args: $args")
throw new MissingMethodException(name, this, args)
}
}

This file was deleted.

6 changes: 2 additions & 4 deletions runtime/groovy/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
</Console>
<File name="FILE" fileName="target/camel-k-runtime-groovy-test.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
</File>
<Null name="NONE"/>
</Appenders>


<Loggers>
<Root level="INFO">
<!--<AppenderRef ref="STDOUT"/>-->
<AppenderRef ref="FILE"/>
<AppenderRef ref="NONE"/>
</Root>
</Loggers>

Expand Down
13 changes: 10 additions & 3 deletions runtime/jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,18 @@
<!-- ****************************** -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void configure() throws Exception {
}

// Wrap routes builder
addRoutes(
includeRoutes(
Reflect.compile(name, IOUtils.toString(is, StandardCharsets.UTF_8)).create().get()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.camel.component.seda.SedaComponent;
import org.apache.camel.main.MainListenerSupport;
import org.apache.camel.main.MainSupport;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;

public class RoutesLoadersTest {

Expand Down Expand Up @@ -112,22 +113,27 @@ public void testLoadXml() throws Exception {
assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testResourceWithoutScheme() {
RoutesLoaders.loaderFor("routes.js", null);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> RoutesLoaders.loaderFor("routes.js", null)
);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testResourceWithIllegalScheme() {
RoutesLoaders.loaderFor("http:routes.js", null);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> RoutesLoaders.loaderFor("http:routes.js", null)
);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testUnsupportedLanguage() {
RoutesLoaders.loaderFor(" test", null);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> RoutesLoaders.loaderFor(" test", null)
);
}


public static class MyRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
Expand Down
6 changes: 2 additions & 4 deletions runtime/jvm/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
</Console>
<File name="FILE" fileName="target/camel-k-runtime-jmv-test.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
</File>
<Null name="NONE"/>
</Appenders>

<Loggers>
<Root level="INFO">
<!--<AppenderRef ref="STDOUT"/>-->
<AppenderRef ref="FILE"/>
<AppenderRef ref="NONE"/>
</Root>
</Loggers>

Expand Down
Loading