You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2020/07/20 09:25:30 UTC
[netbeans] branch master updated: CachingArchiveProvider should
return a proper Archive for jar URLs that have paths inside the archive.
This is an automated email from the ASF dual-hosted git repository.
neilcsmith 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 2049b58 CachingArchiveProvider should return a proper Archive for jar URLs that have paths inside the archive.
new ed3df1d Merge pull request #2264 from jlahoda/caching-archive-jar-with-patch
2049b58 is described below
commit 2049b58d2195d98dd336de0a298b9b02d0c25c12
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Sun Jul 19 11:59:19 2020 +0200
CachingArchiveProvider should return a proper Archive for jar URLs that have paths inside the archive.
---
.../source/parsing/CachingArchiveProvider.java | 5 ++-
.../source/parsing/CachingArchiveProviderTest.java | 50 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java
index 56b9c1c..8b91c8f 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchiveProvider.java
@@ -107,7 +107,7 @@ public final class CachingArchiveProvider {
public Archive getArchive(@NonNull final URL root, final boolean cacheFile) {
final URI rootURI = toURI(root);
Archive archive;
-
+
synchronized (this) {
archive = archives.get(rootURI);
}
@@ -254,7 +254,8 @@ public final class CachingArchiveProvider {
return EMPTY;
}
}
- if ("jar".equals(protocol)) { //NOI18N
+ if ("jar".equals(protocol) && //NOI18N
+ root.first().getPath().endsWith("!/")) { //CachingArchive does not handle paths inside the archive - skip and use FileObjectArchive //NOI18N
URL inner = FileUtil.getArchiveFile(root.first());
protocol = inner.getProtocol();
if ("file".equals(protocol)) { //NOI18N
diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/parsing/CachingArchiveProviderTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/parsing/CachingArchiveProviderTest.java
new file mode 100644
index 0000000..9e8b056
--- /dev/null
+++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/parsing/CachingArchiveProviderTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.parsing;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.stream.StreamSupport;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+import org.netbeans.junit.NbTestCase;
+import org.openide.util.Utilities;
+
+public class CachingArchiveProviderTest extends NbTestCase {
+
+ public CachingArchiveProviderTest(String name) {
+ super(name);
+ }
+
+ //verify jar URLs with paths inside the archive work:
+ public void testZipWithPath() throws IOException {
+ clearWorkDir();
+ File wd = getWorkDir();
+ File zip = new File(wd, "test.zip");
+ try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip))) {
+ out.putNextEntry(new ZipEntry("module/test/test.txt"));
+ }
+ Archive archive = CachingArchiveProvider.getDefault().getArchive(new URL("jar:" + Utilities.toURI(zip).toURL().toString() + "!/module"), false);
+ assertNotNull(archive.getFile("test/test.txt"));
+ assertEquals(1, StreamSupport.stream(archive.getFiles("test", null, null, null, false).spliterator(), false).count());
+ }
+
+}
---------------------------------------------------------------------
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