You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2015/01/01 13:23:10 UTC
svn commit: r1648828 - in /webservices/axiom/branches/apicheck: ./
apicheck/apicheck-maven-plugin/
apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/
apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/
a...
Author: veithen
Date: Thu Jan 1 12:23:10 2015
New Revision: 1648828
URL: http://svn.apache.org/r1648828
Log:
Initial custom API checker code.
Added:
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/APIChecker.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingClassVisitor.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingMethodVisitor.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ClassElement.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/Element.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/MethodElement.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ViolationListener.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/APICheckerTest.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ForbiddenClass.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/MockViolationListener.java (with props)
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ViolatingClass.java (with props)
Modified:
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/pom.xml
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/AbstractCheckMojo.java
webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/resources/org/apache/axiom/apicheck/signatures.txt
webservices/axiom/branches/apicheck/pom.xml
webservices/axiom/branches/apicheck/testing/dom-testsuite/pom.xml
Modified: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/pom.xml?rev=1648828&r1=1648827&r2=1648828&view=diff
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/pom.xml (original)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/pom.xml Thu Jan 1 12:23:10 2015
@@ -49,6 +49,20 @@
<artifactId>forbiddenapis-core</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/AbstractCheckMojo.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/AbstractCheckMojo.java?rev=1648828&r1=1648827&r2=1648828&view=diff
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/AbstractCheckMojo.java (original)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/AbstractCheckMojo.java Thu Jan 1 12:23:10 2015
@@ -18,15 +18,15 @@
*/
package org.apache.axiom.apicheck;
-import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
+import java.io.InputStream;
import java.util.List;
+import org.apache.axiom.apicheck.checker.APIChecker;
+import org.apache.axiom.apicheck.checker.Element;
+import org.apache.axiom.apicheck.checker.ViolationListener;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -36,10 +36,6 @@ import org.apache.maven.plugins.annotati
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
-import de.thetaphi.forbiddenapis.Checker;
-import de.thetaphi.forbiddenapis.ForbiddenApiException;
-import de.thetaphi.forbiddenapis.ParseException;
-
abstract class AbstractCheckMojo extends AbstractMojo {
@Parameter(defaultValue="${project}", readonly=true, required=true)
private MavenProject project;
@@ -71,64 +67,34 @@ abstract class AbstractCheckMojo extends
if (files.length == 0) {
return;
}
-
- URL[] urls = new URL[classpathElements.size()];
- int i = 0;
- for (String classpathElement : classpathElements) {
- try {
- urls[i++] = new File(classpathElement).toURI().toURL();
- } catch (MalformedURLException ex) {
- throw new MojoExecutionException("Unexpected exception", ex);
+ final Log log = getLog();
+ APIChecker checker = new APIChecker(new ViolationListener() {
+ @Override
+ public void log(Element element, String msg) {
+ log.error(msg);
}
- }
- URLClassLoader classLoader = new URLClassLoader(urls);
+ });
try {
- final Log log = getLog();
- Checker checker = new Checker(classLoader, false, false, false) {
- @Override
- protected void logError(String msg) {
- log.error(msg);
- }
-
- @Override
- protected void logWarn(String msg) {
- log.warn(msg);
- }
-
- @Override
- protected void logInfo(String msg) {
- log.info(msg);
- }
- };
+ InputStream in = AbstractCheckMojo.class.getResourceAsStream("signatures.txt");
try {
- checker.parseSignaturesFile(AbstractCheckMojo.class.getResourceAsStream("signatures.txt"));
- } catch (IOException ex) {
- throw new MojoExecutionException("I/O error while reading signatures", ex);
- } catch (ParseException ex) {
- throw new MojoExecutionException("Failed to parse signatures", ex);
- }
- if (checker.hasNoSignatures()) {
- // We get here if Axiom is not in the classpath
- return;
+ checker.loadSignatures(in);
+ } finally {
+ in.close();
}
- for (String file : files) {
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Failed to load signature file", ex);
+ }
+ for (String file : files) {
+
+ try {
+ InputStream in = new FileInputStream(new File(outputDirectory, file));
try {
- checker.addClassToCheck(new FileInputStream(new File(outputDirectory, file)));
- } catch (IOException ex) {
- throw new MojoExecutionException("Failed to load class file " + file, ex);
+ checker.checkClass(in);
+ } finally {
+ in.close();
}
- }
- log.info("Scanning for forbidden API invocations...");
- try {
- checker.run();
- } catch (ForbiddenApiException ex) {
- throw new MojoFailureException(ex.getMessage());
- }
- } finally {
- if (classLoader instanceof Closeable) try {
- ((Closeable)classLoader).close();
} catch (IOException ex) {
- // Ignore
+ throw new MojoExecutionException("Failed to load class file " + file, ex);
}
}
}
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/APIChecker.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/APIChecker.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/APIChecker.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/APIChecker.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,77 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.Type;
+
+public final class APIChecker {
+ private final Map<String,String> classSignatures = new HashMap<String,String>();
+ private final ViolationListener listener;
+
+ public APIChecker(ViolationListener listener) {
+ this.listener = listener;
+ }
+
+ public void loadSignatures(InputStream in) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ if (line.length() == 0 || line.charAt(0) == '#') {
+ continue;
+ }
+ int idx = line.indexOf(' ');
+ classSignatures.put(line.substring(0, idx), line.substring(idx+1));
+ }
+ }
+
+ private void reportViolation(Element element, String verb, String object, String msg) {
+ listener.log(element, element.getDescription() + " " + verb + " forbidden " + object + ": " + msg);
+ }
+
+ void checkClassUsage(Element element, String verb, String className) {
+ String msg = classSignatures.get(className);
+ if (msg != null) {
+ reportViolation(element, verb, "class/interface " + className, msg);
+ }
+ }
+
+ void checkTypeUsage(Element element, String verb, Type type) {
+ switch (type.getSort()) {
+ case Type.OBJECT:
+ checkClassUsage(element, verb, type.getInternalName());
+ break;
+ case Type.ARRAY:
+ checkTypeUsage(element, verb, type.getElementType());
+ break;
+ }
+ }
+
+ public void checkClass(InputStream in) throws IOException {
+ new ClassReader(in).accept(new CheckingClassVisitor(this),
+ ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/APIChecker.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingClassVisitor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingClassVisitor.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingClassVisitor.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingClassVisitor.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,61 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+final class CheckingClassVisitor extends ClassVisitor implements ClassElement {
+ private final APIChecker checker;
+ private String name;
+
+ CheckingClassVisitor(APIChecker checker) {
+ super(Opcodes.ASM5);
+ this.checker = checker;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Class " + name;
+ }
+
+ @Override
+ public void visit(int version, int access, String name, String signature,
+ String superName, String[] interfaces) {
+ this.name = name;
+ checker.checkClassUsage(this, "extends", superName);
+ for (String iface : interfaces) {
+ checker.checkClassUsage(this, "implements", iface);
+ }
+ }
+
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature,
+ String[] exceptions) {
+ CheckingMethodVisitor visitor = new CheckingMethodVisitor(checker, this.name, name);
+ Type type = Type.getType(desc);
+ checker.checkTypeUsage(visitor, "returns", type.getReturnType());
+ for (Type argumentType : type.getArgumentTypes()) {
+ checker.checkTypeUsage(visitor, "has argument of", argumentType);
+ }
+ return visitor;
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingClassVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingMethodVisitor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingMethodVisitor.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingMethodVisitor.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingMethodVisitor.java Thu Jan 1 12:23:10 2015
@@ -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.axiom.apicheck.checker;
+
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+final class CheckingMethodVisitor extends MethodVisitor implements MethodElement {
+ private final APIChecker checker;
+ private final String owner;
+ private final String name;
+
+ CheckingMethodVisitor(APIChecker checker, String owner, String name) {
+ super(Opcodes.ASM5);
+ this.checker = checker;
+ this.owner = owner;
+ this.name = name;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Method " + owner + "#" + name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
+ checker.checkClassUsage(this, "uses", owner);
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/CheckingMethodVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ClassElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ClassElement.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ClassElement.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ClassElement.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,23 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+public interface ClassElement extends Element {
+
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ClassElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/Element.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/Element.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/Element.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/Element.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,26 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+/**
+ * Describes an entity that can be the subject of a violation.
+ */
+public interface Element {
+ String getDescription();
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/Element.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/MethodElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/MethodElement.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/MethodElement.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/MethodElement.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,23 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+public interface MethodElement extends Element {
+ String getName();
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/MethodElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ViolationListener.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ViolationListener.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ViolationListener.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ViolationListener.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,23 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+public interface ViolationListener {
+ void log(Element element, String msg);
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/java/org/apache/axiom/apicheck/checker/ViolationListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/resources/org/apache/axiom/apicheck/signatures.txt
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/resources/org/apache/axiom/apicheck/signatures.txt?rev=1648828&r1=1648827&r2=1648828&view=diff
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/resources/org/apache/axiom/apicheck/signatures.txt (original)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/main/resources/org/apache/axiom/apicheck/signatures.txt Thu Jan 1 12:23:10 2015
@@ -16,8 +16,6 @@
# specific language governing permissions and limitations
# under the License.
#
-@defaultMessage Use OMXMLBuilderFactory to create a builder; use OMXMLParserWrapper to interact with the builder
-org.apache.axiom.om.impl.builder.StAXBuilder
-org.apache.axiom.om.impl.builder.StAXOMBuilder
-@defaultMessage Use OMXMLBuilderFactory to create a builder; use OMXMLParserWrapper or SOAPModelBuilder to interact with the builder
-org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder
+org/apache/axiom/om/impl/builder/StAXBuilder Use OMXMLBuilderFactory to create a builder; use OMXMLParserWrapper to interact with the builder
+org/apache/axiom/om/impl/builder/StAXOMBuilder Use OMXMLBuilderFactory to create a builder; use OMXMLParserWrapper to interact with the builder
+org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder Use OMXMLBuilderFactory to create a builder; use OMXMLParserWrapper or SOAPModelBuilder to interact with the builder
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/APICheckerTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/APICheckerTest.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/APICheckerTest.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/APICheckerTest.java Thu Jan 1 12:23:10 2015
@@ -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.axiom.apicheck.checker;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.empty;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+
+import org.junit.Test;
+
+public class APICheckerTest {
+ @Test
+ public void test() throws Exception {
+ MockViolationListener listener = new MockViolationListener();
+ for (Method method : ViolatingClass.class.getDeclaredMethods()) {
+ listener.addExpectedMethod(method.getName());
+ }
+ APIChecker checker = new APIChecker(listener);
+ String signatures = ForbiddenClass.class.getName().replace('.', '/') + " Forbidden";
+ checker.loadSignatures(new ByteArrayInputStream(signatures.getBytes("utf-8")));
+ InputStream in = APICheckerTest.class.getResourceAsStream(
+ "/" + ViolatingClass.class.getName().replace('.', '/') + ".class");
+ try {
+ checker.checkClass(in);
+ } finally {
+ in.close();
+ }
+ assertThat(listener.getUnseenMethods(), is(empty()));
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/APICheckerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ForbiddenClass.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ForbiddenClass.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ForbiddenClass.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ForbiddenClass.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,24 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+public class ForbiddenClass {
+ public void method() {
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ForbiddenClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/MockViolationListener.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/MockViolationListener.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/MockViolationListener.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/MockViolationListener.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,42 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+import java.util.HashSet;
+import java.util.Set;
+
+final class MockViolationListener implements ViolationListener {
+ private final Set<String> expectedMethods = new HashSet<String>();
+
+ void addExpectedMethod(String name) {
+ expectedMethods.add(name);
+ }
+
+ @Override
+ public void log(Element element, String msg) {
+ System.out.println(msg);
+ if (element instanceof MethodElement) {
+ expectedMethods.remove(((MethodElement)element).getName());
+ }
+ }
+
+ Set<String> getUnseenMethods() {
+ return expectedMethods;
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/MockViolationListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ViolatingClass.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ViolatingClass.java?rev=1648828&view=auto
==============================================================================
--- webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ViolatingClass.java (added)
+++ webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ViolatingClass.java Thu Jan 1 12:23:10 2015
@@ -0,0 +1,48 @@
+/*
+ * 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.axiom.apicheck.checker;
+
+public class ViolatingClass {
+ public ForbiddenClass returnsForbiddenClass() {
+ return null;
+ }
+
+ public void usesForbiddenClassAsArgument(ForbiddenClass arg) {
+ }
+
+ public ForbiddenClass[] returnsArrayOfForbiddenClass() {
+ return null;
+ }
+
+ public void usesArrayOfForbiddenClassAsArgument(ForbiddenClass[] arg) {
+ }
+
+ public void invokesMethodMemberOfForbiddenClass() {
+ returnsForbiddenClass().method();
+ }
+
+ public void usesCastToForbiddenClass() {
+ Object ref1 = null;
+ Object ref2 = (ForbiddenClass)ref1;
+ }
+
+ public void createsInstanceOfForbiddenClass() {
+ new ForbiddenClass();
+ }
+}
Propchange: webservices/axiom/branches/apicheck/apicheck/apicheck-maven-plugin/src/test/java/org/apache/axiom/apicheck/checker/ViolatingClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/branches/apicheck/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/pom.xml?rev=1648828&r1=1648827&r2=1648828&view=diff
==============================================================================
--- webservices/axiom/branches/apicheck/pom.xml (original)
+++ webservices/axiom/branches/apicheck/pom.xml Thu Jan 1 12:23:10 2015
@@ -377,6 +377,11 @@
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
+ <dependency>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>5.0.3</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<properties>
Modified: webservices/axiom/branches/apicheck/testing/dom-testsuite/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/apicheck/testing/dom-testsuite/pom.xml?rev=1648828&r1=1648827&r2=1648828&view=diff
==============================================================================
--- webservices/axiom/branches/apicheck/testing/dom-testsuite/pom.xml (original)
+++ webservices/axiom/branches/apicheck/testing/dom-testsuite/pom.xml Thu Jan 1 12:23:10 2015
@@ -66,7 +66,6 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
- <version>5.0.3</version>
</dependency>
</dependencies>
<build>