Skip to content

Commit

Permalink
Increment version to 3.0.2 which allows new options use.place.names and
Browse files Browse the repository at this point in the history
use.transition.names; update web doc and shell script accordingly.
Refactor a lot of code to reduce duplication.
  • Loading branch information
Lom M. Hillah committed Oct 2, 2019
1 parent 2786ce3 commit 5c59949
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 32 deletions.
10 changes: 5 additions & 5 deletions fr.lip6.move.pnml2nupn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<description>http://cadp.inria.fr/man/caesar.bdd.html</description>

<url>http://pnml.lip6.fr/pnml2nupn/index.html</url>
<url>https://pnml.lip6.fr/pnml2nupn/</url>

<inceptionYear>2014</inceptionYear>

Expand All @@ -26,7 +26,7 @@

<organization>
<name>Sorbonne Université, CNRS, LIP6, and Univ. Paris Nanterre</name>
<url>http://www.lip6.fr/</url>
<url>https://lip6.fr/</url>
</organization>

<developers>
Expand Down Expand Up @@ -267,9 +267,9 @@
<version>2.0.2</version>
<type>jar</type>
<overWrite>false</overWrite>
<includes> **/css/bootstrap.min.css, **/css/fontawesome/**/*,
**/css/themes/flatly/*.css,
**/js/*.js, **/js/languages/*,
<includes>**/css/fontawesome/**/*,
**/css/themes/darkly/*.css,
**/js/*.js, **/js/*.map, **/js/languages/*,
**/js/styles/github.min.css
</includes>
</artifactItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package fr.lip6.move.pnml2nupn.export.impl;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.concurrent.BlockingQueue;

import org.slf4j.Logger;

import com.ximpleware.extended.AutoPilotHuge;
import com.ximpleware.extended.NavExceptionHuge;
import com.ximpleware.extended.VTDNavHuge;
import com.ximpleware.extended.XPathEvalExceptionHuge;
import com.ximpleware.extended.XPathParseExceptionHuge;

import fr.lip6.move.pnml2nupn.MainPNML2NUPN;
import fr.lip6.move.pnml2nupn.exceptions.PNMLImportExportException;
import fr.lip6.move.pnml2nupn.utils.PNML2NUPNUtils;
import fr.lip6.move.pnml2nupn.utils.SafePNChecker;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;

/**
* Utility methods for exporters.
*
*/
public final class ExportUtils {

private ExportUtils() {
}

/**
* Returns true if the considered net is a PT net, false otherwise.
*
* @param ap
* @param vn
* @param logger
* @return
* @throws XPathParseExceptionHuge
* @throws XPathEvalExceptionHuge
* @throws NavExceptionHuge
*/
public static boolean isPTNet(AutoPilotHuge ap, VTDNavHuge vn, Logger logger)
throws XPathParseExceptionHuge, XPathEvalExceptionHuge, NavExceptionHuge {
boolean result = true;
ap.selectXPath(PNMLPaths.NETS_PATH);
while ((ap.evalXPath()) != -1) {
vn.push();
String netType = vn.toString(vn.getAttrVal(PNMLPaths.TYPE_ATTR));
logger.info("Discovered net type: {}", netType);
if (!netType.endsWith(PNMLPaths.PTNET_TYPE)) {
result = false;
break;
}
vn.pop();
}
ap.resetXPath();
vn.toElement(VTDNavHuge.ROOT);
return result;
}

/**
* Checks that the currently analyzed net is 1-safe
*
* @return true if the net is 1-safe
* @throws IOException
* @throws PNMLImportExportException
*/
public static boolean isNet1Safe(SafePNChecker spnc, File inputFile) throws IOException, PNMLImportExportException {
spnc.setPnmlDocPath(inputFile.getCanonicalPath());
boolean res = spnc.isNet1Safe();
return res;
}

/**
* Inserts unit safeness pragma (as reported by the unit safeness checking tool)
*
* @throws InterruptedException
*/
public static void insertUnitSafePragma(BlockingQueue<String> nupnQueue) throws InterruptedException {
PNML2NUPNUtils.insertPragma(MainPNML2NUPN.PRAGMA_UNIT_SAFE_BY_BOUNDS + NUPNConstants.NL, nupnQueue);
}

/**
* Updates current label length only if new label length is strictly greater.
*
* @param newLabel
*/
public static int updateLabelLength(String newLabel, int currentLength) {
int newLength = newLabel.length();
if (newLength > currentLength)
return newLength;
return currentLength;
}

/**
* Sets the labels line (i.e., header) in the NUPN.
*
* @param nupnQueue
* output queue
* @param labelLength
* the greatest label length
* @param thereExistTransitions
* are there any transition in the net?
* @throws InterruptedException
* @throws IOException
*/
public static void setLabelsLine(BlockingQueue<String> nupnQueue, int labelLength, boolean thereExistTransitions)
throws InterruptedException, IOException {
String endOfLabel = NUPNConstants.WS + labelLength + NUPNConstants.NL;
if (!thereExistTransitions) {
nupnQueue.put(NUPNConstants.LABELS_1_1_0 + endOfLabel);
} else {
nupnQueue.put(NUPNConstants.LABELS_1_0_0 + endOfLabel);
}
}

/**
* Append the content of a given file to a NUPN file
*
* @param outPlacesFile
* the file whose content is to be appended
* @param nupnQueue
* the writing queue to the NUPN file
* @param logger
* @throws IOException
*/
public static void appendFileContentToNUPN(File outPlacesFile, BlockingQueue<String> nupnQueue, Logger logger)
throws IOException {
Files.lines(outPlacesFile.toPath()).forEach(l -> {
try {
nupnQueue.put(l + NUPNConstants.NL);
} catch (InterruptedException e) {
logger.error("Error while appending content of external file {} to NUPN file: {}",
outPlacesFile.getAbsolutePath(), e.getMessage());
PNML2NUPNUtils.printStackTrace(e);
}
});
}

/**
* Looks up and returns the PNML node id according to the option
* {@link MainPNML2NUPN#USE_PLACE_NAMES} or
* {@link MainPNML2NUPN#USE_TRANSITION_NAMES}. If the option is set, the id
* would be the node name instead of the id (default behavior).
*
* @param vn
* @param useNodeName
* @param id2NameMap
* @return
* @throws NavExceptionHuge
*/
public static String getPNMLNodeId(VTDNavHuge vn, boolean useNodeName,
Object2ObjectOpenHashMap<String, String> id2NameMap) throws NavExceptionHuge {
String id = vn.toString(vn.getAttrVal(PNMLPaths.ID_ATTR));
if (useNodeName) {
vn.toElement(VTDNavHuge.FIRST_CHILD);
while (!vn.matchElement(PNMLPaths.NAME_ELEMENT)) {
vn.toElement(VTDNavHuge.NEXT_SIBLING);
}
if (vn.matchElement(PNMLPaths.NAME_ELEMENT)) {
vn.toElement(VTDNavHuge.FIRST_CHILD);
while (!vn.matchElement(PNMLPaths.TEXT_ELEMENT)) {
vn.toElement(VTDNavHuge.NEXT_SIBLING);
}
id2NameMap.put(id, vn.toString(vn.getText()).trim());
// id = vn.toString(vn.getText()).trim();
vn.toElement(VTDNavHuge.PARENT);
vn.toElement(VTDNavHuge.PARENT);
} else {
id2NameMap.put(id, NUPNConstants.NO_NAME_PREFIX);
// id = NUPNConstants.NO_NAME_PREFIX + id;
vn.toElement(VTDNavHuge.PARENT);
}
}
return id;
}

/**
* Returns a PNML node Id or name according to the option
* {@link MainPNML2NUPN#USE_PLACE_NAMES} or
* {@link MainPNML2NUPN#USE_TRANSITION_NAMES}. If the option is set, returns the
* name from the map (or {@link NUPNConstants#NO_NAME_PREFIX} if empty name).
*
* @param id
* @param useNodeName
* @param id2NameMap
* @return
*/
public static String getPNMLNodeIdOrName(String id, boolean useNodeName,
Object2ObjectOpenHashMap<String, String> id2NameMap) {
String name;
if (useNodeName) {
name = id2NameMap.get(id);
if (name.isEmpty()) {
name = NUPNConstants.NO_NAME_PREFIX;
}
} else {
name = id;
}
return name;
}

}
8 changes: 5 additions & 3 deletions fr.lip6.move.pnml2nupn/src/site/apt/changelog.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
Changelog of PNML to NUPN Converter ${project.version}
------
------
2019-09-23
2019-10-02
------

