8
8
*/
9
9
package org .elasticsearch .gradle .internal .precommit ;
10
10
11
+ import org .elasticsearch .gradle .internal .AbstractDependenciesTask ;
11
12
import org .elasticsearch .gradle .internal .precommit .LicenseAnalyzer .LicenseInfo ;
12
- import org .gradle .api .DefaultTask ;
13
13
import org .gradle .api .GradleException ;
14
- import org .gradle .api .InvalidUserDataException ;
15
14
import org .gradle .api .artifacts .Configuration ;
16
15
import org .gradle .api .artifacts .component .ComponentIdentifier ;
17
16
import org .gradle .api .file .Directory ;
39
38
import java .util .Arrays ;
40
39
import java .util .HashMap ;
41
40
import java .util .HashSet ;
42
- import java .util .LinkedHashMap ;
43
41
import java .util .LinkedHashSet ;
44
42
import java .util .List ;
45
43
import java .util .Map ;
94
92
* comply with the license terms.
95
93
*/
96
94
@ CacheableTask
97
- public abstract class DependencyLicensesTask extends DefaultTask {
95
+ public abstract class DependencyLicensesTask extends AbstractDependenciesTask {
98
96
99
97
private final Pattern regex = Pattern .compile ("-v?\\ d+.*" );
100
98
@@ -112,11 +110,6 @@ public abstract class DependencyLicensesTask extends DefaultTask {
112
110
*/
113
111
private final DirectoryProperty licensesDir ;
114
112
115
- /**
116
- * A map of patterns to prefix, used to find the LICENSE and NOTICE file.
117
- */
118
- private Map <String , String > mappings = new LinkedHashMap <>();
119
-
120
113
/**
121
114
* Names of dependencies whose shas should not exist.
122
115
*/
@@ -128,24 +121,7 @@ public abstract class DependencyLicensesTask extends DefaultTask {
128
121
private LinkedHashSet <String > ignoreFiles = new LinkedHashSet <>();
129
122
private ProjectLayout projectLayout ;
130
123
131
- /**
132
- * Add a mapping from a regex pattern for the jar name, to a prefix to find
133
- * the LICENSE and NOTICE file for that jar.
134
- */
135
- public void mapping (Map <String , String > props ) {
136
- String from = props .get ("from" );
137
- if (from == null ) {
138
- throw new InvalidUserDataException ("Missing \" from\" setting for license name mapping" );
139
- }
140
- String to = props .get ("to" );
141
- if (to == null ) {
142
- throw new InvalidUserDataException ("Missing \" to\" setting for license name mapping" );
143
- }
144
- if (props .size () > 2 ) {
145
- throw new InvalidUserDataException ("Unknown properties for mapping on dependencyLicenses: " + props .keySet ());
146
- }
147
- mappings .put (from , to );
148
- }
124
+
149
125
150
126
@ Inject
151
127
public DependencyLicensesTask (ObjectFactory objects , ProjectLayout projectLayout ) {
@@ -267,7 +243,7 @@ private void checkDependencies(Map<String, Boolean> licenses, Map<String, Boolea
267
243
for (File dependency : dependencies ) {
268
244
String jarName = dependency .getName ();
269
245
String depName = regex .matcher (jarName ).replaceFirst ("" );
270
- String dependencyName = getDependencyName (mappings , depName );
246
+ String dependencyName = getDependencyName (getMappings (). get () , depName );
271
247
logger .info ("mapped dependency name {} to {} for license/notice check" , depName , dependencyName );
272
248
checkFile (dependencyName , jarName , licenses , "LICENSE" );
273
249
checkFile (dependencyName , jarName , notices , "NOTICE" );
@@ -321,11 +297,6 @@ public LinkedHashSet<String> getIgnoreFiles() {
321
297
return new LinkedHashSet <>(ignoreFiles );
322
298
}
323
299
324
- @ Input
325
- public LinkedHashMap <String , String > getMappings () {
326
- return new LinkedHashMap <>(mappings );
327
- }
328
-
329
300
/**
330
301
* Convencience method for configuring dependencies to be checked and ignoring transitive dependencies for now.
331
302
* */
0 commit comments