Skip to content

Commit

Permalink
Fixes #1162
Browse files Browse the repository at this point in the history
  • Loading branch information
aedelmann committed Nov 15, 2018
1 parent 1b5d512 commit 800659f
Show file tree
Hide file tree
Showing 24 changed files with 899 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generators/generator-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<artifactId>hono</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>generator-template</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.vorto.codegen.hono.EclipseHonoGenerator;
import org.eclipse.vorto.codegen.spi.config.AbstractGeneratorConfiguration;
import org.eclipse.vorto.codegen.spi.model.Generator;
import org.eclipse.vorto.codegen.template.CodeGeneratorTemplateGenerator;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -29,5 +30,6 @@ protected void doSetup() {
addGenerator(Generator.create("/generators/bosch.properties", BoschIoTSuiteGenerator.class));
addGenerator(Generator.create("/generators/ditto.properties", EclipseDittoGenerator.class));
addGenerator(Generator.create("/generators/hono.properties", EclipseHonoGenerator.class));
addGenerator(Generator.create("/generators/generator_template.properties", CodeGeneratorTemplateGenerator.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
vorto.service.name=Vorto Code Generator Template
vorto.service.description=Generates a Vorto Code Generator as part of the Generator Plugin SDK
vorto.service.creator= Eclipse Vorto Team
vorto.service.documentationUrl = https://github.com/eclipse/vorto/tree/development/plugin-sdk/plugin-generator/Readme.md
vorto.service.image32x32= img/icon32x32.png
vorto.service.image144x144= img/icon144x144.png
vorto.service.classifier=platform
vorto.service.tags=infra
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class GeneratorInfo {

public static final String TAG_DEMO = "demo";
public static final String TAG_PROD = "production";
public static final String TAG_INFRA = "infra";

public static GeneratorInfo basicInfo(String name, String description, String organisation) {
GeneratorInfo info = new GeneratorInfo();
Expand All @@ -54,6 +55,12 @@ public GeneratorInfo tags(String...tags) {
this.tags = new HashSet<String>(Arrays.asList(tags));
return this;
}

public GeneratorInfo infra() {
this.tags.clear();
this.tags.add(TAG_INFRA);
return this;
}

public GeneratorInfo demo() {
this.tags.add(TAG_DEMO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public ResponseEntity<InputStreamResource> generate(final @PathVariable String k
return responseFromResult(vorto.generate(key, namespace, name, version, GatewayUtils.mapFromRequest(request), getAuthorization(request)));
}

@RequestMapping(value = "/generators/{key}/generate", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<InputStreamResource> generateInfra(final @PathVariable String key, final HttpServletRequest request) {
return responseFromResult(vorto.generate(key, GatewayUtils.mapFromRequest(request), getAuthorization(request)));
}

private Optional<String> getAuthorization(HttpServletRequest request) {
return Optional.ofNullable(request.getHeader(AUTHORIZATION));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
import org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel;
import org.eclipse.vorto.core.api.model.functionblock.impl.FunctionblockPackageImpl;
import org.eclipse.vorto.core.api.model.informationmodel.InformationModel;
import org.eclipse.vorto.core.api.model.informationmodel.InformationModelFactory;
import org.eclipse.vorto.core.api.model.informationmodel.impl.InformationModelPackageImpl;
import org.eclipse.vorto.core.api.model.mapping.MappingModel;
import org.eclipse.vorto.core.api.model.model.Model;
import org.eclipse.vorto.model.Infomodel;
import org.eclipse.vorto.repository.api.IModelRepository;
import org.eclipse.vorto.repository.api.ModelId;
import org.eclipse.vorto.repository.api.attachment.Attachment;
Expand Down Expand Up @@ -113,6 +115,18 @@ public IGenerationResult generate(String key, String namespace, String name, Str

return generate(generator.getInstance(), model, invocationContext);
}

public IGenerationResult generate(String key, Map<String, String> parameters, Optional<String> headerAuth) {
LOGGER.info(String.format("Generating for Platform [%s]", key));

Generator generator = repo.get(key).orElseThrow(GatewayUtils.notFound(String.format("[Generator %s]", key)));
InformationModel infomodel = InformationModelFactory.eINSTANCE.createInformationModel();
infomodel.setNamespace("com.mycompany");
infomodel.setName("Template");
infomodel.setVersion("0.0.1");
InvocationContext invocationContext = InvocationContext.simpleInvocationContext(parameters);
return generate(generator.getInstance(), infomodel, invocationContext);
}

private IGenerationResult generate(IVortoCodeGenerator generator, InformationModel model, InvocationContext invocationContext) {
try {
Expand Down
2 changes: 2 additions & 0 deletions plugin-sdk/plugin-generator/generator-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/target/
88 changes: 88 additions & 0 deletions plugin-sdk/plugin-generator/generator-template/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.vorto</groupId>
<artifactId>plugin-generator</artifactId>
<version>0.10.0-SNAPSHOT</version>
</parent>

<artifactId>generator-template</artifactId>

<name>Vorto Code Generator Template Plugin</name>

<dependencies>
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>org.eclipse.vorto.core</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>generator-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtend</groupId>
<artifactId>org.eclipse.xtend.lib</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/main/xtend-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
<version>${xtext.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/src/main/xtend-gen</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (c) 2015-2016 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.codegen.template;

import java.util.Optional;

import org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask;
import org.eclipse.vorto.codegen.api.GenerationResultZip;
import org.eclipse.vorto.codegen.api.GeneratorInfo;
import org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate;
import org.eclipse.vorto.codegen.api.IGenerationResult;
import org.eclipse.vorto.codegen.api.IVortoCodeGenProgressMonitor;
import org.eclipse.vorto.codegen.api.IVortoCodeGenerator;
import org.eclipse.vorto.codegen.api.InvocationContext;
import org.eclipse.vorto.codegen.template.plugin.GeneratorMainTemplate;
import org.eclipse.vorto.codegen.template.plugin.HelloWorldTemplate;
import org.eclipse.vorto.codegen.template.runner.GenPropertiesFileTemplate;
import org.eclipse.vorto.codegen.template.runner.GeneratorConfigurationTemplate;
import org.eclipse.vorto.codegen.template.runner.GeneratorRunnerTemplate;
import org.eclipse.vorto.codegen.template.runner.LocalPropertiesFileTemplate;
import org.eclipse.vorto.codegen.template.runner.PomTemplate;
import org.eclipse.vorto.core.api.model.informationmodel.InformationModel;

public class CodeGeneratorTemplateGenerator implements IVortoCodeGenerator {

@Override
public IGenerationResult generate(InformationModel model, InvocationContext context,
IVortoCodeGenProgressMonitor monitor) {

final String serviceKey = context.getConfigurationProperties().getOrDefault("serviceKey", "myplatform").replace(" ", "");

GenerationResultZip output = new GenerationResultZip(model, getServiceKey());
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();

// Generates the parent project
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new org.eclipse.vorto.codegen.template.parent.PomTemplate()));

// Generates the Vorto Code Generator Runner Project
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new GeneratorConfigurationTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new GeneratorRunnerTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new GenPropertiesFileTemplate(serviceKey)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LocalPropertiesFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomTemplate()));

// Generates the Vorto Code Generator Plugin Project
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new org.eclipse.vorto.codegen.template.plugin.PomTemplate(serviceKey)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new GeneratorMainTemplate(serviceKey)));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new HelloWorldTemplate(serviceKey)));

generator.generate(model, context, output);
return output;
}
@Override
public String getServiceKey() {
return "generator_template";
}

@Override
public GeneratorInfo getInfo() {
return GeneratorInfo.basicInfo("Vorto Generator Template",
"Generates a Vorto Code Generator template",
"Vorto Team").withTextConfigurationItem("serviceKey", "Key", Optional.of("MyPlatform")).infra();
}
}
Loading

0 comments on commit 800659f

Please sign in to comment.