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

maven-scr-plugin messes project resources when outputDirectory configuration present on windows

    XMLWordPrintableJSON

Details

    Description

      As I look at the following code, I easily can conclude problems on Windows.

      org.apache.felix.scrplugin.mojo.SCRDescriptorMojo#updateProjectResources()
          private boolean updateProjectResources() {
              final String classesDir = this.project.getBuild().getOutputDirectory().replace(File.separatorChar, '/');
              final String ourRsrcPath = this.outputDirectory.getAbsolutePath().replace(File.separatorChar, '/');
              if ( !classesDir.equals(ourRsrcPath) ) {
                  // now add the descriptor directory to the maven resources
                  boolean found = false;
                  @SuppressWarnings("unchecked")
                  final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
                  while (!found && rsrcIterator.hasNext()) {
                      final Resource rsrc = rsrcIterator.next();
                      found = rsrc.getDirectory().equals(ourRsrcPath);
                  }
                  if (!found) {
                      final Resource resource = new Resource();
                      resource.setDirectory(this.outputDirectory.getAbsolutePath());
                      this.project.addResource(resource);
                  }
                  return true;
              }
              return false;
          }
      

      The problematic snippet is .replace(File.separatorChar, '/'). On any other environment that Windows this might work but it does not work with backslash file separators.
      At first classesDir is compared to ourRsrcPath which is correct as both values have their slashes replaced. The second comparison on line 545, however, is invalid because rsrc.getDirectory() contains native file separators when compared to ourRsrcPath with replaced file separators.

      As a consequence, the outputDirecory becomes (is added as a) maven project resource and everything inside it if previously existing is copied into the target directory. In my case I specified the project root directory as outputDirectory so that Eclipse PDE finds the OSGI-INF folder in the place expected and added the root folder with an inclusion pattern of OSGI-INF/** to the project resources. The issue caused the whole project to get copied into the target/classes folder resulting in something like target/classes/target/classes, which maven-bundle-plugin is then complaining with an error because:

      [ERROR] ... : Classes found in the wrong directory: {target/classes/target/clases/...=...}
      

      Attachments

        1. FELIX-4999.patch
          2 kB
          Philipp Kunz

        Activity

          People

            cziegeler Carsten Ziegeler
            philipp.kunz Philipp Kunz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: