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

ODS (OpenDocument Spreadsheet) Exporter for EMF #7

Closed
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
8 changes: 8 additions & 0 deletions cnf/central.mvn
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ org.eclipse.emfcloud:emfjson-jackson:2.2.0
de.undercouch:bson4jackson:2.13.1
org.yaml:snakeyaml:1.33
org.geckoprojects.emf:org.gecko.emf.osgi.example.model.basic:4.1.1-SNAPSHOT

com.github.jferard:fastods:0.8.1

org.apache.commons:commons-text:1.10.0
org.apache.commons:commons-lang3:3.12.0

com.google.guava:guava:31.1-jre
com.google.guava:failureaccess:1.0.1
11 changes: 11 additions & 0 deletions org.gecko.emf.exporter.ods.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions org.gecko.emf.exporter.ods.tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/bin_test/
23 changes: 23 additions & 0 deletions org.gecko.emf.exporter.ods.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.gecko.emf.exporter.ods.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>bndtools.core.bndnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//.settings/org.eclipse.core.resources.prefs=UTF-8
encoding//.settings/org.eclipse.jdt.core.prefs=UTF-8
encoding//.settings/org.eclipse.jdt.ui.prefs=UTF-8
encoding/bnd.bnd=UTF-8
encoding/test.bndrun=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
16 changes: 16 additions & 0 deletions org.gecko.emf.exporter.ods.tests/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-enable-junit5: true
-library: enable-emf

javac.source: 11
javac.target: 11

Bundle-Version: 1.0.0.SNAPSHOT

-buildpath: \
org.gecko.emf.osgi.component,\
org.eclipse.emf.ecore.xmi,\
org.eclipse.emf.ecore,\
org.gecko.emf.osgi.example.model.basic,\
org.gecko.emf.exporter;version=latest,\
org.apache.commons.commons-text,\
org.gecko.emf.util.model
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Copyright (c) 2012 - 2023 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package org.gecko.emf.ods.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.gecko.emf.ods.tests.helper.EMFODSExporterTestHelper.createBasicPackageResourceSet;
import static org.gecko.emf.ods.tests.helper.EMFODSExporterTestHelper.createBusinessPerson;
import static org.gecko.emf.ods.tests.helper.EMFODSExporterTestHelper.createFlintstonesFamily;
import static org.gecko.emf.ods.tests.helper.EMFODSExporterTestHelper.createRequest;
import static org.gecko.emf.ods.tests.helper.EMFODSExporterTestHelper.createSimpsonFamily;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.gecko.emf.exporter.EMFExportOptions;
import org.gecko.emf.exporter.EMFExporter;
import org.gecko.emf.osgi.example.model.basic.BasicFactory;
import org.gecko.emf.osgi.example.model.basic.BasicPackage;
import org.gecko.emf.osgi.example.model.basic.BusinessPerson;
import org.gecko.emf.osgi.example.model.basic.Family;
import org.gecko.emf.utilities.Request;
import org.gecko.emf.utilities.UtilitiesFactory;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.annotation.Testable;
import org.osgi.framework.ServiceReference;
import org.osgi.test.common.annotation.InjectService;
import org.osgi.test.common.service.ServiceAware;
import org.osgi.test.junit5.context.BundleContextExtension;
import org.osgi.test.junit5.service.ServiceExtension;

/**
* EMF ODS exporter integration test.
*
* @author Michal H. Siemaszko
*/
@Testable
@ExtendWith(BundleContextExtension.class)
@ExtendWith(ServiceExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class EMFODSExporterTest {

@Order(value = -1)
@Test
public void testServices(
@InjectService(cardinality = 1, timeout = 4000, filter = "(component.name=EMFODSExporter)") ServiceAware<EMFExporter> emfOdsExporterAware) {

assertThat(emfOdsExporterAware.getServices()).hasSize(1);
ServiceReference<EMFExporter> emfOdsExporterReference = emfOdsExporterAware.getServiceReference();
assertThat(emfOdsExporterReference).isNotNull();
}

@Test
public void testExportBasicPackageResourceToOds(
@InjectService(cardinality = 1, timeout = 4000, filter = "(component.name=EMFODSExporter)") ServiceAware<EMFExporter> emfOdsExporterAware,
@InjectService BasicFactory basicFactory, @InjectService BasicPackage basicPackage) throws Exception {

assertThat(emfOdsExporterAware.getServices()).hasSize(1);
EMFExporter emfOdsExporterService = emfOdsExporterAware.getService();
assertThat(emfOdsExporterService).isNotNull();

ResourceSet resourceSet = createBasicPackageResourceSet(basicPackage);
Resource xmiResource = resourceSet.createResource(URI.createURI("basicPackageExporter.test"));
assertNotNull(xmiResource);

Family simpsonFamily = createSimpsonFamily(basicFactory);
xmiResource.getContents().add(simpsonFamily);

Family flintstonesFamily = createFlintstonesFamily(basicFactory);
xmiResource.getContents().add(flintstonesFamily);

BusinessPerson businessPerson = createBusinessPerson(basicFactory);
xmiResource.getContents().add(businessPerson);

Path filePath = Files.createTempFile("testBasicPackageExport", ".ods");

OutputStream fileOutputStream = Files.newOutputStream(filePath);

// @formatter:off
emfOdsExporterService.exportResourceTo(xmiResource, fileOutputStream,
Map.of(
EMFExportOptions.OPTION_LOCALE, Locale.GERMANY,
EMFExportOptions.OPTION_EXPORT_NONCONTAINMENT, true,
EMFExportOptions.OPTION_EXPORT_METADATA, true,
EMFExportOptions.OPTION_GENERATE_LINKS, true)
);
// @formatter:on
}

@Disabled
@Test
public void testExportUtilitiesPackageResourceToOds(
@InjectService(cardinality = 1, timeout = 4000, filter = "(component.name=EMFODSExporter)") ServiceAware<EMFExporter> emfOdsExporterAware)
throws Exception {

assertThat(emfOdsExporterAware.getServices()).hasSize(1);
EMFExporter emfOdsExporterService = emfOdsExporterAware.getService();
assertThat(emfOdsExporterService).isNotNull();

Request request = createRequest(UtilitiesFactory.eINSTANCE);

Path filePath = Files.createTempFile("testUtilitiesPackageExport", ".ods");

OutputStream fileOutputStream = Files.newOutputStream(filePath);

// @formatter:off
emfOdsExporterService.exportEObjectsTo(List.of(request), fileOutputStream,
Map.of(
EMFExportOptions.OPTION_LOCALE, Locale.GERMANY,
EMFExportOptions.OPTION_EXPORT_NONCONTAINMENT, true,
EMFExportOptions.OPTION_EXPORT_METADATA, true,
EMFExportOptions.OPTION_GENERATE_LINKS, true)
);
// @formatter:on
}
}
Loading