use of org.codehaus.plexus.util.xml.XMLWriter in project felix by apache.
the class BaselinePlugin method startBaseline.
@Override
protected void startBaseline(Object context, String generationDate, String bundleName, String currentVersion, String previousVersion) {
final XMLWriter xmlWriter = context == null ? null : ((Context) context).xmlWriter;
if (isLoggingResults()) {
log("Baseline Report - Generated by Apache Felix Maven Bundle Plugin on %s based on Bnd - see http://www.aqute.biz/Bnd/Bnd", generationDate);
log("Comparing bundle %s version %s to version %s", bundleName, currentVersion, previousVersion);
log("");
log(TABLE_PATTERN, " ", "PACKAGE_NAME", "DELTA", "CUR_VER", "BASE_VER", "REC_VER", "WARNINGS", "ATTRIBUTES");
log(TABLE_PATTERN, "=", "==================================================", "==========", "==========", "==========", "==========", "==========", "==========");
}
if (xmlWriter != null) {
xmlWriter.startElement("baseline");
xmlWriter.addAttribute("version", "1.0.0");
xmlWriter.addAttribute("vendor", "The Apache Software Foundation");
xmlWriter.addAttribute("vendorURL", "http://www.apache.org/");
xmlWriter.addAttribute("generator", "Apache Felix Maven Bundle Plugin");
xmlWriter.addAttribute("generatorURL", "http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html");
xmlWriter.addAttribute("analyzer", "Bnd");
xmlWriter.addAttribute("analyzerURL", "http://www.aqute.biz/Bnd/Bnd");
xmlWriter.addAttribute("generatedOn", generationDate);
xmlWriter.addAttribute("bundleName", bundleName);
xmlWriter.addAttribute("currentVersion", currentVersion);
xmlWriter.addAttribute("previousVersion", previousVersion);
}
}
use of org.codehaus.plexus.util.xml.XMLWriter in project felix by apache.
the class BaselinePlugin method startPackage.
@Override
protected void startPackage(Object context, boolean mismatch, String name, String shortDelta, String delta, Version newerVersion, Version olderVersion, Version suggestedVersion, DiffMessage diffMessage, Map<String, String> attributes) {
final XMLWriter xmlWriter = context == null ? null : ((Context) context).xmlWriter;
if (isLoggingResults()) {
log(TABLE_PATTERN, mismatch ? '*' : shortDelta, name, delta, newerVersion, olderVersion, suggestedVersion, diffMessage != null ? diffMessage : '-', attributes);
}
if (xmlWriter != null) {
xmlWriter.startElement("package");
xmlWriter.addAttribute("name", name);
xmlWriter.addAttribute("delta", delta);
simpleElement(xmlWriter, "mismatch", String.valueOf(mismatch));
simpleElement(xmlWriter, "newerVersion", newerVersion.toString());
simpleElement(xmlWriter, "olderVersion", olderVersion.toString());
if (suggestedVersion != null) {
simpleElement(xmlWriter, "suggestedVersion", suggestedVersion.toString());
}
if (diffMessage != null) {
simpleElement(xmlWriter, diffMessage.getType().name(), diffMessage.getMessage());
}
xmlWriter.startElement("attributes");
if (attributes != null) {
for (Entry<String, String> attribute : attributes.entrySet()) {
String attributeName = attribute.getKey();
if (':' == attributeName.charAt(attributeName.length() - 1)) {
attributeName = attributeName.substring(0, attributeName.length() - 1);
}
String attributeValue = attribute.getValue();
xmlWriter.startElement(attributeName);
xmlWriter.writeText(attributeValue);
xmlWriter.endElement();
}
}
xmlWriter.endElement();
}
}
use of org.codehaus.plexus.util.xml.XMLWriter in project felix by apache.
the class BaselinePlugin method startDiff.
@Override
protected void startDiff(Object context, int depth, String type, String name, String delta, String shortDelta) {
final XMLWriter xmlWriter = context == null ? null : ((Context) context).xmlWriter;
if (isLoggingResults()) {
log("%-" + (depth * 4) + "s %s %s %s", "", shortDelta, type, name);
}
if (xmlWriter != null) {
xmlWriter.startElement(type);
xmlWriter.addAttribute("name", name);
xmlWriter.addAttribute("delta", delta);
}
}
use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.
the class AntBuildWriter method writeBuildXml.
/**
* Generate an generic <code>build.xml</code> if not already exist
*
* @throws IOException
* @see #DEFAULT_BUILD_FILENAME
*/
private void writeBuildXml() throws IOException {
File outputFile = new File(project.getBasedir(), DEFAULT_BUILD_FILENAME);
if (outputFile.exists() && !overwrite) {
return;
}
String encoding = "UTF-8";
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", DEFAULT_INDENTATION_SIZE), encoding, null);
// ----------------------------------------------------------------------
// <!-- comments -->
// ----------------------------------------------------------------------
AntBuildWriterUtil.writeAntVersionHeader(writer);
// ----------------------------------------------------------------------
// <project/>
// ----------------------------------------------------------------------
writer.startElement("project");
writer.addAttribute("name", project.getArtifactId());
writer.addAttribute("default", "package");
writer.addAttribute("basedir", ".");
XmlWriterUtil.writeLineBreak(writer);
XmlWriterUtil.writeCommentText(writer, "Import " + DEFAULT_MAVEN_BUILD_FILENAME + " into the current project", 1);
writer.startElement("import");
writer.addAttribute("file", DEFAULT_MAVEN_BUILD_FILENAME);
// import
writer.endElement();
XmlWriterUtil.writeLineBreak(writer, 1, 1);
XmlWriterUtil.writeCommentText(writer, "Help target", 1);
writer.startElement("target");
writer.addAttribute("name", "help");
writer.startElement("echo");
writer.addAttribute("message", "Please run: $ant -projecthelp");
// echo
writer.endElement();
// target
writer.endElement();
XmlWriterUtil.writeLineBreak(writer, 2);
// project
writer.endElement();
XmlWriterUtil.writeLineBreak(writer);
w.close();
}
use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.
the class DoapMojo method doWrite.
private void doWrite(MavenProject project, File outputFile, Writer w) throws MojoExecutionException {
if (asfExtOptions.isIncluded()) {
getLog().info("Generating an ASF DOAP file " + outputFile.getAbsolutePath());
} else {
getLog().info("Generating a pure DOAP file " + outputFile.getAbsolutePath());
}
XMLWriter writer = new PrettyPrintXMLWriter(w, project.getModel().getModelEncoding(), null);
// ----------------------------------------------------------------------------
// Convert POM to DOAP
// ----------------------------------------------------------------------------
DoapUtil.writeHeader(writer);
// Heading
DoapUtil.writeStartElement(writer, "rdf", "RDF");
if (Arrays.binarySearch(Locale.getISOLanguages(), lang) < 0) {
messages.addMessage(new String[] { "doapOptions", "lang" }, lang, UserMessages.INVALID_ISO_DATE);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
writer.addAttribute("xml:lang", lang);
if (StringUtils.isEmpty(doapOptions.getXmlnsNamespaceURI())) {
messages.addMessage(new String[] { "doapOptions", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
writer.addAttribute("xmlns" + (StringUtils.isEmpty(doapOptions.getXmlnsPrefix()) ? "" : ":" + doapOptions.getXmlnsPrefix()), doapOptions.getXmlnsNamespaceURI());
writer.addAttribute("xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
writer.addAttribute("xmlns:foaf", "http://xmlns.com/foaf/0.1/");
if (asfExtOptions.isIncluded()) {
if (StringUtils.isEmpty(asfExtOptions.getXmlnsPrefix())) {
messages.addMessage(new String[] { "doapOptions", "xmlnsPrefix" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
if (StringUtils.isEmpty(asfExtOptions.getXmlnsNamespaceURI())) {
messages.addMessage(new String[] { "doapOptions", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED);
}
writer.addAttribute("xmlns" + (StringUtils.isEmpty(asfExtOptions.getXmlnsPrefix()) ? "" : ":" + asfExtOptions.getXmlnsPrefix()), asfExtOptions.getXmlnsNamespaceURI());
}
if (extOptions != null && extOptions.length > 0 && !extOptions[0].getExtensions().isEmpty()) {
for (ExtOptions extOption : extOptions) {
if (StringUtils.isEmpty(extOption.getXmlnsPrefix())) {
messages.addMessage(new String[] { "extOptions", "extOption", "xmlnsPrefix" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
if (StringUtils.isEmpty(extOption.getXmlnsNamespaceURI())) {
messages.addMessage(new String[] { "extOptions", "extOption", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
writer.addAttribute("xmlns" + (StringUtils.isEmpty(extOption.getXmlnsPrefix()) ? "" : ":" + extOption.getXmlnsPrefix()), extOption.getXmlnsNamespaceURI());
}
}
// Project
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Project");
boolean added = false;
if (artifact != null) {
String about = project.getUrl();
if (StringUtils.isNotEmpty(about)) {
try {
new URL(about);
writer.addAttribute("rdf:about", about);
added = true;
} catch (MalformedURLException e) {
// ignore
}
}
if (!added) {
messages.getWarnMessages().add("The project's url defined from " + artifact.toConfiguration() + " is empty or not a valid URL, using <about/> parameter.");
}
}
if (!added) {
if (StringUtils.isNotEmpty(about)) {
try {
new URL(about);
writer.addAttribute("rdf:about", about);
} catch (MalformedURLException e) {
messages.addMessage(new String[] { "about" }, about, UserMessages.INVALID_URL);
}
added = true;
}
}
if (!added) {
messages.addMessage(new String[] { "about" }, null, UserMessages.RECOMMENDED);
}
// name
writeName(writer, project);
// description
writeDescription(writer, project);
// implements
writeImplements(writer);
// Audience
writeAudience(writer);
// Vendor
writeVendor(writer, project);
// created
writeCreated(writer, project);
// homepage and old-homepage
writeHomepage(writer, project);
// Blog
writeBlog(writer);
// licenses
writeLicenses(writer, project);
// programming-language
writeProgrammingLanguage(writer, project);
// category
writeCategory(writer, project);
// os
writeOS(writer, project);
// Plateform
writePlateform(writer);
// Language
writeLanguage(writer);
// SCM
writeSourceRepositories(writer, project);
// bug-database
writeBugDatabase(writer, project);
// mailing list
writeMailingList(writer, project);
// download-page and download-mirror
writeDownloadPage(writer, project);
// screenshots
writeScreenshots(writer, project);
// service-endpoint
writeServiceEndpoint(writer);
// wiki
writeWiki(writer, project);
// Releases
writeReleases(writer, project);
// Developers
List<Contributor> developers = project.getDevelopers();
writeContributors(writer, developers);
// Contributors
List<Contributor> contributors = project.getContributors();
writeContributors(writer, contributors);
// Extra DOAP
Map<Object, String> map = doapOptions.getExtra();
writeExtra(writer, project, "Extra DOAP vocabulary.", map, doapOptions.getXmlnsPrefix());
// ASFext
writeASFext(writer, project);
// Extra extensions
writeExtensions(writer);
// Project
writer.endElement();
writeOrganizations(writer);
// rdf:RDF
writer.endElement();
}
Aggregations