44import io .github .intisy .gradle .github .impl .Gradle ;
55import io .github .intisy .gradle .github .utils .FileUtils ;
66import io .github .intisy .gradle .github .utils .GradleUtils ;
7+ import org .eclipse .jgit .api .errors .GitAPIException ;
78import org .gradle .api .Action ;
89import org .gradle .api .Project ;
910import org .gradle .api .Task ;
1314import org .gradle .api .plugins .JavaPluginConvention ;
1415import org .gradle .api .tasks .Copy ;
1516import org .gradle .api .tasks .SourceSet ;
16- import org .gradle .internal .impldep .org .eclipse .jgit .api .errors .GitAPIException ;
1717
1818import java .io .File ;
1919import java .io .IOException ;
@@ -30,64 +30,56 @@ class Main implements org.gradle.api.Plugin<Project> {
3030 public void apply (Project project ) {
3131 GithubExtension githubExtension = project .getExtensions ().create ("github" , GithubExtension .class );
3232 Logger logger = new Logger (githubExtension , project );
33- GitHub gitHub = new GitHub (logger );
3433
3534 ResourcesExtension resourcesExtension = project .getExtensions ().create ("resources" , ResourcesExtension .class );
3635 Configuration githubImplementation = project .getConfigurations ().create ("githubImplementation" );
3736
38- Task processGitHubResources = project .getTasks ().create ("processGitHubResources" , task -> {
39- task .doLast (t -> {
40- logger .debug ("Process resource event called on " + project .getName ());
41- if (resourcesExtension .getRepoUrl () != null ) {
42- logger .debug ("Found an repository in the resource extension" );
43-
44- JavaPluginConvention javaConvention = project .getConvention ()
45- .getPlugin (JavaPluginConvention .class );
37+ JavaPluginConvention javaConvention = project .getConvention ()
38+ .getPlugin (JavaPluginConvention .class );
4639
47- SourceSet main = javaConvention .getSourceSets ()
48- .getByName (SourceSet .MAIN_SOURCE_SET_NAME );
40+ SourceSet main = javaConvention .getSourceSets ()
41+ .getByName (SourceSet .MAIN_SOURCE_SET_NAME );
4942
50- Set <File > resourceDirs = main .getResources ().getSrcDirs ();
51- String [] repoParts = resourcesExtension . getRepoUrl (). split ( "/" );
43+ Set <File > resourceDirs = main .getResources ().getSrcDirs ();
44+ GitHub gitHub = new GitHub ( logger , resourcesExtension , githubExtension );
5245
53- String repoOwner = repoParts [3 ];
54- String repoName = repoParts [4 ];
46+ Task processGitHubResources = project .getTasks ().create ("processGitHubResources" , task -> task .doLast (t -> {
47+ logger .debug ("Process resource event called on " + project .getName ());
48+ if (resourcesExtension .getRepoUrl () != null ) {
49+ logger .debug ("Found an repository in the resource extension" );
5550
56- File path = GradleUtils .getGradleHome ().resolve ("resources" ).resolve (repoOwner + "-" + repoName ).toFile ();
51+ File path = GradleUtils .getGradleHome ().resolve ("resources" ).resolve (gitHub . getRepoOwner () + "-" + gitHub . getRepoName () ).toFile ();
5752
58- for (File dir : resourceDirs ) {
59- try {
60- gitHub . cloneOrPullRepository ( path , repoOwner , repoName , githubExtension . getAccessToken () , resourcesExtension .getBranch ());
53+ for (File dir : resourceDirs ) {
54+ try {
55+ gitHub . cloneOrPullRepository ( path , resourcesExtension .getBranch ());
6156
62- if (resourcesExtension .isBuildOnly ()) {
63- dir = project .getBuildDir ().toPath ().resolve ("resources" ).resolve (dir .getParentFile ().getName ()).toFile ();
64- }
57+ if (resourcesExtension .isBuildOnly ()) {
58+ dir = project .getBuildDir ().toPath ().resolve ("resources" ).resolve (dir .getParentFile ().getName ()).toFile ();
59+ }
6560
66- FileUtils .deleteDirectory (dir .toPath ());
61+ FileUtils .deleteDirectory (dir .toPath ());
6762
68- if (dir .mkdirs ()) {
69- logger .debug ("Copying resources from " + path + " to: " + dir );
70- FileUtils .copyDirectory (path .toPath ().resolve (resourcesExtension .getPath ()), dir .toPath ());
71- } else {
72- logger .error ("Failed to create directory: " + dir );
73- }
74- } catch (GitAPIException | IOException e ) {
75- throw new RuntimeException (e );
76- }
77- }
78- }
79- });
80- });
63+ if (dir .mkdirs ()) {
64+ logger .debug ("Copying resources from " + path + " to: " + dir );
65+ FileUtils .copyDirectory (path .toPath ().resolve (resourcesExtension .getPath ()), dir .toPath ());
66+ } else {
67+ logger .error ("Failed to create directory: " + dir );
68+ }
69+ } catch (GitAPIException | IOException e ) {
70+ throw new RuntimeException (e );
71+ }
72+ }
73+ }
74+ }));
8175
82- project .getPlugins ().withType (JavaPlugin .class , (Action <? super JavaPlugin >) plugin -> {
83- project .getTasks ().named ("processResources" , Copy .class , processResources -> {
84- logger .debug ("Process resource event found on " + project .getName ());
85- processResources .dependsOn (processGitHubResources );
86- });
87- });
76+ project .getPlugins ().withType (JavaPlugin .class , (Action <? super JavaPlugin >) plugin -> project .getTasks ().named ("processResources" , Copy .class , processResources -> {
77+ logger .debug ("Process resource event found on " + project .getName ());
78+ processResources .dependsOn (processGitHubResources );
79+ }));
8880
8981 project .afterEvaluate (proj -> githubImplementation .getDependencies ().all (dependency -> {
90- File jar = gitHub .getAsset (dependency .getName (), dependency . getGroup (), dependency . getVersion (), githubExtension . getAccessToken ());
82+ File jar = gitHub .getAsset (dependency .getVersion ());
9183
9284 project .getDependencies ().add ("implementation" , project .files (jar ));
9385 }));
@@ -119,7 +111,7 @@ public void apply(Project project) {
119111 String version = dependency .getVersion ();
120112
121113 logger .debug ("Updating GitHub dependency: " + name );
122- String newVersion = gitHub .getLatestVersion (group , name , githubExtension . getAccessToken () );
114+ String newVersion = gitHub .getLatestVersion ();
123115 if (version != null && !version .equals (newVersion )) {
124116 logger .log ("Updating GitHub dependency " + group + "/" + name + " (" + version + " -> " + newVersion + ")" );
125117 Gradle .modifyBuildFile (project , group + ":" + name + ":" + version , group + ":" + name + ":" + newVersion );
0 commit comments