Skip to content

Commit b4a4bfd

Browse files
angelozerrdatho7561
authored andcommitted
Don't re-trigger Java validation for all opened Java files when a Java
file is saved. Signed-off-by: azerr <azerr@redhat.com>
1 parent 128c765 commit b4a4bfd

5 files changed

Lines changed: 66 additions & 61 deletions

File tree

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/project/AbstractConfigSource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ public Integer getPropertyAsInt(String key) {
218218
return null;
219219
}
220220

221-
private void reset() {
221+
@Override
222+
public void reset() {
222223
config = null;
223224
propertyInformations = null;
224225
}

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/project/IConfigSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ public interface IConfigSource {
100100
*/
101101
Set<String> getAllKeys();
102102

103+
void reset();
103104
}

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/project/JDTMicroProfileProject.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.logging.Logger;
2626
import java.util.stream.Collectors;
2727

28+
import org.eclipse.core.resources.IFile;
2829
import org.eclipse.core.resources.IProject;
2930
import org.eclipse.core.runtime.IPath;
3031
import org.eclipse.jdt.core.IClasspathEntry;
@@ -220,6 +221,29 @@ public void evictConfigSourcesCache() {
220221
aggregatedPropertiesProvider = null;
221222
}
222223

224+
/**
225+
* Try updating the given config source file
226+
*
227+
* @param file
228+
* @return true if the config source file has been updated (ex:
229+
* src/main/resources/microprofile-config.properties) and false
230+
* otherwise (ex: target/classes/microprofile-config.properties)
231+
*/
232+
public boolean updateConfigSource(IFile file) {
233+
if (configSources != null) {
234+
for (IConfigSource configSource : configSources) {
235+
// If file comes from target folder, the file will not be updated.
236+
if (configSource.getSourceConfigFileURI().endsWith(file.getLocation().toString())) {
237+
configSource.reset();
238+
propertyValueExpander = null;
239+
aggregatedPropertiesProvider = null;
240+
return true;
241+
}
242+
}
243+
}
244+
return false;
245+
}
246+
223247
/**
224248
* Load config sources from the given project and sort it by using
225249
* {@link IConfigSource#getOrdinal()}

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/project/JDTMicroProfileProjectManager.java

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import org.eclipse.core.resources.IResource;
2424
import org.eclipse.core.resources.IResourceChangeEvent;
2525
import org.eclipse.core.resources.IResourceChangeListener;
26-
import org.eclipse.core.resources.IResourceDelta;
27-
import org.eclipse.core.resources.IResourceDeltaVisitor;
2826
import org.eclipse.core.resources.ResourcesPlugin;
29-
import org.eclipse.core.runtime.CoreException;
3027
import org.eclipse.jdt.core.IJavaProject;
3128
import org.eclipse.jdt.core.JavaCore;
3229
import org.eclipse.jdt.core.JavaModelException;
@@ -52,7 +49,10 @@ public static JDTMicroProfileProjectManager getInstance() {
5249
private final Map<IJavaProject, JDTMicroProfileProject> projects;
5350
private MicroProfileProjectListener microprofileProjectListener;
5451

55-
private class MicroProfileProjectListener implements IResourceChangeListener, IResourceDeltaVisitor {
52+
/**
53+
* Resource Listener to update MicroProfile projects cache.
54+
*/
55+
private class MicroProfileProjectListener implements IResourceChangeListener {
5656

5757
@Override
5858
public void resourceChanged(IResourceChangeEvent event) {
@@ -81,18 +81,6 @@ public void resourceChanged(IResourceChangeEvent event) {
8181
}
8282
break;
8383
}
84-
case IResourceChangeEvent.POST_CHANGE:
85-
IResourceDelta resourceDelta = event.getDelta();
86-
if (resourceDelta != null) {
87-
try {
88-
resourceDelta.accept(this);
89-
} catch (CoreException e) {
90-
if (LOGGER.isLoggable(Level.SEVERE)) {
91-
LOGGER.log(Level.SEVERE, "Error while tracking MicroProfile properties file", e);
92-
}
93-
}
94-
}
95-
break;
9684
}
9785
}
9886

@@ -104,44 +92,6 @@ private void evict(IProject project) {
10492
}
10593
}
10694

