mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[maven] clean up io.File usages IDEA-361666
GitOrigin-RevId: 1387678a0347762cbff6f5f2fd831630ec0ec9be
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dbfc6bfa9c
commit
63432655e0
+42
-55
@@ -18,7 +18,6 @@ import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.StreamUtil
|
||||
import com.intellij.openapi.util.registry.Registry.Companion.stringValue
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.util.text.StringUtilRt
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jdom.Element
|
||||
@@ -26,14 +25,14 @@ import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.idea.maven.model.MavenId
|
||||
import org.jetbrains.idea.maven.utils.MavenLog
|
||||
import org.jetbrains.idea.maven.utils.MavenUtil
|
||||
import java.io.*
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URI
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.listDirectoryEntries
|
||||
import kotlin.io.path.name
|
||||
import kotlin.io.path.*
|
||||
|
||||
class MavenIndexerCMDState(
|
||||
private val myJdk: Sdk,
|
||||
@@ -64,14 +63,14 @@ class MavenIndexerCMDState(
|
||||
params.mainClass = "org.jetbrains.idea.maven.server.indexer.MavenServerIndexerMain"
|
||||
params.classPath.add(PathUtil.getJarPathForClass(StringUtilRt::class.java)) //util-rt
|
||||
params.classPath.add(PathUtil.getJarPathForClass(NotNull::class.java)) //annotations-java5
|
||||
params.classPath.addAllFiles(collectClassPathAndLibsFolder(myDistribution))
|
||||
params.classPath.addAllFiles(collectClassPathAndLibsFolder(myDistribution).map { it.toFile() })
|
||||
params.classPath.add(PathUtil.getJarPathForClass(Element::class.java)) //JDOM
|
||||
return params
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private fun addDependenciesFromMavenRepo(classPath: MutableList<File>) {
|
||||
private fun addDependenciesFromMavenRepo(classPath: MutableList<Path>) {
|
||||
|
||||
val communityHomePath = PathManager.getCommunityHomePath()
|
||||
val mavenIndexerIml = Paths.get(communityHomePath).resolve("plugins/maven/maven-server-indexer/intellij.maven.server.indexer.iml")
|
||||
@@ -92,9 +91,8 @@ class MavenIndexerCMDState(
|
||||
|
||||
for (depTemplate in dependenciesUrls) {
|
||||
val url = depTemplate.replace('$' + PathMacrosImpl.MAVEN_REPOSITORY + '$', pathToRepo)
|
||||
val path = Paths.get(URI(url));
|
||||
val jar = path.toFile()
|
||||
check(jar.isFile) { "File " + jar.path + " not found" }
|
||||
val jar = Paths.get(URI(url));
|
||||
check(jar.isRegularFile()) { "File $jar not found" }
|
||||
classPath.add(jar)
|
||||
}
|
||||
}
|
||||
@@ -110,9 +108,9 @@ class MavenIndexerCMDState(
|
||||
|
||||
}
|
||||
|
||||
private fun collectClassPathAndLibsFolder(distribution: MavenDistribution): List<File> {
|
||||
val classpath = ArrayList<File>()
|
||||
addMavenLibs(classpath, distribution.mavenHome.toFile())
|
||||
private fun collectClassPathAndLibsFolder(distribution: MavenDistribution): List<Path> {
|
||||
val classpath = ArrayList<Path>()
|
||||
addMavenLibs(classpath, distribution.mavenHome)
|
||||
addIndexerRTLibs(classpath)
|
||||
val pathToClass = PathManager.getJarForClass(MavenServerManager::class.java)
|
||||
?: throw IllegalStateException("Cannot find path to maven server manager code")
|
||||
@@ -133,27 +131,27 @@ class MavenIndexerCMDState(
|
||||
return classpath
|
||||
}
|
||||
|
||||
private fun addIndexerRTLibs(classpath: MutableList<File>) {
|
||||
private fun addIndexerRTLibs(classpath: MutableList<Path>) {
|
||||
val resources = indexerRTList
|
||||
val libDir = MavenUtil.getPluginSystemDir("rt-maven-indexer-lib").toFile()
|
||||
if (!libDir.isDirectory) {
|
||||
if (!libDir.mkdirs()) {
|
||||
throw PluginException("Cannot create cache directory for maven", PluginId.getId(MavenUtil.INTELLIJ_PLUGIN_ID))
|
||||
val libDir = MavenUtil.getPluginSystemDir("rt-maven-indexer-lib")
|
||||
if (!libDir.isDirectory()) {
|
||||
try {
|
||||
libDir.createDirectories()
|
||||
} catch (e: IOException) {
|
||||
throw PluginException("Cannot create cache directory for maven", e, PluginId.getId(MavenUtil.INTELLIJ_PLUGIN_ID))
|
||||
}
|
||||
}
|
||||
for (jarName in resources) {
|
||||
val file = File(libDir, jarName)
|
||||
if (!file.isFile) {
|
||||
val file = libDir.resolve(jarName)
|
||||
if (!file.isRegularFile()) {
|
||||
try {
|
||||
MavenIndexerCMDState::class.java.classLoader
|
||||
.getResourceAsStream(jarName).use { `is` ->
|
||||
BufferedOutputStream(FileOutputStream(file)).use { bos ->
|
||||
if (`is` == null) {
|
||||
throw PluginException("Cannot find runtime library $jarName in resources",
|
||||
PluginId.getId(MavenUtil.INTELLIJ_PLUGIN_ID))
|
||||
}
|
||||
StreamUtil.copy(`is`, bos)
|
||||
.getResourceAsStream(jarName).use {
|
||||
if (it == null) {
|
||||
throw PluginException("Cannot find runtime library $jarName in resources",
|
||||
PluginId.getId(MavenUtil.INTELLIJ_PLUGIN_ID))
|
||||
}
|
||||
Files.copy(it, file)
|
||||
}
|
||||
}
|
||||
catch (e: IOException) {
|
||||
@@ -182,49 +180,38 @@ class MavenIndexerCMDState(
|
||||
|
||||
private fun prepareClassPathForProduction(
|
||||
mavenVersion: String,
|
||||
classpath: MutableList<File>,
|
||||
classpath: MutableList<Path>,
|
||||
root: Path,
|
||||
) {
|
||||
classpath.add(File(PathUtil.getJarPathForClass(MavenId::class.java)))
|
||||
classpath.add(File(PathUtil.getJarPathForClass(MavenServer::class.java)))
|
||||
classpath.add( root.resolve("maven-server-indexer.jar").toFile())
|
||||
addDir(classpath, root.resolve("maven-server-indexer").toFile())
|
||||
addDir(classpath, root.resolve("intellij.maven.server.indexer").resolve("lib").toFile())
|
||||
classpath.add(PathManager.getJarForClass(MavenId::class.java)!!)
|
||||
classpath.add(PathManager.getJarForClass(MavenServer::class.java)!!)
|
||||
classpath.add( root.resolve("maven-server-indexer.jar"))
|
||||
addDir(classpath, root.resolve("maven-server-indexer"))
|
||||
addDir(classpath, root.resolve("intellij.maven.server.indexer").resolve("lib"))
|
||||
}
|
||||
|
||||
private fun prepareClassPathForLocalRunAndUnitTests(classpath: MutableList<File>, root: Path, packed: Boolean = false) {
|
||||
classpath.add(File(PathUtil.getJarPathForClass(MavenId::class.java)))
|
||||
private fun prepareClassPathForLocalRunAndUnitTests(classpath: MutableList<Path>, root: Path, packed: Boolean = false) {
|
||||
classpath.add(PathManager.getJarForClass(MavenId::class.java)!!)
|
||||
listOf(root.resolve("intellij.maven.server"),
|
||||
root.resolve("intellij.maven.server.indexer")).forEach {
|
||||
if (packed) {
|
||||
classpath.add(it.listDirectoryEntries("*.jar").first().toFile())
|
||||
classpath.add(it.listDirectoryEntries("*.jar").first())
|
||||
}
|
||||
else {
|
||||
classpath.add(it.toFile())
|
||||
classpath.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addMavenLibs(classpath: MutableList<File>, mavenHome: File) {
|
||||
addDir(classpath, File(mavenHome, "lib"))
|
||||
val bootFolder = File(mavenHome, "boot")
|
||||
val classworldsJars = bootFolder.listFiles { dir: File?, name: String? ->
|
||||
StringUtil.contains(
|
||||
name!!, "classworlds")
|
||||
}
|
||||
if (classworldsJars != null) {
|
||||
Collections.addAll(classpath, *classworldsJars)
|
||||
}
|
||||
private fun addMavenLibs(classpath: MutableList<Path>, mavenHome: Path) {
|
||||
addDir(classpath, mavenHome.resolve("lib"))
|
||||
val bootFolder = mavenHome.resolve("boot")
|
||||
classpath.addAll(bootFolder.listDirectoryEntries("*classworlds*.jar"))
|
||||
}
|
||||
|
||||
private fun addDir(classpath: MutableList<File>, dir: File) {
|
||||
val files = dir.listFiles()
|
||||
if (files == null) return
|
||||
|
||||
for (jar in files) {
|
||||
if (jar.isFile && jar.name.endsWith(".jar")) {
|
||||
classpath.add(jar)
|
||||
}
|
||||
private fun addDir(classpath: MutableList<Path>, dir: Path) {
|
||||
dir.listDirectoryEntries("*.jar").forEach {
|
||||
classpath.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user