You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by "András Sik (Jira)" <ji...@apache.org> on 2020/02/22 23:15:00 UTC

[jira] [Updated] (NETBEANS-3575) Fixed ordering j2ee.platform.classpath entires

     [ https://issues.apache.org/jira/browse/NETBEANS-3575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

András Sik updated NETBEANS-3575:
---------------------------------
    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)
{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}

  was:
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.ClassPathUtils.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)
{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}


> 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
>            Priority: Minor
>
> 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)
> {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: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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