Skip to content

Commit

Permalink
GRADLE-2932 - Incremented the cache layout version.
Browse files Browse the repository at this point in the history
- Simplified CacheLayout.
- Changed GradleDistribution fixture to use a VersionNumber to represent the cache layout, instead of an integer.
  • Loading branch information
adammurdoch committed Oct 23, 2013
1 parent 6e03817 commit aace47c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,27 @@
*/
package org.gradle.api.internal.artifacts.ivyservice;

import org.gradle.util.VersionNumber;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public enum CacheLayout {
ROOT("modules", "%d", 1, null),
FILE_STORE("files", "%d.%d", ROOT.majorVersion, 1),
META_DATA("metadata", "%d.%d", ROOT.majorVersion, 31);
ROOT(null, "modules", 2),
FILE_STORE(ROOT, "files", 1),
META_DATA(ROOT, "metadata", 1);

private final String name;
private final String versionPattern;
private final Integer majorVersion;
private final Integer minorVersion;
private final CacheLayout parent;
private final int version;

private CacheLayout(String name, String versionPattern, Integer majorVersion, Integer minorVersion) {
private CacheLayout(CacheLayout parent, String name, int version) {
this.parent = parent;
this.name = name;
this.versionPattern = versionPattern;
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
}

public Integer getMajorVersion() {
return majorVersion;
this.version = version;
}

public Integer getMinorVersion() {
return minorVersion;
public VersionNumber getVersion() {
return VersionNumber.parse(getFormattedVersion());
}

public String getKey() {
Expand All @@ -53,14 +47,10 @@ public String getKey() {
}

public String getFormattedVersion() {
List<Integer> versions = new ArrayList<Integer>();
versions.add(majorVersion);

if(minorVersion != null) {
versions.add(minorVersion);
if (parent == null) {
return String.valueOf(version);
}

return String.format(versionPattern, versions.toArray());
return parent.getFormattedVersion() + '.' + String.valueOf(version);
}

public File getPath(File parentDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.gradle.cache.internal.PersistentIndexedCacheParameters;
import org.gradle.internal.Factory;
import org.gradle.messaging.serialize.Serializer;
import org.gradle.util.VersionNumber;

import java.io.File;

Expand All @@ -35,7 +36,7 @@ public class DefaultCacheLockingManager implements CacheLockingManager {

// If you update this, also update DefaultGradleDistribution.getArtifactCacheLayoutVersion() (which is the historical record)
// You should also update LocallyAvailableResourceFinderFactory
public static final int CACHE_LAYOUT_VERSION = CacheLayout.META_DATA.getMinorVersion();
public static final VersionNumber CACHE_LAYOUT_VERSION = CacheLayout.META_DATA.getVersion();

private final PersistentCache cache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LocallyAvailableResourceFinder<ArtifactRevisionId> create() {
finders.add(new LocallyAvailableResourceFinderSearchableFileStoreAdapter<ArtifactRevisionId>(fileStore));

// 1.9
// addForPattern(finders, "modules-1/files-1.1/[organisation]/[module](/[branch])/[revision]/*/[artifact]-[revision](-[classifier])(.[ext])");
// addForPattern(finders, "modules-2/files-2.1/[organisation]/[module](/[branch])/[revision]/*/[artifact]-[revision](-[classifier])(.[ext])");

// 1.8
addForPattern(finders, "artifacts-26/filestore/[organisation]/[module](/[branch])/[revision]/[type]/*/[artifact]-[revision](-[classifier])(.[ext])");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.gradle.api.internal.artifacts.ivyservice

import org.gradle.util.VersionNumber
import spock.lang.Specification

class CacheLayoutTest extends Specification {
Expand All @@ -23,33 +24,31 @@ class CacheLayoutTest extends Specification {
CacheLayout cacheLayout = CacheLayout.ROOT

then:
cacheLayout.getKey() == 'modules-1'
cacheLayout.getMajorVersion() == 1
cacheLayout.getFormattedVersion() == '1'
cacheLayout.getPath(new File('some/dir')) == new File('some/dir/modules-1')
cacheLayout.key == 'modules-2'
cacheLayout.version == VersionNumber.parse("2.0.0")
cacheLayout.formattedVersion == '2'
cacheLayout.getPath(new File('some/dir')) == new File('some/dir/modules-2')
}

def "use file store layout"() {
when:
CacheLayout cacheLayout = CacheLayout.FILE_STORE

then:
cacheLayout.key == 'files-1.1'
cacheLayout.majorVersion == 1
cacheLayout.minorVersion == 1
cacheLayout.formattedVersion == '1.1'
cacheLayout.getPath(new File('some/dir')) == new File('some/dir/files-1.1')
cacheLayout.key == 'files-2.1'
cacheLayout.version == VersionNumber.parse("2.1.0")
cacheLayout.formattedVersion == '2.1'
cacheLayout.getPath(new File('some/dir')) == new File('some/dir/files-2.1')
}

def "use metadata store layout"() {
when:
CacheLayout cacheLayout = CacheLayout.META_DATA

then:
cacheLayout.key == 'metadata-1.31'
cacheLayout.majorVersion == 1
cacheLayout.minorVersion == 31
cacheLayout.formattedVersion == '1.31'
cacheLayout.getPath(new File('some/dir')) == new File('some/dir/metadata-1.31')
cacheLayout.key == 'metadata-2.1'
cacheLayout.version == VersionNumber.parse("2.1.0")
cacheLayout.formattedVersion == '2.1'
cacheLayout.getPath(new File('some/dir')) == new File('some/dir/metadata-2.1')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gradle.test.fixtures.file.TestDirectoryProvider;
import org.gradle.test.fixtures.file.TestFile;
import org.gradle.util.GradleVersion;
import org.gradle.util.VersionNumber;

public class DefaultGradleDistribution implements GradleDistribution {

Expand Down Expand Up @@ -112,19 +113,21 @@ public boolean isToolingApiNonAsciiOutputSupported() {
return true;
}

public int getArtifactCacheLayoutVersion() {
if (isSameOrNewer("1.9-rc-1")) {
return 31;
public VersionNumber getArtifactCacheLayoutVersion() {
if (isSameOrNewer("1.9-rc-2")) {
return VersionNumber.parse("2.1");
} else if (isSameOrNewer("1.9-rc-1")) {
return VersionNumber.parse("1.31");
} else if (isSameOrNewer("1.7-rc-1")) {
return 26;
return VersionNumber.parse("0.26");
} else if (isSameOrNewer("1.6-rc-1")) {
return 24;
return VersionNumber.parse("0.24");
} else if (isSameOrNewer("1.4-rc-1")) {
return 23;
return VersionNumber.parse("0.23");
} else if (isSameOrNewer("1.3")) {
return 15;
return VersionNumber.parse("0.15");
} else {
return 1;
return VersionNumber.parse("0.1");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.gradle.test.fixtures.file.TestDirectoryProvider;
import org.gradle.test.fixtures.file.TestFile;
import org.gradle.util.GradleVersion;
import org.gradle.util.VersionNumber;

public interface GradleDistribution {
/**
Expand Down Expand Up @@ -75,7 +76,7 @@ public interface GradleDistribution {
/**
* Returns the version of the artifact cache layout
*/
int getArtifactCacheLayoutVersion();
VersionNumber getArtifactCacheLayoutVersion();

/**
* Returns true if the open API is supported by this distribution.
Expand Down

0 comments on commit aace47c

Please sign in to comment.