implements RepositoryManager
{
/**
- * @plexus.requirement role="org.apache.maven.artifact.repository.discovery.ArtifactDiscoverer" role-hint="legacy"
+ * @plexus.requirement role-hint="legacy"
*/
private ArtifactDiscoverer artifactDiscoverer;
/**
- * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" role-hint="legacy"
+ * @plexus.requirement role-hint="legacy"
*/
private ArtifactRepositoryLayout legacyLayout;
/**
- * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" role-hint="default"
+ * @plexus.requirement role-hint="default"
*/
private ArtifactRepositoryLayout defaultLayout;
/**
- * @plexus.requirement role="org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
+ * @plexus.requirement
*/
private ArtifactRepositoryFactory artifactRepositoryFactory;
/**
- * @plexus.requirement role="org.apache.maven.repository.converter.ArtifactRepositoryFactory"
+ * @plexus.requirement
*/
private RepositoryConverter repositoryConverter;
/**
- * @plexus.requirement role="org.apache.maven.artifact.repository.reporter.ArtifactReporter" role-hint="default"
+ * @plexus.requirement role-hint="default"
*/
private ArtifactReporter reporter;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.proxy.ProxiedArtifactRepository;
import java.util.List;
* @param configuration the configuration
* @return the artifact repository
*/
- ArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration );
+ ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration );
/**
* Create artifact repositories from the given proxy repository configurations.
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.repository.proxy.ProxiedArtifactRepository;
import java.io.File;
import java.util.ArrayList;
return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null );
}
- public ArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
+ public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
{
boolean enabled = isEnabled( configuration.getSnapshotsPolicy() );
String updatePolicy =
new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
- return repoFactory.createArtifactRepository( configuration.getId(), configuration.getUrl(), layout,
- snapshotsPolicy, releasesPolicy );
+ ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(),
+ configuration.getUrl(), layout,
+ snapshotsPolicy, releasesPolicy );
+ ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository );
+ repository.setCacheFailures( configuration.isCacheFailures() );
+ repository.setHardFail( configuration.isHardFail() );
+ repository.setName( configuration.getName() );
+ repository.setUseNetworkProxy( configuration.isUseNetworkProxy() );
+ return repository;
}
public List createRepositories( Configuration configuration )
private ConfigurationStore configurationStore;
/**
- * @plexus.requirement
+ * @plexus.requirement role="org.apache.maven.repository.proxy.ProxyRequestHandler"
+ * @todo seems to be a bug in qdox that the role above is required
*/
private ProxyRequestHandler requestHandler;
private ConfiguredRepositoryFactory repositoryFactory;
/**
- * The proxy handlers for each managed repository.
+ * The proxy groups for each managed repository.
*/
private Map/*<String,ProxiedRepositoryGroup>*/ proxyGroups;
+ /**
+ * The default proxy group/managed repository.
+ */
+ private ProxiedRepositoryGroup defaultProxyGroup;
+
public File get( String path )
throws ProxyException, ResourceDoesNotExistException
{
assert path.startsWith( "/" );
- Map groups = getProxyRepositoryHandlers();
+ Map groups = getProxyGroups();
- String id = parseRepositoryId( path, groups );
+ ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups );
- String repositoryPath = path.substring( id.length() + 2 );
-
- ProxiedRepositoryGroup proxyGroup = (ProxiedRepositoryGroup) groups.get( id );
+ String repositoryPath = path;
+ if ( proxyGroup == null )
+ {
+ if ( defaultProxyGroup != null )
+ {
+ proxyGroup = defaultProxyGroup;
+ }
+ else
+ {
+ throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path );
+ }
+ }
+ else
+ {
+ repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 );
+ }
return requestHandler.get( repositoryPath, proxyGroup.getProxiedRepositories(),
proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() );
{
assert path.startsWith( "/" );
- Map groups = getProxyRepositoryHandlers();
-
- String id = parseRepositoryId( path, groups );
+ Map groups = getProxyGroups();
- String repositoryPath = path.substring( id.length() + 2 );
+ ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups );
- ProxiedRepositoryGroup proxyGroup = (ProxiedRepositoryGroup) groups.get( id );
+ String repositoryPath = path;
+ if ( proxyGroup == null )
+ {
+ if ( defaultProxyGroup != null )
+ {
+ proxyGroup = defaultProxyGroup;
+ }
+ else
+ {
+ throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path );
+ }
+ }
+ else
+ {
+ repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 );
+ }
return requestHandler.getAlways( repositoryPath, proxyGroup.getProxiedRepositories(),
proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() );
return configuration;
}
- private Map getProxyRepositoryHandlers()
+ private Map getProxyGroups()
throws ProxyException
{
if ( proxyGroups == null )
new ProxiedRepositoryGroup( proxiedRepositories, managedRepository, wagonProxy ) );
}
+ // TODO: ability to configure default proxy separately
+
+ if ( groups.size() == 1 )
+ {
+ defaultProxyGroup = (ProxiedRepositoryGroup) groups.values().iterator().next();
+ }
+
proxyGroups = groups;
}
return proxyGroups;
return repositories;
}
- private static String parseRepositoryId( String path, Map handlers )
+ private static ProxiedRepositoryGroup parseRepositoryId( String path, Map groups )
throws ProxyException, ResourceDoesNotExistException
{
- for ( Iterator i = handlers.keySet().iterator(); i.hasNext(); )
+ ProxiedRepositoryGroup group = null;
+
+ for ( Iterator i = groups.entrySet().iterator(); i.hasNext() && group == null; )
{
- String id = (String) i.next();
+ Map.Entry entry = (Map.Entry) i.next();
- if ( path.startsWith( "/" + id + "/" ) )
+ if ( path.startsWith( "/" + entry.getKey() + "/" ) )
{
- return id;
+ group = (ProxiedRepositoryGroup) entry.getValue();
}
}
- throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path );
+
+ return group;
}
private static ProxyInfo createWagonProxy( Proxy proxy )
<artifactId>plexus-log4j-logging</artifactId>
<version>1.1-alpha-2</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ <version>1.0-beta-1</version>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
--- /dev/null
+package org.apache.maven.repository.manager.web.action;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.opensymphony.xwork.ActionSupport;
+import org.apache.maven.repository.proxy.ProxyException;
+import org.apache.maven.repository.proxy.ProxyManager;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * Proxy functionality.
+ *
+ * @plexus.component role="com.opensymphony.xwork.Action" role-hint="proxyAction"
+ */
+public class ProxyAction
+ extends ActionSupport
+{
+ /**
+ * @plexus.requirement
+ */
+ private ProxyManager proxyManager;
+
+ private String path;
+
+ private String filename;
+
+ private String contentType;
+
+ private static final String NOT_FOUND = "notFound";
+
+ private InputStream artifactStream;
+
+ public String execute()
+ throws ProxyException
+ {
+ try
+ {
+ File file = proxyManager.get( path );
+
+ artifactStream = new FileInputStream( file );
+
+ // TODO: could be better
+ contentType = "application/octet-stream";
+
+ filename = file.getName();
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ // TODO: set message?
+ return NOT_FOUND;
+ }
+ catch ( FileNotFoundException e )
+ {
+ // TODO: set message?
+ return NOT_FOUND;
+ }
+
+ return SUCCESS;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public void setPath( String path )
+ {
+ this.path = path;
+ }
+
+ public String getFilename()
+ {
+ return filename;
+ }
+
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ public InputStream getArtifactStream()
+ {
+ return artifactStream;
+ }
+}
{
private static final String BROWSE_PREFIX = "/browse/";
+ private static final String PROXY_PREFIX = "/proxy/";
+
public String getUriFromActionMapping( ActionMapping actionMapping )
{
Map params = actionMapping.getParams();
return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
params.remove( "version" );
}
+ else if ( "proxy".equals( actionMapping.getName() ) )
+ {
+ return PROXY_PREFIX + params.remove( "path" );
+ }
return super.getUriFromActionMapping( actionMapping );
}
}
}
}
+ else if ( path.startsWith( PROXY_PREFIX ) )
+ {
+ // retain the leading /
+ path = path.substring( PROXY_PREFIX.length() - 1 );
+
+ Map params = new HashMap();
+ params.put( "path", path );
+ return new ActionMapping( "proxy", "/", "", params );
+ }
return super.getMapping( httpServletRequest );
}
<result>/WEB-INF/jsp/showArtifact.jsp</result>
</action>
- <!-- TODO! old actions
- <action name="proxy" class="org.apache.maven.repository.proxy.web.action.RepositoryProxyAction">
- <result name="success" type="stream">
- <param name="contentType">application/octet-stream</param>
+ <action name="proxy" class="proxyAction">
+ <result type="stream">
+ <param name="contentType">${contentType}</param>
+ <param name="contentDisposition">filename="${filename}"</param>
<param name="inputName">artifactStream</param>
<param name="bufferSize">1024</param>
</result>
- <result name="notFound" type="dispatcher">notFoundError</result>
- <result name="proxyError" type="dispatcher">proxyError</result>
+ <result name="notFound" type="httpheader">404</result>
</action>
- -->
</package>
<!-- Configuration for the admin package. -->