You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2022/12/29 06:52:48 UTC
[netbeans] branch master updated: Locate sources JAR if it is next to binary JAR
This is an automated email from the ASF dual-hosted git repository.
jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 00baf1aa55 Locate sources JAR if it is next to binary JAR
new 9a86d279f8 Merge pull request #5156 from jtulach/jtulach/SourceNextToBinary
00baf1aa55 is described below
commit 00baf1aa552d46e0b44622938546a9d9f7951ec8
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Tue Dec 27 04:53:45 2022 +0100
Locate sources JAR if it is next to binary JAR
---
.../classpath/SourceNextToBinaryQueryImpl.java | 65 ++++++++++++++++++++++
.../classpath/SourceNextToBinaryQueryImplTest.java | 49 ++++++++++++++++
2 files changed, 114 insertions(+)
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/classpath/SourceNextToBinaryQueryImpl.java b/java/java.source.base/src/org/netbeans/modules/java/source/classpath/SourceNextToBinaryQueryImpl.java
new file mode 100644
index 0000000000..8a8874bbb0
--- /dev/null
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/classpath/SourceNextToBinaryQueryImpl.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.source.classpath;
+
+import java.net.URL;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.queries.SourceForBinaryQuery;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.URLMapper;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service = SourceForBinaryQueryImplementation.class, position = 100000)
+public final class SourceNextToBinaryQueryImpl implements SourceForBinaryQueryImplementation {
+ @Override
+ public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
+ URL file = FileUtil.getArchiveFile(binaryRoot);
+ if (file != null) {
+ FileObject fo = URLMapper.findFileObject(file);
+ if (fo != null) {
+ FileObject src = fo.getParent().getFileObject(fo.getName() + "-sources", fo.getExt());
+ if (src != null) {
+ return new SourceForBinaryQueryImplementation2.Result() {
+ @Override
+ public boolean preferSources() {
+ return false;
+ }
+
+ @Override
+ public FileObject[] getRoots() {
+ return new FileObject[]{FileUtil.getArchiveRoot(src)};
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener l) {
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener l) {
+ }
+ };
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/classpath/SourceNextToBinaryQueryImplTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/classpath/SourceNextToBinaryQueryImplTest.java
new file mode 100644
index 0000000000..0393ee8325
--- /dev/null
+++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/classpath/SourceNextToBinaryQueryImplTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.source.classpath;
+
+import java.net.URL;
+import org.netbeans.api.java.queries.SourceForBinaryQuery;
+import org.netbeans.junit.NbTestCase;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.URLMapper;
+
+public final class SourceNextToBinaryQueryImplTest extends NbTestCase {
+ public SourceNextToBinaryQueryImplTest(String n) {
+ super(n);
+ }
+
+ public void testFindSourceNextToBinary() throws Exception {
+ clearWorkDir();
+ FileObject root = FileUtil.toFileObject(getWorkDir());
+ assertNotNull("Root for testing found", root);
+ FileObject dir = root.createFolder("testFolder");
+ FileObject jar = dir.createData("junit-4.12", "jar");
+ FileObject src = dir.createData("junit-4.12-sources", "jar");
+
+ URL jarRoot = FileUtil.getArchiveRoot(URLMapper.findURL(jar, URLMapper.INTERNAL));
+ SourceNextToBinaryQueryImpl instance = new SourceNextToBinaryQueryImpl();
+ SourceForBinaryQuery.Result result = instance.findSourceRoots(jarRoot);
+ assertNotNull("result is found", result);
+ assertEquals("ONe root", 1, result.getRoots().length);
+ FileObject found = FileUtil.getArchiveFile(result.getRoots()[0]);
+ assertEquals("The right source file found", src, found);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists