use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project drools by kiegroup.
the class StaticMethodTestHelper method getProjectVersion.
static String getProjectVersion() {
URL codeLocUrl = StaticMethodTestHelper.class.getProtectionDomain().getCodeSource().getLocation();
String projVersionStr = null;
String codeLocStr = null;
try {
codeLocStr = codeLocUrl.toURI().toString();
if (codeLocStr.endsWith(".jar")) {
Matcher jarLocMatcher = jarLocRegex.matcher(codeLocStr);
assertTrue("Regex for code (jar) location did not match location!", jarLocMatcher.matches() && jarLocMatcher.groupCount() >= 2);
projVersionStr = jarLocMatcher.group(1);
} else {
codeLocStr = codeLocStr.replace("target/classes/", "pom.xml");
File pomFile = new File(new URI(codeLocStr));
assertTrue(codeLocStr + " does not exist!", pomFile.exists());
Reader reader = null;
try {
reader = new FileReader(pomFile);
MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
Model model = xpp3Reader.read(reader);
projVersionStr = model.getVersion();
if (projVersionStr == null) {
projVersionStr = model.getParent().getVersion();
}
String projectName = model.getGroupId() + ":" + model.getArtifactId();
assertNotNull("Unable to resolve project version for " + projectName, projVersionStr);
} catch (FileNotFoundException fnfe) {
throw new RuntimeException("Unable to open " + pomFile.getAbsolutePath(), fnfe);
} catch (IOException ioe) {
throw new RuntimeException("Unable to read " + codeLocStr, ioe);
} catch (XmlPullParserException xppe) {
throw new RuntimeException("Unable to parse " + codeLocStr, xppe);
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
// no-op
}
}
}
} catch (URISyntaxException urise) {
throw new RuntimeException("Invalid URL: " + codeLocStr, urise);
}
return projVersionStr;
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project kie-wb-common by kiegroup.
the class MigrationToolTest method testNewPomStructure.
@Test
public void testNewPomStructure() throws IOException, XmlPullParserException {
final File projectDir = getProjectDir(SPACE_B, PROJECT_B2), pom = new File(projectDir, "pom.xml");
final MavenXpp3Reader reader = new MavenXpp3Reader();
final Model model = reader.read(new FileInputStream(pom));
assertThat(model.getVersion()).isEqualTo("1.2.3");
assertThat(model.getDependencies()).hasSize(6);
assertThat(model.getBuild().getPlugins()).hasSize(1);
assertThat(model.getPackaging()).isEqualTo("kjar");
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project ignite by apache.
the class MavenUtils method mavenProjectRepositories.
/**
* @return Collection of configured repositories for the Maven project.
*/
private static Collection<String> mavenProjectRepositories() throws Exception {
String workDir = System.getProperty("user.dir");
File prjPomFile = new File(workDir, "pom.xml");
if (!prjPomFile.exists())
return Collections.emptyList();
Path outPath = Files.createTempFile("effective-pom", "");
try {
exec(buildMvnCommand() + " -f " + workDir + " help:effective-pom -Doutput=" + outPath.toAbsolutePath());
Model model = new MavenXpp3Reader().read(new FileInputStream(outPath.toFile()));
return F.transform(model.getRepositories(), RepositoryBase::getUrl);
} finally {
Files.deleteIfExists(outPath);
}
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getPluginBundleVersion.
public SPluginBundleVersion getPluginBundleVersion(String version) {
try {
Path pomFile = getVersionPom(version);
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (FileReader fileReader = new FileReader(pomFile.toFile())) {
model = mavenreader.read(fileReader);
}
SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
sPluginBundleVersion.setOrganization(model.getOrganization().getName());
sPluginBundleVersion.setName(model.getName());
sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
sPluginBundleVersion.setGroupId(groupId);
sPluginBundleVersion.setArtifactId(artifactId);
sPluginBundleVersion.setVersion(version);
sPluginBundleVersion.setDescription(model.getDescription());
// sPluginBundleVersion.setRepository(defaultrepository);
sPluginBundleVersion.setMismatch(false);
try {
sPluginBundleVersion.setIcon(getVersionIcon(version));
} catch (ArtifactResolutionException e) {
// Not a problem
}
try {
GregorianCalendar date = getVersionDate(version);
// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
if (date != null) {
sPluginBundleVersion.setDate(date.getTime());
}
} catch (ArtifactResolutionException e) {
// Not a problem
} catch (Exception e) {
LOGGER.error("", e);
}
return sPluginBundleVersion;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
return null;
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getPluginBundle.
public SPluginBundle getPluginBundle(String version) {
try {
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(versionArtifact);
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (FileReader fileReader = new FileReader(pomFile)) {
model = mavenreader.read(fileReader);
}
SPluginBundle sPluginBundle = new SPluginBundle();
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
return sPluginBundle;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
return null;
}
Aggregations