Skip to content

Instantly share code, notes, and snippets.

@jblaine
Created March 17, 2016 13:11
Show Gist options
  • Save jblaine/bbada6fbe5286063d5df to your computer and use it in GitHub Desktop.
Save jblaine/bbada6fbe5286063d5df to your computer and use it in GitHub Desktop.
Caused by: java.lang.ClassFormatError: Illegal class name "expire-R-PACKAGES-gz$getCacheAge" in class file expire-R-PACKAGES-gz$getCacheAge
import org.artifactory.fs.FileInfo
import org.artifactory.repo.RepoPath
import org.artifactory.request.Request
import static CacheConstants.PACKAGES_GZ_CACHE_MILLIS
class CacheConstants {
static final long PACKAGES_GZ_CACHE_MILLIS = 1800 * 1000L
}
download {
beforeDownloadRequest { Request request, RepoPath repoPath ->
if (repoPath.path.endsWith("/PACKAGES.gz") && isRemote(repoPath.repoKey) && shouldExpire(repoPath)) {
log.warn 'DEBUG: Expiring PACKAGES.gz'
expired = true
} else {
log.warn 'DEBUG: Not expiring PACKAGES.gz'
}
}
}
def isRemote(String repoKey) {
return repositories.getRemoteRepositories().contains(repoKey)
}
def shouldExpire(RepoPath repoPath) {
if (!repositories.exists(repoPath)) {
return false
}
FileInfo fileInfo = repositories.getFileInfo(repoPath)
long cacheAge = getCacheAge(fileInfo)
return cacheAge > PACKAGES_GZ_CACHE_MILLIS || cacheAge == -1
}
def getCacheAge(FileInfo fileInfo) {
long lastUpdated = fileInfo.lastUpdated
if (lastUpdated <= 0) {
return -1
}
return System.currentTimeMillis() - lastUpdated
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment