diff --git a/src/main/java/cli/Action.java b/src/main/java/cli/Action.java index f799f4ebac4ae3bffc35729638559c25b882b7ab..09378a3593887d42f6396a65b86ce311bcb28bfc 100644 --- a/src/main/java/cli/Action.java +++ b/src/main/java/cli/Action.java @@ -67,6 +67,7 @@ import proverifspec.ProVerifQueryResult; import tmltranslator.*; import tmltranslator.mutations.ApplyDiplodocusMutationException; import tmltranslator.mutations.DiplodocusMutation; +import tmltranslator.mutations.DiplodocusMutationParser; import tmltranslator.mutations.ParseDiplodocusMutationException; import ui.MainGUI; import ui.avatarinteractivesimulation.AvatarInteractiveSimulationActions; @@ -646,7 +647,7 @@ public class Action extends Command implements ProVerifOutputListener { } public String getDescription() { - return "Performs a mutation on an DIPLODOCUS (TML, TMAP or TARCHI) model"; + return "Performs a mutation on a DIPLODOCUS (TML, TMAP or TARCHI) model"; } public String getUsage() { @@ -697,6 +698,77 @@ public class Action extends Command implements ProVerifOutputListener { }; + Command makeMutationBatchFromDiplodocus = new Command() { + public String getCommand() { + return DIPLO_MUTATION_BATCH; + } + + public String getShortCommand() { + return "dmb"; + } + + public String getDescription() { + return "Perform a series of mutations on a DIPLODOCUS (TML, TMAP or TARCHI) model"; + } + + public String getUsage() { + return "[MUTATION]\n"; + } + + public String getExample() { + return "dmb path_to_command_file"; + } + + public String executeCommand(String command, Interpreter interpreter) { + + if (!interpreter.isTToolStarted()) { + return Interpreter.TTOOL_NOT_STARTED; + } + + String[] commands = command.split(" "); + if (commands.length < 1) { + return Interpreter.BAD; + } + + TMLModeling<?> tmlModel = interpreter.mgui.gtm.getTMLModeling(); + TMLMapping tmlMapping = interpreter.mgui.gtm.getTMLMapping(); + + List<String> mutationList = null; + try { + mutationList = Files.readAllLines(new File(command).toPath()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + for (String mutationCommand:mutationList){ + try { + DiplodocusMutation dm = DiplodocusMutation.createFromString(mutationCommand); + if (dm != null) { + switch (dm.getMutationType()){ + case "TMLmutation": + if(tmlModel == null){ + return "No TML model"; + } else{ + dm.apply(tmlModel); + } + //case "TARCHImutation": + + //case "TMAPmutation": + } + } + } catch (ParseDiplodocusMutationException e) { + TraceManager.addDev("Exception in parsing mutation: " + e.getMessage()); + return e.getMessage(); + } catch (ApplyDiplodocusMutationException e) { + TraceManager.addDev("Exception in applying mutation: " + e.getMessage()); + return e.getMessage(); + } + } + + return null; + } + }; + // Diplodocus interactive simulation Command diplodocusInteractiveSimulation = new Command() { public String getCommand() { @@ -2265,6 +2337,7 @@ public class Action extends Command implements ProVerifOutputListener { addAndSortSubcommand(checkSyntax); addAndSortSubcommand(removeTimeOperators); addAndSortSubcommand(makeMutationFromDiplodocus); + addAndSortSubcommand(makeMutationBatchFromDiplodocus); addAndSortSubcommand(drawDiplodocusModel); addAndSortSubcommand(generateRGFromAvatar); addAndSortSubcommand(diplodocusInteractiveSimulation); diff --git a/src/main/java/tmltranslator/TMLTask.java b/src/main/java/tmltranslator/TMLTask.java index 3085a74233c7a8d2b39a9e0dfa618e0f2086e904..6517fd4f09c3e1859718d8a024878b7d6c863673 100755 --- a/src/main/java/tmltranslator/TMLTask.java +++ b/src/main/java/tmltranslator/TMLTask.java @@ -417,14 +417,26 @@ public class TMLTask extends TMLElement { channelsList.add(_ch); } + public void removeTMLChannel(TMLChannel _ch) { + channelsList.remove(_ch); + } + public void addReadTMLChannel(TMLChannel _ch) { readTMLChannelsList.add(_ch); } + public void removeReadTMLChannel(TMLChannel _ch) { + readTMLChannelsList.remove(_ch); + } + public void addWriteTMLChannel(TMLChannel _ch) { writeTMLChannelsList.add(_ch); } + public void removeWriteTMLChannel(TMLChannel _ch) { + writeTMLChannelsList.remove(_ch); + } + /*public List<TMLChannel> getTMLChannels() { return new ArrayList<TMLChannel>(channelsList); }*/ @@ -441,6 +453,10 @@ public class TMLTask extends TMLElement { eventsList.add(_evt); } + public void removeTMLEvent(TMLEvent _evt) { + eventsList.remove(_evt); + } + public List<TMLEvent> getTMLEvents() { return new ArrayList<TMLEvent>(eventsList); } diff --git a/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..49269bb07a414d4b7c1c1df3cfd5bf287938cbdf --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java @@ -0,0 +1,52 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLModeling; + +public class AddRequestConnectionMutation extends RequestConnectionMutation { + protected AddRequestConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(_originTaskName, _destinationTaskName, _connectionName); + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + + } +} diff --git a/src/main/java/tmltranslator/mutations/EventConnectionMutation.java b/src/main/java/tmltranslator/mutations/EventConnectionMutation.java index 71e97a1510b3613f6535c85742add9cda8f172fe..abe3a7d1c813873f6576a02945c4dc1c3a15df5c 100644 --- a/src/main/java/tmltranslator/mutations/EventConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/EventConnectionMutation.java @@ -83,15 +83,13 @@ public abstract class EventConnectionMutation extends ConnectionMutation{ if (_tmlModel.getTasks().size() != 0){ appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; } - for (TMLEvent e : events){ - System.out.println(e.getName()); - if (e.getName().equals(getConnectionName())) { - return e; - } else if (e.getName().equals(appName + "__" + getConnectionName() + "__" + appName + "__" + getConnectionName())) { - return e; - } + + TMLEvent event = _tmlModel.getEventByName(getConnectionName()); + if (event != null){ + return event; + } else { + return _tmlModel.getEventByName(appName + "__" + getConnectionName() + "__" + appName + "__" + getConnectionName()); } - return null; } public static EventConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ diff --git a/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java index a9d3e64d8eb1cf7e95f05ebcc24dac916bb4c31a..51ab7f70af3175677b7a68209eecbe94684c699d 100644 --- a/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java @@ -40,6 +40,7 @@ package tmltranslator.mutations; import tmltranslator.TMLChannel; import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; public class RemoveDataConnectionMutation extends DataConnectionMutation{ protected RemoveDataConnectionMutation(String _connectionName) { @@ -53,6 +54,14 @@ public class RemoveDataConnectionMutation extends DataConnectionMutation{ throw new ApplyDiplodocusMutationException("There is no channel named " + getConnectionName() + " in this model."); } else { _tmlModel.removeChannel(channel); + TMLTask originTask = channel.getOriginTask(); + TMLTask destinationTask = channel.getDestinationTask(); + originTask.removeTMLChannel(channel); + originTask.removeReadTMLChannel(channel); + originTask.removeWriteTMLChannel(channel); + destinationTask.removeTMLChannel(channel); + destinationTask.removeReadTMLChannel(channel); + destinationTask.removeWriteTMLChannel(channel); } } diff --git a/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java index 6fe51233eae1881179afcc5826d0f6819c34200e..a8d6bee51325f658e225ca7bcf6f0f429939211b 100644 --- a/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java @@ -53,6 +53,8 @@ public class RemoveEventConnectionMutation extends EventConnectionMutation{ throw new ApplyDiplodocusMutationException("There is no event named " + getConnectionName() + " in this model."); } else { _tmlModel.removeEvent(event); + event.getOriginTask().removeTMLEvent(event); + event.getDestinationTask().removeTMLEvent(event); } } diff --git a/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..bedbd31b4888bc1428588136330583b057d45c13 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java @@ -0,0 +1,80 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLModeling; +import tmltranslator.TMLRequest; + +import java.util.List; + +public abstract class RequestConnectionMutation extends ConnectionMutation { + protected RequestConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(_originTaskName, _destinationTaskName, _connectionName); + } + + protected RequestConnectionMutation(String _connectionName) { + super(_connectionName); + } + + public TMLRequest getRequest(TMLModeling<?> _tmlModel){ + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + + TMLRequest request = _tmlModel.getRequestByName(getConnectionName()); + if (request != null){ + return request; + } else { + return _tmlModel.getRequestByName(appName + "__" + getConnectionName() + "__" + appName + "__" + getConnectionName()); + } + } + + public static RequestConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + switch (DiplodocusMutationParser.findMutationToken(toParse)) { + case "ADD": + case "RM": + case "REMOVE": + default: + break; + } + return null; + } + +}