Search in sources :

Example 1 with IntegrationProjectGenerator

use of io.syndesis.integration.api.IntegrationProjectGenerator in project syndesis by syndesisio.

the class ProjectGeneratorTest method generate.

// *****************************
// Helpers
// *****************************
private Path generate(Integration integration, ProjectGeneratorConfiguration generatorConfiguration, TestResourceManager resourceManager) throws IOException {
    final IntegrationProjectGenerator generator = new ProjectGenerator(generatorConfiguration, resourceManager, getMavenProperties());
    try (InputStream is = generator.generate(integration)) {
        Path ret = testFolder.newFolder("integration-project").toPath();
        try (TarArchiveInputStream tis = new TarArchiveInputStream(is)) {
            TarArchiveEntry tarEntry = tis.getNextTarEntry();
            // tarIn is a TarArchiveInputStream
            while (tarEntry != null) {
                // create a file with the same name as the tarEntry
                File destPath = new File(ret.toFile(), tarEntry.getName());
                if (tarEntry.isDirectory()) {
                    destPath.mkdirs();
                } else {
                    destPath.getParentFile().mkdirs();
                    destPath.createNewFile();
                    try (BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath))) {
                        IOUtils.copy(tis, bout);
                    }
                }
                tarEntry = tis.getNextTarEntry();
            }
        }
        return ret;
    }
}
Also used : Path(java.nio.file.Path) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 2 with IntegrationProjectGenerator

use of io.syndesis.integration.api.IntegrationProjectGenerator in project syndesis by syndesisio.

the class Application method generate.

@SuppressWarnings("PMD.UseProperClassLoader")
private void generate(Integration integration, File targetDir) throws IOException {
    ProjectGeneratorConfiguration configuration = new ProjectGeneratorConfiguration();
    IntegrationProjectGenerator generator = new ProjectGenerator(configuration, new EmptyIntegrationResourceManager(), mavenProperties);
    Path dir = targetDir.toPath();
    Files.createDirectories(dir);
    Files.write(dir.resolve("pom.xml"), generator.generatePom(integration));
    dir = dir.resolve("src/main/java/io/syndesis/example");
    Files.createDirectories(dir);
    ClassPathResource resource = new ClassPathResource("io/syndesis/integration/project/generator/templates/Application.java.mustache");
    try (InputStream is = resource.getInputStream()) {
        Files.write(dir.resolve("Application.java"), IOUtils.toByteArray(is));
    }
}
Also used : Path(java.nio.file.Path) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) ProjectGeneratorConfiguration(io.syndesis.integration.project.generator.ProjectGeneratorConfiguration) InputStream(java.io.InputStream) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) ProjectGenerator(io.syndesis.integration.project.generator.ProjectGenerator) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ProjectGenerator (io.syndesis.integration.project.generator.ProjectGenerator)1 ProjectGeneratorConfiguration (io.syndesis.integration.project.generator.ProjectGeneratorConfiguration)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1