Changelog

* What's new in version ${project.version}? (2019-09-24)
* What's new in version ${project.version}? (2019-10-02)

* Remove useless synchronizations
* Remove useless synchronizations.
* Add options use.place.names and use.transition.names.
They allow using node names instead of their ids in the mappings in the labels section in the NUPN file.

* What's new in version 3.0.1? (2019-09-23)

Expand Down
36 changes: 19 additions & 17 deletions fr.lip6.move.pnml2nupn/src/site/apt/download.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Download PNML to NUPN Converter ${project.version}
------
------
2019-09-23
2019-10-02
------

Download PNML to NUPN Converter ${project.version}
Expand Down Expand Up @@ -47,37 +47,39 @@ There is currently no plan to release a version of Bounds specifically for Windo

===

Previous stable versions
Download previous stable versions

* Download {{{./download/pnml2nupn-3.0.0.jar}version 3.0.0}}
* {{{./download/pnml2nupn-3.0.1.jar}version 3.0.1}}

* {{{./download/pnml2nupn-3.0.0.jar}version 3.0.0}}

* Download {{{./download/pnml2nupn-2.3.0.jar}version 2.3.0}}
* {{{./download/pnml2nupn-2.3.0.jar}version 2.3.0}}

* Download {{{./download/pnml2nupn-2.2.0.jar}version 2.2.0}}
* {{{./download/pnml2nupn-2.2.0.jar}version 2.2.0}}

* Download {{{./download/pnml2nupn-2.1.0.jar}version 2.1.0}}
* {{{./download/pnml2nupn-2.1.0.jar}version 2.1.0}}

* Download {{{./download/pnml2nupn-1.5.4.jar}version 1.5.4}}
* {{{./download/pnml2nupn-1.5.4.jar}version 1.5.4}}

* Download {{{./download/pnml2nupn-1.5.2.jar}version 1.5.2}}
* {{{./download/pnml2nupn-1.5.2.jar}version 1.5.2}}

* Download {{{./download/pnml2nupn-1.5.1.jar}version 1.5.1}}
* {{{./download/pnml2nupn-1.5.1.jar}version 1.5.1}}

* Download {{{./download/pnml2nupn-1.5.0.jar}version 1.5.0}}
* {{{./download/pnml2nupn-1.5.0.jar}version 1.5.0}}

* Download {{{./download/pnml2nupn-1.4.1.jar}version 1.4.1}}
* {{{./download/pnml2nupn-1.4.1.jar}version 1.4.1}}

* Download {{{./download/pnml2nupn-1.4.0.jar}version 1.4.0}}
* {{{./download/pnml2nupn-1.4.0.jar}version 1.4.0}}

* Download {{{./download/fr.lip6.move.pnml2nupn-1.3.1.jar}version 1.3.1}}
* {{{./download/fr.lip6.move.pnml2nupn-1.3.1.jar}version 1.3.1}}

* Download {{{./download/fr.lip6.move.pnml2nupn-1.3.0.jar}version 1.3.0}}
* {{{./download/fr.lip6.move.pnml2nupn-1.3.0.jar}version 1.3.0}}

* Download {{{./download/fr.lip6.move.pnml2bpn-1.2.2.jar}version 1.2.2}}
* {{{./download/fr.lip6.move.pnml2bpn-1.2.2.jar}version 1.2.2}}

* Download {{{./download/fr.lip6.move.pnml2bpn-1.2.1.jar}version 1.2.1}}
* {{{./download/fr.lip6.move.pnml2bpn-1.2.1.jar}version 1.2.1}}

* Download {{{./download/fr.lip6.move.pnml2bpn-1.1.11.jar}version 1.1.11}}
* {{{./download/fr.lip6.move.pnml2bpn-1.1.11.jar}version 1.1.11}}

