use of javax.xml.xpath.XPathExpression in project camel by apache.
the class XPathBuilder method evaluateAs.
/**
* Evaluates the expression as the given result type
*/
protected Object evaluateAs(Exchange exchange, QName resultQName) {
// pool a pre compiled expression from pool
XPathExpression xpathExpression = pool.poll();
if (xpathExpression == null) {
LOG.trace("Creating new XPathExpression as none was available from pool");
// no avail in pool then create one
try {
xpathExpression = createXPathExpression();
} catch (XPathExpressionException e) {
throw new InvalidXPathExpression(getText(), e);
} catch (Exception e) {
throw new RuntimeExpressionException("Cannot create xpath expression", e);
}
} else {
LOG.trace("Acquired XPathExpression from pool");
}
try {
if (logNamespaces && LOG.isInfoEnabled()) {
logNamespaces(exchange);
}
return doInEvaluateAs(xpathExpression, exchange, resultQName);
} finally {
// release it back to the pool
pool.add(xpathExpression);
LOG.trace("Released XPathExpression back to pool");
}
}
use of javax.xml.xpath.XPathExpression in project buck by facebook.
the class SchemeGeneratorTest method schemeWithMultipleTargetsBuildsInCorrectOrder.
@Test
public void schemeWithMultipleTargetsBuildsInCorrectOrder() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget leftTarget = new PBXNativeTarget("leftRule");
leftTarget.setGlobalID("leftGID");
leftTarget.setProductReference(new PBXFileReference("left.a", "left.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
leftTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget rightTarget = new PBXNativeTarget("rightRule");
rightTarget.setGlobalID("rightGID");
rightTarget.setProductReference(new PBXFileReference("right.a", "right.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rightTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget childTarget = new PBXNativeTarget("childRule");
childTarget.setGlobalID("childGID");
childTarget.setProductReference(new PBXFileReference("child.a", "child.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
childTarget.setProductType(ProductType.STATIC_LIBRARY);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(leftTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(rightTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(childTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(childTarget), ImmutableSet.of(rootTarget, leftTarget, rightTarget, childTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
String schemeXml = projectFilesystem.readFileIfItExists(schemePath).get();
System.out.println(schemeXml);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
XPathExpression expr = xpath.compile("//BuildAction//BuildableReference/@BlueprintIdentifier");
NodeList nodes = (NodeList) expr.evaluate(scheme, XPathConstants.NODESET);
List<String> expectedOrdering = ImmutableList.of("rootGID", "leftGID", "rightGID", "childGID");
List<String> actualOrdering = Lists.newArrayList();
for (int i = 0; i < nodes.getLength(); i++) {
actualOrdering.add(nodes.item(i).getNodeValue());
}
assertThat(actualOrdering, equalTo(expectedOrdering));
}
use of javax.xml.xpath.XPathExpression in project buck by facebook.
the class SchemeGeneratorTest method whenProvidedAPrimaryTargetThatIsBuiltWithBuckLaunchesIt.
@Test
public void whenProvidedAPrimaryTargetThatIsBuiltWithBuckLaunchesIt() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductName("Foo");
String runnablePath = "buck-out/gen/Foo/Foo.app";
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), true, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.of(runnablePath), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath runnableLaunchActionXPath = xpathFactory.newXPath();
XPathExpression runnableLaunchActionExpr = runnableLaunchActionXPath.compile("//LaunchAction/PathRunnable");
NodeList runnables = (NodeList) runnableLaunchActionExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(runnables.getLength(), equalTo(1));
Node runnable = runnables.item(0);
assertThat(runnable.getAttributes().getNamedItem("FilePath").getNodeValue(), equalTo(runnablePath));
}
use of javax.xml.xpath.XPathExpression in project buck by facebook.
the class SchemeGeneratorTest method buildableReferenceShouldHaveExpectedProperties.
@Test
public void buildableReferenceShouldHaveExpectedProperties() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath buildableReferenceXPath = xpathFactory.newXPath();
XPathExpression buildableReferenceExpr = buildableReferenceXPath.compile("//BuildableReference");
NodeList buildableReferences = (NodeList) buildableReferenceExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(buildableReferences.getLength(), greaterThan(0));
for (int i = 0; i < buildableReferences.getLength(); i++) {
NamedNodeMap attributes = buildableReferences.item(i).getAttributes();
assertThat(attributes, notNullValue());
assertThat(attributes.getNamedItem("BlueprintIdentifier"), notNullValue());
assertThat(attributes.getNamedItem("BuildableIdentifier"), notNullValue());
assertThat(attributes.getNamedItem("ReferencedContainer"), notNullValue());
assertThat(attributes.getNamedItem("BlueprintName"), notNullValue());
assertThat(attributes.getNamedItem("BuildableName"), notNullValue());
}
}
use of javax.xml.xpath.XPathExpression in project buck by facebook.
the class SchemeGeneratorTest method schemeIncludesAllExpectedActions.
@Test
public void schemeIncludesAllExpectedActions() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget testTarget = new PBXNativeTarget("testRule");
testTarget.setGlobalID("testGID");
testTarget.setProductReference(new PBXFileReference("test.a", "test.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
testTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget testBundleTarget = new PBXNativeTarget("testBundleRule");
testBundleTarget.setGlobalID("testBundleGID");
testBundleTarget.setProductReference(new PBXFileReference("test.xctest", "test.xctest", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
testBundleTarget.setProductType(ProductType.UNIT_TEST);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(testTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(testBundleTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(testBundleTarget), ImmutableSet.of(testBundleTarget), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
String schemeXml = projectFilesystem.readFileIfItExists(schemePath).get();
System.out.println(schemeXml);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath buildActionXpath = xpathFactory.newXPath();
XPathExpression buildActionExpr = buildActionXpath.compile("//BuildAction//BuildableReference/@BlueprintIdentifier");
NodeList buildActionNodes = (NodeList) buildActionExpr.evaluate(scheme, XPathConstants.NODESET);
List<String> expectedOrdering = ImmutableList.of("rootGID", "testBundleGID");
List<String> actualOrdering = Lists.newArrayList();
for (int i = 0; i < buildActionNodes.getLength(); i++) {
actualOrdering.add(buildActionNodes.item(i).getNodeValue());
}
assertThat(actualOrdering, equalTo(expectedOrdering));
XPath testActionXpath = xpathFactory.newXPath();
XPathExpression testActionExpr = testActionXpath.compile("//TestAction//BuildableReference/@BlueprintIdentifier");
String testActionBlueprintIdentifier = (String) testActionExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(testActionBlueprintIdentifier, equalTo("testBundleGID"));
XPath launchActionXpath = xpathFactory.newXPath();
XPathExpression launchActionExpr = launchActionXpath.compile("//LaunchAction//BuildableReference/@BlueprintIdentifier");
String launchActionBlueprintIdentifier = (String) launchActionExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(launchActionBlueprintIdentifier, equalTo("rootGID"));
XPath profileActionXpath = xpathFactory.newXPath();
XPathExpression profileActionExpr = profileActionXpath.compile("//ProfileAction//BuildableReference/@BlueprintIdentifier");
String profileActionBlueprintIdentifier = (String) profileActionExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(profileActionBlueprintIdentifier, equalTo("rootGID"));
}
Aggregations