Skip to content

Commit b201ed2

Browse files
committed
MTA-4775: Effort differs between applications depending on whether they can be built or not
Signed-off-by: A.Arnold <[email protected]>
1 parent dd484d7 commit b201ed2

File tree

2 files changed

+144
-36
lines changed

2 files changed

+144
-36
lines changed

docs/topics/create-yaml-rule.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ _Example_
173173
when:
174174
java.referenced:
175175
location: PACKAGE
176-
pattern: org.jboss.*
176+
pattern: org.jboss*
177177
----
178178

179179
. Create an `AND` or `OR` condition

docs/topics/yaml-rule-structure-syntax.adoc

Lines changed: 143 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ when:
228228

229229
{ProductShortName} supports three types of conditions: `provider`, `and`, and `or`.
230230

231-
==== Provider conditions
231+
[id="yaml-provider-conditions_{context}"]
232+
== Provider conditions
232233

233234
The Application Analyzer detects the programming languages, frameworks, and tools used to build an application, and it generates default rulesets for each supported provider using the Language Server Protocol (LSP) accordingly.
234235
Each supported provider has a ruleset defined by default and is run independently in a separate container.
@@ -273,7 +274,8 @@ a|
273274
* Node.js
274275
|===
275276

276-
===== `builtin` provider
277+
[id="yaml-builtin-provider_{context}"]
278+
=== `builtin` provider
277279

278280
`builtin` is an internal provider that can analyze various files and internal metadata generated by the engine.
279281

@@ -350,15 +352,19 @@ when:
350352
----
351353
<1> When more than one tag is given, a logical AND is implied.
352354

353-
===== `java` provider
355+
[id="yaml-java-provider_{context}"]
356+
=== `java` provider
354357

355-
The `java` provider analyzes Java source code.
358+
The Language Server used by the Java provider is Eclipse’s JDT Language Server (JDTLS). Internally, the JDTLS uses the Eclipse Java Development Toolkit, which includes utilities for searching code in projects.
356359

357360
This provider has the following capabilities:
358361

359362
* `referenced`
360363
* `dependency`
361364

365+
In the `pattern` element of a `java.referenced` condition, you can search through application code by using these utilities. For more details, see link:https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fsearch%2FSearchPattern.html&anchor=createPattern[Class SearchPattern], which contains all the information for building these patterns for `createPattern(String, int, int, int)`.
366+
367+
362368
.`referenced`
363369

