本文整理汇总了Java中org.apache.maven.model.io.xpp3.MavenXpp3Reader类的典型用法代码示例。如果您正苦于以下问题:Java MavenXpp3Reader类的具体用法?Java MavenXpp3Reader怎么用?Java MavenXpp3Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MavenXpp3Reader类属于org.apache.maven.model.io.xpp3包,在下文中一共展示了MavenXpp3Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbstractProjectStub
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
AbstractProjectStub(String pomResourceName) throws IOException, XmlPullParserException {
super(new MavenXpp3Reader().read(ITCompileBundleMojo.class.getResourceAsStream(pomResourceName)));
Model model = getModel();
setGroupId(model.getGroupId());
setArtifactId(model.getArtifactId());
setVersion(model.getVersion());
setName(model.getName());
setUrl(model.getUrl());
setPackaging(model.getPackaging());
SimpleArtifactStub artifact = new SimpleArtifactStub(
model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPackaging());
artifact.setArtifactHandler(new SimpleArtifactHandlerStub(model.getPackaging()));
setArtifact(artifact);
Build build = new Build();
build.setFinalName(model.getArtifactId() + '-' + model.getVersion());
setBuild(build);
for (Dependency dependency: model.getDependencies()) {
if (dependency.getScope() == null) {
dependency.setScope(JavaScopes.COMPILE);
}
}
}
示例2: fromPom
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
public static CarnotzetModuleCoordinates fromPom(@NonNull Path pom) {
Model result;
try {
BufferedReader in = new BufferedReader(Files.newBufferedReader(pom, StandardCharsets.UTF_8));
MavenXpp3Reader reader = new MavenXpp3Reader();
result = reader.read(in);
}
catch (XmlPullParserException | IOException e) {
throw new CarnotzetDefinitionException(e);
}
String groupId = result.getGroupId();
String version = result.getVersion();
if (groupId == null) {
groupId = result.getParent().getGroupId();
}
if (version == null) {
version = result.getParent().getVersion();
}
return new CarnotzetModuleCoordinates(groupId, result.getArtifactId(), version, null);
}
示例3: getAppAssemblerBooterVersion
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
private static String getAppAssemblerBooterVersion()
throws IOException, XmlPullParserException
{
if ( appassemblerVersion == null )
{
MavenXpp3Reader reader = new MavenXpp3Reader();
FileReader fileReader = new FileReader( getTestFile( "pom.xml" ) );
try
{
appassemblerVersion = reader.read( fileReader ).getParent().getVersion();
}
finally
{
IOUtil.close( fileReader );
}
}
return appassemblerVersion;
}
示例4: getModelFromPOM
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
/**
* Load a Maven {@link Model} object from a POM file.
*
* @param pom
* @param logger
* @return the model parsed from the POM file
* @throws XmlPullParserException
* @throws IOException
*/
public static Model getModelFromPOM(File pom, Log logger) throws IOException, XmlPullParserException {
Model model = null;
FileInputStream fis = null;
InputStreamReader isr = null;
try {
fis = new FileInputStream(pom);
isr = new InputStreamReader(fis, "utf-8"); // FIXME
MavenXpp3Reader reader = new MavenXpp3Reader();
model = reader.read(isr);
} finally {
try {
isr.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return model;
}
示例5: mergeModelFromPOM
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
/**
* Merge a Maven {@link Model} object from a POM file to an existing Maven
* {@link Model} object.
*
* @param pom
* @param existingModel
* @param logger
* @return the existing model merged with the parsed model from the POM file
* @throws XmlPullParserException
* @throws IOException
*/
public static Model mergeModelFromPOM(File pom, Model existingModel, Log logger) throws IOException, XmlPullParserException {
if (pom == null || !pom.exists() || existingModel == null || logger == null) return null;
Model model = null;
FileInputStream fis = null;
InputStreamReader isr = null;
try {
fis = new FileInputStream(pom);
isr = new InputStreamReader(fis, "utf-8"); // FIXME
MavenXpp3Reader reader = new MavenXpp3Reader();
model = reader.read(isr);
DefaultInheritanceAssembler assembler = new DefaultInheritanceAssembler();
assembler.assembleModelInheritance(model, existingModel, null, null);
} finally {
try {
isr.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return model;
}
示例6: mavenProjectFor
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
public MavenProject mavenProjectFor(File pom, List<Property> properties) throws Exception {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader(pom));
for (Property p : properties) {
model.addProperty(p.name, p.value);
}
model.setRepositories(new ArrayList<Repository>());
MavenProject project = new MavenProject(model);
project.setPluginArtifactRepositories(new ArrayList<ArtifactRepository>());
project.setFile(pom);
return project;
}
示例7: getMavenPropertyVersionFor
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
public static String getMavenPropertyVersionFor(String key) {
// Maven compile uses a jar, and is in target
String basePath = Paths.get("").toAbsolutePath().toString();
if (basePath.endsWith("target")) {
basePath = basePath.replace("target/", "");
}
String pomfile = basePath + "/../../pom.xml";
Model model = null;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try {
FileReader reader = new FileReader(pomfile);
model = mavenreader.read(reader);
model.setPomFile(new File(pomfile));
} catch (Exception ex) {
throw new IllegalStateException("Can't find the pom.xml file. basePath=" + basePath + " pomFile=" + pomfile);
}
MavenProject project = new MavenProject(model);
Properties properties = project.getProperties();
String value = (String) properties.get(key);
return value;
}
示例8: readProject
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
MavenProject readProject(File pomFile) throws IOException {
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
FileReader fileReader = null;
try {
fileReader = new FileReader(pomFile);
Model model = mavenReader.read(fileReader);
model.setPomFile(pomFile);
MavenProject project = new MavenProject(model);
project.setFile(pomFile);
project.setArtifact(createArtifact(pomFile, model.getGroupId(), model.getArtifactId(), model.getVersion(), "compile", model.getPackaging(), ""));
return project;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (fileReader != null) {
fileReader.close();
}
}
}
示例9: parseParentPom
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
public void parseParentPom(InputStream inputStream) {
try {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(inputStream);
PomInformation parentPom = new PomInformation();
setPropertiesFromModel(parentPom, model);
parentPom.setParent(model.getParent());
this.parentPomInformation = parentPom;
} catch (Exception ex) {
LOGGER.error("Error while reading parent POM file", ex);
}
}
示例10: getRawModel
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
/**
* Gets the current raw model before any interpolation what-so-ever.
*
* @param modifiedPomXMLEventReader The {@link ModifiedPomXMLEventReader} to get the raw model for.
* @return The raw model.
* @throws IOException if the file is not found or if the file does not parse.
*/
public static Model getRawModel( ModifiedPomXMLEventReader modifiedPomXMLEventReader )
throws IOException
{
StringReader stringReader = null;
try
{
stringReader = new StringReader( modifiedPomXMLEventReader.asStringBuilder().toString() );
MavenXpp3Reader reader = new MavenXpp3Reader();
return reader.read( stringReader );
}
catch ( XmlPullParserException e )
{
IOException ioe = new IOException( e.getMessage() );
ioe.initCause( e );
throw ioe;
}
finally
{
if ( stringReader != null )
{
stringReader.close();
}
}
}
示例11: loadProject
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
protected MavenProject loadProject(File pomFile) throws IOException, XmlPullParserException {
MavenProject ret;
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
//Removed null and file exists protections that mask errors
FileReader reader = null;
reader = new FileReader(pomFile);
Model model = mavenReader.read(reader);
model.setPomFile(pomFile);
ret = new MavenProject(model);
if(model.getParent() != null) {
MavenProject parent = new MavenProject();
parent.setGroupId(model.getParent().getGroupId());
parent.setArtifactId(model.getParent().getArtifactId());
parent.setVersion(model.getParent().getVersion());
ret.setParent(parent);
}
reader.close();
return ret;
}
示例12: getProjectVersion
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
/**
*
* @return
*/
private static String getProjectVersion() {
File corePomfile = new File(
ITHelper.class.getClassLoader().getResource("").getPath()
+ "/../../pom.xml");
Model model = null;
FileReader reader;
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
try {
reader = new FileReader(corePomfile);
model = mavenReader.read(reader);
model.setPomFile(corePomfile);
} catch(Exception ex){}
MavenProject project = new MavenProject(model);
return project.getVersion();
}
示例13: getCurrentProjectVersion
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
/**
* Gets current project version from pom.xml file.
*
* @return Current project version.
* @throws MojoFailureException
*/
protected String getCurrentProjectVersion() throws MojoFailureException {
try {
// read pom.xml
final MavenXpp3Reader mavenReader = new MavenXpp3Reader();
final FileReader fileReader = new FileReader(mavenSession
.getCurrentProject().getFile().getAbsoluteFile());
try {
final Model model = mavenReader.read(fileReader);
if (model.getVersion() == null) {
throw new MojoFailureException(
"Cannot get current project version. This plugin should be executed from the parent project.");
}
return model.getVersion();
} finally {
if (fileReader != null) {
fileReader.close();
}
}
} catch (Exception e) {
throw new MojoFailureException("", e);
}
}
示例14: readMavenModel
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
private Model readMavenModel(String baseDir) throws FileNotFoundException, IOException {
Reader reader = null;
try {
Path pomPath = fs.getPath(baseDir, "pom.xml");
if (Files.notExists(pomPath)) {
return null;
}
reader = new FileReader(pomPath.toFile());
MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
return xpp3Reader.read(reader);
} catch (XmlPullParserException e) {
throw new IllegalStateException("Cannot read maven model");
} finally {
if (reader != null) {
reader.close();
}
}
}
示例15: getBuildStringFromPomXml
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入依赖的package包/类
public String getBuildStringFromPomXml() {
Model model = null;
FileReader reader = null;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try {
File pomfile = new File("pom.xml");
reader = new FileReader(pomfile);
model = mavenreader.read(reader);
model.setPomFile(pomfile);
} catch (Exception ex) {
ex.printStackTrace();
}
MavenProject project = new MavenProject(model);
logger.trace("version " + project.getVersion());
return project.getVersion();
}