Skip to content

Commit

Permalink
Merge pull request #392 from cucumber/fix/missing_stepdef_from_classp…
Browse files Browse the repository at this point in the history
…ath_with_annot_iocucumber

fix #391 - step definition using annotations from io.cucumber are not detected
  • Loading branch information
qvdk authored Mar 11, 2020
2 parents 6149c9c + fa9577e commit 05d723a
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private List<StepDefinition> getCukeSteps(ICompilationUnit iCompUnit, MarkerFact
if (m.find()) {
if ("*".equals(m.group(2))) {
importedAnnotations.addAll(getAllAnnotationsInPackage(iCompUnit.getJavaProject(),
CUCUMBER_API_JAVA + m.group(1), m.group(1)));
CUCUMBER_API_JAVA + m.group(1), m.group(1), progressMonitor));
} else {
importedAnnotations.add(new CucumberAnnotation(m.group(2), m.group(1)));
}
Expand All @@ -111,7 +111,7 @@ private List<StepDefinition> getCukeSteps(ICompilationUnit iCompUnit, MarkerFact
if (m.find()) {
if ("*".equals(m.group(2))) {
importedAnnotations.addAll(getAllAnnotationsInPackage(iCompUnit.getJavaProject(),
IO_CUCUMBER_JAVA + m.group(1), m.group(1)));
IO_CUCUMBER_JAVA + m.group(1), m.group(1), progressMonitor));
} else {
importedAnnotations.add(new CucumberAnnotation(m.group(2), m.group(1)));
}
Expand Down Expand Up @@ -260,7 +260,7 @@ private int getLineNumber(ICompilationUnit compUnit, IAnnotation annotation) thr
}

private List<CucumberAnnotation> getAllAnnotationsInPackage(final IJavaProject javaProject,
final String packageFrag, final String lang) throws CoreException, JavaModelException {
final String packageFrag, final String lang, IProgressMonitor monitor) throws CoreException, JavaModelException {

SearchPattern pattern = SearchPattern.createPattern(packageFrag, IJavaSearchConstants.PACKAGE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
Expand All @@ -287,12 +287,12 @@ public void acceptSearchMatch(SearchMatch match) {
}
};
SearchEngine engine = new SearchEngine();
jdtSearch(engine, pattern, scope, requestor);
jdtSearch(engine, pattern, scope, requestor, monitor);
return annotations;
}

private void jdtSearch(SearchEngine engine, SearchPattern pattern, IJavaSearchScope scope,
SearchRequestor requestor) throws CoreException {
SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
try {
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null);
Expand All @@ -315,6 +315,10 @@ private CucumberAnnotation getCukeAnnotation(List<CucumberAnnotation> importedAn
if (m.find()) {
return new CucumberAnnotation(m.group(2), m.group(1));
}
m = ioCucumberAnnotationMatcher.matcher(annotation.getElementName());
if (m.find()) {
return new CucumberAnnotation(m.group(2), m.group(1));
}
for (CucumberAnnotation cuke : importedAnnotations) {
if (cuke.getAnnotation().equals(annotation.getElementName()))
return cuke;
Expand Down Expand Up @@ -397,7 +401,7 @@ public boolean support(IResource resource) throws CoreException {
private Set<StepDefinition> findStepDefinitionsInClasspath(IJavaProject javaProject, MarkerFactory markerFactory,
IProgressMonitor monitor) throws CoreException {

SearchPattern searchPattern = SearchPattern.createPattern("cucumber.api.java.*.*", IJavaSearchConstants.TYPE,
SearchPattern searchPattern = SearchPattern.createPattern("*cucumber*.java*", IJavaSearchConstants.TYPE,
IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE,
SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);

Expand Down Expand Up @@ -456,7 +460,7 @@ public void acceptSearchMatch(SearchMatch match) {
};

for (IJavaSearchScope scope : scopes) {
jdtSearch(engine, searchPattern, scope, requestor);
jdtSearch(engine, searchPattern, scope, requestor, monitor);
}

return stepDefinitions;
Expand Down

0 comments on commit 05d723a

Please sign in to comment.