o Code from netbeans integration that will write out changes to a model and preserve the existing structure for the most part.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@493817 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-01-07 19:23:21 +00:00
parent d47e7c221c
commit ed381aec0d

View File

@ -22,10 +22,16 @@
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.codehaus.plexus.util.IOUtil;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
import java.nio.channels.FileLock;
//TODO: turn this into a component
@ -75,4 +81,63 @@ public static void write( Writer w,
writer.write( newModel, doc, w, format );
}
/*
public static void writePomModel( FileObject pom,
Model newModel )
throws IOException
{
InputStream inStr = null;
FileLock lock = null;
OutputStreamWriter outStr = null;
try
{
inStr = pom.getInputStream();
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build( inStr );
inStr.close();
inStr = null;
lock = pom.lock();
MavenJDOMWriter writer = new MavenJDOMWriter();
String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8";
outStr = new OutputStreamWriter( pom.getOutputStream( lock ), encoding );
Format form = Format.getRawFormat().setEncoding( encoding );
writer.write( newModel, doc, outStr, form );
outStr.close();
outStr = null;
}
catch ( JDOMException exc )
{
exc.printStackTrace();
throw (IOException) new IOException( "Cannot parse the POM by JDOM." ).initCause( exc );
}
finally
{
IOUtil.close( inStr );
IOUtil.close( outStr );
if ( lock != null )
{
lock.releaseLock();
}
}
}
*/
}