-
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.
Introduce properties manager for easy implements other properties for…
…mats
- Loading branch information
1 parent
8f4e6be
commit bdebdff
Showing
16 changed files
with
416 additions
and
109 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 @@ | ||
invoker.goals = clean process-resources |
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,6 @@ | ||
|
||
# test properties for IT | ||
|
||
props1 = value1 | ||
props2 = value2 | ||
props3 = value3 |
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,4 @@ | ||
|
||
# test properties for IT | ||
|
||
props3 = value3 |
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,42 @@ | ||
<?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>org.codehaus.mojo.properties.it</groupId> | ||
<artifactId>write-project</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<build> | ||
|
||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>properties-maven-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>read-project-properties</goal> | ||
</goals> | ||
<configuration> | ||
<files> | ||
<file>main.properties</file> | ||
<!-- default manager for properties should be used --> | ||
<file>main2.txt</file> | ||
</files> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</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,5 @@ | ||
Test resource using properties from external files | ||
|
||
props1 has value ${props1} | ||
props2 has value ${props2} | ||
props3 has value ${props3} |
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,30 @@ | ||
/* | ||
* 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 testFile = new File( basedir, 'target/classes/test.txt' ) | ||
assert testFile.exists() | ||
|
||
String content = testFile.getText() | ||
assert content.contains('props1 has value value1') | ||
assert content.contains('props2 has value value2') | ||
assert content.contains('props3 has value value3') | ||
|
||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.exists() | ||
assert buildLog.getText().contains("[WARNING] Unknown properties resource extension: 'txt' assume as: 'properties'") | ||
|
44 changes: 44 additions & 0 deletions
44
src/main/java/org/codehaus/mojo/properties/AbstractPropertiesMojo.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,44 @@ | ||
package org.codehaus.mojo.properties; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.codehaus.mojo.properties.managers.PropertiesManager; | ||
|
||
/** | ||
* Abstract Mojo with Properties managers support. | ||
*/ | ||
public abstract class AbstractPropertiesMojo extends AbstractMojo { | ||
|
||
private final List<PropertiesManager> propertiesManagers; | ||
|
||
protected AbstractPropertiesMojo(List<PropertiesManager> propertiesManagers) { | ||
this.propertiesManagers = propertiesManagers; | ||
} | ||
|
||
protected PropertiesManager getPropertiesManager(String resourceExtension) { | ||
getLog().debug("Available properties managers: " + propertiesManagers); | ||
|
||
String resourceExtensionLowerCase = resourceExtension.toLowerCase(Locale.ROOT); | ||
Optional<PropertiesManager> propertiesStore = propertiesManagers.stream() | ||
.filter(manager -> manager.isExtensionSupport(resourceExtensionLowerCase)) | ||
.findFirst(); | ||
|
||
if (!propertiesStore.isPresent()) { | ||
getLog().warn("Unknown properties resource extension: '" + resourceExtension + "' assume as: '" | ||
+ PropertiesManager.DEFAULT_MANAGER_EXTENSION + "'"); | ||
return getDefaultPropertiesManager(); | ||
} else { | ||
return propertiesStore.get(); | ||
} | ||
} | ||
|
||
private PropertiesManager getDefaultPropertiesManager() { | ||
return propertiesManagers.stream() | ||
.filter(manager -> manager.isExtensionSupport(PropertiesManager.DEFAULT_MANAGER_EXTENSION)) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException("Default properties manager not exist")); | ||
} | ||
} |
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
Oops, something went wrong.