Skip to content

Commit

Permalink
Resolved closest lower java-compiler-ant-tasks version if provided is…
Browse files Browse the repository at this point in the history
…n't available
  • Loading branch information
hsz committed Mar 25, 2022
1 parent cebfc7b commit a2f3837
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 29 deletions.
102 changes: 84 additions & 18 deletions src/main/kotlin/org/jetbrains/intellij/IntelliJPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import org.jetbrains.intellij.dependency.PluginDependencyManager
import org.jetbrains.intellij.dependency.PluginDependencyNotation
import org.jetbrains.intellij.dependency.PluginProjectDependency
import org.jetbrains.intellij.jbr.JbrResolver
import org.jetbrains.intellij.model.MavenMetadata
import org.jetbrains.intellij.model.XmlExtractor
import org.jetbrains.intellij.performanceTest.ProfilerName
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
import org.jetbrains.intellij.tasks.*
Expand Down Expand Up @@ -807,28 +809,92 @@ open class IntelliJPlugin : Plugin<Project> {
}, {
listOf(
"${extension.intellijRepository.get()}/${releaseType(version)}",
IntelliJPluginConstants.INTELLIJ_DEPENDENCIES
IntelliJPluginConstants.INTELLIJ_DEPENDENCIES,
).map(::mavenRepository)
})
}, true)
}

