Terms of Service | Privacy Policy | Cookie Policy

Commit f0dd4eb4 authored by Uwe Plonus's avatar Uwe Plonus

First rudimentary design of the API

parent 3421a5d3
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.sw4j.api-sniffer</groupId>
<artifactId>api-sample</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<groupId>org.sw4j.api-sniffer.api-sample</groupId>
<artifactId>base</artifactId>
<packaging>jar</packaging>
<name>Java API Sniffer API Samples Base</name>
<description>Base API Samples for API Sniffer.</description>
<properties>
<!-- Generic -->
<netbeans.hint.license>gpl30</netbeans.hint.license>
<!-- Plugin versions -->
</properties>
</project>
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.sample.base;
/**
*
* @author Uwe Plonus
*/
public @interface SimpleAnnotation {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.sample.base;
/**
*
* @author Uwe Plonus
*/
public class SimpleClass {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.sample.base;
/**
*
* @author Uwe Plonus
*/
public enum SimpleEnum {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.sample.base;
/**
*
* @author Uwe Plonus
*/
public interface SimpleInterface {
}
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.sw4j</groupId>
<artifactId>api-sniffer</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<groupId>org.sw4j.api-sniffer</groupId>
<artifactId>api-sample</artifactId>
<packaging>pom</packaging>
<name>Java API Sniffer API Samples</name>
<description>API Samples for API Sniffer.</description>
<properties>
<!-- Generic -->
<netbeans.hint.license>gpl30</netbeans.hint.license>
<!-- Plugin versions -->
</properties>
<modules>
<module>${api-sample-base}</module>
</modules>
</project>
......@@ -23,7 +23,10 @@ import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import org.objectweb.asm.ClassReader;
import org.sw4j.apisniffer.api.Api;
import org.sw4j.apisniffer.builder.ApiBuilder;
import org.sw4j.apisniffer.visitor.ApiClassVisitor;
/**
*
......@@ -32,7 +35,10 @@ import org.sw4j.apisniffer.api.Api;
@NotThreadSafe
public class ApiScanner {
private ApiBuilder apiBuilder;
public void scanDirectory(@Nonnull final File folder) throws IOException {
apiBuilder = new ApiBuilder();
if (!folder.getAbsoluteFile().isDirectory()) {
throw new IllegalArgumentException(
new StringBuilder("The method scanFolder(File) is for")
......@@ -53,10 +59,14 @@ public class ApiScanner {
}
}
private void scanClass(@Nonnull final InputStream classFile) {
private void scanClass(@Nonnull final InputStream classFile) throws IOException {
ClassReader cr = new ClassReader(classFile);
ApiClassVisitor cv = new ApiClassVisitor(apiBuilder);
cr.accept(cv, 0);
}
public void scanJar(@Nonnull final InputStream is) throws IOException {
apiBuilder = new ApiBuilder();
}
/**
......
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.api;
/**
*
* @author Uwe Plonus
*/
public interface AnnotationType extends Type {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.api;
/**
*
* @author Uwe Plonus
*/
public interface ClassType extends Type {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.api;
/**
*
* @author Uwe Plonus
*/
public interface EnumType extends Type {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.api;
/**
*
* @author Uwe Plonus
*/
public interface InterfaceType extends Type {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.builder;
/**
*
* @author Uwe Plonus
*/
public class AnnotationTypeBuilder extends TypeBuilder {
}
......@@ -30,6 +30,22 @@ import org.sw4j.apisniffer.api.Type;
@NotThreadSafe
public final class ApiBuilder {
public ClassTypeBuilder createClassTypeBuilder() {
return new ClassTypeBuilder();
}
public InterfaceTypeBuilder createInterfaceTypeBuilder() {
return new InterfaceTypeBuilder();
}
public EnumTypeBuilder createEnumTypeBuilder() {
return new EnumTypeBuilder();
}
public AnnotationTypeBuilder createAnnotationTypeBuilder() {
return new AnnotationTypeBuilder();
}
/**
* Builds an {@link Api} object.
*
......
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.builder;
/**
*
* @author Uwe Plonus
*/
public class ClassTypeBuilder extends TypeBuilder {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.builder;
/**
*
* @author Uwe Plonus
*/
public class EnumTypeBuilder extends TypeBuilder {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.builder;
/**
*
* @author Uwe Plonus
*/
public class InterfaceTypeBuilder extends TypeBuilder {
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.builder;
/**
*
* @author Uwe Plonus
*/
public abstract class TypeBuilder {
private String internalName;
public void setInternalName(String name) {
this.internalName = name;
}
public boolean isNameSet() {
return internalName != null;
}
}
/*
* Copyright (C) 2015 Uwe Plonus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.apisniffer.visitor;
import javax.annotation.concurrent.NotThreadSafe;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypePath;
import org.sw4j.apisniffer.builder.ApiBuilder;
import org.sw4j.apisniffer.builder.TypeBuilder;
/**
*
* @author Uwe Plonus
*/
@NotThreadSafe
public final class ApiClassVisitor extends ClassVisitor {
private final ApiBuilder apiBuilder;
private TypeBuilder typeBuilder;
public ApiClassVisitor(ApiBuilder apiBuilder) {
super(Opcodes.ASM5);
this.apiBuilder = apiBuilder;
}
@Override
public void visit(int version, int access, String name, String signature, String superName,
String[] interfaces) {
if ((access & Opcodes.ACC_ANNOTATION) == Opcodes.ACC_ANNOTATION) {
typeBuilder = apiBuilder.createAnnotationTypeBuilder();
} else if ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE) {
typeBuilder = apiBuilder.createInterfaceTypeBuilder();
} else if ((access & Opcodes.ACC_ENUM) == Opcodes.ACC_ENUM) {
typeBuilder = apiBuilder.createEnumTypeBuilder();
} else {
typeBuilder = apiBuilder.createClassTypeBuilder();
}
typeBuilder.setInternalName(name);
super.visit(version, access, name, signature, superName, interfaces);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
String[] exceptions) {
return super.visitMethod(access, name, desc, signature, exceptions);
}
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature,
Object value) {
return super.visitField(access, name, desc, signature, value);
}
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
super.visitInnerClass(name, outerName, innerName, access);
}
@Override
public void visitAttribute(Attribute attr) {
super.visitAttribute(attr);
}
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc,
boolean visible) {
return super.visitTypeAnnotation(typeRef, typePath, desc, visible);
}
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
return super.visitAnnotation(desc, visible);
}
@Override
public void visitOuterClass(String owner, String name, String desc) {
super.visitOuterClass(owner, name, desc);
}
@Override
public void visitEnd() {
super.visitEnd();
}
}
......@@ -18,7 +18,9 @@ package org.sw4j.apisniffer;
import java.io.File;
import java.io.IOException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
/**
......@@ -29,6 +31,10 @@ public class ApiScannerTest {
private ApiScanner objectToTest;
@BeforeClass
public void setUpClass() {
}
@BeforeMethod
public void setUp() {
objectToTest = new ApiScanner();
......@@ -36,13 +42,15 @@ public class ApiScannerTest {
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = ".*target/test-classes/dummy.*")
public void testScanDirectoryWithFile() throws IOException {
objectToTest.scanDirectory(new File("target/test-classes/dummy"));
@Parameters("testClasses")
public void testScanDirectoryWithFile(String testClasses) throws IOException {
objectToTest.scanDirectory(new File(testClasses, "dummy"));
}
@Test
public void testScanDirectory() throws IOException {
objectToTest.scanDirectory(new File(""));
@Parameters({"baseApiClasses",})
public void testScanDirectory(String baseClasses) throws IOException {
objectToTest.scanDirectory(new File("..", baseClasses));
}
}
......@@ -42,6 +42,11 @@
<maven.compiler.target>1.7</maven.compiler.target>
<netbeans.hint.license>gpl30</netbeans.hint.license>
<!-- Project Tests -->
<api-sample>api-sample</api-sample>
<api-sample-base>base</api-sample-base>
<api-sample-base-folder>${api-sample}/${api-sample-base}</api-sample-base-folder>
<!-- Dependencies -->
<asm-version>5.0.4</asm-version>
<jsr305-version>3.0.0</jsr305-version>
......@@ -59,6 +64,7 @@
<release-plugin-version>2.5.2</release-plugin-version>
<scm-publish-plugin-version>1.1</scm-publish-plugin-version>
<site-plugin-version>3.4</site-plugin-version>
<surefire-plugin-version>2.18.1</surefire-plugin-version>
<!-- Reporting Plugins -->
<dependency-check-plugin-version>1.2.11</dependency-check-plugin-version>
......@@ -71,6 +77,7 @@
</properties>
<modules>
<module>${api-sample}</module>
<module>api-sniffer</module>
<module>api-sniffer-maven-plugin</module>
<module>it</module>
......@@ -147,6 +154,23 @@
<releaseProfiles>release</releaseProfiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<configuration>
<scmBranch>gh-pages</scmBranch>
<skipCheckin>true</skipCheckin>
</configuration>
<executions>
<execution>
<id>scm-publish</id>
<phase>site-deploy</phase>
<goals>
<goal>publish-scm</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
......@@ -171,20 +195,14 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<scmBranch>gh-pages</scmBranch>
<skipCheckin>true</skipCheckin>
<systemPropertyVariables>
<baseApiClasses>${api-sample-base-folder}/target/classes</baseApiClasses>
<projectBaseFolder>${project.basedir}</projectBaseFolder>
<testClasses>${project.build.testOutputDirectory}</testClasses>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>scm-publish</id>
<phase>site-deploy</phase>
<goals>
<goal>publish-scm</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
......@@ -266,6 +284,11 @@
<artifactId>maven-site-plugin</artifactId>
<version>${site-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin-version}</version>
</plugin>
<plugin>