@@ -28,7 +28,7 @@ class ProtoPom extends XMLElement {
28
28
Version getVersion ( ) { result = this .getAChild ( ) }
29
29
30
30
/**
31
- * Gets a string representing the version, or an empty string if no version
31
+ * Gets a string representing the version, or an empty string if no ` version`
32
32
* tag was provided.
33
33
*/
34
34
string getVersionString ( ) {
@@ -53,7 +53,7 @@ class Pom extends ProtoPom {
53
53
Pom ( ) {
54
54
this .getName ( ) = "project" and
55
55
// Ignore "dependency-reduced-pom" files - these are generated by the
56
- // shading plugin , and duplicate existing pom files.
56
+ // Maven Shade Plugin , and duplicate existing POM files.
57
57
this .getFile ( ) .getStem ( ) != "dependency-reduced-pom"
58
58
}
59
59
@@ -77,7 +77,7 @@ class Pom extends ProtoPom {
77
77
/** Gets a child XML element named "dependencies". */
78
78
Dependencies getDependencies ( ) { result = this .getAChild ( ) }
79
79
80
- /** Gets a child XML element named ` dependencyManagement` . */
80
+ /** Gets a child XML element named " dependencyManagement" . */
81
81
DependencyManagement getDependencyManagement ( ) { result = getAChild ( ) }
82
82
83
83
/** Gets a Dependency element for this POM. */
@@ -100,7 +100,8 @@ class Pom extends ProtoPom {
100
100
}
101
101
102
102
/**
103
- * Gets a property value defined for this project with the given name.
103
+ * Gets a property value defined for this project with the given name, either in a local
104
+ * `<properties>` section, or in the `<properties>` section of an ancestor POM.
104
105
*/
105
106
PomProperty getProperty ( string name ) {
106
107
result .getName ( ) = name and
@@ -112,7 +113,7 @@ class Pom extends ProtoPom {
112
113
*/
113
114
PomElement getProjectProperty ( ) {
114
115
(
115
- // It must either be a child of the pom , or a child of the parent node of the pom
116
+ // It must either be a child of the POM , or a child of the parent node of the POM
116
117
result = getAChild ( )
117
118
or
118
119
result = getParentPom ( ) .getAChild ( ) and
@@ -124,8 +125,8 @@ class Pom extends ProtoPom {
124
125
}
125
126
126
127
/**
127
- * Resolve the given placeholder (if possible) in the static context of this pom . Resolution
128
- * occurs by considering the properties defined by this project.
128
+ * Resolve the given placeholder (if possible) in the static context of this POM . Resolution
129
+ * occurs by considering the properties defined by this project or an ancestor project .
129
130
*/
130
131
string resolvePlaceholder ( string name ) {
131
132
if name .prefix ( 8 ) = "project."
@@ -142,32 +143,33 @@ class Pom extends ProtoPom {
142
143
}
143
144
144
145
/**
145
- * Gets all the dependencies that are exported by this pom . An exported dependency is one that
146
- * is transitively available, i.e. one with scope compile.
146
+ * Gets all the dependencies that are exported by this POM . An exported dependency is one that
147
+ * is transitively available, i.e. one with scope " compile" .
147
148
*/
148
149
Dependency getAnExportedDependency ( ) {
149
150
result = getADependency ( ) and result .getScope ( ) = "compile"
150
151
}
151
152
152
153
/**
153
- * Gets a pom dependency that is exported by this pom . An exported dependency is one that
154
- * is transitively available, i.e. one with scope compile.
154
+ * Gets a POM dependency that is exported by this POM . An exported dependency is one that
155
+ * is transitively available, i.e. one with scope " compile" .
155
156
*/
156
157
Pom getAnExportedPom ( ) { result = getAnExportedDependency ( ) .getPom ( ) }
157
158
158
159
/**
159
- * Gets the `<parent>` element of this pom , if any.
160
+ * Gets the `<parent>` element of this POM , if any.
160
161
*/
161
162
Parent getParentElement ( ) { result = getAChild ( ) }
162
163
163
164
/**
164
- * Gets the pom referred to by the `<parent>` element of this pom , if any.
165
+ * Gets the POM referred to by the `<parent>` element of this POM , if any.
165
166
*/
166
167
Pom getParentPom ( ) { result = getParentElement ( ) .getPom ( ) }
167
168
168
169
/**
169
170
* Gets the version specified for dependency `dep` in a `dependencyManagement`
170
- * section if this pom or one of its ancestors.
171
+ * section in this POM or one of its ancestors, or an empty string if no version
172
+ * is specified.
171
173
*/
172
174
string getVersionStringForDependency ( Dependency dep ) {
173
175
if exists ( getDependencyManagement ( ) .getDependency ( dep ) )
@@ -223,12 +225,13 @@ class Dependency extends ProtoPom {
223
225
Pom getPom ( ) { result .getShortCoordinate ( ) = this .getShortCoordinate ( ) }
224
226
225
227
/**
226
- * Gets the jar file that we think maven resolved this dependency to (if any).
228
+ * Gets the jar file that Maven likely resolved this dependency to (if any).
229
+ * See `MavenRepo.getAnArtifact(ProtoPom)` for how this match is determined.
227
230
*/
228
231
File getJar ( ) { exists ( MavenRepo mr | result = mr .getAnArtifact ( this ) ) }
229
232
230
233
/**
231
- * Gets the scope of this dependency. If the scope tag is present, this will
234
+ * Gets the scope of this dependency. If the ` scope` tag is present, this will
232
235
* be the string contents of that tag, otherwise it defaults to "compile".
233
236
*/
234
237
string getScope ( ) {
@@ -249,14 +252,14 @@ class Dependency extends ProtoPom {
249
252
}
250
253
251
254
/**
252
- * A Maven dependency element that represents an actual dependency from a given pom project.
255
+ * A Maven dependency element that represents an actual dependency from a given POM project.
253
256
*/
254
257
class PomDependency extends Dependency {
255
258
PomDependency ( ) {
256
259
exists ( Pom source |
257
- // This dependency must be a dependency of a pom - dependency tags can also appear in the dependency
258
- // management section, where they do not directly contribute to the dependencies of the containing
259
- // pom .
260
+ // This dependency must be a dependency of a POM - dependency tags can also appear in the
261
+ // dependencyManagement section, where they do not directly contribute to the dependencies of
262
+ // the containing POM .
260
263
source .getADependency ( ) = this and
261
264
// Consider dependencies that can be used at compile time.
262
265
(
@@ -284,7 +287,7 @@ class PomElement extends XMLElement {
284
287
s = allCharactersString ( ) and
285
288
if s .matches ( "${%" )
286
289
then
287
- // Resolve the placeholder in the parent pom
290
+ // Resolve the placeholder in the parent POM
288
291
result = getParent * ( ) .( Pom ) .resolvePlaceholder ( s .substring ( 2 , s .length ( ) - 1 ) )
289
292
else result = s
290
293
)
@@ -330,7 +333,7 @@ class Dependencies extends PomElement {
330
333
Dependency getADependency ( ) { result = this .getAChild ( ) }
331
334
}
332
335
333
- /** An XML element named ` dependencyManagement` , as found in Maven POM XML files. */
336
+ /** An XML element named " dependencyManagement" , as found in Maven POM XML files. */
334
337
class DependencyManagement extends PomElement {
335
338
DependencyManagement ( ) { getName ( ) = "dependencyManagement" }
336
339
@@ -349,7 +352,7 @@ class DependencyManagement extends PomElement {
349
352
}
350
353
351
354
/**
352
- * An XML element name "properties", as found in Maven POM XML files.
355
+ * An XML element named "properties", as found in Maven POM XML files.
353
356
*/
354
357
class PomProperties extends PomElement {
355
358
PomProperties ( ) { this .getName ( ) = "properties" }
@@ -366,8 +369,8 @@ class PomProperty extends PomElement {
366
369
}
367
370
368
371
/**
369
- * A folder that represents a maven local repository using the standard layout. Any folder called
370
- * "repository" with a parent name ".m2" is considered to be a maven repository.
372
+ * A folder that represents a local Maven repository using the standard layout. Any folder called
373
+ * "repository" with a parent name ".m2" is considered to be a Maven repository.
371
374
*/
372
375
class MavenRepo extends Folder {
373
376
MavenRepo ( ) { getBaseName ( ) = "repository" and getParentContainer ( ) .getBaseName ( ) = ".m2" }
@@ -378,18 +381,18 @@ class MavenRepo extends Folder {
378
381
File getAJarFile ( ) { result = getAChildContainer * ( ) .( File ) and result .getExtension ( ) = "jar" }
379
382
380
383
/**
381
- * Gets any jar artifacts in this repository that match the pom project definition. This is an
382
- * over approximation. For soft qualifiers (e.g. 1.0) we return precise matches in preference to
383
- * artefact only matches. For hard qualifiers (e.g. [1.0]) we return only precise matches. For
384
- * all other qualifiers, we return all matches regardless of version.
384
+ * Gets any jar artifacts in this repository that match the POM project definition. This is an
385
+ * over approximation. For soft qualifiers (e.g. 1.0) precise matches are returned in preference
386
+ * to artifact- only matches. For hard qualifiers (e.g. [1.0]) only precise matches are returned.
387
+ * For all other qualifiers, all matches are returned regardless of version.
385
388
*/
386
389
MavenRepoJar getAnArtifact ( ProtoPom pom ) {
387
390
result = getAJarFile ( ) and
388
391
if exists ( MavenRepoJar mrj | mrj .preciseMatch ( pom ) ) or versionHardMatch ( pom )
389
392
then
390
393
// Either a hard match qualifier, or soft and there is at least one precise match
391
394
result .preciseMatch ( pom )
392
- else result .artefactMatches ( pom )
395
+ else result .artifactMatches ( pom )
393
396
}
394
397
}
395
398
@@ -401,16 +404,19 @@ private predicate versionHardMatch(ProtoPom pom) {
401
404
}
402
405
403
406
/**
404
- * A jar file inside a maven repository.
407
+ * A jar file inside a Maven repository.
405
408
*
406
409
* See: https://cwiki.apache.org/confluence/display/MAVENOLD/Repository+Layout+-+Final
407
410
*/
408
411
class MavenRepoJar extends File {
409
412
MavenRepoJar ( ) { exists ( MavenRepo mr | mr .getAJarFile ( ) = this ) }
410
413
411
- string getGroupID ( ) {
414
+ /**
415
+ * Gets the `groupId` of this jar.
416
+ */
417
+ string getGroupId ( ) {
412
418
exists ( MavenRepo mr | mr .getAJarFile ( ) = this |
413
- // Assuming the standard layout, the first part of the directory structure from the maven
419
+ // Assuming the standard layout, the first part of the directory structure from the Maven
414
420
// repository will be the groupId converted to a path by replacing "." with "/".
415
421
result =
416
422
getParentContainer ( )
@@ -422,24 +428,30 @@ class MavenRepoJar extends File {
422
428
)
423
429
}
424
430
425
- string getArtefactID ( ) { result = getParentContainer ( ) .getParentContainer ( ) .getBaseName ( ) }
431
+ /**
432
+ * Gets the `artifactId` of this jar.
433
+ */
434
+ string getArtifactId ( ) { result = getParentContainer ( ) .getParentContainer ( ) .getBaseName ( ) }
426
435
436
+ /**
437
+ * Gets the artifact version string of this jar.
438
+ */
427
439
string getVersion ( ) { result = getParentContainer ( ) .getBaseName ( ) }
428
440
429
441
/**
430
- * Holds if this jar is an artefact for the given pom or dependency, regardless of which version it is.
442
+ * Holds if this jar is an artifact for the given POM or dependency, regardless of which version it is.
431
443
*/
432
- predicate artefactMatches ( ProtoPom pom ) {
433
- pom .getGroup ( ) .getValue ( ) = getGroupID ( ) and
434
- pom .getArtifact ( ) .getValue ( ) = getArtefactID ( )
444
+ predicate artifactMatches ( ProtoPom pom ) {
445
+ pom .getGroup ( ) .getValue ( ) = getGroupId ( ) and
446
+ pom .getArtifact ( ) .getValue ( ) = getArtifactId ( )
435
447
}
436
448
437
449
/**
438
- * Holds if this jar is both an artefact for the pom , and has a version string that matches the pom
450
+ * Holds if this jar is both an artifact for the POM , and has a version string that matches the POM
439
451
* version string. Only soft and hard version matches are supported.
440
452
*/
441
453
predicate preciseMatch ( ProtoPom pom ) {
442
- artefactMatches ( pom ) and
454
+ artifactMatches ( pom ) and
443
455
if versionHardMatch ( pom )
444
456
then ( "[" + getVersion ( ) + "]" ) .matches ( pom .getVersionString ( ) + "%" )
445
457
else getVersion ( ) .matches ( pom .getVersionString ( ) + "%" )
0 commit comments