ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r679874 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings: IvySettingsFile.java IvySettingsModel.java
Date Fri, 25 Jul 2008 18:35:28 GMT
Author: xavier
Date: Fri Jul 25 11:35:27 2008
New Revision: 679874

URL: http://svn.apache.org/viewvc?rev=679874&view=rev
Log:
load default settings model on initialization + prevent bug when a dependency of one of Ivy
classes is not available in classpath (eg ant for AntBuildTrigger)

Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java?rev=679874&r1=679873&r2=679874&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
Fri Jul 25 11:35:27 2008
@@ -86,6 +86,15 @@
     }
 
     public Map/*<String,String>*/ getTypedefs() {
+        Map p = getDefaultTypedefs();
+        Matcher m = TYPEDEF_PATTERN.matcher(getDoc());
+        while (m.find()) {
+            p.put(substitute(m.group(1)), substitute(m.group(2)));
+        }
+        return p;
+    }
+
+    public static Map/*<String,String>*/ getDefaultTypedefs() {
         Properties p = new Properties();
         try {
             p.load(XmlSettingsParser.class.getResourceAsStream("typedef.properties"));
@@ -93,10 +102,6 @@
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-        Matcher m = TYPEDEF_PATTERN.matcher(getDoc());
-        while (m.find()) {
-            p.put(substitute(m.group(1)), substitute(m.group(2)));
-        }
         return p;
     }
 

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java?rev=679874&r1=679873&r2=679874&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
Fri Jul 25 11:35:27 2008
@@ -55,6 +55,9 @@
     public IvySettingsModel(IvyModelSettings settings, File file) {
         super(settings);
         this.file = file;
+        this.cl = Ivy.class.getClassLoader();
+        this.typedefClasses = getTypedefClasses(this.cl, IvySettingsFile.getDefaultTypedefs());
+        doLoadModel();
     }
 
     public void refreshIfNeeded(IvyFile file) {
@@ -75,6 +78,11 @@
         cl = getClassLoader(sfile);
         typedefClasses = getTypedefClasses(sfile, cl);
 
+        doLoadModel();
+        loaded = toLoad;
+    }
+
+    private void doLoadModel() {
         IvyTag ivyTag = new IvyTag("ivysettings", "Root tag of Ivy settings file");
 
         ivyTag.addChildIvyTag(new IvyTag("property",  
@@ -215,7 +223,6 @@
         ivyTag.addChildIvyTag(tag);
 
         addTag(ivyTag);
-        loaded = toLoad;
     }
 
     private void addTypedefChildren(IvyTag tag, Map children) {
@@ -249,40 +256,52 @@
             
             private void init() {
                 if (!init) {
-                    Method[] methods = clazz.getMethods();
-                    for (int i = 0; i < methods.length; i++) {
-                        Method m = methods[i];
-                        if (m.getName().startsWith("create") && m.getParameterTypes().length
== 0
-                                && isSupportedChildType(m.getReturnType())) {
-                            String name = StringUtils
-                                    .uncapitalize(m.getName().substring("create".length()));
-                            if (name.length() == 0) {
-                                continue;
-                            }
-                            addChildIvyTag(typedefedTag(name, m.getReturnType()));
-                        } else if (m.getName().startsWith("add")
-                                && m.getParameterTypes().length == 1
-                                && isSupportedChildType(m.getParameterTypes()[0])
-                                && Void.TYPE.equals(m.getReturnType())) {
-                            String name = StringUtils.uncapitalize(m.getName().substring(
-                                        m.getName().startsWith("addConfigured") ? 
-                                                "addConfigured".length() : "add".length()));
-                            if (name.length() == 0) {
-                                addTypedefChildren(this, getChildClasses(typedefClasses,
m.getParameterTypes()[0]));
-                            } else {
-                                addChildIvyTag(typedefedTag(name, m.getParameterTypes()[0]));
+                    try {
+                        Method[] methods = clazz.getMethods();
+                        for (int i = 0; i < methods.length; i++) {
+                            Method m = methods[i];
+                            if (m.getName().startsWith("create") && m.getParameterTypes().length
== 0
+                                    && isSupportedChildType(m.getReturnType())) {
+                                String name = StringUtils
+                                .uncapitalize(m.getName().substring("create".length()));
+                                if (name.length() == 0) {
+                                    continue;
+                                }
+                                addChildIvyTag(typedefedTag(name, m.getReturnType()));
+                            } else if (m.getName().startsWith("add")
+                                    && m.getParameterTypes().length == 1
+                                    && isSupportedChildType(m.getParameterTypes()[0])
+                                    && Void.TYPE.equals(m.getReturnType())) {
+                                String name = StringUtils.uncapitalize(m.getName().substring(
+                                    m.getName().startsWith("addConfigured") ? 
+                                            "addConfigured".length() : "add".length()));
+                                if (name.length() == 0) {
+                                    addTypedefChildren(this, getChildClasses(typedefClasses,
m.getParameterTypes()[0]));
+                                } else {
+                                    addChildIvyTag(typedefedTag(name, m.getParameterTypes()[0]));
+                                }
+                            } else if (m.getName().startsWith("set") 
+                                    && Void.TYPE.equals(m.getReturnType())
+                                    && m.getParameterTypes().length == 1
+                                    && isSupportedAttributeType(m.getParameterTypes()[0]))
{
+                                IvyTagAttribute att = new IvyTagAttribute(
+                                    StringUtils.uncapitalize(m.getName().substring(3)));
+                                if (m.getParameterTypes()[0] == boolean.class) {
+                                    att.setValueProvider(IvyBooleanTagAttribute.VALUE_PROVIDER);
+                                }
+                                addAttribute(att);
                             }
-                        } else if (m.getName().startsWith("set") 
-                                && Void.TYPE.equals(m.getReturnType())
-                                && m.getParameterTypes().length == 1
-                                && isSupportedAttributeType(m.getParameterTypes()[0]))
{
-                            IvyTagAttribute att = new IvyTagAttribute(
-                                        StringUtils.uncapitalize(m.getName().substring(3)));
-                            if (m.getParameterTypes()[0] == boolean.class) {
-                                att.setValueProvider(IvyBooleanTagAttribute.VALUE_PROVIDER);
-                            }
-                            addAttribute(att);
                         }
+                    } catch (NoClassDefFoundError e) {
+                        // we catch this because listing methods may raise a NoClassDefFoundError
+                        // if the class relies on a dependency which is not available in
classpath
+                        getSettings().logError(
+                            "impossible to init tag for " + clazz + ": " + e,
+                            null);
+                    } catch (Exception e) {
+                        getSettings().logError(
+                            "error occured while initializing tag for " + clazz + ": " +
e,
+                            e);
                     }
                     init = true;
                 }
@@ -331,8 +350,12 @@
     }
 
     private Map/*<String,Class>*/ getTypedefClasses(IvySettingsFile file, ClassLoader
cl) {
-        Map/*<String,Class>*/ classes = new LinkedHashMap();
         Map typedefs = file.getTypedefs();
+        return getTypedefClasses(cl, typedefs);
+    }
+
+    private Map getTypedefClasses(ClassLoader cl, Map typedefs) {
+        Map/*<String,Class>*/ classes = new LinkedHashMap();
         for (Iterator it = typedefs.entrySet().iterator(); it.hasNext();) {
             Entry entry = (Entry) it.next();
             try {



Mime
View raw message