Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-3575

Fixed ordering of j2ee.platform.classpath entires

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 12.0
    • None

    Description

      According to my experience j2ee.platform.classpath entries are "randomly" ordered in the corresponding project.properties files (where applicable). It would be much better, if the ordering would be fixed (eg. alphabetical regarding the (absolute) path of the entries), so it would not cause constant problems for various version management systems. (They tend to mark this line as changed, since the order may vary, and thus may cause unnecessary conflicts.)

      This has been bugging me (and I bet also others) for quite a while now, to an extent to try to fix it on my own. I might have found a solution which seems to work for me. In doing so, I have modified the NetBeans source code, but now I'm unsure of what to do, or if my solution is correct. Given that I've never contributes to the Apache community I'd decided it might be the best if I opened a ticket abut it here.

      My modification is really simple, and all it does is order the classpath entries in an ascending order, based on the absolute pathname of the corresponding files. This is all done in org.netbeans.modules.j2ee.common.ClassPathUtil.java, where getJ2eePlatformClasspathEntries is defined. Of course this could be polished, but I'd like to know first if such modification would be allowed at all?

      Here is the quick fix, I was referring to: (original source if based on TAG 11.2)

      public static File[] getJ2eePlatformClasspathEntries(@NullAllowed Project project, @NullAllowed J2eePlatform j2eePlatform) {
          if (project != null) {
              J2eeModuleProvider j2eeModuleProvider = project.getLookup().lookup(J2eeModuleProvider.class);
              if (j2eeModuleProvider != null) {
                  J2eePlatform j2eePlatformLocal = j2eePlatform != null ? j2eePlatform : Deployment.getDefault().getJ2eePlatform(j2eeModuleProvider.getServerInstanceID());
                  if (j2eePlatformLocal != null) {
                      try {
                          File[] files = j2eePlatformLocal.getClasspathEntries(j2eeModuleProvider.getConfigSupport().getLibraries());
                          sortClassPathEntries(files);
                          return files;
                          //return j2eePlatformLocal.getClasspathEntries(j2eeModuleProvider.getConfigSupport().getLibraries());
                      } catch (ConfigurationException ex) {
                          LOGGER.log(Level.FINE, null, ex);
                          File[] files = j2eePlatformLocal.getClasspathEntries();
                          sortClassPathEntries(files);
                          return files;
                          //return j2eePlatformLocal.getClasspathEntries();
                      }
                  }
              }
          }
          if (j2eePlatform != null) {
              File[] files = j2eePlatform.getClasspathEntries();
              sortClassPathEntries(files);
              return files;
              //return j2eePlatform.getClasspathEntries();
          }
          return new File[] {};
      }
      
      private static void sortClassPathEntries(File[] files) {
          Arrays.sort(files, new Comparator < File > () {
              @Override
              public int compare(File f1, File f2) {
                  return f1.getAbsolutePath().compareTo(f2.getAbsolutePath());
              }
          });
      }

      Attachments

        Issue Links

          Activity

            People

              ЯazoR András Sik
              ЯazoR András Sik
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 4h 40m
                  4h 40m