Skip to content

Commit 83a752e

Browse files
FoD: Don't compare URLs (use URI) for feature matching
Feature on Demand scans the feature list and uses the URL for the feature to identify the correct feature. URL uses the registered Handler to implement #equals and #hashCode. When run with NetBinox both the layers and the FeatureInfo yield URLs using the JarClassLoader. When run with Felix as OSGI runtime the layers report URLHandlersStreamHandlerProxy. Instead of changing the URL logic, use the URI to find a valid FeatureInfo.
1 parent 88d2b1f commit 83a752e

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

ergonomics/ide.ergonomics/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
javac.source=1.8
17+
javac.release=21
1818
javac.compilerargs=-Xlint -Xlint:-serial
1919

2020
javadoc.arch=${basedir}/arch.xml

ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FoDLayersProvider.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.netbeans.modules.ide.ergonomics.fod;
2020

21+
import java.net.URI;
22+
import java.net.URISyntaxException;
2123
import java.net.URL;
2224
import java.util.*;
2325
import java.util.logging.Level;
@@ -26,6 +28,7 @@
2628
import org.netbeans.spi.project.support.ant.AntBasedProjectType;
2729
import org.openide.filesystems.FileObject;
2830
import org.openide.filesystems.Repository;
31+
import org.openide.util.Exceptions;
2932
import org.openide.util.Lookup;
3033
import org.openide.util.LookupEvent;
3134
import org.openide.util.LookupListener;
@@ -82,15 +85,25 @@ protected void registerLayers(Collection<? super URL> context) {
8285
}
8386

8487
public FeatureInfo whichProvides(FileObject template) {
85-
Set<URL> layers = new HashSet<URL>();
88+
Set<URI> layers = new HashSet<>();
8689
Object obj = template.getAttribute("layers");
87-
if (obj instanceof URL[]) {
88-
layers.addAll(Arrays.asList((URL[])obj));
90+
if (obj instanceof URL[] urlArray) {
91+
for(URL url: urlArray) {
92+
try {
93+
layers.add(url.toURI());
94+
} catch (URISyntaxException | NullPointerException ex) {
95+
LOG.log(Level.WARNING, "Failed to convert URL to URI: {0}", url);
96+
}
97+
}
8998
}
9099

91100
for (FeatureInfo info : FeatureManager.features()) {
92-
if (layers.contains(info.getLayerURL())) {
93-
return info;
101+
try {
102+
if (layers.contains(info.getLayerURL().toURI())) {
103+
return info;
104+
}
105+
} catch (URISyntaxException | NullPointerException ex) {
106+
LOG.log(Level.WARNING, "Failed to convert URL to URI: {0}", info.getLayerURL());
94107
}
95108
}
96109
return null;

0 commit comments

Comments
 (0)