Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHardi Probst2014-06-14 18:26:02 -0400
committerJan Sievers2014-09-19 10:18:03 -0400
commit0e84c63efc03f11c7fa42c62f828429fce06cea2 (patch)
tree9e54f3699ce6b12abba2d24819717d32fd77bc23
parentd7a2a1106f7f99cad8eeeb602174f97a904246f4 (diff)
downloadorg.eclipse.tycho.nexus-0e84c63efc03f11c7fa42c62f828429fce06cea2.tar.gz
org.eclipse.tycho.nexus-0e84c63efc03f11c7fa42c62f828429fce06cea2.tar.xz
org.eclipse.tycho.nexus-0e84c63efc03f11c7fa42c62f828429fce06cea2.zip
437438 implementation and unittest of the release redeploy bugfix
- checks if the master repository is a MavenRepository for RELEASE artifacts and with WRITE (REDEPLOY) policy - compares timestamps to update cache if necessary - see UnzipCacheTest.testReleaseRedeploy for a testcase - RepositoryMock has a new inner subclass MavenRepositoryMock which implements the MavenRepository interface Bug: 437438 Signed-off-by: hardi.probst@gmail.com Change-Id: Ic8cbe59d39c62198160ee115ee168de6535b15c2
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCache.java34
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java34
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java117
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java5
-rw-r--r--unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-1.zipbin0 -> 163 bytes
-rw-r--r--unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-2.zipbin0 -> 305 bytes
6 files changed, 188 insertions, 2 deletions
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 ee9426f..5822103 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
@@ -23,6 +23,9 @@ import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.LocalStorageException;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.item.StorageItem;
+import org.sonatype.nexus.proxy.maven.MavenRepository;
+import org.sonatype.nexus.proxy.maven.RepositoryPolicy;
+import org.sonatype.nexus.proxy.repository.RepositoryWritePolicy;
import org.sonatype.nexus.proxy.storage.UnsupportedStorageOperationException;
import org.sonatype.nexus.proxy.storage.local.LocalRepositoryStorage;
import org.sonatype.nexus.proxy.storage.local.fs.DefaultFSLocalRepositoryStorage;
@@ -59,12 +62,30 @@ public class UnzipCache {
try {
synchronized (folderLock) {
final ResourceStoreRequest request = new ResourceStoreRequest(zipItemPath);
+ boolean doReleaseRedeployCheck = false;
+
if (!localStorage.containsItem(repository, request)) {
logger.debug("Caching zip file from master repository: " + zipItemPath);
final StorageItem storageItem = retrieveItemFromMaster(request);
localStorage.storeItem(repository, storageItem);
+ } else {
+ //repositoryWritePolicy only if cache is already filled
+ doReleaseRedeployCheck = masterIsReleaseRepoAndSupportsRedeploy();
+ logger.debug("doReleaseRedeployCheck: " + doReleaseRedeployCheck);
+ }
+ File file = ((DefaultFSLocalRepositoryStorage) localStorage).getFileFromBase(repository, request);
+
+ if (doReleaseRedeployCheck) {
+ long cacheModified = file.lastModified();
+ final StorageItem storageItem = retrieveItemFromMaster(request);
+
+ if (storageItem.getModified() > cacheModified) {
+ logger.debug("Release redpeloy detected: Caching zip file from master repository: "
+ + zipItemPath);
+ localStorage.storeItem(repository, storageItem);
+ file = ((DefaultFSLocalRepositoryStorage) localStorage).getFileFromBase(repository, request);
+ }
}
- final File file = ((DefaultFSLocalRepositoryStorage) localStorage).getFileFromBase(repository, request);
logger.debug("Accessed cached zip file: " + zipItemPath);
return file;
}
@@ -148,4 +169,15 @@ public class UnzipCache {
}
}
+ private boolean masterIsReleaseRepoAndSupportsRedeploy() {
+ boolean releaseRepo = false;
+
+ if (repository.getMasterRepository() instanceof MavenRepository) {
+ releaseRepo = RepositoryPolicy.RELEASE.equals(((MavenRepository) repository.getMasterRepository())
+ .getRepositoryPolicy());
+ }
+
+ return releaseRepo
+ && RepositoryWritePolicy.ALLOW_WRITE.equals(repository.getMasterRepository().getWritePolicy());
+ }
}
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 4f162f1..96d8455 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
@@ -21,6 +21,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import org.apache.commons.io.FileUtils;
import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
@@ -67,6 +68,39 @@ public class UnzipCacheTest extends UnzipPluginTestSupport {
}
@Test
+ public void testReleaseRedeploy() throws Exception {
+ String redeployableRepoDir = "src/test/resources/redeployRelRepo";
+ String redeployableArchiveRepoPath = "/dir/redeployable-1.0.0.zip";
+ String redeployableArchiveFullPath = redeployableRepoDir + redeployableArchiveRepoPath;
+ final File redeployableArchiveFile = new File(redeployableArchiveFullPath);
+
+ try {
+ UnzipCache cache = createUnzipRepo(createRedeployRelRepo()).getCache();
+
+ final File version1File = new File(redeployableRepoDir + "/dir/version-1.zip");
+ final File version2File = new File(redeployableRepoDir + "/dir/version-2.zip");
+
+ FileUtils.copyFile(version1File, redeployableArchiveFile);
+
+ final File redeployableRequest1 = cache.getArchive(redeployableArchiveRepoPath);
+ //expect content of version-1.zip
+ Assert.assertArrayEquals(FileUtils.readFileToByteArray(version1File),
+ FileUtils.readFileToByteArray(redeployableRequest1));
+
+ //update content of redeployable-1.0.0
+ FileUtils.copyFile(version2File, redeployableArchiveFile);
+ FileUtils.touch(redeployableArchiveFile);
+
+ final File redeployableRequest2 = cache.getArchive(redeployableArchiveRepoPath);
+ //expect content of version-2.zip
+ Assert.assertArrayEquals(FileUtils.readFileToByteArray(version2File),
+ FileUtils.readFileToByteArray(redeployableRequest2));
+ } finally {
+ FileUtils.deleteQuietly(redeployableArchiveFile);
+ }
+ }
+
+ @Test
public void testCleanUpOldSnapshots() throws StorageException, ItemNotFoundException {
final File latestZip = new File(oldZip.getParentFile() + File.separator + "archive-1.0.0-20101013-2.zip");
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 cd76bc1..28e847a 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
@@ -17,6 +17,7 @@ import java.io.InputStream;
import java.net.URLConnection;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.Map;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
@@ -30,15 +31,24 @@ 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.AbstractStorageItem;
import org.sonatype.nexus.proxy.item.ContentLocator;
import org.sonatype.nexus.proxy.item.DefaultStorageFileItem;
import org.sonatype.nexus.proxy.item.RepositoryItemUidFactory;
import org.sonatype.nexus.proxy.item.StorageCollectionItem;
import org.sonatype.nexus.proxy.item.StorageItem;
import org.sonatype.nexus.proxy.item.uid.RepositoryItemUidAttributeManager;
+import org.sonatype.nexus.proxy.maven.ArtifactStoreHelper;
+import org.sonatype.nexus.proxy.maven.MavenRepository;
+import org.sonatype.nexus.proxy.maven.MetadataManager;
+import org.sonatype.nexus.proxy.maven.RepositoryPolicy;
+import org.sonatype.nexus.proxy.maven.gav.GavCalculator;
+import org.sonatype.nexus.proxy.maven.packaging.ArtifactPackagingMapper;
import org.sonatype.nexus.proxy.registry.ContentClass;
import org.sonatype.nexus.proxy.repository.AbstractRepository;
import org.sonatype.nexus.proxy.repository.RepositoryKind;
+import org.sonatype.nexus.proxy.repository.RepositoryWritePolicy;
+import org.sonatype.nexus.proxy.storage.UnsupportedStorageOperationException;
import org.sonatype.nexus.util.PathUtils;
@SuppressWarnings({ "nls", "deprecation" })
@@ -70,7 +80,18 @@ public class RepositoryMock extends AbstractRepository {
return new RepositoryMock("masterRepo", repositoryItemUidFactory, repositoryItemUidAttributeManager);
}
- private RepositoryMock(final String repositoryId, RepositoryItemUidFactory repositoryItemUidFactory,
+ /**
+ * Creates a Repository with dummy content from src/test/resources/masterRepo
+ *
+ * @return
+ */
+ public static RepositoryMock createRedeployRelRepo(RepositoryItemUidFactory repositoryItemUidFactory,
+ RepositoryItemUidAttributeManager repositoryItemUidAttributeManager) {
+ return new MavenRepositoryMock("redeployRelRepo", repositoryItemUidFactory, repositoryItemUidAttributeManager,
+ RepositoryPolicy.RELEASE, RepositoryWritePolicy.ALLOW_WRITE);
+ }
+
+ RepositoryMock(final String repositoryId, RepositoryItemUidFactory repositoryItemUidFactory,
RepositoryItemUidAttributeManager repositoryItemUidAttributeManager) {
this.repositoryId = repositoryId;
this.repositoryItemUidFactory = repositoryItemUidFactory;
@@ -210,4 +231,98 @@ public class RepositoryMock extends AbstractRepository {
return null;
}
+ public static class MavenRepositoryMock extends RepositoryMock implements MavenRepository {
+
+ private RepositoryPolicy repositoryPolicy;
+ private RepositoryWritePolicy repositoryWritePolicy;
+
+ MavenRepositoryMock(String repositoryId, RepositoryItemUidFactory repositoryItemUidFactory,
+ RepositoryItemUidAttributeManager repositoryItemUidAttributeManager, RepositoryPolicy repPolicy,
+ RepositoryWritePolicy writePolicy) {
+ super(repositoryId, repositoryItemUidFactory, repositoryItemUidAttributeManager);
+ this.repositoryPolicy = repPolicy;
+ this.repositoryWritePolicy = writePolicy;
+ }
+
+ @Override
+ public RepositoryPolicy getRepositoryPolicy() {
+ return repositoryPolicy;
+ }
+
+ @Override
+ public RepositoryWritePolicy getWritePolicy() {
+ return repositoryWritePolicy;
+ }
+
+ @Override
+ public void deleteItemWithChecksums(ResourceStoreRequest arg0) throws UnsupportedStorageOperationException,
+ ItemNotFoundException, IllegalOperationException, StorageException, AccessDeniedException {
+ }
+
+ @Override
+ public void deleteItemWithChecksums(boolean arg0, ResourceStoreRequest arg1)
+ throws UnsupportedStorageOperationException, IllegalOperationException, ItemNotFoundException,
+ StorageException {
+ }
+
+ @Override
+ public ArtifactPackagingMapper getArtifactPackagingMapper() {
+ return null;
+ }
+
+ @Override
+ public ArtifactStoreHelper getArtifactStoreHelper() {
+ return null;
+ }
+
+ @Override
+ public GavCalculator getGavCalculator() {
+ return null;
+ }
+
+ @Override
+ public MetadataManager getMetadataManager() {
+ return null;
+ }
+
+ @Override
+ public boolean isMavenArtifact(StorageItem arg0) {
+ return false;
+ }
+
+ @Override
+ public boolean isMavenArtifactPath(String arg0) {
+ return false;
+ }
+
+ @Override
+ public boolean isMavenMetadata(StorageItem arg0) {
+ return false;
+ }
+
+ @Override
+ public boolean isMavenMetadataPath(String arg0) {
+ return false;
+ }
+
+ @Override
+ public boolean recreateMavenMetadata(ResourceStoreRequest arg0) {
+ return false;
+ }
+
+ @Override
+ public void setRepositoryPolicy(RepositoryPolicy arg0) {
+ }
+
+ @Override
+ public void storeItemWithChecksums(boolean arg0, AbstractStorageItem arg1)
+ throws UnsupportedStorageOperationException, IllegalOperationException, StorageException {
+ }
+
+ @Override
+ public void storeItemWithChecksums(ResourceStoreRequest arg0, InputStream arg1, Map<String, String> arg2)
+ throws UnsupportedStorageOperationException, ItemNotFoundException, IllegalOperationException,
+ StorageException, AccessDeniedException {
+ }
+ }
}
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java
index f352976..982fa58 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java
@@ -22,4 +22,9 @@ public class UnzipPluginTestSupport extends NexusTestSupport {
return UnzipRepositoryMock.createUnzipRepository(masterRepository, lookup(LinkPersister.class),
lookup(RepositoryItemUidFactory.class));
}
+
+ protected RepositoryMock createRedeployRelRepo() throws Exception {
+ return RepositoryMock.createRedeployRelRepo(lookup(RepositoryItemUidFactory.class),
+ lookup(RepositoryItemUidAttributeManager.class));
+ }
}
diff --git a/unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-1.zip b/unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-1.zip
new file mode 100644
index 0000000..bc3053c
--- /dev/null
+++ b/unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-1.zip
Binary files differ
diff --git a/unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-2.zip b/unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-2.zip
new file mode 100644
index 0000000..ed3f2ff
--- /dev/null
+++ b/unzip-repository-plugin/src/test/resources/redeployRelRepo/dir/version-2.zip
Binary files differ

Back to the top