XMLUnit を使用して 2 つの Maven POM ファイルの違いを取得しようとしています。まず私のコード:
package com.company.control.cfgmgnt.tools.pommerge.core.internal.xml.comparison;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.DifferenceConstants;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
import com.company.control.cfgmgnt.tools.pommerge.core.internal.xml.DocumentReader;
public class ComparisonTask extends XMLTestCase
{
public List<Difference> testAllDifferences( final File f1, final File f2, final boolean includeComments )
throws Exception {
XMLUnit.setIgnoreComments( !includeComments );
XMLUnit.setIgnoreWhitespace( true );
String myControlXML = DocumentReader.readXMLfile2String( f1 );
String myTestXML = DocumentReader.readXMLfile2String( f2 );
DetailedDiff myDiff = new DetailedDiff( compareXML( myControlXML, myTestXML ) );
myDiff.overrideElementQualifier( new RecursiveElementNameAndTextQualifier() );
List<Difference> _out = cleanDifferenceOutput( myDiff.getAllDifferences() );
return _out;
}
private static List<Difference> cleanDifferenceOutput( final List<Difference> list ) {
ArrayList<Difference> out = new ArrayList<Difference>();
for ( Difference dif : list ) {
if ( ( dif.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID )
|| ( dif.getId() == DifferenceConstants.TEXT_VALUE_ID ) ) {
out.add( dif );
}
}
return out;
}
}
コントロールPOMは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>phoenix-parent</artifactId>
<groupId>com.company.phoenix</groupId>
<version>1.24.0-control-java7-SNAPSHOT</version>
</parent>
<groupId>com.company.control.project</groupId>
<artifactId>project</artifactId>
<version>1.0.0-control-java7-SNAPSHOT</version>
<packaging>pom</packaging>
<developers>
<developer>
<!-- user id of the responsible person (used for email) -->
<id>xyyyyy</id>
<!-- display name of responsible person -->
<name>xxxxx yyyyy</name>
<roles>
<role>projectmanager</role>
</roles>
<properties>
<!-- end date of this project, it will be automatically removed afterwards -->
<estimatedProjectEndDate>2014/01/08</estimatedProjectEndDate>
</properties>
</developer>
</developers>
<scm>
<connection>scm:svn:http://svn.company.com/phoenix/svn/phoenix/projects/feature/control-java7/trunk</connection>
<developerConnection>scm:svn:http://svn.company.com/phoenix/svn/phoenix/projects/feature/control-java7/trunk</developerConnection>
<url><![CDATA[http://svn.company.com/phoenix/svn/phoenix/projects/feature/control-java7/]]></url>
</scm>
<issueManagement>
<system>JIRA</system>
<url>http://jira.company.com/browse/TFWK</url>
</issueManagement>
...そしてテストPOM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parent</artifactId>
<groupId>com.company</groupId>
<version>1.24.2-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<groupId>com.company.control.project</groupId>
<artifactId>project</artifactId>
<version>1.1.5-SNAPSHOT</version>
<packaging>pom</packaging>
<description>project aggregator for project.stabletrunk</description>
<issueManagement>
<system>JIRA</system>
<url>http://jira.company.com/browse/</url>
</issueManagement>
<distributionManagement>
<site>
<id>maven-sites</id>
<name>repository for Maven Websites</name>
<url>scp://phoenix-sites.company.com/maven-sites/projects/stableTrunk/${project.version}/</url>
</site>
</distributionManagement>
<properties>
<sonar.branch>${project.artifactId}</sonar.branch>
<sonar.host.url>http://phoenix-sonar.company.com</sonar.host.url>
</properties>
違いの XPath を出力すると、次のコントロール/テスト ペアが得られます。
/project[1]/parent[1]/artifactId[1]/text()[1]
/project[1]/parent[1]/artifactId[1]/text()[1]
/project[1]/parent[1]/groupId[1]/text()[1]
/project[1]/parent[1]/groupId[1]/text()[1]
/project[1]/parent[1]/version[1]/text()[1]
/project[1]/parent[1]/version[1]/text()[1]
null
/project[1]/parent[1]/relativePath[1]
/project[1]/version[1]/text()[1]
/project[1]/version[1]/text()[1]
/project[1]/developers[1]/developer[1]/id[1]
null
/project[1]/developers[1]/developer[1]/name[1]
null
/project[1]/developers[1]/developer[1]/roles[1]
null
/project[1]/developers[1]/developer[1]/properties[1]
null
/project[1]/scm[1]/connection[1]/text()[1]
/project[1]/issueManagement[1]/system[1]/text()[1]
/project[1]/scm[1]/developerConnection[1]/text()[1]
/project[1]/issueManagement[1]/url[1]/text()[1]
/project[1]/scm[1]/url[1]
null
null
/project[1]/distributionManagement[1]/site[1]/id[1]/text()[1]
null
/project[1]/distributionManagement[1]/site[1]/name[1]
null
/project[1]/distributionManagement[1]/site[1]/url[1]
/project[1]/issueManagement[1]/url[1]
null
null
/project[1]/properties[1]
そして今、私の質問: 要素「issueManagement」が一致しないのはなぜですか? それは両方のPOMにあります...