use of org.apache.maven.settings.building.SettingsBuildingException in project gradle by gradle.
the class DefaultLocalMavenRepositoryLocator method getLocalMavenRepository.
@Override
public File getLocalMavenRepository() throws CannotLocateLocalMavenRepositoryException {
String localOverride = system.getProperty("maven.repo.local");
if (localOverride != null) {
return new File(localOverride);
}
try {
String repoPath = parseLocalRepoPathFromMavenSettings();
if (repoPath != null) {
File file = new File(resolvePlaceholders(repoPath.trim()));
if (isDriveRelativeWindowsPath(file)) {
return file.getAbsoluteFile();
} else {
return file;
}
} else {
File defaultLocation = new File(mavenFileLocations.getUserMavenDir(), "repository").getAbsoluteFile();
LOGGER.debug("No local repository in Settings file defined. Using default path: {}", defaultLocation);
return defaultLocation;
}
} catch (SettingsBuildingException e) {
throw new CannotLocateLocalMavenRepositoryException("Unable to parse local Maven settings.", e);
}
}
use of org.apache.maven.settings.building.SettingsBuildingException in project acceptance-test-harness by jenkinsci.
the class ArtifactResolverUtil method resolve.
/**
* @param artifact The artifact to be resolved
*
* @return artifact resolution result
*/
public ArtifactResult resolve(DefaultArtifact artifact) {
Builder repoBuilder = new RemoteRepository.Builder("repo.jenkins-ci.org", "default", "https://repo.jenkins-ci.org/public/");
DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
File userHome = new File(System.getProperty("user.home"));
File userSettingsFile = new File(new File(userHome, ".m2"), "settings.xml");
request.setUserSettingsFile(userSettingsFile);
if (userSettingsFile.exists()) {
LOGGER.config("Found maven settings file - " + userSettingsFile.getAbsolutePath());
SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
try {
Settings settings = settingsBuilder.build(request).getEffectiveSettings();
org.apache.maven.settings.Proxy mavenActiveproxy = settings.getActiveProxy();
if (mavenActiveproxy != null) {
LOGGER.config("Found maven proxy settings. Will use for artifact resolution");
repoBuilder.setProxy(asProxy(mavenActiveproxy));
} else {
LOGGER.config("Did not find an active proxy in maven settings xml file");
}
} catch (SettingsBuildingException e) {
LOGGER.log(Level.WARNING, "Could not find or load settings.xml to attempt to user proxy settings.", e);
}
}
RemoteRepository repo = repoBuilder.build();
ArtifactResult r;
try {
r = repoSystem.resolveArtifact(repoSystemSession, new ArtifactRequest(artifact, Arrays.asList(repo), null));
} catch (ArtifactResolutionException e) {
throw new RuntimeException("Could not resolve " + artifact + " from Maven repository", e);
}
LOGGER.config("Found " + r);
return r;
}
use of org.apache.maven.settings.building.SettingsBuildingException in project sts4 by spring-projects.
the class MavenBridge method getSettings.
public synchronized Settings getSettings(final boolean force_reload) throws MavenException {
// MUST NOT use createRequest!
File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE;
if (mavenConfiguration.getUserSettingsFile() != null) {
userSettingsFile = new File(mavenConfiguration.getUserSettingsFile());
}
boolean reload = force_reload || settings == null;
if (!reload && userSettingsFile != null) {
reload = userSettingsFile.lastModified() != settings_timestamp || userSettingsFile.length() != settings_length;
}
if (reload) {
// TODO: Can't that delegate to buildSettings()?
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
// 440696 guard against ConcurrentModificationException
Properties systemProperties = new Properties();
copyProperties(systemProperties, System.getProperties());
request.setSystemProperties(systemProperties);
if (mavenConfiguration.getGlobalSettingsFile() != null) {
request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
}
if (userSettingsFile != null) {
request.setUserSettingsFile(userSettingsFile);
}
try {
settings = lookup(SettingsBuilder.class).build(request).getEffectiveSettings();
} catch (SettingsBuildingException ex) {
String msg = "Could not read settings.xml, assuming default values";
log.error(msg, ex);
/*
* NOTE: This method provides input for various other core
* functions, just bailing out would make m2e highly unusuable.
* Instead, we fail gracefully and just ignore the broken
* settings, using defaults.
*/
settings = new Settings();
}
if (userSettingsFile != null) {
settings_length = userSettingsFile.length();
settings_timestamp = userSettingsFile.lastModified();
}
}
return settings;
}
use of org.apache.maven.settings.building.SettingsBuildingException in project maven-plugins by apache.
the class AbstractInvokerMojo method mergeSettings.
/**
* Merge the settings file
*
* @param interpolatedSettingsFile The interpolated settings file.
* @return The merged settings file.
* @throws MojoExecutionException Fail the build in case the merged settings file can't be created.
*/
private File mergeSettings(File interpolatedSettingsFile) throws MojoExecutionException {
File mergedSettingsFile;
Settings mergedSettings = this.settings;
if (mergeUserSettings) {
if (interpolatedSettingsFile != null) {
// Have to merge the specified settings file (dominant) and the one of the invoking Maven process
try {
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setGlobalSettingsFile(interpolatedSettingsFile);
Settings dominantSettings = settingsBuilder.build(request).getEffectiveSettings();
Settings recessiveSettings = cloneSettings();
SettingsUtils.merge(dominantSettings, recessiveSettings, TrackableBase.USER_LEVEL);
mergedSettings = dominantSettings;
getLog().debug("Merged specified settings file with settings of invoking process");
} catch (SettingsBuildingException e) {
throw new MojoExecutionException("Could not read specified settings file", e);
}
}
}
if (this.settingsFile != null && !mergeUserSettings) {
mergedSettingsFile = interpolatedSettingsFile;
} else {
try {
mergedSettingsFile = writeMergedSettingsFile(mergedSettings);
} catch (IOException e) {
throw new MojoExecutionException("Could not create temporary file for invoker settings.xml", e);
}
}
return mergedSettingsFile;
}
Aggregations