Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use filesToProcess to construct the graph #1297

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 101 additions & 86 deletions packages/nx-maven/src/graph/create-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import {
RawProjectGraphDependency,
joinPathFragments,
validateDependency,
workspaceRoot,
} from '@nx/devkit';
import * as path from 'path';
import { getPlugin, getSkipAggregatorProjectLinkingOption } from '../utils';
import {
MavenProjectType,
WorkspaceDataType,
getCachedWorkspaceData,
getProject,
removeWorkspaceDataCache,
} from './graph-utils';
import { getPlugin, getSkipAggregatorProjectLinkingOption } from '../utils';

export const createDependencies: CreateDependencies = (
_,
Expand All @@ -30,91 +29,107 @@ export const createDependencies: CreateDependencies = (
const skipAggregatorProjectLinkingOption =
getSkipAggregatorProjectLinkingOption(plugin);

for (const project of projects) {
if (project.skipProject) {
continue;
}

const projectRoot = path.relative(
workspaceRoot,
project.projectAbsolutePath,
);

const projectSourceFile = joinPathFragments(projectRoot, 'pom.xml');

if (project.parentProjectArtifactId) {
const parentProject = getProject(
projects,
project.parentProjectArtifactId,
);

if (!parentProject.skipProject) {
const newDependency = {
source: project.artifactId,
target: parentProject.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}

if (skipAggregatorProjectLinkingOption === false) {
if (
project.aggregatorProjectArtifactId &&
project.aggregatorProjectArtifactId !== project.parentProjectArtifactId
) {
const aggregatorProject = getProject(
projects,
project.aggregatorProjectArtifactId,
);

if (!aggregatorProject.skipProject) {
const newDependency = {
source: project.artifactId,
target: aggregatorProject.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
Object.keys(context.filesToProcess.projectFileMap).forEach((source) => {
Object.values(context.filesToProcess.projectFileMap[source]).forEach(
(fileData) => {
const filePath = fileData.file;
if (path.basename(filePath) === 'pom.xml') {
const project = projects.find(
(element) =>
joinPathFragments(element.projectRoot, 'pom.xml') === filePath,
);

if (!project) {
throw new Error(`Can't find project for file: ${filePath}`);
}

if (!project.skipProject) {
const projectSourceFile = joinPathFragments(
project.projectRoot,
'pom.xml',
);

if (project.parentProjectArtifactId) {
const parentProject = getProject(
projects,
project.parentProjectArtifactId,
);

if (!parentProject.skipProject) {
const newDependency = {
source: project.artifactId,
target: parentProject.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}

if (skipAggregatorProjectLinkingOption === false) {
if (
project.aggregatorProjectArtifactId &&
project.aggregatorProjectArtifactId !==
project.parentProjectArtifactId
) {
const aggregatorProject = getProject(
projects,
project.aggregatorProjectArtifactId,
);

if (!aggregatorProject.skipProject) {
const newDependency = {
source: project.artifactId,
target: aggregatorProject.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}
}

const dependencies = getDependencyProjects(project, projects);
for (const dependency of dependencies) {
if (!dependency.skipProject) {
const newDependency = {
source: project.artifactId,
target: dependency.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}

const profileDependencies = getProfileDependencyProjects(
project,
projects,
);
for (const profileDependency of profileDependencies) {
if (!profileDependency.skipProject) {
const newDependency = {
source: project.artifactId,
target: profileDependency.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}
}
}
}
}

const dependencies = getDependencyProjects(project, projects);
for (const dependency of dependencies) {
if (!dependency.skipProject) {
const newDependency = {
source: project.artifactId,
target: dependency.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}

const profileDependencies = getProfileDependencyProjects(project, projects);
for (const profileDependency of profileDependencies) {
if (!profileDependency.skipProject) {
const newDependency = {
source: project.artifactId,
target: profileDependency.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}
}
},
);
});

// Remove cached data
removeWorkspaceDataCache();
Expand Down
Loading