+ * This map is used to ensure that each zip file is accessed by only one thread at a time, preventing + * concurrent access issues. The keys in the map are {@link URI} objects representing the zip files, and + * the values are {@link ReentrantLock} objects that are used to control access to the corresponding zip file. + * The map itself is wrapped with {@link Collections#synchronizedMap(Map)} to ensure thread safety + * when accessing the map. + *
+ */ + private static final Maptrue
or false
- */
- private boolean isAncestor(String ancestor, String child) {
- //children will start with myName and have no child path
- int ancestorLength = ancestor.length();
- if (ancestorLength == 0) {
- return true;
- }
- return child.startsWith(ancestor) && child.length() > ancestorLength && child.charAt(ancestorLength) == '/';
- }
-
- /**
- * Returns whether parent is the immediate parent of child.
- * @param parent the potential parent
- * @param child the potential child
- * @return true
or false
- */
- private boolean isParent(String parent, String child) {
- //children will start with myName and have no child path
- int chop = parent.length() + 1;
- return child.startsWith(parent) && child.length() > chop && child.substring(chop).indexOf('/') == -1;
- }
-
- @Override
- public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
- try (ZipInputStream in = new ZipInputStream(rootStore.openInputStream(EFS.NONE, monitor))) {
- ZipEntry entry = findEntry(path.toString(), in);
- if (entry == null) {
- throw new CoreException(Status.error("File not found: " + rootStore.toString()));
- }
- if (entry.isDirectory()) {
- throw new CoreException(Status.error("Resource is not a file: " + rootStore.toString()));
- }
- return in;
- } catch (IOException e) {
- throw new CoreException(Status.error("Could not read file: " + rootStore.toString(), e));
- }
- }
-
- @Override
- public URI toURI() {
- try {
- return new URI(ZipFileSystem.SCHEME_ZIP, null, path.makeAbsolute().toString(), rootStore.toURI().toString(), null);
- } catch (URISyntaxException e) {
- //should not happen
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/core/internal/filesystem/zip/ZipFileSystemContributor.java b/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/core/internal/filesystem/zip/ZipFileSystemContributor.java
deleted file mode 100644
index d8516a8b60a..00000000000
--- a/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/core/internal/filesystem/zip/ZipFileSystemContributor.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2022 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.core.internal.filesystem.zip;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.ide.fileSystem.FileSystemContributor;
-
-/**
- * ZipFileSystemContributor is the zip example of a file system contributor.
- */
-public class ZipFileSystemContributor extends FileSystemContributor {
-
- public ZipFileSystemContributor() {
- super();
- }
-
- @Override
- public URI getURI(String pathString) {
- try {
- if (pathString.startsWith(ZipFileSystem.SCHEME_ZIP))
- return new URI(pathString);
- } catch (URISyntaxException e1) {
- return null;
- }
- if (File.separatorChar != '/')
- pathString = pathString.replace(File.separatorChar, '/');
- final int length = pathString.length();
- StringBuffer pathBuf = new StringBuffer(length + 1);
- pathBuf.append("file:"); //$NON-NLS-1$
- // There must be a leading slash in a hierarchical URI
- if (length > 0 && (pathString.charAt(0) != '/'))
- pathBuf.append('/');
- // additional double-slash for UNC paths to distinguish from host
- // separator
- if (pathString.startsWith("//")) //$NON-NLS-1$
- pathBuf.append('/').append('/');
- pathBuf.append(pathString);
- try {
- //scheme, host, path, query, fragment
- return new URI(ZipFileSystem.SCHEME_ZIP, null, "/", pathBuf.toString(), null); //$NON-NLS-1$
- } catch (URISyntaxException e) {
- return null;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.ide.fileSystem.FileSystemContributor#browseFileSystem(java.lang.String, org.eclipse.swt.widgets.Shell)
- */
- @Override
- public URI browseFileSystem(String initialPath, Shell shell) {
-
- FileDialog dialog = new FileDialog(shell);
-
- if (initialPath.length() > 0)
- dialog.setFilterPath(initialPath);
-
- dialog.setFilterExtensions(new String[] {"*.zip"});//$NON-NLS-1$
-
- String selectedFile = dialog.open();
- if (selectedFile == null)
- return null;
- return getURI(selectedFile);
- }
-
-}
diff --git a/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/ui/examples/filesystem/CollapseZipHandler.java b/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/ui/examples/filesystem/CollapseZipHandler.java
deleted file mode 100644
index 9b75ba8bf0d..00000000000
--- a/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/ui/examples/filesystem/CollapseZipHandler.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2022 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Patrick Ziegler - Migration from a JFace Action to a Command Handler,
- * in order to be used with the 'org.eclipse.ui.menus'
- * extension point.
- *******************************************************************************/
-package org.eclipse.ui.examples.filesystem;
-
-import java.net.URI;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.filesystem.URIUtil;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-public class CollapseZipHandler extends AbstractHandler {
-
- private void collapseZip(IFolder folder, Shell shell) {
- try {
- URI zipURI = new URI(folder.getLocationURI().getQuery());
- //check if the zip file is physically stored below the folder in the workspace
- IFileStore parentStore = EFS.getStore(folder.getParent().getLocationURI());
- URI childURI = parentStore.getChild(folder.getName()).toURI();
- if (URIUtil.equals(zipURI, childURI)) {
- //the zip file is in the workspace so just delete the link
- // and refresh the parent to create the resource
- folder.delete(IResource.NONE, null);
- folder.getParent().refreshLocal(IResource.DEPTH_INFINITE, null);
- } else {
- //otherwise the zip file must be a linked resource
- IFile file = folder.getParent().getFile(IPath.fromOSString(folder.getName()));
- file.createLink(zipURI, IResource.REPLACE, null);
- }
- } catch (Exception e) {
- MessageDialog.openError(shell, "Error", "Error opening zip file");
- e.printStackTrace();
- }
- }
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- ISelection selection = HandlerUtil.getCurrentSelection(event);
-
- if (!(selection instanceof IStructuredSelection)) {
- return null;
- }
-
- Object element = ((IStructuredSelection) selection).getFirstElement();
-
- if (!(element instanceof IFolder)) {
- return null;
- }
-
- collapseZip((IFolder) element, shell);
- return null;
- }
-
-}
diff --git a/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/ui/examples/filesystem/ExpandZipHandler.java b/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/ui/examples/filesystem/ExpandZipHandler.java
deleted file mode 100644
index 7fde7131080..00000000000
--- a/resources/examples/org.eclipse.ui.examples.filesystem/src/org/eclipse/ui/examples/filesystem/ExpandZipHandler.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2022 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Patrick Ziegler - Migration from a JFace Action to a Command Handler,
- * in order to be used with the 'org.eclipse.ui.menus'
- * extension point.
- *******************************************************************************/
-package org.eclipse.ui.examples.filesystem;
-
-import java.net.URI;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.internal.filesystem.zip.ZipFileSystem;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-public class ExpandZipHandler extends AbstractHandler {
-
- private void expandZip(IFile file, Shell shell) {
- try {
- URI zipURI = new URI(ZipFileSystem.SCHEME_ZIP, null, "/", file.getLocationURI().toString(), null);
- IFolder link = file.getParent().getFolder(IPath.fromOSString(file.getName()));
- link.createLink(zipURI, IResource.REPLACE, null);
- } catch (Exception e) {
- MessageDialog.openError(shell, "Error", "Error opening zip file");
- e.printStackTrace();
- }
- }
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- Shell shell = HandlerUtil.getActiveShell(event);
- ISelection selection = HandlerUtil.getCurrentSelection(event);
-
- if (!(selection instanceof IStructuredSelection)) {
- return null;
- }
-
- Object element = ((IStructuredSelection) selection).getFirstElement();
-
- if (!(element instanceof IFile)) {
- return null;
- }
-
- expandZip((IFile) element, shell);
- return null;
- }
-
-}
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.jar b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.jar
new file mode 100644
index 00000000000..b35136e36b2
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.jar differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.war b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.war
new file mode 100644
index 00000000000..852d10c1a2e
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.war differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.zip
new file mode 100644
index 00000000000..b33117fa405
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText.zip differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.jar b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.jar
new file mode 100644
index 00000000000..b35136e36b2
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.jar differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.war b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.war
new file mode 100644
index 00000000000..852d10c1a2e
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.war differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.zip
new file mode 100644
index 00000000000..b33117fa405
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/BasicText2.zip differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/DeepNested.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/DeepNested.zip
new file mode 100644
index 00000000000..4a65ed604fe
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/DeepNested.zip differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/Empty.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/Empty.zip
new file mode 100644
index 00000000000..15cb0ecb3e2
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/Empty.zip differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/Fake.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/Fake.zip
new file mode 100644
index 00000000000..945948d8236
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/Fake.zip
@@ -0,0 +1 @@
+THIS IS NOT A ZIP!
\ No newline at end of file
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/NestedZipFileParent.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/NestedZipFileParent.zip
new file mode 100644
index 00000000000..6af194f1ce7
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/NestedZipFileParent.zip differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/PasswordProtected.zip b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/PasswordProtected.zip
new file mode 100644
index 00000000000..6030f241b4a
Binary files /dev/null and b/resources/tests/org.eclipse.core.tests.resources/resources/ZipFileSystem/PasswordProtected.zip differ
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/AllZipFileSystemTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/AllZipFileSystemTests.java
new file mode 100644
index 00000000000..f54297acd23
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/AllZipFileSystemTests.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import org.junit.platform.suite.api.SelectClasses;
+import org.junit.platform.suite.api.Suite;
+
+/**
+ * Class for collecting all test classes that deal with the zip file system API.
+ */
+@Suite
+@SelectClasses({ CloseTest.class, CopyTest.class, CreateTest.class, DeleteTest.class, MoveTest.class,
+ RenameTest.class, SetupTest.class, OpenTest.class })
+public class AllZipFileSystemTests {
+}
+
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CloseTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CloseTest.java
new file mode 100644
index 00000000000..33de38cb5e5
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CloseTest.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.ZipFileTransformer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class CloseTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCloseZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ ZipFileSystemTestSetup.ensureExists(openedZipFile);
+ ZipFileTransformer.closeZipFile(openedZipFile);
+ IFile zipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName);
+ // Don't use Utility method ensureDoesNotExist because the fileStore is still
+ // available after closing. The fileStore is the File itself in the local file
+ // system that still exists after closing.
+ assertTrue("folder was not properly deleted: " + openedZipFile, !openedZipFile.exists());
+ ZipFileSystemTestSetup.ensureExists(zipFile);
+ }
+
+ /*
+ * Test for a bug that breaks the opened zip file underneath the zip file that
+ * is closing. The zip file underneath converts to a linked file but the local
+ * file in the project is deleted so the linked file has no target.
+ */
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCloseZipFileWithZipFileUnderneath(String zipFileName) throws Exception {
+ IFolder firstZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ String secondZipFileName = zipFileName.replace(".", "2.");
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0), secondZipFileName);
+ ZipFileTransformer.openZipFile(ZipFileSystemTestSetup.projects.get(0).getFile(secondZipFileName), true);
+ IFolder secondZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(secondZipFileName);
+
+ ZipFileTransformer.closeZipFile(firstZipFile);
+ IFile closedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName);
+ // Don't use Utility method ensureDoesNotExist because the fileStore is still
+ // available after closing. The fileStore is the File itself in the local file
+ // system that still exists after closing.
+ assertTrue("folder was not properly deleted: " + firstZipFile, !firstZipFile.exists());
+ ZipFileSystemTestSetup.ensureExists(closedZipFile);
+ ZipFileSystemTestSetup.ensureExists(secondZipFile);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CopyTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CopyTest.java
new file mode 100644
index 00000000000..aa184b3c409
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CopyTest.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import java.io.ByteArrayInputStream;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ *
+ */
+public class CopyTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ ZipFileSystemTestSetup.ensureExists(openedZipFile);
+ IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("Folder");
+ destinationFolder.create(true, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFolder);
+ IFolder copyDestination = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder("Folder" + "/" + zipFileName);
+ openedZipFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(openedZipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFileInsideOfZipFile(String zipFileName) throws Exception {
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile(
+ zipFileName + "/" + ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("Folder");
+ destinationFolder.create(true, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFolder);
+ IFile copyDestination = ZipFileSystemTestSetup.projects.get(0)
+ .getFile("Folder" + "/" + ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFolderInsideOfZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ ZipFileSystemTestSetup.ensureExists(openedZipFile);
+ IFolder newFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFile textFile = newFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder copyDestination = openedZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
+ newFolder.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFileIntoZipFile(String zipFileName) throws Exception {
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile copyDestination = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName + "/" + "NewFile.txt");
+ textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFolderIntoZipFile(String zipFileName) throws Exception {
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile copyDestination = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName + "/" + "NewFile.txt");
+ textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFileFromOutsideOfZipFIleIntoFolderInZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder newFolder = openedZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile copyDestination = newFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
+ textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFolderIntoFolderInZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder firstNewFolder = openedZipFile.getFolder("FirstNewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(firstNewFolder);
+ firstNewFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(firstNewFolder);
+ IFolder secondNewFolder = openedZipFile.getFolder("SecondNewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(secondNewFolder);
+ secondNewFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(secondNewFolder);
+ IFile textFile = firstNewFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder copyDestination = secondNewFolder.getFolder("FirstNewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
+ firstNewFolder.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(firstNewFolder);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCopyFileFromOneFolderToOtherFolderInsideofZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder firstNewFolder = openedZipFile.getFolder("FirstNewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(firstNewFolder);
+ firstNewFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(firstNewFolder);
+ IFolder secondNewFolder = openedZipFile.getFolder("SecondNewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(secondNewFolder);
+ secondNewFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(secondNewFolder);
+ IFile textFile = firstNewFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile copyDestination = secondNewFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
+ textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(copyDestination);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CreateTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CreateTest.java
new file mode 100644
index 00000000000..13e2daeb3e7
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/CreateTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import java.io.ByteArrayInputStream;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class CreateTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCreateFileInsideOfZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFile textFile = openedZipFile.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testCreateFolderInsideOfZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder newFolder = openedZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/DeleteTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/DeleteTest.java
new file mode 100644
index 00000000000..714cd07b41a
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/DeleteTest.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class DeleteTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testDeleteZipFile(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ ZipFileSystemTestSetup.ensureExists(openedZipFile);
+ openedZipFile.delete(false, false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(openedZipFile);
+ IFile zipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName);
+ ZipFileSystemTestSetup.ensureDoesNotExist(zipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testDeleteFileInsideOfZipFile(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFile textFile = openedZipFile.getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ textFile.delete(true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testDeleteEmptyFolder(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder folder = openedZipFile.getFolder("FolderToDelete");
+ ZipFileSystemTestSetup.ensureDoesNotExist(folder);
+ folder.create(true, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(folder);
+ folder.delete(true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(folder);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testDeleteFolderWithChildren(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder folder = openedZipFile.getFolder("FolderToDelete");
+ ZipFileSystemTestSetup.ensureDoesNotExist(folder);
+ folder.create(true, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(folder);
+ IFile textFile = folder.getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ textFile.create(new ByteArrayInputStream("Hello World!".getBytes()), true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ folder.delete(true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(folder);
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/MoveTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/MoveTest.java
new file mode 100644
index 00000000000..d5236c515e9
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/MoveTest.java
@@ -0,0 +1,332 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.ZipFileTransformer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+
+public class MoveTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveZipFileWithinProject(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("destinationFolder");
+ destinationFolder.create(false, true, new NullProgressMonitor());
+ IFolder destination = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder("destinationFolder/" + zipFileName);
+ openedZipFile.move(destination.getFullPath(), false, new NullProgressMonitor());
+ IFolder newFolder = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(destinationFolder.getName() + "/" + zipFileName);
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ ZipFileSystemTestSetup.ensureDoesNotExist(openedZipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveZipFileToOtherProject(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder destination = ZipFileSystemTestSetup.projects.get(1)
+ .getFolder(zipFileName);
+ destination.delete(true, new NullProgressMonitor());
+ openedZipFile.move(destination.getFullPath(), false, new NullProgressMonitor());
+ IFolder newFolder = ZipFileSystemTestSetup.projects.get(1)
+ .getFolder(zipFileName);
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ ZipFileSystemTestSetup.ensureDoesNotExist(openedZipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveZipFileToOtherProjectFolder(String zipFileName) throws CoreException, IOException {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(1).getFolder("destinationFolder");
+ destinationFolder.create(false, true, new NullProgressMonitor());
+ IFolder destination = ZipFileSystemTestSetup.projects.get(1)
+ .getFolder("destinationFolder/" + zipFileName);
+ openedZipFile.move(destination.getFullPath(), false, new NullProgressMonitor());
+ IFolder newFolder = ZipFileSystemTestSetup.projects.get(1)
+ .getFolder(destinationFolder.getName() + "/" + zipFileName);
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ ZipFileSystemTestSetup.ensureDoesNotExist(openedZipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFileIntoZipFile(String zipFileName) throws Exception {
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ String text = "Foo";
+ InputStream stream = new ByteArrayInputStream(text.getBytes());
+ textFile.create(stream, false, new NullProgressMonitor());
+ stream.close();
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile destinationFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName + "/" + "NewFile.txt");
+ textFile.move(destinationFile.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFile);
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFolderIntoZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder destinationFolder = openedZipFile.getFolder("destinationFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(destinationFolder);
+ destinationFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFolder);
+ IFolder newFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFolder newFolderDestination = destinationFolder.getFolder("NewFolder");
+ newFolder.move(newFolderDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ ZipFileSystemTestSetup.ensureExists(newFolderDestination);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFolderWithContentIntoZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder destinationFolder = openedZipFile.getFolder("destinationFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(destinationFolder);
+ destinationFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFolder);
+ IFolder newFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFile textFile = newFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ String text = "Foo";
+ InputStream stream = new ByteArrayInputStream(text.getBytes());
+ textFile.create(stream, false, new NullProgressMonitor());
+ stream.close();
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder newFolderDestination = destinationFolder.getFolder("NewFolder");
+ newFolder.move(newFolderDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ ZipFileSystemTestSetup.ensureExists(newFolderDestination);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFileFromZipFile(String zipFileName) throws Exception {
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(zipFileName + "/"
+ + ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile destinationFile = ZipFileSystemTestSetup.projects.get(0).getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ textFile.move(destinationFile.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFile);
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFolderFromZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder newFolder = openedZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFolder folderDestination = ZipFileSystemTestSetup.projects.get(0).getFolder("NewFolder");
+ newFolder.move(folderDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ ZipFileSystemTestSetup.ensureExists(folderDestination);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFolderWithContentFromZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder newFolder = openedZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFile textFile = newFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ String text = "Foo";
+ InputStream stream = new ByteArrayInputStream(text.getBytes());
+ textFile.create(stream, false, new NullProgressMonitor());
+ stream.close();
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder folderDestination = ZipFileSystemTestSetup.projects.get(0).getFolder("NewFolder");
+ newFolder.move(folderDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ ZipFileSystemTestSetup.ensureExists(folderDestination);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFolderWithContentFromZipFileIntoOtherZipFile(String zipFileName) throws Exception {
+ IFolder firstZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(zipFileName);
+ String secondZipFileName = zipFileName.replace(".", "2.");
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0), secondZipFileName);
+ ZipFileTransformer.openZipFile(ZipFileSystemTestSetup.projects.get(0).getFile(secondZipFileName), true);
+ IFolder secondZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(secondZipFileName);
+
+ IFolder newFolder = firstZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFile textFile = newFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ String text = "Foo";
+ InputStream stream = new ByteArrayInputStream(text.getBytes());
+ textFile.create(stream, false, new NullProgressMonitor());
+ stream.close();
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder movedFolderDestination = secondZipFile.getFolder("NewFolder");
+ newFolder.move(movedFolderDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ ZipFileSystemTestSetup.ensureExists(movedFolderDestination);
+ IFile movedTextFile = movedFolderDestination.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureExists(movedTextFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFolderWithContentFromZipFileIntoOtherZipFileTwice(String zipFileName) throws Exception {
+ IFolder firstZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(zipFileName);
+ String secondZipFileName = zipFileName.replace(".", "2.");
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0), secondZipFileName);
+ ZipFileTransformer.openZipFile(ZipFileSystemTestSetup.projects.get(0).getFile(secondZipFileName), true);
+ IFolder secondZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(secondZipFileName);
+
+ IFolder newFolder = firstZipFile.getFolder("NewFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ newFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(newFolder);
+ IFile textFile = newFolder.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ String text = "Foo";
+ InputStream stream = new ByteArrayInputStream(text.getBytes());
+ textFile.create(stream, false, new NullProgressMonitor());
+ stream.close();
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder movedFolderDestination = secondZipFile.getFolder("NewFolder");
+ newFolder.move(movedFolderDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
+ ZipFileSystemTestSetup.ensureExists(movedFolderDestination);
+ IFile movedTextFile = movedFolderDestination.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureExists(movedTextFile);
+
+ // Move second time
+ IFolder originDestination = newFolder;
+ movedFolderDestination.move(originDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureDoesNotExist(movedFolderDestination);
+ ZipFileSystemTestSetup.ensureExists(originDestination);
+ movedTextFile = originDestination.getFile("NewFile.txt");
+ ZipFileSystemTestSetup.ensureExists(movedTextFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveFileInsideOfZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder destinationFolder = openedZipFile.getFolder("destinationFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(destinationFolder);
+ destinationFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFolder);
+ IFile textFile = openedZipFile.getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFile fileDestination = destinationFolder.getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ ZipFileSystemTestSetup.ensureDoesNotExist(fileDestination);
+ textFile.move(fileDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(fileDestination);
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveZipFileIntoZipFile(String zipFileName) throws Exception {
+ IFolder firstZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ String secondZipFileName = zipFileName.replace(".", "2.");
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0), secondZipFileName);
+ ZipFileTransformer.openZipFile(ZipFileSystemTestSetup.projects.get(0).getFile(secondZipFileName), true);
+ IFolder secondZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(secondZipFileName);
+
+ // move second ZipFile into first ZipFile
+ IFile secondZipFileDestination = firstZipFile.getFile(secondZipFileName);
+ secondZipFile.move(secondZipFileDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(secondZipFileDestination);
+ ZipFileSystemTestSetup.ensureDoesNotExist(secondZipFile);
+ }
+
+ /**
+ * When moving or expanding an opened zip file that contains a folder with
+ * content. errors can occur. This is because the local name of the resources
+ * inside the folder contains "\" seperators that are not allowed when
+ * refreshing the Workspace. This test checks if this specific error is handeled
+ * correctly in RefreshLocalVisitor#visit()
+ */
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testMoveZipFileWithFolder(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ String contentFolderPath = zipFileName + "/" + "Folder";
+ IFolder contentFolder = ZipFileSystemTestSetup.projects.get(0).getFolder(contentFolderPath);
+ ZipFileSystemTestSetup.ensureDoesNotExist(contentFolder);
+ contentFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(contentFolder);
+ String text = "Foo";
+ InputStream stream = new ByteArrayInputStream(text.getBytes());
+ IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile(contentFolderPath + "/" + "textFile");
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ textFile.create(stream, false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("destinationFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(destinationFolder);
+ destinationFolder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(destinationFolder);
+ IFolder zipFileDestination = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder("destinationFolder/" + zipFileName);
+ ZipFileSystemTestSetup.ensureDoesNotExist(zipFileDestination);
+ openedZipFile.move(zipFileDestination.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(zipFileDestination);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/OpenTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/OpenTest.java
new file mode 100644
index 00000000000..e5cc8f08bf3
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/OpenTest.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ZipFileTransformer;
+import org.eclipse.core.runtime.CoreException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class OpenTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @Test
+ public void testOpenEmptyZipFile() throws IOException, CoreException, URISyntaxException {
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0),
+ ZipFileSystemTestSetup.EMPTY_ZIP_FILE_NAME);
+ IProject project = ZipFileSystemTestSetup.projects.get(0);
+ IFile zipFile = project.getFile(ZipFileSystemTestSetup.EMPTY_ZIP_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(zipFile);
+
+ try {
+ ZipFileTransformer.openZipFile(zipFile, true);
+ } catch (CoreException e) {
+ ZipFileSystemTestSetup.ensureExists(zipFile);
+ String expectedMessage = "The file is either empty or doesn't represent a ZIP file:";
+ assertTrue(e.getMessage().contains(expectedMessage));
+ }
+ }
+
+ @Test
+ public void testOpenNestedZipFileParent() throws IOException, CoreException, URISyntaxException {
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0),
+ ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ IFile nestedZipFileParent = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ ZipFileSystemTestSetup.ensureExists(nestedZipFileParent);
+ ZipFileTransformer.openZipFile(nestedZipFileParent, true);
+ IFolder openedNestedZipFileParent = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ ZipFileSystemTestSetup.ensureExists(openedNestedZipFileParent);
+ }
+
+ @Test
+ public void testOpenNestedZipFileChild() throws IOException, CoreException, URISyntaxException {
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0),
+ ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ IFile nestedZipFileParent = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ ZipFileSystemTestSetup.ensureExists(nestedZipFileParent);
+ ZipFileTransformer.openZipFile(nestedZipFileParent, true);
+ IFolder openedNestedZipFileParent = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ ZipFileSystemTestSetup.ensureExists(openedNestedZipFileParent);
+ IFile nestedZipFileChild = openedNestedZipFileParent.getFile(ZipFileSystemTestSetup.NESTED_ZIP_FILE_CHILD_NAME);
+ ZipFileSystemTestSetup.ensureExists(nestedZipFileChild);
+
+ // Attempt to open the nested ZIP file and expect an exception
+ try {
+ ZipFileTransformer.openZipFile(nestedZipFileChild, true);
+ fail("Expected a CoreException to be thrown when opening a nested ZIP file");
+ } catch (CoreException e) {
+ // Verify that the expected exception was thrown
+ assertTrue("Expected CoreException to be thrown when opening a nested ZIP file",
+ e.getMessage().contains("Nested ZIP files are not allowed to be opened"));
+
+ IFolder openedNestedZipFileChild = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(ZipFileSystemTestSetup.NESTED_ZIP_FILE_CHILD_NAME);
+ ZipFileSystemTestSetup.ensureDoesNotExist(openedNestedZipFileChild);
+ }
+ }
+
+ @Test
+ public void testOpenDeepNestedTextFile() throws IOException, CoreException, URISyntaxException {
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0),
+ ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ IFile nestedZipFileParent = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ ZipFileSystemTestSetup.ensureExists(nestedZipFileParent);
+ ZipFileTransformer.openZipFile(nestedZipFileParent, true);
+ IFolder openedNestedZipFileParent = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(ZipFileSystemTestSetup.NESTED_ZIP_FILE_PARENT_NAME);
+ ZipFileSystemTestSetup.ensureExists(openedNestedZipFileParent);
+
+ String nestedPath = "sub1/Text.txt";
+ IFile nestedFile = openedNestedZipFileParent.getFile(nestedPath);
+ ZipFileSystemTestSetup.ensureExists(nestedFile);
+
+ String nestedPathShouldFail = "sub2";
+ IFolder nestedFileShouldFail = openedNestedZipFileParent.getFolder(nestedPathShouldFail);
+ ZipFileSystemTestSetup.ensureDoesNotExist(nestedFileShouldFail);
+
+ String deepNestedPath = "sub1/sub2/sub3/sub4/sub5/sub6/sub8/sub9/sub10/Text.txt";
+ IFile deepNestedFile = openedNestedZipFileParent.getFile(deepNestedPath);
+ ZipFileSystemTestSetup.ensureExists(deepNestedFile);
+ }
+
+ @Test
+ public void testOpenFakeZip() {
+ try {
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0),
+ ZipFileSystemTestSetup.FAKE_ZIP_FILE_NAME);
+ IFile fakeZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(ZipFileSystemTestSetup.FAKE_ZIP_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(fakeZipFile);
+
+ ZipFileTransformer.openZipFile(fakeZipFile, true);
+ fail("Expected an IOException due to incorrect file header.");
+ } catch (CoreException e) {
+ String expectedMessage = "The file is either empty or doesn't represent a ZIP file";
+ assertTrue(e.getMessage().contains(expectedMessage));
+ } catch (Exception e) {
+ fail("Expected a CoreException, but got a different type of exception.");
+ }
+ }
+
+ @Test
+ public void testOpenPasswordProtectedZip() {
+ try {
+ ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0),
+ ZipFileSystemTestSetup.PASSWORD_PROTECTED_ZIP_FILE_NAME);
+ IFile passwordProtectedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFile(ZipFileSystemTestSetup.PASSWORD_PROTECTED_ZIP_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(passwordProtectedZipFile);
+
+ ZipFileTransformer.openZipFile(passwordProtectedZipFile, true);
+ fail("Expected an IOException due to password protection.");
+ } catch (CoreException e) {
+ String expectedMessage = "Opening encrypted ZIP files is not supported:";
+ assertTrue("Expected message: " + expectedMessage, e.getMessage().contains(expectedMessage));
+ } catch (Exception e) {
+ fail("Expected a CoreException, but got a different type of exception.");
+ }
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/RenameTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/RenameTest.java
new file mode 100644
index 00000000000..5a8852e3fe6
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/RenameTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class RenameTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testRenameZipFile(String zipFileName) throws Exception {
+ // IFolder is renamed by moving with the new path
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder renamedOpenZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName + "Renamed");
+ openedZipFile.move(renamedOpenZipFile.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(renamedOpenZipFile);
+ ZipFileSystemTestSetup.ensureDoesNotExist(openedZipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testRenameFileInsideOfZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFile textFile = openedZipFile.getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ IFile renamedTextFile = openedZipFile.getFile(textFile.getName() + "Renamed");
+ textFile.move(renamedTextFile.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(renamedTextFile);
+ ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testRenameFolderInsideOfZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ IFolder folder = openedZipFile.getFolder("newFolder");
+ ZipFileSystemTestSetup.ensureDoesNotExist(folder);
+ folder.create(false, true, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(folder);
+ IFolder renamedFolder = openedZipFile.getFolder(folder.getName() + "Renamed");
+ folder.move(renamedFolder.getFullPath(), false, new NullProgressMonitor());
+ ZipFileSystemTestSetup.ensureExists(renamedFolder);
+ ZipFileSystemTestSetup.ensureDoesNotExist(folder);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/SetupTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/SetupTest.java
new file mode 100644
index 00000000000..30a13b86625
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/SetupTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class SetupTest {
+
+ @BeforeEach
+ public void setup() throws Exception {
+ ZipFileSystemTestSetup.setup();
+ }
+
+ @AfterEach
+ public void teardown() throws Exception {
+ ZipFileSystemTestSetup.teardown();
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testZipFileInProject(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+ ZipFileSystemTestSetup.ensureExists(openedZipFile);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
+ public void testTextFileInZipFile(String zipFileName) throws Exception {
+ IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
+ .getFolder(zipFileName);
+
+ IFile textFile = openedZipFile.getFile(ZipFileSystemTestSetup.TEXT_FILE_NAME);
+ ZipFileSystemTestSetup.ensureExists(textFile);
+ }
+}
diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/ZipFileSystemTestSetup.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/ZipFileSystemTestSetup.java
new file mode 100644
index 00000000000..15c20fde553
--- /dev/null
+++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/zip/ZipFileSystemTestSetup.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License 2.0 which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors: Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.tests.filesystem.zip;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.ZipFileTransformer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+
+class ZipFileSystemTestSetup {
+ static final String ZIP_FILE_NAME = "BasicText.zip";
+ static final String JAR_FILE_NAME = "BasicText.jar";
+ static final String WAR_FILE_NAME = "BasicText.war";
+
+ static final String EMPTY_ZIP_FILE_NAME = "Empty.zip";
+ static final String FAKE_ZIP_FILE_NAME = "Fake.zip";
+ static final String PASSWORD_PROTECTED_ZIP_FILE_NAME = "PasswordProtected.zip";
+ static final String NESTED_ZIP_FILE_PARENT_NAME = "NestedZipFileParent.zip";
+ static final String NESTED_ZIP_FILE_CHILD_NAME = "NestedZipFileChild.zip";
+ static final String DEEP_NESTED_ZIP_FILE_NAME = "DeepNested.zip";
+
+ static final String TEXT_FILE_NAME = "Text.txt";
+
+ static List