-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update java application prototype to match online sample
- Loading branch information
Showing
16 changed files
with
325 additions
and
44 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...ified-plugin/plugin-jvm/src/main/resources/templates/java-application/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# declarative-samples-java-app | ||
A sample Java application written in the Declarative Gradle DSL, using the prototype Declarative Gradle `javaApplication` Software Type defined in the `org.gradle.experimental.jvm-ecosystem` ecosystem plugin. | ||
|
||
## Building and Running | ||
|
||
This sample shows the definition of a multiproject Java application implemented using Java 17 source code. | ||
The project is the result of converting the project produced by the `gradle init` command in Gradle 8.9. | ||
|
||
To build and test the application without running, use: | ||
|
||
```shell | ||
> ./gradlew build | ||
``` | ||
|
||
To run the application, use: | ||
|
||
```shell | ||
> ./gradlew run | ||
``` |
8 changes: 8 additions & 0 deletions
8
...fied-plugin/plugin-jvm/src/main/resources/templates/java-application/app/build.gradle.dcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
javaApplication { | ||
mainClass = "org.example.app.App" | ||
|
||
dependencies { | ||
implementation("org.apache.commons:commons-text:1.11.0") | ||
implementation(project(":utilities")) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../src/main/resources/templates/java-application/app/src/main/java/org/example/app/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.app; | ||
|
||
import org.example.list.LinkedList; | ||
|
||
import static org.example.utilities.StringUtils.join; | ||
import static org.example.utilities.StringUtils.split; | ||
import static org.example.app.MessageUtils.getMessage; | ||
|
||
import org.apache.commons.text.WordUtils; | ||
|
||
public class App { | ||
public static void main(String[] args) { | ||
LinkedList tokens; | ||
tokens = split(getMessage()); | ||
String result = join(tokens); | ||
System.out.println(WordUtils.capitalize(result)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../resources/templates/java-application/app/src/main/java/org/example/app/MessageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.app; | ||
|
||
class MessageUtils { | ||
public static String getMessage() { | ||
return "Hello World!"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ources/templates/java-application/app/src/test/java/org/example/app/MessageUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.app; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class MessageUtilsTest { | ||
@Test void testGetMessage() { | ||
assertEquals("Hello World!", MessageUtils.getMessage()); | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
.../unified-plugin/plugin-jvm/src/main/resources/templates/java-application/build.gradle.dcl
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...ied-plugin/plugin-jvm/src/main/resources/templates/java-application/list/build.gradle.dcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
javaLibrary {} |
81 changes: 81 additions & 0 deletions
81
.../resources/templates/java-application/list/src/main/java/org/example/list/LinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.list; | ||
|
||
public class LinkedList { | ||
private Node head; | ||
|
||
public void add(String element) { | ||
Node newNode = new Node(element); | ||
|
||
Node it = tail(head); | ||
if (it == null) { | ||
head = newNode; | ||
} else { | ||
it.next = newNode; | ||
} | ||
} | ||
|
||
private static Node tail(Node head) { | ||
Node it; | ||
|
||
for (it = head; it != null && it.next != null; it = it.next) {} | ||
|
||
return it; | ||
} | ||
|
||
public boolean remove(String element) { | ||
boolean result = false; | ||
Node previousIt = null; | ||
Node it = null; | ||
for (it = head; !result && it != null; previousIt = it, it = it.next) { | ||
if (0 == element.compareTo(it.data)) { | ||
result = true; | ||
unlink(previousIt, it); | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private void unlink(Node previousIt, Node currentIt) { | ||
if (currentIt == head) { | ||
head = currentIt.next; | ||
} else { | ||
previousIt.next = currentIt.next; | ||
} | ||
} | ||
|
||
public int size() { | ||
int size = 0; | ||
|
||
for (Node it = head; it != null; ++size, it = it.next) {} | ||
|
||
return size; | ||
} | ||
|
||
public String get(int index) { | ||
Node it = head; | ||
while (index > 0 && it != null) { | ||
it = it.next; | ||
index--; | ||
} | ||
|
||
if (it == null) { | ||
throw new IndexOutOfBoundsException("Index is out of range"); | ||
} | ||
|
||
return it.data; | ||
} | ||
|
||
private static class Node { | ||
final String data; | ||
Node next; | ||
|
||
Node(String data) { | ||
this.data = data; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ources/templates/java-application/list/src/test/java/org/example/list/LinkedListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.list; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class LinkedListTest { | ||
@Test void testConstructor() { | ||
LinkedList list = new LinkedList(); | ||
assertEquals(0, list.size()); | ||
} | ||
|
||
@Test void testAdd() { | ||
LinkedList list = new LinkedList(); | ||
|
||
list.add("one"); | ||
assertEquals(1, list.size()); | ||
assertEquals("one", list.get(0)); | ||
|
||
list.add("two"); | ||
assertEquals(2, list.size()); | ||
assertEquals("two", list.get(1)); | ||
} | ||
|
||
@Test void testRemove() { | ||
LinkedList list = new LinkedList(); | ||
|
||
list.add("one"); | ||
list.add("two"); | ||
assertTrue(list.remove("one")); | ||
|
||
assertEquals(1, list.size()); | ||
assertEquals("two", list.get(0)); | ||
|
||
assertTrue(list.remove("two")); | ||
assertEquals(0, list.size()); | ||
} | ||
|
||
@Test public void testRemoveMissing() { | ||
LinkedList list = new LinkedList(); | ||
|
||
list.add("one"); | ||
list.add("two"); | ||
assertFalse(list.remove("three")); | ||
assertEquals(2, list.size()); | ||
} | ||
} |
43 changes: 41 additions & 2 deletions
43
...ified-plugin/plugin-jvm/src/main/resources/templates/java-application/settings.gradle.dcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
pluginManagement { | ||
repositories { | ||
google() // for Android plugin | ||
google() // Needed for the Android plugin, applied by the unified plugin | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
plugins { | ||
id("org.gradle.experimental.jvm-ecosystem") version "0.1.10" | ||
id("org.gradle.experimental.jvm-ecosystem") version "0.1.7" | ||
} | ||
|
||
rootProject.name = "example-java-app" | ||
|
||
include("app") | ||
include("list") | ||
include("utilities") | ||
|
||
defaults { | ||
javaLibrary { | ||
javaVersion = 17 | ||
|
||
dependencies { | ||
implementation("org.apache.commons:commons-text:1.11.0") | ||
} | ||
|
||
testing { | ||
dependencies { | ||
implementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
runtimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
} | ||
} | ||
|
||
javaApplication { | ||
javaVersion = 17 | ||
|
||
dependencies { | ||
implementation("org.apache.commons:commons-text:1.11.0") | ||
} | ||
|
||
testing { | ||
testJavaVersion = 21 | ||
dependencies { | ||
implementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
runtimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
} | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
...ugin-jvm/src/main/resources/templates/java-application/src/main/java/com/example/App.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...-jvm/src/main/resources/templates/java-application/src/test/java/com/example/AppTest.java
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...lugin/plugin-jvm/src/main/resources/templates/java-application/utilities/build.gradle.dcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
javaLibrary { | ||
dependencies { | ||
api(project(":list")) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/templates/java-application/utilities/src/main/java/org/example/utilities/JoinUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.utilities; | ||
|
||
import org.example.list.LinkedList; | ||
|
||
class JoinUtils { | ||
public static String join(LinkedList source) { | ||
StringBuilder result = new StringBuilder(); | ||
for (int i = 0; i < source.size(); ++i) { | ||
if (result.length() > 0) { | ||
result.append(" "); | ||
} | ||
result.append(source.get(i)); | ||
} | ||
|
||
return result.toString(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../templates/java-application/utilities/src/main/java/org/example/utilities/SplitUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.utilities; | ||
|
||
import org.example.list.LinkedList; | ||
|
||
class SplitUtils { | ||
public static LinkedList split(String source) { | ||
int lastFind = 0; | ||
int currentFind = 0; | ||
LinkedList result = new LinkedList(); | ||
|
||
while ((currentFind = source.indexOf(" ", lastFind)) != -1) { | ||
String token = source.substring(lastFind); | ||
if (currentFind != -1) { | ||
token = token.substring(0, currentFind - lastFind); | ||
} | ||
|
||
addIfValid(token, result); | ||
lastFind = currentFind + 1; | ||
} | ||
|
||
String token = source.substring(lastFind); | ||
addIfValid(token, result); | ||
|
||
return result; | ||
} | ||
|
||
private static void addIfValid(String token, LinkedList list) { | ||
if (isTokenValid(token)) { | ||
list.add(token); | ||
} | ||
} | ||
|
||
private static boolean isTokenValid(String token) { | ||
return !token.isEmpty(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...templates/java-application/utilities/src/main/java/org/example/utilities/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* This source file was generated by the Gradle 'init' task | ||
*/ | ||
package org.example.utilities; | ||
|
||
import org.example.list.LinkedList; | ||
|
||
public class StringUtils { | ||
public static String join(LinkedList source) { | ||
return JoinUtils.join(source); | ||
} | ||
|
||
public static LinkedList split(String source) { | ||
return SplitUtils.split(source); | ||
} | ||
} |