You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/09/29 10:07:05 UTC

svn commit: r819856 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/

Author: davsclaus
Date: Tue Sep 29 08:07:05 2009
New Revision: 819856

URL: http://svn.apache.org/viewvc?rev=819856&view=rev
Log:
MR-187: Moved tooling code from camel-core to tooling.

Added:
    camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java   (with props)
    camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java   (with props)
Removed:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterLoader.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterRegistry.java
Modified:
    camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java

Modified: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java?rev=819856&r1=819855&r2=819856&view=diff
==============================================================================
--- camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java (original)
+++ camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java Tue Sep 29 08:07:05 2009
@@ -32,9 +32,6 @@
 import java.util.TreeSet;
 
 import org.apache.camel.impl.DefaultPackageScanClassResolver;
-import org.apache.camel.impl.ReportingTypeConverterLoader;
-import org.apache.camel.impl.ReportingTypeConverterLoader.TypeMapping;
-import org.apache.camel.impl.ReportingTypeConverterRegistry;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -323,7 +320,7 @@
         }
     }
 
-    private void generateReport(Sink sink, Locale locale, TypeMapping[] mappings)
+    private void generateReport(Sink sink, Locale locale, ReportingTypeConverterLoader.TypeMapping[] mappings)
         throws MojoExecutionException {
         beginReport(sink, locale);
 
@@ -335,7 +332,7 @@
         sink.table();
         tableHeader(sink, locale);
 
-        for (TypeMapping mapping : mappings) {
+        for (ReportingTypeConverterLoader.TypeMapping mapping : mappings) {
             boolean ignored = false;
             Class<?> from = mapping.getFromType();
             Class<?> to = mapping.getToType();

Added: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java?rev=819856&view=auto
==============================================================================
--- camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java (added)
+++ camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java Tue Sep 29 08:07:05 2009
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.converter.AnnotationTypeConverterLoader;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Type converter loader that is capable of reporting the loaded type converters.
+ * <p/>
+ * Used by the camel-maven-plugin.
+ *
+ * @version $Revision$
+ */
+public class ReportingTypeConverterLoader extends AnnotationTypeConverterLoader {
+
+    private static final Comparator<TypeMapping> COMPARE_LAST_LOADED_FIRST = new Comparator<TypeMapping>() {
+        public int compare(TypeMapping t1, TypeMapping t2) {
+            if (ObjectHelper.equal(t1.fromType, t2.fromType)) {
+                return ObjectHelper.equal(t1.toType, t2.toType) ? t1.index - t2.index : ObjectHelper
+                    .compare(getTypeName(t1.toType), getTypeName(t2.toType));
+            }
+            return ObjectHelper.compare(getTypeName(t1.fromType), getTypeName(t2.fromType));
+        }
+
+    };
+
+    private final List<TypeMapping> typeMappings = new ArrayList<TypeMapping>();
+
+    public ReportingTypeConverterLoader(PackageScanClassResolver resolver) {
+        super(resolver);
+    }
+
+    public TypeMapping[] getTypeConversions() {
+        Collections.sort(typeMappings, COMPARE_LAST_LOADED_FIRST);
+        return typeMappings.toArray(new TypeMapping[typeMappings.size()]);
+    }
+
+    protected void registerTypeConverter(TypeConverterRegistry registry, Method method, Class toType,
+                                         Class fromType, TypeConverter typeConverter) {
+
+        TypeMapping mapping = new TypeMapping(toType, fromType, typeConverter.getClass(), method);
+        typeMappings.add(mapping);
+    }
+
+    private static String getTypeName(Class type) {
+        return type != null ? type.getName() : null;
+    }
+
+    /**
+     * Represents a mapping from one type (which can be null) to another
+     *
+     * Used by the camel-maven-plugin.
+     */
+    public static class TypeMapping {
+        private static int counter;
+        private final Class toType;
+        private final Class fromType;
+        private final Class converterType;
+        private final Method method;
+        private final int index;
+
+        public TypeMapping(Class toType, Class fromType, Class converterType, Method method) {
+            this.toType = toType;
+            this.fromType = fromType;
+            this.converterType = converterType;
+            this.method = method;
+            this.index = counter++;
+        }
+
+        public Class getFromType() {
+            return fromType;
+        }
+
+        public Class getToType() {
+            return toType;
+        }
+
+        public Class getConverterType() {
+            return converterType;
+        }
+
+        public Method getMethod() {
+            return method;
+        }
+
+        public int getIndex() {
+            return index;
+        }
+
+        @Override
+        public boolean equals(Object object) {
+            if (object instanceof TypeMapping) {
+                TypeMapping that = (TypeMapping)object;
+                return this.index == that.index;
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            int answer = toType.hashCode();
+            if (fromType != null) {
+                answer *= 37 + fromType.hashCode();
+            }
+            return answer;
+        }
+
+        @Override
+        public String toString() {
+            return "[" + fromType.getSimpleName() + "=>" + toType.getSimpleName() + "]";
+        }
+    }
+
+}

Propchange: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java?rev=819856&view=auto
==============================================================================
--- camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java (added)
+++ camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java Tue Sep 29 08:07:05 2009
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.Injector;
+import org.apache.camel.spi.TypeConverterRegistry;
+
+/**
+ * Registry for reporting type converters.
+ * <p/>
+ * Used by the camel-maven-plugin.
+ *
+ * @version $Revision$
+ */
+public class ReportingTypeConverterRegistry implements TypeConverterRegistry {
+    private final List<String> errors = new ArrayList<String>();
+
+    public String[] getErrors() {
+        return errors.toArray(new String[errors.size()]);
+    }
+
+    public void addTypeConverter(Class toType, Class fromType, TypeConverter typeConverter) {
+        if (errors.size() == 0) {
+            errors.add("Method should not be invoked.");
+        }
+    }
+
+    public void addFallbackTypeConverter(TypeConverter typeConverter) {
+        if (errors.size() == 0) {
+            errors.add("Method should not be invoked.");
+        }
+    }
+
+    public TypeConverter lookup(Class toType, Class fromType) {
+        if (errors.size() == 0) {
+            errors.add("Method should not be invoked.");
+        }
+        return null;
+    }
+
+    public void setInjector(Injector injector) {
+        if (errors.size() == 0) {
+            errors.add("Method should not be invoked.");
+        }
+    }
+
+    public Injector getInjector() {
+        return null;
+    }
+
+}

Propchange: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ReportingTypeConverterRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date