1
1
/*
2
- * Copyright 2012-2023 the original author or authors.
2
+ * Copyright 2012-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .io .FileWriter ;
21
21
import java .io .IOException ;
22
22
import java .util .Properties ;
23
- import java .util .concurrent .Callable ;
24
23
import java .util .stream .Collectors ;
25
24
26
25
import org .gradle .api .DefaultTask ;
26
+ import org .gradle .api .Project ;
27
27
import org .gradle .api .Task ;
28
28
import org .gradle .api .artifacts .Configuration ;
29
29
import org .gradle .api .artifacts .ResolvedArtifact ;
30
30
import org .gradle .api .file .FileCollection ;
31
+ import org .gradle .api .file .RegularFileProperty ;
32
+ import org .gradle .api .provider .Property ;
31
33
import org .gradle .api .tasks .Classpath ;
34
+ import org .gradle .api .tasks .Input ;
32
35
import org .gradle .api .tasks .OutputFile ;
33
36
import org .gradle .api .tasks .TaskAction ;
34
37
39
42
*
40
43
* @author Andy Wilkinson
41
44
*/
42
- public class StarterMetadata extends DefaultTask {
45
+ public abstract class StarterMetadata extends DefaultTask {
43
46
44
47
private Configuration dependencies ;
45
48
46
- private File destination ;
47
-
48
49
public StarterMetadata () {
49
- getInputs ().property ("name" , (Callable <String >) () -> getProject ().getName ());
50
- getInputs ().property ("description" , (Callable <String >) () -> getProject ().getDescription ());
50
+ Project project = getProject ();
51
+ getStarterName ().convention (project .provider (project ::getName ));
52
+ getStarterDescription ().convention (project .provider (project ::getDescription ));
51
53
}
52
54
55
+ @ Input
56
+ public abstract Property <String > getStarterName ();
57
+
58
+ @ Input
59
+ public abstract Property <String > getStarterDescription ();
60
+
53
61
@ Classpath
54
62
public FileCollection getDependencies () {
55
63
return this .dependencies ;
@@ -60,28 +68,23 @@ public void setDependencies(Configuration dependencies) {
60
68
}
61
69
62
70
@ OutputFile
63
- public File getDestination () {
64
- return this .destination ;
65
- }
66
-
67
- public void setDestination (File destination ) {
68
- this .destination = destination ;
69
- }
71
+ public abstract RegularFileProperty getDestination ();
70
72
71
73
@ TaskAction
72
74
void generateMetadata () throws IOException {
73
75
Properties properties = CollectionFactory .createSortedProperties (true );
74
- properties .setProperty ("name" , getProject ().getName ());
75
- properties .setProperty ("description" , getProject ().getDescription ());
76
+ properties .setProperty ("name" , getStarterName ().get ());
77
+ properties .setProperty ("description" , getStarterDescription ().get ());
76
78
properties .setProperty ("dependencies" ,
77
79
String .join ("," ,
78
80
this .dependencies .getResolvedConfiguration ()
79
81
.getResolvedArtifacts ()
80
82
.stream ()
81
83
.map (ResolvedArtifact ::getName )
82
84
.collect (Collectors .toSet ())));
83
- this .destination .getParentFile ().mkdirs ();
84
- try (FileWriter writer = new FileWriter (this .destination )) {
85
+ File destination = getDestination ().getAsFile ().get ();
86
+ destination .getParentFile ().mkdirs ();
87
+ try (FileWriter writer = new FileWriter (destination )) {
85
88
properties .store (writer , null );
86
89
}
87
90
}
0 commit comments