mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
added advanced configuration file to allow credentials for maven repositories
This commit is contained in:
@@ -0,0 +1,164 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||||
|
* binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other
|
||||||
|
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||||
|
* nor the names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.plugin;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.sun.xml.txw2.annotation.XmlCDATA;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
import sonia.scm.xml.XmlCipherStringAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 1.41
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlRootElement(name = "advanced-configuration")
|
||||||
|
public class AdvancedPluginConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<PluginRepository> getRepositories()
|
||||||
|
{
|
||||||
|
if (repositories == null)
|
||||||
|
{
|
||||||
|
repositories = ImmutableSet.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
return repositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Server> getServers()
|
||||||
|
{
|
||||||
|
if (servers == null)
|
||||||
|
{
|
||||||
|
servers = ImmutableSet.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- inner classes --------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @version Enter version here..., 14/07/20
|
||||||
|
* @author Enter your name here...
|
||||||
|
*/
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public static class Server
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getPassword()
|
||||||
|
{
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getUsername()
|
||||||
|
{
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields -------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlJavaTypeAdapter(XmlCipherStringAdapter.class)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String username;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "repository")
|
||||||
|
@XmlElementWrapper(name = "repositories")
|
||||||
|
private Set<PluginRepository> repositories;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElement(name = "server")
|
||||||
|
@XmlElementWrapper(name = "servers")
|
||||||
|
private Set<Server> servers;
|
||||||
|
}
|
||||||
@@ -48,6 +48,8 @@ import org.sonatype.aether.collection.DependencyGraphTransformer;
|
|||||||
import org.sonatype.aether.graph.Dependency;
|
import org.sonatype.aether.graph.Dependency;
|
||||||
import org.sonatype.aether.graph.DependencyFilter;
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
import org.sonatype.aether.graph.DependencyNode;
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.repository.Authentication;
|
||||||
|
import org.sonatype.aether.repository.AuthenticationSelector;
|
||||||
import org.sonatype.aether.repository.LocalRepository;
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
import org.sonatype.aether.repository.LocalRepositoryManager;
|
import org.sonatype.aether.repository.LocalRepositoryManager;
|
||||||
import org.sonatype.aether.repository.Proxy;
|
import org.sonatype.aether.repository.Proxy;
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||||
|
* binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other
|
||||||
|
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||||
|
* nor the names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.plugin;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableMap.Builder;
|
||||||
|
|
||||||
|
import org.sonatype.aether.repository.Authentication;
|
||||||
|
import org.sonatype.aether.repository.AuthenticationSelector;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.AdvancedPluginConfiguration.Server;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
* @since 1.41
|
||||||
|
*/
|
||||||
|
public class AetherAuthenticationSelector implements AuthenticationSelector
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param configuration
|
||||||
|
*/
|
||||||
|
public AetherAuthenticationSelector(AdvancedPluginConfiguration configuration)
|
||||||
|
{
|
||||||
|
Builder<String, Server> builder = ImmutableMap.builder();
|
||||||
|
|
||||||
|
for (Server server : configuration.getServers())
|
||||||
|
{
|
||||||
|
builder.put(server.getId(), server);
|
||||||
|
}
|
||||||
|
|
||||||
|
servers = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param servers
|
||||||
|
*/
|
||||||
|
public AetherAuthenticationSelector(Map<String, Server> servers)
|
||||||
|
{
|
||||||
|
this.servers = servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Authentication getAuthentication(RemoteRepository repository)
|
||||||
|
{
|
||||||
|
Authentication authentication = null;
|
||||||
|
Server server = servers.get(Strings.nullToEmpty(repository.getId()));
|
||||||
|
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
authentication = new Authentication(server.getUsername(),
|
||||||
|
server.getPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
return authentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private final Map<String, Server> servers;
|
||||||
|
}
|
||||||
@@ -82,6 +82,8 @@ public class AetherPluginHandler
|
|||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
private final AdvancedPluginConfiguration advancedPluginConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -92,10 +94,11 @@ public class AetherPluginHandler
|
|||||||
* @param configuration
|
* @param configuration
|
||||||
*/
|
*/
|
||||||
public AetherPluginHandler(PluginManager pluginManager,
|
public AetherPluginHandler(PluginManager pluginManager,
|
||||||
SCMContextProvider context, ScmConfiguration configuration)
|
SCMContextProvider context, ScmConfiguration configuration, AdvancedPluginConfiguration advancedPluginConfiguration)
|
||||||
{
|
{
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
this.advancedPluginConfiguration = advancedPluginConfiguration;
|
||||||
localRepositoryDirectory = new File(context.getBaseDirectory(),
|
localRepositoryDirectory = new File(context.getBaseDirectory(),
|
||||||
BootstrapListener.PLUGIN_DIRECTORY);
|
BootstrapListener.PLUGIN_DIRECTORY);
|
||||||
|
|
||||||
@@ -124,7 +127,7 @@ public class AetherPluginHandler
|
|||||||
logger.error("could not read classpath file", ex);
|
logger.error("could not read classpath file", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IOUtil.mkdirs(localRepositoryDirectory);
|
IOUtil.mkdirs(localRepositoryDirectory);
|
||||||
repositorySystem = Aether.createRepositorySystem();
|
repositorySystem = Aether.createRepositorySystem();
|
||||||
localRepository = new LocalRepository(localRepositoryDirectory);
|
localRepository = new LocalRepository(localRepositoryDirectory);
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ package sonia.scm.plugin;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -104,17 +106,15 @@ public class DefaultPluginManager
|
|||||||
public static final PluginFilter FILTER_UPDATES =
|
public static final PluginFilter FILTER_UPDATES =
|
||||||
new StatePluginFilter(PluginState.UPDATE_AVAILABLE);
|
new StatePluginFilter(PluginState.UPDATE_AVAILABLE);
|
||||||
|
|
||||||
|
|
||||||
|
private static final String ADVANCED_CONFIGURATION = "advanced-configuration.xml";
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
* @param context
|
||||||
* @param securityContextProvicer
|
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* @param pluginLoader
|
* @param pluginLoader
|
||||||
* @param cacheManager
|
* @param cacheManager
|
||||||
@@ -151,9 +151,21 @@ public class DefaultPluginManager
|
|||||||
{
|
{
|
||||||
throw new ConfigurationException(ex);
|
throw new ConfigurationException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File file = new File(context.getBaseDirectory(), ADVANCED_CONFIGURATION);
|
||||||
|
if (file.exists())
|
||||||
|
{
|
||||||
|
advancedPluginConfiguration = JAXB.unmarshal(file, AdvancedPluginConfiguration.class);
|
||||||
|
} else {
|
||||||
|
advancedPluginConfiguration = new AdvancedPluginConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
this.configuration.addListener(this);
|
this.configuration.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final AdvancedPluginConfiguration advancedPluginConfiguration;
|
||||||
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
@@ -246,7 +258,7 @@ public class DefaultPluginManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
AetherPluginHandler aph = new AetherPluginHandler(this, context,
|
AetherPluginHandler aph = new AetherPluginHandler(this, context,
|
||||||
configuration);
|
configuration, advancedPluginConfiguration);
|
||||||
Collection<PluginRepository> repositories =
|
Collection<PluginRepository> repositories =
|
||||||
Sets.newHashSet(new PluginRepository("package-repository",
|
Sets.newHashSet(new PluginRepository("package-repository",
|
||||||
"file://".concat(tempDirectory.getAbsolutePath())));
|
"file://".concat(tempDirectory.getAbsolutePath())));
|
||||||
@@ -638,10 +650,14 @@ public class DefaultPluginManager
|
|||||||
if (pluginHandler == null)
|
if (pluginHandler == null)
|
||||||
{
|
{
|
||||||
pluginHandler = new AetherPluginHandler(this,
|
pluginHandler = new AetherPluginHandler(this,
|
||||||
SCMContext.getContext(), configuration);
|
SCMContext.getContext(), configuration, advancedPluginConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder<PluginRepository> builder = ImmutableSet.builder();
|
||||||
|
builder.addAll(advancedPluginConfiguration.getRepositories());
|
||||||
|
builder.addAll(center.getRepositories());
|
||||||
|
|
||||||
pluginHandler.setPluginRepositories(center.getRepositories());
|
pluginHandler.setPluginRepositories(builder.build());
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user