private AnnotationNode createGrabAnnotation(String group, String module, String version, String classifier, String type, boolean transitive) { AnnotationNode annotationNode = new AnnotationNode(new ClassNode(Grab.class)); annotationNode.addMember("group", new ConstantExpression(group)); annotationNode.addMember("module", new ConstantExpression(module)); annotationNode.addMember("version", new ConstantExpression(version)); if (classifier != null) { annotationNode.addMember("classifier", new ConstantExpression(classifier)); } if (type != null) { annotationNode.addMember("type", new ConstantExpression(type)); } annotationNode.addMember("transitive", new ConstantExpression(transitive)); annotationNode.addMember("initClass", new ConstantExpression(false)); return annotationNode; }
private void visitModule(ModuleNode module) { for (ClassNode classNode : module.getClasses()) { AnnotationNode annotation = new AnnotationNode(new ClassNode(Grab.class)); annotation.addMember("value", new ConstantExpression("groovy")); classNode.addAnnotation(annotation); // We only need to do it at most once break; } // Disable the addition of a static initializer that calls Grape.addResolver // because all the dependencies are local now disableGrabResolvers(module.getClasses()); disableGrabResolvers(module.getImports()); }
@Test public void basicAdd() { this.dependencyCustomizer.add("spring-boot-starter-logging"); List<AnnotationNode> grabAnnotations = this.classNode .getAnnotations(new ClassNode(Grab.class)); assertThat(grabAnnotations).hasSize(1); AnnotationNode annotationNode = grabAnnotations.get(0); assertGrabAnnotation(annotationNode, "org.springframework.boot", "spring-boot-starter-logging", "1.2.3", null, null, true); }
@Test public void nonTransitiveAdd() { this.dependencyCustomizer.add("spring-boot-starter-logging", false); List<AnnotationNode> grabAnnotations = this.classNode .getAnnotations(new ClassNode(Grab.class)); assertThat(grabAnnotations).hasSize(1); AnnotationNode annotationNode = grabAnnotations.get(0); assertGrabAnnotation(annotationNode, "org.springframework.boot", "spring-boot-starter-logging", "1.2.3", null, null, false); }
@Test public void fullyCustomized() { this.dependencyCustomizer.add("spring-boot-starter-logging", "my-classifier", "my-type", false); List<AnnotationNode> grabAnnotations = this.classNode .getAnnotations(new ClassNode(Grab.class)); assertThat(grabAnnotations).hasSize(1); AnnotationNode annotationNode = grabAnnotations.get(0); assertGrabAnnotation(annotationNode, "org.springframework.boot", "spring-boot-starter-logging", "1.2.3", "my-classifier", "my-type", false); }
@Test public void anyMissingClassesWithMixtureOfClassesPerformsAdd() { this.dependencyCustomizer .ifAnyMissingClasses(getClass().getName(), "does.not.Exist") .add("spring-boot-starter-logging"); assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1); }
@Test public void allMissingClassesWithMixtureOfClassesDoesNotPerformAdd() { this.dependencyCustomizer .ifAllMissingClasses(getClass().getName(), "does.not.Exist") .add("spring-boot-starter-logging"); assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty(); }
@Test public void allMissingClassesWithAllClassesMissingPerformsAdd() { this.dependencyCustomizer .ifAllMissingClasses("does.not.Exist", "does.not.exist.Either") .add("spring-boot-starter-logging"); assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1); }
@Test public void basicAdd() { this.dependencyCustomizer.add("spring-boot-starter-logging"); List<AnnotationNode> grabAnnotations = this.classNode .getAnnotations(new ClassNode(Grab.class)); assertEquals(1, grabAnnotations.size()); AnnotationNode annotationNode = grabAnnotations.get(0); assertGrabAnnotation(annotationNode, "org.springframework.boot", "spring-boot-starter-logging", "1.2.3", null, null, true); }
@Test public void nonTransitiveAdd() { this.dependencyCustomizer.add("spring-boot-starter-logging", false); List<AnnotationNode> grabAnnotations = this.classNode .getAnnotations(new ClassNode(Grab.class)); assertEquals(1, grabAnnotations.size()); AnnotationNode annotationNode = grabAnnotations.get(0); assertGrabAnnotation(annotationNode, "org.springframework.boot", "spring-boot-starter-logging", "1.2.3", null, null, false); }
@Test public void fullyCustomized() { this.dependencyCustomizer.add("spring-boot-starter-logging", "my-classifier", "my-type", false); List<AnnotationNode> grabAnnotations = this.classNode .getAnnotations(new ClassNode(Grab.class)); assertEquals(1, grabAnnotations.size()); AnnotationNode annotationNode = grabAnnotations.get(0); assertGrabAnnotation(annotationNode, "org.springframework.boot", "spring-boot-starter-logging", "1.2.3", "my-classifier", "my-type", false); }
@Test public void anyMissingClassesWithMixtureOfClassesPerformsAdd() { this.dependencyCustomizer .ifAnyMissingClasses(getClass().getName(), "does.not.Exist") .add("spring-boot-starter-logging"); assertEquals(1, this.classNode.getAnnotations(new ClassNode(Grab.class)).size()); }
@Test public void allMissingClassesWithMixtureOfClassesDoesNotPerformAdd() { this.dependencyCustomizer .ifAllMissingClasses(getClass().getName(), "does.not.Exist") .add("spring-boot-starter-logging"); assertEquals(0, this.classNode.getAnnotations(new ClassNode(Grab.class)).size()); }
@Test public void allMissingClassesWithAllClassesMissingPerformsAdd() { this.dependencyCustomizer .ifAllMissingClasses("does.not.Exist", "does.not.exist.Either") .add("spring-boot-starter-logging"); assertEquals(1, this.classNode.getAnnotations(new ClassNode(Grab.class)).size()); }
@Test public void anyMissingClassesWithMissingClassesPerformsAdd() { this.dependencyCustomizer.ifAnyMissingClasses("does.not.Exist") .add("spring-boot-starter-logging"); assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1); }
@Test public void anyMissingClassesWithNoMissingClassesDoesNotPerformAdd() { this.dependencyCustomizer.ifAnyMissingClasses(getClass().getName()) .add("spring-boot-starter-logging"); assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty(); }
@Test public void allMissingClassesWithNoMissingClassesDoesNotPerformAdd() { this.dependencyCustomizer.ifAllMissingClasses(getClass().getName()) .add("spring-boot-starter-logging"); assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty(); }
private AnnotationNode createGrabAnnotation() { ClassNode classNode = new ClassNode(Grab.class); AnnotationNode annotationNode = new AnnotationNode(classNode); annotationNode.addMember("value", new ConstantExpression("spring-core")); return annotationNode; }
@Test public void anyMissingClassesWithMissingClassesPerformsAdd() { this.dependencyCustomizer.ifAnyMissingClasses("does.not.Exist") .add("spring-boot-starter-logging"); assertEquals(1, this.classNode.getAnnotations(new ClassNode(Grab.class)).size()); }
@Test public void anyMissingClassesWithNoMissingClassesDoesNotPerformAdd() { this.dependencyCustomizer.ifAnyMissingClasses(getClass().getName()) .add("spring-boot-starter-logging"); assertEquals(0, this.classNode.getAnnotations(new ClassNode(Grab.class)).size()); }
@Test public void allMissingClassesWithNoMissingClassesDoesNotPerformAdd() { this.dependencyCustomizer.ifAllMissingClasses(getClass().getName()) .add("spring-boot-starter-logging"); assertEquals(0, this.classNode.getAnnotations(new ClassNode(Grab.class)).size()); }