use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.
the class ComponentsXmlArchiverFileFilterTest method testAddComponentsXml_ShouldAddComponentWithoutRoleHint.
public void testAddComponentsXml_ShouldAddComponentWithoutRoleHint() throws IOException, XmlPullParserException {
final Reader reader = writeComponentsXml(Collections.singletonList(new ComponentDef("role", null, "org.apache.maven.Impl")));
filter.addComponentsXml(reader);
assertFalse(filter.components.isEmpty());
final Xpp3Dom componentDom = filter.components.get("role");
assertEquals("role", componentDom.getChild("role").getValue());
assertNull(componentDom.getChild("role-hint"));
assertEquals("org.apache.maven.Impl", componentDom.getChild("implementation").getValue());
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.
the class ComponentsXmlArchiverFileFilterTest method createComponentDom.
private Xpp3Dom createComponentDom(final ComponentDef def) {
final Xpp3Dom dom = new Xpp3Dom("component");
final Xpp3Dom role = new Xpp3Dom("role");
role.setValue(def.role);
dom.addChild(role);
final String hint = def.roleHint;
if (hint != null) {
final Xpp3Dom roleHint = new Xpp3Dom("role-hint");
roleHint.setValue(hint);
dom.addChild(roleHint);
}
final Xpp3Dom impl = new Xpp3Dom("implementation");
impl.setValue(def.implementation);
dom.addChild(impl);
return dom;
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.
the class MetadataUtils method createMetadata.
/**
* Creates local metadata files for the specified artifact. The goal is to simulate the installation of the artifact
* by a local build, thereby decoupling the forked builds from the inderministic collection of remote repositories
* that are available to the main build and from which the artifact was originally resolved.
*
* @param file The artifact's file in the local test repository, must not be <code>null</code>.
* @param artifact The artifact to create metadata for, must not be <code>null</code>.
* @throws IOException If the metadata could not be created.
*/
public static void createMetadata(File file, Artifact artifact) throws IOException {
TimeZone tz = java.util.TimeZone.getTimeZone("UTC");
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
fmt.setTimeZone(tz);
String timestamp = fmt.format(new Date());
if (artifact.isSnapshot()) {
File metadataFile = new File(file.getParentFile(), "maven-metadata-local.xml");
Xpp3Dom metadata = new Xpp3Dom("metadata");
addChild(metadata, "groupId", artifact.getGroupId());
addChild(metadata, "artifactId", artifact.getArtifactId());
addChild(metadata, "version", artifact.getBaseVersion());
Xpp3Dom versioning = new Xpp3Dom("versioning");
versioning.addChild(addChild(new Xpp3Dom("snapshot"), "localCopy", "true"));
addChild(versioning, "lastUpdated", timestamp);
metadata.addChild(versioning);
writeMetadata(metadataFile, metadata);
}
File metadataFile = new File(file.getParentFile().getParentFile(), "maven-metadata-local.xml");
Set<String> allVersions = new LinkedHashSet<String>();
Xpp3Dom metadata = readMetadata(metadataFile);
if (metadata != null) {
Xpp3Dom versioning = metadata.getChild("versioning");
if (versioning != null) {
Xpp3Dom versions = versioning.getChild("versions");
if (versions != null) {
Xpp3Dom[] children = versions.getChildren("version");
for (Xpp3Dom aChildren : children) {
allVersions.add(aChildren.getValue());
}
}
}
}
allVersions.add(artifact.getBaseVersion());
metadata = new Xpp3Dom("metadata");
addChild(metadata, "groupId", artifact.getGroupId());
addChild(metadata, "artifactId", artifact.getArtifactId());
Xpp3Dom versioning = new Xpp3Dom("versioning");
versioning.addChild(addChildren(new Xpp3Dom("versions"), "version", allVersions));
addChild(versioning, "lastUpdated", timestamp);
metadata.addChild(versioning);
metadata = Xpp3DomUtils.mergeXpp3Dom(metadata, readMetadata(metadataFile));
writeMetadata(metadataFile, metadata);
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.
the class MetadataUtils method readMetadata.
private static Xpp3Dom readMetadata(File metadataFile) throws IOException {
if (!metadataFile.isFile()) {
return null;
}
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(metadataFile);
final Xpp3Dom xpp3Dom = Xpp3DomBuilder.build(reader);
reader.close();
reader = null;
return xpp3Dom;
} catch (XmlPullParserException e) {
throw (IOException) new IOException(e.getMessage()).initCause(e);
} finally {
IOUtil.close(reader);
}
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project maven-plugins by apache.
the class MetadataUtils method addChild.
private static Xpp3Dom addChild(Xpp3Dom parent, String childName, String childValue) {
Xpp3Dom child = new Xpp3Dom(childName);
child.setValue(childValue);
parent.addChild(child);
return parent;
}
Aggregations