Skip to content

Commit

Permalink
#799 resolving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdiazgon committed Dec 4, 2018
2 parents 07ba898 + 18dc0db commit 9b20101
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 43 deletions.
15 changes: 4 additions & 11 deletions cobigen-maven/cobigen-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<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>
<artifactId>maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down Expand Up @@ -39,12 +37,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core-api</artifactId>
<version>5.0.0</version>
<version>5.1.0</version>
</dependency>

<!-- dependencies to annotations -->
Expand Down Expand Up @@ -97,7 +90,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
Expand All @@ -107,4 +100,4 @@
</plugins>
</pluginManagement>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("");
return;
}

List<GenerableArtifact> generableArtifacts = collectIncrements(cobiGen, inputs);
generableArtifacts.addAll(collectTemplates(cobiGen, inputs));

Expand Down Expand Up @@ -208,10 +207,13 @@ private CobiGen createCobiGenInstance() throws MojoExecutionException, MojoFailu

/**
* Walks the class path in search of an 'context.xml' resource to identify the enclosing folder or jar
* file. That location is then searched for class files and a list with those loaded classes is returned
* file. That location is then searched for class files and a list with those loaded classes is returned.
* If the sources are not compiled, the templates will not be able to be generated.
* @return a List of Classes for template generation.
* @throws MojoExecutionException
* When no context.xml can be found
*/
private List<Class<?>> resolveUtilClasses() {
private List<Class<?>> resolveUtilClasses() throws MojoExecutionException {
final List<Class<?>> result = new LinkedList<>();
final ClassRealm classRealm = pluginDescriptor.getClassRealm();
if (configurationFolder != null) {
Expand All @@ -223,18 +225,27 @@ private List<Class<?>> resolveUtilClasses() {
}
}

URL contextXmlUrl = classRealm.getResource("context.xml");
if (contextXmlUrl == null) {
getLog().error("No context.xml could be found in the classpath!");
return null;
Path templateRoot;
URL contextConfigurationLocation = classRealm.getResource("context.xml");
if (contextConfigurationLocation == null
|| contextConfigurationLocation.getPath().endsWith("target/classes/context.xml")) {
contextConfigurationLocation = classRealm.getResource("src/main/templates/context.xml");
if (contextConfigurationLocation == null) {
throw new MojoExecutionException("No context.xml could be found in the classpath!");
} else {
templateRoot =
Paths.get(URI.create(contextConfigurationLocation.toString())).getParent().getParent().getParent();
}
} else {
templateRoot = Paths.get(URI.create(contextConfigurationLocation.toString()));
}
getLog().debug("Found context.xml @ " + contextXmlUrl.toString());
getLog().debug("Found context.xml @ " + contextConfigurationLocation.toString());
final List<String> foundClasses = new LinkedList<>();
if (contextXmlUrl.toString().startsWith("jar")) {
getLog().info("Processing configuration archive " + contextXmlUrl.toString());
if (contextConfigurationLocation.toString().startsWith("jar")) {
getLog().info("Processing configuration archive " + contextConfigurationLocation.toString());
try {
// Get the URI of the jar from the URL of the contained context.xml
URI jarUri = URI.create(contextXmlUrl.toString().split("!")[0]);
URI jarUri = URI.create(contextConfigurationLocation.toString().split("!")[0]);
FileSystem jarfs = FileSystems.getFileSystem(jarUri);

// walk the jar file
Expand Down Expand Up @@ -272,13 +283,12 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce
}
}
} else {
final Path configFolder = Paths.get(URI.create(contextXmlUrl.toString())).getParent();
getLog().info("Processing configuration folder " + configFolder.toString());
templateRoot = templateRoot.getParent();
getLog().info("Processing configuration folder " + templateRoot.toString());
getLog().debug("Searching for classes ...");
final List<Path> foundPaths = new LinkedList<>();
try {
Files.walkFileTree(configFolder, new SimpleFileVisitor<Path>() {

Files.walkFileTree(templateRoot, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(".class")) {
Expand All @@ -295,28 +305,25 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce
return FileVisitResult.CONTINUE;
}
});
} catch (

IOException e) {
} catch (IOException e) {
getLog().error(e);
}

if (foundPaths.size() > 0) {

getLog().debug("Cleanup test classes ...");
String classOutput = getClassOutputPathFromDotClasspathFile(configFolder);
String classOutput = getClassOutputPathFromDotClasspathFile(templateRoot);
if (classOutput != null) {
Path classOutputPath = Paths.get(classOutput);
Iterator<Path> it = foundPaths.iterator();
while (it.hasNext()) {
Path next = it.next();
if (!configFolder.relativize(next).startsWith(classOutputPath)) {
if (!templateRoot.relativize(next).startsWith(classOutputPath)) {
getLog().debug(" * Removed class file " + next.toString());
it.remove();
}
}

Path absoluteClassOutputPath = configFolder.resolve(classOutputPath);
Path absoluteClassOutputPath = templateRoot.resolve(classOutputPath);
try {
URL classOutputUrl = absoluteClassOutputPath.toUri().toURL();
pluginDescriptor.getClassRealm().addURL(classOutputUrl);
Expand All @@ -327,7 +334,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce

for (Path path : foundPaths) {
try {
result.add(loadClassByPath(configFolder.relativize(path), classRealm));
result.add(loadClassByPath(templateRoot.relativize(path), classRealm));
} catch (ClassNotFoundException e) {
getLog().error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,24 @@ public void testThrowExceptionOnNothingGenerated() throws Exception {
assertThat(result.getExitCode()).as("Exit Code").isEqualTo(1);
assertThat(result.getExecutionException()).isNull();
}

/**
* Tries to reproduce issue #715 https://github.com/devonfw/tools-cobigen/issues/715 where a Windows path
* exception is thrown when trying to generate from an OpenApi file. For doing so, processes a generation
* of oasp4j template increments daos, entity_infrastructure, TOs, Logic and Rest Service and just checks
* whether the files have been generated. Takes a yaml file as input.
* @throws Exception
* test fails
*/
@Test
public void testDifferentFileSystemThrowsNoProviderMismatchException() throws Exception {
File testProject = new File(TEST_RESOURCES_ROOT + "TestDifferentFileSystems/");
File testProjectRoot = runMavenInvoker(testProject, MavenMetadata.LOCAL_REPO);
long numFilesInTarget =
Files.walk(testProjectRoot.toPath().resolve("src")).filter(Files::isRegularFile).count();
// 4 from from daos + 4 from entity infrastructure + 6 from TOs + 4 from Logic (all in one) + 2 rest
// service imp = 18
assertThat(numFilesInTarget).isEqualTo(33);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
openapi: 3.0.0
servers:
- url: 'https://localhost:8081/server/services/rest'
description: Just some data
info:
title: Devon Example
description: Example of a API definition
version: 1.0.0
x-rootpackage: com.capgemini.spoc.openapi
paths:
/shopmanagement/v1/shop/{shopId}:
get:
operationId: findShop
parameters:
- name: shopId
in: path
required: true
schema:
type: integer
format: int64
minimum: 0
maximum: 50
responses:
'200':
description: Any
content:
application/json:
schema:
$ref: '#/components/schemas/Shop'
text/plain:
schema:
type: string
'404':
description: Not found
/salemanagement/v1/sale/{saleId}:
get:
operationId: findSale
parameters:
- name: saleId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Any
/salemanagement/v1/sale/{bla}:
get:
operationId: findSale
parameters:
- name: bla
in: path
required: true
schema:
type: integer
format: int64
minimum: 10
maximum: 200
responses:
'200':
description: Any
/salemanagement/v1/sale/:
post:
responses:
'200':
description: Any
requestBody:
$ref: '#/components/requestBodies/ShopData'
tags:
- searchCriteria
/shopmanagement/v1/shop/new:
post:
responses:
'200':
description: Any
requestBody:
$ref: '#/components/requestBodies/ShopData'
components:
schemas:
Shop:
x-component: shopmanagement
description: Entity definiton of Shop
type: object
properties:
shopExample:
type: string
maxLength: 100
minLength: 5
uniqueItems: true
x-manytomany: Shop
x-onetoone: Sale
Sale:
x-component: salemanagement
description: Entity definiton of Shop
type: object
properties:
saleExample:
type: number
format: int64
maximum: 100
minimum: 0
x-onetoone: Shop
x-onetomany: Shop
required:
- saleExample
requestBodies:
ShopData:
content:
application/json:
schema:
$ref: '#/components/schemas/Shop'
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<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>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>Oasp4JTemplateTest-TestDifferentFileSystems</artifactId>
<version>dev-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>maven-plugin</artifactId>
<version>${pluginVersion}</version>
<executions>
<execution>
<id>generate</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<configurationFolder>${templatesProject}</configurationFolder>
<inputFiles>
<inputFile>Input.yaml</inputFile>
</inputFiles>
<templates>
<template>ALL</template>
</templates>
</configuration>
<dependencies>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>templates-oasp4j</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>tempeng-freemarker</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>openapiplugin</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>javaplugin</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>xmlplugin</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>htmlplugin</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>tsplugin</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>jsonplugin</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 9b20101

Please sign in to comment.