1111import org .gradle .api .plugins .JavaPluginConvention ;
1212import org .gradle .api .tasks .SourceSet ;
1313
14+ import javax .annotation .Nonnull ;
1415import java .io .File ;
1516import java .net .MalformedURLException ;
1617import java .net .URL ;
2627import java .util .function .Predicate ;
2728import java .util .stream .Collectors ;
2829
30+ /**
31+ * Base class which provides common utility method to more specific plugins: like classpath
32+ * resources.
33+ *
34+ * Also, handle maven specific exceptions.
35+ *
36+ * @author edgar
37+ */
2938public class BaseTask extends DefaultTask {
3039
3140 protected static final String APP_CLASS = "mainClassName" ;
3241
33- public List <Project > getProjects () {
42+ /**
43+ * Available projects.
44+ *
45+ * @return Available projects.
46+ */
47+ public @ Nonnull List <Project > getProjects () {
3448 return Collections .singletonList (getProject ());
3549 }
3650
37- protected String computeMainClassName (List <Project > projects ) {
51+ /**
52+ * Compute class name from available projects.
53+ *
54+ * @param projects Projects.
55+ * @return Main class.
56+ */
57+ protected @ Nonnull String computeMainClassName (@ Nonnull List <Project > projects ) {
3858 return projects .stream ()
3959 .filter (it -> it .getProperties ().containsKey (APP_CLASS ))
4060 .map (it -> it .getProperties ().get (APP_CLASS ).toString ())
@@ -43,24 +63,55 @@ protected String computeMainClassName(List<Project> projects) {
4363 "Application class not found. Did you forget to set `" + APP_CLASS + "`?" ));
4464 }
4565
46- protected Set <Path > binDirectories (Project project , SourceSet sourceSet ) {
66+ /**
67+ * Project binary directories.
68+ *
69+ * @param project Project.
70+ * @param sourceSet Source set.
71+ * @return Directories.
72+ */
73+ protected @ Nonnull Set <Path > binDirectories (@ Nonnull Project project ,
74+ @ Nonnull SourceSet sourceSet ) {
4775 return classpath (project , sourceSet , it -> Files .exists (it ) && Files .isDirectory (it ));
4876 }
4977
50- protected Set <Path > dependencies (Project project , SourceSet sourceSet ) {
78+ /**
79+ * Project dependencies(jars).
80+ *
81+ * @param project Project.
82+ * @param sourceSet Source set.
83+ * @return Jar files.
84+ */
85+ protected @ Nonnull Set <Path > dependencies (@ Nonnull Project project ,
86+ @ Nonnull SourceSet sourceSet ) {
5187 return classpath (project , sourceSet , it -> Files .exists (it ) && it .toString ().endsWith (".jar" ));
5288 }
5389
54- protected Path classes (Project project ) {
55- SourceSet sourceSet = sourceSet (project );
90+ /**
91+ * Project classes directory.
92+ *
93+ * @param project Project.
94+ * @return Classes directory.
95+ */
96+ protected @ Nonnull Path classes (@ Nonnull Project project ) {
97+ SourceSet sourceSet = sourceSet (project );
5698 return sourceSet .getRuntimeClasspath ().getFiles ().stream ()
5799 .filter (f -> f .exists () && f .isDirectory () && f .toString ().contains ("classes" ))
58100 .findFirst ()
59101 .get ()
60102 .toPath ();
61103 }
62104
63- protected Set <Path > classpath (Project project , SourceSet sourceSet , Predicate <Path > predicate ) {
105+ /**
106+ * Project classpath.
107+ *
108+ * @param project Project.
109+ * @param sourceSet Source set.
110+ * @param predicate Path filter.
111+ * @return Classpath.
112+ */
113+ protected @ Nonnull Set <Path > classpath (@ Nonnull Project project , @ Nonnull SourceSet sourceSet ,
114+ @ Nonnull Predicate <Path > predicate ) {
64115 Set <Path > result = new LinkedHashSet <>();
65116 // classes/main, resources/main + jars
66117 sourceSet .getRuntimeClasspath ().getFiles ().stream ()
@@ -77,7 +128,14 @@ protected Set<Path> classpath(Project project, SourceSet sourceSet, Predicate<Pa
77128 return result ;
78129 }
79130
80- protected Set <Path > sourceDirectories (Project project , SourceSet sourceSet ) {
131+ /**
132+ * Project source directories.
133+ *
134+ * @param project Project.
135+ * @param sourceSet Source set.
136+ * @return Source directories.
137+ */
138+ protected @ Nonnull Set <Path > sourceDirectories (@ Nonnull Project project , @ Nonnull SourceSet sourceSet ) {
81139 Path eclipse = project .getProjectDir ().toPath ().resolve (".classpath" );
82140 if (Files .exists (eclipse )) {
83141 // let eclipse to do the incremental compilation
@@ -89,15 +147,34 @@ protected Set<Path> sourceDirectories(Project project, SourceSet sourceSet) {
89147 .collect (Collectors .toCollection (LinkedHashSet ::new ));
90148 }
91149
92- protected SourceSet sourceSet (final Project project ) {
150+ /**
151+ * Source set.
152+ *
153+ * @param project Project.
154+ * @return SourceSet.
155+ */
156+ protected @ Nonnull SourceSet sourceSet (final @ Nonnull Project project ) {
93157 return getJavaConvention (project ).getSourceSets ()
94158 .getByName (SourceSet .MAIN_SOURCE_SET_NAME );
95159 }
96160
97- protected JavaPluginConvention getJavaConvention (final Project project ) {
161+ /**
162+ * Java plugin convention.
163+ *
164+ * @param project Project.
165+ * @return Java plugin convention.
166+ */
167+ protected @ Nonnull JavaPluginConvention getJavaConvention (final @ Nonnull Project project ) {
98168 return project .getConvention ().getPlugin (JavaPluginConvention .class );
99169 }
100170
171+ /**
172+ * Creates a class loader.
173+ *
174+ * @param projects Projects to use.
175+ * @return Class loader.
176+ * @throws MalformedURLException If there is a bad path reference.
177+ */
101178 protected ClassLoader createClassLoader (List <Project > projects )
102179 throws MalformedURLException {
103180 List <URL > cp = new ArrayList <>();
0 commit comments