-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Will generate source code to standard output given a model and a template. The template follows same synstax as graphwalker version 2
- Loading branch information
1 parent
88f2ea5
commit ee8a8cd
Showing
4 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
graphwalker-cli/src/main/java/org/graphwalker/cli/commands/Source.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.graphwalker.cli.commands; | ||
|
||
/* | ||
* #%L | ||
* GraphWalker Command Line Interface | ||
* %% | ||
* Copyright (C) 2005 - 2014 GraphWalker | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Parameters(commandDescription = "Will generate source code using the provided model and a template. See http://graphwalker.org/docs/command_line_syntax") | ||
public class Source { | ||
|
||
@Parameter(names = {"--input", "-i"}, required = true, arity = 2, | ||
description = "This command requires an input model file, and an input template file. " + | ||
"See http://graphwalker.org/docs/command_line_syntax") | ||
public List<String> input = new ArrayList<>(); | ||
} |
46 changes: 46 additions & 0 deletions
46
graphwalker-cli/src/test/java/org/graphwalker/cli/SourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* #%L | ||
* GraphWalker Command Line Interface | ||
* %% | ||
* Copyright (C) 2005 - 2014 GraphWalker | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
|
||
package org.graphwalker.cli; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
|
||
|
||
public class SourceTest extends CLITestRoot { | ||
|
||
@Test | ||
public void generatePerl() throws IOException { | ||
String args[] = {"source", "--input", "json/example.json", "template/perl.template"}; | ||
Result result = runCommand(args); | ||
Assert.assertThat(result.getError(), is("")); | ||
Assert.assertThat(result.getOutput().length(), is(1850)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
HEADER<{{ | ||
use strict; | ||
use warnings; | ||
|
||
use SOAP::Lite; | ||
|
||
# Connect to the MBT web-service | ||
my $MBTService = SOAP::Lite->service($ARGV[0]); | ||
|
||
# Load MBT with a new xml | ||
my $arg = SOAP::Data->new(name => 'arg0', value => $ARGV[1]); | ||
my $res = $MBTService->Load($arg); | ||
|
||
if ($res eq "false") { | ||
die "Unable to reload MBT, check path to .xml file!\nRemember that the path is relative where mbt is launched."; | ||
} | ||
|
||
# Walk the model | ||
while ( $MBTService->HasNextStep() eq "true"){ | ||
# Get next step from MBT | ||
my $step = $MBTService->GetNextStep(); | ||
if ($step ne '') { | ||
# Run the step | ||
eval( $step ) or die; | ||
} | ||
} | ||
print "MBT Statistics: \n" . $MBTService->GetStatistics() . "\n"; | ||
|
||
}}>HEADER | ||
|
||
# | ||
# This sub routine implements the {EDGE_VERTEX} '{LABEL}' | ||
# | ||
sub {LABEL}() | ||
{ | ||
print "{EDGE_VERTEX}: {LABEL}\n"; | ||
die "The {EDGE_VERTEX}: {LABEL} is not implemented yet!"; | ||
} | ||
|
||
FOOTER<{{ | ||
return 1; | ||
}}>FOOTER |