use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class GitHubDownloaderTestCase method testConfigureAuthenticationWithNoServer.
public void testConfigureAuthenticationWithNoServer() throws Exception {
IssueManagement issueManagement = newGitHubIssueManagement();
GitHubDownloader gitHubDownloader = newGitHubDownloader(issueManagement);
Settings settings = new Settings();
Server server = newServer("not-the-right-one");
settings.addServer(server);
SettingsDecrypter decrypter = mock(SettingsDecrypter.class);
SettingsDecryptionResult result = mock(SettingsDecryptionResult.class);
Log log = mock(Log.class);
when(result.getProblems()).thenReturn(Collections.<SettingsProblem>emptyList());
when(result.getServer()).thenReturn(server);
when(decrypter.decrypt(new DefaultSettingsDecryptionRequest(server))).thenReturn(result);
gitHubDownloader.configureAuthentication(decrypter, "github-server", settings, log);
verify(log).warn("Can't find server id [github-server] configured in githubAPIServerId.");
}
use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class EffectiveSettingsMojo method copySettings.
/**
* @param settings could be {@code null}
* @return a new instance of settings or {@code null} if settings was {@code null}.
*/
private static Settings copySettings(Settings settings) {
if (settings == null) {
return null;
}
// Not a deep copy in M2.2.1 !!!
Settings clone = SettingsUtils.copySettings(settings);
List<Server> clonedServers = new ArrayList<Server>(settings.getServers().size());
for (Server server : settings.getServers()) {
Server clonedServer = new Server();
clonedServer.setConfiguration(server.getConfiguration());
clonedServer.setDirectoryPermissions(server.getDirectoryPermissions());
clonedServer.setFilePermissions(server.getFilePermissions());
clonedServer.setId(server.getId());
clonedServer.setPassphrase(server.getPassphrase());
clonedServer.setPassword(server.getPassword());
clonedServer.setPrivateKey(server.getPrivateKey());
clonedServer.setSourceLevel(server.getSourceLevel());
clonedServer.setUsername(server.getUsername());
clonedServers.add(clonedServer);
}
clone.setServers(clonedServers);
List<Proxy> clonedProxies = new ArrayList<Proxy>(settings.getProxies().size());
for (Proxy proxy : settings.getProxies()) {
Proxy clonedProxy = new Proxy();
clonedProxy.setActive(proxy.isActive());
clonedProxy.setHost(proxy.getHost());
clonedProxy.setId(proxy.getId());
clonedProxy.setNonProxyHosts(proxy.getNonProxyHosts());
clonedProxy.setPassword(proxy.getPassword());
clonedProxy.setPort(proxy.getPort());
clonedProxy.setProtocol(proxy.getProtocol());
clonedProxy.setSourceLevel(proxy.getSourceLevel());
clonedProxy.setUsername(proxy.getUsername());
clonedProxies.add(clonedProxy);
}
clone.setProxies(clonedProxies);
return clone;
}
use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class AbstractSiteDeployWebDavTest method davDeployThruProxyWitAuthzInProxy.
@Test
public void davDeployThruProxyWitAuthzInProxy() throws Exception {
FileUtils.cleanDirectory(siteTargetPath);
//SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler( siteTargetPath );
Map<String, String> authentications = new HashMap<String, String>();
authentications.put("foo", "titi");
AuthAsyncProxyServlet servlet = new AuthAsyncProxyServlet(authentications, siteTargetPath);
SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(servlet);
try {
File pluginXmlFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
AbstractMojo mojo = getMojo(pluginXmlFile);
assertNotNull(mojo);
SiteMavenProjectStub siteMavenProjectStub = new SiteMavenProjectStub("deploy-dav");
siteMavenProjectStub.getDistributionManagement().getSite().setUrl("dav:http://toto.com/site/");
setVariableValueToObject(mojo, "project", siteMavenProjectStub);
Settings settings = new Settings();
Proxy proxy = new Proxy();
//dummy proxy
proxy.setActive(true);
proxy.setHost("localhost");
proxy.setPort(simpleDavServerHandler.getPort());
proxy.setProtocol("dav");
proxy.setUsername("foo");
proxy.setPassword("titi");
proxy.setNonProxyHosts("www.google.com|*.somewhere.com");
settings.addProxy(proxy);
setVariableValueToObject(mojo, "settings", settings);
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setProxies(Arrays.asList(proxy));
MavenSession mavenSession = new MavenSession(getContainer(), null, request, null);
setVariableValueToObject(mojo, "mavenSession", mavenSession);
File inputDirectory = new File("src/test/resources/unit/deploy-dav/target/site");
// test which mojo we are using
if (ReflectionUtils.getFieldByNameIncludingSuperclasses("inputDirectory", mojo.getClass()) != null) {
setVariableValueToObject(mojo, "inputDirectory", inputDirectory);
} else {
ArtifactRepositoryFactory artifactRepositoryFactory = getContainer().lookup(ArtifactRepositoryFactory.class);
setVariableValueToObject(mojo, "stagingDirectory", inputDirectory);
setVariableValueToObject(mojo, "reactorProjects", Collections.emptyList());
setVariableValueToObject(mojo, "localRepository", artifactRepositoryFactory.createArtifactRepository("local", "foo", "default", null, null));
setVariableValueToObject(mojo, "siteTool", getContainer().lookup(SiteTool.class));
setVariableValueToObject(mojo, "siteDirectory", new File("foo"));
setVariableValueToObject(mojo, "repositories", Collections.emptyList());
}
mojo.execute();
assertContentInFiles();
assertTrue(requestsContainsProxyUse(servlet.httpRequests));
assertAtLeastOneRequestContainsHeader(servlet.httpRequests, "Proxy-Authorization");
for (HttpRequest rq : servlet.httpRequests) {
log.info(rq.toString());
}
} finally {
simpleDavServerHandler.stop();
}
}
use of org.apache.maven.settings.Settings in project indy by Commonjava.
the class SettingsGeneratedForRemoteRepoTest method generateSettingsXml.
@Test
public void generateSettingsXml() throws Exception {
final IndyClientHttp http = getHttp();
// all mavdav requests are siblings of the default base-url suffix '/api/'
final String url = getDotMavenUrl("settings/remote/settings-central.xml");
System.out.println("Requesting: " + url);
final HttpResources resources = http.getRaw(new HttpGet(url));
InputStream stream = null;
Settings settings = null;
try {
stream = resources.getResponseStream();
settings = new SettingsXpp3Reader().read(stream);
} finally {
closeQuietly(stream);
closeQuietly(resources);
}
assertThat(settings.getLocalRepository(), equalTo("${user.home}/.m2/repo-remote-central"));
assertThat(settings.getMirrors(), notNullValue());
assertThat(settings.getMirrors().size(), equalTo(1));
final Mirror mirror = settings.getMirrors().get(0);
assertThat(mirror.getUrl(), equalTo(http.toIndyUrl("remote/central")));
}
use of org.apache.maven.settings.Settings 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);
}
Aggregations