Map<ThirdPartyId, ThirdParty> load() throws MojoExecutionException { try { Map<ThirdPartyId, ThirdParty> fullThirdParties = new HashMap<ThirdPartyId, ThirdParty>(); if (file != null) { Properties props = new Properties(); props.load(new FileInputStream(file)); for (Map.Entry<Object, Object> eachEntry : props.entrySet()) { String key = (String) eachEntry.getKey(); String value = (String) eachEntry.getValue(); ThirdPartyId id = parseId(key); ThirdParty eachThirdParty = fullThirdParties.get(id); if (eachThirdParty == null) { eachThirdParty = new ThirdParty(); eachThirdParty.setClassifier(id.getClassifier()); eachThirdParty.setType(id.getType()); fullThirdParties.put(id, eachThirdParty); } switch (ThirdPartyProps.valueOf(key.substring(key.lastIndexOf('.') + 1))) { case src: eachThirdParty.setSrc(value); break; case md5: eachThirdParty.setMd5(value); break; } } } return fullThirdParties; } catch (IOException ex) { throw new MojoExecutionException( "Unable to load Third parties file [ " + file.getAbsolutePath() + " ]", ex); } }
private ThirdPartyId parseId(String key) { String[] split = key.split("\\."); if (split.length < 3) { throw new IllegalArgumentException("Property name [ " + key + " ] cannot be parsed"); } String classifier = split[0]; String type = StringUtils.join(Arrays.copyOfRange(split, 1, split.length - 1), "."); String prop = split[split.length - 1]; ThirdPartyProps.valueOf(prop); return new ThirdPartyId(classifier, type); }