diff --git a/j2ee.common/manifest.mf b/j2ee.common/manifest.mf --- a/j2ee.common/manifest.mf +++ b/j2ee.common/manifest.mf @@ -2,5 +2,5 @@ OpenIDE-Module: org.netbeans.modules.j2ee.common/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/common/Bundle.properties OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker -OpenIDE-Module-Specification-Version: 1.74 +OpenIDE-Module-Specification-Version: 1.75 AutoUpdate-Show-In-Client: false diff --git a/j2ee.common/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilities.java b/j2ee.common/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilities.java --- a/j2ee.common/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilities.java +++ b/j2ee.common/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilities.java @@ -153,6 +153,82 @@ return EjbSupport.getInstance(platform).isEjb31LiteSupported(platform); } + /** + * Compares if the first given profile has equal or higher Java EE version + * in comparison to the second profile. + * + * Please be aware of the following rules: + *

+ * + * 1) Each Java EE X version is considered as lower than Java EE X+1 version + * (this applies regardless on Web/Full specification and in reality it means + * that even Java EE 6 Full version is considered as lower than Java EE 7 Web) + *

+ * + * 2) Each Java EE X Web version is considered as lower than Java EE X Full + *
+ * + * @since 1.75 + * @param profileToCompare profile that we want to compare + * @param comparingVersion version which we are comparing with + * @return true if the profile version is equal or higher in + * comparison with the second one, false otherwise + */ + public static boolean isVersionEqualOrHigher(Profile profileToCompare, Profile comparingVersion) { + int comparisonResult = Profile.UI_COMPARATOR.compare(profileToCompare, comparingVersion); + if (comparisonResult < 0) { + // This version is lower than profile version + return false; + + } else if (comparisonResult == 0) { + // The same version for both + return true; + + } else { + String profileToCompareVersion = getProfileVersion(profileToCompare); + String comparingProfileVersion = getProfileVersion(comparingVersion); + + // If the canonicalName is the same value we have to differ between Web and Full profile + if (profileToCompareVersion.equals(comparingProfileVersion)) { + return compareWebAndFull(profileToCompare, comparingVersion); + } else { + return true; + } + } + } + + private static boolean compareWebAndFull(Profile profileToCompare, Profile comparingVersion) { + boolean isThisFullProfile = isFullProfile(profileToCompare); + boolean isParamFullProfile = isFullProfile(comparingVersion); + + if (isThisFullProfile && isParamFullProfile) { + // Both profiles are Java EE Full + return true; + } + if (!isThisFullProfile && !isParamFullProfile) { + // Both profiles are Java EE Web + return true; + } + return false; + } + + private static String getProfileVersion(Profile profile) { + String profileDetails = profile.toPropertiesString(); + int indexOfDash = profileDetails.indexOf("-"); + if (indexOfDash != -1) { + return profileDetails.substring(0, indexOfDash); + } + return profileDetails; + } + + private static boolean isFullProfile(Profile profile) { + final String profileDetails = profile.toPropertiesString(); + if (profileDetails.indexOf("-") == -1) { + return true; + } + return false; + } + public boolean hasDefaultPersistenceProvider() { J2eePlatform platform = Util.getPlatform(project); if (platform == null) { diff --git a/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilitiesTest.java b/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilitiesTest.java --- a/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilitiesTest.java +++ b/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/J2eeProjectCapabilitiesTest.java @@ -72,6 +72,28 @@ super(testName); } + public void testIsHigherJavaEEVersionJavaEE5() { + assertFalse(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.J2EE_13)); + assertFalse(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.J2EE_14)); + + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.JAVA_EE_5)); + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.JAVA_EE_6_FULL)); + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.JAVA_EE_6_WEB)); + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.JAVA_EE_7_FULL)); + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_5, Profile.JAVA_EE_7_WEB)); + } + + public void testIsHigherJavaEEVersionJavaEE6full() { + assertFalse(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.J2EE_13)); + assertFalse(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.J2EE_14)); + assertFalse(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.JAVA_EE_5)); + assertFalse(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.JAVA_EE_6_WEB)); + + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.JAVA_EE_6_FULL)); + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.JAVA_EE_7_WEB)); + assertTrue(J2eeProjectCapabilities.isVersionEqualOrHigher(Profile.JAVA_EE_6_FULL, Profile.JAVA_EE_7_FULL)); + } + public void testIsEjbSupported() throws Exception { Project p = createProject(Profile.JAVA_EE_5, Type.EJB); J2eeProjectCapabilities cap = J2eeProjectCapabilities.forProject(p);