FIX: norevision management: added a unit test, it now seems to work well

git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484062 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Xavier Hanin 2005-10-26 07:06:37 +00:00
parent 9cd7fa373a
commit 16ef8e71fc
7 changed files with 111 additions and 24 deletions

View File

@ -61,21 +61,33 @@ public class ModuleRevisionId {
* @return true if the given revision can be considered as a revision of this module revision id.
*/
public boolean acceptRevision(String revision) {
if (_revision.equals(revision)) {
return true;
}
if (_revision.startsWith("latest.")) {
return true;
}
if (_revision.endsWith("+") && revision.startsWith(_revision.substring(0, _revision.length() - 1))) {
return true;
}
return false;
return acceptRevision(_revision, revision);
}
/**
* @return true if the revision is an exact one, i.e. not a 'latest.' nor a xx+ one.
*/
public boolean isExactRevision() {
return !_revision.startsWith("latest.") && !_revision.endsWith("+");
return isExactRevision(_revision);
}
public static boolean acceptRevision(String askedRevision, String revision) {
if (askedRevision.equals(revision)) {
return true;
}
if (askedRevision.startsWith("latest.")) {
return true;
}
if (askedRevision.endsWith("+") && revision.startsWith(askedRevision.substring(0, askedRevision.length() - 1))) {
return true;
}
return false;
}
/**
* @return true if the revision is an exact one, i.e. not a 'latest.' nor a xx+ one.
*/
public static boolean isExactRevision(String revision) {
return !revision.startsWith("latest.") && !revision.endsWith("+");
}
}

View File

@ -111,7 +111,6 @@ public abstract class BasicResolver extends AbstractResolver {
boolean downloaded = false;
boolean searched = false;
Date cachedPublicationDate = null;
String cachedRevision = null;
ModuleRevisionId mrid = dd.getDependencyRevisionId();
// check revision
int index = mrid.getRevision().indexOf("@");
@ -191,7 +190,6 @@ public abstract class BasicResolver extends AbstractResolver {
return searchedRmr(rmr);
} else {
Message.verbose("\t"+getName()+": revision in cache is not up to date: "+resolvedMrid);
cachedRevision = rmr.getDescriptor().getResolvedModuleRevisionId().getRevision();
if (dd.isChanging()) {
// ivy file has been updated, we should see if it has a new publication date
// to see if a new download is required (in case the dependency is a changing one)
@ -237,7 +235,7 @@ public abstract class BasicResolver extends AbstractResolver {
throw new IllegalStateException("bad module name found in "+ivyRef.getResource()+": expected="+mrid.getName()+" found="+md.getModuleRevisionId().getName());
}
if (ivyRef.getRevision() != null && md.getModuleRevisionId().getRevision() != null &&
!ivyRef.getRevision().equals(md.getModuleRevisionId().getRevision())) {
!ModuleRevisionId.acceptRevision(ivyRef.getRevision(), md.getModuleRevisionId().getRevision())) {
throw new IllegalStateException("bad revision found in "+ivyRef.getResource()+": expected="+ivyRef.getRevision()+" found="+md.getModuleRevisionId().getRevision());
}
@ -248,15 +246,6 @@ public abstract class BasicResolver extends AbstractResolver {
Message.verbose("dependency "+dd+" has changed: deleting old artifacts");
deleteOldArtifacts = true;
}
if (cachedRevision != null) {
if (!cachedRevision.equals(md.getResolvedModuleRevisionId().getRevision())) {
// revision has changed, artifacts should be downloaded again
Message.verbose("revision "+dd+" has changed: deleting old artifacts");
deleteOldArtifacts = true;
} else {
Message.debug("revision "+dd+" has not changed: keeping old artifacts");
}
}
if (deleteOldArtifacts) {
String[] confs = rmr.getDescriptor().getConfigurationsNames();
for (int i = 0; i < confs.length; i++) {

View File

@ -158,6 +158,68 @@ public class FileSystemResolverTest extends TestCase {
assertEquals(pubdate, rmr.getPublicationDate());
}
public void testNoRevision() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setIvy(_ivy);
_ivy.addResolver(resolver);
assertEquals("test", resolver.getName());
resolver.addIvyPattern("test"+FS+"repositories"+FS+"norevision"+FS+"ivy-[module].xml");
resolver.addArtifactPattern("test"+FS+"repositories"+FS+"norevision"+FS+"[artifact].[ext]");
File modify = new File("test/repositories/norevision/ivy-mod1.1.xml");
File artifact = new File("test/repositories/norevision/mod1.1.jar");
// 'publish' 'before' version
FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-before.xml"), modify, null);
FileUtil.copy(new File("test/repositories/norevision/mod1.1-before.jar"), artifact, null);
Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
modify.setLastModified(pubdate.getTime());
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "latest.integration");
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data);
assertNotNull(rmr);
assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), rmr.getId());
assertEquals(pubdate, rmr.getPublicationDate());
Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default");
File archiveFileInCache = _ivy.getArchiveFileInCache(_cache, artifacts[0]);
resolver.download(artifacts, _ivy, _cache);
assertTrue(archiveFileInCache.exists());
BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache));
assertEquals("before", r.readLine());
r.close();
// updates ivy file and artifact in repository
FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-after.xml"), modify, null);
FileUtil.copy(new File("test/repositories/norevision/mod1.1-after.jar"), artifact, null);
pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime();
modify.setLastModified(pubdate.getTime());
// no need to update new artifact timestamp cause it isn't used
// should get the new version even if checkModified is false, beacause we ask a latest.integration
resolver.setCheckmodified(false);
rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data);
assertNotNull(rmr);
assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"), rmr.getId());
assertEquals(pubdate, rmr.getPublicationDate());
artifacts = rmr.getDescriptor().getArtifacts("default");
archiveFileInCache = _ivy.getArchiveFileInCache(_cache, artifacts[0]);
assertFalse(archiveFileInCache.exists());
// should download the new artifact
artifacts = rmr.getDescriptor().getArtifacts("default");
resolver.download(artifacts, _ivy, _cache);
assertTrue(archiveFileInCache.exists());
r = new BufferedReader(new FileReader(archiveFileInCache));
assertEquals("after", r.readLine());
r.close();
}
public void testChanging() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
@ -226,7 +288,7 @@ public class FileSystemResolverTest extends TestCase {
r = new BufferedReader(new FileReader(archiveFileInCache));
assertEquals("after", r.readLine());
r.close();
}
}
public void testLatestTime() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();

View File

@ -0,0 +1,11 @@
<ivy-module version="1.0">
<info organisation="org1"
module="mod1.1"
revision="1.1"
status="integration"
publication="20050501110000"
/>
<dependencies>
<dependency name="mod1.2" rev="2.1"/>
</dependencies>
</ivy-module>

View File

@ -0,0 +1,11 @@
<ivy-module version="1.0">
<info organisation="org1"
module="mod1.1"
revision="1.0"
status="integration"
publication="20041101110000"
/>
<dependencies>
<dependency name="mod1.2" rev="2.0"/>
</dependencies>
</ivy-module>

View File

@ -0,0 +1 @@
after

View File

@ -0,0 +1 @@
before