Skip to content
Draft
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
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lsp4mp.commons;

public class ConfigSourceInfo {

private String uri;

private String profile;

private int ordinal;

public ConfigSourceInfo() {
}

public ConfigSourceInfo(String uri, int ordinal, String profile) {
super();
this.uri = uri;
this.ordinal = ordinal;
this.profile = profile;
}


public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public String getProfile() {
return profile;
}

public void setProfile(String profile) {
this.profile = profile;
}

public int getOrdinal() {
return ordinal;
}

public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.lsp4mp.commons;

import java.util.Collections;
import java.util.Set;

import org.eclipse.lsp4mp.commons.metadata.ConfigurationMetadata;

Expand All @@ -38,6 +39,8 @@ public class MicroProfileProjectInfo extends ConfigurationMetadata {

private ClasspathKind classpathKind;

private Set<ConfigSourceInfo> configSources;

/**
* Returns the project URI.
*
Expand Down Expand Up @@ -74,4 +77,11 @@ public void setClasspathKind(ClasspathKind classpathKind) {
this.classpathKind = classpathKind;
}

public Set<ConfigSourceInfo> getConfigSources() {
return configSources;
}

public void setConfigSources(Set<ConfigSourceInfo> configSources) {
this.configSources = configSources;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -51,11 +52,14 @@
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4mp.commons.ClasspathKind;
import org.eclipse.lsp4mp.commons.ConfigSourceInfo;
import org.eclipse.lsp4mp.commons.DocumentFormat;
import org.eclipse.lsp4mp.commons.MicroProfileProjectInfo;
import org.eclipse.lsp4mp.commons.MicroProfileProjectInfoParams;
import org.eclipse.lsp4mp.commons.MicroProfilePropertiesScope;
import org.eclipse.lsp4mp.commons.MicroProfilePropertyDefinitionParams;
import org.eclipse.lsp4mp.jdt.core.project.JDTMicroProfileProject;
import org.eclipse.lsp4mp.jdt.core.project.JDTMicroProfileProjectManager;
import org.eclipse.lsp4mp.jdt.core.utils.IJDTUtils;
import org.eclipse.lsp4mp.jdt.core.utils.JDTMicroProfileUtils;
import org.eclipse.lsp4mp.jdt.internal.core.FakeJavaProject;
Expand Down Expand Up @@ -116,6 +120,9 @@ public MicroProfileProjectInfo getMicroProfileProjectInfo(IJavaProject javaProje
List<MicroProfilePropertiesScope> scopes, ClasspathKind classpathKind, IJDTUtils utils,
DocumentFormat documentFormat, IProgressMonitor monitor) throws JavaModelException, CoreException {
MicroProfileProjectInfo info = createInfo(javaProject.getProject(), classpathKind);
Set<ConfigSourceInfo> configSources = getConfigSourceInfos(javaProject);
info.setConfigSources(configSources);

if (classpathKind == ClasspathKind.NONE) {
info.setProperties(Collections.emptyList());
return info;
Expand Down Expand Up @@ -156,6 +163,16 @@ public MicroProfileProjectInfo getMicroProfileProjectInfo(IJavaProject javaProje
return info;
}

private static Set<ConfigSourceInfo> getConfigSourceInfos(IJavaProject javaProject) throws JavaModelException {
JDTMicroProfileProject mpProject = JDTMicroProfileProjectManager.getInstance()
.getJDTMicroProfileProject(javaProject);
return mpProject.getConfigSources() //
.stream() //
.map(configSource -> new ConfigSourceInfo(configSource.getSourceConfigFileURI(),
configSource.getOrdinal(), configSource.getProfile())) //
.collect(Collectors.toSet());
}

/**
* Configure the classpath used for the search of MicroProfile properties. At
* this step we can add new JARs to use for the search (ex : for Quarkus we add
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lsp4mp.commons;

public class ConfigSourceInfo {

private String uri;

private String profile;

private int ordinal;

public ConfigSourceInfo() {
}

public ConfigSourceInfo(String uri, int ordinal, String profile) {
super();
this.uri = uri;
this.ordinal = ordinal;
this.profile = profile;
}


public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public String getProfile() {
return profile;
}

public void setProfile(String profile) {
this.profile = profile;
}

public int getOrdinal() {
return ordinal;
}

public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.lsp4mp.commons;

import java.util.Collections;
import java.util.Set;

import org.eclipse.lsp4mp.commons.metadata.ConfigurationMetadata;

Expand All @@ -38,6 +39,8 @@ public class MicroProfileProjectInfo extends ConfigurationMetadata {

private ClasspathKind classpathKind;

private Set<ConfigSourceInfo> configSources;

/**
* Returns the project URI.
*
Expand Down Expand Up @@ -74,4 +77,11 @@ public void setClasspathKind(ClasspathKind classpathKind) {
this.classpathKind = classpathKind;
}

public Set<ConfigSourceInfo> getConfigSources() {
return configSources;
}

public void setConfigSources(Set<ConfigSourceInfo> configSources) {
this.configSources = configSources;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public ComputedItemMetadata(ItemMetadata metadata, ItemHint itemHint, ValueHint

public ExtendedMicroProfileProjectInfo(MicroProfileProjectInfo delegate) {
super.setProjectURI(delegate.getProjectURI());
super.setConfigSources(delegate.getConfigSources());
// Update hints
super.setHints(
new CopyOnWriteArrayList<>(delegate.getHints() != null ? delegate.getHints() : new ArrayList<>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
import org.eclipse.lsp4mp.ls.commons.client.CommandKind;
import org.eclipse.lsp4mp.ls.commons.client.ExtendedCompletionCapabilities;
import org.eclipse.lsp4mp.ls.java.JavaTextDocuments.JavaTextDocument;
import org.eclipse.lsp4mp.ls.properties.IPropertiesModelProvider;
import org.eclipse.lsp4mp.model.Node;
import org.eclipse.lsp4mp.model.PropertiesModel;
import org.eclipse.lsp4mp.model.Property;
import org.eclipse.lsp4mp.services.properties.IPropertiesModelProvider;
import org.eclipse.lsp4mp.settings.MicroProfileCodeLensSettings;
import org.eclipse.lsp4mp.settings.MicroProfileValidationSettings;
import org.eclipse.lsp4mp.settings.SharedSettings;
Expand Down Expand Up @@ -272,10 +272,7 @@ public CompletableFuture<Either<List<? extends Location>, List<? extends Locatio
String documentURI = location.getTargetUri();
if (documentURI.endsWith(".properties")) {
PropertiesModel model = propertiesModelProvider
.getPropertiesModel(documentURI);
if (model == null) {
model = PropertiesFileUtils.loadProperties(documentURI);
}
.getPropertiesModel(documentURI);
if (model != null) {
for (Node node : model.getChildren()) {
if (node.getNodeType() == Node.NodeType.PROPERTY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MicroProfileProjectInfoCache {

private static final Logger LOGGER = Logger.getLogger(MicroProfileProjectInfoCache.class.getName());

private final Map<String /* application.properties URI */, CompletableFuture<MicroProfileProjectInfo>> cache;
private final Map<String /* microprofile-config.properties, application.properties, etc URI */, CompletableFuture<MicroProfileProjectInfo>> cache;

private final MicroProfileProjectInfoProvider provider;

Expand All @@ -52,11 +52,12 @@ public MicroProfileProjectInfoCache(MicroProfileProjectInfoProvider provider) {

/**
* Returns as promise the MicroProfile project information for the given
* application.properties URI.
* microprofile-config.properties, application.properties, etc URI.
*
* @param params the URI of themicroprofile-config.properties, application.properties, etc.
*
* @param params the URI of the application.properties.
* @return as promise the MicroProfile project information for the given
* application.properties URI.
* microprofile-config.properties, application.properties, etc URI.
*/
public CompletableFuture<MicroProfileProjectInfo> getProjectInfo(MicroProfileProjectInfoParams params) {
return getProjectInfoFromCache(params). //
Expand Down Expand Up @@ -94,8 +95,8 @@ CompletableFuture<MicroProfileProjectInfo> getProjectInfoFromCache(MicroProfileP
LOGGER.log(Level.WARNING, String.format(
"Error while getting MicroProfileProjectInfo (sources) for '%s'", params.getUri()), ex);
return MicroProfileProjectInfo.EMPTY_PROJECT_INFO;
}). //
thenApply(info ->
}) //
.thenApply(info ->
// then update the cache with the new properties
{
wrapper.updateSourcesProperties(info.getProperties(), info.getHints());
Expand Down Expand Up @@ -131,13 +132,13 @@ public Collection<String> propertiesChanged(MicroProfilePropertiesChangeEvent ev
}

private Collection<String> classpathChanged(Set<String> projectURIs) {
List<String> applicationPropertiesURIs = getApplicationPropertiesURIs(projectURIs);
List<String> applicationPropertiesURIs = getPropertiesFileURIs(projectURIs);
applicationPropertiesURIs.forEach(cache::remove);
return applicationPropertiesURIs;
}

private Collection<String> javaSourceChanged(Set<String> projectURIs) {
List<String> applicationPropertiesURIs = getApplicationPropertiesURIs(projectURIs);
List<String> applicationPropertiesURIs = getPropertiesFileURIs(projectURIs);
for (String uri : applicationPropertiesURIs) {
ExtendedMicroProfileProjectInfo info = getProjectInfoWrapper(cache.get(uri));
if (info != null) {
Expand All @@ -148,15 +149,15 @@ private Collection<String> javaSourceChanged(Set<String> projectURIs) {
}

/**
* Returns the application.propeties URIs which belongs to the given project
* URIs.
* Returns the propeties file URIs (microprofile-config.properties,
* application.properties, etc) which belongs to the given project URI.
*
* @param projectURIs project URIs
*
* @return the application.propeties URIs which belongs to the given project
* URIs.
* @return the propeties file URIs (microprofile-config.properties,
* application.properties, etc) which belongs to the given project URI.
*/
private List<String> getApplicationPropertiesURIs(Set<String> projectURIs) {
private List<String> getPropertiesFileURIs(Set<String> projectURIs) {
return cache.entrySet().stream().filter(entry -> {
MicroProfileProjectInfo projectInfo = getProjectInfoWrapper(entry.getValue());
if (projectInfo != null) {
Expand Down
Loading