diff --git a/j2ee.core/manifest.mf b/j2ee.core/manifest.mf --- a/j2ee.core/manifest.mf +++ b/j2ee.core/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.j2ee.core/0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/core/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.15 +OpenIDE-Module-Specification-Version: 1.16 AutoUpdate-Show-In-Client: false diff --git a/j2ee.core/src/org/netbeans/api/j2ee/core/Profile.java b/j2ee.core/src/org/netbeans/api/j2ee/core/Profile.java --- a/j2ee.core/src/org/netbeans/api/j2ee/core/Profile.java +++ b/j2ee.core/src/org/netbeans/api/j2ee/core/Profile.java @@ -79,26 +79,75 @@ public static final Profile JAVA_EE_7_FULL = new Profile(6, "1.7", null, "JavaEE7Full.displayName"); public static final Profile JAVA_EE_7_WEB = new Profile(7, "1.7", "web", "JavaEE7Web.displayName"); - + private final int order; + private final String canonicalName; + + private final String profileType; + // cache private final String propertiesString; private final String bundleKey; - private Profile(int order, String canonicalName, String profile, String bundleKey) { + private Profile(int order, String canonicalName, String profileType, String bundleKey) { this.order = order; + this.canonicalName = canonicalName; + this.profileType = profileType; this.bundleKey = bundleKey; StringBuilder builder = new StringBuilder(canonicalName); - if (profile != null) { - builder.append("-").append(profile); // NOI18N + if (profileType != null) { + builder.append("-").append(profileType); // NOI18N } this.propertiesString = builder.toString(); } /** + * Finds out if the current profile version is the same or higher in comparison + * to the one from parameter. + * + * @since 1.16 + * @param profile which we are comparing with + * @return true if the profile version is equal or higher than the given one, false otherwise + */ + public boolean isEqualOrHigher(Profile profile) { + int comparison = UI_COMPARATOR.compare(this, profile); + if (comparison < 0) { + // This version is lower than profile version + return false; + + } else if (comparison == 0) { + // The same version for both + return true; + + } else { + // If the canonicalName is the same value we have to differ between Web and Full profile + if (canonicalName.equals(profile.canonicalName)) { + boolean isThisFullProfile = isFullProfile(this); + boolean isParamFullProfile = isFullProfile(profile); + + if (isThisFullProfile && isParamFullProfile) { + // Both profiles are Java EE Full + return true; + } + if (!isThisFullProfile && !isParamFullProfile) { + // Both profiles are Java EE Web + return true; + } + return false; + } else { + return true; + } + } + } + + private boolean isFullProfile(Profile profile) { + return profile.profileType == null; + } + + /** * Returns the UI visible description of the profile. * * @return the UI visible description of the profile diff --git a/j2ee.core/test/unit/src/org/netbeans/api/j2ee/core/ProfileTest.java b/j2ee.core/test/unit/src/org/netbeans/api/j2ee/core/ProfileTest.java --- a/j2ee.core/test/unit/src/org/netbeans/api/j2ee/core/ProfileTest.java +++ b/j2ee.core/test/unit/src/org/netbeans/api/j2ee/core/ProfileTest.java @@ -39,7 +39,6 @@ * * Portions Copyrighted 2009 Sun Microsystems, Inc. */ - package org.netbeans.api.j2ee.core; import org.netbeans.junit.NbTestCase; @@ -64,4 +63,26 @@ assertEquals(Profile.JAVA_EE_6_WEB, Profile.fromPropertiesString("EE_6_WEB")); assertNull(Profile.fromPropertiesString("something")); } + + public void testIsEqualOrHigherJavaEE5() { + assertFalse(Profile.JAVA_EE_5.isEqualOrHigher(Profile.J2EE_13)); + assertFalse(Profile.JAVA_EE_5.isEqualOrHigher(Profile.J2EE_14)); + + assertTrue(Profile.JAVA_EE_5.isEqualOrHigher(Profile.JAVA_EE_5)); + assertTrue(Profile.JAVA_EE_5.isEqualOrHigher(Profile.JAVA_EE_6_FULL)); + assertTrue(Profile.JAVA_EE_5.isEqualOrHigher(Profile.JAVA_EE_6_WEB)); + assertTrue(Profile.JAVA_EE_5.isEqualOrHigher(Profile.JAVA_EE_7_FULL)); + assertTrue(Profile.JAVA_EE_5.isEqualOrHigher(Profile.JAVA_EE_7_WEB)); + } + + public void testIsEqualOrHigherJavaEE6full() { + assertFalse(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.J2EE_13)); + assertFalse(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.J2EE_14)); + assertFalse(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.JAVA_EE_5)); + assertFalse(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.JAVA_EE_6_WEB)); + + assertTrue(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.JAVA_EE_6_FULL)); + assertTrue(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.JAVA_EE_7_FULL)); + assertTrue(Profile.JAVA_EE_6_FULL.isEqualOrHigher(Profile.JAVA_EE_7_WEB)); + } }