дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-18 15:46:14 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
4828d518e0 |
No files matched your search
@@ -1241,10 +1241,13 @@ fn file_stamp(path: &Path) -> FileStamp {
|
||||
std::fs::metadata(path).ok().map(|m| (m.modified().ok(), m.len()))
|
||||
}
|
||||
|
||||
/// The POM files a reactor walk read or looked for, and the module folders it found outside the root.
|
||||
/// The POM files a reactor walk read or looked for, the module folders it found outside the
|
||||
/// root, and the folders of every project in the reactor (canonical, the root's first).
|
||||
#[derive(Clone)]
|
||||
struct ReactorScan {
|
||||
stamps: Vec<(PathBuf, FileStamp)>,
|
||||
dirs: Vec<PathBuf>,
|
||||
members: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
/// Folders of the modules that the reactor of `root/pom.xml` lists outside `root`
|
||||
@@ -1254,18 +1257,28 @@ struct ReactorScan {
|
||||
/// Callers keep the outermost directory only. Memoized on the POMs' modification times and
|
||||
/// sizes: content roots are read on hot paths (every references search, Find in Files).
|
||||
pub fn reactor_external_dirs(root: &Path, profiles: &[String], unlinked: &[String]) -> Vec<PathBuf> {
|
||||
reactor(root, profiles, unlinked).dirs
|
||||
}
|
||||
|
||||
/// Folders of every project in the reactor of `root/pom.xml` (canonical): `root` itself and its
|
||||
/// modules, theirs in turn, including those of the active `profiles`. A POM elsewhere below `root`
|
||||
/// that no `<module>` reaches is a separate build.
|
||||
pub fn reactor_member_dirs(root: &Path, profiles: &[String]) -> Vec<PathBuf> {
|
||||
reactor(root, profiles, &[]).members
|
||||
}
|
||||
|
||||
fn reactor(root: &Path, profiles: &[String], unlinked: &[String]) -> ReactorScan {
|
||||
type Memo = HashMap<(PathBuf, Vec<String>, Vec<String>), ReactorScan>;
|
||||
static MEMO: std::sync::LazyLock<Mutex<Memo>> = std::sync::LazyLock::new(Default::default);
|
||||
let key = (root.to_path_buf(), profiles.to_vec(), unlinked.to_vec());
|
||||
if let Some(scan) = MEMO.lock().unwrap_or_else(|e| e.into_inner()).get(&key)
|
||||
&& scan.stamps.iter().all(|(path, stamp)| file_stamp(path) == *stamp)
|
||||
{
|
||||
return scan.dirs.clone();
|
||||
return scan.clone();
|
||||
}
|
||||
let scan = scan_reactor(root, profiles, unlinked);
|
||||
let dirs = scan.dirs.clone();
|
||||
MEMO.lock().unwrap_or_else(|e| e.into_inner()).insert(key, scan);
|
||||
dirs
|
||||
MEMO.lock().unwrap_or_else(|e| e.into_inner()).insert(key, scan.clone());
|
||||
scan
|
||||
}
|
||||
|
||||
/// Reads only the POMs the reactor lists (no parent resolution and no directory walk).
|
||||
@@ -1274,7 +1287,8 @@ fn scan_reactor(root: &Path, profiles: &[String], unlinked: &[String]) -> Reacto
|
||||
let chosen = Resolver::new(None, profiles);
|
||||
let unlinked: HashSet<String> = unlinked.iter().map(|p| normalized_pom(p.trim())).collect();
|
||||
let first = root.join("pom.xml");
|
||||
let mut scan = ReactorScan { stamps: vec![(first.clone(), file_stamp(&first))], dirs: Vec::new() };
|
||||
let mut scan =
|
||||
ReactorScan { stamps: vec![(first.clone(), file_stamp(&first))], dirs: Vec::new(), members: Vec::new() };
|
||||
let mut seen: HashSet<PathBuf> = HashSet::new();
|
||||
let mut pending = vec![first];
|
||||
while let Some(path) = pending.pop() {
|
||||
@@ -1288,6 +1302,7 @@ fn scan_reactor(root: &Path, profiles: &[String], unlinked: &[String]) -> Reacto
|
||||
let Some(pom) = xml::read_text(&path).as_deref().and_then(parse_pom) else { continue };
|
||||
let dir = path.parent().unwrap_or(root).to_path_buf();
|
||||
let dir_canon = dunce::canonicalize(&dir).unwrap_or_else(|_| dir.clone());
|
||||
scan.members.push(dir_canon.clone());
|
||||
if !dir_canon.starts_with(&canonical_root) {
|
||||
if canonical_root.starts_with(&dir_canon) {
|
||||
continue;
|
||||
|
||||
@@ -108,27 +108,53 @@ fn detected_and_saved(
|
||||
}
|
||||
|
||||
/// Folders of the Maven / Gradle builds linked explicitly (Add Maven Projects, linked Gradle
|
||||
/// builds) that detection did not reach: deeper than its folder search and outside the builds
|
||||
/// it found, which own their nested folders.
|
||||
/// builds) that detection did not reach: deeper than its folder search, or inside the folder of
|
||||
/// a build it found without being one of that build's projects (a separate build nested there).
|
||||
fn linked_build_dirs(
|
||||
root: &Path,
|
||||
settings: &ide_core::settings::Settings,
|
||||
gradle: Option<&[ide_build::GradleModel]>,
|
||||
detected: &[RunConfig],
|
||||
) -> Vec<std::path::PathBuf> {
|
||||
let found: Vec<_> = detected
|
||||
.iter()
|
||||
.filter(|c| matches!(c.kind.as_str(), "maven" | "gradle"))
|
||||
.map(|c| ide_core::project_roots::resolve(root, c.cwd.as_deref().unwrap_or(Path::new(""))))
|
||||
.collect();
|
||||
let found = |kind: &str| -> Vec<std::path::PathBuf> {
|
||||
let mut dirs: Vec<_> = detected
|
||||
.iter()
|
||||
.filter(|c| c.kind == kind)
|
||||
.map(|c| ide_core::project_roots::resolve(root, c.cwd.as_deref().unwrap_or(Path::new(""))))
|
||||
.collect();
|
||||
dirs.dedup();
|
||||
dirs
|
||||
};
|
||||
let canonical = |dir: &Path| dunce::canonicalize(dir).unwrap_or_else(|_| dir.to_path_buf());
|
||||
let profiles = settings.languages.java.maven.profiles(&[]);
|
||||
let maven_builds = found("maven");
|
||||
let poms = settings.languages.java.maven.linked_projects.iter().filter_map(|pom| {
|
||||
let pom = root.join(pom.trim());
|
||||
pom.is_file().then(|| pom.parent().map(Path::to_path_buf)).flatten()
|
||||
});
|
||||
poms.chain(gradle.unwrap_or_default().iter().map(|build| root.join(&build.dir)))
|
||||
.map(|dir| ide_core::project_roots::resolve(root, &dir))
|
||||
.filter(|dir| !found.iter().any(|build| dir.starts_with(build)))
|
||||
.collect()
|
||||
let maven = poms.map(|dir| ide_core::project_roots::resolve(root, &dir)).filter(|dir| {
|
||||
let dir_canon = canonical(dir);
|
||||
!maven_builds.iter().any(|build| {
|
||||
dir.starts_with(build) && ide_build::maven::reactor_member_dirs(build, &profiles).contains(&dir_canon)
|
||||
})
|
||||
});
|
||||
let models = gradle.unwrap_or_default();
|
||||
let gradle_builds = found("gradle");
|
||||
let gradle =
|
||||
models.iter().map(|build| ide_core::project_roots::resolve(root, &root.join(&build.dir))).filter(|dir| {
|
||||
!gradle_builds.iter().any(|build| {
|
||||
dir == build
|
||||
|| (dir.starts_with(build)
|
||||
&& models.iter().filter(|m| root.join(&m.dir) == *build).any(|m| {
|
||||
m.projects
|
||||
.iter()
|
||||
.any(|p| ide_core::project_roots::resolve(root, &root.join(&p.dir)) == *dir)
|
||||
}))
|
||||
})
|
||||
});
|
||||
let mut dirs: Vec<_> = maven.chain(gradle).collect();
|
||||
dirs.dedup();
|
||||
dirs
|
||||
}
|
||||
|
||||
fn linked_config(
|
||||
@@ -672,11 +698,59 @@ mod ownership_tests {
|
||||
),
|
||||
(
|
||||
"linked module inside the root reactor belongs to the reactor",
|
||||
vec![("pom.xml".into(), "<project></project>"), (format!("{deep}/pom.xml"), BOOT_POM)],
|
||||
vec![
|
||||
(
|
||||
"pom.xml".into(),
|
||||
"<project><modules><module>site/service/03_src/demo-monitor</module></modules></project>",
|
||||
),
|
||||
(format!("{deep}/pom.xml"), BOOT_POM),
|
||||
],
|
||||
vec!["site/service/03_src/demo-monitor/pom.xml"],
|
||||
None,
|
||||
vec!["maven:package".into(), "maven:test".into()],
|
||||
),
|
||||
(
|
||||
"a separate Maven build linked inside the root build's folder has its own configurations",
|
||||
vec![("pom.xml".into(), "<project></project>"), (format!("{deep}/pom.xml"), BOOT_POM)],
|
||||
vec!["site/service/03_src/demo-monitor/pom.xml"],
|
||||
None,
|
||||
vec![
|
||||
"maven:package".into(),
|
||||
"maven:test".into(),
|
||||
format!("maven:package:{deep}"),
|
||||
format!("maven:test:{deep}"),
|
||||
format!("maven:spring-boot:run:{deep}"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"a Gradle subproject linked as a build belongs to the root build",
|
||||
vec![
|
||||
("settings.gradle.kts".into(), "rootProject.name = \"root\"\ninclude(\"a:b:c:tool\")\n"),
|
||||
("build.gradle.kts".into(), "plugins {\n java\n}"),
|
||||
(format!("{tool}/build.gradle.kts"), "plugins {\n application\n}"),
|
||||
],
|
||||
vec![],
|
||||
Some(vec![".", tool]),
|
||||
vec!["gradle:build".into(), "gradle:test".into()],
|
||||
),
|
||||
(
|
||||
"a separate Gradle build linked inside the root build's folder has its own configurations",
|
||||
vec![
|
||||
("settings.gradle.kts".into(), "rootProject.name = \"root\"\n"),
|
||||
("build.gradle.kts".into(), "plugins {\n java\n}"),
|
||||
(format!("{tool}/settings.gradle.kts"), "rootProject.name = \"tool\"\n"),
|
||||
(format!("{tool}/build.gradle.kts"), "plugins {\n application\n}"),
|
||||
],
|
||||
vec![],
|
||||
Some(vec![".", tool]),
|
||||
vec![
|
||||
"gradle:build".into(),
|
||||
"gradle:test".into(),
|
||||
format!("gradle:build:{tool}"),
|
||||
format!("gradle:test:{tool}"),
|
||||
format!("gradle:run:{tool}"),
|
||||
],
|
||||
),
|
||||
(
|
||||
"linked module within the search depth is not detected twice",
|
||||
vec![("svc/pom.xml".into(), "<project></project>")],
|
||||
|
||||
Reference in new issue
Заблокувати користувача