P2MetadataMojo extends AbstractMojo { static void writeArtifactLocations(File outputFile, Map<String, File> artifactLocations) throws MojoExecutionException { Properties outputProperties = new Properties(); for (Entry<String, File> entry : artifactLocations.entrySet()) { if (entry.getKey() == null) { outputProperties.put(KEY_ARTIFACT_MAIN, entry.getValue().getAbsolutePath()); } else { outputProperties.put(KEY_ARTIFACT_ATTACHED + entry.getKey(), entry.getValue().getAbsolutePath()); } } writeProperties(outputProperties, outputFile); }  @Override void execute();  }
@Test public void testWriteArtifactLocations() throws Exception { Map<String, File> artifactLocations = new HashMap<>(); artifactLocations.put(null, MAIN_ARTIFACT); artifactLocations.put("source", SOURCE_ARTIFACT); artifactLocations.put("other-classifier", OTHER_ARTIFACT); P2MetadataMojo.writeArtifactLocations(testFile, artifactLocations); Properties result = loadProperties(testFile); assertEquals(3, result.size()); assertEquals(MAIN_ARTIFACT.getCanonicalFile(), getFileEntry("artifact.main", result)); assertEquals(SOURCE_ARTIFACT.getCanonicalFile(), getFileEntry("artifact.attached.source", result)); assertEquals(OTHER_ARTIFACT.getCanonicalFile(), getFileEntry("artifact.attached.other-classifier", result)); }
@Test public void testWriteOnlyAttachedArtifactLocation() throws Exception { Map<String, File> artifactLocations = new HashMap<>(); artifactLocations.put("other-classifier", OTHER_ARTIFACT); P2MetadataMojo.writeArtifactLocations(testFile, artifactLocations); Properties result = loadProperties(testFile); assertEquals(1, result.size()); assertEquals(OTHER_ARTIFACT.getCanonicalFile(), getFileEntry("artifact.attached.other-classifier", result)); }