Problem trying --------------- Key: FELIX-1819 URL: https://issues.apache.org/jira/browse/FELIX-1819 Project: Felix Issue Type: Bug Components: Maven SCR Plugin Affects Versions: maven-scr-plugin-1.2.0 Reporter: Rembert Magri Fix For: maven-scr-plugin-1.4.1 Attachments: JavaClassDescriptorManager.java
When adding dependencies with "provided" scope, the plugin cannot find the bundle correctly. I fixed the problem by changing the getManifest and getFile methods as follows: protected Manifest getManifest(Artifact artifact) throws IOException { if (!this.isJavaArtifact(artifact)) { throw new IllegalArgumentException("Trying to load Manifest from a non-Java type"); } if ("bundle".equals(artifact.getType())) { return getManifestFromBundle(artifact); } return getManifestFromJarFile(artifact); } private Manifest getManifestFromBundle(Artifact artifact) throws FileNotFoundException, IOException { //artifact.getFile() returns {project}/target/classes, and I want {project}/META-INF/MANIFEST.MF File file = getFileFromBundle(artifact, "META-INF/MANIFEST.MF"); FileInputStream manifestInputStream = null; try { manifestInputStream = new FileInputStream(file); return new Manifest(manifestInputStream); } finally { if (manifestInputStream != null) { try { manifestInputStream.close(); } catch (IOException ignore) { } } } } private Manifest getManifestFromJarFile(Artifact artifact) throws IOException { JarFile file = null; try { file = new JarFile(artifact.getFile()); return file.getManifest(); } finally { if (file != null) { try { file.close(); } catch (IOException ignore) { } } } } protected File getFile(Artifact artifact, String path) throws IOException { if ("bundle".equals(artifact.getType())) { return getFileFromBundle(artifact, path); } return getFileFromJar(artifact, path); } private File getFileFromBundle(Artifact artifact, String path) throws FileNotFoundException { //artifact.getFile() returns {project}/target/classes, and I want {project}/path File file = artifact.getFile(); File targetFile = new File(file.getParentFile().getParentFile(),path); if (targetFile.canRead()) { return targetFile; } log.warn("Won't be able to read: " + targetFile); return null; } private File getFileFromJar(Artifact artifact, String path) throws IOException, FileNotFoundException { final int pos = path.lastIndexOf('.'); final String suffix = path.substring(pos + 1); JarFile file = null; File tmpFile = null; try { file = new JarFile(artifact.getFile()); final JarEntry entry = file.getJarEntry(path); if ( entry != null ) { tmpFile = File.createTempFile("scrjcdm" + artifact.getArtifactId(), suffix); tmpFile.deleteOnExit(); final FileOutputStream fos = new FileOutputStream(tmpFile); IOUtil.copy(file.getInputStream(entry), fos); IOUtil.close(fos); return tmpFile; } return null; } finally { if (file != null) { try { file.close(); } catch (IOException ignore) { } } } } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.