private static ModuleArtifactMap createArtifactLocationMap(File repositoryDir)
      throws ProvisionException {
    ModuleArtifactMap artifactLocationMap = ModuleArtifactMap.createInstance(repositoryDir);

    // add p2artifacts.xml in standard location
    artifactLocationMap.add(
        RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS,
        new File(repositoryDir, RepositoryLayoutHelper.FILE_NAME_P2_ARTIFACTS));
    return artifactLocationMap;
  }
  @Override
  public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException {
    if (descriptor == null) {
      throw new NullPointerException();
    } else if (!(descriptor instanceof ModuleArtifactDescriptor)) {
      throw new IllegalArgumentException("Descriptor must have been created by this repository");
    }

    String classifier = descriptor.getProperty(RepositoryLayoutHelper.PROP_CLASSIFIER);

    // look up storage location
    File storageLocation = artifactsMap.addToAutomaticLocation(classifier);

    // TODO download.size/artifact.size is not set in the descriptor for product binaries -> compute
    // while streaming

    internalAddDescriptor(descriptor);
    storeOrProvisioningException();

    try {
      return new FileOutputStream(storageLocation);
    } catch (FileNotFoundException e) {
      throw new ProvisionException(
          "Failed to write artifact " + descriptor.getArtifactKey() + " to " + storageLocation, e);
    }
  }
  public static ModuleArtifactRepository restoreInstance(
      IProvisioningAgent agent, File repositoryDir) throws ProvisionException {
    ModuleArtifactRepository restoredInstance =
        new ModuleArtifactRepository(
            agent, repositoryDir.toURI(), ModuleArtifactMap.restoreInstance(repositoryDir));

    restoredInstance.load();
    return restoredInstance;
  }