Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Oberlies2014-04-04 05:51:16 -0400
committerJan Sievers2014-04-07 09:50:24 -0400
commit7a0ae4bfecec7f05d00bfc5eaccb2a745191065d (patch)
tree031d9e1f71e214c241a7d4383be2221a7384bdf4
parentd3b5c0ba29623cff08e03b65e43e2e2baacd185c (diff)
downloadorg.eclipse.tycho.nexus-7a0ae4bfecec7f05d00bfc5eaccb2a745191065d.tar.gz
org.eclipse.tycho.nexus-7a0ae4bfecec7f05d00bfc5eaccb2a745191065d.tar.xz
org.eclipse.tycho.nexus-7a0ae4bfecec7f05d00bfc5eaccb2a745191065d.zip
431866 Keep original request objects for directory listing
- Try to keep the original ResourceStorageRequest objects so that the property that Nexus reads while listing directory content are present. Bug: 431866 Bug: 423014 Change-Id: I0ef35c80937de6e3e696af8a8ab12462f884368d
-rw-r--r--unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java35
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java32
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCache.java26
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItem.java16
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItem.java112
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java5
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java22
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java1
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java9
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java17
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java4
11 files changed, 194 insertions, 85 deletions
diff --git a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
index fcfbb66..c40cf2e 100644
--- a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
+++ b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
@@ -11,7 +11,9 @@
package org.eclipse.tycho.nexus.internal.plugin;
import static java.util.Arrays.asList;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.sonatype.nexus.client.core.subsystem.content.Location.repositoryLocation;
@@ -109,19 +111,46 @@ public class UnzipRepositoryPluginITCase extends AbstractUnzipRepositoryPluginIT
}
@Test
- public void testUnzipRepoWithHostedRepoAsMaster() throws Exception {
+ public void testListOnGroupIdFolderInUnzipRepository() throws Exception {
+ assertThat(getContentFromRepo("releases.unzip", "/org/example"), containsString(">artifact/</a>"));
+ }
+
+ @Test
+ public void testListOnFolderContainingArchiveInUnzipRepository() throws Exception {
+ assertThat(getContentFromRepo("snapshots.unzip", "/org/example/artifact/2.0.0-SNAPSHOT/"),
+ containsString(">artifact-2.0.0-SNAPSHOT.jar-unzip/</a>"));
+ }
+
+ @Test
+ public void testListArchiveContentInUnzipRepository() throws Exception {
+ assertThat(
+ getContentFromRepo("snapshots.unzip",
+ "/org/example/artifact/2.0.0-SNAPSHOT/artifact-2.0.0-SNAPSHOT.jar-unzip/org/dubdidel/dei"),
+ containsString(">Dei.class</a>"));
+ }
+
+ @Test
+ public void testListArchiveContentWithNestedFoldersInUnzipRepository() throws Exception {
+ assertThat(
+ getContentFromRepo("snapshots.unzip",
+ "/org/example/artifact/2.0.0-SNAPSHOT/artifact-2.0.0-SNAPSHOT.jar-unzip/org/dubdidel/"),
+ containsString(">dei/</a>"));
+ }
+
+ @Test
+ public void testGetArtifactFromUnzipRepoWithHostedRepoAsMaster() throws Exception {
assertEquals(getTestData(EXAMPLE_RELEASED_JAR, "artifacts/releases/"),
getFileFromZipInRepo("releases.unzip", EXAMPLE_RELEASED_JAR));
}
@Test
- public void testUnzipRepoWithGroupRepoAsMaster() throws Exception {
+ public void testGetArtifactFromUnzipRepoWithGroupRepoAsMaster() throws Exception {
assertEquals(getTestData(EXAMPLE_RELEASED_JAR, "artifacts/releases/"),
getFileFromZipInRepo("releases.group.unzip", EXAMPLE_RELEASED_JAR));
}
@Test
- public void testUnzipRepoWithVirtualSnapshotVersion() throws Exception {
+ public void testGetArtifactFromUnzipRepoWithVirtualSnapshotVersion() throws Exception {
// use virtual version "SNAPSHOT" which should translate to latest available snapshot
assertEquals(
getTestData(EXAMPLE_SNAPSHOT_JAR, "artifacts/snapshots/"),
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java
index 22af8e4..2ad2eb9 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java
@@ -190,7 +190,8 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
if (!isMasterAvailable) {
String repositoryId = getExternalConfiguration(false).getMasterRepositoryId();
try {
- getLogger().debug("setting master repository '" + repositoryId + "' for unzip repository '" + getId() + "'");
+ getLogger().debug(
+ "setting master repository '" + repositoryId + "' for unzip repository '" + getId() + "'");
setMasterRepositoryId(repositoryId);
} catch (NoSuchRepositoryException e) {
getLogger().error("[" + repositoryId + "] " + "cannot set master repository " + e.getMessage());
@@ -220,18 +221,26 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
* access folders (some folders are only accessible if the request URL end with a double slash).
* In addition this method also finds file items if the request URL ends with a slash.
*
- * @param request
+ * @param originalRequest
* the request that defines which item be retrieved
+ * @param conversionResult
* @return the item from the master repository
* @throws ItemNotFoundException
* is thrown if there is no item under the specified request path in the master
* repository
* @throws LocalStorageException
*/
- StorageItem retrieveItemFromMaster(final String requestPath) throws ItemNotFoundException, LocalStorageException {
+ StorageItem retrieveItemFromMaster(final ResourceStoreRequest originalRequest, ConversionResult conversionResult)
+ throws ItemNotFoundException, LocalStorageException {
try {
- final ResourceStoreRequest request = new ResourceStoreRequest(requestPath);
- return doRetrieveItemFromMaster(request);
+ // use original request with modified path (e.g. like in AbstractMavenRepository.doRetrieveArtifactItem)
+ originalRequest.pushRequestPath(conversionResult.getConvertedPath());
+ try {
+ return doRetrieveItemFromMaster(originalRequest);
+ } finally {
+ originalRequest.popRequestPath();
+ }
+
} catch (final IllegalOperationException e) {
throw new LocalStorageException(e);
} catch (@SuppressWarnings("deprecation") final org.sonatype.nexus.proxy.StorageException e) {
@@ -259,7 +268,7 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
// a) path does not point to zip content (-> null)
// b) a path to a file/folder inside a zip file (-> ZippedItem is created and returned)
// c) a non-existing path under an existing zip file (-> retrieving ZippedItem fails with ItemNotFoundException)
- final ZippedItem zippedItem = getZippedItem(conversionResult);
+ final ZippedItem zippedItem = getZippedItem(conversionResult, request);
if (zippedItem != null) {
final StorageItem zippedStorageItem = zippedItem.getZippedStorageItem();
getLogger().debug(timeTrace.getMessage());
@@ -268,7 +277,7 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
// check if item exists in master repository
// this call will fail with ItemNotFoundException if the item does not exist in the master repository
- final StorageItem masterItem = retrieveItemFromMaster(conversionResult.getConvertedPath());
+ final StorageItem masterItem = retrieveItemFromMaster(request, conversionResult);
if (masterItem instanceof StorageCollectionItem) {
// item is non-zip folder
@@ -291,14 +300,15 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
*
* @param conversionResult
* the result of the snapshot path conversion, containing the converted path
+ * @param request
* @return item that represents a file or folder within a zip file, <code>null</code> if the
* requested path does not point to zip content
* @throws LocalStorageException
* @throws ItemNotFoundException
* is thrown if for non-existing or invalid request path
*/
- private ZippedItem getZippedItem(final ConversionResult conversionResult) throws LocalStorageException,
- ItemNotFoundException {
+ private ZippedItem getZippedItem(final ConversionResult conversionResult, ResourceStoreRequest request)
+ throws LocalStorageException, ItemNotFoundException {
final StringBuilder pathInZip = new StringBuilder();
final String[] pathSegments = conversionResult.getConvertedPath().split("/");
String zipFilePath = "";
@@ -332,8 +342,8 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
// creating a new ZippedItem fails with ItemNotFoundException if a non-existing file or folder
// inside the (existing) zip file is accessed
getLogger().debug(conversionResult.getConvertedPath() + " points into a zip file.");
- final ZippedItem zippedItem = new ZippedItem(this, zipItemPath, pathInZip.toString(), zipLastModified,
- getLogger());
+ final ZippedItem zippedItem = ZippedItem.newZippedItem(this, request, zipItemPath, pathInZip.toString(),
+ zipLastModified, getLogger());
return zippedItem;
}
return null;
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCache.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCache.java
index 87443ff..15e518e 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCache.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCache.java
@@ -44,9 +44,8 @@ public class UnzipCache {
* Returns the requested artifact from the local storage if the artifact was already cached. If
* not it retrieves it from the corresponding repository and stores it in the local storage.
*
- * @param requestPath
- * the path to the requested artifact in the repository
- *
+ * @param zipItemPath
+ * the path to the zip file
* @return the file in the local storage
*
* @throws ItemNotFoundException
@@ -55,21 +54,19 @@ public class UnzipCache {
* @throws LocalStorageException
*
*/
- public File getArchive(final String requestPath) throws ItemNotFoundException, LocalStorageException {
- final PathLockMonitor folderLock = PathLock.getLock(getRequestPathParent(requestPath));
+ public File getArchive(final String zipItemPath) throws ItemNotFoundException, LocalStorageException {
+ final PathLockMonitor folderLock = PathLock.getLock(getRequestPathParent(zipItemPath));
try {
synchronized (folderLock) {
- final ResourceStoreRequest request = new ResourceStoreRequest(requestPath);
+ final ResourceStoreRequest request = new ResourceStoreRequest(zipItemPath);
if (!localStorage.containsItem(repository, request)) {
-
- logger.debug("Caching zip file from master repository: " + requestPath);
- final StorageItem storageItem = retrieveItemFromMaster(requestPath);
+ logger.debug("Caching zip file from master repository: " + zipItemPath);
+ final StorageItem storageItem = retrieveItemFromMaster(request);
localStorage.storeItem(repository, storageItem);
}
final File file = ((DefaultFSLocalRepositoryStorage) localStorage).getFileFromBase(repository, request);
- logger.debug("Accessed cached zip file: " + requestPath);
+ logger.debug("Accessed cached zip file: " + zipItemPath);
return file;
-
}
} catch (final UnsupportedStorageOperationException e) {
throw new LocalStorageException(e);
@@ -138,11 +135,10 @@ public class UnzipCache {
return ItemPathUtils.getParentPath(path) + ItemPathUtils.PATH_SEPARATOR;
}
- private StorageItem retrieveItemFromMaster(final String requestPath) throws ItemNotFoundException,
- LocalStorageException {
+ private StorageItem retrieveItemFromMaster(final ResourceStoreRequest masterRepositoryRequest)
+ throws ItemNotFoundException, LocalStorageException {
try {
- final ResourceStoreRequest request = new ResourceStoreRequest(requestPath);
- return repository.getMasterRepository().retrieveItem(request);
+ return repository.getMasterRepository().retrieveItem(masterRepositoryRequest);
} catch (final IllegalOperationException e) {
throw new LocalStorageException(e);
} catch (final AccessDeniedException e) {
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItem.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItem.java
index 898f894..ad3cb7a 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItem.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItem.java
@@ -75,16 +75,22 @@ public class ZipAwareStorageCollectionItem extends DefaultStorageCollectionItem
} else if (Util.checkIfZip(member)) {
if (snapshotConversionResult.isPathConverted()) {
if (member.getPath().contains(snapshotConversionResult.getLatestVersion())) {
- membersToDisplay.add(new ZippedStorageCollectionItem(new ZippedItem(repository, member
- .getPath().replace(snapshotConversionResult.getLatestVersion(), "SNAPSHOT"), "", member
- .getModified(), logger)));
+ String virtualSnapshotArtifactPath = member.getPath().replace(
+ snapshotConversionResult.getLatestVersion(), "SNAPSHOT");
+ membersToDisplay.add(createStorageItemForRootOfZipFile(member, virtualSnapshotArtifactPath));
}
} else {
- membersToDisplay.add(new ZippedStorageCollectionItem(new ZippedItem(repository, member.getPath(),
- "", member.getModified(), logger)));
+ membersToDisplay.add(createStorageItemForRootOfZipFile(member, member.getPath()));
}
}
}
+
return membersToDisplay;
}
+
+ private ZippedStorageCollectionItem createStorageItemForRootOfZipFile(final StorageItem member, String path)
+ throws ItemNotFoundException, LocalStorageException {
+ return new ZippedStorageCollectionItem(ZippedItem.newZippedChildItem(repository,
+ collectionStorageItem.getItemContext(), path, "", member.getModified(), logger));
+ }
}
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItem.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItem.java
index fe60216..f993436 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItem.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItem.java
@@ -24,6 +24,7 @@ import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
import org.slf4j.Logger;
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.LocalStorageException;
+import org.sonatype.nexus.proxy.RequestContext;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.item.StorageCollectionItem;
import org.sonatype.nexus.proxy.item.StorageFileItem;
@@ -57,17 +58,20 @@ public class ZippedItem {
}
private final DefaultUnzipRepository repository;
- private final StorageItem zippedStorageItem;
+ private StorageItem zippedStorageItem;
private final String pathInZip;
private final String zipItemPath;
private final long lastModified;
private final Logger logger;
+ private final ResourceStoreRequest request;
/**
* Creates a ZippedItem for a file or folder based on the path to and inside the zip file.
*
* @param repository
* the repository in which the zipped item is accessed (the unzip repository)
+ * @param request
+ * the original request for this item
* @param zipItemPath
* the path to the zip file
* @param pathInZip
@@ -79,24 +83,40 @@ public class ZippedItem {
* @throws LocalStorageException
* is thrown if an issue with the zip file itself occured
*/
- public ZippedItem(final DefaultUnzipRepository repository, final String zipItemPath, final String pathInZip,
- final long lastModified, final Logger logger) throws ItemNotFoundException, LocalStorageException {
- this.repository = repository;
- this.zipItemPath = zipItemPath;
-
- this.lastModified = lastModified;
- this.logger = logger;
-
- if (pathInZip != null) {
- this.pathInZip = removeTrailingSlash(pathInZip);
- } else {
- this.pathInZip = "";
- }
- zippedStorageItem = createZippedStorageItem();
+ public static ZippedItem newZippedItem(final DefaultUnzipRepository repository, final ResourceStoreRequest request,
+ final String zipItemPath, final String pathInZip, final long lastModified, final Logger logger)
+ throws ItemNotFoundException, LocalStorageException {
+ ZippedItem result = new ZippedItem(repository, request, zipItemPath, pathInZip, lastModified, logger);
+ result.initZippedStorageItem();
+ return result;
}
- private static String removeTrailingSlash(final String path) {
- return (path.endsWith("/") ? path.substring(0, path.length() - 1) : path);
+ /**
+ * Creates a ZippedItem which is the child of a folder being listed.
+ *
+ * @param repository
+ * the repository in which the zipped item is accessed (the unzip repository)
+ * @param parentContext
+ * the context for the request of the parent item being listed
+ * @param zipItemPath
+ * the path to the zip file
+ * @param pathInZip
+ * the path of the zipped item relative to the zip file
+ * @param lastModified
+ * the modification timestamp of the zip file and all entries
+ * @throws ItemNotFoundException
+ * is thrown if the path within the zip file does not point to an existing zip entry
+ * @throws LocalStorageException
+ * is thrown if an issue with the zip file itself occured
+ */
+ public static ZippedItem newZippedChildItem(DefaultUnzipRepository repository, RequestContext parentContext,
+ String zipItemPath, String pathInZip, long lastModified, Logger logger) throws LocalStorageException,
+ ItemNotFoundException {
+ ResourceStoreRequest requestForChild = createRequestForChild(parentContext, zipItemPath, pathInZip);
+
+ ZippedItem result = new ZippedItem(repository, requestForChild, zipItemPath, pathInZip, lastModified, logger);
+ result.initZippedStorageItem();
+ return result;
}
/**
@@ -109,21 +129,42 @@ public class ZippedItem {
* the zip entry representing the zipped file in the zip file
* @throws ItemNotFoundException
*/
- private ZippedItem(final ZippedItem parentItem, final ZipEntry entry, final Logger logger)
+ public static ZippedItem newZippedChildItem(final ZippedItem parentItem, final ZipEntry entry, final Logger logger)
throws ItemNotFoundException {
- repository = parentItem.getRepository();
- zipItemPath = parentItem.zipItemPath;
+ ResourceStoreRequest requestForChild = createRequestForChild(parentItem.getRequest().getRequestContext(),
+ parentItem.zipItemPath, entry.getName());
+
+ ZippedItem result = new ZippedItem(parentItem.getRepository(), requestForChild, parentItem.zipItemPath,
+ entry.getName(), parentItem.getLastModified(), logger);
+ result.initZippedStorageItem(entry);
+ return result;
+ }
+
+ private static ResourceStoreRequest createRequestForChild(RequestContext parentContext, String zipItemPath,
+ String pathInZip) {
+ ResourceStoreRequest request = new ResourceStoreRequest(getPath(zipItemPath, pathInZip));
+ request.getRequestContext().setParentContext(parentContext);
+ return request;
+ }
+
+ private static String removeTrailingSlash(final String path) {
+ return (path.endsWith("/") ? path.substring(0, path.length() - 1) : path);
+ }
+
+ private ZippedItem(final DefaultUnzipRepository repository, final ResourceStoreRequest request,
+ final String zipItemPath, final String pathInZip, final long lastModified, final Logger logger) {
+ this.repository = repository;
+ this.request = request;
+ this.zipItemPath = zipItemPath;
- lastModified = parentItem.getLastModified();
+ this.lastModified = lastModified;
this.logger = logger;
- if (entry.getName() != null) {
- final String pathInZip = entry.getName();
+ if (pathInZip != null) {
this.pathInZip = removeTrailingSlash(pathInZip);
} else {
- pathInZip = "";
+ this.pathInZip = "";
}
- zippedStorageItem = createZippedStorageItem(entry);
}
/**
@@ -145,6 +186,10 @@ public class ZippedItem {
* @return the absolute path of the zipped entry
*/
public String getPath() {
+ return getPath(zipItemPath, pathInZip);
+ }
+
+ private static String getPath(String zipItemPath, String pathInZip) {
final String unzippedPath = zipItemPath + Util.UNZIP_TYPE_EXTENSION;
if (pathInZip != null && !"".equals(pathInZip)) {
return unzippedPath + "/" + pathInZip;
@@ -159,7 +204,6 @@ public class ZippedItem {
* @return the request for this zipped item
*/
public ResourceStoreRequest getRequest() {
- final ResourceStoreRequest request = new ResourceStoreRequest(getPath(), true, false);
return request;
}
@@ -188,11 +232,11 @@ public class ZippedItem {
}
}
- private StorageItem createZippedStorageItem(final ZipEntry entry) {
+ private void initZippedStorageItem(final ZipEntry entry) {
if (entry.isDirectory()) {
- return new ZippedStorageCollectionItem(this);
+ zippedStorageItem = new ZippedStorageCollectionItem(this);
} else {
- return new ZippedStorageFileItem(this, entry.getSize());
+ zippedStorageItem = new ZippedStorageFileItem(this, entry.getSize());
}
}
@@ -208,11 +252,12 @@ public class ZippedItem {
* @throws LocalStorageException
* is thrown if an issue with the zip file itself occured
*/
- private StorageItem createZippedStorageItem() throws ItemNotFoundException, LocalStorageException {
+ private void initZippedStorageItem() throws ItemNotFoundException, LocalStorageException {
if (pathInZip.length() == 0) {
// this ZippedItem represents the zip file itself
// -> return a collection storage item for the zip file
- return new ZippedStorageCollectionItem(this);
+ zippedStorageItem = new ZippedStorageCollectionItem(this);
+ return;
}
ZipFile zipFile = null;
try {
@@ -225,7 +270,8 @@ public class ZippedItem {
final ZipEntry entry = entries.nextElement();
final String entryName = removeTrailingSlash(entry.getName());
if (pathInZip.equals(entryName)) {
- return createZippedStorageItem(entry);
+ initZippedStorageItem(entry);
+ return;
}
}
} catch (final ItemNotFoundException e) {
@@ -310,7 +356,7 @@ public class ZippedItem {
final ZipEntry entry = entries.nextElement();
if (isDirectMember(entry.getName())) {
StorageItem zipEntryItem;
- final ZippedItem zippedItem = new ZippedItem(this, entry, logger);
+ final ZippedItem zippedItem = newZippedChildItem(this, entry, logger);
if (entry.isDirectory()) {
zipEntryItem = new ZippedStorageCollectionItem(zippedItem);
} else {
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java
index 951ec69..85f8605 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java
@@ -13,7 +13,6 @@ package org.eclipse.tycho.nexus.internal.plugin.storage;
import java.io.IOException;
import java.io.InputStream;
-import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.item.ContentLocator;
import org.sonatype.nexus.proxy.item.DefaultStorageFileItem;
@@ -64,8 +63,8 @@ public final class ZippedStorageFileItem extends DefaultStorageFileItem {
* the modification time of the represented file
*/
public ZippedStorageFileItem(final ZippedItem zippedItem, final long length) {
- super(zippedItem.getRepository(), new ResourceStoreRequest(zippedItem.getPath()), true, false,
- new ZippedStorageFileContentLocator(zippedItem, length));
+ super(zippedItem.getRepository(), zippedItem.getRequest(), true, false, new ZippedStorageFileContentLocator(
+ zippedItem, length));
// At creation time the underlying zip entry is known.
// Keeping this information avoids to open the zip and loop over the
// entries when answering related questions
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java
index 21b93c0..452d5a7 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java
@@ -15,6 +15,7 @@ import java.util.Collection;
import org.eclipse.tycho.nexus.internal.plugin.storage.Util;
import org.eclipse.tycho.nexus.internal.plugin.storage.ZippedStorageCollectionItem;
+import org.eclipse.tycho.nexus.internal.plugin.storage.ZippedStorageFileItem;
import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
import org.eclipse.tycho.nexus.internal.plugin.test.UnzipPluginTestSupport;
@@ -96,11 +97,15 @@ public abstract class DefaultUnzipRepositoryTest extends UnzipPluginTestSupport
}
@Test
- public void testRetriveFileInArchive() throws IllegalOperationException, ItemNotFoundException, IOException {
+ public void testRetrieveFileInArchive() throws Exception {
final String filePath = "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/test.txt";
- final StorageItem item = unzipRepo.doRetrieveItem(new ResourceStoreRequest(filePath));
- Assert.assertTrue(item instanceof DefaultStorageFileItem);
- final DefaultStorageFileItem fileItem = (DefaultStorageFileItem) item;
+ ResourceStoreRequest request = new ResourceStoreRequest(filePath);
+ request.setRequestUrl("http://foo");
+ final StorageItem item = unzipRepo.doRetrieveItem(request);
+ Assert.assertEquals("request URL not preserved - bug 431866", "http://foo", item.getResourceStoreRequest()
+ .getRequestUrl());
+ Assert.assertTrue(item instanceof ZippedStorageFileItem);
+ final ZippedStorageFileItem fileItem = (ZippedStorageFileItem) item;
Assert.assertEquals("text/plain", fileItem.getMimeType());
Assert.assertEquals(filePath, fileItem.getPath());
TestUtil.assertContent("some content", fileItem);
@@ -139,11 +144,14 @@ public abstract class DefaultUnzipRepositoryTest extends UnzipPluginTestSupport
}
@Test
- public void testRetrieveSubCollectionInArchive() throws IllegalOperationException, ItemNotFoundException,
- AccessDeniedException, NoSuchResourceStoreException, IOException {
+ public void testRetrieveSubCollectionInArchive() throws Exception {
final String collectionPath = "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir/subdir";
- final StorageItem item = unzipRepo.doRetrieveItem(new ResourceStoreRequest(collectionPath));
+ final ResourceStoreRequest request = new ResourceStoreRequest(collectionPath);
+ request.setRequestUrl("http://foo");
+ final StorageItem item = unzipRepo.doRetrieveItem(request);
Assert.assertTrue(item instanceof ZippedStorageCollectionItem);
+ Assert.assertEquals("request URL not preserved - bug 431866", "http://foo", item.getResourceStoreRequest()
+ .getRequestUrl());
final StorageCollectionItem collectionItem = (StorageCollectionItem) item;
Assert.assertEquals(collectionPath, collectionItem.getPath());
final Collection<StorageItem> members = collectionItem.list();
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java
index 42950ba..93e2ba3 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java
@@ -31,6 +31,7 @@ import org.sonatype.nexus.proxy.StorageException;
@SuppressWarnings("deprecation")
public class UnzipCacheTest extends UnzipPluginTestSupport {
+
private static final String PATH_UP_TO_VERSION = "/ga/1.0.0-SNAPSHOT/archive-1.0.0-";
private static final String LATEST_VERSION = "20101013";
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java
index 96d9841..4d571dd 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java
@@ -22,6 +22,8 @@ import org.junit.Test;
import org.slf4j.LoggerFactory;
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.LocalStorageException;
+import org.sonatype.nexus.proxy.RequestContext;
+import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.item.DefaultStorageCollectionItem;
import org.sonatype.nexus.proxy.item.DefaultStorageFileItem;
import org.sonatype.nexus.util.ItemPathUtils;
@@ -145,7 +147,8 @@ public class ZippedItemTest extends UnzipPluginTestSupport {
@Test(expected = LocalStorageException.class)
public void testZipItemNotFound() throws Exception {
final String pathInZip = "test.txt";
- new ZippedItem(unzipReposMock, "/", pathInZip, 0L, LoggerFactory.getLogger(getClass()));
+ ZippedItem.newZippedItem(unzipReposMock, new ResourceStoreRequest("/-unzip/" + pathInZip), "/", pathInZip, 0L,
+ LoggerFactory.getLogger(getClass()));
}
@Test
@@ -174,8 +177,8 @@ public class ZippedItemTest extends UnzipPluginTestSupport {
}
private ZippedItem createZippedItem(final String pathInZip) throws LocalStorageException, ItemNotFoundException {
- return new ZippedItem(unzipReposMock, pathToArchive, pathInZip, System.currentTimeMillis(),
- LoggerFactory.getLogger(getClass()));
+ return ZippedItem.newZippedChildItem(unzipReposMock, new RequestContext(), pathToArchive, pathInZip,
+ System.currentTimeMillis(), LoggerFactory.getLogger(getClass()));
}
@AfterClass
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java
index dd22dbc..f7400f1 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java
@@ -26,7 +26,9 @@ import org.slf4j.LoggerFactory;
import org.sonatype.nexus.proxy.AccessDeniedException;
import org.sonatype.nexus.proxy.IllegalOperationException;
import org.sonatype.nexus.proxy.ItemNotFoundException;
+import org.sonatype.nexus.proxy.LocalStorageException;
import org.sonatype.nexus.proxy.NoSuchResourceStoreException;
+import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.item.StorageItem;
@SuppressWarnings("nls")
@@ -43,8 +45,7 @@ public class ZippedStorageCollectionItemTest extends UnzipPluginTestSupport {
@Test
public void testList() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final ZippedItem zippedItem = new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "dir", 0L,
- testLogger);
+ final ZippedItem zippedItem = createZippedItem("dir", 0L);
final ZippedStorageCollectionItem zippedStorageCollectionItem = new ZippedStorageCollectionItem(zippedItem);
TestUtil.assertMembers(new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir/subdir" },
new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir/test.txt" },
@@ -54,7 +55,7 @@ public class ZippedStorageCollectionItemTest extends UnzipPluginTestSupport {
@Test
public void testListInRoot() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final ZippedItem zippedItem = new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "", 0L, testLogger);
+ final ZippedItem zippedItem = createZippedItem("", 0L);
final ZippedStorageCollectionItem zippedStorageCollectionItem = new ZippedStorageCollectionItem(zippedItem);
TestUtil.assertMembers(new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir" },
new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/test.txt" },
@@ -67,7 +68,7 @@ public class ZippedStorageCollectionItemTest extends UnzipPluginTestSupport {
final File file = new File("./src/test/resources/" + "masterRepo" + "/dir/subdir/archive.zip");
final long time = file.lastModified();
- final ZippedItem zipItem = new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "", time, testLogger);
+ final ZippedItem zipItem = createZippedItem("", time);
final ZippedStorageCollectionItem zipStorageCollectionItem = new ZippedStorageCollectionItem(zipItem);
Assert.assertEquals(time, zipStorageCollectionItem.getModified());
@@ -79,6 +80,14 @@ public class ZippedStorageCollectionItemTest extends UnzipPluginTestSupport {
}
}
+ private ZippedItem createZippedItem(String pathInZip, long lastModified) throws ItemNotFoundException,
+ LocalStorageException {
+ String pathToZip = "/dir/subdir/archive.zip";
+ return ZippedItem.newZippedItem(unzipRepositoryMock,
+ new ResourceStoreRequest(pathToZip + "-unzip/" + pathInZip), pathToZip, pathInZip, lastModified,
+ testLogger);
+ }
+
@AfterClass
public static void classTearDown() {
TestUtil.cleanUpTestFiles();
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java
index d89c071..221b2f0 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java
@@ -27,6 +27,7 @@ import org.sonatype.nexus.proxy.IllegalOperationException;
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.LocalStorageException;
import org.sonatype.nexus.proxy.NoSuchResourceStoreException;
+import org.sonatype.nexus.proxy.RequestContext;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.StorageException;
import org.sonatype.nexus.proxy.item.ContentLocator;
@@ -165,13 +166,14 @@ public class RepositoryMock extends AbstractRepository {
final StorageCollectionItem collectionItem = EasyMock.createMock(StorageCollectionItem.class);
EasyMock.expect(collectionItem.getRepositoryId()).andStubReturn(repositoryId);
EasyMock.expect(collectionItem.getPath()).andStubReturn(pathWithoutTrailingSlash);
- EasyMock.expect(collectionItem.getResourceStoreRequest()).andAnswer(
+ EasyMock.expect(collectionItem.getResourceStoreRequest()).andStubAnswer(
new IAnswer<ResourceStoreRequest>() {
@Override
public ResourceStoreRequest answer() throws Throwable {
return new ResourceStoreRequest(pathWithoutTrailingSlash);
}
});
+ EasyMock.expect(collectionItem.getItemContext()).andStubReturn(new RequestContext());
EasyMock.expect(collectionItem.list()).andAnswer(new IAnswer<Collection<StorageItem>>() {
@Override

Back to the top