forked from mojohaus/flatten-maven-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for keeping comments in .flattened-pom.xml mojohaus#269
- Loading branch information
1 parent
cb92e97
commit b30e8e6
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/test/java/org/codehaus/mojo/flatten/KeepCommentsInPomTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.codehaus.mojo.flatten; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.configuration.DefaultPlexusConfiguration; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test-Case for {@link FlattenMojo}. | ||
* | ||
*/ | ||
public class KeepCommentsInPomTest { | ||
|
||
private static final String PATH = "src/test/resources/keep-comments-in-pom/"; | ||
private static final String TEST_TARGET_PATH = "target/test/resources/keep-comments-in-pom/"; | ||
private static final String FLATTENED_POM = TEST_TARGET_PATH + ".flattened-pom.xml"; | ||
private static final String EXPECTED_FLATTENED_POM = PATH + "expected-flattened-pom.xml"; | ||
|
||
@Rule | ||
public MojoRule rule = new MojoRule(); | ||
|
||
@Before | ||
public void setup() { | ||
new File(TEST_TARGET_PATH).mkdirs(); | ||
} | ||
/** | ||
* Test method to check that profile activation file is not interpolated. | ||
* | ||
* @throws Exception if something goes wrong. | ||
*/ | ||
@Test | ||
public void keepsProfileActivationFile() throws Exception { | ||
MavenProject project = rule.readMavenProject( new File( PATH ) ); | ||
FlattenMojo flattenMojo = (FlattenMojo) rule.lookupConfiguredMojo( project, "flatten" ); | ||
|
||
DefaultPlexusConfiguration tempPluginConfiguration = new DefaultPlexusConfiguration("test"); | ||
tempPluginConfiguration.addChild("outputDirectory", TEST_TARGET_PATH); | ||
rule.configureMojo(flattenMojo, tempPluginConfiguration); | ||
|
||
// execute writes new FLATTENED_POM | ||
flattenMojo.execute(); | ||
|
||
String tempExpectedContent = getContent(EXPECTED_FLATTENED_POM); | ||
String tempActualContent = getContent(FLATTENED_POM); | ||
assertEquals("Expected POM does not match, see "+FLATTENED_POM, tempExpectedContent,tempActualContent); | ||
|
||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private String getContent(String aPomFile) throws IOException { | ||
String tempString; | ||
try (InputStream tempIn = new FileInputStream(aPomFile)) { | ||
tempString = IOUtils.toString(tempIn); | ||
} | ||
// remove platform dependent CR/LF | ||
tempString = tempString.replaceAll("\r\n", "\n"); | ||
return tempString; | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/resources/keep-comments-in-pom/expected-flattened-pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.codehaus.mojo.flatten.its</groupId> | ||
<artifactId>resolve-properties-ci-do-not-interpolate-profile-activation-file</artifactId> | ||
<version>1.2.3.4</version> | ||
<properties> | ||
<!-- some nice comment --> | ||
<revision>1.2.3.4</revision> | ||
</properties> | ||
<build> | ||
<defaultGoal>verify</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>flatten-maven-plugin</artifactId> | ||
<configuration> | ||
<flattenMode>resolveCiFriendliesOnly</flattenMode> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<!-- another comment what the profile is doing --> | ||
<activation> | ||
<file> | ||
<exists>file.txt</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<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>org.codehaus.mojo.flatten.its</groupId> | ||
<artifactId>resolve-properties-ci-do-not-interpolate-profile-activation-file</artifactId> | ||
<version>${revision}</version> | ||
|
||
<properties> | ||
<!-- some nice comment --> | ||
<revision>1.2.3.4</revision> | ||
</properties> | ||
|
||
<build> | ||
<defaultGoal>verify</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>flatten-maven-plugin</artifactId> | ||
<configuration> | ||
<flattenMode>resolveCiFriendliesOnly</flattenMode> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<!-- another comment what the profile is doing --> | ||
<activation> | ||
<file> | ||
<exists>file.txt</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
</project> |