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 (fabric8io#1387)
- Loading branch information
1 parent
cc61d85
commit b93309b
Showing
22 changed files
with
523 additions
and
8 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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
package io.fabric8.maven.core.config; | ||
|
||
public class MappingConfig { | ||
|
||
private String kind; | ||
|
||
private String filenameTypes; | ||
|
||
public String getKind() { | ||
return kind; | ||
} | ||
|
||
public String getFilenameTypes() { | ||
return filenameTypes; | ||
} | ||
|
||
public String[] getFilenamesAsArray() { | ||
if (this.filenameTypes == null) { | ||
return new String[0]; | ||
} | ||
return filenameTypes.split(",\\s*"); | ||
} | ||
|
||
public boolean isValid() { | ||
return kind != null && filenameTypes != null && filenameTypes.length() > 0; | ||
} | ||
|
||
} |
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
Oops, something went wrong.