Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating three packages and profiles for code generation #22

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/java-code-generation-integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Java Code Generation

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn clean install --projects OLGA-Core,OLGA-Cli --file pom.xml -Pjava
working-directory: ./OLGA
4 changes: 2 additions & 2 deletions OLGA/OLGA-Cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>semanticstore.ontology.library.generator</groupId>
<artifactId>OLGA</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
</parent>
<artifactId>OLGA-Cli</artifactId>
<name>OLGA-Cli</name>
Expand Down Expand Up @@ -40,7 +40,7 @@ Query the generated ontology instance by relying on Object Oriented Classes.</de
<dependency>
<groupId>semanticstore.ontology.library.generator</groupId>
<artifactId>OLGA-Core</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
Expand Down
41 changes: 38 additions & 3 deletions OLGA/OLGA-Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<groupId>semanticstore.ontology.library.generator</groupId>
<artifactId>OLGA</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
</parent>
<artifactId>OLGA-Core</artifactId>
<name>OLGA-Core</name>
<url>https://github.com/EcoStruxure/OLGA/tree/master/OLGA/OLGA-Core</url>
<url>https://github.com/EcoStruxure/OLGA/tree/master/OLGA/OLGA-Core</url>
<description>OLGA is based on a model driven approach taking as input an ontology file expressed in one of the supported W3C supported standards (RDF, OWL) and generating a library conform to the ontology model.

The generated library is then imported and used to programmatically to:
Expand Down Expand Up @@ -41,7 +41,35 @@ Query the generated ontology instance by relying on Object Oriented Classes.</de
<junit.version>4.12</junit.version>
<log.version>1.7.25</log.version>
<log4j.version>1.2.17</log4j.version>
</properties>
</properties>
<profiles>
<profile>
<id>csharp</id>
<properties>
<exclude.tests>**/*Python</exclude.tests>
</properties>
</profile>
<profile>
<id>python</id>
<properties>
<exclude.tests>**/*Csharp</exclude.tests>
</properties>
</profile>
<profile>
<id>java</id>
<properties>
<exclude.tests>**/*Csharp</exclude.tests>
<exclude.tests>**/*Python</exclude.tests>
</properties>
</profile>
<profile>
<id>default</id>
<properties>
<exclude.tests>**/*Csharp</exclude.tests>
<exclude.tests>**/*Python</exclude.tests>
</properties>
</profile>
</profiles>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
Expand All @@ -62,6 +90,13 @@ Query the generated ontology instance by relying on Object Oriented Classes.</de
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.28.3</version>
</path>
</annotationProcessorPaths>
<manifest>
<mainClass>semanticstore.ontology.library.generator.olga.OlgaService</mainClass>
</manifest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
import java.util.Map;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import semanticstore.ontology.library.generator.exceptions.InvalidUriException;
import semanticstore.ontology.library.generator.generators.AbstractGenerator;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to make these plugins that are loaded at runtime? It would make it easier for a person adding a new generator...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joephayes
I actually started using Dagger for dependency injection as you are pointing out.
Then I realized others might not use it to extend OLGA.
I think it makes sense to seperate them and run the tests of code generation for all three.
But the compilation tests we can't assert unless the underlying dependencies are installed.

thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joephayes friendly ping :)

Copy link
Contributor

@joephayes joephayes Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charbull Sorry for the delay!

At a high level, I'm thinking in terms of modules (plugins). OLGA would maintain a registry of modules and load the code as needed.

What if OLGA defined these as service interfaces and then the Python, C# and Java generators can be implemented as services? OLGA could then use the Java ServiceLoader to load the desired implementations.

If OLGA adopted this model, the code for the different generators would move into separate repos and the compilation tests would move as well.

It would also give a definitive answer to the question "how do I add a new generator?"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charbull - is this something you want to discuss more? Maybe I should open a separate issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joephayes I think it makes sense, I will start looking at it.
For the RDF python generator do you have some bandwidth to collaborate in co-development?

Copy link
Contributor

@joephayes joephayes Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charbull - A colleague of mine and I will have some bandwidth towards the end of this month and we could work on the generator for RDF Python then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great !
Will send another PR for the service loader

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great! Looking forward to it!

import semanticstore.ontology.library.generator.generators.java.RDF4JGenerator;
import semanticstore.ontology.library.generator.generators.csharp.TrinityGenerator;
import semanticstore.ontology.library.generator.generators.python.RdfAlchemyGenerator;

import semanticstore.ontology.library.generator.global.LIBRARY;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* ---------------------
*/
package semanticstore.ontology.library.generator.generators;
package semanticstore.ontology.library.generator.generators.csharp;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -49,6 +49,7 @@
import freemarker.template.TemplateException;
import freemarker.template.TemplateNotFoundException;
import semanticstore.ontology.library.generator.exceptions.InvalidUriException;
import semanticstore.ontology.library.generator.generators.AbstractGenerator;
import semanticstore.ontology.library.generator.global.UTILS;
import semanticstore.ontology.library.generator.model.ZClass;
import semanticstore.ontology.library.generator.model.ZObjectProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* ---------------------
*/
package semanticstore.ontology.library.generator.generators;
package semanticstore.ontology.library.generator.generators.java;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -48,6 +48,7 @@
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateNotFoundException;
import semanticstore.ontology.library.generator.generators.AbstractGenerator;
import semanticstore.ontology.library.generator.exceptions.InvalidUriException;
import semanticstore.ontology.library.generator.global.UTILS;
import semanticstore.ontology.library.generator.model.ZClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* ---------------------
*/
package semanticstore.ontology.library.generator.generators;
package semanticstore.ontology.library.generator.generators.python;

