Skip to content

Commit

Permalink
build: work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
khalilou88 committed Oct 10, 2024
1 parent f56dcc1 commit e180f03
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 60 deletions.
9 changes: 5 additions & 4 deletions packages/nx-maven/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
addMissedProperties,
addProjectToAggregator,
extractRootPomValues,
getAggregatorProjectName,
getAggregatorProjectRoot,
getMavenRootDirectory,
getParentProjectValues,
getPlugin,
Expand Down Expand Up @@ -72,6 +72,7 @@ interface NormalizedSchema extends NxMavenAppGeneratorSchema {
serveTargetName: string;
testTargetName: string;
integrationTestTargetName: string;
aggregatorProjectRoot: string;
}

function normalizeOptions(
Expand Down Expand Up @@ -134,7 +135,7 @@ function normalizeOptions(
const testTargetName = getTestTargetName(plugin);
const integrationTestTargetName = getIntegrationTestTargetName(plugin);

const aggregatorProject = getAggregatorProjectName(
const aggregatorProjectRoot = getAggregatorProjectRoot(
tree,
options.aggregatorProject,
mavenRootDirectory,
Expand Down Expand Up @@ -165,7 +166,7 @@ function normalizeOptions(
serveTargetName,
testTargetName,
integrationTestTargetName,
aggregatorProject,
aggregatorProjectRoot,
};
}

Expand Down Expand Up @@ -494,7 +495,7 @@ async function applicationGenerator(
addFiles(tree, normalizedOptions);
addProjectToAggregator(tree, {
projectRoot: normalizedOptions.projectRoot,
aggregatorProject: normalizedOptions.aggregatorProject,
aggregatorProjectRoot: normalizedOptions.aggregatorProjectRoot,
mavenRootDirectory: normalizedOptions.mavenRootDirectory,
});
if (!options.skipFormat) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-maven/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface NxMavenAppGeneratorSchema {
packaging: PackagingType;
configFormat: '.properties' | '.yml';
parentProject: string;
aggregatorProject: string;
aggregatorProject?: string;
minimal?: boolean;
port?: string | number;
framework?: FrameworkType;
Expand Down
9 changes: 5 additions & 4 deletions packages/nx-maven/src/generators/library/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
addLibraryToProjects,
addMissedProperties,
addProjectToAggregator,
getAggregatorProjectName,
getAggregatorProjectRoot,
getMavenRootDirectory,
getParentProjectValues,
getPlugin,
Expand Down Expand Up @@ -59,6 +59,7 @@ interface NormalizedSchema extends NxMavenLibGeneratorSchema {
mavenRootDirectory: string;
buildTargetName: string;
testTargetName: string;
aggregatorProjectRoot: string;
}

function normalizeOptions(
Expand Down Expand Up @@ -106,7 +107,7 @@ function normalizeOptions(
const buildTargetName = getBuildTargetName(plugin);
const testTargetName = getTestTargetName(plugin);

const aggregatorProject = getAggregatorProjectName(
const aggregatorProjectRoot = getAggregatorProjectRoot(
tree,
options.aggregatorProject,
mavenRootDirectory,
Expand All @@ -131,7 +132,7 @@ function normalizeOptions(
mavenRootDirectory,
buildTargetName,
testTargetName,
aggregatorProject,
aggregatorProjectRoot,
};
}

Expand Down Expand Up @@ -344,7 +345,7 @@ async function libraryGenerator(
addFiles(tree, normalizedOptions);
addProjectToAggregator(tree, {
projectRoot: normalizedOptions.projectRoot,
aggregatorProject: normalizedOptions.aggregatorProject,
aggregatorProjectRoot: normalizedOptions.aggregatorProjectRoot,
mavenRootDirectory: normalizedOptions.mavenRootDirectory,
});
addLibraryToProjects(tree, normalizedOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-maven/src/generators/library/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface NxMavenLibGeneratorSchema {
groupId: string;
projectVersion: string;
parentProject: string;
aggregatorProject: string;
aggregatorProject?: string;
projects?: string;
skipStarterCode?: boolean;
framework?: FrameworkType;
Expand Down
13 changes: 7 additions & 6 deletions packages/nx-maven/src/generators/parent-project/generator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
parseTags,
generateProjectDirectory,
generateProjectName,
generateProjectRoot,
generateSimpleProjectName,
getBuildTargetName,
kotlinVersion,
mavenCompilerPluginVersion,
mavenEnforcerPluginVersion,
Expand All @@ -16,9 +16,9 @@ import {
micronautSerializationVersion,
micronautTestResourcesVersion,
micronautVersion,
parseTags,
quarkusVersion,
springBootVersion,
getBuildTargetName,
} from '@jnxplus/common';
import {
Tree,
Expand All @@ -32,7 +32,7 @@ import * as path from 'path';
import {
addMissedProperties,
addProjectToAggregator,
getAggregatorProjectName,
getAggregatorProjectRoot,
getMavenRootDirectory,
getParentProjectValues,
getPlugin,
Expand Down Expand Up @@ -70,6 +70,7 @@ interface NormalizedSchema extends NxMavenParentProjectGeneratorSchema {
mavenSurefirePluginVersion: string;
mavenFailsafePluginVersion: string;
buildTargetName: string;
aggregatorProjectRoot: string;
}

function normalizeOptions(
Expand Down Expand Up @@ -107,7 +108,7 @@ function normalizeOptions(
const plugin = getPlugin();
const buildTargetName = getBuildTargetName(plugin);

const aggregatorProject = getAggregatorProjectName(
const aggregatorProjectRoot = getAggregatorProjectRoot(
tree,
options.aggregatorProject,
mavenRootDirectory,
Expand Down Expand Up @@ -138,7 +139,7 @@ function normalizeOptions(
mavenSurefirePluginVersion,
mavenFailsafePluginVersion,
buildTargetName,
aggregatorProject,
aggregatorProjectRoot,
};
}

Expand Down Expand Up @@ -196,7 +197,7 @@ async function parentProjectGenerator(
addFiles(tree, normalizedOptions);
addProjectToAggregator(tree, {
projectRoot: normalizedOptions.projectRoot,
aggregatorProject: normalizedOptions.aggregatorProject,
aggregatorProjectRoot: normalizedOptions.aggregatorProjectRoot,
mavenRootDirectory: normalizedOptions.mavenRootDirectory,
});
if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface NxMavenParentProjectGeneratorSchema {
groupId: string;
projectVersion?: string;
parentProject: string;
aggregatorProject: string;
aggregatorProject?: string;
framework?: FrameworkType;
language: 'java' | 'kotlin' | 'java-kotlin';
skipFormat?: boolean;
Expand Down
66 changes: 23 additions & 43 deletions packages/nx-maven/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,30 @@ function getProjectRootFromTree(
tree: Tree,
mavenRootDirectory: string,
projectName: string,
) {
): string {
let projectRoot = '';

if (!projectName) {
throw new Error('ProjectName cannot be empty');
}

try {
projectRoot = readProjectConfiguration(tree, projectName).root;
return projectRoot;
} catch (err) {
logger.warn(err);
}

logger.warn(`Here ${projectRoot}`);

if (projectRoot) {
return projectRoot;
}

const mavenRootDirAbsolutePath = path.join(workspaceRoot, mavenRootDirectory);

const projectBasedir = getExpressionValue(
'project.basedir',
mavenRootDirAbsolutePath,
projectName,
);

logger.warn(`Here 99 ${projectBasedir}`);
const mavenRootDirAbsolutePath = path.join(
workspaceRoot,
mavenRootDirectory,
);

projectRoot = path.relative(workspaceRoot, projectBasedir);
const projectBasedir = getExpressionValue(
'project.basedir',
mavenRootDirAbsolutePath,
projectName,
);

logger.warn(`Here 22 ${projectRoot}`);
projectRoot = path.relative(workspaceRoot, projectBasedir);

if (!projectRoot) {
throw new Error('ProjectRoot cannot be empty');
return projectRoot;
}

return projectRoot;
}

export function getExpressionValue(
Expand Down Expand Up @@ -181,21 +167,19 @@ export function addProjectToAggregator(
tree: Tree,
options: {
projectRoot: string;
aggregatorProject: string;
aggregatorProjectRoot: string;
mavenRootDirectory: string;
},
) {
const aggregatorProjectRoot = getProjectRootFromTree(
tree,
options.mavenRootDirectory,
options.aggregatorProject,
const parentProjectPomPath = path.join(
options.aggregatorProjectRoot,
'pom.xml',
);
const parentProjectPomPath = path.join(aggregatorProjectRoot, 'pom.xml');
const xmlDoc = readXmlTree(tree, parentProjectPomPath);

const aggregatorProjectAbsolutPath = path.join(
workspaceRoot,
aggregatorProjectRoot,
options.aggregatorProjectRoot,
);
const projectAbsolutePath = path.join(workspaceRoot, options.projectRoot);

Expand Down Expand Up @@ -604,18 +588,14 @@ export function getSkipAggregatorProjectLinkingOption(
return false;
}

export function getAggregatorProjectName(
export function getAggregatorProjectRoot(
tree: Tree,
aggregatorProject: string,
aggregatorProject: string | undefined,
mavenRootDirectory: string,
) {
if (!aggregatorProject) {
const xmlDoc = readXmlTree(
tree,
joinPathFragments(mavenRootDirectory, 'pom.xml'),
);

return getArtifactId(xmlDoc);
return mavenRootDirectory;
}
return aggregatorProject;

return getProjectRootFromTree(tree, mavenRootDirectory, aggregatorProject);
}

0 comments on commit e180f03

Please sign in to comment.