András Sik created NETBEANS-3575:
------------------------------------

             Summary: Fixed ordering j2ee.platform.classpath entires
                 Key: NETBEANS-3575
                 URL: https://issues.apache.org/jira/browse/NETBEANS-3575
             Project: NetBeans
          Issue Type: Improvement
            Reporter: András Sik


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 varios version management systems. (They tend to mark this line as 
changed

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.ClassPathUtils.java, in cases 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)
{code:java}
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());
        }
    });
}{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to