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/Util.java b/j2ee.common/src/org/netbeans/modules/j2ee/common/Util.java
--- a/j2ee.common/src/org/netbeans/modules/j2ee/common/Util.java
+++ b/j2ee.common/src/org/netbeans/modules/j2ee/common/Util.java
@@ -226,6 +226,118 @@
}
return false;
}
+
+ /**
+ * Find out if the version of the given profile is at least Java EE 5 or higher.
+ *
+ * @param profile profile that we want to compare
+ * @return true if the version of the given profile is Java EE 5 or higher,
+ * false otherwise
+ * @since 1.75
+ */
+ public static boolean isAtLeastJavaEE5(@NonNull Profile profile) {
+ return isVersionEqualOrHigher(profile, Profile.JAVA_EE_5);
+ }
+
+ /**
+ * Find out if the version of the given profile is at least Java EE 6 Web or
+ * higher.
+ *
+ * @param profile profile that we want to compare
+ * @return true if the version of the given profile is Java EE 6 Web or
+ * higher, false otherwise
+ * @since 1.75
+ */
+ public static boolean isAtLeastJavaEE6(@NonNull Profile profile) {
+ return isVersionEqualOrHigher(profile, Profile.JAVA_EE_6_WEB);
+ }
+
+ /**
+ * 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
+ *
+ *
+ * @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
+ * @since 1.75
+ */
+ private static boolean isVersionEqualOrHigher(
+ @NonNull Profile profileToCompare,
+ @NonNull Profile comparingVersion) {
+
+ int comparisonResult = Profile.UI_COMPARATOR.compare(profileToCompare, comparingVersion);
+ 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 {
+ if (comparisonResult > 0) {
+ // profileToCompare has lower version than comparingVersion
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+ }
+
+ private static boolean compareWebAndFull(
+ @NonNull Profile profileToCompare,
+ @NonNull 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;
+ }
+ if (isThisFullProfile && !isParamFullProfile) {
+ // profileToCompare is Java EE Full profile and comparingVersion is only Java EEWeb profile
+ return true;
+ }
+ return false;
+ }
+
+ private static String getProfileVersion(@NonNull Profile profile) {
+ String profileDetails = profile.toPropertiesString();
+ int indexOfDash = profileDetails.indexOf("-");
+ if (indexOfDash != -1) {
+ return profileDetails.substring(0, indexOfDash);
+ }
+ return profileDetails;
+ }
+
+ private static boolean isFullProfile(@NonNull Profile profile) {
+ final String profileDetails = profile.toPropertiesString();
+ if (profileDetails.indexOf("-") == -1) {
+ return true;
+ }
+ return false;
+ }
/**
* Returns source level of a given project
diff --git a/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/UtilTest.java b/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/UtilTest.java
--- a/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/UtilTest.java
+++ b/j2ee.common/test/unit/src/org/netbeans/modules/j2ee/common/UtilTest.java
@@ -51,9 +51,8 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import org.netbeans.junit.Manager;
+import org.netbeans.api.j2ee.core.Profile;
import org.netbeans.junit.NbTestCase;
-import org.netbeans.modules.j2ee.common.Util;
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
import org.openide.filesystems.FileUtil;
@@ -67,7 +66,28 @@
public UtilTest(String testName) {
super(testName);
}
-
+
+ public void testIsHigherJavaEEVersionJavaEE5() {
+ assertFalse(Util.isAtLeastJavaEE5(Profile.J2EE_13));
+ assertFalse(Util.isAtLeastJavaEE5(Profile.J2EE_14));
+
+ assertTrue(Util.isAtLeastJavaEE5(Profile.JAVA_EE_5));
+ assertTrue(Util.isAtLeastJavaEE5(Profile.JAVA_EE_6_FULL));
+ assertTrue(Util.isAtLeastJavaEE5(Profile.JAVA_EE_6_WEB));
+ assertTrue(Util.isAtLeastJavaEE5(Profile.JAVA_EE_7_FULL));
+ assertTrue(Util.isAtLeastJavaEE5(Profile.JAVA_EE_7_WEB));
+ }
+
+ public void testIsHigherJavaEEVersionJavaEE6full() {
+ assertFalse(Util.isAtLeastJavaEE6(Profile.J2EE_13));
+ assertFalse(Util.isAtLeastJavaEE6(Profile.J2EE_14));
+ assertFalse(Util.isAtLeastJavaEE6(Profile.JAVA_EE_5));
+
+ assertTrue(Util.isAtLeastJavaEE6(Profile.JAVA_EE_6_WEB));
+ assertTrue(Util.isAtLeastJavaEE6(Profile.JAVA_EE_6_FULL));
+ assertTrue(Util.isAtLeastJavaEE6(Profile.JAVA_EE_7_WEB));
+ assertTrue(Util.isAtLeastJavaEE6(Profile.JAVA_EE_7_FULL));
+ }
public void testContainsClass() throws IOException {
File dataDir = getDataDir();