Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public Integer getPropertyAsInt(String key) {
return null;
}

private void reset() {
@Override
public void reset() {
config = null;
propertyInformations = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ public interface IConfigSource {
*/
Set<String> getAllKeys();

void reset();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathEntry;
Expand Down Expand Up @@ -220,6 +221,29 @@ public void evictConfigSourcesCache() {
aggregatedPropertiesProvider = null;
}

/**
* Try updating the given config source file
*
* @param file
* @return true if the config source file has been updated (ex:
* src/main/resources/microprofile-config.properties) and false
* otherwise (ex: target/classes/microprofile-config.properties)
*/
public boolean updateConfigSource(IFile file) {
if (configSources != null) {
for (IConfigSource configSource : configSources) {
// If file comes from target folder, the file will not be updated.
if (configSource.getSourceConfigFileURI().endsWith(file.getLocation().toString())) {
configSource.reset();
propertyValueExpander = null;
aggregatedPropertiesProvider = null;
return true;
}
}
}
return false;
}

/**
* Load config sources from the given project and sort it by using
* {@link IConfigSource#getOrdinal()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
Expand All @@ -52,7 +49,10 @@ public static JDTMicroProfileProjectManager getInstance() {
private final Map<IJavaProject, JDTMicroProfileProject> projects;
private MicroProfileProjectListener microprofileProjectListener;

private class MicroProfileProjectListener implements IResourceChangeListener, IResourceDeltaVisitor {
/**
* Resource Listener to update MicroProfile projects cache.
*/
private class MicroProfileProjectListener implements IResourceChangeListener {

@Override
public void resourceChanged(IResourceChangeEvent event) {
Expand Down Expand Up @@ -81,18 +81,6 @@ public void resourceChanged(IResourceChangeEvent event) {
}
break;
}
case IResourceChangeEvent.POST_CHANGE:
IResourceDelta resourceDelta = event.getDelta();
if (resourceDelta != null) {
try {
resourceDelta.accept(this);
} catch (CoreException e) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, "Error while tracking MicroProfile properties file", e);
}
}
}
break;
}
}

Expand All @@ -104,44 +92,6 @@ private void evict(IProject project) {
}
}

@Override
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
if (resource == null) {
return false;
}
switch (resource.getType()) {
case IResource.ROOT:
case IResource.PROJECT:
case IResource.FOLDER:
return resource.isAccessible();
case IResource.FILE:
IFile file = (IFile) resource;
if ((isFileDeleted(delta) || isFileContentChanged(delta) || isFileAdded(delta))
&& isConfigSource(file)) {
// it's a config source file (ex : microprofile-config.properties)
JDTMicroProfileProject mpProject = getJDTMicroProfileProject(file);
if (mpProject != null) {
// Evict the properties cache
mpProject.evictConfigSourcesCache();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was super annoying because it evicted the config source cache as soon as an application.properties was updated (in other words when a Java file was saved because target/classes/application.properties was updated) or when src/main/resources/application.properties was updated.

}
}
}
return false;
}

private boolean isFileDeleted(IResourceDelta delta) {
return delta.getKind() == IResourceDelta.REMOVED;
}

private boolean isFileAdded(IResourceDelta delta) {
return delta.getKind() == IResourceDelta.ADDED;
}

private boolean isFileContentChanged(IResourceDelta delta) {
return (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0);
}

}

private JDTMicroProfileProjectManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,33 @@ public boolean visit(IResourceDelta delta) throws CoreException {
mpProject.getProjectRuntime().clearProjectClassCache();
}
fireAsyncEvent(event);
} else if (isConfigSource(file) && isFileContentChanged(delta)) {
MicroProfilePropertiesChangeEvent event = new MicroProfilePropertiesChangeEvent();
event.setType(MicroProfilePropertiesScope.ONLY_CONFIG_FILES);
event.setProjectURIs(new HashSet<String>());
event.getProjectURIs().add(JDTMicroProfileUtils.getProjectURI(file.getProject()));
fireAsyncEvent(event);
} else if (isConfigSource(file)) {
// Create, delete, update config source file (ex :
// microprofile-config.properties)

JDTMicroProfileProject mpProject = JDTMicroProfileProjectManager.getInstance()
.getJDTMicroProfileProject(file);

boolean generateEvent = false;
if (isFileDeleted(delta) || isFileAdded(delta)) {
generateEvent = true;
// Create, delete config source file (ex : microprofile-config.properties)
if (mpProject != null) {
// Evict the properties cache
mpProject.evictConfigSourcesCache();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The evict cache of config source is done now only when a config file is created/deleted which is required to rebuild the config files scope.

}
} else if (isFileContentChanged(delta)) {
// Update config source file (ex : microprofile-config.properties)
generateEvent = mpProject != null ? mpProject.updateConfigSource(file) : true;
Copy link
Copy Markdown
Contributor Author

@angelozerr angelozerr Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case comes from when:

  • a Java file is saved, target/application.properties is updated.
  • src/main/resources/application.properties is updated.

The mpProject.updateConfigSource(file) returns true only when src/main/resources/application.properties is updated

When application.properties is updated (only for sources), we don't evict the full cache of config sources but just reset the IConfigSource

}

if (generateEvent) {
MicroProfilePropertiesChangeEvent event = new MicroProfilePropertiesChangeEvent();
event.setType(MicroProfilePropertiesScope.ONLY_CONFIG_FILES);
event.setProjectURIs(new HashSet<String>());
event.getProjectURIs().add(JDTMicroProfileUtils.getProjectURI(file.getProject()));
fireAsyncEvent(event);
}
}
}
return false;
Expand Down Expand Up @@ -277,6 +298,14 @@ private boolean isConfigSource(IFile file) {
return JDTMicroProfileProjectManager.getInstance().isConfigSource(file);
}

private boolean isFileDeleted(IResourceDelta delta) {
return delta.getKind() == IResourceDelta.REMOVED;
}

private boolean isFileAdded(IResourceDelta delta) {
return delta.getKind() == IResourceDelta.ADDED;
}

private boolean isFileContentChanged(IResourceDelta delta) {
return (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0);
}
Expand Down
Loading