You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2013/01/10 14:24:31 UTC
svn commit: r1431345 - in /qpid/proton/branches/jni-binding:
design/api-reconciliation/ design/api-reconciliation/src/
design/api-reconciliation/src/main/ design/api-reconciliation/src/main/java/
design/api-reconciliation/src/main/java/org/ design/api-...
Author: kwall
Date: Thu Jan 10 13:24:30 2013
New Revision: 1431345
URL: http://svn.apache.org/viewvc?rev=1431345&view=rev
Log:
PROTON-191: First version of Proton API Reconciliation tool. Simple standalone tool to reconcile the public functions of the Proton-C API with the methods of the Proton-J API exposed via its interface.
Added:
qpid/proton/branches/jni-binding/design/api-reconciliation/
qpid/proton/branches/jni-binding/design/api-reconciliation/generate-c-functions.sh (with props)
qpid/proton/branches/jni-binding/design/api-reconciliation/pom.xml
qpid/proton/branches/jni-binding/design/api-reconciliation/src/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReader.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Joiner.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Main.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/PackageSearcher.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Reconciliation.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReconciliationReport.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReportRow.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/reportwriter/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriter.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReaderTest.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/JoinerTest.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/PackageSearcherTest.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReconciliationTest.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReportRowTest.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/TestUtils.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/reportwriter/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriterTest.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/DummyClass.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceA.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceB.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/subpackage/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/subpackage/InterfaceInSubPackage.java
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedmany.csv
qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedsingle.csv
qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonCEquivalent.java
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/generate-c-functions.sh
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/generate-c-functions.sh?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/generate-c-functions.sh (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/generate-c-functions.sh Thu Jan 10 13:24:30 2013
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# 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.
+#
+
+BASE_DIR=`dirname $0`
+INCLUDE_DIR=$BASE_DIR/../../proton-c/include/proton
+OUTPUT_DIR=$BASE_DIR/target
+
+mkdir -p $OUTPUT_DIR
+ctags --c-kinds=p -x $INCLUDE_DIR/*.h | awk '{print $1'} > $OUTPUT_DIR/cfunctions.txt
Propchange: qpid/proton/branches/jni-binding/design/api-reconciliation/generate-c-functions.sh
------------------------------------------------------------------------------
svn:executable = *
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/pom.xml
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/pom.xml?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/pom.xml (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/pom.xml Thu Jan 10 13:24:30 2013
@@ -0,0 +1,59 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>proton-api-reconciliation</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.apache.qpid.proton.apireconciliation.Main</mainClass>
+ <arguments>
+ <argument>org.apache.qpid.proton</argument>
+ <argument>target/cfunctions.txt</argument>
+ <argument>target/apireconciliation.csv</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>proton-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections</artifactId>
+ <version>0.9.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReader.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReader.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReader.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReader.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+
+public class CFunctionNameListReader
+{
+
+ public List<String> readCFunctionNames(String fileContainingFunctionNames) throws IOException
+ {
+ File functionNameFile = new File(fileContainingFunctionNames);
+ if (!functionNameFile.canRead())
+ {
+ throw new FileNotFoundException("File " + functionNameFile + " cannot be found or is not readable.");
+ }
+
+ List<String> cFunctionNames = FileUtils.readLines(functionNameFile);
+ return cFunctionNames;
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Joiner.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Joiner.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Joiner.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Joiner.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.qpid.proton.ProtonCEquivalent;
+
+public class Joiner
+{
+ /**
+ * Does an outer join of the supplied C functions with those named by the
+ * {@link ProtonCEquivalent} annotations on the Java methods.
+ */
+ public ReconciliationReport join(List<String> protonCFunctions, Set<Method> javaMethods)
+ {
+ ReconciliationReport report = new ReconciliationReport();
+
+ Map<String, Method> cFunctionToJavaMethodMap = createOneToOneMappingBetweenCFunctionNameAndJavaMethodMap(javaMethods);
+
+ Set<Method> unannotatedMethods = new HashSet<Method>(javaMethods);
+ unannotatedMethods.removeAll(cFunctionToJavaMethodMap.values());
+
+ for (Method unannotatedMethod : unannotatedMethods)
+ {
+ report.addRow(null, unannotatedMethod);
+ }
+
+ for (String protonCFunction : protonCFunctions)
+ {
+ Method javaMethod = cFunctionToJavaMethodMap.remove(protonCFunction);
+ report.addRow(protonCFunction, javaMethod);
+ }
+
+ // add anything remaining in annotatedNameToMethod to report as Java methods with an unknown annotation
+ for (Method method : cFunctionToJavaMethodMap.values())
+ {
+ report.addRow(null, method);
+ }
+
+ return report;
+ }
+
+ private Map<String, Method> createOneToOneMappingBetweenCFunctionNameAndJavaMethodMap(Set<Method> javaMethods)
+ {
+ Map<String, Method> annotatedNameToMethod = new HashMap<String, Method>();
+ Set<String> functionsWithDuplicateJavaMappings = new HashSet<String>();
+
+ for (Method method : javaMethods)
+ {
+ ProtonCEquivalent protonCEquivalent = method.getAnnotation(ProtonCEquivalent.class);
+ if (protonCEquivalent != null)
+ {
+ String functionName = protonCEquivalent.functionName();
+ if (annotatedNameToMethod.containsKey(functionName))
+ {
+ functionsWithDuplicateJavaMappings.add(functionName);
+ }
+ annotatedNameToMethod.put(functionName, method);
+ }
+ }
+
+ // Any functions that had duplicate java method names are removed.
+ for (String functionName : functionsWithDuplicateJavaMappings)
+ {
+ annotatedNameToMethod.remove(functionName);
+ }
+
+ return annotatedNameToMethod;
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Main.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Main.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Main.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Main.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,53 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.util.List;
+
+import org.apache.qpid.proton.apireconciliation.reportwriter.ReconciliationReportWriter;
+
+public class Main
+{
+
+ public static void main(String[] args) throws Exception
+ {
+ if (args.length != 3)
+ {
+ System.err.println("Unexpected number of arguments");
+ Runtime.getRuntime().exit(-1);
+ }
+
+ String packageRootName = args[0];
+ String cFunctionFile = args[1];
+ String outputFile = args[2];
+
+ CFunctionNameListReader cFunctionNameListReader = new CFunctionNameListReader();
+
+ Reconciliation reconciliation = new Reconciliation();
+
+ List<String> cFunctionNames = cFunctionNameListReader.readCFunctionNames(cFunctionFile);
+ ReconciliationReport report = reconciliation.reconcile(cFunctionNames, packageRootName);
+
+ ReconciliationReportWriter writer = new ReconciliationReportWriter();
+ writer.write(outputFile, report);
+ System.err.println("Written : " + outputFile);
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/PackageSearcher.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/PackageSearcher.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/PackageSearcher.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/PackageSearcher.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,50 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.reflections.Reflections;
+import org.reflections.scanners.SubTypesScanner;
+
+public class PackageSearcher
+{
+ @SuppressWarnings("rawtypes")
+ public Set<Method> findMethods(String packageName)
+ {
+ Reflections reflections = new Reflections(packageName, new SubTypesScanner(false));
+ Set<Class<?>> classes = reflections.getSubTypesOf(Object.class);
+
+ // for each class, find methods
+ Set<Method> retVal = new HashSet<Method>();
+ for (Class clazz : classes)
+ {
+ if(clazz.isInterface())
+ {
+ retVal.addAll(Arrays.asList(clazz.getMethods()));
+ }
+ }
+
+ return retVal;
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Reconciliation.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Reconciliation.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Reconciliation.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/Reconciliation.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+
+public class Reconciliation
+{
+ private PackageSearcher _packageSearcher = new PackageSearcher();
+ private Joiner _joiner = new Joiner();
+
+ public ReconciliationReport reconcile(List<String> protonCFunctions, String packageRootName)
+ {
+ Set<Method> javaMethods = _packageSearcher.findMethods(packageRootName);
+ ReconciliationReport report = _joiner.join(protonCFunctions, javaMethods);
+ return report;
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReconciliationReport.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReconciliationReport.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReconciliationReport.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReconciliationReport.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ReconciliationReport
+{
+ private List<ReportRow> _reportRows = new ArrayList<ReportRow>();
+
+ public Iterator<ReportRow> rowIterator()
+ {
+ return _reportRows.iterator();
+ }
+
+ public void addRow(String declaredProtonCFunction, Method javaMethod)
+ {
+ _reportRows.add(new ReportRow(declaredProtonCFunction, javaMethod));
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReportRow.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReportRow.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReportRow.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/ReportRow.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.lang.reflect.Method;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+public class ReportRow
+{
+ private final String _declaredProtonCFunction;
+ private final Method _javaMethod;
+
+ public ReportRow(String declaredProtonCFunction, Method javaMethod)
+ {
+ _declaredProtonCFunction = declaredProtonCFunction;
+ _javaMethod = javaMethod;
+ }
+
+ public String getCFunction()
+ {
+ return _declaredProtonCFunction;
+ }
+
+ public Method getJavaMethod()
+ {
+ return _javaMethod;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder().append(_declaredProtonCFunction)
+ .append(_javaMethod)
+ .toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj.getClass() != getClass())
+ {
+ return false;
+ }
+ ReportRow rhs = (ReportRow) obj;
+ return new EqualsBuilder()
+ .append(_declaredProtonCFunction, rhs._declaredProtonCFunction)
+ .append(_javaMethod, rhs._javaMethod)
+ .isEquals();
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this)
+ .append("_declaredProtonCFunction", _declaredProtonCFunction)
+ .append("_javaMethod", _javaMethod)
+ .toString();
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriter.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriter.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriter.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/main/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriter.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.qpid.proton.apireconciliation.reportwriter;
+
+import static java.lang.String.format;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.qpid.proton.ProtonCEquivalent;
+import org.apache.qpid.proton.apireconciliation.ReconciliationReport;
+import org.apache.qpid.proton.apireconciliation.ReportRow;
+
+public class ReconciliationReportWriter
+{
+ private static final String ROW_FORMAT="%s,%s,%s";
+ private static final String REPORT_TITLE = format(ROW_FORMAT, "C function","Java Method","Java Annotation");
+
+ public void write(String outputFile, ReconciliationReport report) throws IOException
+ {
+ File output = new File(outputFile);
+ List<String> reportLines = new ArrayList<String>();
+
+ reportLines.add(REPORT_TITLE);
+
+ Iterator<ReportRow> itr = report.rowIterator();
+ while (itr.hasNext())
+ {
+ ReportRow row = itr.next();
+ Method javaMethod = row.getJavaMethod();
+ String cFunction = row.getCFunction() == null ? "" : row.getCFunction();
+ String fullyQualifiedMethodName = createFullyQualifiedJavaMethodName(javaMethod);
+ String annotationCFunction = extractCFunctionNameFromAnnotation(javaMethod);
+
+ reportLines.add(format(ROW_FORMAT, cFunction, fullyQualifiedMethodName, annotationCFunction));
+ }
+
+ FileUtils.writeLines(output, reportLines);
+ }
+
+ private String extractCFunctionNameFromAnnotation(Method javaMethod)
+ {
+ if (javaMethod != null && javaMethod.getAnnotation(ProtonCEquivalent.class) != null)
+ {
+ return javaMethod.getAnnotation(ProtonCEquivalent.class).functionName();
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+ private String createFullyQualifiedJavaMethodName(Method javaMethod)
+ {
+ if (javaMethod != null)
+ {
+ return javaMethod.getDeclaringClass().getName() + "#" + javaMethod.getName();
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReaderTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReaderTest.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReaderTest.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/CFunctionNameListReaderTest.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,54 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+
+public class CFunctionNameListReaderTest
+{
+
+ private CFunctionNameListReader _cFunctionDeclarationReader = new CFunctionNameListReader();
+
+ @Test
+ public void testReadFileContainingSingleCFunction() throws Exception
+ {
+ String declarationFile = createTestFileContaining("function1", "function2", "function3");
+
+ List<String> functions = _cFunctionDeclarationReader.readCFunctionNames(declarationFile);
+ assertEquals(3, functions.size());
+ assertEquals("function1", functions.get(0));
+ assertEquals("function3", functions.get(2));
+ }
+
+ private String createTestFileContaining(String... functionNames) throws Exception
+ {
+ File file = File.createTempFile(CFunctionNameListReader.class.getSimpleName(), "txt");
+ file.deleteOnExit();
+ FileUtils.writeLines(file, Arrays.asList(functionNames));
+ return file.getAbsolutePath();
+ }
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/JoinerTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/JoinerTest.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/JoinerTest.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/JoinerTest.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,163 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Method;
+import static java.util.Arrays.asList;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.qpid.proton.ProtonCEquivalent;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JoinerTest
+{
+ private static final String C_FUNCTION1 = "cFunction1";
+ private static final String C_FUNCTION2 = "cFunction2";
+ private Joiner _joiner = new Joiner();
+ private Method _method1 = null;
+ private Method _method2 = null;
+ private Method _methodSharingFunctionNameAnnotationWithMethod2 = null;
+ private Method _methodWithoutAnnotation;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ _method1 = getClass().getMethod("javaMethodWithMapping1");
+ _method2 = getClass().getMethod("javaMethodWithMapping2");
+ _methodSharingFunctionNameAnnotationWithMethod2 = getClass().getMethod("javaMethodSharingFunctionNameAnnotationWithMethod2");
+ _methodWithoutAnnotation = getClass().getMethod("javaMethodWithoutAnnotation");
+ }
+
+ @Test
+ public void testSingleRowReport() throws Exception
+ {
+ List<String> protonCFunctions = asList(C_FUNCTION1);
+ Set<Method> javaMethods = new HashSet<Method>(asList(_method1));
+
+ ReconciliationReport reconciliationReport = _joiner.join(protonCFunctions, javaMethods);
+ assertSingleRowEquals(reconciliationReport, C_FUNCTION1, _method1);
+ }
+
+ @Test
+ public void testCFunctionWithoutCorrespondingAnnotatedJavaMethod() throws Exception
+ {
+ List<String> protonCFunctions = asList("functionX");
+ Set<Method> javaMethods = Collections.emptySet();
+
+ ReconciliationReport reconciliationReport = _joiner.join(protonCFunctions, javaMethods);
+ assertSingleRowEquals(reconciliationReport, "functionX", null);
+ }
+
+ @Test
+ public void testJavaMethodAnnotatedWithUnknownCFunctionName() throws Exception
+ {
+ List<String> protonCFunctions = Collections.emptyList();
+ Set<Method> javaMethods = new HashSet<Method>(asList(_method1));
+
+ ReconciliationReport reconciliationReport = _joiner.join(protonCFunctions, javaMethods);
+ assertSingleRowEquals(reconciliationReport, null, _method1);
+ }
+
+ @Test
+ public void testJavaMethodWithoutAnnotation() throws Exception
+ {
+ List<String> protonCFunctions = Collections.emptyList();
+ Set<Method> javaMethods = new HashSet<Method>(asList(_methodWithoutAnnotation));
+
+ ReconciliationReport reconciliationReport = _joiner.join(protonCFunctions, javaMethods);
+ assertSingleRowEquals(reconciliationReport, null, _methodWithoutAnnotation);
+ }
+
+ @Test
+ public void testJavaMethodsWithAnnotationToSameFunction() throws Exception
+ {
+ List<String> protonCFunctions = asList(C_FUNCTION2);
+ Set<Method> javaMethods = new HashSet<Method>(asList(_method2, _methodSharingFunctionNameAnnotationWithMethod2));
+
+ ReconciliationReport reconciliationReport = _joiner.join(protonCFunctions, javaMethods);
+ Set<ReportRow> rowSet = TestUtils.getReportRowsFrom(reconciliationReport);
+
+ Set<ReportRow> expectedRowSet = new HashSet<ReportRow>(asList(
+ new ReportRow(C_FUNCTION2, null),
+ new ReportRow(null, _method2),
+ new ReportRow(null, _methodSharingFunctionNameAnnotationWithMethod2)));
+
+ assertEquals(expectedRowSet, rowSet);
+ }
+
+ @Test
+ public void testMultipleRowReport() throws Exception
+ {
+ List<String> protonCFunctions = asList(C_FUNCTION1, C_FUNCTION2);
+ Set<Method> javaMethods = new HashSet<Method>(asList(_method1, _method2));
+
+ ReconciliationReport reconciliationReport = _joiner.join(protonCFunctions, javaMethods);
+
+ Set<ReportRow> rowSet = TestUtils.getReportRowsFrom(reconciliationReport);
+
+ Set<ReportRow> expectedRowSet = new HashSet<ReportRow>(asList(
+ new ReportRow(C_FUNCTION1, _method1),
+ new ReportRow(C_FUNCTION2, _method2)));
+
+ assertEquals(expectedRowSet,rowSet);
+ }
+
+ private void assertSingleRowEquals(ReconciliationReport reconciliationReport, String expectedCFunctionName, Method expectedJavaMethod)
+ {
+ Iterator<ReportRow> rowIterator = reconciliationReport.rowIterator();
+ ReportRow row = rowIterator.next();
+ assertReportRowEquals(row, expectedCFunctionName, expectedJavaMethod);
+
+ assertFalse(rowIterator.hasNext());
+ }
+
+ private void assertReportRowEquals(ReportRow row, String expectedCFunctionName, Method expectedMethod)
+ {
+ assertEquals(expectedCFunctionName, row.getCFunction());
+ assertEquals(expectedMethod, row.getJavaMethod());
+ }
+
+ @ProtonCEquivalent(functionName=C_FUNCTION1)
+ public void javaMethodWithMapping1()
+ {
+ }
+
+ @ProtonCEquivalent(functionName=C_FUNCTION2)
+ public void javaMethodWithMapping2()
+ {
+ }
+
+ @ProtonCEquivalent(functionName=C_FUNCTION2)
+ public void javaMethodSharingFunctionNameAnnotationWithMethod2()
+ {
+ }
+
+ public void javaMethodWithoutAnnotation()
+ {
+ }
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/PackageSearcherTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/PackageSearcherTest.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/PackageSearcherTest.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/PackageSearcherTest.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.qpid.proton.ProtonCEquivalent;
+import org.apache.qpid.proton.apireconciliation.testdata.InterfaceA;
+import org.apache.qpid.proton.apireconciliation.testdata.InterfaceB;
+import org.apache.qpid.proton.apireconciliation.testdata.subpackage.InterfaceInSubPackage;
+import org.junit.Test;
+
+public class PackageSearcherTest
+{
+ @Test
+ public void testFindMethods() throws Exception
+ {
+ PackageSearcher packageSearcher = new PackageSearcher();
+
+ Set<Method> actualMethods = packageSearcher.findMethods(InterfaceA.class.getPackage().getName());
+ assertEquals(3, actualMethods.size());
+
+ Set<Method> expectedMethods = new HashSet<Method>(Arrays.asList(
+ InterfaceA.class.getMethod(InterfaceA.methodA1),
+ InterfaceB.class.getMethod(InterfaceB.methodWithoutAnnotation),
+ InterfaceInSubPackage.class.getMethod(InterfaceInSubPackage.methodWithinSubpackage)
+ ));
+
+ assertEquals(expectedMethods, actualMethods);
+ }
+
+ @Test
+ public void testFindMethodsRetainsAnnotations() throws Exception
+ {
+ PackageSearcher packageSearcher = new PackageSearcher();
+
+ Set<Method> actualMethods = packageSearcher.findMethods(InterfaceInSubPackage.class.getPackage().getName());
+ assertEquals(1, actualMethods.size());
+
+ Method actualMethod = actualMethods.iterator().next();
+ assertEquals("subpackageFunction",
+ actualMethod.getAnnotation(ProtonCEquivalent.class).functionName());
+ }
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReconciliationTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReconciliationTest.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReconciliationTest.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReconciliationTest.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.qpid.proton.apireconciliation.testdata.InterfaceA;
+import org.apache.qpid.proton.apireconciliation.testdata.InterfaceB;
+import org.apache.qpid.proton.apireconciliation.testdata.subpackage.InterfaceInSubPackage;
+import org.junit.Test;
+
+public class ReconciliationTest
+{
+ private static final List<String> LIST_OF_C_FUNCTIONS = Arrays.asList(InterfaceA.cFunction1, InterfaceInSubPackage.cFunction);
+ private static final String TEST_PACKAGE_TREE_ROOT = "org.apache.qpid.proton.apireconciliation.testdata";
+
+ @Test
+ public void test() throws Exception
+ {
+ Method method = InterfaceA.class.getMethod(InterfaceA.methodA1);
+ Method unmappedMethod = InterfaceB.class.getMethod(InterfaceB.methodWithoutAnnotation);
+ Method methodWithinSubpackage = InterfaceInSubPackage.class.getMethod(InterfaceInSubPackage.methodWithinSubpackage);
+
+ Reconciliation reconciliation = new Reconciliation();
+ ReconciliationReport report = reconciliation.reconcile(LIST_OF_C_FUNCTIONS, TEST_PACKAGE_TREE_ROOT);
+ Set<ReportRow> rowSet = TestUtils.getReportRowsFrom(report);
+
+ Set<ReportRow> expectedRowSet = new HashSet<ReportRow>(asList(
+ new ReportRow(InterfaceA.cFunction1, method),
+ new ReportRow(InterfaceInSubPackage.cFunction, methodWithinSubpackage),
+ new ReportRow(null, unmappedMethod)));
+
+ assertEquals(expectedRowSet,rowSet);
+ }
+
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReportRowTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReportRowTest.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReportRowTest.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/ReportRowTest.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Method;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ReportRowTest
+{
+
+ private Method _javaMethod1;
+ private Method _javaMethod2;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ _javaMethod1 = getClass().getMethod("javaMethod1");
+ _javaMethod2 = getClass().getMethod("javaMethod2");
+ }
+
+ @Test
+ public void testSames() throws Exception
+ {
+
+ ReportRow reportRow = new ReportRow("cfunction", _javaMethod1);
+ Object other = new Object();
+
+ assertTrue(reportRow.equals(reportRow));
+ assertFalse(reportRow.equals(other));
+ }
+
+ @Test
+ public void testEquals() throws Exception
+ {
+
+ assertTrue(new ReportRow("cfunction", _javaMethod1).equals(new ReportRow("cfunction", _javaMethod1)));
+
+ assertFalse(new ReportRow("cfunction", _javaMethod1).equals(new ReportRow("cfunction2", _javaMethod1)));
+ assertFalse(new ReportRow("cfunction2", _javaMethod1).equals(new ReportRow("cfunction2", _javaMethod2)));
+
+ assertFalse(new ReportRow("cfunction", _javaMethod1).equals(null));
+
+ }
+
+ @Test
+ public void testEqualsWithNulls() throws Exception
+ {
+ assertTrue(new ReportRow("cfunction", null).equals(new ReportRow("cfunction", null)));
+ assertTrue(new ReportRow(null, _javaMethod1).equals(new ReportRow(null, _javaMethod1)));
+
+ assertFalse(new ReportRow("cfunction", _javaMethod1).equals(new ReportRow("cfunction", null)));
+ assertFalse(new ReportRow("cfunction", _javaMethod1).equals(new ReportRow(null, _javaMethod1)));
+ }
+
+ // Used by reflection by test methods
+ public void javaMethod1()
+ {
+ }
+
+ // Used by reflection by test methods
+ public void javaMethod2()
+ {
+ }
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/TestUtils.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/TestUtils.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/TestUtils.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/TestUtils.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,38 @@
+/*
+ * 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.qpid.proton.apireconciliation;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class TestUtils
+{
+ public static Set<ReportRow> getReportRowsFrom(ReconciliationReport reconciliationReport)
+ {
+ Iterator<ReportRow> rowIterator = reconciliationReport.rowIterator();
+ Set<ReportRow> rows = new HashSet<ReportRow>();
+ while (rowIterator.hasNext())
+ {
+ rows.add(rowIterator.next());
+ }
+ return rows;
+ }
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriterTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriterTest.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriterTest.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/reportwriter/ReconciliationReportWriterTest.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,103 @@
+/*
+ * 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.qpid.proton.apireconciliation.reportwriter;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.qpid.proton.ProtonCEquivalent;
+import org.apache.qpid.proton.apireconciliation.ReconciliationReport;
+import org.junit.Test;
+
+
+public class ReconciliationReportWriterTest
+{
+ private ReconciliationReportWriter _writer = new ReconciliationReportWriter();
+ private ReconciliationReport _report = new ReconciliationReport();
+
+ @Test
+ public void testReportWithSingleFullyMappedRow() throws Exception
+ {
+ File expectedReport = getClasspathResource("expectedsingle.csv");
+ File outputFile = createTemporaryFile();
+
+ _report.addRow("function1", getClass().getMethod("methodWithMapping"));
+ _writer.write(outputFile.getAbsolutePath(), _report);
+
+ assertFilesSame(expectedReport, outputFile);
+ }
+
+ @Test
+ public void testReportWithManyRowsSomeUnmapped() throws Exception
+ {
+ File expectedReport = getClasspathResource("expectedmany.csv");
+ File outputFile = createTemporaryFile();
+
+ _report.addRow("function1", getClass().getMethod("methodWithMapping"));
+ _report.addRow("function2", getClass().getMethod("anotherMethodWithMapping"));
+ _report.addRow(null, getClass().getMethod("methodWithoutMapping"));
+ _report.addRow("function4", null);
+ _writer.write(outputFile.getAbsolutePath(), _report);
+
+ assertFilesSame(expectedReport, outputFile);
+ }
+
+ private File getClasspathResource(String filename) throws URISyntaxException
+ {
+ URL resource = getClass().getResource(filename);
+ assertNotNull("Resource " + filename + " could not be found",resource);
+ return new File(resource.toURI());
+ }
+
+ private File createTemporaryFile() throws Exception
+ {
+ File tmpFile = File.createTempFile(getClass().getSimpleName(), "csv");
+ tmpFile.deleteOnExit();
+ return tmpFile;
+ }
+
+ private void assertFilesSame(File expectedReport, File actualReport) throws IOException
+ {
+ assertTrue(expectedReport.canRead());
+ assertTrue(actualReport.canRead());
+ assertEquals("Report contents unexpected",
+ FileUtils.readFileToString(expectedReport),
+ FileUtils.readFileToString(actualReport));
+ }
+
+ @ProtonCEquivalent(functionName="function1")
+ public void methodWithMapping()
+ {
+ }
+
+ @ProtonCEquivalent(functionName="function2")
+ public void anotherMethodWithMapping()
+ {
+ }
+
+ public void methodWithoutMapping()
+ {
+ }
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/DummyClass.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/DummyClass.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/DummyClass.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/DummyClass.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.qpid.proton.apireconciliation.testdata;
+
+import org.apache.qpid.proton.apireconciliation.PackageSearcher;
+
+/**
+ * Methods on classes should be ignored by {@link PackageSearcher}
+ */
+public class DummyClass
+{
+ public void dummyClassMethod()
+ {
+ };
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceA.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceA.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceA.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceA.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.qpid.proton.apireconciliation.testdata;
+
+import org.apache.qpid.proton.ProtonCEquivalent;
+
+public interface InterfaceA
+{
+ String cFunction1 = "function1";
+ String methodA1 = "methodA1";
+
+ @ProtonCEquivalent(functionName=cFunction1)
+ void methodA1();
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceB.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceB.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceB.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/InterfaceB.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,27 @@
+/*
+ * 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.qpid.proton.apireconciliation.testdata;
+
+
+public interface InterfaceB
+{
+ String methodWithoutAnnotation = "methodWithoutAnnotation";
+
+ void methodWithoutAnnotation();
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/subpackage/InterfaceInSubPackage.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/subpackage/InterfaceInSubPackage.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/subpackage/InterfaceInSubPackage.java (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/java/org/apache/qpid/proton/apireconciliation/testdata/subpackage/InterfaceInSubPackage.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.qpid.proton.apireconciliation.testdata.subpackage;
+
+import org.apache.qpid.proton.ProtonCEquivalent;
+
+public interface InterfaceInSubPackage
+{
+ String cFunction = "subpackageFunction";
+ String methodWithinSubpackage = "methodWithinSubpackage";
+
+ @ProtonCEquivalent(functionName = cFunction)
+ void methodWithinSubpackage();
+}
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedmany.csv
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedmany.csv?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedmany.csv (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedmany.csv Thu Jan 10 13:24:30 2013
@@ -0,0 +1,5 @@
+C function,Java Method,Java Annotation
+function1,org.apache.qpid.proton.apireconciliation.reportwriter.ReconciliationReportWriterTest#methodWithMapping,function1
+function2,org.apache.qpid.proton.apireconciliation.reportwriter.ReconciliationReportWriterTest#anotherMethodWithMapping,function2
+,org.apache.qpid.proton.apireconciliation.reportwriter.ReconciliationReportWriterTest#methodWithoutMapping,
+function4,,
Added: qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedsingle.csv
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedsingle.csv?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedsingle.csv (added)
+++ qpid/proton/branches/jni-binding/design/api-reconciliation/src/test/resources/org/apache/qpid/proton/apireconciliation/reportwriter/expectedsingle.csv Thu Jan 10 13:24:30 2013
@@ -0,0 +1,2 @@
+C function,Java Method,Java Annotation
+function1,org.apache.qpid.proton.apireconciliation.reportwriter.ReconciliationReportWriterTest#methodWithMapping,function1
Added: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonCEquivalent.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonCEquivalent.java?rev=1431345&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonCEquivalent.java (added)
+++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonCEquivalent.java Thu Jan 10 13:24:30 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.qpid.proton;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used to mark which function in Proton-C a Proton-J method corresponds to,
+ * for API reconciliation purposes.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ProtonCEquivalent
+{
+ String functionName();
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org