use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ModelIO method getRemotePluginVersionOverrides.
private Set<Plugin> getRemotePluginVersionOverrides(final PluginType type, final ProjectVersionRef ref, final Properties userProperties) throws ManipulationException {
logger.debug("Resolving remote {} POM: {}", type, ref);
final Set<Plugin> pluginOverrides = new HashSet<>();
final Map<ProjectRef, ProjectVersionRef> pluginOverridesPomView = new HashMap<>();
final Model m = resolveRawModel(ref);
try {
final MavenPomView pomView = galleyWrapper.readPomView(ref);
final List<PluginView> deps;
if (type == PluginType.PluginMgmt) {
deps = pomView.getAllManagedBuildPlugins();
} else {
deps = pomView.getAllBuildPlugins();
}
for (final PluginView p : deps) {
pluginOverridesPomView.put(p.asProjectRef(), p.asProjectVersionRef());
}
} catch (GalleyMavenException e) {
throw new ManipulationException("Unable to resolve: %s", e, ref);
}
logger.debug("Found pluginOverridesResolvedVersions {} ", pluginOverridesPomView);
// set of plugins with versions to handle those.
for (Map.Entry<ProjectRef, ProjectVersionRef> entry : pluginOverridesPomView.entrySet()) {
Plugin p = new Plugin();
p.setArtifactId(entry.getKey().getArtifactId());
p.setGroupId(entry.getKey().getGroupId());
p.setVersion(entry.getValue().getVersionString());
pluginOverrides.add(p);
}
// TODO: active profiles!
if (m.getBuild() != null && m.getBuild().getPluginManagement() != null) {
Iterator<Plugin> plit = null;
if (type == PluginType.PluginMgmt && m.getBuild().getPluginManagement() != null) {
logger.debug("Returning override of " + m.getBuild().getPluginManagement().getPlugins());
plit = m.getBuild().getPluginManagement().getPlugins().iterator();
} else if (type == PluginType.Plugins && m.getBuild().getPlugins() != null) {
logger.debug("Returning override of " + m.getBuild().getPlugins());
plit = m.getBuild().getPlugins().iterator();
}
while (plit != null && plit.hasNext()) {
Plugin p = plit.next();
ProjectRef pr = new SimpleProjectRef(p.getGroupId(), p.getArtifactId());
if ((isNotEmpty(p.getVersion()) && p.getVersion().startsWith("${")) || isEmpty(p.getVersion())) {
// Property reference to something in the remote pom. Resolve and inline it now.
String newVersion = resolveProperty(userProperties, m.getProperties(), p.getVersion());
// TODO: Complete replacement with PomView
if (newVersion.startsWith("${") || newVersion.length() == 0) {
// Use PomView as that contains a pre-resolved list of plugins.
newVersion = pluginOverridesPomView.get(pr).getVersionString();
}
logger.debug("Replacing plugin override version " + p.getVersion() + " with " + newVersion);
p.setVersion(newVersion);
}
// Replacing the element with the fully parsed element from the Model.
pluginOverrides.remove(p);
pluginOverrides.add(p);
// resolve any properties.
if (p.getConfiguration() != null) {
processChildren(userProperties, m, (Xpp3Dom) p.getConfiguration());
}
if (p.getExecutions() != null) {
List<PluginExecution> exes = p.getExecutions();
for (PluginExecution pe : exes) {
if (pe.getConfiguration() != null) {
processChildren(userProperties, m, (Xpp3Dom) pe.getConfiguration());
}
}
}
if (p.getDependencies() != null) {
for (Dependency d : p.getDependencies()) {
if (!isEmpty(d.getVersion()) && d.getVersion().startsWith("${")) {
logger.debug("Processing dependency {} and updating with {} ", d, resolveProperty(userProperties, m.getProperties(), d.getVersion()));
d.setVersion(resolveProperty(userProperties, m.getProperties(), d.getVersion()));
}
}
}
logger.debug("Added plugin override for {} with configuration \n" + p.getConfiguration() + " and executions " + p.getExecutions() + " and dependencies " + p.getDependencies(), p.getId());
}
} else {
throw new ManipulationException("Attempting to align to a BOM that does not have a " + type.toString() + " section");
}
return pluginOverrides;
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ModelIO method getRemoteDependencyVersionOverrides.
public Map<ArtifactRef, String> getRemoteDependencyVersionOverrides(final ProjectVersionRef ref) throws ManipulationException {
logger.debug("Resolving dependency management GAV: " + ref);
final Map<ArtifactRef, String> versionOverrides = new LinkedHashMap<>();
try {
final MavenPomView pomView = galleyWrapper.readPomView(ref);
// TODO: active profiles!
final List<DependencyView> deps = pomView.getAllManagedDependencies();
if (deps == null || deps.isEmpty()) {
logger.warn("Attempting to align to a BOM that does not have a dependencyManagement section");
} else {
for (final DependencyView dep : deps) {
versionOverrides.put(dep.asArtifactRef(), dep.getVersion());
logger.debug("Added version override for: " + dep.asProjectRef().toString() + ":" + dep.getVersion());
}
}
} catch (final GalleyMavenException e) {
throw new ManipulationException("Unable to resolve: %s", e, ref);
}
return versionOverrides;
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class SettingsIO method update.
public void update(Settings settings, File settingsFile) throws ManipulationException {
try {
Settings defaultSettings = new Settings();
if (settingsFile.exists()) {
DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
settingsRequest.setGlobalSettingsFile(settingsFile);
defaultSettings = settingsBuilder.build(settingsRequest).getEffectiveSettings();
}
for (Profile profile : settings.getProfiles()) {
Iterator<Profile> i = defaultSettings.getProfiles().iterator();
while (i.hasNext()) {
if (i.next().getId().equals(profile.getId())) {
i.remove();
}
}
defaultSettings.addProfile(profile);
}
for (String activeProfile : settings.getActiveProfiles()) {
Iterator<String> i = defaultSettings.getActiveProfiles().iterator();
while (i.hasNext()) {
if (i.next().equals(activeProfile)) {
i.remove();
}
}
defaultSettings.addActiveProfile(activeProfile);
}
for (Mirror mirror : settings.getMirrors()) {
defaultSettings.addMirror(mirror);
}
for (Proxy proxy : settings.getProxies()) {
defaultSettings.addProxy(proxy);
}
for (Server server : settings.getServers()) {
defaultSettings.addServer(server);
}
for (String pluginGroup : settings.getPluginGroups()) {
defaultSettings.addPluginGroup(pluginGroup);
}
if (settings.getLocalRepository() != null) {
defaultSettings.setLocalRepository(settings.getLocalRepository());
}
write(defaultSettings, settingsFile);
} catch (SettingsBuildingException e) {
throw new ManipulationException("Failed to build existing settings.xml for repo removal backup.", e, settingsFile, e.getMessage());
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class GalleyInfrastructure method init.
private void init(final File targetDirectory, final List<ArtifactRepository> remoteRepositories, final ArtifactRepository localRepository, final Settings settings, final List<String> activeProfiles, final Location customLocation, final Transport customTransport, File cacheDir_) throws ManipulationException {
LocationExpander locationExpander;
try {
final List<Location> custom = customLocation == null ? Collections.<Location>emptyList() : Collections.singletonList(customLocation);
locationExpander = new MavenLocationExpander(custom, remoteRepositories, localRepository, mirrorSelector, settings, activeProfiles);
} catch (final MalformedURLException e) {
throw new ManipulationException("Failed to setup Maven-specific LocationExpander: %s", e, e.getMessage());
}
xml = new XMLInfrastructure();
xpaths = new XPathManager();
final TransportManager transports;
if (customTransport != null) {
transports = new TransportManagerImpl(customTransport);
} else {
transports = new TransportManagerImpl(new HttpClientTransport(new HttpImpl(new MemoryPasswordManager())), new FileTransport(), new ZipJarTransport());
}
cacheDir = cacheDir_;
if (cacheDir == null) {
cacheDir = new File(targetDirectory, "manipulator-cache");
}
final FileEventManager fileEvents = new NoOpFileEventManager();
final CacheProvider cache = new FileCacheProvider(cacheDir, new HashedLocationPathGenerator(), fileEvents, new NoOpTransferDecorator());
final NotFoundCache nfc = new MemoryNotFoundCache();
executor = Executors.newCachedThreadPool();
final TransportManagerConfig config = new TransportManagerConfig();
final TransferManager transfers = new TransferManagerImpl(transports, cache, nfc, fileEvents, new DownloadHandler(nfc, config, executor), new UploadHandler(nfc, config, executor), new ListingHandler(nfc), new ExistenceHandler(nfc), new SpecialPathManagerImpl(), executor);
final TypeMapper types = new StandardTypeMapper();
final ArtifactMetadataManager metadataManager = new ArtifactMetadataManagerImpl(transfers, locationExpander);
final VersionResolver versionResolver = new VersionResolverImpl(new MavenMetadataReader(xml, locationExpander, metadataManager, xpaths));
artifactManager = new ArtifactManagerImpl(transfers, locationExpander, types, versionResolver);
// TODO: auto-adjust this to the current Maven runtime!
final MavenPluginDefaults pluginDefaults = new StandardMaven304PluginDefaults();
final MavenPluginImplications pluginImplications = new StandardMavenPluginImplications(xml);
pomReader = new MavenPomReader(xml, locationExpander, artifactManager, xpaths, pluginDefaults, pluginImplications);
metadataReader = new MavenMetadataReader(xml, locationExpander, metadataManager, xpaths);
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class PomIO method write.
private void write(final Project project, final File pom, final Model model) throws ManipulationException {
try {
final String manifestInformation = project.isInheritanceRoot() ? ManifestUtils.getManifestInformation() : null;
MavenJDOMWriter mjw = new MavenJDOMWriter(model);
// We possibly could store the EOL type in the Project when we first read
// the file but we would then have to do a dual read, then write as opposed
// to a read, then read + write now.
LineSeparator ls = determineEOL(pom);
mjw.setLineSeparator(ls);
mjw.write(model, pom, new DocumentModifier() {
@Override
public void postProcess(final Document doc) {
// Only add the modified by to the top level pom.
if (project.isExecutionRoot()) {
final Iterator<Content> it = doc.getContent(new ContentFilter(ContentFilter.COMMENT)).iterator();
while (it.hasNext()) {
final Comment c = (Comment) it.next();
if (c.toString().contains(MODIFIED_BY)) {
it.remove();
}
}
doc.addContent(Collections.<Content>singletonList(new Comment("\nModified by POM Manipulation Extension for Maven " + manifestInformation + "\n")));
}
}
});
} catch (final IOException e) {
throw new ManipulationException("Failed to read POM for rewrite: %s. Reason: %s", e, pom, e.getMessage());
} catch (final JDOMException e) {
throw new ManipulationException("Failed to parse POM for rewrite: %s. Reason: %s", e, pom, e.getMessage());
}
}
Aggregations