本文整理汇总了Java中org.codehaus.plexus.util.WriterFactory.newXmlWriter方法的典型用法代码示例。如果您正苦于以下问题:Java WriterFactory.newXmlWriter方法的具体用法?Java WriterFactory.newXmlWriter怎么用?Java WriterFactory.newXmlWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.plexus.util.WriterFactory
的用法示例。
在下文中一共展示了WriterFactory.newXmlWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toXml
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
/**
* Saves the {@link WebappStructure} to the specified file.
*
* @param webappStructure the structure to save
* @param targetFile the file to use to save the structure
* @throws IOException if an error occurred while saving the webapp structure
*/
public void toXml( WebappStructure webappStructure, File targetFile )
throws IOException
{
// CHECKSTYLE_OFF: LineLength
Writer writer = null;
try
{
if ( !targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs() )
{
throw new IOException( "Could not create parent [" + targetFile.getParentFile().getAbsolutePath() + "]" );
}
if ( !targetFile.exists() && !targetFile.createNewFile() )
{
throw new IOException( "Could not create file [" + targetFile.getAbsolutePath() + "]" );
}
writer = WriterFactory.newXmlWriter( targetFile );
XSTREAM.toXML( webappStructure, writer );
}
finally
{
IOUtil.close( writer );
}
// CHECKSTYLE_ON: LineLength
}
示例2: write
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
private void write( File metadataFile, Metadata metadata )
throws RepositoryException
{
Writer writer = null;
try
{
metadataFile.getParentFile().mkdirs();
writer = WriterFactory.newXmlWriter( metadataFile );
new MetadataXpp3Writer().write( writer, metadata );
}
catch ( IOException e )
{
throw new RepositoryException( "Could not write metadata " + metadataFile + ": " + e.getMessage(), e );
}
finally
{
IOUtil.close( writer );
}
}
示例3: generatePomFile
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
/**
* Generates a (temporary) POM file from the plugin configuration. It's the responsibility of the caller to delete
* the generated file when no longer needed.
*
* @return The path to the generated POM file, never <code>null</code>.
* @throws MojoExecutionException If the POM file could not be generated.
*/
private File generatePomFile()
throws MojoExecutionException
{
Model model = generateModel();
Writer writer = null;
try
{
File pomFile = File.createTempFile( "mvninstall", ".pom" );
writer = WriterFactory.newXmlWriter(pomFile);
new MavenXpp3Writer().write( writer, model );
return pomFile;
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error writing temporary POM file: " + e.getMessage(), e );
}
finally
{
IOUtil.close(writer);
}
}
示例4: getTransformedResource
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
byte[] getTransformedResource()
throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 * 4 );
Writer writer = WriterFactory.newXmlWriter( baos );
try
{
Xpp3Dom dom = new Xpp3Dom( "component-set" );
Xpp3Dom componentDom = new Xpp3Dom( "components" );
dom.addChild( componentDom );
for ( Xpp3Dom component : components.values() )
{
componentDom.addChild( component );
}
Xpp3DomWriter.write( writer, dom );
writer.close();
writer = null;
}
finally
{
IOUtil.close( writer );
}
return baos.toByteArray();
}
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:32,代码来源:ComponentsXmlResourceTransformer.java
示例5: getTransformedResource
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
byte[] getTransformedResource()
throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 * 4 );
Writer writer = WriterFactory.newXmlWriter( baos );
try
{
Xpp3Dom dom = new Xpp3Dom( "plugin" );
Xpp3Dom componentDom = new Xpp3Dom( "mojos" );
dom.addChild( componentDom );
for ( Xpp3Dom mojo : mojos )
{
componentDom.addChild( mojo );
}
Xpp3DomWriter.write( writer, dom );
writer.close();
writer = null;
}
finally
{
IOUtil.close( writer );
}
return baos.toByteArray();
}
示例6: doPackaging
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
public void doPackaging(PackagingContext context) throws Exception {
Model model = context.getProject().getOriginalModel();
model.getDependencies().clear();
File f = new File(context.getProject().getBasedir(), "target/pom.xml");
Writer w = WriterFactory.newXmlWriter(f);
PomWriter.write(w, model);
context.getProject().setFile(f);
}
示例7: updateVersion
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
public UpdateResult updateVersion() {
List<File> changedPoms = new ArrayList<File>();
List<String> errors = new ArrayList<String>();
for (ReleasableModule module : reactor.getModulesInBuildOrder()) {
try {
MavenProject project = module.getProject();
if (module.willBeReleased()) {
log.info("Going to release " + module.getArtifactId() + " " + module.getNewVersion());
}
List<String> errorsForCurrentPom = alterModel(project, module.getNewVersion());
errors.addAll(errorsForCurrentPom);
File pom = project.getFile().getCanonicalFile();
changedPoms.add(pom);
Writer fileWriter = WriterFactory.newXmlWriter(pom);
Model originalModel = project.getOriginalModel();
try {
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
pomWriter.write(fileWriter, originalModel);
} finally {
fileWriter.close();
}
} catch (Exception e) {
return new UpdateResult(changedPoms, errors, e);
}
}
return new UpdateResult(changedPoms, errors, null);
}
示例8: writeFile
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
/**
* Writes a StringBuilder into a file.
*
* @param outFile The file to read.
* @param input The contents of the file.
* @throws IOException when things go wrong.
*/
protected final void writeFile( File outFile, StringBuilder input )
throws IOException
{
Writer writer = WriterFactory.newXmlWriter( outFile );
try
{
IOUtil.copy( input.toString(), writer );
}
finally
{
IOUtil.close( writer );
}
}
示例9: getTransformedResource
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
byte[] getTransformedResource()
throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 * 4 );
Writer writer = WriterFactory.newXmlWriter( baos );
try
{
Xpp3Dom dom = new Xpp3Dom( "component-set" );
Xpp3Dom componentDom = new Xpp3Dom( "components" );
dom.addChild( componentDom );
for ( Xpp3Dom component : components.values() )
{
componentDom.addChild( component );
}
Xpp3DomWriter.write( writer, dom );
}
finally
{
IOUtil.close( writer );
}
return baos.toByteArray();
}
示例10: getTransformedResource
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
byte[] getTransformedResource()
throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream( 1024 * 4 );
Writer writer = WriterFactory.newXmlWriter( baos );
try
{
Xpp3Dom dom = new Xpp3Dom( "plugin" );
Xpp3Dom componentDom = new Xpp3Dom( "mojos" );
dom.addChild( componentDom );
for ( Xpp3Dom mojo : mojos )
{
componentDom.addChild( mojo );
}
Xpp3DomWriter.write( writer, dom );
}
finally
{
IOUtil.close( writer );
}
return baos.toByteArray();
}
示例11: writeFile
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
/**
* Writes a StringBuilder into a file.
*
* @param outFile The file to read.
* @param input The contents of the file.
* @throws IOException when things go wrong.
*/
protected final void writeFile( File outFile, StringBuilder input )
throws IOException
{
Writer writer = WriterFactory.newXmlWriter( outFile );
try
{
IOUtil.copy( input.toString(), writer );
}
finally
{
IOUtil.close( writer );
}
}
开发者ID:petr-ujezdsky,项目名称:versions-maven-plugin-svn-clone,代码行数:21,代码来源:AbstractVersionsUpdaterMojo.java
示例12: initializeWriter
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
protected Writer initializeWriter(final File destinationFile) throws
MojoExecutionException {
try {
return WriterFactory.newXmlWriter(destinationFile);
} catch (IOException e) {
throw new MojoExecutionException("Exception while opening file[" +
destinationFile.getAbsolutePath() + "]", e);
}
}
示例13: writeWorkFlow
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
/**
* Generates an Oozie workflow to execute the job in the given schedule.
*
* @param schedule the schedule to write
* @param context the application's context
* @param output an output stream to which the workflow is written
*/
public static void writeWorkFlow(Schedule schedule,
AppContext context,
OutputStream output) throws IOException {
XmlStreamWriter streamWriter = WriterFactory.newXmlWriter(output);
PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(streamWriter);
writer.startElement(WORKFLOW_ELEMENT);
writer.addAttribute("name", schedule.getName());
writer.addAttribute("xmlns", OOZIE_WORKFLOW_NS);
element(writer, "start", "to", schedule.getName());
writer.startElement("action");
writer.addAttribute("name", schedule.getName());
// Reduce retry attempts. TODO: make this configurable?
writer.addAttribute("retry-max", "2");
writer.addAttribute("retry-interval", "1");
// Write the appropriate action to be used in the job.
SchedulableJobManager manager = JobManagers.createSchedulable(schedule, context);
manager.writeOozieActionBlock(writer, schedule);
element(writer, "ok", "to", "end");
element(writer, "error", "to", "kill");
writer.endElement(); // action
writer.startElement("kill");
writer.addAttribute("name", "kill");
element(writer, "message", "Error in workflow for " + schedule.getName());
writer.endElement(); // kill
element(writer, "end", "name", "end");
writer.endElement(); // workflow
streamWriter.flush();
}
示例14: writeBundle
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
public static void writeBundle(Class appClass,
AppContext context,
Path appPath,
List<Schedule> schedules,
OutputStream output) throws IOException {
Configuration conf = context.getHadoopConf();
XmlStreamWriter streamWriter = WriterFactory.newXmlWriter(output);
PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(streamWriter);
writer.startElement(BUNDLE_ELEMENT);
writer.addAttribute("name", appClass.getCanonicalName());
writer.addAttribute("xmlns", OOZIE_BUNDLE_NS);
writer.startElement("parameters");
// Default to the HDFS scheme for the root path if none is provided.
Path qualifiedPath = appPath.toUri().getScheme() == null ?
appPath.makeQualified(URI.create("hdfs:/"), appPath) :
appPath;
property(writer, "kiteAppRoot", qualifiedPath.toString());
property(writer, "oozie.libpath", "${kiteAppRoot}/lib");
property(writer, "nameNode", conf.get("fs.default.name"));
String resourceManager = conf.get("yarn.resourcemanager.address");
// MR2 uses YARN for the job tracker, but some Hadoop deployments
// don't have the resoure manager setting visible. We work around this
// by grabbing the job tracker setting and swapping to the resource
// manager port.
// TODO: is there a better way to deal with this?
if (resourceManager == null) {
String jobTracker = conf.get("mapred.job.tracker");
if (jobTracker != null)
resourceManager = jobTracker.replace("8021", "8032");
}
if (resourceManager != null)
property(writer, "jobTracker", resourceManager);
// TODO: handle application configuration.
// if (appConfigPath != null)
// property(writer, "appConfigPath", appConfigPath.toString());
writer.endElement(); // parameters
int i = 0;
for (Schedule schedule: schedules) {
writer.startElement("coordinator");
writer.addAttribute("name", schedule.getName());
element(writer, "app-path", "${kiteAppRoot}/" + coordPath(schedule));
writer.endElement(); // coordinator
}
writer.endElement(); // bundle
streamWriter.flush();
}
示例15: fixTimestamp
import org.codehaus.plexus.util.WriterFactory; //导入方法依赖的package包/类
/**
* Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local metadata if necessary to allow
* proper merging/updating of metadata during deployment.
*/
private void fixTimestamp( File metadataFile, Metadata metadata, Metadata reference )
{
boolean changed = false;
if ( metadata != null && reference != null )
{
Versioning versioning = metadata.getVersioning();
Versioning versioningRef = reference.getVersioning();
if ( versioning != null && versioningRef != null )
{
String lastUpdated = versioning.getLastUpdated();
String now = versioningRef.getLastUpdated();
if ( lastUpdated != null && now != null && now.compareTo( lastUpdated ) < 0 )
{
getLogger().warn(
"The last updated timestamp in " + metadataFile + " refers to the future (now = "
+ now + ", lastUpdated = " + lastUpdated
+ "). Please verify that the clocks of all"
+ " deploying machines are reasonably synchronized." );
versioning.setLastUpdated( now );
changed = true;
}
}
}
if ( changed )
{
getLogger().debug( "Repairing metadata in " + metadataFile );
Writer writer = null;
try
{
writer = WriterFactory.newXmlWriter( metadataFile );
new MetadataXpp3Writer().write( writer, metadata );
}
catch ( IOException e )
{
String msg = "Could not write fixed metadata to " + metadataFile + ": " + e.getMessage();
if ( getLogger().isDebugEnabled() )
{
getLogger().warn( msg, e );
}
else
{
getLogger().warn( msg );
}
}
finally
{
IOUtil.close( writer );
}
}
}