distSession = osgiFactory.openDistSession();
Node distNode = osgiFactory.getDist(distSession, uri);
- zin = new ZipInputStream(distNode.getNode(Node.JCR_CONTENT)
- .getProperty(Property.JCR_DATA).getBinary().getStream());
+ zin = new ZipInputStream(
+ distNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary().getStream());
ZipEntry zentry = null;
entries: while ((zentry = zin.getNextEntry()) != null) {
String groupId = includes.get(include);
JarInputStream jis = new JarInputStream(zin);
if (jis.getManifest() == null) {
- log.warn("No MANIFEST in entry " + name
- + ", skipping...");
+ log.warn("No MANIFEST in entry " + name + ", skipping...");
continue entries;
}
- NameVersion nv = RepoUtils.readNameVersion(jis
- .getManifest());
+ NameVersion nv = RepoUtils.readNameVersion(jis.getManifest());
if (nv != null) {
if (nv.getName().endsWith(".source"))
continue entries;
- CategorizedNameVersion cnv = new OsgiCategorizedNV(
- groupId, nv.getName(), nv.getVersion(),
+ CategorizedNameVersion cnv = new OsgiCategorizedNV(groupId, nv.getName(), nv.getVersion(),
this);
nvs.add(cnv);
// no need to process further includes
public void run() {
if (mavenGroupIndexes && (version == null))
- throw new SlcException(
- "'mavenGroupIndexes' requires 'version' to be set");
+ throw new SlcException("'mavenGroupIndexes' requires 'version' to be set");
Map<String, Set<Artifact>> binaries = new HashMap<String, Set<Artifact>>();
Map<String, Set<Artifact>> sources = new HashMap<String, Set<Artifact>>();
boolean nothingWasDone = true;
Node distNode = osgiFactory.getDist(distSession, uri);
- zin = new ZipInputStream(distNode.getNode(Node.JCR_CONTENT)
- .getProperty(Property.JCR_DATA).getBinary().getStream());
+ zin = new ZipInputStream(
+ distNode.getNode(Node.JCR_CONTENT).getProperty(Property.JCR_DATA).getBinary().getStream());
ZipEntry zentry = null;
entries: while ((zentry = zin.getNextEntry()) != null) {
// sources autodetect
String baseName = FilenameUtils.getBaseName(name);
if (baseName.endsWith("-sources")) {
- String bundle = baseName.substring(0, baseName.length()
- - "-sources".length());
+ String bundle = baseName.substring(0, baseName.length() - "-sources".length());
// log.debug(name + "," + baseName + ", " + bundle);
- String bundlePath = FilenameUtils.getPath(name) + bundle
- + ".jar";
+ String bundlePath = FilenameUtils.getPath(name) + bundle + ".jar";
if (wrappers.containsKey(bundlePath)) {
BndWrapper wrapper = wrappers.get(bundlePath);
- NameVersion bundleNv = new DefaultNameVersion(
- wrapper.getName(), wrapper.getVersion());
- byte[] pdeSource = RepoUtils.packageAsPdeSource(zin,
- bundleNv);
- Artifact sourcesArtifact = new DefaultArtifact(
- wrapper.getCategory(), wrapper.getName()
- + ".source", "jar",
- wrapper.getVersion());
- Node pdeSourceNode = RepoUtils.copyBytesAsArtifact(
- javaSession.getRootNode(), sourcesArtifact,
+ NameVersion bundleNv = new DefaultNameVersion(wrapper.getName(), wrapper.getVersion());
+ byte[] pdeSource = RepoUtils.packageAsPdeSource(zin, bundleNv);
+ Artifact sourcesArtifact = new DefaultArtifact(wrapper.getCategory(),
+ wrapper.getName() + ".source", "jar", wrapper.getVersion());
+ Node pdeSourceNode = RepoUtils.copyBytesAsArtifact(javaSession.getRootNode(), sourcesArtifact,
pdeSource);
osgiFactory.indexNode(pdeSourceNode);
pdeSourceNode.getSession().save();
if (log.isDebugEnabled())
- log.debug("Added sources " + sourcesArtifact
- + " for bundle " + wrapper.getArtifact()
+ log.debug("Added sources " + sourcesArtifact + " for bundle " + wrapper.getArtifact()
+ "from " + name + " in binary archive.");
}
BndWrapper wrapper = (BndWrapper) wrappers.get(name);
// we must copy since the stream is closed by BND
byte[] origJarBytes = IOUtils.toByteArray(zin);
- Artifact artifact = wrapZipEntry(javaSession, zentry,
- origJarBytes, wrapper);
+ Artifact artifact = wrapZipEntry(javaSession, zentry, origJarBytes, wrapper);
nothingWasDone = false;
addArtifactToIndex(binaries, wrapper.getGroupId(), artifact);
} else {
for (String wrapperKey : wrappers.keySet())
if (pathMatcher.match(wrapperKey, name)) {
// first matched is taken
- BndWrapper wrapper = (BndWrapper) wrappers
- .get(wrapperKey);
+ BndWrapper wrapper = (BndWrapper) wrappers.get(wrapperKey);
// we must copy since the stream is closed by BND
byte[] origJarBytes = IOUtils.toByteArray(zin);
- Artifact artifact = wrapZipEntry(javaSession,
- zentry, origJarBytes, wrapper);
+ Artifact artifact = wrapZipEntry(javaSession, zentry, origJarBytes, wrapper);
nothingWasDone = false;
- addArtifactToIndex(binaries, wrapper.getGroupId(),
- artifact);
+ addArtifactToIndex(binaries, wrapper.getGroupId(), artifact);
continue entries;
} else {
if (log.isTraceEnabled())
- log.trace(name + " not matched by "
- + wrapperKey);
+ log.trace(name + " not matched by " + wrapperKey);
}
for (String exclude : excludes)
if (pathMatcher.match(include, name)) {
String groupId = includes.get(include);
byte[] origJarBytes = IOUtils.toByteArray(zin);
- Artifact artifact = importZipEntry(javaSession,
- zentry, origJarBytes, groupId);
+ Artifact artifact = importZipEntry(javaSession, zentry, origJarBytes, groupId);
if (artifact == null) {
log.warn("Skipped non identified " + zentry);
continue entries;
// indexes
if (mavenGroupIndexes && version != null) {
for (String groupId : binaries.keySet()) {
- RepoUtils.writeGroupIndexes(javaSession, "/", groupId,
- version, binaries.get(groupId),
- sources.containsKey(groupId) ? sources.get(groupId)
- : null);
+ RepoUtils.writeGroupIndexes(javaSession, "/", groupId, version, binaries.get(groupId),
+ sources.containsKey(groupId) ? sources.get(groupId) : null);
}
}
}
}
- protected Artifact wrapZipEntry(Session javaSession, ZipEntry zentry,
- byte[] origJarBytes, BndWrapper wrapper) throws RepositoryException {
+ protected Artifact wrapZipEntry(Session javaSession, ZipEntry zentry, byte[] origJarBytes, BndWrapper wrapper)
+ throws RepositoryException {
ByteArrayOutputStream out = null;
ByteArrayInputStream in = null;
Node newJarNode;
wrapper.wrapJar(in, out);
Artifact artifact = wrapper.getArtifact();
- newJarNode = RepoUtils.copyBytesAsArtifact(
- javaSession.getRootNode(), artifact, out.toByteArray());
+ 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());
+ log.debug("Wrapped jar " + zentry.getName() + " to " + newJarNode.getPath());
if (sourcesProvider != null)
addSource(javaSession, artifact, out.toByteArray());
}
}
- protected void addSource(Session javaSession, Artifact artifact,
- byte[] binaryJarBytes) {
+ protected void addSource(Session javaSession, Artifact artifact, byte[] binaryJarBytes) {
InputStream in = null;
ByteArrayOutputStream out = null;
Jar jar = null;
IOUtils.closeQuietly(in);
in = new ByteArrayInputStream(out.toByteArray());
- byte[] sourcesJar = RepoUtils.packageAsPdeSource(
- in,
- new DefaultNameVersion(artifact.getArtifactId(), artifact
- .getVersion()));
- Artifact sourcesArtifact = new DefaultArtifact(
- artifact.getGroupId(),
- artifact.getArtifactId() + ".source", "jar",
- artifact.getVersion());
- Node sourcesJarNode = RepoUtils.copyBytesAsArtifact(
- javaSession.getRootNode(), sourcesArtifact, sourcesJar);
+ byte[] sourcesJar = RepoUtils.packageAsPdeSource(in,
+ new DefaultNameVersion(artifact.getArtifactId(), artifact.getVersion()));
+ Artifact sourcesArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId() + ".source",
+ "jar", artifact.getVersion());
+ Node sourcesJarNode = RepoUtils.copyBytesAsArtifact(javaSession.getRootNode(), sourcesArtifact, sourcesJar);
sourcesJarNode.getSession().save();
if (log.isDebugEnabled())
- log.debug("Added sources " + sourcesArtifact + " for bundle "
- + artifact + "from source provider " + sourcesProvider);
+ log.debug("Added sources " + sourcesArtifact + " for bundle " + artifact + "from source provider "
+ + sourcesProvider);
} catch (Exception e) {
throw new SlcException("Cannot get sources for " + artifact, e);
} finally {
}
}
- protected Artifact importZipEntry(Session javaSession, ZipEntry zentry,
- byte[] binaryJarBytes, String groupId) throws RepositoryException {
+ protected Artifact importZipEntry(Session javaSession, ZipEntry zentry, byte[] binaryJarBytes, String groupId)
+ throws RepositoryException {
ByteArrayInputStream in = null;
Node newJarNode;
try {
log.warn("Cannot identify " + zentry.getName());
return null;
}
- Artifact artifact = new DefaultArtifact(groupId,
- nameVersion.getName(), "jar", nameVersion.getVersion());
- newJarNode = RepoUtils.copyBytesAsArtifact(
- javaSession.getRootNode(), artifact, binaryJarBytes);
+ Artifact artifact = new DefaultArtifact(groupId, nameVersion.getName(), "jar", nameVersion.getVersion());
+ newJarNode = RepoUtils.copyBytesAsArtifact(javaSession.getRootNode(), artifact, binaryJarBytes);
osgiFactory.indexNode(newJarNode);
newJarNode.getSession().save();
- if (log.isDebugEnabled())
- log.debug("Imported OSGi bundle " + zentry.getName() + " to "
- + newJarNode.getPath());
+ if (log.isDebugEnabled()) {
+ log.debug(zentry.getName() + " => " + artifact);
+ }
if (sourcesProvider != null)
addSource(javaSession, artifact, binaryJarBytes);
}
}
- private void addArtifactToIndex(Map<String, Set<Artifact>> index,
- String groupId, Artifact artifact) {
+ 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.put(groupId, new TreeSet<Artifact>(new ArtifactIdComparator()));
index.get(groupId).add(artifact);
}