CORDA-1280 - Update the api-scanner to the most recent version + regenerate api (#3154)

* Update v3 api scanner to most recent version

* Regenerate api-current.txt

* Fix bootstrapper classpath
This commit is contained in:
Anthony Keenan 2018-05-16 11:56:23 +01:00 committed by Katelyn Baker
parent d63ee71564
commit 181829a325
50 changed files with 6062 additions and 3606 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
gradlePluginsVersion=3.2.0
gradlePluginsVersion=3.2.1
kotlinVersion=1.1.60
platformVersion=3
guavaVersion=21.0

View File

@ -0,0 +1,14 @@
package net.corda.annotation;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
@Target({TYPE})
@Retention(CLASS)
@Inherited
public @interface AnAnnotation {
}

View File

@ -0,0 +1,12 @@
package net.corda.core;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
@Retention(CLASS)
@Target({TYPE})
public @interface DoNotImplement {
}

View File

@ -1,4 +1,5 @@
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'java-gradle-plugin'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'com.jfrog.artifactory'
@ -20,8 +21,13 @@ gradlePlugin {
}
}
configurations {
jacocoRuntime
}
dependencies {
compile "io.github.lukehutch:fast-classpath-scanner:2.7.0"
compile "io.github.lukehutch:fast-classpath-scanner:2.18.2"
testCompile project(':api-scanner:annotations')
testCompile "org.assertj:assertj-core:$assertj_version"
testCompile "junit:junit:$junit_version"
@ -29,13 +35,17 @@ dependencies {
// on the Kotlin classes in the test/resources directory.
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile project(':api-scanner:annotations')
jacocoRuntime "org.jacoco:org.jacoco.agent:${jacoco.toolVersion}:runtime"
}
processTestResources {
filesMatching('**/kotlin-*/build.gradle') {
expand(['kotlin_version': kotlin_version])
}
filesMatching('gradle.properties') {
expand(['jacocoAgent': configurations.jacocoRuntime.asPath.replace('\\', '/'),
'buildDir': buildDir])
}
}
publish {

View File

@ -0,0 +1,128 @@
package net.corda.plugins;
import io.github.lukehutch.fastclasspathscanner.scanner.ClassInfo;
import io.github.lukehutch.fastclasspathscanner.scanner.FieldInfo;
import io.github.lukehutch.fastclasspathscanner.scanner.MethodInfo;
import io.github.lukehutch.fastclasspathscanner.typesignature.TypeSignature;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toCollection;
public class ApiPrintWriter extends PrintWriter {
ApiPrintWriter(File file, String encoding) throws FileNotFoundException, UnsupportedEncodingException {
super(file, encoding);
}
public void println(ClassInfo classInfo, int modifierMask, List<String> filteredAnnotations) {
append(asAnnotations(filteredAnnotations, ""));
append(Modifier.toString(classInfo.getClassRef().getModifiers() & modifierMask));
if (classInfo.isAnnotation()) {
/*
* Annotation declaration.
*/
append(" @interface ").print(classInfo.getClassName());
} else if (classInfo.isStandardClass()) {
/*
* Class declaration.
*/
append(" class ").print(classInfo.getClassName());
Set<ClassInfo> superclasses = classInfo.getDirectSuperclasses();
if (!superclasses.isEmpty()) {
append(" extends ").print(stringOf(superclasses));
}
Set<ClassInfo> interfaces = classInfo.getDirectlyImplementedInterfaces();
if (!interfaces.isEmpty()) {
append(" implements ").print(stringOf(interfaces));
}
} else {
/*
* Interface declaration.
*/
append(" interface ").print(classInfo.getClassName());
Set<ClassInfo> superinterfaces = classInfo.getDirectSuperinterfaces();
if (!superinterfaces.isEmpty()) {
append(" extends ").print(stringOf(superinterfaces));
}
}
println();
}
public void println(MethodInfo method, String indentation) {
append(asAnnotations(method.getAnnotationNames(), indentation));
append(indentation);
if (method.getModifiersStr() != null) {
append(method.getModifiersStr()).append(' ');
}
if (!method.isConstructor()) {
append(removeQualifierFromBaseTypes(method.getResultTypeStr())).append(' ');
}
append(method.getMethodName()).append('(');
LinkedList<String> paramTypes = method
.getTypeSignature()
.getParameterTypeSignatures()
.stream()
.map(ApiPrintWriter::removeQualifierFromBaseTypes)
.collect(toCollection(LinkedList::new));
//if parameter is varargs, remove the array [] qualifier and replace with ellipsis
if (method.isVarArgs() && !paramTypes.isEmpty()) {
String vararg = paramTypes.removeLast();
paramTypes.add(vararg.substring(0, vararg.length() - 2) + "...");
}
append(paramTypes.stream().collect(joining(", ")));
println(')');
}
public void println(FieldInfo field, String indentation) {
append(asAnnotations(field.getAnnotationNames(), indentation))
.append(indentation)
.append(field.getModifierStr())
.append(' ')
.append(removeQualifierFromBaseTypes(field.getTypeStr()))
.append(' ')
.append(field.getFieldName());
if (field.getConstFinalValue() != null) {
append(" = ");
if (field.getConstFinalValue() instanceof String) {
append('"').append(field.getConstFinalValue().toString()).append('"');
} else if (field.getConstFinalValue() instanceof Character) {
append('\'').append(field.getConstFinalValue().toString()).append('\'');
} else {
append(field.getConstFinalValue().toString());
}
}
println();
}
private static String asAnnotations(Collection<String> items, String indentation) {
if (items.isEmpty()) {
return "";
}
return items.stream().map(ApiPrintWriter::removePackageName).collect(joining(System.lineSeparator() + indentation + '@', indentation + "@", System.lineSeparator()));
}
private static String removePackageName(String className) {
return className.substring(className.lastIndexOf('.') + 1);
}
private static String stringOf(Collection<ClassInfo> items) {
return items.stream().map(ClassInfo::getClassName).collect(joining(", "));
}
private static String removeQualifierFromBaseTypes(String className) {
return className.replace("java.lang.", "");
}
private static String removeQualifierFromBaseTypes(TypeSignature typeSignature) {
return removeQualifierFromBaseTypes(typeSignature.toString());
}
}

View File

@ -31,26 +31,35 @@ public class ScanApi extends DefaultTask {
* The VARARG modifier for methods has the same value as the TRANSIENT modifier for fields.
* Unfortunately, {@link Modifier#methodModifiers() methodModifiers} doesn't include this
* flag, and so we need to add it back ourselves.
*
* @link https://docs.oracle.com/javase/specs/jls/se8/html/index.html
*/
private static final int METHOD_MASK = Modifier.methodModifiers() | Modifier.TRANSIENT;
private static final int FIELD_MASK = Modifier.fieldModifiers();
private static final int VISIBILITY_MASK = Modifier.PUBLIC | Modifier.PROTECTED;
private static final String DONOTIMPLEMENT_ANNOTATION_NAME = "net.corda.core.DoNotImplement";
private static final String INTERNAL_ANNOTATION_NAME = ".CordaInternal";
private static final String DEFAULT_INTERNAL_ANNOTATION = "net.corda.core" + INTERNAL_ANNOTATION_NAME;
private static final Set<String> ANNOTATION_BLACKLIST;
static {
Set<String> blacklist = new LinkedHashSet<>();
blacklist.add("kotlin.jvm.JvmField");
blacklist.add("kotlin.jvm.JvmOverloads");
blacklist.add(DEFAULT_INTERNAL_ANNOTATION);
ANNOTATION_BLACKLIST = unmodifiableSet(blacklist);
Set<String> blacklist = new LinkedHashSet<>();
blacklist.add("kotlin.jvm.JvmField");
blacklist.add("kotlin.jvm.JvmOverloads");
blacklist.add("kotlin.jvm.JvmStatic");
blacklist.add("kotlin.jvm.JvmDefault");
blacklist.add("kotlin.Deprecated");
blacklist.add("java.lang.Deprecated");
blacklist.add(DEFAULT_INTERNAL_ANNOTATION);
ANNOTATION_BLACKLIST = unmodifiableSet(blacklist);
}
/**
* This information has been lifted from:
* @link <a href="https://github.com/JetBrains/kotlin/blob/master/core/runtime.jvm/src/kotlin/Metadata.kt">Metadata.kt</a>
*
* @link <a href="https://github.com/JetBrains/kotlin/blob/master/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt">KotlinClassHeader.Kind</a>
* @link <a href="https://github.com/JetBrains/kotlin/blob/master/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java">JvmAnnotationNames</a>
*/
private static final String KOTLIN_METADATA = "kotlin.Metadata";
private static final String KOTLIN_CLASSTYPE_METHOD = "k";
@ -174,8 +183,8 @@ public class ScanApi extends DefaultTask {
File target = toTarget(source);
getLogger().info("API file: {}", target.getAbsolutePath());
try (
URLClassLoader appLoader = new URLClassLoader(new URL[]{ toURL(source) }, classpathLoader);
PrintWriter writer = new PrintWriter(target, "UTF-8")
URLClassLoader appLoader = new URLClassLoader(new URL[]{toURL(source)}, classpathLoader);
ApiPrintWriter writer = new ApiPrintWriter(target, "UTF-8")
) {
scan(writer, appLoader);
} catch (IOException e) {
@ -183,7 +192,7 @@ public class ScanApi extends DefaultTask {
}
}
void scan(PrintWriter writer, ClassLoader appLoader) {
void scan(ApiPrintWriter writer, ClassLoader appLoader) {
Set<String> inherited = new HashSet<>();
ScanResult result = new FastClasspathScanner(getScanSpecification())
.matchAllAnnotationClasses(annotation -> {
@ -235,21 +244,14 @@ public class ScanApi extends DefaultTask {
invisibleAnnotations = unmodifiableSet(invisible);
}
private void writeApis(PrintWriter writer, ScanResult result) {
private void writeApis(ApiPrintWriter writer, ScanResult result) {
Map<String, ClassInfo> allInfo = result.getClassNameToClassInfo();
result.getNamesOfAllClasses().forEach(className -> {
if (className.contains(".internal.")) {
// These classes belong to internal Corda packages.
return;
}
if (className.contains("$$inlined$")) {
/*
* These classes are internally generated by the Kotlin compiler
* and are not exposed as part of the public API
* TODO: Filter out using EnclosingMethod attribute in classfile
*/
return;
}
ClassInfo classInfo = allInfo.get(className);
if (classInfo.getClassLoaders() == null) {
// Ignore classes that belong to one of our target ClassLoader's parents.
@ -268,81 +270,54 @@ public class ScanApi extends DefaultTask {
return;
}
if (classInfo.getFullyQualifiedContainingMethodName() != null) {
// Ignore Kotlin auto-generated internal classes
// which are not part of the api
return;
}
int kotlinClassType = getKotlinClassType(javaClass);
if (kotlinClassType == KOTLIN_SYNTHETIC) {
// Exclude classes synthesised by the Kotlin compiler.
return;
}
writeClass(writer, classInfo, javaClass.getModifiers());
writeClass(writer, classInfo);
writeMethods(writer, classInfo.getMethodAndConstructorInfo());
writeFields(writer, classInfo.getFieldInfo());
writer.println("##");
});
}
private void writeClass(PrintWriter writer, ClassInfo classInfo, int modifiers) {
private void writeClass(ApiPrintWriter writer, ClassInfo classInfo) {
if (classInfo.isAnnotation()) {
/*
* Annotation declaration.
*/
writer.append(Modifier.toString(modifiers & INTERFACE_MASK));
writer.append(" @interface ").print(classInfo);
writer.println(classInfo, INTERFACE_MASK, emptyList());
} else if (classInfo.isStandardClass()) {
/*
* Class declaration.
*/
Names annotationNames = toNames(readClassAnnotationsFor(classInfo));
if (!annotationNames.visible.isEmpty()) {
writer.append(asAnnotations(annotationNames.visible));
}
writer.append(Modifier.toString(modifiers & CLASS_MASK));
writer.append(" class ").print(classInfo);
Set<ClassInfo> superclasses = classInfo.getDirectSuperclasses();
if (!superclasses.isEmpty()) {
writer.append(" extends ").print(stringOf(superclasses));
}
Set<ClassInfo> interfaces = classInfo.getDirectlyImplementedInterfaces();
if (!interfaces.isEmpty()) {
writer.append(" implements ").print(stringOf(interfaces));
}
writer.println(classInfo, CLASS_MASK, toNames(readClassAnnotationsFor(classInfo)).visible);
} else {
/*
* Interface declaration.
*/
Names annotationNames = toNames(readInterfaceAnnotationsFor(classInfo));
if (!annotationNames.visible.isEmpty()) {
writer.append(asAnnotations(annotationNames.visible));
}
writer.append(Modifier.toString(modifiers & INTERFACE_MASK));
writer.append(" interface ").print(classInfo);
Set<ClassInfo> superinterfaces = classInfo.getDirectSuperinterfaces();
if (!superinterfaces.isEmpty()) {
writer.append(" extends ").print(stringOf(superinterfaces));
}
writer.println(classInfo, INTERFACE_MASK, toNames(readInterfaceAnnotationsFor(classInfo)).visible);
}
writer.println();
}
private void writeMethods(PrintWriter writer, List<MethodInfo> methods) {
private void writeMethods(ApiPrintWriter writer, List<MethodInfo> methods) {
sort(methods);
for (MethodInfo method : methods) {
if (isVisible(method.getAccessFlags()) // Only public and protected methods
&& isValid(method.getAccessFlags(), METHOD_MASK) // Excludes bridge and synthetic methods
if (isVisible(method.getModifiers()) // Only public and protected methods
&& isValid(method.getModifiers(), METHOD_MASK) // Excludes bridge and synthetic methods
&& !hasInternalAnnotation(method.getAnnotationNames()) // Excludes methods annotated as @CordaInternal
&& !isKotlinInternalScope(method)) {
writer.append(" ").println(filterAnnotationsFor(method));
writer.println(filterAnnotationsFor(method), " ");
}
}
}
private void writeFields(PrintWriter output, List<FieldInfo> fields) {
private void writeFields(ApiPrintWriter writer, List<FieldInfo> fields) {
sort(fields);
for (FieldInfo field : fields) {
if (isVisible(field.getAccessFlags())
&& isValid(field.getAccessFlags(), FIELD_MASK)
if (isVisible(field.getModifiers())
&& isValid(field.getModifiers(), FIELD_MASK)
&& !hasInternalAnnotation(field.getAnnotationNames())) {
output.append(" ").println(filterAnnotationsFor(field));
writer.println(filterAnnotationsFor(field), " ");
}
}
}
@ -363,10 +338,18 @@ public class ScanApi extends DefaultTask {
private Names toNames(Collection<ClassInfo> classes) {
Map<Boolean, List<String>> partitioned = classes.stream()
.map(ClassInfo::toString)
.map(ClassInfo::getClassName)
.filter(ScanApi::isApplicationClass)
.collect(partitioningBy(this::isVisibleAnnotation, toCollection(ArrayList::new)));
return new Names(ordering(partitioned.get(true)), ordering(partitioned.get(false)));
List<String> visible = partitioned.get(true);
int idx = visible.indexOf(DONOTIMPLEMENT_ANNOTATION_NAME);
if (idx != -1) {
swap(visible, 0, idx);
sort(visible.subList(1, visible.size()));
} else {
sort(visible);
}
return new Names(visible, ordering(partitioned.get(false)));
}
private Set<ClassInfo> readClassAnnotationsFor(ClassInfo classInfo) {
@ -396,12 +379,17 @@ public class ScanApi extends DefaultTask {
return new MethodInfo(
method.getClassName(),
method.getMethodName(),
method.getAccessFlags(),
method.getTypeDescriptor(),
method.getAnnotationNames().stream()
method.getAnnotationInfo()
.stream()
.filter(this::isVisibleAnnotation)
.sorted()
.collect(toList())
.collect(toList()),
method.getModifiers(),
method.getTypeDescriptorStr(),
method.getTypeSignatureStr(),
method.getParameterNames(),
method.getParameterModifiers(),
method.getParameterAnnotationInfo()
);
}
@ -409,18 +397,23 @@ public class ScanApi extends DefaultTask {
return new FieldInfo(
field.getClassName(),
field.getFieldName(),
field.getAccessFlags(),
field.getTypeDescriptor(),
field.getModifiers(),
field.getTypeDescriptorStr(),
field.getTypeSignatureStr(),
field.getConstFinalValue(),
field.getAnnotationNames().stream()
field.getAnnotationInfo().stream()
.filter(this::isVisibleAnnotation)
.sorted()
.collect(toList())
);
}
private boolean isVisibleAnnotation(String annotationName) {
return !invisibleAnnotations.contains(annotationName);
private boolean isVisibleAnnotation(AnnotationInfo annotation) {
return isVisibleAnnotation(annotation.getAnnotationName());
}
private boolean isVisibleAnnotation(String className) {
return !invisibleAnnotations.contains(className);
}
private boolean hasInternalAnnotation(Collection<String> annotationNames) {
@ -445,14 +438,6 @@ public class ScanApi extends DefaultTask {
return (accessFlags & VISIBILITY_MASK) != 0;
}
private static String stringOf(Collection<ClassInfo> items) {
return items.stream().map(ClassInfo::toString).collect(joining(", "));
}
private static String asAnnotations(Collection<String> items) {
return items.stream().collect(joining(" @", "@", " "));
}
private static boolean isApplicationClass(String typeName) {
return !typeName.startsWith("java.") && !typeName.startsWith("kotlin.");
}
@ -466,13 +451,14 @@ public class ScanApi extends DefaultTask {
for (File file : files) {
urls.add(toURL(file));
}
return urls.toArray(new URL[urls.size()]);
return urls.toArray(new URL[0]);
}
}
class Names {
List<String> visible;
@SuppressWarnings("WeakerAccess") List<String> hidden;
@SuppressWarnings("WeakerAccess")
List<String> hidden;
Names(List<String> visible, List<String> hidden) {
this.visible = unmodifiable(visible);

View File

@ -1,52 +1,37 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class AnnotatedClassTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "annotated-class");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("annotated-class/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testAnnotatedClass() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "annotated-class.txt");
assertThat(api).isRegularFile();
assertThat(Files.readAllLines(api)).containsOnlyOnce(
"@net.corda.annotation.AlsoInherited @net.corda.annotation.IsInherited @net.corda.annotation.NotInherited public class net.corda.example.HasInheritedAnnotation extends java.lang.Object",
"@net.corda.annotation.AlsoInherited @net.corda.annotation.IsInherited public class net.corda.example.InheritingAnnotations extends net.corda.example.HasInheritedAnnotation"
);
assertThat(testProject.getApiLines())
.containsSequence(
"@AlsoInherited",
"@IsInherited",
"@NotInherited",
"public class net.corda.example.HasInheritedAnnotation extends java.lang.Object")
.containsSequence(
"@AlsoInherited",
"@IsInherited",
"public class net.corda.example.InheritingAnnotations extends net.corda.example.HasInheritedAnnotation")
.containsSequence(
"@DoNotImplement",
"@AnAnnotation",
"public class net.corda.example.DoNotImplementAnnotation extends java.lang.Object");
}
}

View File

@ -1,52 +1,29 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.gradle.testkit.runner.TaskOutcome.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class AnnotatedFieldTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "annotated-field");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("annotated-field/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testAnnotatedField() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "annotated-field.txt");
assertThat(api).isRegularFile();
assertThat(Files.readAllLines(api)).containsOnlyOnce(
"public class net.corda.example.HasAnnotatedField extends java.lang.Object",
" @net.corda.example.A @net.corda.example.B @net.corda.example.C public static final String ANNOTATED_FIELD = \"<string-value>\""
);
assertThat(testProject.getApiLines())
.containsSequence(
" @A",
" @B",
" @C",
" public static final String ANNOTATED_FIELD = \"<string-value>\"");
}
}

View File

@ -1,52 +1,38 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class AnnotatedInterfaceTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "annotated-interface");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("annotated-interface/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testAnnotatedInterface() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "annotated-interface.txt");
assertThat(api).isRegularFile();
assertThat(Files.readAllLines(api)).containsOnlyOnce(
"@net.corda.annotation.AlsoInherited @net.corda.annotation.IsInherited @net.corda.annotation.NotInherited public interface net.corda.example.HasInheritedAnnotation",
"@net.corda.annotation.AlsoInherited @net.corda.annotation.IsInherited public interface net.corda.example.InheritingAnnotations extends net.corda.example.HasInheritedAnnotation"
);
assertThat(testProject.getApiLines())
.containsSequence(
"@AlsoInherited",
"@IsInherited",
"@NotInherited",
"public interface net.corda.example.HasInheritedAnnotation")
.containsSequence(
"@AlsoInherited",
"@IsInherited",
"public interface net.corda.example.InheritingAnnotations extends net.corda.example.HasInheritedAnnotation")
.containsSequence(
"@DoNotImplement",
"@AnAnnotation",
"public interface net.corda.example.DoNotImplementAnnotation"
);
}
}

View File

@ -1,52 +1,35 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class AnnotatedMethodTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "annotated-method");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("annotated-method/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testAnnotatedMethod() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "annotated-method.txt");
assertThat(api).isRegularFile();
assertThat(Files.readAllLines(api)).containsOnlyOnce(
"public class net.corda.example.HasAnnotatedMethod extends java.lang.Object",
" @net.corda.example.A @net.corda.example.B @net.corda.example.C public void hasAnnotation()"
);
assertThat(testProject.getApiLines())
.containsSequence(
" @A",
" @B",
" @C",
" public void hasAnnotation()")
//Should not include @Deprecated annotation
.containsSequence(
"public class net.corda.example.HasDeprecatedMethod extends java.lang.Object",
" public <init>()",
" public void isDeprecated()"
);
}
}

View File

@ -1,50 +1,26 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class BasicAnnotationTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "basic-annotation");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("basic-annotation/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testBasicAnnotation() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "basic-annotation.txt");
assertThat(api).isRegularFile();
assertEquals(
"public @interface net.corda.example.BasicAnnotation\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,52 +1,28 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class BasicClassTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "basic-class");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("basic-class/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testBasicClass() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "basic-class.txt");
assertThat(api).isRegularFile();
assertEquals(
"public class net.corda.example.BasicClass extends java.lang.Object\n" +
" public <init>(String)\n" +
" public String getName()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,51 +1,27 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class BasicInterfaceTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "basic-interface");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("basic-interface/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testBasicInterface() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "basic-interface.txt");
assertThat(api).isRegularFile();
assertEquals(
"public interface net.corda.example.BasicInterface\n" +
" public abstract java.math.BigInteger getBigNumber()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,52 +1,28 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class ClassWithInternalAnnotationTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "class-internal-annotation");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("class-internal-annotation/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testClassWithInternalAnnotation() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
assertThat(output).contains("net.corda.example.InvisibleAnnotation");
Path api = pathOf(testProjectDir, "build", "api", "class-internal-annotation.txt");
assertThat(api).isRegularFile();
assertThat(testProject.getOutput()).contains("net.corda.example.InvisibleAnnotation");
assertEquals("public class net.corda.example.AnnotatedClass extends java.lang.Object\n" +
" public <init>()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -2,23 +2,24 @@ package net.corda.plugins;
import org.junit.rules.TemporaryFolder;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardCopyOption.*;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public final class CopyUtils {
private static final String testGradleUserHome = System.getProperty("test.gradle.user.home", "");
private CopyUtils() {
}
public static long installResource(TemporaryFolder folder, String resourceName) throws IOException {
File buildFile = folder.newFile(resourceName.substring(1 + resourceName.lastIndexOf('/')));
return copyResourceTo(resourceName, buildFile);
}
public static long copyResourceTo(String resourceName, Path target) throws IOException {
try (InputStream input = CopyUtils.class.getClassLoader().getResourceAsStream(resourceName)) {
return Files.copy(input, target, REPLACE_EXISTING);
@ -28,22 +29,4 @@ public final class CopyUtils {
public static long copyResourceTo(String resourceName, File target) throws IOException {
return copyResourceTo(resourceName, target.toPath());
}
public static String toString(Path file) throws IOException {
return new String(Files.readAllBytes(file), UTF_8);
}
public static Path pathOf(TemporaryFolder folder, String... elements) {
return Paths.get(folder.getRoot().getAbsolutePath(), elements);
}
public static List<String> getGradleArgsForTasks(String... taskNames) {
List<String> args = new ArrayList<>(taskNames.length + 3);
Collections.addAll(args, taskNames);
args.add("--info");
if (!testGradleUserHome.isEmpty()) {
Collections.addAll(args,"-g", testGradleUserHome);
}
return args;
}
}

View File

@ -1,51 +1,36 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class ExtendedClassTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private static final TemporaryFolder testProjectDir = new TemporaryFolder();
private static final GradleProject testProject = new GradleProject(testProjectDir, "extended-class");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("extended-class/build.gradle", buildFile);
}
@ClassRule
public static final TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testExtendedClass() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
assertThat(testProject.getApiLines()).containsSequence(
"public class net.corda.example.ExtendedClass extends java.io.FilterInputStream",
" public <init>(java.io.InputStream)",
"##");
}
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "extended-class.txt");
assertThat(api).isRegularFile();
assertEquals(
"public class net.corda.example.ExtendedClass extends java.io.FilterInputStream\n" +
" public <init>(java.io.InputStream)\n" +
"##\n", CopyUtils.toString(api));
@Test
public void testImplementingClass() throws IOException {
assertThat(testProject.getApiLines()).containsSequence(
"public class net.corda.example.ImplementingClass extends java.lang.Object implements java.io.Closeable",
" public <init>()",
" public void close()",
"##");
}
}

View File

@ -1,52 +1,28 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class ExtendedInterfaceTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "extended-interface");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("extended-interface/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testExtendedInterface() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "extended-interface.txt");
assertThat(api).isRegularFile();
assertEquals(
"public interface net.corda.example.ExtendedInterface extends java.util.concurrent.Future\n" +
" public abstract String getName()\n" +
" public abstract void setName(String)\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,55 +1,31 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.gradle.testkit.runner.TaskOutcome.*;
import static org.junit.Assert.*;
public class FieldWithInternalAnnotationTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "field-internal-annotation");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("field-internal-annotation/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testFieldWithInternalAnnotations() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
assertThat(output)
assertThat(testProject.getOutput())
.contains("net.corda.example.field.InvisibleAnnotation")
.contains("net.corda.example.field.LocalInvisibleAnnotation");
Path api = pathOf(testProjectDir, "build", "api", "field-internal-annotation.txt");
assertThat(api).isRegularFile();
assertEquals("public class net.corda.example.field.HasVisibleField extends java.lang.Object\n" +
" public <init>()\n" +
" public String hasInvisibleAnnotations\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -0,0 +1,101 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.joining;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.gradle.testkit.runner.TaskOutcome.*;
import static org.junit.Assert.*;
/**
* JUnit rule to execute the scanApi Gradle task. This rule should be chained with TemporaryFolder.
*/
public class GradleProject implements TestRule {
private static final String testGradleUserHome = System.getProperty("test.gradle.user.home", "");
private final TemporaryFolder projectDir;
private final String name;
private String output;
private Path api;
public GradleProject(TemporaryFolder projectDir, String name) {
this.projectDir = projectDir;
this.name = name;
this.output = "";
}
public Path getApi() {
return api;
}
public List<String> getApiLines() throws IOException {
// Files.readAllLines() uses UTF-8 by default.
return (api == null) ? emptyList() : Files.readAllLines(api);
}
public String getApiText() throws IOException {
return getApiLines().stream().collect(joining("\n"));
}
public String getOutput() {
return output;
}
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
installResource(projectDir, name + "/build.gradle");
installResource(projectDir, "gradle.properties");
BuildResult result = GradleRunner.create()
.withProjectDir(projectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
api = pathOf(projectDir, "build", "api", name + ".txt");
assertThat(api).isRegularFile();
base.evaluate();
}
};
}
public static Path pathOf(TemporaryFolder folder, String... elements) {
return Paths.get(folder.getRoot().getAbsolutePath(), elements);
}
public static List<String> getGradleArgsForTasks(String... taskNames) {
List<String> args = new ArrayList<>(taskNames.length + 3);
Collections.addAll(args, taskNames);
args.add("--info");
if (!testGradleUserHome.isEmpty()) {
Collections.addAll(args,"-g", testGradleUserHome);
}
return args;
}
}

View File

@ -1,52 +1,28 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class InternalAnnotationTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "internal-annotation");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("internal-annotation/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testInternalAnnotations() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
assertThat(output)
assertThat(testProject.getOutput())
.contains("net.corda.core.CordaInternal")
.contains("net.corda.example.CordaInternal");
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "internal-annotation.txt");
assertThat(api).isRegularFile();
assertEquals("", CopyUtils.toString(api));
assertEquals("", testProject.getApiText());
}
}

View File

@ -1,51 +1,27 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.gradle.testkit.runner.TaskOutcome.*;
import static org.junit.Assert.*;
public class InternalFieldTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "internal-field");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("internal-field/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testInternalField() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "internal-field.txt");
assertThat(api).isRegularFile();
assertEquals(
"public class net.corda.example.WithInternalField extends java.lang.Object\n" +
" public <init>()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,50 +1,27 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.*;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class InternalMethodTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "internal-method");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("internal-method/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testInternalMethod() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "internal-method.txt");
assertThat(api).isRegularFile();
assertEquals(
"public class net.corda.example.WithInternalMethod extends java.lang.Object\n" +
" public <init>()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,53 +1,29 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class InternalPackageTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "internal-package");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("internal-package/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testInternalPackageIsIgnored() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
assertThat(output).contains("net.corda.internal.InvisibleClass");
Path api = pathOf(testProjectDir, "build", "api", "internal-package.txt");
assertThat(api).isRegularFile();
assertThat(testProject.getOutput()).contains("net.corda.internal.InvisibleClass");
assertEquals(
"public class net.corda.VisibleClass extends java.lang.Object\n" +
"public class net.corda.VisibleClass extends java.lang.Object\n" +
" public <init>()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,69 +1,98 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class KotlinAnnotationsTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private static final TemporaryFolder testProjectDir = new TemporaryFolder();
private static final GradleProject testProject = new GradleProject(testProjectDir, "kotlin-annotations");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("kotlin-annotations/build.gradle", buildFile);
@ClassRule
public static final TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
private static final String[] expectedClassWithDeprecatedFunctions = {
"public final class net.corda.example.HasDeprecatedFunctions extends java.lang.Object",
" public <init>()",
" @NotNull",
" public final String doSomething()",
"##"
};
private static final String[] expectedClassWithJvmField = {
"public final class net.corda.example.HasJvmField extends java.lang.Object",
" public <init>()",
" @NotNull",
" public final String stringValue = \"Hello World\"",
"##"
};
private static final String[] expectedClassWithJvmStaticFunction = {
"public final class net.corda.example.HasJvmStaticFunction extends java.lang.Object",
" public <init>()",
" public static final void doThing(String)",
" public static final net.corda.example.HasJvmStaticFunction$Companion Companion",
"##"
};
private static final String[] expectedClassWithJvmStaticFunctionCompanion = {
"public static final class net.corda.example.HasJvmStaticFunction$Companion extends java.lang.Object",
" public final void doThing(String)",
"##"
};
private static final String[] expectedClassWithOverloadedConstructor = {
"public final class net.corda.example.HasOverloadedConstructor extends java.lang.Object",
" public <init>()",
" public <init>(String)",
" public <init>(String, String)",
" public <init>(String, String, int)",
" @NotNull",
" public final String getNotNullable()",
" @Nullable",
" public final String getNullable()",
" public final int getNumber()",
"##"
};
@Test
public void testDeprecatedAnnotation() throws IOException {
assertThat(testProject.getApiLines())
.containsSequence(expectedClassWithDeprecatedFunctions);
}
@Test
public void testKotlinAnnotations() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
public void testJvmFieldAnnotation() throws IOException {
assertThat(testProject.getApiLines())
.containsSequence(expectedClassWithJvmField);
}
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
@Test
public void testJvmStaticAnnotation() throws IOException {
assertThat(testProject.getApiLines())
.containsSequence(expectedClassWithJvmStaticFunction)
.containsSequence(expectedClassWithJvmStaticFunctionCompanion);
}
Path api = pathOf(testProjectDir, "build", "api", "kotlin-annotations.txt");
assertThat(api).isRegularFile();
assertEquals(
"public final class net.corda.example.HasJvmField extends java.lang.Object\n" +
" public <init>()\n" +
" @org.jetbrains.annotations.NotNull public final String stringValue = \"Hello World\"\n" +
"##\n" +
"public final class net.corda.example.HasJvmStaticFunction extends java.lang.Object\n" +
" public <init>()\n" +
" @kotlin.jvm.JvmStatic public static final void doThing(String)\n" +
" public static final net.corda.example.HasJvmStaticFunction$Companion Companion\n" +
"##\n" +
"public static final class net.corda.example.HasJvmStaticFunction$Companion extends java.lang.Object\n" +
" @kotlin.jvm.JvmStatic public final void doThing(String)\n" +
"##\n" +
"public final class net.corda.example.HasOverloadedConstructor extends java.lang.Object\n" +
" public <init>()\n" +
" public <init>(String)\n" +
" public <init>(String, String)\n" +
" public <init>(String, String, int)\n" +
" @org.jetbrains.annotations.NotNull public final String getNotNullable()\n" +
" @org.jetbrains.annotations.Nullable public final String getNullable()\n" +
" public final int getNumber()\n" +
"##\n", CopyUtils.toString(api));
@Test
public void testJvmOverloadedAnnotation() throws IOException {
assertThat(testProject.getApiLines())
.containsSequence(expectedClassWithOverloadedConstructor);
}
@Test
public void testJvmDefaultAnnotation() throws IOException {
assertThat(testProject.getApiLines())
.containsSequence(
"public interface net.corda.example.HasDefaultMethod",
" public void doSomething(String)",
"##"
);
}
}

View File

@ -0,0 +1,27 @@
package net.corda.plugins;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class KotlinAutoGeneratedClassTest {
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "kotlin-auto-generated-class");
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testKotlinAutoGeneratedClassMethod() throws IOException {
assertEquals("public final class net.corda.example.ContainsAutoGeneratedClass extends java.lang.Object\n" +
" public <init>()\n" +
" public final void methodContainingInlinedFunction()\n" +
"##", testProject.getApiText());
}
}

View File

@ -1,53 +1,29 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
import static org.junit.Assert.*;
public class KotlinInternalAnnotationTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "kotlin-internal-annotation");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("kotlin-internal-annotation/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testKotlinInternalAnnotation() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
assertThat(output).contains("net.corda.example.kotlin.CordaInternal");
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "kotlin-internal-annotation.txt");
assertThat(api).isRegularFile();
assertThat(testProject.getOutput()).contains("net.corda.example.kotlin.CordaInternal");
assertEquals(
"public final class net.corda.example.kotlin.AnnotatedClass extends java.lang.Object\n" +
" public <init>()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,53 +1,29 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class KotlinLambdasTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "kotlin-lambdas");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("kotlin-lambdas/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testKotlinLambdas() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
assertThat(output).contains("net.corda.example.LambdaExpressions$testing$$inlined$schedule$1");
Path api = pathOf(testProjectDir, "build", "api", "kotlin-lambdas.txt");
assertThat(api).isRegularFile();
assertThat(testProject.getOutput()).contains("net.corda.example.LambdaExpressions$testing$$inlined$schedule$1");
assertEquals("public final class net.corda.example.LambdaExpressions extends java.lang.Object\n" +
" public <init>()\n" +
" public final void testing(kotlin.Unit)\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,48 +1,38 @@
package net.corda.plugins;
import org.gradle.testkit.runner.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
public class KotlinVarargMethodTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "kotlin-vararg-method");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("kotlin-vararg-method/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
private static final String[] expectedInterfaceWithVarargMethod = {
"public interface net.corda.example.KotlinVarargMethod",
" public abstract void action(int...)",
"##"
};
private static final String[] expectedInterfaceWithArrayVarargMethod = {
"public interface net.corda.example.KotlinVarargArrayMethod",
" public abstract void action(String[]...)",
"##"
};
@Test
public void testKotlinVarargMethod() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "kotlin-vararg-method.txt");
assertThat(api).isRegularFile();
assertEquals("public interface net.corda.example.KotlinVarargMethod\n" +
" public abstract void action(Object...)\n" +
"##\n", CopyUtils.toString(api));
assertThat(testProject.getApiLines())
.containsSequence(expectedInterfaceWithVarargMethod)
.containsSequence(expectedInterfaceWithArrayVarargMethod);
}
}

View File

@ -1,55 +1,32 @@
package net.corda.plugins;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import static org.gradle.testkit.runner.TaskOutcome.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
public class MethodWithInternalAnnotationTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "method-internal-annotation");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("method-internal-annotation/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testMethodWithInternalAnnotations() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
assertThat(output)
assertThat(testProject.getOutput())
.contains("net.corda.example.method.InvisibleAnnotation")
.contains("net.corda.example.method.LocalInvisibleAnnotation");
Path api = pathOf(testProjectDir, "build", "api", "method-internal-annotation.txt");
assertThat(api).isRegularFile();
assertEquals("public class net.corda.example.method.HasVisibleMethod extends java.lang.Object\n" +
" public <init>()\n" +
" public void hasInvisibleAnnotations()\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -1,48 +1,26 @@
package net.corda.plugins;
import org.gradle.testkit.runner.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import static net.corda.plugins.CopyUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
import static org.junit.Assert.*;
public class VarargMethodTest {
@Rule
public final TemporaryFolder testProjectDir = new TemporaryFolder();
private final TemporaryFolder testProjectDir = new TemporaryFolder();
private final GradleProject testProject = new GradleProject(testProjectDir, "vararg-method");
@Before
public void setup() throws IOException {
File buildFile = testProjectDir.newFile("build.gradle");
copyResourceTo("vararg-method/build.gradle", buildFile);
}
@Rule
public TestRule rules = RuleChain.outerRule(testProjectDir).around(testProject);
@Test
public void testVarargMethod() throws IOException {
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments(getGradleArgsForTasks("scanApi"))
.withPluginClasspath()
.build();
String output = result.getOutput();
System.out.println(output);
BuildTask scanApi = result.task(":scanApi");
assertNotNull(scanApi);
assertEquals(SUCCESS, scanApi.getOutcome());
Path api = pathOf(testProjectDir, "build", "api", "vararg-method.txt");
assertThat(api).isRegularFile();
assertEquals("public interface net.corda.example.VarargMethod\n" +
" public abstract void action(Object...)\n" +
"##\n", CopyUtils.toString(api));
"##", testProject.getApiText());
}
}

View File

@ -0,0 +1,9 @@
package net.corda.example;
import net.corda.annotation.*;
import net.corda.core.*;
@AnAnnotation
@DoNotImplement
public class DoNotImplementAnnotation {
}

View File

@ -1,6 +1,7 @@
package net.corda.example;
import net.corda.annotation.*;
import net.corda.core.*;
@NotInherited
@IsInherited

View File

@ -1,4 +1,4 @@
package net.corda.example;
public class InheritingAnnotations extends HasInheritedAnnotation {
}
}

View File

@ -0,0 +1,9 @@
package net.corda.example;
import net.corda.annotation.*;
import net.corda.core.*;
@AnAnnotation
@DoNotImplement
public interface DoNotImplementAnnotation {
}

View File

@ -1,6 +1,7 @@
package net.corda.example;
import net.corda.annotation.*;
import net.corda.core.*;
@NotInherited
@IsInherited

View File

@ -5,4 +5,4 @@ public class HasAnnotatedMethod {
public void hasAnnotation() {
System.out.println("VISIBLE ANNOTATIONS");
}
}
}

View File

@ -0,0 +1,6 @@
package net.corda.example;
public class HasDeprecatedMethod {
@Deprecated
public void isDeprecated() { System.out.println("IS DEPRECATED");}
}

View File

@ -0,0 +1,9 @@
package net.corda.example;
import java.io.*;
public class ImplementingClass implements Closeable {
@Override
public void close() throws IOException {
}
}

View File

@ -0,0 +1 @@
org.gradle.jvmargs=-javaagent:"$jacocoAgent"=destfile="$buildDir/jacoco/test.exec",includes=net/corda/plugins/**

View File

@ -23,6 +23,13 @@ dependencies {
compile 'org.jetbrains.kotlin:kotlin-reflect:$kotlin_version'
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = ['-Xenable-jvm-default']
}
}
jar {
baseName = "kotlin-annotations"
}

View File

@ -0,0 +1,12 @@
@file:Suppress("UNUSED")
package net.corda.example
interface HasDefaultMethod {
// This annotation is an experimental feature of Kotlin 1.2.40
// and IntelliJ is probably complaining about it. But it will
// still build successfully in Gradle.
@JvmDefault
fun doSomething(message: String) {
println(message)
}
}

View File

@ -0,0 +1,7 @@
@file:Suppress("UNUSED")
package net.corda.example
class HasDeprecatedFunctions @Deprecated("Dont use this anymore!") constructor () {
@Deprecated("Dont use this anymore!")
fun doSomething() = "123"
}

View File

@ -1,3 +1,4 @@
@file:Suppress("UNUSED")
package net.corda.example
class HasJvmField {

View File

@ -1,3 +1,4 @@
@file:Suppress("UNUSED")
package net.corda.example
class HasJvmStaticFunction {

View File

@ -1,3 +1,4 @@
@file:Suppress("UNUSED")
package net.corda.example
class HasOverloadedConstructor @JvmOverloads constructor (

View File

@ -0,0 +1,32 @@
plugins {
id 'net.corda.plugins.api-scanner'
id 'org.jetbrains.kotlin.jvm' version '$kotlin_version'
}
description 'Test appearance of Kotlin lambdas'
repositories {
mavenLocal()
mavenCentral()
}
sourceSets {
main {
kotlin {
srcDir file("../resources/test/kotlin-auto-generated-class/kotlin")
}
}
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version'
compile 'org.jetbrains.kotlin:kotlin-reflect:$kotlin_version'
}
jar {
baseName = "kotlin-auto-generated-class"
}
scanApi {
verbose = true
}

View File

@ -0,0 +1,19 @@
package net.corda.example
class ContainsAutoGeneratedClass {
private open class PrivateInnerClass
private inline fun runSomething(crossinline action: PrivateInnerClass.() -> Unit): PrivateInnerClass {
return object: PrivateInnerClass() {
fun run() = action()
}
}
private val timer = PrivateInnerClass()
fun methodContainingInlinedFunction() {
runSomething {
println()
}
}
}

View File

@ -1,5 +1,9 @@
package net.corda.example
interface KotlinVarargMethod {
fun action(vararg arg: Any?)
fun action(vararg arg: Int)
}
interface KotlinVarargArrayMethod {
fun action(vararg arg: Array<String>)
}

View File

@ -91,7 +91,7 @@ open class Baseform : DefaultTask() {
val plugin = project.convention.getPlugin(JavaPluginConvention::class.java)
val classpath = plugin.sourceSets.getByName(MAIN_SOURCE_SET_NAME).runtimeClasspath
val urls = classpath.files.map { it.toURI().toURL() }.toTypedArray()
return URLClassLoader(urls, javaClass.classLoader).loadClass("net.corda.nodeapi.internal.network.NetworkBootstrapper")
return URLClassLoader(urls).loadClass("net.corda.nodeapi.internal.network.NetworkBootstrapper")
}
/**