runCatching {
downloadCompiler(compilerVersion)
}.fold(onSuccess = { it }, onFailure = {
/**
* Try falling back on the version without the -EAP-SNAPSHOT suffix if the download
* for it fails - not all versions have a corresponding -EAP-SNAPSHOT version present
* in the snapshot repository.
*/
if (compilerVersion.endsWith(IntelliJPluginConstants.RELEASE_SUFFIX_EAP)) {
val nonEapVersion = compilerVersion.replace(
IntelliJPluginConstants.RELEASE_SUFFIX_EAP, ""
listOf(
{
runCatching {
downloadCompiler(compilerVersion)
}.fold(
onSuccess = { it },
onFailure = {
warn(logCategory(), "Cannot resolve java-compiler-ant-tasks in version: $compilerVersion")
null
},
)
downloadCompiler(nonEapVersion)
} else {
throw it
}
})
},
{
/**
* Try falling back on the version without the -EAP-SNAPSHOT suffix if the download
* for it fails - not all versions have a corresponding -EAP-SNAPSHOT version present
* in the snapshot repository.
*/
if (compilerVersion.endsWith(IntelliJPluginConstants.RELEASE_SUFFIX_EAP)) {
val nonEapVersion = compilerVersion.replace(
IntelliJPluginConstants.RELEASE_SUFFIX_EAP, ""
)
runCatching {
downloadCompiler(nonEapVersion)
}.fold(
onSuccess = {
warn(logCategory(), "Resolved non-EAP java-compiler-ant-tasks version: $nonEapVersion")
it
},
onFailure = {
warn(logCategory(), "Cannot resolve java-compiler-ant-tasks in version: $nonEapVersion")
null
},
)
} else {
null
}
},
{
/**
* Get the list of available packages and pick the closest lower one.
*/
val url = URL(IntelliJPluginConstants.JAVA_COMPILER_ANT_TASKS_MAVEN_METADATA)
val version = Version.parse(compilerVersion)
val closestCompilerVersion = XmlExtractor<MavenMetadata>()
.unmarshal(url.openStream())
.versioning?.versions?.let { versions ->
versions
.map(Version.Companion::parse)
.filter { it <= version }
.maxOf { it }.version
}

if (closestCompilerVersion == null) {
warn(logCategory(), "Cannot resolve java-compiler-ant-tasks Maven metadata")
null
} else {
runCatching {
downloadCompiler(closestCompilerVersion)
}.fold(
onSuccess = {
warn(
logCategory(),
"Resolved closest lower java-compiler-ant-tasks version: $closestCompilerVersion"
)
it
},
onFailure = {
warn(
logCategory(),
"Cannot resolve java-compiler-ant-tasks in version: $closestCompilerVersion"
)
null
},
)
}
},
)
.asSequence()
.mapNotNull { it() }
.firstOrNull()
} else {
warn(
logCategory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ object IntelliJPluginConstants {
const val DEFAULT_JBR_REPOSITORY = "$CACHE_REDIRECTOR/intellij-jbr"
const val PLUGIN_VERIFIER_REPOSITORY =
"$CACHE_REDIRECTOR/packages.jetbrains.team/maven/p/intellij-plugin-verifier/intellij-plugin-verifier"
const val JAVA_COMPILER_ANT_TASKS_MAVEN_METADATA =
"$DEFAULT_INTELLIJ_REPOSITORY/releases/com/jetbrains/intellij/java/java-compiler-ant-tasks/maven-metadata.xml"


const val PLUGIN_PATH = "plugin.path"
const val VERSION_LATEST = "latest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import javax.xml.bind.annotation.XmlElementWrapper
import javax.xml.bind.annotation.XmlRootElement

@XmlRootElement(name = "metadata")
data class SpacePackagesMavenMetadata(
data class MavenMetadata(

@set:XmlElement
var groupId: String? = null,
Expand All @@ -14,10 +14,10 @@ data class SpacePackagesMavenMetadata(
var artifactId: String? = null,

@set:XmlElement
var versioning: SpacePackagesMavenMetadataVersioning? = null,
var versioning: MavenMetadataVersioning? = null,
)

data class SpacePackagesMavenMetadataVersioning(
data class MavenMetadataVersioning(

@set:XmlElement
var latest: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ObjectFactory {

fun createPluginsCache() = PluginsCache()

fun createPluginVerifierRepository() = SpacePackagesMavenMetadata()
fun createPluginVerifierRepository() = MavenMetadata()

fun createProductsReleases() = ProductsReleases()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.jetbrains.intellij.IntelliJPluginConstants.VERSION_LATEST
import org.jetbrains.intellij.Version
import org.jetbrains.intellij.debug
import org.jetbrains.intellij.logCategory
import org.jetbrains.intellij.model.SpacePackagesMavenMetadata
import org.jetbrains.intellij.model.MavenMetadata
import org.jetbrains.intellij.model.XmlExtractor
import org.jetbrains.intellij.utils.ArchiveUtils
import java.io.File
Expand All @@ -32,7 +32,7 @@ open class DownloadRobotServerPluginTask @Inject constructor(objectFactory: Obje
fun resolveLatestVersion(): String {
debug(message = "Resolving latest Robot Server Plugin version")
val url = URL(METADATA_URL)
return XmlExtractor<SpacePackagesMavenMetadata>().unmarshal(url.openStream()).versioning?.latest
return XmlExtractor<MavenMetadata>().unmarshal(url.openStream()).versioning?.latest
?: throw GradleException("Cannot resolve the latest Robot Server Plugin version")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.jetbrains.intellij.ifFalse
import org.jetbrains.intellij.info
import org.jetbrains.intellij.jbr.JbrResolver
import org.jetbrains.intellij.logCategory
import org.jetbrains.intellij.model.SpacePackagesMavenMetadata
import org.jetbrains.intellij.model.MavenMetadata
import org.jetbrains.intellij.model.XmlExtractor
import org.jetbrains.intellij.utils.ArchiveUtils
import org.jetbrains.intellij.utils.DependenciesDownloader
Expand Down Expand Up @@ -58,7 +58,7 @@ open class RunPluginVerifierTask @Inject constructor(
fun resolveLatestVersion(): String {
debug(message = "Resolving latest Plugin Verifier version")
val url = URL(METADATA_URL)
return XmlExtractor<SpacePackagesMavenMetadata>().unmarshal(url.openStream()).versioning?.latest
return XmlExtractor<MavenMetadata>().unmarshal(url.openStream()).versioning?.latest
?: throw GradleException("Cannot resolve the latest Plugin Verifier version")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ open class DependenciesDownloader @Inject constructor(
context: String?,
dependenciesBlock: DependencyHandler.() -> Dependency,
repositoriesBlock: (RepositoryHandler.() -> ArtifactRepository)? = null,
) = downloadFromMultipleRepositories(context, dependenciesBlock) {
silent: Boolean = false,
) = downloadFromMultipleRepositories(context, dependenciesBlock, {
listOfNotNull(repositoriesBlock?.invoke(this))
}
}, silent)

fun downloadFromMultipleRepositories(
context: String?,
dependenciesBlock: DependencyHandler.() -> Dependency,
repositoriesBlock: RepositoryHandler.() -> List<ArtifactRepository>,
silent: Boolean = false,
): List<File> {
val dependency = dependenciesBlock.invoke(dependencyHandler)
val repositories = repositoriesBlock.invoke(repositoryHandler) + repositoryHandler.mavenCentral()

try {
return configurationContainer.detachedConfiguration(dependency).files.toList()
} catch (e: Exception) {
error(context, "Error when resolving dependency: $dependency", e)
if (!silent) {
error(context, "Error when resolving dependency: $dependency", e)
}
throw e
} finally {
repositoryHandler.removeAll(repositories.toSet())
Expand Down

0 comments on commit a2f3837

Please sign in to comment.