2020import java .util .logging .Logger ;
2121
2222import org .eclipse .core .resources .IFile ;
23+ import org .eclipse .core .resources .IProject ;
2324import org .eclipse .core .resources .IResource ;
2425import org .eclipse .core .resources .IResourceChangeEvent ;
2526import org .eclipse .core .resources .IResourceChangeListener ;
2627import org .eclipse .core .resources .IResourceDelta ;
2728import org .eclipse .core .resources .IResourceDeltaVisitor ;
2829import org .eclipse .core .resources .ResourcesPlugin ;
2930import org .eclipse .core .runtime .CoreException ;
31+ import org .eclipse .core .runtime .IPath ;
3032import org .eclipse .jdt .core .ElementChangedEvent ;
3133import org .eclipse .jdt .core .IElementChangedListener ;
3234import org .eclipse .jdt .core .IJavaElement ;
3335import org .eclipse .jdt .core .IJavaElementDelta ;
3436import org .eclipse .jdt .core .IJavaProject ;
37+ import org .eclipse .jdt .core .IPackageFragmentRoot ;
3538import org .eclipse .jdt .core .JavaCore ;
39+ import org .eclipse .jdt .core .JavaModelException ;
3640import org .eclipse .lsp4mp .commons .MicroProfilePropertiesChangeEvent ;
3741import org .eclipse .lsp4mp .commons .MicroProfilePropertiesScope ;
3842import org .eclipse .lsp4mp .jdt .core .IMicroProfilePropertiesChangedListener ;
@@ -146,11 +150,17 @@ public boolean visit(IResourceDelta delta) throws CoreException {
146150 if (resource == null ) {
147151 return false ;
148152 }
153+
154+ // Step 5: Process folders, files, and projects as needed
149155 switch (resource .getType ()) {
150156 case IResource .ROOT :
157+ return true ;
151158 case IResource .PROJECT :
159+ IProject project = (IProject ) resource ;
160+ return project .isAccessible () && project .hasNature (JavaCore .NATURE_ID );
152161 case IResource .FOLDER :
153- return resource .isAccessible ();
162+ // Ignore folder which belongs to Java output file location (ex: target/classes)
163+ return resource .isAccessible () && !isInOutput (resource );
154164 case IResource .FILE :
155165 IFile file = (IFile ) resource ;
156166 if (isJavaFile (file ) && isFileContentChanged (delta )) {
@@ -171,6 +181,43 @@ public boolean visit(IResourceDelta delta) throws CoreException {
171181 return false ;
172182 }
173183
184+ /**
185+ * Returns true if the given (folder) resource is in the Java output location
186+ * (ex : /target/classes) and false otherwise (ex: src/main/java).
187+ *
188+ * @param resource the folder resource.
189+ * @return true if the given (folder) resource is in the Java output location
190+ * (ex : /target/classes) and false otherwise (ex: src/main/java).
191+ * @throws JavaModelException
192+ */
193+ private static boolean isInOutput (IResource resource ) throws JavaModelException {
194+
195+ IJavaProject javaProject = JavaCore .create (resource .getProject ());
196+ IPath resourcePath = resource .getFullPath ();
197+
198+ // Exclude resources in the main output location (e.g.,/ProjectName/bin)
199+ IPath outputLocation = javaProject .getOutputLocation ();
200+ IPath outputFullPath = ResourcesPlugin .getWorkspace ().getRoot ().getFolder (outputLocation ).getFullPath ();
201+ if (outputFullPath .isPrefixOf (resourcePath )) {
202+ return true ;
203+ }
204+
205+ // Exclude resources in custom output locations (if any)
206+ for (IPackageFragmentRoot root : javaProject .getPackageFragmentRoots ()) {
207+ if (root .getKind () == IPackageFragmentRoot .K_SOURCE ) {
208+ IPath customOutput = root .getRawClasspathEntry ().getOutputLocation ();
209+ if (customOutput != null ) {
210+ IPath customFullPath = ResourcesPlugin .getWorkspace ().getRoot ().getFolder (customOutput )
211+ .getFullPath ();
212+ if (customFullPath .isPrefixOf (resourcePath )) {
213+ return true ;
214+ }
215+ }
216+ }
217+ }
218+ return false ;
219+ }
220+
174221 private void fireAsyncEvent (MicroProfilePropertiesChangeEvent event ) {
175222 // IMPORTANT: The LSP notification 'microprofile/propertiesChanged' must be
176223 // executed
0 commit comments