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

Add mutiny support #189

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54901cc
Merge pull request #1 from vert-x3/master
wowselim May 3, 2021
0c93937
Merge branch 'vert-x3:master' into master
wowselim May 27, 2021
6fafcbe
Merge branch 'vert-x3:master' into master
wowselim Jun 10, 2021
9d90949
add support for mutiny projects
wowselim Jun 17, 2021
647c80f
add separate stack for mutiny
wowselim Jun 20, 2021
309f536
fix wrong flavor name in templates
wowselim Jun 20, 2021
071c09f
remove obsolete artifact id prefix
wowselim Jun 20, 2021
75b2527
add flavor option to README.md
wowselim Jun 20, 2021
4e123d5
fix bug where mutiny dependencies were not checked
wowselim Jun 20, 2021
2cd1c19
remove "default" text from flavor in README.md
wowselim Jun 20, 2021
34c507d
fix bug with mixed mutiny & vertx deps
wowselim Jun 20, 2021
9730547
fix version bug with mixed mutiny & vertx deps
wowselim Jun 20, 2021
c86dfec
ignore isVertxDependency in jackson
wowselim Jun 20, 2021
b0b31e6
fix bug where groupId ends up wrong
wowselim Jun 26, 2021
3ca065d
make sure flavor deps are handled correctly
wowselim Jun 26, 2021
3575d46
Merge branch 'master' into add-mutiny-support
wowselim Jul 3, 2021
b886b1d
use Vert.x API instead of Flavor for website
wowselim Jul 5, 2021
e098a10
remove flavor ids from project constants
wowselim Jul 5, 2021
bdd8041
remove flavor from http request examples
wowselim Jul 5, 2021
24a9001
bump mutiny version to 2.8.0
wowselim Jul 5, 2021
03b4d28
switch from two stacks to boolean flag for mutiny bindings
wowselim Jul 5, 2021
fa9cb0a
add generator test for flavors
wowselim Jul 5, 2021
90a3fb9
add info about default flavor to readme
wowselim Jul 5, 2021
dc01e0c
add error msg for unsatisfiable dependencies
wowselim Jul 8, 2021
b231d26
bump mutiny version to 2.9.0
wowselim Jul 8, 2021
aceac49
add verticle & test code for mutiny flavor
wowselim Jul 8, 2021
f9907d0
set junit5 flag for mutiny projects
wowselim Jul 8, 2021
7a11188
fix bug that failed mutiny projects
wowselim Jul 8, 2021
9b85004
include flavor in VertxProject#toString
wowselim Jul 9, 2021
37612ce
don't include vertx depchain for mutiny
wowselim Jul 9, 2021
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: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ You can provide the following query parameters to customize the project
- `vertxDependencies`: a comma separated list of artifactIds of the vert.x modules
- `packageName`: code package name, derived from `groupId` and `artifactId` by default
- `jdkVersion`: which version of the JDK to use, defaults to `1.8`
- `flavor`: `vert.x` or `mutiny`

Full example:

```
curl -X GET \
'http://start.vertx.io/starter.zip?artifactId=starter&buildTool=maven&groupId=io.vertx&language=java&vertxDependencies=&vertxVersion=4.1.1' \
'http://start.vertx.io/starter.zip?artifactId=starter&buildTool=maven&groupId=io.vertx&language=java&vertxDependencies=&vertxVersion=4.1.1&flavor=vert.x' \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'http://start.vertx.io/starter.zip?artifactId=starter&buildTool=maven&groupId=io.vertx&language=java&vertxDependencies=&vertxVersion=4.1.1&flavor=vert.x' \
'https://start.vertx.io/starter.zip?artifactId=starter&buildTool=maven&groupId=io.vertx&language=java&vertxDependencies=&vertxVersion=4.1.1' \

Let's keep the default for simple examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in bdd8041

-o starter.zip
```

Expand All @@ -51,6 +52,7 @@ artitfactId==starter \
language==java \
buildTool==maven \
vertxVersion==4.1.1 \
flavor==vert.x \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
flavor==vert.x \

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in bdd8041

