use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class AnalyticsTest method projectPersisted.
@Test
void projectPersisted(Vertx vertx, VertxTestContext testContext) {
Instant createdOn = Instant.now().truncatedTo(MINUTES);
VertxProject vertxProject = new VertxProject().setId("should-not-persist").setGroupId("should-not-persist").setArtifactId("should-not-persist").setPackageName("should-not-persist").setCreatedOn(createdOn).setOperatingSystem("Other");
vertx.eventBus().publish(Topics.PROJECT_CREATED, vertxProject);
Checkpoint checkpoint = testContext.laxCheckpoint();
vertx.setPeriodic(20, id -> {
JsonObject query = new JsonObject();
client.find(AnalyticsService.COLLECTION_NAME, query, testContext.succeeding(list -> {
testContext.verify(() -> {
assertTrue(list.size() <= 1);
if (list.size() == 1) {
JsonObject document = list.get(0);
assertFalse(Stream.of("id", "groupId", "artifactId", "packageName").anyMatch(document::containsKey));
assertEquals(createdOn, document.getJsonObject("createdOn").getInstant("$date"));
assertEquals(vertxProject.getOperatingSystem(), document.getString("operatingSystem"));
checkpoint.flag();
assertTrue(vertx.cancelTimer(id));
}
});
}));
});
}
use of io.vertx.starter.model.VertxProject 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()));
});
}));
}
});
}));
}));
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class AnalyticsService method onProjectCreated.
public void onProjectCreated(Message<VertxProject> message) {
log.debug("Building analytics with on new project created");
VertxProject project = message.body();
JsonObject document = toDocument(project);
mongoClient.save(COLLECTION_NAME, document, res -> {
if (res.failed()) {
log.error("Failed to save document", res.cause());
}
});
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class GeneratorService method onProjectRequested.
public Buffer onProjectRequested(VertxProject project) throws Exception {
ArchiveOutputStreamFactory factory;
ArchiveFormat archiveFormat = project.getArchiveFormat();
if (archiveFormat == ArchiveFormat.TGZ) {
factory = baos -> new TarArchiveOutputStream(new GzipCompressorOutputStream(baos));
} else if (archiveFormat == ArchiveFormat.ZIP) {
factory = baos -> new ZipArchiveOutputStream(baos);
} else {
throw new IllegalArgumentException("Unsupported archive format: " + archiveFormat.getFileExtension());
}
try (TempDir tempDir = TempDir.create();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ArchiveOutputStream out = factory.create(baos)) {
createProject(project, tempDir);
generateArchive(tempDir, out);
out.finish();
out.close();
return Buffer.buffer(baos.toByteArray());
}
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class GeneratorVerticle method onProjectRequested.
private void onProjectRequested(Message<VertxProject> msg) {
VertxProject project = msg.body();
vertx.executeBlocking(fut -> {
try {
fut.complete(generatorService.onProjectRequested(project));
} catch (Exception e) {
fut.fail(e);
}
}, false, ar -> {
if (ar.succeeded()) {
msg.reply(ar.result());
} else {
log.error("Failed to generate project " + project.getId(), ar.cause());
msg.fail(-1, ar.cause().getMessage());
}
});
}
Aggregations