107-
@Override
108-
public boolean visit(IResourceDelta delta) throws CoreException {
109-
IResource resource = delta.getResource();
110-
if (resource == null) {
111-
return false;
112-
}
113-
switch (resource.getType()) {
114-
case IResource.ROOT:
115-
case IResource.PROJECT:
116-
case IResource.FOLDER:
117-
return resource.isAccessible();
118-
case IResource.FILE:
119-
IFile file = (IFile) resource;
120-
if ((isFileDeleted(delta) || isFileContentChanged(delta) || isFileAdded(delta))
121-
&& isConfigSource(file)) {
122-
// it's a config source file (ex : microprofile-config.properties)
123-
JDTMicroProfileProject mpProject = getJDTMicroProfileProject(file);
124-
if (mpProject != null) {
125-
// Evict the properties cache
126-
mpProject.evictConfigSourcesCache();
127-
}
128-
}
129-
}
130-
return false;
131-
}
132-
133-
private boolean isFileDeleted(IResourceDelta delta) {
134-
return delta.getKind() == IResourceDelta.REMOVED;
135-
}
136-
137-
private boolean isFileAdded(IResourceDelta delta) {
138-
return delta.getKind() == IResourceDelta.ADDED;
139-
}
140-
141-
private boolean isFileContentChanged(IResourceDelta delta) {
142-
return (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0);
143-
}
144-
14595
}
14696

14797
private JDTMicroProfileProjectManager() {

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/core/MicroProfilePropertiesListenerManager.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,33 @@ public boolean visit(IResourceDelta delta) throws CoreException {
189189
mpProject.getProjectRuntime().clearProjectClassCache();
190190
}
191191
fireAsyncEvent(event);
192-
} else if (isConfigSource(file) && isFileContentChanged(delta)) {
193-
MicroProfilePropertiesChangeEvent event = new MicroProfilePropertiesChangeEvent();
194-
event.setType(MicroProfilePropertiesScope.ONLY_CONFIG_FILES);
195-
event.setProjectURIs(new HashSet<String>());
196-
event.getProjectURIs().add(JDTMicroProfileUtils.getProjectURI(file.getProject()));
197-
fireAsyncEvent(event);
192+
} else if (isConfigSource(file)) {
193+
// Create, delete, update config source file (ex :
194+
// microprofile-config.properties)
195+
196+
JDTMicroProfileProject mpProject = JDTMicroProfileProjectManager.getInstance()
197+
.getJDTMicroProfileProject(file);
198+
199+
boolean generateEvent = false;
200+
if (isFileDeleted(delta) || isFileAdded(delta)) {
201+
generateEvent = true;
202+
// Create, delete config source file (ex : microprofile-config.properties)
203+
if (mpProject != null) {
204+
// Evict the properties cache
205+
mpProject.evictConfigSourcesCache();
206+
}
207+
} else if (isFileContentChanged(delta)) {
208+
// Update config source file (ex : microprofile-config.properties)
209+
generateEvent = mpProject != null ? mpProject.updateConfigSource(file) : true;
210+
}
211+
212+
if (generateEvent) {
213+
MicroProfilePropertiesChangeEvent event = new MicroProfilePropertiesChangeEvent();
214+
event.setType(MicroProfilePropertiesScope.ONLY_CONFIG_FILES);
215+
event.setProjectURIs(new HashSet<String>());
216+
event.getProjectURIs().add(JDTMicroProfileUtils.getProjectURI(file.getProject()));
217+
fireAsyncEvent(event);
218+
}
198219
}
199220
}
200221
return false;
@@ -277,6 +298,14 @@ private boolean isConfigSource(IFile file) {
277298
return JDTMicroProfileProjectManager.getInstance().isConfigSource(file);
278299
}
279300

301+
private boolean isFileDeleted(IResourceDelta delta) {
302+
return delta.getKind() == IResourceDelta.REMOVED;
303+
}
304+
305+
private boolean isFileAdded(IResourceDelta delta) {
306+
return delta.getKind() == IResourceDelta.ADDED;
307+
}
308+
280309
private boolean isFileContentChanged(IResourceDelta delta) {
281310
return (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0);
282311
}

0 commit comments

Comments
 (0)