use of javax.xml.xpath.XPathFactory in project buck by facebook.
the class SchemeGeneratorTest method launchActionShouldNotContainRemoteRunnableWhenNotProvided.
@Test
public void launchActionShouldNotContainRemoteRunnableWhenNotProvided() 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 remoteRunnableLaunchActionXPath = xpathFactory.newXPath();
XPathExpression remoteRunnableLaunchActionExpr = remoteRunnableLaunchActionXPath.compile("//LaunchAction/RemoteRunnable");
NodeList remoteRunnables = (NodeList) remoteRunnableLaunchActionExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(remoteRunnables.getLength(), equalTo(0));
}
use of javax.xml.xpath.XPathFactory in project buck by facebook.
the class SchemeGeneratorTest method whenProvidedAPrimaryTargetThatIsBuiltWithBuckDoesntBuildDependencies.
@Test
public void whenProvidedAPrimaryTargetThatIsBuiltWithBuckDoesntBuildDependencies() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget libraryTarget = new PBXNativeTarget("library");
libraryTarget.setGlobalID("libraryGID");
libraryTarget.setProductReference(new PBXFileReference("lib.a", "lib.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
libraryTarget.setProductType(ProductType.STATIC_LIBRARY);
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(libraryTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(libraryTarget, 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 buildActionXpath = xpathFactory.newXPath();
XPathExpression buildActionExpr = buildActionXpath.compile("//BuildAction//BuildActionEntry");
NodeList buildActionNodes = (NodeList) buildActionExpr.evaluate(scheme, XPathConstants.NODESET);
Node libraryNode = null;
for (int i = 0; i < buildActionNodes.getLength(); i++) {
Node node = buildActionNodes.item(i);
if (node.getChildNodes().getLength() != 1) {
continue;
}
Node buildableReference = node.getChildNodes().item(0);
if (buildableReference.getAttributes().getNamedItem("BlueprintIdentifier").getNodeValue().equals("libraryGID")) {
libraryNode = node;
break;
}
}
assertThat(libraryNode, is(notNullValue()));
assertThat(libraryNode.getAttributes().getNamedItem("buildForRunning").getNodeValue(), equalTo("NO"));
}
use of javax.xml.xpath.XPathFactory in project buck by facebook.
the class SchemeGeneratorTest method schemeWithNoPrimaryRuleCanIncludeTests.
@Test
public void schemeWithNoPrimaryRuleCanIncludeTests() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget testLibraryTarget = new PBXNativeTarget("testLibrary");
testLibraryTarget.setGlobalID("testLibraryGID");
testLibraryTarget.setProductReference(new PBXFileReference("lib.a", "lib.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
testLibraryTarget.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(testLibraryTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(testTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(testBundleTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.empty(), ImmutableSet.of(), 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("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(""));
XPath launchActionBuildConfigurationXpath = xpathFactory.newXPath();
XPathExpression launchActionBuildConfigurationExpr = launchActionBuildConfigurationXpath.compile("//LaunchAction//@buildConfiguration");
String launchActionBuildConfigurationBlueprintIdentifier = (String) launchActionBuildConfigurationExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(launchActionBuildConfigurationBlueprintIdentifier, equalTo("Debug"));
XPath profileActionXpath = xpathFactory.newXPath();
XPathExpression profileActionExpr = profileActionXpath.compile("//ProfileAction//BuildableReference/@BlueprintIdentifier");
String profileActionBlueprintIdentifier = (String) profileActionExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(profileActionBlueprintIdentifier, equalTo(""));
XPath profileActionBuildConfigurationXpath = xpathFactory.newXPath();
XPathExpression profileActionBuildConfigurationExpr = profileActionBuildConfigurationXpath.compile("//ProfileAction//@buildConfiguration");
String profileActionBuildConfigurationBlueprintIdentifier = (String) profileActionBuildConfigurationExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(profileActionBuildConfigurationBlueprintIdentifier, equalTo("Release"));
XPath analyzeActionBuildConfigurationXpath = xpathFactory.newXPath();
XPathExpression analyzeActionBuildConfigurationExpr = analyzeActionBuildConfigurationXpath.compile("//AnalyzeAction//@buildConfiguration");
String analyzeActionBuildConfigurationBlueprintIdentifier = (String) analyzeActionBuildConfigurationExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(analyzeActionBuildConfigurationBlueprintIdentifier, equalTo("Debug"));
XPath archiveActionBuildConfigurationXpath = xpathFactory.newXPath();
XPathExpression archiveActionBuildConfigurationExpr = archiveActionBuildConfigurationXpath.compile("//ArchiveAction//@buildConfiguration");
String archiveActionBuildConfigurationBlueprintIdentifier = (String) archiveActionBuildConfigurationExpr.evaluate(scheme, XPathConstants.STRING);
assertThat(archiveActionBuildConfigurationBlueprintIdentifier, equalTo("Release"));
}
use of javax.xml.xpath.XPathFactory in project mybatis-3 by mybatis.
the class XPathParser method commonConstructor.
private void commonConstructor(boolean validation, Properties variables, EntityResolver entityResolver) {
this.validation = validation;
this.entityResolver = entityResolver;
this.variables = variables;
XPathFactory factory = XPathFactory.newInstance();
this.xpath = factory.newXPath();
}
use of javax.xml.xpath.XPathFactory in project nutz by nutzam.
the class Xmls method getEles.
/**
* 从一个 XML 元素开始,根据一条 XPath 获取一组元素
*
* @param ele
* XML 元素
* @param xpath
* 要获取的元素的 XPath
* @return 元素列表
*/
public static List<Element> getEles(Element ele, String xpath) {
XPathFactory factory = XPathFactory.newInstance();
XPath xp = factory.newXPath();
try {
XPathExpression expression = xp.compile(xpath);
NodeList nodes = (NodeList) expression.evaluate(ele, XPathConstants.NODESET);
List<Element> list = new ArrayList<Element>();
int len = nodes.getLength();
for (int i = 0; i < len; i++) {
Node node = nodes.item(i);
if (node instanceof Element) {
list.add((Element) node);
}
}
return list;
} catch (XPathExpressionException e) {
throw Lang.wrapThrow(e);
}
}
Aggregations