19
19
import java .io .File ;
20
20
import java .io .IOException ;
21
21
import java .util .LinkedHashSet ;
22
+ import java .util .Optional ;
22
23
import java .util .Set ;
23
24
24
- import com .google .common .base .Optional ;
25
- import com .gradleware .tooling .toolingmodel .OmniEclipseProject ;
26
- import com .gradleware .tooling .toolingmodel .OmniProjectTask ;
27
- import com .gradleware .tooling .toolingmodel .repository .FetchStrategy ;
28
25
import io .spring .javaformat .eclipse .Executor ;
29
26
import io .spring .javaformat .eclipse .Messages ;
30
27
import io .spring .javaformat .eclipse .projectsettings .ProjectSettingsFilesLocator ;
31
- import org .eclipse .buildship .core .CorePlugin ;
32
- import org .eclipse .buildship .core .workspace .GradleBuild ;
33
- import org .eclipse .buildship .core .workspace .GradleWorkspaceManager ;
28
+ import org .eclipse .buildship .core .GradleBuild ;
29
+ import org .eclipse .buildship .core .internal .CorePlugin ;
30
+ import org .eclipse .buildship .core .internal .workspace .FetchStrategy ;
31
+ import org .eclipse .buildship .core .internal .workspace .InternalGradleBuild ;
32
+ import org .eclipse .buildship .core .internal .workspace .InternalGradleWorkspace ;
33
+ import org .eclipse .buildship .core .internal .workspace .ModelProviderUtil ;
34
34
import org .eclipse .core .resources .IProject ;
35
35
import org .eclipse .core .resources .ResourcesPlugin ;
36
36
import org .eclipse .core .runtime .CoreException ;
40
40
import org .eclipse .core .runtime .jobs .Job ;
41
41
import org .gradle .tooling .CancellationTokenSource ;
42
42
import org .gradle .tooling .GradleConnector ;
43
+ import org .gradle .tooling .model .GradleTask ;
44
+ import org .gradle .tooling .model .eclipse .EclipseProject ;
43
45
44
46
/**
45
47
* Job to trigger refresh of project specific settings when the gradle plugin is used.
@@ -73,30 +75,29 @@ protected IStatus run(IProgressMonitor monitor) {
73
75
74
76
private void configureProjects (IProgressMonitor monitor )
75
77
throws CoreException , IOException {
76
- GradleWorkspaceManager manager = CorePlugin .gradleWorkspaceManager ();
78
+ InternalGradleWorkspace workspace = CorePlugin .internalGradleWorkspace ();
77
79
for (IProject project : ResourcesPlugin .getWorkspace ().getRoot ().getProjects ()) {
78
- Optional <GradleBuild > build = manager . getGradleBuild (project );
80
+ Optional <GradleBuild > build = workspace . getBuild (project );
79
81
if (build .isPresent ()) {
80
- configureProject (project , build .get (), monitor );
82
+ configureProject (project , ( InternalGradleBuild ) build .get (), monitor );
81
83
}
82
84
}
83
85
}
84
86
85
- private void configureProject (IProject project , GradleBuild build ,
87
+ private void configureProject (IProject project , InternalGradleBuild build ,
86
88
IProgressMonitor monitor ) throws CoreException , IOException {
87
- Set <OmniEclipseProject > projects = build .getModelProvider ()
88
- .fetchEclipseGradleProjects (FetchStrategy .FORCE_RELOAD ,
89
- this .tokenSource .token (), monitor );
89
+ Set <EclipseProject > projects = ModelProviderUtil .fetchAllEclipseProjects (build ,
90
+ this .tokenSource , FetchStrategy .FORCE_RELOAD , monitor );
90
91
if (hasSpringFormatPlugin (projects )) {
91
92
ProjectSettingsFilesLocator locator = new ProjectSettingsFilesLocator (
92
93
getSearchFolders (projects ));
93
94
locator .locateSettingsFiles ().applyToProject (project , monitor );
94
95
}
95
96
}
96
97
97
- private boolean hasSpringFormatPlugin (Set <OmniEclipseProject > projects ) {
98
- for (OmniEclipseProject project : projects ) {
99
- for (OmniProjectTask task : project .getGradleProject ().getProjectTasks ()) {
98
+ private boolean hasSpringFormatPlugin (Set <EclipseProject > projects ) {
99
+ for (EclipseProject project : projects ) {
100
+ for (GradleTask task : project .getGradleProject ().getTasks ()) {
100
101
if (isSpringFormatPlugin (task )) {
101
102
return true ;
102
103
}
@@ -105,15 +106,17 @@ private boolean hasSpringFormatPlugin(Set<OmniEclipseProject> projects) {
105
106
return false ;
106
107
}
107
108
108
- private boolean isSpringFormatPlugin (OmniProjectTask task ) {
109
+ private boolean isSpringFormatPlugin (GradleTask task ) {
109
110
return TASK_NAME .equals (task .getName ());
110
111
}
111
112
112
- private Set <File > getSearchFolders (Set <OmniEclipseProject > projects ) {
113
+ private Set <File > getSearchFolders (Set <EclipseProject > projects ) {
113
114
Set <File > searchFolders = new LinkedHashSet <>();
114
- for (OmniEclipseProject project : projects ) {
115
- searchFolders .add (project .getProjectDirectory ());
116
- searchFolders .add (project .getRoot ().getProjectDirectory ());
115
+ for (EclipseProject project : projects ) {
116
+ while (project != null ) {
117
+ searchFolders .add (project .getProjectDirectory ());
118
+ project = project .getParent ();
119
+ }
117
120
}
118
121
return searchFolders ;
119
122
}
0 commit comments