===

Expand Down
30 changes: 30 additions & 0 deletions fr.lip6.move.pnml2nupn/src/site/apt/usage.apt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ Options

This tool supports some options (technically speaking: properties) that you might activate to change its behaviour.

* Use place names

This option makes the translator use place names instead of their ids for the mappings <<PNML id / NUPN id>> in the labels section of the NUPN file.
When there is a NUPN toolspecific section in the PNML the extraction of the NUPN ignores this option (since the grammar of that section requires
the list of places to be IDREFs - references to IDs).

To enable this property, proceed like so:

<java -Duse.place.names=true ...>

The default value for this option is <false>.

** Supporting versions

Since v3.0.2.

* Use transition names

This option makes the translator use place names instead of their ids for the mappings <PNML id / NUPN id> in the labels section of the NUPN file.
When there is a NUPN tool specific section in the PNML the extraction of the NUPN ignores this option (since the grammar of that section requires
the list of places to be IDREFs - references to IDs).

<java -Duse.transition.names=true ...>

The default value for this option is <false>.

** Supporting versions

Since v3.0.2.

* Preserve NUPN in native mode

With this option, if there is a NUPN toolspecific section in the PNML document, it will be directly considered
Expand Down
17 changes: 15 additions & 2 deletions fr.lip6.move.pnml2nupn/src/site/resources/download/pnml2nupn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#############################################################################################
# Script to launch PNML 2 NUPN (1-Safe P/T Net) model transformation. #
# Version: 2019-09-23 (since v1.5.2) #
# Version: 2019-10-02 (since v1.5.2) #
# Contributors: Lom M. Hillah #
# Institutions: Sorbonne Université, and Univ. Paris Nanterre, LIP6, CNRS #
# Example: ./pnml2nupn.sh pathToModelsFolder [pathToASingleFile] [pathToOtherFolder] [...] #
Expand Down Expand Up @@ -76,6 +76,19 @@ PRESERVE_NUPN_MIX="-Dpreserve.nupn.mix=false"
# This option preempts preserve.nupn.mix. Therefore, it deactivates preserve.nupn.mix when it is set.
PRESERVE_NUPN_NATIVE="-Dpreserve.nupn.native=false"

# Use PNML place names instead of their ids for the mappings PNML id/ NUPN id
# in the labels section of the NUPN.
# This option is ignored when a NUPN tool specific section is found in the PNML.
USE_PLACE_NAMES="-Duse.place.names=false"

# Use PNML transition names instead of their ids for the mappings PNML id/ NUPN id
# in the labels section of the NUPN.
# This option is ignored when a NUPN tool specific section is found in the PNML.
USE_TRANSITION_NAMES="-Duse.transition.names=false"

# Group the options to pass over to the pnml2nupn translator.
TRANSLATOR_OPTS="$HAS_UNSAFE_ARCS $CAMI_TMP_KEEP $UNIT_SAFENESS_CHECKING $UNIT_SAFENESS_CHECKING_ONLY $UNSAFE_PLACES_NB_REPORT $FORCE_NUPN_GEN $PRESERVE_NUPN_MIX $PRESERVE_NUPN_NATIVE $USE_PLACE_NAMES $USE_TRANSITION_NAMES"

# Activate debug mode (print stack traces in case of error)? Uncomment the following if you wish so.
export PNML2NUPN_DEBUG=true

Expand All @@ -88,7 +101,7 @@ fi

echo "Launching PNML2NUPN program"

PNML2NUPN="$JAVA $HAS_UNSAFE_ARCS $CAMI_TMP_KEEP $UNIT_SAFENESS_CHECKING $UNIT_SAFENESS_CHECKING_ONLY $UNSAFE_PLACES_NB_REPORT $FORCE_NUPN_GEN $PRESERVE_NUPN_MIX $PRESERVE_NUPN_NATIVE $JVM_ARGS -jar $JAR_FILE"
PNML2NUPN="$JAVA $TRANSLATOR_OPTS $JVM_ARGS -jar $JAR_FILE"

list=""
for file in "$@"
Expand Down
Loading

0 comments on commit 5c59949

Please sign in to comment.