Search in sources :

Example 1 with Language

use of io.vertx.starter.model.Language in project vertx-starter by vert-x3.

the class GeneratorTest method testProject.

private void testProject(VertxProject project, Vertx vertx, VertxTestContext testContext) {
    vertx.eventBus().<Buffer>request(Topics.PROJECT_REQUESTED, project, testContext.succeeding(msg -> {
        unpack(vertx, testContext, workdir, msg.body(), testContext.succeeding(unpacked -> {
            testContext.verify(() -> {
                verifyBaseFiles();
                BuildTool buildTool = project.getBuildTool();
                Language language = project.getLanguage();
                if (buildTool == MAVEN) {
                    verifyMavenFiles();
                } else if (buildTool == GRADLE) {
                    verifyGradleFiles(language);
                } else {
                    testContext.failNow(new NoStackTraceThrowable(unsupported(buildTool)));
                    return;
                }
                try {
                    verifySourceFiles(language);
                } catch (IOException e) {
                    throw new AssertionError(e);
                }
                if (Utils.isWindows()) {
                    testContext.completeNow();
                } else {
                    buildProject(vertx, buildTool, testContext.succeeding(projectBuilt -> {
                        testContext.verify(() -> {
                            if (buildTool == MAVEN) {
                                try {
                                    verifyMavenOutputFiles();
                                } catch (IOException e) {
                                    throw new AssertionError(e);
                                }
                            } else if (buildTool == GRADLE) {
                                try {
                                    verifyGradleOutputFiles();
                                } catch (IOException e) {
                                    throw new AssertionError(e);
                                }
                            } else {
                                testContext.failNow(new NoStackTraceThrowable(unsupported(buildTool)));
                            }
                            runDevMode(vertx, buildTool, testContext.succeeding(devModeRan -> testContext.completeNow()));
                        });
                    }));
                }
            });
        }));
    }));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxTestContext(io.vertx.junit5.VertxTestContext) java.util(java.util) io.vertx.core(io.vertx.core) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Process(com.julienviet.childprocess.Process) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JdkVersion(io.vertx.starter.model.JdkVersion) KOTLIN(io.vertx.starter.model.Language.KOTLIN) GeneratorVerticle(io.vertx.starter.GeneratorVerticle) VertxProjectCodec(io.vertx.starter.VertxProjectCodec) Utils(io.vertx.core.impl.Utils) Timeout(io.vertx.junit5.Timeout) MAVEN(io.vertx.starter.model.BuildTool.MAVEN) JAVA(io.vertx.starter.model.Language.JAVA) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) GRADLE(io.vertx.starter.model.BuildTool.GRADLE) RecordParser(io.vertx.core.parsetools.RecordParser) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) BuildTool(io.vertx.starter.model.BuildTool) Path(java.nio.file.Path) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) MethodSource(org.junit.jupiter.params.provider.MethodSource) OutputStream(java.io.OutputStream) AssumptionViolatedException(org.junit.AssumptionViolatedException) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Files(java.nio.file.Files) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) TGZ(io.vertx.starter.model.ArchiveFormat.TGZ) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) VertxExtension(io.vertx.junit5.VertxExtension) Util(io.vertx.starter.Util) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Topics(io.vertx.starter.config.Topics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) Language(io.vertx.starter.model.Language) org.junit.jupiter.api(org.junit.jupiter.api) ProcessOptions(com.julienviet.childprocess.ProcessOptions) VertxProject(io.vertx.starter.model.VertxProject) Language(io.vertx.starter.model.Language) BuildTool(io.vertx.starter.model.BuildTool) IOException(java.io.IOException) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 2 with Language

use of io.vertx.starter.model.Language in project vertx-starter by vert-x3.

the class GeneratorService method createProject.

private void createProject(VertxProject project, TempDir tempDir) throws IOException {
    log.trace("Generating project: {}", project);
    Map<String, Object> ctx = new HashMap<>();
    ctx.put("buildTool", project.getBuildTool().name().toLowerCase());
    String groupId = project.getGroupId();
    ctx.put("groupId", groupId);
    String artifactId = project.getArtifactId();
    ctx.put("artifactId", artifactId);
    Language language = project.getLanguage();
    ctx.put("language", language.name().toLowerCase());
    ctx.put("vertxVersion", project.getVertxVersion());
    Set<String> vertxDependencies = project.getVertxDependencies();
    if (vertxDependencies == null) {
        vertxDependencies = new HashSet<>();
    }
    boolean hasVertxUnit = vertxDependencies.remove("vertx-unit");
    ctx.put("hasVertxUnit", hasVertxUnit);
    boolean hasVertxJUnit5 = vertxDependencies.remove("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("vertxDependencies", vertxDependencies);
    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");
    if (project.getBuildTool() == GRADLE) {
        copy(tempDir, "files/gradle", "gradlew");
        copy(tempDir, "files/gradle", "gradlew.bat");
        if (project.getLanguage() == KOTLIN) {
            copy(tempDir, "files/gradle", "gradle.properties");
        }
        copy(tempDir, "files/gradle", "gradle/wrapper/gradle-wrapper.jarr");
        copy(tempDir, "files/gradle", "gradle/wrapper/gradle-wrapper.properties");
        render(tempDir, ctx, ".", "build.gradle.kts");
        render(tempDir, ctx, ".", "settings.gradle.kts");
    } else if (project.getBuildTool() == MAVEN) {
        copy(tempDir, "files/maven", "mvnw");
        copy(tempDir, "files/maven", "mvnw.cmd");
        copy(tempDir, "files/maven", "_mvn/wrapper/maven-wrapper.jarr");
        copy(tempDir, "files/maven", "_mvn/wrapper/maven-wrapper.properties");
        copy(tempDir, "files/maven", "_mvn/wrapper/MavenWrapperDownloader.java");
        render(tempDir, ctx, ".", "pom.xml");
    } else {
        throw new RuntimeException("Unsupported build tool: " + project.getBuildTool());
    }
    String packageDir = packageName.replace('.', '/');
    String srcDir = "src/main/" + language.getName();
    render(tempDir, ctx, srcDir, "MainVerticle" + language.getExtension(), srcDir + "/" + packageDir);
    String testSrcDir = "src/test/" + language.getName();
    render(tempDir, ctx, testSrcDir, "TestMainVerticle" + language.getExtension(), testSrcDir + "/" + packageDir);
    render(tempDir, ctx, ".", "README.adoc");
}
Also used : Path(java.nio.file.Path) Language(io.vertx.starter.model.Language)

Example 3 with Language

use of io.vertx.starter.model.Language in project vertx-starter by vert-x3.

the class GeneratorTest method testProjectsJdk8.

static Stream<VertxProject> testProjectsJdk8() throws IOException {
    List<String> versions = Util.loadStarterData().getJsonArray("versions").stream().map(JsonObject.class::cast).map(obj -> obj.getString("number")).filter(version -> !version.endsWith("-SNAPSHOT")).collect(toList());
    List<Set<String>> testDeps = Arrays.asList(Collections.singleton("vertx-unit"), Collections.singleton("vertx-junit5"));
    Stream.Builder<VertxProject> builder = Stream.builder();
    for (BuildTool buildTool : BuildTool.values()) {
        for (Language language : Language.values()) {
            for (String version : versions) {
                for (Set<String> vertxDependencies : testDeps) {
                    VertxProject vertxProject = defaultProject().setBuildTool(buildTool).setLanguage(language).setVertxVersion(version).setVertxDependencies(new HashSet<>(vertxDependencies)).setPackageName("com.mycompany.project.special");
                    builder.add(vertxProject);
                }
            }
        }
    }
    return builder.build();
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) java.util(java.util) io.vertx.core(io.vertx.core) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Process(com.julienviet.childprocess.Process) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JdkVersion(io.vertx.starter.model.JdkVersion) KOTLIN(io.vertx.starter.model.Language.KOTLIN) GeneratorVerticle(io.vertx.starter.GeneratorVerticle) VertxProjectCodec(io.vertx.starter.VertxProjectCodec) Utils(io.vertx.core.impl.Utils) Timeout(io.vertx.junit5.Timeout) MAVEN(io.vertx.starter.model.BuildTool.MAVEN) JAVA(io.vertx.starter.model.Language.JAVA) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) GRADLE(io.vertx.starter.model.BuildTool.GRADLE) RecordParser(io.vertx.core.parsetools.RecordParser) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) BuildTool(io.vertx.starter.model.BuildTool) Path(java.nio.file.Path) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) MethodSource(org.junit.jupiter.params.provider.MethodSource) OutputStream(java.io.OutputStream) AssumptionViolatedException(org.junit.AssumptionViolatedException) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Files(java.nio.file.Files) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) TGZ(io.vertx.starter.model.ArchiveFormat.TGZ) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) VertxExtension(io.vertx.junit5.VertxExtension) Util(io.vertx.starter.Util) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Topics(io.vertx.starter.config.Topics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) Language(io.vertx.starter.model.Language) org.junit.jupiter.api(org.junit.jupiter.api) ProcessOptions(com.julienviet.childprocess.ProcessOptions) VertxProject(io.vertx.starter.model.VertxProject) Language(io.vertx.starter.model.Language) VertxProject(io.vertx.starter.model.VertxProject) BuildTool(io.vertx.starter.model.BuildTool) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) OutputStream(java.io.OutputStream) Stream(java.util.stream.Stream)

Aggregations

Language (io.vertx.starter.model.Language)3 Path (java.nio.file.Path)3 Process (com.julienviet.childprocess.Process)2 ProcessOptions (com.julienviet.childprocess.ProcessOptions)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)2 io.vertx.core (io.vertx.core)2 Buffer (io.vertx.core.buffer.Buffer)2 NoStackTraceThrowable (io.vertx.core.impl.NoStackTraceThrowable)2 Utils (io.vertx.core.impl.Utils)2 JsonObject (io.vertx.core.json.JsonObject)2 RecordParser (io.vertx.core.parsetools.RecordParser)2 Timeout (io.vertx.junit5.Timeout)2 VertxExtension (io.vertx.junit5.VertxExtension)2 VertxTestContext (io.vertx.junit5.VertxTestContext)2 GeneratorVerticle (io.vertx.starter.GeneratorVerticle)2 Util (io.vertx.starter.Util)2 VertxProjectCodec (io.vertx.starter.VertxProjectCodec)2 Topics (io.vertx.starter.config.Topics)2 TGZ (io.vertx.starter.model.ArchiveFormat.TGZ)2 BuildTool (io.vertx.starter.model.BuildTool)2