Java源码示例:gherkin.ast.GherkinDocument

示例1
private void parseGherkinSource(String path) {
    if (!pathToReadEventMap.containsKey(path)) {
        return;
    }
    Parser<GherkinDocument> parser = new Parser<GherkinDocument>(new AstBuilder());
    TokenMatcher matcher = new TokenMatcher();
    try {
        GherkinDocument gherkinDocument = parser.parse(pathToReadEventMap.get(path).source, matcher);
        pathToAstMap.put(path, gherkinDocument);
        Map<Integer, AstNode> nodeMap = new HashMap<Integer, AstNode>();
        AstNode currentParent = new AstNode(gherkinDocument.getFeature(), null);
        for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) {
            processScenarioDefinition(nodeMap, child, currentParent);
        }
        pathToNodeMap.put(path, nodeMap);
    } catch (ParserException e) {
        // Ignore exceptions
    }
}
 
示例2
private void parseGherkinSource(final String path) {
    if (!pathToReadEventMap.containsKey(path)) {
        return;
    }
    final Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    final TokenMatcher matcher = new TokenMatcher();
    try {
        final GherkinDocument gherkinDocument = parser.parse(pathToReadEventMap.get(path).source, matcher);
        pathToAstMap.put(path, gherkinDocument);
        final Map<Integer, AstNode> nodeMap = new HashMap<>();
        final AstNode currentParent = new AstNode(gherkinDocument.getFeature(), null);
        for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) {
            processScenarioDefinition(nodeMap, child, currentParent);
        }
        pathToNodeMap.put(path, nodeMap);
    } catch (ParserException e) {
        LOGGER.trace(e.getMessage(), e);
    }
}
 
示例3
private void parseGherkinSource(final URI path) {
    if (!pathToReadEventMap.containsKey(path)) {
        return;
    }
    final Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    final TokenMatcher matcher = new TokenMatcher();
    try {
        final GherkinDocument gherkinDocument = parser.parse(pathToReadEventMap.get(path).getSource(),
                matcher);
        pathToAstMap.put(path, gherkinDocument);
        final Map<Integer, AstNode> nodeMap = new HashMap<>();
        final AstNode currentParent = new AstNode(gherkinDocument.getFeature(), null);
        for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) {
            processScenarioDefinition(nodeMap, child, currentParent);
        }
        pathToNodeMap.put(path, nodeMap);
    } catch (ParserException e) {
        throw new IllegalStateException("You are using a plugin that only supports till Gherkin 5.\n"
                + "Please check if the Gherkin provided follows the standard of Gherkin 5\n", e
        );
    }
}
 
示例4
private void parseGherkinSource(final String path) {
    if (!pathToReadEventMap.containsKey(path)) {
        return;
    }
    final Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    final TokenMatcher matcher = new TokenMatcher();
    try {
        final GherkinDocument gherkinDocument = parser.parse(pathToReadEventMap.get(path).source, matcher);
        pathToAstMap.put(path, gherkinDocument);
        final Map<Integer, AstNode> nodeMap = new HashMap<>();
        final AstNode currentParent = new AstNode(gherkinDocument.getFeature(), null);
        for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) {
            processScenarioDefinition(nodeMap, child, currentParent);
        }
        pathToNodeMap.put(path, nodeMap);
    } catch (ParserException e) {
        LOGGER.trace(e.getMessage(), e);
    }
}
 
示例5
private AllureResults runFeature(final String featureResource,
                                 final String... moreOptions) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber2Jvm cucumber2Jvm = new AllureCucumber2Jvm(lifecycle);
    final ClassLoader classLoader = currentThread().getContextClassLoader();
    final ResourceLoader resourceLoader = new MultiLoader(classLoader);
    final ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    final List<String> opts = new ArrayList<>(Arrays.asList(
            "--glue", "io.qameta.allure.cucumber2jvm.samples",
            "--plugin", "null"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new RuntimeOptions(opts);
    final Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, options);

    options.addPlugin(cucumber2Jvm);

    final String gherkin = readResource(featureResource);
    Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    TokenMatcher matcher = new TokenMatcher();
    GherkinDocument gherkinDocument = parser.parse(gherkin, matcher);
    CucumberFeature feature = new CucumberFeature(gherkinDocument, featureResource, gherkin);

    feature.sendTestSourceRead(runtime.getEventBus());
    runtime.runFeature(feature);
    return writer;
}
 
