Skip to content

Commit 5b877fd

Browse files
committed
Kobby Maven Tutorial
1 parent 9b2416f commit 5b877fd

21 files changed

Lines changed: 1400 additions & 1 deletion

File tree

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.war
15+
*.nar
16+
*.ear
17+
*.zip
18+
*.tar.gz
19+
*.rar
20+
21+
# IDEA
22+
*.iml
23+
24+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25+
hs_err_pid*
26+
/.gradle/
27+
/.idea/
28+
build/
29+
target/
30+
31+
# OS X DS_Store
32+
.DS_Store
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
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+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
# kobby-maven-tutorial
1+
[![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen)](https://github.com/ermadmi78/kobby-maven-tutorial/blob/main/LICENSE)
2+
3+
### Kobby Maven Tutorial
4+
5+
The GraphQL Client DSL code in this tutorial is generated using the [Kobby Plugin](https://github.com/ermadmi78/kobby).
6+
7+
1. Clone this tutorial
8+
1. See GraphQL schema [here](https://github.com/ermadmi78/kobby-maven-tutorial/blob/main/kobby-maven-tutorial-cinema-api/src/main/resources/io/github/ermadmi78/kobby/cinema/api/cinema.graphqls)
9+
1. Start server: `./mvnw -pl kobby-maven-tutorial-cinema-server -am spring-boot:run`
10+
1. Try to execute GraphQL queries in [console](http://localhost:8080/playground) (for example `query { films { id title } }`)
11+
1. Start client: `./mvnw -pl kobby-maven-tutorial-cinema-client -am spring-boot:run`
12+
1. See queries, generated by Kobby DSL in client output
13+
1. See client source code [here](https://github.com/ermadmi78/kobby-maven-tutorial/blob/main/kobby-maven-tutorial-cinema-client/src/main/kotlin/io/github/ermadmi78/kobby/cinema/client/application.kt)
14+
1. Just try to write your own query by means of Kobby DSL!
15+
16+
A more sophisticated example of a GraphQL service with API customization,
17+
integration tests, and Spring Security can be found [here](https://github.com/ermadmi78/kobby-maven-example).
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.github.ermadmi78</groupId>
9+
<artifactId>kobby-maven-tutorial</artifactId>
10+
<version>0.0.0-SNAPSHOT</version>
11+
</parent>
12+
<artifactId>kobby-maven-tutorial-cinema-api</artifactId>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>io.github.ermadmi78</groupId>
18+
<artifactId>kobby-maven-plugin</artifactId>
19+
<version>${kobby.version}</version>
20+
<executions>
21+
<execution>
22+
<phase>generate-sources</phase>
23+
<goals>
24+
<goal>generate-kotlin</goal>
25+
</goals>
26+
</execution>
27+
</executions>
28+
</plugin>
29+
</plugins>
30+
</build>
31+
32+
<dependencies>
33+
<!--Add this dependency to enable Jackson annotation generation in DTO classes-->
34+
<dependency>
35+
<groupId>com.fasterxml.jackson.core</groupId>
36+
<artifactId>jackson-annotations</artifactId>
37+
<version>${jackson.version}</version>
38+
<scope>compile</scope>
39+
</dependency>
40+
41+
<!--Add this dependency to enable default Ktor adapters generation-->
42+
<dependency>
43+
<groupId>io.ktor</groupId>
44+
<artifactId>ktor-client-cio-jvm</artifactId>
45+
<version>${ktor.version}</version>
46+
<scope>compile</scope>
47+
</dependency>
48+
</dependencies>
49+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
type Query {
2+
film(id: ID!): Film
3+
films: [Film!]!
4+
}
5+
6+
type Mutation {
7+
createFilm(title: String!): Film!
8+
}
9+
10+
type Subscription {
11+
filmCreated: Film!
12+
}
13+
14+
type Film {
15+
id: ID!
16+
title: String!
17+
actors: [Actor!]!
18+
}
19+
20+
type Actor {
21+
id: ID!
22+
firstName: String!
23+
lastName: String
24+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.github.ermadmi78</groupId>
9+
<artifactId>kobby-maven-tutorial</artifactId>
10+
<version>0.0.0-SNAPSHOT</version>
11+
</parent>
12+
<artifactId>kobby-maven-tutorial-cinema-client</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.github.ermadmi78</groupId>
17+
<artifactId>kobby-maven-tutorial-cinema-api</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>com.fasterxml.jackson.module</groupId>
28+
<artifactId>jackson-module-kotlin</artifactId>
29+
<version>${jackson.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.fasterxml.jackson.module</groupId>
33+
<artifactId>jackson-module-parameter-names</artifactId>
34+
<version>${jackson.version}</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.jetbrains.kotlinx</groupId>
39+
<artifactId>kotlinx-coroutines-core</artifactId>
40+
<version>${kotlinx.coroutines.version}</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>io.ktor</groupId>
45+
<artifactId>ktor-client-cio-jvm</artifactId>
46+
<version>${ktor.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.ktor</groupId>
50+
<artifactId>ktor-client-jackson</artifactId>
51+
<version>${ktor.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>io.ktor</groupId>
55+
<artifactId>ktor-client-websockets-jvm</artifactId>
56+
<version>${ktor.version}</version>
57+
</dependency>
58+
</dependencies>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-maven-plugin</artifactId>
65+
<version>${spring.boot.version}</version>
66+
<configuration>
67+
<fork>true</fork>
68+
<skip>false</skip>
69+
</configuration>
70+
<executions>
71+
<execution>
72+
<goals>
73+
<goal>repackage</goal>
74+
</goals>
75+
</execution>
76+
</executions>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
</project>

0 commit comments

Comments
 (0)