-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to use the detected properties before reading pom.xml (
#59) Motivation: It's currently not possible to use the detected properties to activate profiles. Modifications: PR implements afterSessionStart in addition to afterProjectsRead. This makes it possible to use the detected properties to activate profiles. ``` ... <profile> <id>Ubuntu</id> <activation> <property> <name>os.detected.release</name> <value>ubuntu</value> </property> </activation> ... <!-- Now you can do Ubuntu-specific work --> ... </profile> ``` Result: `os-maven-plugin` is now capable of injecting the detected properties even before reading `pom.xml`.
- Loading branch information
1 parent
fd2b70e
commit 43ed4d4
Showing
5 changed files
with
166 additions
and
3 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
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,8 @@ | ||
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd"> | ||
<extension> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
</extension> | ||
</extensions> |
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,83 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>kr.motd.maven.it</groupId> | ||
<artifactId>test-activate-profile</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<description> | ||
An integration test that checks whether the profile can be activated by detected properties. If the | ||
project.properties file contains the "active.profile" property and it has the expected value, the test is | ||
considered successful. | ||
</description> | ||
|
||
<prerequisites> | ||
<!-- (since Maven 3.3.1) configure your extension in .mvn/extensions.xml --> | ||
<!-- https://maven.apache.org/examples/maven-3-lifecycle-extensions.html --> | ||
<maven>3.3.1</maven> | ||
</prerequisites> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>properties-maven-plugin</artifactId> | ||
<version>1.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>write-project-properties</id> | ||
<phase>validate</phase> | ||
<goals> | ||
<goal>write-project-properties</goal> | ||
</goals> | ||
<configuration> | ||
<outputFile>${project.build.directory}/project.properties</outputFile> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>detected-windows</id> | ||
<activation> | ||
<property> | ||
<name>os.detected.name</name> | ||
<value>windows</value> | ||
</property> | ||
</activation> | ||
<properties> | ||
<active.profile>detected-windows</active.profile> | ||
</properties> | ||
</profile> | ||
|
||
<profile> | ||
<id>detected-ubuntu</id> | ||
<activation> | ||
<property> | ||
<name>os.detected.release</name> | ||
<value>ubuntu</value> | ||
</property> | ||
</activation> | ||
<properties> | ||
<active.profile>detected-ubuntu</active.profile> | ||
</properties> | ||
</profile> | ||
|
||
<profile> | ||
<id>detected-osx</id> | ||
<activation> | ||
<property> | ||
<name>os.detected.name</name> | ||
<value>osx</value> | ||
</property> | ||
</activation> | ||
<properties> | ||
<active.profile>detected-osx</active.profile> | ||
</properties> | ||
</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,24 @@ | ||
import org.apache.commons.io.FileUtils | ||
import org.apache.commons.lang3.SystemUtils | ||
|
||
def projectPropertiesFile = new File(basedir, "target/project.properties") | ||
|
||
assert projectPropertiesFile.exists() : "project.properties not found" | ||
assert projectPropertiesFile.canRead() : "project.properties cannot be read" | ||
|
||
Properties projectProperties = new Properties() | ||
projectPropertiesFile.withInputStream { | ||
projectProperties.load(it) | ||
} | ||
|
||
if (SystemUtils.IS_OS_WINDOWS) { | ||
assert projectProperties."active.profile" == 'detected-windows' | ||
} else if (SystemUtils.IS_OS_LINUX) { | ||
String osReleaseContent = FileUtils.readFileToString(new File("/etc/os-release")) | ||
|
||
if (osReleaseContent.contains("ID=ubuntu")) { | ||
assert projectProperties."active.profile" == 'detected-ubuntu' | ||
} | ||
} else if (SystemUtils.IS_OS_MAC) { | ||
assert projectProperties."active.profile" == 'detected-osx' | ||
} |
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