VersionInfoPListManager { void addDependencyToPlist(List<Dependency> dependencies, PListAccessor plistAccessor, String path, boolean hideConfidentialInformation) throws IOException { for (int i = 0; i < dependencies.size(); i++) { String _path = path + i; Dependency dep = dependencies.get(i); plistAccessor.addDictToArray("coordinates", _path); plistAccessor.addStringValueToDict(GROUP_ID, dep.getCoordinates().getGroupId(), _path + ":coordinates"); plistAccessor.addStringValueToDict(ARTIFACT_ID, dep.getCoordinates().getArtifactId(), _path + ":coordinates"); plistAccessor.addStringValueToDict(VERSION, dep.getCoordinates().getVersion(), _path + ":coordinates"); plistAccessor.addDictToArray("scm", _path); String port = getScmPort(dep, hideConfidentialInformation); plistAccessor.addStringValueToDict("connection", port, _path + ":scm"); plistAccessor.addStringValueToDict("revision", dep.getScm().getRevision(), _path + ":scm"); addDependencyToPlist(dep.getDependencies(), plistAccessor, _path + ":dependencies:", hideConfidentialInformation); } }    }
@Test public void testSimpleDependency() throws Exception { Dependency dep = new Dependency(); Coordinates coord = new Coordinates(); coord.setArtifactId("depArtifactId"); coord.setGroupId("depGroupId"); coord.setVersion("depVersion"); SCM scm = new SCM(); scm.setConnection("scm:perforce:DEPPERFORCEHOST:9999: scm.setRevision("depRevision"); dep.setCoordinates(coord); dep.setScm(scm); List<Dependency> dependencies = new ArrayList<Dependency>(); dependencies.add(dep); new VersionInfoPListManager().addDependencyToPlist(dependencies, plistAccessorPerforce, "dependencies:", true); Assert.assertEquals("depArtifactId", plistAccessorPerforce.printValue("dependencies:0:coordinates:artifactId")); Assert.assertEquals("depGroupId", plistAccessorPerforce.printValue("dependencies:0:coordinates:groupId")); Assert.assertEquals("depVersion", plistAccessorPerforce.printValue("dependencies:0:coordinates:version")); Assert.assertEquals("9999 plistAccessorPerforce.printValue("dependencies:0:scm:connection")); Assert.assertEquals("depRevision", plistAccessorPerforce.printValue("dependencies:0:scm:revision")); }
@Test(expected = IllegalStateException.class) public void testTransitiveDependency() throws Exception { Dependency dep = new Dependency(); Coordinates coord = new Coordinates(); coord.setArtifactId("depArtifactId"); coord.setGroupId("depGroupId"); coord.setVersion("depVersion"); SCM scm = new SCM(); scm.setConnection("scm:perforce:DEPPERFORCEPORT: scm.setRevision("depRevision"); dep.setCoordinates(coord); dep.setScm(scm); Dependency transitivDep = new Dependency(); Coordinates transitivDepCoord = new Coordinates(); transitivDepCoord.setArtifactId("transitivDepArtifactId"); transitivDepCoord.setGroupId("transitivDepGroupId"); transitivDepCoord.setVersion("transitiveDepVersion"); SCM transitivDepScm = new SCM(); transitivDepScm.setConnection("scm:perforce:TRANSDEPPERFORCEHOST:9999: transitivDepScm.setRevision("transitiveDepRevision"); transitivDep.setCoordinates(transitivDepCoord); transitivDep.setScm(transitivDepScm); dep.addDependency(transitivDep); List<Dependency> dependencies = new ArrayList<Dependency>(); dependencies.add(dep); new VersionInfoPListManager().addDependencyToPlist(dependencies, plistAccessorPerforce, "dependencies:", true); Assert.assertEquals("transitivDepArtifactId", plistAccessorPerforce.printValue("dependencies:0:dependencies:0:coordinates:artifactId")); Assert.assertEquals("transitivDepGroupId", plistAccessorPerforce.printValue("dependencies:0:dependencies:0:coordinates:groupId")); Assert.assertEquals("transitiveDepVersion", plistAccessorPerforce.printValue("dependencies:0:dependencies:0:coordinates:version")); Assert.assertEquals("9999 plistAccessorPerforce.printValue("dependencies:0:dependencies:0:scm:connection")); Assert .assertEquals("transitiveDepRevision", plistAccessorPerforce.printValue("dependencies:0:dependencies:0:scm:revision")); plistAccessorPerforce.printValue("dependencies:0:dependencies:1:scm:revision"); }