364370
The `referenced` capability enables the provider to find references in the source code. This capability takes three input parameters: `pattern`, `location`, and `annotated`.
@@ -371,49 +377,151 @@ when:
371377
location: "<location>" <2>
372378
annotated: "<annotated>" <3>
373379
----
374-
<1> A regular expression pattern to match, for example, `org.kubernetes.*`.
380+
<1> A regular expression pattern to match, for example, `org.kubernetes*`.
375381
<2> Specifies the exact location where the pattern needs to be matched, for example, `IMPORT`.
376382
<3> Checks for specific annotations and their elements, such as name and value in the Java code using a query. For example, the following query matches the Bean(url = “http://www.example.com”) annotation in the method.
383+
384+
385+
.Examples
386+
387+
* Search for any class under the `javax.xml` package, occurring in any
388+
location:
377389
+
378-
[source,terminal]
390+
[source,yaml]
379391
----
380-
annotated:
381-
pattern: org.framework.Bean
382-
elements:
383-
- name: url
384-
value: "http://www.example.com"
392+
java.referenced:
393+
pattern: javax.xml*
385394
----
395+
+
396+
[WARNING]
397+
====
398+
If you want to match using an asterisk `*` wildcard for a wider range of results, it is recommended to place it directly after the package, not after the dot:
386399
387-
The supported locations are the following:
400+
For example:
388401
389-
* `CONSTRUCTOR_CALL`
390-
* `TYPE`
391-
* `INHERITANCE`
392-
* `METHOD_CALL`
393-
* `ANNOTATION`
394-
* `IMPLEMENTS_TYPE`
395-
* `ENUM_CONSTANT`
396-
* `RETURN_TYPE`
397-
* `IMPORT`
398-
* `VARIABLE_DECLARATION`
399-
* `FIELD`
400-
* `METHOD`
402+
* `pattern: javax.xml*`
403+
+
404+
and not:
401405
402-
.`dependency`
406+
* `pattern: javax.xml.*`
407+
====
403408

404-
The `dependency` capability enables the provider to find dependencies for a given application. {ProductShortName} generates a list of the application's dependencies, and you can use this capability to query the list and check whether a certain dependency exists for the application within a given range of the dependency's versions.
409+
* Search for method declarations that return `java.lang.String`:
410+
+
411+
[source,yaml]
412+
----
413+
java.referenced:
414+
location: METHOD
415+
pattern: '* java.lang.String'
416+
----
405417

406-
[source,terminal]
418+
* Search for a method named "`method`" declared on `org.konveyor.MyClass`
419+
that returns a `List` of a type that extends `java.lang.String`:
420+
+
421+
[source,yaml]
407422
----
408-
when:
409-
java.dependency:
410-
name: "<dependency_name>" <1>
411-
upperbound: "<version_string>" <2>
412-
lowerbound: "<version_string>" <3>
423+
java.referenced:
424+
location: METHOD
425+
pattern: 'org.konveyor.Myclass.method(*) java.util.List<? extends java.lang.String>'
413426
----
414-
<1> Name of the dependency to search for.
415-
<2> Upper bound on the version of the dependency.
416-
<3> Lower bound on the version of the dependency.
427+
428+
* Search for a class that implements `java.util.List`:
429+
+
430+
[source,yaml]
431+
----
432+
java.referenced:
433+
location: IMPLEMENTS_TYPE
434+
pattern: java.util.List
435+
----
436+
437+
[id="yaml-java-locations_{context}"]
438+
==== `java` locations
439+
440+
The Java provider allows scoping down the search to certain source code locations. You can scope down Java searches from any one of the following search locations:
441+
442+
* *IMPORT*: IMPORT allows for searches on class imports. It can either be used with a fully qualified domain name (FQDN) or an asterisk as a wildcard to allow for wider matches:
443+
+
444+
For example:
445+
+
446+
[source,yaml]
447+
----
448+
java.referenced:
449+
pattern: org.apache.lucene.search*
450+
location: IMPORT
451+
----
452+
453+
+
454+
This scope would match on each of these imports:
455+
+
456+
[source,java]
457+
----
458+
import org.apache.lucene.search.Query;
459+
import org.apache.lucene.search.Sort;
460+
import org.apache.lucene.search.SortField;
461+
----
462+
+
463+
If you want to match using an asterisk `*` wildcard for a wider range of results, it is recommended to place it directly after the package, not after the dot:
464+
465+
** Use: `org.apache.lucene.search*`
466+
467+
** Do not use: `org.apache.lucene.search.*`
468+
469+
470+
* *PACKAGE*: PACKAGE allows for searches on any usage of a package, be it in an import or used as part of a FQDN in the code:
471+
+
472+
[source,yaml]
473+
----
474+
java.referenced:
475+
pattern: org.apache.lucene.search*
476+
location: PACKAGE
477+
----
478+
+
479+
This scope would match on both the import and the fully qualified usage:
480+
+
481+
[source,java]
482+
----
483+
import org.apache.lucene.search.*;
484+
----
485+
+
486+
[source,java]
487+
----
488+
public class Test {
489+
private org.apache.lucene.search.Query query;
490+
}
491+
----
492+
+
493+
If you want to match using an asterisk `*` wildcard for a wider range of results, it is recommended to place it directly after the package, not after the dot.
494+
495+
496+
* *CONSTRUCTOR_CALL* and *METHOD_CALL*: for matching constructors and methods, respectively. The pattern possibilities are varied, and it is possible to match against specific return types, arguments, and so on.
497+
+
498+
For instance, looking for a method named `method` declared in the `org.konveyor.MyClass` that returns a `List` of a type that extends `java.lang.String` and accepts a single parameter:
499+
+
500+
[source,yaml]
501+
----
502+
java.referenced:
503+
location: METHOD
504+
pattern: 'org.konveyor.Myclass.method(*) java.util.List<? extends java.lang.String>'
505+
----
506+
507+
More information about the possibilities of these patterns can be found in the link:[Class SearchPattern section] of the Eclipse documentation, which contain all the required information for building these patterns.
508+
509+
[WARNING]
510+
====
511+
In the current release of {ProductShortName}, fully qualified static method matching does not function as expected.
512+
====
513+
514+
* *TYPE*: matches against types in general, appearing anywhere.
515+
* *INHERITANCE*: matches against a class inheriting from a given type.
516+
* *ANNOTATION*: matches against annotations.
517+
* *IMPLEMENTS_TYPE*: matches against any type implementing the given type.
518+
* *ENUM_CONSTANT*: matches against enum constants.
519+
* *RETURN_TYPE*: matches against a type being returned by a method.
520+
* *VARIABLE_DECLARATION*: matches against a type being declared as a variable.
521+
* *FIELD* (declaration): matches against a type appearing in a field declaration. It can be coupled with an annotation match, this being an annotation happening on the field.
522+
* *METHOD*: matches against a given method declaration. It can be coupled with an annotation match.
523+
* *CLASS* (declaration): matches against a given method declaration. It can be coupled with an annotation match.
524+
417525

418526
===== `go` provider
419527

0 commit comments

Comments
 (0)