forked from fabric8io/fabric8-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fabric8io#1382): Allow to provide additional fragment filename m…
…appings
- Loading branch information
1 parent
bf5332c
commit e76aaf0
Showing
14 changed files
with
331 additions
and
7 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
core/src/main/java/io/fabric8/maven/core/config/MappingConfig.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,24 @@ | ||
package io.fabric8.maven.core.config; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
public class MappingConfig { | ||
|
||
@Parameter(required = true) | ||
private String kind; | ||
|
||
@Parameter(required = true) | ||
private String filenames; | ||
|
||
public String getKind() { | ||
return kind; | ||
} | ||
|
||
public String getFilenames() { | ||
return filenames; | ||
} | ||
|
||
public String[] getFilenamesAsArray() { | ||
return filenames.split(",\\s*"); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
core/src/main/java/io/fabric8/maven/core/util/PropertiesMappingParser.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,52 @@ | ||
package io.fabric8.maven.core.util; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
public class PropertiesMappingParser { | ||
|
||
/** | ||
* This method reads properties file to load custom mapping between kinds and filenames. | ||
* | ||
* <pre> | ||
* ConfigMap=cm, configmap | ||
* Service=service | ||
* </pre> | ||
* | ||
* @param mapping | ||
* stream of a properties file setting mappings between kinds and filenames. | ||
* | ||
* @return Serialization of all elements as a map | ||
*/ | ||
public Map<String, List<String>> parse(final InputStream mapping) { | ||
|
||
final Properties mappingProperties = new Properties(); | ||
try { | ||
mappingProperties.load(mapping); | ||
|
||
final Map<String, List<String>> serializedContent = new HashMap<>(); | ||
|
||
final Set<String> kinds = mappingProperties.stringPropertyNames(); | ||
|
||
for (String kind : kinds) { | ||
final String filenames = mappingProperties.getProperty(kind); | ||
final String[] filenameTypes = filenames.split(","); | ||
final List<String> scannedFiletypes = new ArrayList<>(); | ||
for (final String filenameType : filenameTypes) { | ||
scannedFiletypes.add(filenameType.trim()); | ||
} | ||
serializedContent.put(kind, scannedFiletypes); | ||
} | ||
|
||
return serializedContent; | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
core/src/test/java/io/fabric8/maven/core/util/PropertiesMappingParserTest.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,37 @@ | ||
package io.fabric8.maven.core.util; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class PropertiesMappingParserTest { | ||
|
||
private static final String MAPPING_PROPERTIES = "ConfigMap=cm, configmap"; | ||
|
||
@Test | ||
public void should_read_mappings_from_properties_file() { | ||
|
||
// Given | ||
|
||
final PropertiesMappingParser propertiesMappingParser = new PropertiesMappingParser(); | ||
|
||
// When | ||
|
||
final Map<String, List<String>> serializedContent = | ||
propertiesMappingParser.parse(new ByteArrayInputStream(MAPPING_PROPERTIES.getBytes())); | ||
|
||
// Then | ||
|
||
final Map<String, List<String>> expectedSerlializedContent = new HashMap<>(); | ||
expectedSerlializedContent.put("ConfigMap", Arrays.asList("cm", "configmap")); | ||
|
||
assertThat(serializedContent) | ||
.containsAllEntriesOf(expectedSerlializedContent); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.