import java.io.BufferedWriter;
import java.io.File;
Expand Down Expand Up @@ -50,6 +50,7 @@
import freemarker.template.TemplateException;
import freemarker.template.TemplateNotFoundException;
import semanticstore.ontology.library.generator.exceptions.InvalidUriException;
import semanticstore.ontology.library.generator.generators.AbstractGenerator;
import semanticstore.ontology.library.generator.global.UTILS;
import semanticstore.ontology.library.generator.model.ZClass;
import semanticstore.ontology.library.generator.model.ZInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* ---------------------
*/
package semanticstore.ontology.library.generator.code.generator;
package semanticstore.ontology.library.generator.code.generator.generators.csharp;


import static org.junit.Assert.assertTrue;
Expand All @@ -44,23 +44,20 @@
import semanticstore.ontology.library.generator.test.utils.GeneratedOntologies;

@RunWith(Parameterized.class)
public class CommentsTest {
public class CommentsTestCsharp {

@BeforeClass
public static void generateOntology() throws Exception {
// check if the needed ontologies have been generated
assertTrue(GeneratedOntologies.isSimpleBasicGenerated("cs", "trinity"));
assertTrue(GeneratedOntologies.isSimpleLonelyBasicGenerated("cs", "trinity"));
assertTrue(GeneratedOntologies.isSarefBasicGenerated("cs", "trinity"));
assertTrue(GeneratedOntologies.isSimpleBasicGenerated("java", "rdf4j"));
}

// building set of parameter to test : (code , path to tested class, expected comment, test name )
@Parameters(name = "{index}: {0}-Comment {3}")
public static Collection<Object[]> data() {
Path csharp = Paths.get("OLGA/generated/testSimple-dotnetTrinity/TestSimple/Rdf/Model/");
Path java =
Paths.get("OLGA/generated/testsimple-RDF4J-java/src/main/java/testsimple/rdf/model/");
Path csharpLonely =
Paths.get("OLGA/generated/testSimpleLonely-dotnetTrinity/TestSimpleLonely/Rdf/Model/");
Path cSharpSaref = Paths.get(
Expand All @@ -87,12 +84,6 @@ public static Collection<Object[]> data() {
list.add(new Object[] {"CSHARP LONELY", csharpLonely.resolve("IFloor.cs"),
"/// provides information about floor accronym~\"#%&*", "Data property"});

list.add(new Object[] {"JAVA", java.resolve("Building.java"), "Class mabna", "Class"});
list.add(new Object[] {"JAVA", java.resolve("Building.java"), "shows building property.",
"Data property"});
list.add(new Object[] {"JAVA", java.resolve("Building.java"), "Depends on Building class.",
"Object Property"});

list.add(new Object[] {"CSHARP", cSharpSaref.resolve("IWashingMachine.cs"),
"/// <inheritdoc cref=\"IAppliance\"/>", "Comment Inheritance Saref WashMach"});
list.add(new Object[] {"CSHARP", cSharpSaref.resolve("ITemporalUnit.cs"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* ---------------------
*/
package semanticstore.ontology.library.generator.code.generator;
package semanticstore.ontology.library.generator.code.generator.generators.csharp;

import static org.junit.Assert.*;
import java.io.IOException;
Expand All @@ -34,7 +34,7 @@
import org.junit.Test;
import semanticstore.ontology.library.generator.test.utils.GeneratedOntologies;

public class DependenciesTest {
public class DependenciesTestCsharp {

@BeforeClass
public static void generateOntology() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
package semanticstore.ontology.library.generator.code.generator;
/*
* -------------------------
*
* MIT License
*
* Copyright (c) 2018, Schneider Electric USA, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ---------------------
*/
package semanticstore.ontology.library.generator.code.generator.generators.csharp;

import static org.junit.Assert.*;
import java.io.IOException;
Expand All @@ -21,7 +45,7 @@
*
*/
@RunWith(Parameterized.class)
public class IndentationTest {
public class IndentationTestCsharp {

@BeforeClass
public static void generateOntology() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* ---------------------
*/
package semanticstore.ontology.library.generator.code.generator;
package semanticstore.ontology.library.generator.code.generator.generators.csharp;

import static org.junit.Assert.assertTrue;
import java.nio.file.Files;
Expand All @@ -38,7 +38,7 @@
import semanticstore.ontology.library.generator.service.OlgaService;
import semanticstore.ontology.library.generator.test.utils.GeneratedOntologies;

public class OLGAOutputOptionTest {
public class OLGAOutputOptionTestCsharp {


static Path outputPath;
Expand Down
Loading