示例6
private AllureResults runFeature(final String featureResource,
                                 final String... moreOptions) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber3Jvm cucumber3Jvm = new AllureCucumber3Jvm(lifecycle);
    final ClassLoader classLoader = currentThread().getContextClassLoader();
    final ResourceLoader resourceLoader = new MultiLoader(classLoader);
    final ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    final List<String> opts = new ArrayList<>(Arrays.asList(
            "--glue", "io.qameta.allure.cucumber3jvm.samples",
            "--plugin", "null"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new RuntimeOptions(opts);
    final Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, options);

    options.addPlugin(cucumber3Jvm);
    options.noSummaryPrinter();

    final String gherkin = readResource(featureResource);
    Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    TokenMatcher matcher = new TokenMatcher();
    GherkinDocument gherkinDocument = parser.parse(gherkin, matcher);
    CucumberFeature feature = new CucumberFeature(gherkinDocument, featureResource, gherkin);

    feature.sendTestSourceRead(runtime.getEventBus());
    runtime.runFeature(feature);
    return writer;
}
 
示例7
private ScenarioDefinition findScenarioDefinitionViaLocation(Location location, GherkinDocument gherkinDocument) {
    List<ScenarioDefinition> scenarioDefinitions = gherkinDocument.getFeature().getChildren();
    for (ScenarioDefinition definition : scenarioDefinitions) {
        if (isLocationSame(definition.getLocation(), location)) {
            return definition;
        }
    }
    return null;
}
 
示例8
private byte runFeature(final AllureResultsWriterStub writer,
                        final String featureResource,
                        final String... moreOptions) {

    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber4Jvm cucumber4Jvm = new AllureCucumber4Jvm(lifecycle);
    final ClassLoader classLoader = currentThread().getContextClassLoader();
    final ResourceLoader resourceLoader = new MultiLoader(classLoader);
    final ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    final List<String> opts = new ArrayList<>(Arrays.asList(
            "--glue", "io.qameta.allure.cucumber4jvm.samples",
            "--plugin", "null_summary"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new CommandlineOptionsParser().parse(opts).build();
    boolean mt = options.isMultiThreaded();

    FeatureSupplier featureSupplier = () -> {
        try {
            final String gherkin = readResource(featureResource);
            Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
            TokenMatcher matcher = new TokenMatcher();
            GherkinDocument gherkinDocument = parser.parse(gherkin, matcher);
            List<PickleEvent> pickleEvents = compilePickles(gherkinDocument, featureResource);
            CucumberFeature feature = new CucumberFeature(gherkinDocument, URI.create(featureResource), gherkin, pickleEvents);

            return Collections.singletonList(feature);
        } catch (IOException e) {
            return Collections.EMPTY_LIST;
        }
    };
    final Runtime runtime = Runtime.builder()
            .withResourceLoader(resourceLoader)
            .withClassFinder(classFinder)
            .withClassLoader(classLoader)
            .withRuntimeOptions(options)
            .withAdditionalPlugins(cucumber4Jvm)
            .withFeatureSupplier(featureSupplier)
            .build();

    runtime.run();
    return runtime.exitStatus();
}
 
示例9
private static List<PickleEvent> compilePickles(GherkinDocument gherkinDocument, String resource) {
    if (gherkinDocument.getFeature() == null) {
        return Collections.emptyList();
    }
    List<PickleEvent> pickleEvents = new ArrayList<>();
    for (Pickle pickle : new Compiler().compile(gherkinDocument)) {
        pickleEvents.add(new PickleEvent(resource, pickle));
    }
    return pickleEvents;
}
 
示例10
/**
 * Generates a single Cucumber runner for each separate feature file.
 *
 * @param outputDirectory the output directory to place generated files
 * @param featureFiles    The feature files to create runners for
 * @throws MojoExecutionException if something goes wrong
 */
public void generateCucumberITFiles(final File outputDirectory,
                                    final Collection<File> featureFiles) throws MojoExecutionException {
    Parser<GherkinDocument> parser = new Parser<GherkinDocument>(new AstBuilder());
    TagPredicate tagPredicate = new TagPredicate(overriddenParameters.getTags());

    TokenMatcher matcher = new TokenMatcher();

    for (final File file : featureFiles) {
        GherkinDocument gherkinDocument = null;
        final List<Pickle> acceptedPickles = new ArrayList<Pickle>();
        try {
            String source = FileUtils.readFileToString(file);
            gherkinDocument = parser.parse(source, matcher);
            Compiler compiler = new Compiler();
            List<Pickle> pickles = compiler.compile(gherkinDocument);

            for (Pickle pickle : pickles) {
                if (tagPredicate.apply(pickle.getTags())) {
                    acceptedPickles.add(pickle);
                    continue;
                }
            }

        } catch (final IOException e) {
            // should never happen
            // TODO - proper logging
            System.out.println(format("WARNING: Failed to parse '%s'...IGNORING",
                    file.getName()));
        }

        if (acceptedPickles.isEmpty()) {
            continue;
        }

        outputFileName = classNamingScheme.generate(file.getName());
        setFeatureFileLocation(file);
        setParsedFeature(gherkinDocument.getFeature());
        writeFile(outputDirectory);

    }
}