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
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ protected final Repository gitRepository() {
return gitRepository;
}

/**
* The POM the project was built from. Another plugin may set the project file to a POM it
* generated, such as a flattened one, but leaves the POM file of the model.
*/
protected final Path pomFile() {
return currentProject.getFile().toPath();
return currentProject.getModel().getPomFile().toPath();
}

protected final Path baseDir() {
Expand Down
43 changes: 43 additions & 0 deletions core/src/test/java/com/cosium/code/format/FlattenedPomTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.cosium.code.format;

import static org.assertj.core.api.Assertions.assertThat;

import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenPluginTest;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import org.junit.jupiter.api.DisplayName;

/**
* flatten-maven-plugin swaps the project file for the flattened POM, and maven-source-plugin forks
* the lifecycle, running the hooks installation again after that swap.
*
* @author Réda Housni Alaoui
*/
@MavenVersions({"3.5.0"})
public class FlattenedPomTest extends AbstractTest {

public FlattenedPomTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Exception {
super(mavenBuilder, "flattened-pom");
}

@MavenPluginTest
@DisplayName(
"GIVEN a flattened POM set as project file WHEN a forked lifecycle installs the hooks THEN"
+ " the hook runs the original POM")
public void test1() throws Exception {
buildMavenExecution(projectRoot()).execute("package").assertErrorFreeLog();

Path hook =
jGit()
.getRepository()
.getDirectory()
.toPath()
.resolve("hooks")
.resolve("flattened-pom.git-code-format.pre-commit.sh");
assertThat(hook)
.content(StandardCharsets.UTF_8)
.contains("-f \"$(git rev-parse --show-toplevel)/pom.xml\"");
}
}
8 changes: 8 additions & 0 deletions core/src/test/projects/flattened-pom/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>io.takari.m2e.workspace</groupId>
<artifactId>org.eclipse.m2e.workspace.cli</artifactId>
<version>0.4.0</version>
</extension>
</extensions>
54 changes: 54 additions & 0 deletions core/src/test/projects/flattened-pom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.cosium.code.format.test</groupId>
<artifactId>flattened-pom</artifactId>
<version>1.00-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>${it-project.version}</version>
<executions>
<execution>
<goals>
<goal>install-hooks</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.4.1</version>
<configuration>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading