本文整理汇总了Java中org.apache.maven.model.io.xpp3.MavenXpp3Reader.read方法的典型用法代码示例。如果您正苦于以下问题:Java MavenXpp3Reader.read方法的具体用法?Java MavenXpp3Reader.read怎么用?Java MavenXpp3Reader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.model.io.xpp3.MavenXpp3Reader
的用法示例。
在下文中一共展示了MavenXpp3Reader.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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;
}
示例6: 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();
}
}
}
示例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: 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;
}
示例10: 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();
}
示例11: 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();
}
}
}
示例12: 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();
}
示例13: resolveDependenciesFromMultimodulePrj
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入方法依赖的package包/类
public static List<Artifact> resolveDependenciesFromMultimodulePrj(List<String> pomsPaths) {
MavenXpp3Reader reader = new MavenXpp3Reader();
List<Artifact> deps = new ArrayList<>();
try {
for (String pomx : pomsPaths) {
Path pom = Paths.get(pomx);
Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom)));
if (model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null) {
createArtifacts(model.getDependencyManagement().getDependencies(),
deps);
}
if (model.getDependencies() != null) {
createArtifacts(model.getDependencies(),
deps);
}
}
} catch (Exception ex) {
logger.error(ex.getMessage());
return Collections.emptyList();
}
return deps;
}
示例14: getParent
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入方法依赖的package包/类
private Parent getParent(IDocument doc) {
Model model = null;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
InputStream in = null;
try {
in = IOUtils.toInputStream(doc.get(), "UTF-8");
model = mavenreader.read(in);
return model.getParent();
} catch (Exception ex) {
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
return null;
}
示例15: getModel
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; //导入方法依赖的package包/类
public Model getModel(File artifactFile) throws IOException {
Model model = null;
FileReader reader = null;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try {
reader = new FileReader(artifactFile);
model = mavenreader.read(reader);
} catch (Exception ex) {
} finally {
if (reader != null) {
reader.close();
}
}
return model;
}