本文整理匯總了Java中org.apache.maven.model.io.xpp3.MavenXpp3Writer.write方法的典型用法代碼示例。如果您正苦於以下問題:Java MavenXpp3Writer.write方法的具體用法?Java MavenXpp3Writer.write怎麽用?Java MavenXpp3Writer.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.maven.model.io.xpp3.MavenXpp3Writer
的用法示例。
在下文中一共展示了MavenXpp3Writer.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createPom
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
private File createPom( File targetPath, String filename, FileMetadata fileMetadata, String groupId,
String artifactId, String version, String packaging )
throws IOException
{
Model projectModel = new Model();
projectModel.setModelVersion( "4.0.0" );
projectModel.setGroupId( groupId );
projectModel.setArtifactId( artifactId );
projectModel.setVersion( version );
projectModel.setPackaging( packaging );
File pomFile = new File( targetPath, filename );
MavenXpp3Writer writer = new MavenXpp3Writer();
try (FileWriter w = new FileWriter( pomFile ))
{
writer.write( w, projectModel );
}
return pomFile;
}
示例2: write
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
public String write(Manifest manifest, ArtifactDescriptor artifact) {
MavenXpp3Writer writer = new MavenXpp3Writer();
Model model = new Model();
addProjectInformation(manifest, artifact, model);
addRequiresDependency(manifest, model);
addArchiveDependencies(manifest, model);
addBinaryDependencies(manifest, model);
addRepositories(manifest, model);
StringWriter sw = new StringWriter();
try {
writer.write(sw, model);
}
catch (IOException e) {
}
return sw.toString();
}
示例3: generatePOM
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
private static void generatePOM(Path pomFile, String groupId, String artifactId, List<String> dependencies)
throws IOException {
Model pom = new Model();
pom.setModelVersion(MODEL_VERSION);
pom.setGroupId(groupId);
pom.setArtifactId(artifactId);
pom.setVersion(VERSION.toString());
pom.setPackaging("jar");
pom.setName(artifactId + ": fabricated POM for testing");
for (String dependency: dependencies) {
pom.addDependency(createMavenDependency(dependency, TYPE));
pom.addDependency(createMavenDependency(dependency, "jar"));
}
MavenXpp3Writer writer = new MavenXpp3Writer();
try (OutputStream outputStream = Files.newOutputStream(pomFile)) {
writer.write(outputStream, pom);
}
}
示例4: writeEffectivePom
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
/**
* org.apache.maven.plugins.help.EffectivePomMojo#writeEffectivePom
*/
private static void writeEffectivePom(MavenProject project, XMLWriter writer)
throws MojoExecutionException {
Model pom = project.getModel();
cleanModel(pom);
String effectivePom;
StringWriter sWriter = new StringWriter();
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
try {
pomWriter.write(sWriter, pom);
}
catch (IOException e) {
throw new MojoExecutionException("Cannot serialize POM to XML.", e);
}
effectivePom = addMavenNamespace(sWriter.toString(), true);
writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
writer.writeMarkup(effectivePom);
}
示例5: testReadModel
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
@Test
public void testReadModel() throws IOException {
// PREPARE
final String expected = IOUtils.toString(getClass()
.getResourceAsStream("/objects4j.xml"), Charset.forName("ISO-8859-1"));
// TEST
final Model model = MavenPomReader
.readModel("org.fuin:objects4j:0.6.1");
// VERIFY
final MavenXpp3Writer writer = new MavenXpp3Writer();
final StringWriter sw = new StringWriter();
writer.write(sw, model);
assertThat(sw.toString()).isEqualTo(expected);
assertThat(model.getName()).isEqualTo("Objects4J");
assertThat(model.getScm()).isNotNull();
assertThat(model.getScm().getUrl()).isEqualTo("https://github.com/fuinorg/objects4j/");
}
示例6: writeEffectivePom
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
/**
* method from org.apache.maven.plugins.help.EffectivePomMojo Method for writing the effective pom
* informations of the current build.
*
* @param project the project of the current build, not null.
* @param writer the XML writer , not null, not null.
* @throws MojoExecutionException if any
*/
private static void writeEffectivePom(MavenProject project, XMLWriter writer)
throws MojoExecutionException {
Model pom = project.getModel();
cleanModel(pom);
String effectivePom;
StringWriter sWriter = new StringWriter();
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
try {
pomWriter.write(sWriter, pom);
} catch (IOException e) {
throw new MojoExecutionException("Cannot serialize POM to XML.", e);
}
effectivePom = addMavenNamespace(sWriter.toString(), true);
writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
writer.writeMarkup(effectivePom);
}
示例7: createPom
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
private Path createPom( Path targetPath, String filename, FileMetadata fileMetadata, String groupId,
String artifactId, String version, String packaging )
throws IOException
{
Model projectModel = new Model();
projectModel.setModelVersion( "4.0.0" );
projectModel.setGroupId( groupId );
projectModel.setArtifactId( artifactId );
projectModel.setVersion( version );
projectModel.setPackaging( packaging );
Path pomFile = targetPath.resolve( filename );
MavenXpp3Writer writer = new MavenXpp3Writer();
try (FileWriter w = new FileWriter( pomFile.toFile() ))
{
writer.write( w, projectModel );
}
return pomFile;
}
示例8: generate
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
@Override
public void generate() {
logger.info("Creating the pom file {}", POM_FILE);
File pom = new File(baseDir, POM_FILE);
OutputStreamWriter fileWriter = null;
try {
fileWriter = new OutputStreamWriter(new FileOutputStream(pom), Charsets.UTF_8);
logger.debug("Writing the generated pom file {}", POM_FILE);
MavenXpp3Writer writer = new MavenXpp3Writer();
writer.write(fileWriter, model);
} catch (Exception e) {
throw new MinnalGeneratorException("Failed while writing the pom - " + pom.getName(), e);
} finally {
closeStream(fileWriter);
}
}
示例9: write
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
public void write( Writer output, Map<String, Object> options, Model model )
throws IOException
{
if ( output == null )
{
throw new IllegalArgumentException( "output writer missing" );
}
if ( model == null )
{
throw new IllegalArgumentException( "model missing" );
}
try
{
MavenXpp3Writer w = new MavenXpp3Writer();
w.write( output, model );
}
finally
{
IOUtil.close( output );
}
}
示例10: writeRelocationPom
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId,
String newArtifactId, String newVersion, String message,
ArtifactRepository repository, FileTransaction transaction )
throws IOException
{
Model pom = new Model();
pom.setGroupId( groupId );
pom.setArtifactId( artifactId );
pom.setVersion( version );
DistributionManagement dMngt = new DistributionManagement();
Relocation relocation = new Relocation();
relocation.setGroupId( newGroupId );
relocation.setArtifactId( newArtifactId );
relocation.setVersion( newVersion );
if ( message != null && message.length() > 0 )
{
relocation.setMessage( message );
}
dMngt.setRelocation( relocation );
pom.setDistributionManagement( dMngt );
Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); //$NON-NLS-1$
File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) );
StringWriter strWriter = new StringWriter();
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
pomWriter.write( strWriter, pom );
transaction.createFile( strWriter.toString(), pomFile, digesters );
}
示例11: updateVersion
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的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);
}
示例12: write
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
private void write(Project project, Model model) throws AddDependencyException {
try {
MavenXpp3Writer writer = new MavenXpp3Writer();
writer.write(new FileWriter(project.getPath().resolve("pom.xml").toFile()), model);
} catch(IOException e) {
throw new AddDependencyException("Failed to write pom.xml", e);
}
}
示例13: asXML
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
public String asXML(final Log log, final boolean removeDuplicatedSiblings) throws Exception {
final MavenXpp3Writer mavenWritter = new MavenXpp3Writer();
final StringWriter buffer = new StringWriter(16384);
mavenWritter.write(buffer, this.model);
String result = buffer.toString();
if (removeDuplicatedSiblings) {
if (log != null) {
log.warn("Activated search and removing of duplicated sibling elements!");
}
result = findAndRemoveDuplicatedSiblings(log, result);
} else if (log != null) {
log.info("Search and removing of duplicated sibling elements is OFF");
}
return result;
}
示例14: mavenModelToString
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
public static String mavenModelToString(Model model) {
MavenXpp3Writer writer = new MavenXpp3Writer();
StringWriter stringWriter = new StringWriter();
try {
writer.write(stringWriter, model);
} catch (IOException e) {
throw new RepositoryRuntimeException("Failed to convert maven model to string", e);
}
return stringWriter.toString();
}
示例15: saveMavenProject
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; //導入方法依賴的package包/類
public static void saveMavenProject(MavenProject project, File file) throws IOException {
if (file.getParentFile()!=null){
file.getParentFile().mkdirs();
}
MavenXpp3Writer mavenXpp3writer = new MavenXpp3Writer();
FileWriter fileWriter = new FileWriter(file);
mavenXpp3writer.write(fileWriter, project.getModel());
fileWriter.close();
}