Skip to content

Commit

Permalink
1000 volatile field implies dynamic
Browse files Browse the repository at this point in the history
    Signed-off-by David Jencks <david_jencks@yahoo.com>
  • Loading branch information
djencks committed Jul 22, 2015
1 parent c14d0dc commit 14b3d94
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
27 changes: 20 additions & 7 deletions biz.aQute.bnd.test/src/aQute/bnd/test/XmlTester.java
@@ -1,15 +1,22 @@
package aQute.bnd.test;

import java.io.*;
import java.util.*;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;

import javax.xml.namespace.*;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import junit.framework.*;
import junit.framework.Assert;

import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XmlTester {
final static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Expand Down Expand Up @@ -81,6 +88,12 @@ public void assertTrimmedAttribute(String value, String expr) throws XPathExpres
Assert.assertEquals(value, o.trim().replaceAll("\n", "\\\\n"));
}

public void assertNoAttribute(String expr) throws XPathExpressionException {
System.err.println(expr);
String o = (String) xpath.evaluate(expr, document, XPathConstants.STRING);
Assert.assertEquals("", o);
}

public void assertNamespace(String namespace) {
Element element = document.getDocumentElement();
String xmlns = element.getNamespaceURI();
Expand Down
37 changes: 37 additions & 0 deletions biz.aQute.bndlib.tests/src/test/component/DSAnnotationTest.java
Expand Up @@ -2806,4 +2806,41 @@ public static void testMixedStandardBnd() throws Exception {
errors.get(3));
assertEquals(0, b.getWarnings().size());
}

@Component
static class VolatileField {
@Reference
private volatile LogService log1;
@Reference
private LogService log2;
}

public static void testVolatileFieldDynamic() throws Exception {
Builder b = new Builder();
b.setProperty(Constants.DSANNOTATIONS, "test.component.*VolatileField");
b.setProperty("Private-Package", "test.component");
b.addClasspath(new File("bin"));

Jar jar = b.build();
assertOk(b);
Attributes a = getAttr(jar);
checkRequires(a, true, LogService.class.getName());

Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$VolatileField.xml");
System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
assertNotNull(r);
r.write(System.err);
XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
// Test the defaults
xt.assertAttribute("test.component.DSAnnotationTest$VolatileField", "scr:component/implementation/@class");

xt.assertAttribute("log1", "scr:component/reference[1]/@name");
xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
xt.assertAttribute("dynamic", "scr:component/reference[1]/@policy");

xt.assertAttribute("log2", "scr:component/reference[2]/@name");
xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
xt.assertNoAttribute("scr:component/reference[2]/@policy");

}
}
Expand Up @@ -569,6 +569,8 @@ else if (referencesByMember.containsKey(member))
def.field = member.getName();
if (def.name == null)
def.name = def.field;
if (def.policy == null && member.isVolatile())
def.policy = ReferencePolicy.DYNAMIC;

String sig = member.getSignature();
if (sig == null)
Expand Down

0 comments on commit 14b3d94

Please sign in to comment.