use of org.apache.maven.settings.building.DefaultSettingsBuilder in project karaf by apache.
the class MavenConfigurationSupport method readSettings.
/**
* Reads on demand <code>settings.xml</code> file - without password decryption. Also
* collects declared servers by ID.
* @param settingsFile
*/
protected synchronized Settings readSettings(File settingsFile) throws SettingsBuildingException {
if (!settingsFile.isFile() || !settingsFile.canRead()) {
return null;
}
try {
DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder builder = factory.newInstance();
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile(settingsFile);
SettingsBuildingResult result = builder.build(request);
if (result.getProblems().size() > 0) {
for (SettingsProblem problem : result.getProblems()) {
System.err.println(problem);
}
return null;
} else {
Settings settings = result.getEffectiveSettings();
if (settings.getServers() != null) {
for (Server server : settings.getServers()) {
servers.put(server.getId(), server);
}
}
return settings;
}
} catch (Throwable e) {
System.err.println(e.getMessage());
LOG.error(e.getMessage(), e);
throw e;
}
}
use of org.apache.maven.settings.building.DefaultSettingsBuilder in project bazel by bazelbuild.
the class MavenServerFunction method compute.
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException, RepositoryFunctionException {
String repository = (String) skyKey.argument();
Rule repositoryRule = null;
try {
repositoryRule = RepositoryFunction.getRule(repository, env);
} catch (RepositoryNotFoundException ex) {
// Ignored. We throw a new one below.
}
BlazeDirectories directories = PrecomputedValue.BLAZE_DIRECTORIES.get(env);
if (env.valuesMissing()) {
return null;
}
String serverName;
String url;
Map<String, FileValue> settingsFiles;
boolean foundRepoRule = repositoryRule != null && repositoryRule.getRuleClass().equals(MavenServerRule.NAME);
if (!foundRepoRule) {
if (repository.equals(MavenServerValue.DEFAULT_ID)) {
settingsFiles = getDefaultSettingsFile(directories, env);
serverName = MavenServerValue.DEFAULT_ID;
url = MavenConnector.getMavenCentralRemote().getUrl();
} else {
throw new RepositoryFunctionException(new IOException("Could not find maven repository " + repository), Transience.TRANSIENT);
}
} else {
WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(repositoryRule);
serverName = repositoryRule.getName();
try {
url = mapper.get("url", Type.STRING);
if (!mapper.isAttributeValueExplicitlySpecified("settings_file")) {
settingsFiles = getDefaultSettingsFile(directories, env);
} else {
PathFragment settingsFilePath = new PathFragment(mapper.get("settings_file", Type.STRING));
RootedPath settingsPath = RootedPath.toRootedPath(directories.getWorkspace().getRelative(settingsFilePath), PathFragment.EMPTY_FRAGMENT);
FileValue fileValue = (FileValue) env.getValue(FileValue.key(settingsPath));
if (fileValue == null) {
return null;
}
if (!fileValue.exists()) {
throw new RepositoryFunctionException(new IOException("Could not find settings file " + settingsPath), Transience.TRANSIENT);
}
settingsFiles = ImmutableMap.<String, FileValue>builder().put(USER_KEY, fileValue).build();
}
} catch (EvalException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
}
}
if (settingsFiles == null) {
return null;
}
Fingerprint fingerprint = new Fingerprint();
try {
for (Map.Entry<String, FileValue> entry : settingsFiles.entrySet()) {
fingerprint.addString(entry.getKey());
Path path = entry.getValue().realRootedPath().asPath();
if (path.exists()) {
fingerprint.addBoolean(true);
fingerprint.addBytes(path.getDigest());
} else {
fingerprint.addBoolean(false);
}
}
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
byte[] fingerprintBytes = fingerprint.digestAndReset();
if (settingsFiles.isEmpty()) {
return new MavenServerValue(serverName, url, new Server(), fingerprintBytes);
}
DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
if (settingsFiles.containsKey(SYSTEM_KEY)) {
request.setGlobalSettingsFile(settingsFiles.get(SYSTEM_KEY).realRootedPath().asPath().getPathFile());
}
if (settingsFiles.containsKey(USER_KEY)) {
request.setUserSettingsFile(settingsFiles.get(USER_KEY).realRootedPath().asPath().getPathFile());
}
DefaultSettingsBuilder builder = (new DefaultSettingsBuilderFactory()).newInstance();
SettingsBuildingResult result;
try {
result = builder.build(request);
} catch (SettingsBuildingException e) {
throw new RepositoryFunctionException(new IOException("Error parsing settings files: " + e.getMessage()), Transience.TRANSIENT);
}
if (!result.getProblems().isEmpty()) {
throw new RepositoryFunctionException(new IOException("Errors interpreting settings file: " + Arrays.toString(result.getProblems().toArray())), Transience.PERSISTENT);
}
Settings settings = result.getEffectiveSettings();
Server server = settings.getServer(serverName);
server = server == null ? new Server() : server;
return new MavenServerValue(serverName, url, server, fingerprintBytes);
}
use of org.apache.maven.settings.building.DefaultSettingsBuilder in project fabric8 by jboss-fuse.
the class MavenConfigurationImpl method buildSettings.
private Settings buildSettings(String localRepoPath, String settingsPath, boolean useFallbackRepositories) {
Settings settings;
if (settingsPath == null) {
settings = new Settings();
} else {
DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder builder = factory.newInstance();
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile(new File(settingsPath));
try {
SettingsBuildingResult result = builder.build(request);
settings = result.getEffectiveSettings();
} catch (SettingsBuildingException exc) {
throw new AssertionError("cannot build settings", exc);
}
}
if (useFallbackRepositories) {
Profile fallbackProfile = new Profile();
Repository central = new Repository();
central.setId("central");
central.setUrl("http://repo1.maven.org/maven2");
fallbackProfile.setId("fallback");
fallbackProfile.setRepositories(Arrays.asList(central));
settings.addProfile(fallbackProfile);
settings.addActiveProfile("fallback");
}
if (localRepoPath != null) {
settings.setLocalRepository(localRepoPath);
}
return settings;
}
use of org.apache.maven.settings.building.DefaultSettingsBuilder in project gate-core by GateNLP.
the class Utils method loadMavenSettings.
public static Settings loadMavenSettings() throws SettingsBuildingException {
// http://stackoverflow.com/questions/27818659/loading-mavens-settings-xml-for-jcabi-aether-to-use
SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest();
settingsBuildingRequest.setSystemProperties(System.getProperties());
settingsBuildingRequest.setUserSettingsFile(new File(settingsXml));
settingsBuildingRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
SettingsBuildingResult settingsBuildingResult;
DefaultSettingsBuilderFactory mvnSettingBuilderFactory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder settingsBuilder = mvnSettingBuilderFactory.newInstance();
settingsBuildingResult = settingsBuilder.build(settingsBuildingRequest);
Settings effectiveSettings = settingsBuildingResult.getEffectiveSettings();
return effectiveSettings;
}
use of org.apache.maven.settings.building.DefaultSettingsBuilder in project gradle by gradle.
the class DefaultMavenSettingsProvider method buildSettings.
/**
* Builds a complete `Settings` instance for this machine.
*
* Note that this can be an expensive operation, spawning an external process
* and doing a bunch of additional processing.
*/
@Override
public Settings buildSettings() throws SettingsBuildingException {
DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder defaultSettingsBuilder = factory.newInstance();
DefaultSettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest();
settingsBuildingRequest.setSystemProperties(System.getProperties());
settingsBuildingRequest.setUserSettingsFile(mavenFileLocations.getUserSettingsFile());
settingsBuildingRequest.setGlobalSettingsFile(mavenFileLocations.getGlobalSettingsFile());
SettingsBuildingResult settingsBuildingResult = defaultSettingsBuilder.build(settingsBuildingRequest);
return settingsBuildingResult.getEffectiveSettings();
}
Aggregations