+ protected Artifact wrapZipEntry(Session javaSession, ZipEntry zentry,
+ byte[] sourceJarBytes, BndWrapper wrapper)
+ throws RepositoryException {
+ ByteArrayOutputStream out = null;
+ ByteArrayInputStream in = null;
+ Node newJarNode;
+ try {
+ out = new ByteArrayOutputStream((int) zentry.getSize());
+ in = new ByteArrayInputStream(sourceJarBytes);
+ wrapper.wrapJar(in, out);
+
+ Artifact artifact = wrapper.getArtifact();
+ newJarNode = RepoUtils.copyBytesAsArtifact(
+ javaSession.getRootNode(), artifact, out.toByteArray());
+ osgiFactory.indexNode(newJarNode);
+ newJarNode.getSession().save();
+ if (log.isDebugEnabled())
+ log.debug("Wrapped jar " + zentry.getName() + " to "
+ + newJarNode.getPath());
+ return artifact;
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ }
+ }
+
+ protected Artifact importZipEntry(Session javaSession, ZipEntry zentry,
+ byte[] sourceJarBytes, String groupId) throws RepositoryException {
+ ByteArrayInputStream in = null;
+ Node newJarNode;
+ try {
+ in = new ByteArrayInputStream(sourceJarBytes);
+ NameVersion nameVersion = RepoUtils.readNameVersion(in);
+ Artifact artifact = new DefaultArtifact(groupId,
+ nameVersion.getName(), "jar", nameVersion.getVersion());
+ newJarNode = RepoUtils.copyBytesAsArtifact(
+ javaSession.getRootNode(), artifact, sourceJarBytes);
+ osgiFactory.indexNode(newJarNode);
+ newJarNode.getSession().save();
+ if (log.isDebugEnabled())
+ log.debug("Imported OSGi bundle " + zentry.getName() + " to "
+ + newJarNode.getPath());
+ return artifact;
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ private void addArtifactToIndex(Map<String, Set<Artifact>> index,
+ String groupId, Artifact artifact) {
+ if (!index.containsKey(groupId))
+ index.put(groupId,
+ new TreeSet<Artifact>(new ArtifactIdComparator()));
+ index.get(groupId).add(artifact);
+ }