Map<String, RepositoryItem> filesToDeploy = new HashMap<String, RepositoryItem>();
Map<String, List<String>> typeMembersByType = new HashMap<String, List<String>>();
if(repoPackagePath==null)
{
// Construct package manifest and files to deploy map by path
Package packageManifest = new Package();
packageManifest.setVersion("29.0"); // TODO: Make version configurable / auto
List<PackageTypeMembers> packageTypeMembersList = new ArrayList<PackageTypeMembers>();
scanFilesToDeploy(filesToDeploy, typeMembersByType, repositoryContainer);
for(String metadataType : typeMembersByType.keySet())
{
PackageTypeMembers packageTypeMembers = new PackageTypeMembers();
packageTypeMembers.setName(metadataType);
packageTypeMembers.setMembers((String[])typeMembersByType.get(metadataType).toArray(new String[0]));
packageTypeMembersList.add(packageTypeMembers);
}
packageManifest.setTypes((PackageTypeMembers[]) packageTypeMembersList.toArray(new PackageTypeMembers[0]));
// Serialise it (better way to do this?)
TypeMapper typeMapper = new TypeMapper();
ByteArrayOutputStream packageBaos = new ByteArrayOutputStream();
QName packageQName = new QName("http://soap.sforce.com/2006/04/metadata", "Package");
XmlOutputStream xmlOutputStream = new XmlOutputStream(packageBaos, true);
xmlOutputStream.setPrefix("", "http://soap.sforce.com/2006/04/metadata");
xmlOutputStream.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
packageManifest.write(packageQName, xmlOutputStream, typeMapper);
xmlOutputStream.close();
packageManifestXml = new String(packageBaos.toByteArray());
}
// Download the Repository as an archive zip