Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/maven/maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>dev.nx</groupId>
<artifactId>nx-parent</artifactId>
<version>0.0.7</version>
<version>0.0.8</version>
<relativePath>../../../pom.xml</relativePath>
</parent>

Expand Down
11 changes: 11 additions & 0 deletions packages/maven/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../node_modules/nx/schemas/generators-schema.json",
"generators": {
"update-0.0.8": {
"cli": "nx",
"version": "0.0.8-beta.0",
"description": "Update Maven plugin version from 0.0.7 to 0.0.8 in pom.xml files",
"factory": "./dist/migrations/0-0-8/update-pom-xml-version"
}
}
}
2 changes: 1 addition & 1 deletion packages/maven/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx/maven",
"version": "0.0.1",
"version": "0.0.8",
"private": false,
"description": "Nx plugin for Maven integration",
"repository": {
Expand Down
10 changes: 10 additions & 0 deletions packages/maven/src/migrations/0-0-8/update-pom-xml-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Tree } from '@nx/devkit';
import { updateNxMavenPluginVersion } from '../../utils/pom-xml-updater';

/**
* Migration for @nx/maven v0.0.8
* Updates the Maven plugin version from 0.0.7 to 0.0.8 in user pom.xml files
*/
export default async function update(tree: Tree) {
updateNxMavenPluginVersion(tree, '0.0.8');
}
113 changes: 113 additions & 0 deletions packages/maven/src/utils/__snapshots__/pom-xml-updater.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`pom-xml-updater updateNxMavenPluginVersion should correctly identify nx-maven-plugin with whitespace 1`] = `
"<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>
dev.nx.maven
</groupId>
<artifactId>
nx-maven-plugin
</artifactId>
<version>0.0.8</version>
</plugin>
</plugins>
</build>
</project>"
`;

exports[`pom-xml-updater updateNxMavenPluginVersion should handle pom.xml with dependencies and other version elements 1`] = `
"<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.8</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>
</project>"
`;

exports[`pom-xml-updater updateNxMavenPluginVersion should not update other plugin versions 1`] = `
"<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>0.0.7</version>
</plugin>
</plugins>
</build>
</project>"
`;

exports[`pom-xml-updater updateNxMavenPluginVersion should only update plugins, not parent version 1`] = `
"<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent>
<groupId>dev.nx</groupId>
<artifactId>nx-parent</artifactId>
<version>0.0.7</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.8</version>
</plugin>
</plugins>
</build>
</project>"
`;

exports[`pom-xml-updater updateNxMavenPluginVersion should preserve XML formatting and structure 1`] = `
"<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.8</version>
</plugin>
</plugins>
</build>
</project>"
`;

exports[`pom-xml-updater updateNxMavenPluginVersion should update the nx-maven-plugin version only 1`] = `
"<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.8</version>
</plugin>
</plugins>
</build>
</project>"
`;
221 changes: 221 additions & 0 deletions packages/maven/src/utils/pom-xml-updater.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import { Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { updateNxMavenPluginVersion } from './pom-xml-updater';

describe('pom-xml-updater', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace({});
});

describe('updateNxMavenPluginVersion', () => {
it('should update the nx-maven-plugin version only', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.7</version>
</plugin>
</plugins>
</build>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toMatchSnapshot();
});

it('should not update other plugin versions', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>0.0.7</version>
</plugin>
</plugins>
</build>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toMatchSnapshot();
});

it('should not modify pom.xml if file does not exist', () => {
// Act & Assert - should not throw
expect(() => {
updateNxMavenPluginVersion(tree, '0.0.8');
}).not.toThrow();
});

it('should preserve XML formatting and structure', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.7</version>
</plugin>
</plugins>
</build>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toMatchSnapshot();
});

it('should not update if version is already the target version', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.8</version>
</plugin>
</plugins>
</build>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toEqual(pomContent);
});

it('should handle pom.xml with dependencies and other version elements', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.7</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toMatchSnapshot();
});

it('should correctly identify nx-maven-plugin with whitespace', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<build>
<plugins>
<plugin>
<groupId>
dev.nx.maven
</groupId>
<artifactId>
nx-maven-plugin
</artifactId>
<version>
0.0.7
</version>
</plugin>
</plugins>
</build>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toMatchSnapshot();
});

it('should only update plugins, not parent version', () => {
// Arrange
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent>
<groupId>dev.nx</groupId>
<artifactId>nx-parent</artifactId>
<version>0.0.7</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>dev.nx.maven</groupId>
<artifactId>nx-maven-plugin</artifactId>
<version>0.0.7</version>
</plugin>
</plugins>
</build>
</project>`;

tree.write('pom.xml', pomContent);

// Act
updateNxMavenPluginVersion(tree, '0.0.8');

// Assert
const updatedContent = tree.read('pom.xml', 'utf-8');
expect(updatedContent).toMatchSnapshot();
});
});
});
Loading
Loading