vertxDependencies==vertx-web,vertx-web-client \
-o starter.zip
```
Expand Down
65 changes: 58 additions & 7 deletions src/main/java/io/vertx/starter/ValidationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public class ValidationHandler implements Handler<RoutingContext> {
private final JsonObject defaults;
private final Set<String> versions;
private final Map<String, List<String>> exclusions;
private final Set<String> dependencies;
private final Map<String, Dependency> vertxStackDependencies;
private final Map<String, Dependency> mutinyStackDependencies;

public ValidationHandler(JsonObject defaults, JsonArray versions, JsonArray stack) {
public ValidationHandler(JsonObject defaults, JsonArray versions, JsonArray vertxStack, JsonArray mutinyStack) {
this.defaults = defaults;
this.versions = versions.stream()
.map(JsonObject.class::cast)
Expand All @@ -57,12 +58,26 @@ public ValidationHandler(JsonObject defaults, JsonArray versions, JsonArray stac
obj -> obj.getString("number"),
obj -> obj.getJsonArray("exclusions", new JsonArray()).stream().map(String.class::cast).collect(toList()))
);
dependencies = stack.stream()
vertxStackDependencies = vertxStack.stream()
.map(JsonObject.class::cast)
.flatMap(category -> category.getJsonArray("items").stream())
.map(JsonObject.class::cast)
.map(item -> item.getString("artifactId"))
.collect(toSet());
.collect(toMap(
item -> item.getString("artifactId"),
item -> new Dependency()
.setGroupId(item.getString("groupId"))
.setArtifactId(item.getString("artifactId")))
);
mutinyStackDependencies = mutinyStack.stream()
.map(JsonObject.class::cast)
.flatMap(category -> category.getJsonArray("items").stream())
.map(JsonObject.class::cast)
.collect(toMap(
item -> item.getString("artifactId"),
item -> new Dependency()
.setGroupId(item.getString("groupId"))
.setArtifactId(item.getString("artifactId")))
);
}

@Override
Expand All @@ -86,6 +101,10 @@ public void handle(RoutingContext rc) {
return;
}

if (!validateAndSetEnum(rc, FLAVOR, ProjectFlavor::fromId, vertxProject::setFlavor)) {
return;
}

String vertxVersion = getQueryParam(rc, VERTX_VERSION);
if (isNotBlank(vertxVersion)) {
if (!versions.contains(vertxVersion)) {
Expand All @@ -103,7 +122,21 @@ public void handle(RoutingContext rc) {
.map(String::toLowerCase)
.collect(toSet());

if (!dependencies.containsAll(vertxDependencies) ||
boolean areAllDependenciesSatisfiable;
if (vertxProject.getFlavor() == ProjectFlavor.VERTX) {
areAllDependenciesSatisfiable = vertxStackDependencies.keySet()
.containsAll(vertxDependencies);
} else if (vertxProject.getFlavor() == ProjectFlavor.MUTINY) {
areAllDependenciesSatisfiable = vertxDependencies.stream()
.allMatch(dependency ->
mutinyStackDependencies.keySet().stream()
.anyMatch(mutinyDependency -> mutinyDependency.endsWith(dependency))
);
} else {
throw new IllegalArgumentException("There's no stack for flavor " + vertxProject.getFlavor());
}

if (!areAllDependenciesSatisfiable ||
!Collections.disjoint(exclusions.get(vertxProject.getVertxVersion()), vertxDependencies)) {
fail(rc, VERTX_DEPENDENCIES, deps);
return;
Expand All @@ -114,7 +147,25 @@ public void handle(RoutingContext rc) {
return;
}

vertxProject.setVertxDependencies(vertxDependencies);
Set<Dependency> flavoredDependencies;
if (vertxProject.getFlavor() == ProjectFlavor.VERTX) {
flavoredDependencies = vertxDependencies.stream()
.map(vertxStackDependencies::get)
.collect(toSet());
} else if (vertxProject.getFlavor() == ProjectFlavor.MUTINY) {
flavoredDependencies = vertxDependencies.stream()
.map(dependency -> mutinyStackDependencies.keySet().stream()
.filter(mutinyDependency -> mutinyDependency.endsWith(dependency))
.findFirst())
.filter(Optional::isPresent)
.map(Optional::get)
.map(mutinyStackDependencies::get)
.collect(toSet());
} else {
throw new IllegalArgumentException("Unknown project flavor " + vertxProject.getFlavor());
}

vertxProject.setVertxDependencies(flavoredDependencies);
}

ArchiveFormat archiveFormat = ArchiveFormat.fromFilename(rc.request().path());
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/vertx/starter/WebVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public WebVerticle() {

JsonObject defaults = starterData.getJsonObject("defaults");
JsonArray versions = starterData.getJsonArray("versions");
JsonArray stack = starterData.getJsonArray("stack");
JsonArray vertxStack = starterData.getJsonArray("vertxStack");
JsonArray mutinyStack = starterData.getJsonArray("mutinyStack");

validationHandler = new ValidationHandler(defaults, versions, stack);
validationHandler = new ValidationHandler(defaults, versions, vertxStack, mutinyStack);
generationHandler = new GenerationHandler();
metadataHandler = new MetadataHandler(defaults, versions, stack);
metadataHandler = new MetadataHandler(defaults, versions, vertxStack, mutinyStack);

} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/vertx/starter/config/ProjectConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ public interface ProjectConstants {
String ARCHIVE_FORMAT = "archiveFormat";
String PACKAGE_NAME = "packageName";
String JDK_VERSION = "jdkVersion";
String FLAVOR = "flavor";
String MUTINY_FLAVOR = "mutiny";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is necessary. It can be stored as an enum value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in e098a10

String VERTX_FLAVOR = "vert.x";
}
54 changes: 54 additions & 0 deletions src/main/java/io/vertx/starter/model/Dependency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.vertx.starter.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.Objects;

public class Dependency {
private String groupId;
private String artifactId;

public String getGroupId() {
return groupId;
}

public Dependency setGroupId(String groupId) {
this.groupId = groupId;
return this;
}

public String getArtifactId() {
return artifactId;
}

public Dependency setArtifactId(String artifactId) {
this.artifactId = artifactId;
return this;
}

@JsonIgnore
public boolean isVertxDependency() {
return ProjectFlavor.VERTX.getGroupId().equals(groupId);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Dependency that = (Dependency) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId);
}

@Override
public String toString() {
return "Dependency{" +
"groupId='" + groupId + '\'' +
", artifactId='" + artifactId + '\'' +
'}';
}
}
42 changes: 42 additions & 0 deletions src/main/java/io/vertx/starter/model/ProjectFlavor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.vertx.starter.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Locale;

import static io.vertx.starter.config.ProjectConstants.MUTINY_FLAVOR;
import static io.vertx.starter.config.ProjectConstants.VERTX_FLAVOR;

public enum ProjectFlavor {
@JsonProperty(VERTX_FLAVOR)
VERTX(VERTX_FLAVOR, "io.vertx"),
@JsonProperty(MUTINY_FLAVOR)
MUTINY(MUTINY_FLAVOR, "io.smallrye.reactive");

private final String id;
private final String groupId;

ProjectFlavor(String id, String groupId) {
this.id = id;
this.groupId = groupId;
}

public String getId() {
return id;
}

public String getGroupId() {
return groupId;
}

public static ProjectFlavor fromId(String id) {
switch (id.toLowerCase(Locale.ROOT)) {
case MUTINY_FLAVOR:
return MUTINY;
case VERTX_FLAVOR:
return VERTX;
default:
return null;
}
}
}
16 changes: 13 additions & 3 deletions src/main/java/io/vertx/starter/model/VertxProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public class VertxProject {
private Language language;
private BuildTool buildTool;
private String vertxVersion;
private Set<String> vertxDependencies;
private Set<Dependency> vertxDependencies;
private ArchiveFormat archiveFormat;
private String packageName;
private JdkVersion jdkVersion;
private String operatingSystem;
private Instant createdOn;
private ProjectFlavor flavor;

public String getId() {
return id;
Expand Down Expand Up @@ -88,11 +89,11 @@ public VertxProject setVertxVersion(String vertxVersion) {
return this;
}

public Set<String> getVertxDependencies() {
public Set<Dependency> getVertxDependencies() {
return vertxDependencies;
}

public VertxProject setVertxDependencies(Set<String> vertxDependencies) {
public VertxProject setVertxDependencies(Set<Dependency> vertxDependencies) {
this.vertxDependencies = vertxDependencies;
return this;
}
Expand Down Expand Up @@ -142,6 +143,15 @@ public VertxProject setCreatedOn(Instant createdOn) {
return this;
}

public ProjectFlavor getFlavor() {
return flavor;
}

public VertxProject setFlavor(ProjectFlavor flavor) {
this.flavor = flavor;
return this;
}

@Override
public String toString() {
// DO NOT RETURN USER RELATED-DATA (groupId, artifactId, packageName)
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/vertx/starter/service/GeneratorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.templ.freemarker.FreeMarkerTemplateEngine;
import io.vertx.starter.model.ArchiveFormat;
import io.vertx.starter.model.Dependency;
import io.vertx.starter.model.Language;
import io.vertx.starter.model.VertxProject;
import org.apache.commons.compress.archivers.ArchiveEntry;
Expand Down Expand Up @@ -117,26 +118,26 @@ private void createProject(VertxProject project, TempDir tempDir) throws IOExcep
Language language = project.getLanguage();
ctx.put("language", language.name().toLowerCase());
ctx.put("vertxVersion", project.getVertxVersion());
Set<String> vertxDependencies = project.getVertxDependencies();
Set<Dependency> vertxDependencies = project.getVertxDependencies();
if (vertxDependencies == null) {
vertxDependencies = new HashSet<>();
}
boolean hasVertxUnit = vertxDependencies.remove("vertx-unit");
boolean hasVertxUnit = vertxDependencies
.removeIf(dependency -> dependency.getArtifactId().equals("vertx-unit"));
ctx.put("hasVertxUnit", hasVertxUnit);
boolean hasVertxJUnit5 = vertxDependencies.remove("vertx-junit5") || !hasVertxUnit;
boolean hasVertxJUnit5 = vertxDependencies
.removeIf(dependency -> dependency.getArtifactId().equals("vertx-junit5")) || !hasVertxUnit;
ctx.put("hasVertxJUnit5", hasVertxJUnit5);
if (hasVertxUnit && hasVertxJUnit5) {
throw new RuntimeException("You cannot generate a project which depends on both vertx-unit and vertx-junit5.");
}
vertxDependencies.addAll(language.getLanguageDependencies());
ctx.put("languageDependencies", language.getLanguageDependencies());
ctx.put("vertxDependencies", vertxDependencies);
ctx.put("flavor", project.getFlavor().getId());
String packageName = packageName(project);
ctx.put("packageName", packageName);
ctx.put("jdkVersion", project.getJdkVersion().getValue());

Path tempDirPath = tempDir.path();
String tempDirPathStr = tempDirPath.toString();

copy(tempDir, "files", "_editorconfig");
copy(tempDir, "files", "_gitignore");

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/io/vertx/starter/service/MetadataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.vertx.starter.model.BuildTool;
import io.vertx.starter.model.JdkVersion;
import io.vertx.starter.model.Language;
import io.vertx.starter.model.ProjectFlavor;

import java.util.Arrays;
import java.util.function.Function;
Expand All @@ -36,15 +37,17 @@ public class MetadataHandler implements Handler<RoutingContext> {

private final Buffer metadata;

public MetadataHandler(JsonObject defaults, JsonArray versions, JsonArray stack) {
public MetadataHandler(JsonObject defaults, JsonArray versions, JsonArray vertxStack, JsonArray mutinyStack) {
metadata = new JsonObject()
.put("defaults", defaults)
.put("versions", versions)
.put("stack", stack)
.put("stack", vertxStack)
.put("buildTools", values(BuildTool.values(), BuildTool::getValue))
.put("languages", values(Language.values(), Language::getName))
.put("jdkVersions", values(JdkVersion.values(), JdkVersion::getValue))
.put("vertxDependencies", stack) // deprecated
.put("flavors", values(ProjectFlavor.values(), ProjectFlavor::getId))
.put("vertxDependencies", vertxStack) // deprecated
.put("mutinyDependencies", mutinyStack) // deprecated
.put("vertxVersions", versions.stream() // deprecated
.map(JsonObject.class::cast)
.map(obj -> obj.getString("number"))
Expand Down
Loading