1 /* Copyright 2004-2005 Graeme Rocher
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 package org
.codehaus
.groovy
.grails
.plugins
;
18 * Utility class containing methods that aid in loading and evaluating plug-ins
20 * @author Graeme Rocher
23 * Created: Nov 29, 2007
25 public class GrailsPluginUtils
{
27 static final String WILDCARD
= "*";
28 static final COMPARATOR
= [compare
: { o1
, o2
->
30 if(o1
== '*') result
= 1
31 else if(o2
== '*') result
= -1
33 def nums1
= o1
.split(/\
./).findAll
{ it
.trim() != ''}*.toInteger()
34 def nums2
= o2
.split(/\
./).findAll
{ it
.trim() != ''}*.toInteger()
35 for(i in
0..<nums1
.size()) {
36 if(nums2
.size() > i
) {
37 result
= nums1
[i
].compareTo(nums2
[i
])
44 equals
: { false }] as Comparator
47 * Check if the required version is a valid for the given plugin version
49 * @param pluginVersion The plugin version
50 * @param requiredVersion The required version
51 * @return True if it is valid
53 public static boolean isValidVersion(String pluginVersion
, String requiredVersion
) {
55 pluginVersion
= trimTag(pluginVersion
);
57 if(requiredVersion
.indexOf('>')>-1) {
58 def tokens
= requiredVersion
.split(">")*.trim()
61 newTokens
<< trimTag(t
)
64 tokens
<< pluginVersion
65 tokens
= tokens
.sort(COMPARATOR
)
67 if(tokens
[1] == pluginVersion
) return true
70 else if(pluginVersion
.equals(trimTag(requiredVersion
))) return true;
74 private static trimTag(pluginVersion
) {
75 def i
= pluginVersion
.indexOf('-')
77 pluginVersion
= pluginVersion
[0..i
-1]