List of usage examples for javax.xml.xpath XPath getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.sonar.dotnet.tools.commons.visualstudio.ModelFactory.java
/** * Generates a list of projects from the path of the visual studio projects files (.csproj) * //w w w.ja v a2 s. c o m * @param projectFile * the project file * @param projectName * the name of the project * @throws DotNetToolsException * @throws FileNotFoundException * if the file was not found */ public static VisualStudioProject getProject(File projectFile, String projectName, List<String> buildConfigurations) throws FileNotFoundException, DotNetToolsException { VisualStudioProject project = new VisualStudioProject(); project.setProjectFile(projectFile); project.setName(projectName); File projectDir = projectFile.getParentFile(); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); // This is a workaround to avoid Xerces class-loading issues ClassLoader savedClassloader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(xpath.getClass().getClassLoader()); try { // We define the namespace prefix for Visual Studio xpath.setNamespaceContext(new VisualStudioNamespaceContext()); if (buildConfigurations != null) { Map<String, File> buildConfOutputDirMap = new HashMap<String, File>(); for (String config : buildConfigurations) { XPathExpression configOutputExpression = xpath.compile( "/vst:Project/vst:PropertyGroup[contains(@Condition,'" + config + "')]/vst:OutputPath"); String configOutput = extractProjectProperty(configOutputExpression, projectFile); buildConfOutputDirMap.put(config, new File(projectDir, configOutput)); } project.setBuildConfOutputDirMap(buildConfOutputDirMap); } XPathExpression projectTypeExpression = xpath.compile("/vst:Project/vst:PropertyGroup/vst:OutputType"); XPathExpression assemblyNameExpression = xpath .compile("/vst:Project/vst:PropertyGroup/vst:AssemblyName"); XPathExpression rootNamespaceExpression = xpath .compile("/vst:Project/vst:PropertyGroup/vst:RootNamespace"); XPathExpression debugOutputExpression = xpath .compile("/vst:Project/vst:PropertyGroup[contains(@Condition,'Debug')]/vst:OutputPath"); XPathExpression releaseOutputExpression = xpath .compile("/vst:Project/vst:PropertyGroup[contains(@Condition,'Release')]/vst:OutputPath"); XPathExpression silverlightExpression = xpath .compile("/vst:Project/vst:PropertyGroup/vst:SilverlightApplication"); // Extracts the properties of a Visual Studio Project String typeStr = extractProjectProperty(projectTypeExpression, projectFile); String silverlightStr = extractProjectProperty(silverlightExpression, projectFile); String assemblyName = extractProjectProperty(assemblyNameExpression, projectFile); String rootNamespace = extractProjectProperty(rootNamespaceExpression, projectFile); String debugOutput = extractProjectProperty(debugOutputExpression, projectFile); String releaseOutput = extractProjectProperty(releaseOutputExpression, projectFile); // Assess if the artifact is a library or an executable ArtifactType type = ArtifactType.LIBRARY; if (StringUtils.containsIgnoreCase(typeStr, "exe")) { type = ArtifactType.EXECUTABLE; } // The project is populated project.setProjectFile(projectFile); project.setType(type); project.setDirectory(projectDir); project.setAssemblyName(assemblyName); project.setRootNamespace(rootNamespace); project.setDebugOutputDir(new File(projectDir, debugOutput)); project.setReleaseOutputDir(new File(projectDir, releaseOutput)); if (StringUtils.isNotEmpty(silverlightStr)) { project.setSilverlightProject(true); } project.setBinaryReferences(getBinaryReferences(xpath, projectFile)); assessTestProject(project, testProjectNamePattern); return project; } catch (XPathExpressionException xpee) { throw new DotNetToolsException("Error while processing the project " + projectFile, xpee); } finally { // Replaces the class loader after usage Thread.currentThread().setContextClassLoader(savedClassloader); } }