Skip to content

Instantly share code, notes, and snippets.

@kris7t
Last active November 9, 2018 17:16
Show Gist options
  • Save kris7t/e4eb1f138c4f851f4f88cc7252727318 to your computer and use it in GitHub Desktop.
Save kris7t/e4eb1f138c4f851f4f88cc7252727318 to your computer and use it in GitHub Desktop.
Read PNML and NUPN from a plain Java (Gradle) project
plugins {
java
}
group = "hu.bme.mit.theta.interchange.pnml"
version = "0.0.1-SNAPSHOT"
val javaVersion by extra { JavaVersion.VERSION_11 }
val pnmlFrameworkVersion by extra { "2.2.12" }
val emfCommonVersion by extra { "2.10.1" }
val emfCodeGenVersion by extra { "2.10.0" }
val emfCodeGenEcoreVersion by extra { "2.10.2-v20150123-0452" }
val emfEcoreVersion by extra { "2.10.2-v20150123-0348" }
val oclVersion by extra { "3.4.2.v20140725-2242" }
val oclCommonVersion by extra { "1.2.0.v20140610-0641" }
val oclEcoreVersion by extra { "3.3.100.v20140610-0641" }
val lpgRuntimeVersion by extra { "2.0.17-v201004271640" }
val axiomVersion by extra { "1.2.20" }
val jingVersion by extra { "20091111" }
val logbackVersion by extra { "1.2.3" }
val junitVersion by extra { "4.12" }
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
dependencies {
implementation("fr.lip6.pnml:fr.lip6.pnml.framework.coremodel:$pnmlFrameworkVersion")
implementation("fr.lip6.pnml:fr.lip6.pnml.framework.ptnet:$pnmlFrameworkVersion")
implementation("fr.lip6.pnml:fr.lip6.pnml.framework.symmetricnet:$pnmlFrameworkVersion")
implementation("fr.lip6.pnml:fr.lip6.pnml.framework.hlpn:$pnmlFrameworkVersion")
implementation("fr.lip6.pnml:fr.lip6.pnml.framework.pthlpng:$pnmlFrameworkVersion")
implementation("fr.lip6.pnml:fr.lip6.pnml.framework.utils:$pnmlFrameworkVersion")
implementation("fr.lip6.pnml:fr.lip6.pnml.nupn.toolinfo:$pnmlFrameworkVersion")
implementation("org.eclipse.emf:org.eclipse.emf.common:$emfCommonVersion")
implementation("org.eclipse.emf:org.eclipse.emf.codegen:$emfCodeGenVersion")
implementation("org.eclipse.emf:org.eclipse.emf.codegen.ecore:$emfCodeGenEcoreVersion")
implementation("org.eclipse.emf:org.eclipse.emf.ecore:$emfEcoreVersion")
implementation("org.eclipse.emf:org.eclipse.emf.ecore.xmi:$emfEcoreVersion")
implementation("org.eclipse.ocl:org.eclipse.ocl:$oclVersion")
implementation("org.eclipse.ocl:org.eclipse.ocl.common:$oclCommonVersion")
implementation("org.eclipse.ocl:org.eclipse.ocl.ecore:$oclEcoreVersion")
implementation("lpg.runtime:java:$lpgRuntimeVersion")
implementation("org.apache.ws.commons.axiom:axiom-api:$axiomVersion")
implementation("org.apache.ws.commons.axiom:axiom-impl:$axiomVersion")
implementation("com.thaiopensource:jing:$jingVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
testImplementation("junit:junit:$junitVersion")
}
configurations.all {
resolutionStrategy.eachDependency {
if (requested.name == "xml-apis") {
useVersion("1.0.b2")
}
}
}
repositories {
jcenter()
maven("https://repo.eclipse.org/content/groups/releases/")
}
package hu.bme.mit.theta.interchange.pnml;
import fr.lip6.move.pnml.framework.utils.*;
import fr.lip6.move.pnml.framework.utils.exception.*;
import fr.lip6.move.pnml.ptnet.*;
import fr.lip6.move.pnml.ptnet.hlapi.*;
import fr.lip6.nupn.*;
import fr.lip6.nupn.helper.*;
import org.junit.*;
import java.io.*;
import java.math.*;
import java.net.*;
public class PnmlImportTest {
@Test
public void testImport() throws URISyntaxException, InvalidIDException, ImportException, IOException {
final File pnmlFile = new File(getClass().getResource("/aslink_01_a.pnml").toURI());
final PetriNetDocHLAPI hlapi = (PetriNetDocHLAPI) PNMLUtils.importPnmlDocument(pnmlFile, false);
final ToolInfo toolInfo = hlapi.getNets().get(0).getPages().get(0).getToolspecifics().get(0);
Assert.assertEquals("nupn", toolInfo.getTool());
Assert.assertEquals("1.1", toolInfo.getVersion());
final NUPNToolspecificType nupn = NUPNReader.loadNUPNToolInfoAsToolspecificType(toolInfo.getFormattedXMLBuffer().toString());
Assert.assertEquals(BigInteger.valueOf(83), nupn.getStructure().getUnits());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment