use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project archiva by apache.
the class Maven2RepositoryStorage method applyServerSideRelocation.
@Override
public void applyServerSideRelocation(ManagedRepositoryContent managedRepository, ArtifactReference artifact) throws ProxyDownloadException {
if ("pom".equals(artifact.getType())) {
return;
}
// Build the artifact POM reference
ArtifactReference pomReference = new ArtifactReference();
pomReference.setGroupId(artifact.getGroupId());
pomReference.setArtifactId(artifact.getArtifactId());
pomReference.setVersion(artifact.getVersion());
pomReference.setType("pom");
RepositoryProxyConnectors connectors = applicationContext.getBean("repositoryProxyConnectors#default", RepositoryProxyConnectors.class);
// Get the artifact POM from proxied repositories if needed
connectors.fetchFromProxies(managedRepository, pomReference);
// Open and read the POM from the managed repo
Path pom = managedRepository.toFile(pomReference);
if (!Files.exists(pom)) {
return;
}
try {
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
Model model = null;
try (Reader reader = Files.newBufferedReader(pom, Charset.defaultCharset())) {
model = MAVEN_XPP_3_READER.read(reader);
}
DistributionManagement dist = model.getDistributionManagement();
if (dist != null) {
Relocation relocation = dist.getRelocation();
if (relocation != null) {
// artifact is relocated : update the repositoryPath
if (relocation.getGroupId() != null) {
artifact.setGroupId(relocation.getGroupId());
}
if (relocation.getArtifactId() != null) {
artifact.setArtifactId(relocation.getArtifactId());
}
if (relocation.getVersion() != null) {
artifact.setVersion(relocation.getVersion());
}
}
}
} catch (IOException e) {
// Unable to read POM : ignore.
} catch (XmlPullParserException e) {
// Invalid POM : ignore
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project motech by motech.
the class PomInformation method parsePom.
public void parsePom(InputStream inputStream) {
try {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(inputStream);
if (dependencies == null) {
dependencies = new LinkedList<>();
}
if (repositories == null) {
repositories = new LinkedList<>();
}
parent = model.getParent();
setPropertiesFromModel(this, model);
for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
if (!"test".equalsIgnoreCase(dependency.getScope())) {
dependencies.add(new Dependency(new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), "jar", dependency.getVersion()), JavaScopes.RUNTIME));
}
}
for (Repository remoteRepository : model.getRepositories()) {
repositories.add(new RemoteRepository(remoteRepository.getId(), "default", remoteRepository.getUrl()));
}
} catch (Exception ex) {
LOGGER.error("Error while reading POM file", ex);
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project motech by motech.
the class PomInformation method parseParentPom.
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);
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project JavaFXLibrary by eficode.
the class HelperFunctions method loadRobotLibraryVersion.
public static String loadRobotLibraryVersion() {
try {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));
return model.getVersion();
} catch (Exception e) {
return "unknown";
}
}
use of org.eclipse.ceylon.aether.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;
}
Aggregations