Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-1819

Problem with dependencies resolution

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • maven-scr-plugin-1.2.0
    • maven-scr-plugin-1.4.2
    • SCR Tooling
    • None

    Description

      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) {
      }
      }
      }
      }

      Attachments

        1. JavaClassDescriptorManager.java
          21 kB
          Rembert Magri

        Activity

          People

            cziegeler Carsten Ziegeler
            rmagri Rembert Magri
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: