Skip to content

Commit

Permalink
[#25] Stop using .properties files for keys
Browse files Browse the repository at this point in the history
the format being used is not quite that of a properties file. the fact that CheckStyle is unhappy with a sample keys map "properties" file that is accepted by PGP confirms this. I've renamed the vars, changed the docs, and updated the sample files. the new file extension is ".list" for keys map files.
  • Loading branch information
Kortanul authored and slawekjaranowski committed Nov 12, 2017
1 parent 32f5cad commit 420fc20
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/it/sigOkKeysMap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<artifactId>pgpverify-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<keysMapLocation>${project.basedir}/keysmap.properties</keysMapLocation>
<keysMapLocation>${project.basedir}/keysmap.list</keysMapLocation>
</configuration>
<executions>
<execution>
Expand Down
2 changes: 1 addition & 1 deletion src/it/sigOkKeysMapMultiModule/modules-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<artifactId>pgpverify-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<keysMapLocation>/test/keysmap.properties</keysMapLocation>
<keysMapLocation>/test/keysmap.list</keysMapLocation>
</configuration>
<executions>
<execution>
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/com/github/s4u/plugins/KeysMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public void load(String locale) throws ResourceNotFoundException, IOException {
final Map<String, String> propertyMap;

try (final InputStream inputStream = resourceManager.getResourceAsInputStream(locale)) {
propertyMap = loadProps(inputStream);
propertyMap = loadKeysMap(inputStream);
}

processProps(propertyMap);
processKeysMap(propertyMap);
}
}

Expand All @@ -70,14 +70,13 @@ public boolean isValidKey(Artifact artifact, PGPPublicKey key) {
return false;
}

private Map<String, String> loadProps(final InputStream inputStream)
private Map<String, String> loadKeysMap(final InputStream inputStream)
throws IOException {
final Map<String, String> propertyMap = new LinkedHashMap<>();
final BufferedReader propertiesReader =
new BufferedReader(new InputStreamReader(inputStream));
final Map<String, String> keysMaps = new LinkedHashMap<>();
final BufferedReader mapReader = new BufferedReader(new InputStreamReader(inputStream));
String currentLine;

while ((currentLine = propertiesReader.readLine()) != null) {
while ((currentLine = mapReader.readLine()) != null) {
if (!isCommentLine(currentLine)) {
final String[] parts = currentLine.split("=");

Expand All @@ -86,17 +85,17 @@ private Map<String, String> loadProps(final InputStream inputStream)
"Property line is malformed: " + currentLine);
}

propertyMap.put(parts[0], parts[1]);
keysMaps.put(parts[0], parts[1]);
}
}

return propertyMap;
return keysMaps;
}

private void processProps(Map<String, String> properties) {
for (Entry<String, String> property : properties.entrySet()) {
private void processKeysMap(Map<String, String> keysMap) {
for (Entry<String, String> mapEntry : keysMap.entrySet()) {
ArtifactInfo artifactInfo =
createArtifactInfo(property.getKey(), property.getValue());
createArtifactInfo(mapEntry.getKey(), mapEntry.getValue());

keysMapList.add(artifactInfo);
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/github/s4u/plugins/PGPVerifyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,21 @@ public class PGPVerifyMojo extends AbstractMojo {
private boolean verifyPomFiles;

/**
* <p>Specifies the location of the properties file which contains the map of dependency to pgp key.</p>
* <p>Specifies the location of a file that contains the map of dependencies to PGP
* key.</p>
*
* <p>The syntax of each line of properties file is:<br/><br/>
* <p>The format of the file is similar to, but more flexible than, a Java properties file.
* The syntax of each line of properties file is:<br/><br/>
* <code>groupId:artifactId:version=pgpKey</code></p>
*
* <p>You can use <code>*</code> in <code>groupId, artefactId and version</code> as wildcard.</p>
* <p>You can use <code>*</code> in <code>groupId, artifactId and version</code> as
* wildcard.</p>
*
* <p><code>pgpKey</code> must be written as hex number starting with 0x.
* You can use <code>*</code> or <code>any</code> for match any pgp key.</p>
*
* <p>You can also omit <code>version</code> and <code>artifactId</code> which means any value for those fields.</p>
* <p>You can also omit <code>version</code> and <code>artifactId</code> which means any value
* for those fields.</p>
*
* @since 1.1.0
*/
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/github/s4u/plugins/KeysMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void emptyLocationTest() throws Exception {

@Test
public void validKeyFromMap1() throws Exception {
keysMap.load("/keysMap1.properties");
keysMap.load("/keysMap1.list");

assertTrue(
keysMap.isValidKey(
Expand All @@ -79,7 +79,7 @@ public void validKeyFromMap1() throws Exception {

@Test
public void validKeyFromMap2() throws Exception {
keysMap.load("/keysMap1.properties");
keysMap.load("/keysMap1.list");

assertTrue(
keysMap.isValidKey(
Expand All @@ -89,7 +89,7 @@ public void validKeyFromMap2() throws Exception {

@Test
public void invalidKeyFromMap() throws Exception {
keysMap.load("/keysMap1.properties");
keysMap.load("/keysMap1.list");

assertFalse(
keysMap.isValidKey(
Expand All @@ -99,7 +99,7 @@ public void invalidKeyFromMap() throws Exception {

@Test
public void keysProcessedInEncounterOrder() throws Exception {
keysMap.load("/keysMap2.properties");
keysMap.load("/keysMap2.list");

assertTrue(
keysMap.isValidKey(
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 420fc20

Please sign in to comment.