use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project CzechIdMng by bcvsolutions.
the class MavenManager method getModel.
/**
* Resolve maven model from given library. Pom or jar library is supported only.
* Jar library has to contain standard maven pom.xml descriptor.
*
* @param extractedLibrary extracted library (~module) folder
* @return maven model
* @since 10.7.0
*/
public Model getModel(File extractedLibrary) {
Assert.notNull(extractedLibrary, "Library (jar / pom) is required.");
File pomFile = null;
// pom / jar library is supported
if (extractedLibrary.getName().equals(MAVEN_PROJECT_FILE_NAME)) {
pomFile = extractedLibrary;
} else {
File moduleMavenResources = new File(String.format("%s/META-INF/maven", extractedLibrary.getPath()));
if (!moduleMavenResources.exists()) {
LOG.info("Library [{}] cannot be resolved as maven dependency for backend build, " + "required maven descriptor [{}] not found.", extractedLibrary.getName(), MAVEN_PROJECT_FILE_NAME);
return null;
}
//
for (File file : FileUtils.listFiles(moduleMavenResources, null, true)) {
if (file.getName().equals(MAVEN_PROJECT_FILE_NAME)) {
// find the first file, more projects are not supported now
pomFile = file;
break;
}
}
}
// pom file not resolved
if (pomFile == null) {
LOG.info("Library [{}] cannot be resolved as maven dependency for backend build, " + "required maven descriptor [{}] not found.", extractedLibrary.getName(), MAVEN_PROJECT_FILE_NAME);
return null;
}
// read model from pom file
try (InputStream is = new FileInputStream(pomFile)) {
Model model = mavenReader.read(is);
model.setPomFile(pomFile);
return model;
} catch (IOException | XmlPullParserException ex) {
LOG.warn("Library [{}] cannot be resolved as maven dependency for backend build, " + "required maven descriptor [{}] is not readable.", extractedLibrary.getName(), MAVEN_PROJECT_FILE_NAME, ex);
return null;
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project gradle by gradle.
the class ValidatingMavenPublisher method parsePomFileIntoMavenModel.
private Model parsePomFileIntoMavenModel(MavenNormalizedPublication publication) {
File pomFile = publication.getPomArtifact().getFile();
try {
Model model = readModelFromPom(pomFile);
model.setPomFile(pomFile);
return model;
} catch (XmlPullParserException parseException) {
throw new InvalidMavenPublicationException(publication.getName(), "POM file is invalid. Check any modifications you have made to the POM file.", parseException);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project kie-wb-common by kiegroup.
the class PomEditorServiceImpl method checkRepositories.
private void checkRepositories(final Path pomPath, final String pomXml) {
// Check is the POM's GAV has been changed.
final KieModule module = moduleService.resolveModule(pomPath);
POM pom = new POM(GAV_UNDETERMINED);
try {
pom = pomContentHandler.toModel(pomXml);
if (pom.getGav().equals(module.getPom().getGav())) {
return;
}
// If GAV is snapshot we can freely override the module
if (pom.getGav().isSnapshot()) {
return;
}
} catch (final XmlPullParserException e) {
throw new InvalidPomException(e.getLineNumber(), e.getColumnNumber());
} catch (final IOException e) {
logger.warn("Unable to load pom.xml. It is therefore impossible to ascertain GAV.", e);
}
// Check is the POM's GAV resolves to any pre-existing artifacts.
// Filter resolved Repositories by those enabled for the Module.
final ModuleRepositories moduleRepositories = moduleRepositoriesService.load(module.getRepositoriesPath());
final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(pomXml, moduleRepositories.filterByIncluded());
if (repositories.size() > 0) {
throw new GAVAlreadyExistsException(pom.getGav(), repositories);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project intellij-community by JetBrains.
the class MavenEmbedder method buildSettings.
public static Settings buildSettings(PlexusContainer container, MavenEmbedderSettings embedderSettings) {
File file = embedderSettings.getGlobalSettingsFile();
if (file != null) {
System.setProperty(MavenSettingsBuilder.ALT_GLOBAL_SETTINGS_XML_LOCATION, file.getPath());
}
Settings settings = null;
try {
MavenSettingsBuilder builder = (MavenSettingsBuilder) container.lookup(MavenSettingsBuilder.ROLE);
File userSettingsFile = embedderSettings.getUserSettingsFile();
if (userSettingsFile != null && userSettingsFile.exists() && !userSettingsFile.isDirectory()) {
settings = builder.buildSettings(userSettingsFile, false);
}
if (settings == null) {
settings = builder.buildSettings();
}
} catch (ComponentLookupException e) {
MavenEmbedderLog.LOG.error(e);
} catch (IOException e) {
MavenEmbedderLog.LOG.warn(e);
} catch (XmlPullParserException e) {
MavenEmbedderLog.LOG.warn(e);
}
if (settings == null) {
settings = new Settings();
}
if (embedderSettings.getLocalRepository() != null) {
settings.setLocalRepository(embedderSettings.getLocalRepository().getPath());
}
if (settings.getLocalRepository() == null) {
settings.setLocalRepository(System.getProperty("user.home") + "/.m2/repository");
}
settings.setOffline(embedderSettings.isWorkOffline());
settings.setInteractiveMode(false);
settings.setUsePluginRegistry(embedderSettings.isUsePluginRegistry());
RuntimeInfo runtimeInfo = new RuntimeInfo(settings);
runtimeInfo.setPluginUpdateOverride(embedderSettings.getPluginUpdatePolicy() == MavenEmbedderSettings.UpdatePolicy.ALWAYS_UPDATE);
settings.setRuntimeInfo(runtimeInfo);
return settings;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project indy by Commonjava.
the class MavenMetadataMerger method merge.
@Override
public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Generating merged metadata in: {}:{}", group.getKey(), path);
final Metadata master = new Metadata();
master.setVersioning(new Versioning());
final MetadataXpp3Reader reader = new MetadataXpp3Reader();
final FileReader fr = null;
InputStream stream = null;
boolean merged = false;
Transfer snapshotProvider = null;
for (final Transfer src : sources) {
if (!src.exists()) {
continue;
}
try {
stream = src.openInputStream();
String content = IOUtils.toString(stream);
logger.debug("Adding in metadata content from: {}\n\n{}\n\n", src, content);
// there is a lot of junk in here to make up for Metadata's anemic merge() method.
final Metadata md = reader.read(new StringReader(content), false);
if (md.getGroupId() != null) {
master.setGroupId(md.getGroupId());
}
if (md.getArtifactId() != null) {
master.setArtifactId(md.getArtifactId());
}
if (md.getVersion() != null) {
master.setVersion(md.getVersion());
}
master.merge(md);
Versioning versioning = master.getVersioning();
Versioning mdVersioning = md.getVersioning();
// FIXME: Should we try to merge snapshot lists instead of using the first one we encounter??
if (versioning.getSnapshot() == null && mdVersioning != null) {
logger.info("INCLUDING snapshot information from: {} in: {}:{}", src, group.getKey(), path);
snapshotProvider = src;
versioning.setSnapshot(mdVersioning.getSnapshot());
final List<SnapshotVersion> snapshotVersions = versioning.getSnapshotVersions();
boolean added = false;
for (final SnapshotVersion snap : mdVersioning.getSnapshotVersions()) {
if (!snapshotVersions.contains(snap)) {
snapshotVersions.add(snap);
added = true;
}
}
if (added) {
Collections.sort(snapshotVersions, new SnapshotVersionComparator());
}
} else {
logger.warn("SKIPPING snapshot information from: {} in: {}:{} (obscured by: {})", src, group.getKey(), path, snapshotProvider);
}
merged = true;
} catch (final IOException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot read metadata: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} catch (final XmlPullParserException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot parse metadata: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} finally {
closeQuietly(fr);
closeQuietly(stream);
}
}
Versioning versioning = master.getVersioning();
if (versioning != null && versioning.getVersions() != null) {
if (metadataProviders != null) {
for (MavenMetadataProvider provider : metadataProviders) {
try {
Metadata toMerge = provider.getMetadata(group.getKey(), path);
if (toMerge != null) {
merged = master.merge(toMerge) || merged;
}
} catch (IndyWorkflowException e) {
logger.error(String.format("Cannot read metadata: %s from metadata provider: %s. Reason: %s", path, provider.getClass().getSimpleName(), e.getMessage()), e);
}
}
}
List<SingleVersion> versionObjects = versioning.getVersions().stream().map(VersionUtils::createSingleVersion).collect(Collectors.toList());
Collections.sort(versionObjects);
versioning.setVersions(versionObjects.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
if (versionObjects.size() > 0) {
String latest = versionObjects.get(versionObjects.size() - 1).renderStandard();
versioning.setLatest(latest);
versioning.setRelease(latest);
}
}
if (merged) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
new MetadataXpp3Writer().write(baos, master);
return baos.toByteArray();
} catch (final IOException e) {
logger.error(String.format("Cannot write consolidated metadata: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
}
}
return null;
}
Aggregations