-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from dehasi/ISSUE-57-prevent-resolving-system…
…-properties #57 Prevent interpolation of a profile activation file
- Loading branch information
Showing
7 changed files
with
244 additions
and
4 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
...jects/resolve-properties-ci-do-not-interpolate-profile-activation-file/invoker.properties
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 @@ | ||
invoker.mavenOpts = -Drevision=1.2.3.4 -Dany.property |
56 changes: 56 additions & 0 deletions
56
src/it/projects/resolve-properties-ci-do-not-interpolate-profile-activation-file/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,56 @@ | ||
<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> | ||
|
||
<!-- banned --> | ||
<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> | ||
<id>0</id> | ||
<activation> | ||
<file> | ||
<exists>file.txt</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
<profile> | ||
<id>1</id> | ||
<activation> | ||
<file> | ||
<exists>${basedir}/file.txt</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
<profile> | ||
<id>2</id> | ||
<activation> | ||
<file> | ||
<exists>${any.property}</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
<profile> | ||
<id>3</id> | ||
<activation> | ||
<file> | ||
<exists>${revision}</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
...t/projects/resolve-properties-ci-do-not-interpolate-profile-activation-file/verify.groovy
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 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
File originalPom = new File( basedir, 'pom.xml' ) | ||
assert originalPom.exists() | ||
|
||
def originalProject = new XmlSlurper().parse( originalPom ) | ||
assert 'file.txt' == originalProject.profiles.profile[0].activation.file.exists.text() | ||
assert '${basedir}/file.txt' == originalProject.profiles.profile[1].activation.file.exists.text() | ||
assert '${any.property}' == originalProject.profiles.profile[2].activation.file.exists.text() | ||
assert '${revision}' == originalProject.profiles.profile[3].activation.file.exists.text() | ||
|
||
File flattenedPom = new File( basedir, '.flattened-pom.xml' ) | ||
assert flattenedPom.exists() | ||
def flattenedProject = new XmlSlurper().parse( flattenedPom ) | ||
|
||
assert 'file.txt' == flattenedProject.profiles.profile[0].activation.file.exists.text() | ||
assert '${basedir}/file.txt' == flattenedProject.profiles.profile[1].activation.file.exists.text() | ||
assert '${any.property}' == flattenedProject.profiles.profile[2].activation.file.exists.text() | ||
assert '1.2.3.4' == flattenedProject.profiles.profile[3].activation.file.exists.text() |
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
90 changes: 90 additions & 0 deletions
90
src/test/java/org/codehaus/mojo/flatten/FlattenMojoTest.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,90 @@ | ||
package org.codehaus.mojo.flatten; | ||
|
||
/* | ||
* 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 org.apache.maven.model.Model; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Test-Case for {@link FlattenMojo}. | ||
* | ||
* @author dehasi | ||
*/ | ||
public class FlattenMojoTest { | ||
|
||
private static final String PATH = "src/test/resources/resolve-properties-ci-do-not-interpolate-profile-activation-file/"; | ||
private static final String POM = PATH + "pom.xml"; | ||
private static final String FLATTENED_POM = PATH + ".flattened-pom.xml"; | ||
|
||
@Rule | ||
public MojoRule rule = new MojoRule(); | ||
|
||
/** | ||
* 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" ); | ||
|
||
flattenMojo.execute(); | ||
|
||
assertThat( profileActivationFile( FLATTENED_POM ) ) | ||
.isEqualTo( profileActivationFile( POM ) ); | ||
} | ||
|
||
private static String profileActivationFile( String pom ) throws Exception { | ||
return readPom( pom ).getProfiles().get( 0 ).getActivation().getFile().getExists(); | ||
} | ||
|
||
private static Model readPom(String pomFilePath) throws IOException, XmlPullParserException { | ||
MavenXpp3Reader reader = new MavenXpp3Reader(); | ||
|
||
return reader.read( new FileInputStream( new File( pomFilePath ) ) ); | ||
} | ||
|
||
/** | ||
* After test method. Removes flattened-pom.xml file which is created during test. | ||
* | ||
* @throws RuntimeException if can't remove file. | ||
*/ | ||
@After | ||
public void removeFlattenedPom() throws IOException { | ||
File flattenedPom = new File( FLATTENED_POM ); | ||
if ( flattenedPom.exists() ) { | ||
if ( !flattenedPom.delete() ) { | ||
throw new IOException( "Can't delete %s" + flattenedPom ); | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/resources/resolve-properties-ci-do-not-interpolate-profile-activation-file/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 @@ | ||
<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> | ||
<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> | ||
<activation> | ||
<file> | ||
<exists>file.txt</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
</project> |