Search in sources :

Example 6 with Settings

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.");
}
Also used : Server(org.apache.maven.settings.Server) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) Log(org.apache.maven.plugin.logging.Log) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) IssueManagement(org.apache.maven.model.IssueManagement) Settings(org.apache.maven.settings.Settings)

Example 7 with Settings

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;
}
Also used : Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) ArrayList(java.util.ArrayList) Settings(org.apache.maven.settings.Settings)

Example 8 with Settings

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();
    }
}
Also used : HttpRequest(org.apache.maven.plugins.site.deploy.SimpleDavServerHandler.HttpRequest) SiteMavenProjectStub(org.apache.maven.plugins.site.stubs.SiteMavenProjectStub) HashMap(java.util.HashMap) SiteTool(org.apache.maven.doxia.tools.SiteTool) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) AbstractMojo(org.apache.maven.plugin.AbstractMojo) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) MavenSession(org.apache.maven.execution.MavenSession) Proxy(org.apache.maven.settings.Proxy) File(java.io.File) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Example 9 with Settings

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")));
}
Also used : InputStream(java.io.InputStream) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpGet(org.apache.http.client.methods.HttpGet) SettingsXpp3Reader(org.apache.maven.settings.io.xpp3.SettingsXpp3Reader) Mirror(org.apache.maven.settings.Mirror) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Example 10 with Settings

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);
}
Also used : FileValue(com.google.devtools.build.lib.skyframe.FileValue) Server(org.apache.maven.settings.Server) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) RepositoryFunctionException(com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException) Settings(org.apache.maven.settings.Settings) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) Fingerprint(com.google.devtools.build.lib.util.Fingerprint) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) RepositoryNotFoundException(com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryNotFoundException) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) MavenServerRule(com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule) Rule(com.google.devtools.build.lib.packages.Rule) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkspaceAttributeMapper(com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper) Nullable(javax.annotation.Nullable)

Aggregations

Settings (org.apache.maven.settings.Settings)26 File (java.io.File)14 Proxy (org.apache.maven.settings.Proxy)6 IOException (java.io.IOException)5 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)5 Server (org.apache.maven.settings.Server)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 MavenSession (org.apache.maven.execution.MavenSession)3 AbstractMojo (org.apache.maven.plugin.AbstractMojo)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SiteMavenProjectStub (org.apache.maven.plugins.site.stubs.SiteMavenProjectStub)3 MavenProject (org.apache.maven.project.MavenProject)3 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)3 StringWriter (java.io.StringWriter)2 Properties (java.util.Properties)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1