private @NotNull CompositePackagingElement<?> getOrCreateDirectoryOrArchive(@NotNull CompositePackagingElement<?> root,
                                                                              @NotNull @NonNls String path,
                                                                              final boolean directory, boolean addAsFirstChild) {
    path = StringUtil.trimStart(StringUtil.trimEnd(path, "/"), "/");
    if (path.isEmpty()) {
      return root;
    }
    int index = path.lastIndexOf('/');
    String lastName = path.substring(index + 1);
    String parentPath = index != -1 ? path.substring(0, index) : "";

    final CompositePackagingElement<?> parent = getOrCreateDirectoryOrArchive(root, parentPath, true, addAsFirstChild);
    final CompositePackagingElement<?> last = directory ? createDirectory(lastName) : createArchive(lastName);
    if (addAsFirstChild) {
      parent.addFirstChild(last);
      return last;
    }
    else {
      return parent.addOrFindChild(last);
    }
  }
private @NotNull CompositePackagingElement<?> getOrCreateDirectoryOrArchive(@NotNull CompositePackagingElement<?> root,
                                                                              @NotNull @NonNls String path,
                                                                              final boolean directory, boolean addAsFirstChild)