mirror of https://github.com/apache/archiva.git
Work towards compilable webapp
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@527650 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9e2d664ab3
commit
454fb5b0be
|
@ -27,6 +27,8 @@ package org.apache.maven.archiva.database;
|
|||
*/
|
||||
public interface ArchivaDAO
|
||||
{
|
||||
public static final String ROLE = ArchivaDAO.class.getName();
|
||||
|
||||
ArtifactDAO getArtifactDAO();
|
||||
|
||||
ProjectModelDAO getProjectModelDAO();
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.maven.archiva.database;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -52,20 +52,20 @@ public interface RepositoryDAO
|
|||
* This is the only list of options created in this DAO.
|
||||
*/
|
||||
|
||||
public ArchivaRepositoryModel createRepository( String id, String url );
|
||||
public ArchivaRepository createRepository( String id, String name, String url );
|
||||
|
||||
public List /*<ArchivaRepositoryModel>*/getRepositories()
|
||||
public List /*<ArchivaRepository>*/getRepositories()
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException;
|
||||
|
||||
public ArchivaRepositoryModel getRepository( String id )
|
||||
public ArchivaRepository getRepository( String id )
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException;
|
||||
|
||||
public List queryRepository( Constraint constraint )
|
||||
public List /*<ArchivaRepository>*/queryRepositories( Constraint constraint )
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException;
|
||||
|
||||
public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
|
||||
public ArchivaRepository saveRepository( ArchivaRepository repository )
|
||||
throws ArchivaDatabaseException;
|
||||
|
||||
public void deleteRepository( ArchivaRepositoryModel repository )
|
||||
public void deleteRepository( ArchivaRepository repository )
|
||||
throws ArchivaDatabaseException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.apache.maven.archiva.database.constraints;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.maven.archiva.database.Constraint;
|
||||
|
||||
/**
|
||||
* ArtifactsRelatedConstraint
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ArtifactsRelatedConstraint
|
||||
extends AbstractConstraint
|
||||
implements Constraint
|
||||
{
|
||||
private String whereClause;
|
||||
|
||||
public ArtifactsRelatedConstraint( String groupId, String artifactId, String version )
|
||||
{
|
||||
whereClause = "groupId == '" + StringEscapeUtils.escapeSql( groupId ) + "' AND artifactId == '"
|
||||
+ StringEscapeUtils.escapeSql( artifactId ) + "' AND version == '" + StringEscapeUtils.escapeSql( version )
|
||||
+ "'";
|
||||
}
|
||||
|
||||
public String getSortColumn()
|
||||
{
|
||||
return "classifier";
|
||||
}
|
||||
|
||||
public String getWhereCondition()
|
||||
{
|
||||
return whereClause;
|
||||
}
|
||||
}
|
|
@ -62,12 +62,6 @@ public class JdoArtifactDAO
|
|||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
if ( !( e instanceof ObjectNotFoundException ) )
|
||||
{
|
||||
getLogger().warn(
|
||||
"Unable to get artifact [" + groupId + ":" + artifactId + ":" + version + ":"
|
||||
+ classifier + ":" + type + "]: " + e.getMessage(), e );
|
||||
}
|
||||
artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,11 @@ import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
|||
import org.apache.maven.archiva.database.Constraint;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.database.RepositoryDAO;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -42,12 +45,12 @@ public class JdoRepositoryDAO
|
|||
* @plexus.requirement role-hint="archiva"
|
||||
*/
|
||||
private JdoAccess jdo;
|
||||
|
||||
|
||||
/* .\ Archiva Repository \.____________________________________________________________ */
|
||||
|
||||
public ArchivaRepositoryModel createRepository( String id, String url )
|
||||
public ArchivaRepository createRepository( String id, String name, String url )
|
||||
{
|
||||
ArchivaRepositoryModel repo;
|
||||
ArchivaRepository repo;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -55,9 +58,7 @@ public class JdoRepositoryDAO
|
|||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
repo = new ArchivaRepositoryModel();
|
||||
repo.setId( id );
|
||||
repo.setUrl( url );
|
||||
repo = new ArchivaRepository( id, name, url );
|
||||
}
|
||||
|
||||
return repo;
|
||||
|
@ -69,26 +70,49 @@ public class JdoRepositoryDAO
|
|||
return jdo.getAllObjects( ArchivaRepositoryModel.class );
|
||||
}
|
||||
|
||||
public ArchivaRepositoryModel getRepository( String id )
|
||||
public ArchivaRepository getRepository( String id )
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
return (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id, null );
|
||||
ArchivaRepositoryModel model = (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id,
|
||||
null );
|
||||
return new ArchivaRepository( model );
|
||||
}
|
||||
|
||||
public List queryRepository( Constraint constraint )
|
||||
public List queryRepositories( Constraint constraint )
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
return jdo.getAllObjects( ArchivaRepositoryModel.class, constraint );
|
||||
List results = jdo.getAllObjects( ArchivaRepositoryModel.class, constraint );
|
||||
|
||||
if ( ( results == null ) || results.isEmpty() )
|
||||
{
|
||||
return results;
|
||||
}
|
||||
|
||||
List ret = new ArrayList();
|
||||
Iterator it = results.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
ArchivaRepositoryModel model = (ArchivaRepositoryModel) it.next();
|
||||
ret.add( new ArchivaRepository( model ) );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
|
||||
public ArchivaRepository saveRepository( ArchivaRepository repository )
|
||||
{
|
||||
return (ArchivaRepositoryModel) jdo.saveObject( repository );
|
||||
ArchivaRepositoryModel model = (ArchivaRepositoryModel) jdo.saveObject( repository.getModel() );
|
||||
if ( model == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ArchivaRepository( model );
|
||||
}
|
||||
|
||||
public void deleteRepository( ArchivaRepositoryModel repository )
|
||||
public void deleteRepository( ArchivaRepository repository )
|
||||
throws ArchivaDatabaseException
|
||||
{
|
||||
jdo.removeObject( repository );
|
||||
jdo.removeObject( repository.getModel() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.apache.maven.archiva.database;
|
|||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
|
||||
import org.codehaus.plexus.jdo.JdoFactory;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.jpox.SchemaTool;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.maven.archiva.database.jdo;
|
|||
import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.RepositoryDAO;
|
||||
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -41,18 +41,18 @@ public class JdoRepositoryDAOTest
|
|||
throws ArchivaDatabaseException
|
||||
{
|
||||
RepositoryDAO repoDao = dao.getRepositoryDAO();
|
||||
|
||||
|
||||
// Create it
|
||||
ArchivaRepositoryModel repo = repoDao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
|
||||
ArchivaRepository repo = repoDao.createRepository( "testRepo", "Test Repository",
|
||||
"http://localhost:8080/repository/foo" );
|
||||
assertNotNull( repo );
|
||||
|
||||
// Set some mandatory values
|
||||
repo.setName( "The Test Repository." );
|
||||
repo.setCreationSource( "Test Case" );
|
||||
repo.setLayoutName( "default" );
|
||||
repo.getModel().setCreationSource( "Test Case" );
|
||||
repo.getModel().setLayoutName( "default" );
|
||||
|
||||
// Save it.
|
||||
ArchivaRepositoryModel repoSaved = repoDao.saveRepository( repo );
|
||||
ArchivaRepository repoSaved = repoDao.saveRepository( repo );
|
||||
assertNotNull( repoSaved );
|
||||
assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
|
||||
|
||||
|
@ -62,28 +62,28 @@ public class JdoRepositoryDAOTest
|
|||
assertEquals( 1, repos.size() );
|
||||
|
||||
// Test that retreived object is what we expect.
|
||||
ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
|
||||
ArchivaRepository firstRepo = (ArchivaRepository) repos.get( 0 );
|
||||
assertNotNull( firstRepo );
|
||||
assertEquals( "testRepo", repo.getId() );
|
||||
assertEquals( "The Test Repository.", repo.getName() );
|
||||
assertEquals( "Test Case", repo.getCreationSource() );
|
||||
assertEquals( "default", repo.getLayoutName() );
|
||||
assertEquals( "The Test Repository.", repo.getModel().getName() );
|
||||
assertEquals( "Test Case", repo.getModel().getCreationSource() );
|
||||
assertEquals( "default", repo.getModel().getLayoutName() );
|
||||
|
||||
// Change value and save.
|
||||
repoSaved.setName( "Saved Again" );
|
||||
repoSaved.getModel().setCreationSource( "Changed" );
|
||||
repoDao.saveRepository( repoSaved );
|
||||
|
||||
// Test that only 1 object is saved.
|
||||
assertEquals( 1, repoDao.getRepositories().size() );
|
||||
|
||||
// Get the specific repo.
|
||||
ArchivaRepositoryModel actualRepo = repoDao.getRepository( "testRepo" );
|
||||
ArchivaRepository actualRepo = repoDao.getRepository( "testRepo" );
|
||||
assertNotNull( actualRepo );
|
||||
|
||||
// Test expected values.
|
||||
assertEquals( "testRepo", actualRepo.getId() );
|
||||
assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
|
||||
assertEquals( "Saved Again", actualRepo.getName() );
|
||||
assertEquals( "Changed", actualRepo.getModel().getCreationSource() );
|
||||
|
||||
// Test that only 1 object is saved.
|
||||
assertEquals( 1, repoDao.getRepositories().size() );
|
||||
|
|
|
@ -64,6 +64,12 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-app-configuration-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
|
@ -120,17 +126,19 @@
|
|||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.archiva</groupId>
|
||||
<artifactId>archiva-proxy</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.archiva</groupId>
|
||||
<artifactId>archiva-core</artifactId>
|
||||
<artifactId>archiva-database</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.archiva</groupId>
|
||||
<artifactId>archiva-common</artifactId>
|
||||
<artifactId>archiva-repository-layer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.archiva</groupId>
|
||||
|
@ -142,15 +150,6 @@
|
|||
<!-- TODO: actually, just exclude from WAR plugin -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-dependency-tree</artifactId>
|
||||
<version>1.0-alpha-2</version>
|
||||
</dependency>
|
||||
<!-- Plexus Security Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus.security</groupId>
|
||||
|
|
|
@ -22,11 +22,7 @@ package org.apache.maven.archiva.web.action;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
|
||||
import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
|
||||
import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
|
||||
import org.apache.maven.archiva.indexer.RepositoryIndexException;
|
||||
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -51,12 +47,7 @@ public class BrowseAction
|
|||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private RepositoryArtifactIndexFactory factory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ConfiguredRepositoryFactory repositoryFactory;
|
||||
private ArchivaDAO dao;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
|
@ -243,15 +234,6 @@ public class BrowseAction
|
|||
return groups;
|
||||
}
|
||||
|
||||
private RepositoryArtifactIndex getIndex()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
File indexPath = new File( configuration.getIndexPath() );
|
||||
|
||||
return factory.createStandardIndex( indexPath );
|
||||
}
|
||||
|
||||
public List getGroups()
|
||||
{
|
||||
return groups;
|
||||
|
|
|
@ -20,39 +20,14 @@ package org.apache.maven.archiva.web.action;
|
|||
*/
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
|
||||
import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
|
||||
import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
|
||||
import org.apache.maven.archiva.indexer.RepositoryIndexException;
|
||||
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
|
||||
import org.apache.maven.archiva.indexer.lucene.LuceneQuery;
|
||||
import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
|
||||
import org.apache.maven.archiva.proxy.ProxyException;
|
||||
import org.apache.maven.archiva.reporting.database.ArtifactResultsDatabase;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.model.ArchivaProjectModel;
|
||||
import org.apache.maven.archiva.web.util.VersionMerger;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactCollector;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.shared.dependency.tree.DependencyNode;
|
||||
import org.apache.maven.shared.dependency.tree.DependencyTree;
|
||||
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
|
||||
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
|
||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.codehaus.plexus.xwork.action.PlexusActionSupport;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -68,55 +43,25 @@ import java.util.Set;
|
|||
/**
|
||||
* Browse the repository.
|
||||
*
|
||||
* TODO change name to ShowVersionedAction to conform to terminology.
|
||||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="showArtifactAction"
|
||||
*/
|
||||
public class ShowArtifactAction
|
||||
extends PlexusActionSupport
|
||||
{
|
||||
/* .\ Not Exposed \._____________________________________________ */
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ConfiguredRepositoryFactory repositoryFactory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private MavenProjectBuilder projectBuilder;
|
||||
private ArchivaDAO dao;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private RepositoryArtifactIndexFactory factory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArtifactMetadataSource artifactMetadataSource;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArtifactCollector collector;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private DependencyTreeBuilder dependencyTreeBuilder;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
ArtifactResultsDatabase artifactsDatabase;
|
||||
/* .\ Input Parameters \.________________________________________ */
|
||||
|
||||
private String groupId;
|
||||
|
||||
|
@ -124,75 +69,81 @@ public class ShowArtifactAction
|
|||
|
||||
private String version;
|
||||
|
||||
private Model model;
|
||||
/* .\ Exposed Output Objects \.__________________________________ */
|
||||
|
||||
private Collection dependencies;
|
||||
/**
|
||||
* The model of this versioned project.
|
||||
*/
|
||||
private ArchivaProjectModel model;
|
||||
|
||||
private List dependencyTree;
|
||||
/**
|
||||
* The list of artifacts that depend on this versioned project.
|
||||
*/
|
||||
private List dependees;
|
||||
|
||||
private String repositoryId;
|
||||
|
||||
private String repositoryUrlName;
|
||||
|
||||
private String artifactPath;
|
||||
|
||||
private List mailingLists;
|
||||
|
||||
/**
|
||||
* The reports associated with this versioned project.
|
||||
*/
|
||||
private List reports;
|
||||
|
||||
/**
|
||||
* Show the versioned project information tab.
|
||||
*
|
||||
* TODO: Change name to 'project'
|
||||
*/
|
||||
public String artifact()
|
||||
throws IOException, XmlPullParserException, ProjectBuildingException, ResourceDoesNotExistException,
|
||||
ProxyException, ArtifactResolutionException
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
if ( !checkParameters() )
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
MavenProject project = readProject();
|
||||
|
||||
model = project.getModel();
|
||||
this.model = readProject();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the artifact information tab.
|
||||
*/
|
||||
public String dependencies()
|
||||
throws IOException, XmlPullParserException, ProjectBuildingException
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
if ( !checkParameters() )
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
MavenProject project = readProject();
|
||||
|
||||
model = project.getModel();
|
||||
this.model = readProject();
|
||||
|
||||
// TODO: should this be the whole set of artifacts, and be more like the maven dependencies report?
|
||||
this.dependencies = VersionMerger.wrap( project.getModel().getDependencies() );
|
||||
// this.dependencies = VersionMerger.wrap( project.getModel().getDependencies() );
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the mailing lists information tab.
|
||||
*/
|
||||
public String mailingLists()
|
||||
throws IOException, XmlPullParserException, ProjectBuildingException
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
if ( !checkParameters() )
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
MavenProject project = readProject();
|
||||
|
||||
model = project.getModel();
|
||||
|
||||
this.mailingLists = project.getMailingLists();
|
||||
this.model = readProject();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the reports tab.
|
||||
*/
|
||||
public String reports()
|
||||
throws IOException, XmlPullParserException, ProjectBuildingException
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
if ( !checkParameters() )
|
||||
{
|
||||
|
@ -200,115 +151,51 @@ public class ShowArtifactAction
|
|||
}
|
||||
|
||||
System.out.println("#### In reports.");
|
||||
this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId, version );
|
||||
// TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId, version );
|
||||
System.out.println("#### Found " + reports.size() + " reports.");
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the dependees (other artifacts that depend on this project) tab.
|
||||
*/
|
||||
public String dependees()
|
||||
throws IOException, XmlPullParserException, ProjectBuildingException, RepositoryIndexException,
|
||||
RepositoryIndexSearchException
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
if ( !checkParameters() )
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
MavenProject project = readProject();
|
||||
this.model = readProject();
|
||||
|
||||
model = project.getModel();
|
||||
|
||||
RepositoryArtifactIndex index = getIndex();
|
||||
|
||||
String id = createId( groupId, artifactId, version );
|
||||
List records = index.search( new LuceneQuery( new TermQuery( new Term( "dependencies", id ) ) ) );
|
||||
|
||||
dependencies = VersionMerger.merge( records );
|
||||
// TODO: create depends on collector.
|
||||
this.dependees = Collections.EMPTY_LIST;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the dependencies of this versioned project tab.
|
||||
*/
|
||||
public String dependencyTree()
|
||||
throws ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
if ( !checkParameters() )
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
List repositories = repositoryFactory.createRepositories( configuration );
|
||||
|
||||
Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
|
||||
// TODO: maybe we can decouple the assembly parts of the project builder from the repository handling to get rid of the temp repo
|
||||
ArtifactRepository localRepository = repositoryFactory.createLocalRepository( configuration );
|
||||
MavenProject project = projectBuilder.buildFromRepository( artifact, repositories, localRepository );
|
||||
|
||||
model = project.getModel();
|
||||
|
||||
getLogger().debug( " processing : " + groupId + ":" + artifactId + ":" + version );
|
||||
|
||||
DependencyTree dependencies = collectDependencies( project, localRepository );
|
||||
|
||||
this.dependencyTree = new ArrayList();
|
||||
|
||||
populateFlatTreeList( dependencies.getRootNode(), dependencyTree );
|
||||
this.model = readProject();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private void populateFlatTreeList( DependencyNode currentNode, List dependencyList )
|
||||
private ArchivaProjectModel readProject()
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
DependencyNode childNode;
|
||||
|
||||
for ( Iterator iterator = currentNode.getChildren().iterator(); iterator.hasNext(); )
|
||||
{
|
||||
childNode = (DependencyNode) iterator.next();
|
||||
dependencyList.add( childNode );
|
||||
populateFlatTreeList( childNode, dependencyList );
|
||||
}
|
||||
}
|
||||
|
||||
private DependencyTree collectDependencies( MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, ProjectBuildingException, InvalidDependencyVersionException
|
||||
{
|
||||
try
|
||||
{
|
||||
return dependencyTreeBuilder.buildDependencyTree( project, localRepository, artifactFactory,
|
||||
artifactMetadataSource, collector );
|
||||
}
|
||||
catch ( DependencyTreeBuilderException e )
|
||||
{
|
||||
getLogger().error( "Unable to build dependency tree.", e );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String createId( String groupId, String artifactId, String version )
|
||||
{
|
||||
return groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
|
||||
private RepositoryArtifactIndex getIndex()
|
||||
throws RepositoryIndexException
|
||||
{
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
File indexPath = new File( configuration.getIndexPath() );
|
||||
|
||||
return factory.createStandardIndex( indexPath );
|
||||
}
|
||||
|
||||
private MavenProject readProject()
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
List repositories = repositoryFactory.createRepositories( configuration );
|
||||
|
||||
Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
|
||||
// TODO: maybe we can decouple the assembly parts of the project builder from the repository handling to get rid of the temp repo
|
||||
ArtifactRepository localRepository = repositoryFactory.createLocalRepository( configuration );
|
||||
return projectBuilder.buildFromRepository( artifact, repositories, localRepository );
|
||||
return dao.getProjectModelDAO().getProjectModel( groupId, artifactId, version );
|
||||
}
|
||||
|
||||
private boolean checkParameters()
|
||||
|
@ -338,16 +225,11 @@ public class ShowArtifactAction
|
|||
return result;
|
||||
}
|
||||
|
||||
public Model getModel()
|
||||
public ArchivaProjectModel getModel()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
public Collection getDependencies()
|
||||
{
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
|
@ -368,11 +250,6 @@ public class ShowArtifactAction
|
|||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public List getDependencyTree()
|
||||
{
|
||||
return dependencyTree;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
|
@ -383,165 +260,6 @@ public class ShowArtifactAction
|
|||
this.version = version;
|
||||
}
|
||||
|
||||
public String getArtifactPath()
|
||||
{
|
||||
return artifactPath;
|
||||
}
|
||||
|
||||
public static class DependencyWrapper
|
||||
{
|
||||
private final String groupId;
|
||||
|
||||
private final String artifactId;
|
||||
|
||||
/**
|
||||
* Versions added. We ignore duplicates since you might add those with varying classifiers.
|
||||
*/
|
||||
private Set versions = new HashSet();
|
||||
|
||||
private String version;
|
||||
|
||||
private String scope;
|
||||
|
||||
private String classifier;
|
||||
|
||||
public DependencyWrapper( StandardArtifactIndexRecord record )
|
||||
{
|
||||
this.groupId = record.getGroupId();
|
||||
|
||||
this.artifactId = record.getArtifactId();
|
||||
|
||||
addVersion( record.getVersion() );
|
||||
}
|
||||
|
||||
public DependencyWrapper( Dependency dependency )
|
||||
{
|
||||
this.groupId = dependency.getGroupId();
|
||||
|
||||
this.artifactId = dependency.getArtifactId();
|
||||
|
||||
this.scope = dependency.getScope();
|
||||
|
||||
this.classifier = dependency.getClassifier();
|
||||
|
||||
addVersion( dependency.getVersion() );
|
||||
}
|
||||
|
||||
public String getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
public String getClassifier()
|
||||
{
|
||||
return classifier;
|
||||
}
|
||||
|
||||
public void addVersion( String version )
|
||||
{
|
||||
// We use DefaultArtifactVersion to get the correct sorting order later, however it does not have
|
||||
// hashCode properly implemented, so we add it here.
|
||||
// TODO: add these methods to the actual DefaultArtifactVersion and use that.
|
||||
versions.add( new DefaultArtifactVersion( version )
|
||||
{
|
||||
public int hashCode()
|
||||
{
|
||||
int result;
|
||||
result = getBuildNumber();
|
||||
result = 31 * result + getMajorVersion();
|
||||
result = 31 * result + getMinorVersion();
|
||||
result = 31 * result + getIncrementalVersion();
|
||||
result = 31 * result + ( getQualifier() != null ? getQualifier().hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DefaultArtifactVersion that = (DefaultArtifactVersion) o;
|
||||
|
||||
if ( getBuildNumber() != that.getBuildNumber() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( getIncrementalVersion() != that.getIncrementalVersion() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( getMajorVersion() != that.getMajorVersion() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( getMinorVersion() != that.getMinorVersion() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( getQualifier() != null ? !getQualifier().equals( that.getQualifier() )
|
||||
: that.getQualifier() != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
|
||||
if ( versions.size() == 1 )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.version = null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public List getVersions()
|
||||
{
|
||||
List versions = new ArrayList( this.versions );
|
||||
Collections.sort( versions );
|
||||
return versions;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
public String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
public List getMailingLists()
|
||||
{
|
||||
return mailingLists;
|
||||
}
|
||||
|
||||
public String getRepositoryUrlName()
|
||||
{
|
||||
return repositoryUrlName;
|
||||
}
|
||||
|
||||
public List getReports()
|
||||
{
|
||||
return reports;
|
||||
|
|
|
@ -19,9 +19,11 @@ package org.apache.maven.archiva.web.check;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.rbac.profile.RoleProfileException;
|
||||
import org.codehaus.plexus.rbac.profile.RoleProfileManager;
|
||||
|
@ -49,7 +51,7 @@ public class RoleExistanceEnvironmentCheck
|
|||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
private ArchivaDAO dao;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="archiva"
|
||||
|
@ -64,15 +66,14 @@ public class RoleExistanceEnvironmentCheck
|
|||
{
|
||||
try
|
||||
{
|
||||
// check if there is potential for role/repo disconnect
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
if ( configuration.isValid() )
|
||||
{
|
||||
List repos = configuration.getRepositories();
|
||||
List repos = dao.getRepositoryDAO().getRepositories();
|
||||
|
||||
for ( Iterator i = repos.iterator(); i.hasNext(); )
|
||||
if ( hasManagedRepository( repos ) )
|
||||
{
|
||||
Iterator it = repos.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
RepositoryConfiguration repository = (RepositoryConfiguration) i.next();
|
||||
RepositoryConfiguration repository = (RepositoryConfiguration) it.next();
|
||||
|
||||
roleProfileManager.getDynamicRole( "archiva-repository-manager", repository.getId() );
|
||||
|
||||
|
@ -85,9 +86,33 @@ public class RoleExistanceEnvironmentCheck
|
|||
list.add( this.getClass().getName() + "error initializing roles: " + rpe.getMessage() );
|
||||
getLogger().info( "error initializing roles", rpe );
|
||||
}
|
||||
catch ( ObjectNotFoundException e )
|
||||
{
|
||||
list.add( this.getClass().getName() + "error initializing roles (repository not found): " + e.getMessage() );
|
||||
getLogger().info( "error initializing roles", e );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
list.add( this.getClass().getName() + "error initializing roles (database error): " + e.getMessage() );
|
||||
getLogger().info( "error initializing roles", e );
|
||||
}
|
||||
|
||||
checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasManagedRepository( List repos )
|
||||
{
|
||||
Iterator it = repos.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
ArchivaRepository repo = (ArchivaRepository) it.next();
|
||||
if ( repo.isManaged() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,14 @@ package org.apache.maven.archiva.web.interceptor;
|
|||
|
||||
import com.opensymphony.xwork.ActionInvocation;
|
||||
import com.opensymphony.xwork.interceptor.Interceptor;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An interceptor that makes the application configuration available
|
||||
*
|
||||
|
@ -39,7 +43,7 @@ public class ConfigurationInterceptor
|
|||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
private ArchivaDAO dao;
|
||||
|
||||
/**
|
||||
* @param actionInvocation
|
||||
|
@ -49,20 +53,12 @@ public class ConfigurationInterceptor
|
|||
public String intercept( ActionInvocation actionInvocation )
|
||||
throws Exception
|
||||
{
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
List repos = dao.getRepositoryDAO().getRepositories();
|
||||
|
||||
if ( !configuration.isValid() )
|
||||
if ( !hasManagedRepository( repos ) )
|
||||
{
|
||||
if ( configuration.getRepositories().isEmpty() )
|
||||
{
|
||||
getLogger().info( "No repositories were configured - forwarding to repository configuration page" );
|
||||
return "config-repository-needed";
|
||||
}
|
||||
else
|
||||
{
|
||||
getLogger().info( "Configuration is incomplete - forwarding to configuration page" );
|
||||
return "config-needed";
|
||||
}
|
||||
getLogger().info( "No repositories exist - forwarding to repository configuration page" );
|
||||
return "config-repository-needed";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -79,4 +75,29 @@ public class ConfigurationInterceptor
|
|||
{
|
||||
// This space left intentionally blank
|
||||
}
|
||||
|
||||
public boolean hasManagedRepository( List repos )
|
||||
{
|
||||
if ( repos == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( repos.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Iterator it = repos.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
ArchivaRepository repo = (ArchivaRepository) it.next();
|
||||
if ( repo.isManaged() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,11 +74,6 @@ public class ProxiedDavServer
|
|||
*/
|
||||
private ProxyRequestHandler proxyRequestHandler;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ConfiguredRepositoryFactory repositoryFactory;
|
||||
|
||||
private RepositoryConfiguration repositoryConfiguration;
|
||||
|
||||
private ArtifactRepository managedRepository;
|
||||
|
|
|
@ -20,8 +20,10 @@ package org.apache.maven.archiva.web.repository;
|
|||
*/
|
||||
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.apache.maven.archiva.security.ArchivaRoleConstants;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
import org.codehaus.plexus.registry.RegistryListener;
|
||||
|
@ -40,15 +42,16 @@ import org.codehaus.plexus.webdav.servlet.DavServerRequest;
|
|||
import org.codehaus.plexus.webdav.servlet.multiplexed.MultiplexedWebDavServlet;
|
||||
import org.codehaus.plexus.webdav.util.WebdavMethodUtil;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* RepositoryServlet
|
||||
*
|
||||
|
@ -74,9 +77,15 @@ public class RepositoryServlet
|
|||
*/
|
||||
private AuditLog audit;
|
||||
|
||||
private Configuration configuration;
|
||||
/**
|
||||
* @plexus.requirement role-hint="jdo"
|
||||
*/
|
||||
private ArchivaDAO dao;
|
||||
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration configuration;
|
||||
|
||||
public void initComponents()
|
||||
throws ServletException
|
||||
|
@ -87,46 +96,73 @@ public class RepositoryServlet
|
|||
httpAuth = (HttpAuthenticator) lookup( HttpAuthenticator.ROLE, "basic" );
|
||||
audit = (AuditLog) lookup( AuditLog.ROLE );
|
||||
|
||||
archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
|
||||
configuration = archivaConfiguration.getConfiguration();
|
||||
archivaConfiguration.addChangeListener( this );
|
||||
dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
|
||||
configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
|
||||
configuration.addChangeListener( this );
|
||||
}
|
||||
|
||||
public void initServers( ServletConfig servletConfig )
|
||||
throws DavServerException
|
||||
{
|
||||
List repositories = configuration.getRepositories();
|
||||
Iterator itrepos = repositories.iterator();
|
||||
while ( itrepos.hasNext() )
|
||||
try
|
||||
{
|
||||
RepositoryConfiguration repoConfig = (RepositoryConfiguration) itrepos.next();
|
||||
File repoDir = new File( repoConfig.getDirectory() );
|
||||
|
||||
if ( !repoDir.exists() )
|
||||
List repositories = dao.getRepositoryDAO().getRepositories();
|
||||
Iterator itrepos = repositories.iterator();
|
||||
while ( itrepos.hasNext() )
|
||||
{
|
||||
repoDir.mkdirs();
|
||||
ArchivaRepository repo = (ArchivaRepository) itrepos.next();
|
||||
if ( !repo.isManaged() )
|
||||
{
|
||||
// Skip non-managed.
|
||||
continue;
|
||||
}
|
||||
|
||||
File repoDir = new File( repo.getUrl().getPath() );
|
||||
|
||||
if ( !repoDir.exists() )
|
||||
{
|
||||
repoDir.mkdirs();
|
||||
}
|
||||
|
||||
DavServerComponent server = createServer( repo.getId(), repoDir, servletConfig );
|
||||
|
||||
server.addListener( audit );
|
||||
}
|
||||
|
||||
DavServerComponent server = createServer( repoConfig.getUrlName(), repoDir, servletConfig );
|
||||
|
||||
server.addListener( audit );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
throw new DavServerException( "Unable to initialized dav servers: " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
public RepositoryConfiguration getRepositoryConfiguration( DavServerRequest request )
|
||||
public ArchivaRepository getRepository( DavServerRequest request )
|
||||
{
|
||||
return configuration.getRepositoryByUrlName( request.getPrefix() );
|
||||
String id = request.getPrefix();
|
||||
try
|
||||
{
|
||||
return dao.getRepositoryDAO().getRepository( id );
|
||||
}
|
||||
catch ( ObjectNotFoundException e )
|
||||
{
|
||||
log( "Unable to find repository for id [" + id + "]" );
|
||||
return null;
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
log( "Unable to find repository for id [" + id + "]: " + e.getMessage(), e );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getRepositoryName( DavServerRequest request )
|
||||
{
|
||||
RepositoryConfiguration repoConfig = getRepositoryConfiguration( request );
|
||||
ArchivaRepository repoConfig = getRepository( request );
|
||||
if ( repoConfig == null )
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
return repoConfig.getName();
|
||||
return repoConfig.getModel().getName();
|
||||
}
|
||||
|
||||
public boolean isAuthenticated( DavServerRequest davRequest, HttpServletResponse response )
|
||||
|
@ -146,7 +182,6 @@ public class RepositoryServlet
|
|||
new AuthenticationException( "User Credentials Invalid" ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
catch ( AuthenticationException e )
|
||||
{
|
||||
|
@ -185,16 +220,15 @@ public class RepositoryServlet
|
|||
permission = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
|
||||
}
|
||||
|
||||
AuthorizationResult authzResult =
|
||||
securitySystem.authorize( securitySession, permission, getRepositoryConfiguration( davRequest )
|
||||
.getId() );
|
||||
AuthorizationResult authzResult = securitySystem.authorize( securitySession, permission, davRequest
|
||||
.getPrefix() );
|
||||
|
||||
if ( !authzResult.isAuthorized() )
|
||||
{
|
||||
if ( authzResult.getException() != null )
|
||||
{
|
||||
log( "Authorization Denied [ip=" + request.getRemoteAddr() + ",isWriteRequest=" + isWriteRequest +
|
||||
",permission=" + permission + "] : " + authzResult.getException().getMessage() );
|
||||
log( "Authorization Denied [ip=" + request.getRemoteAddr() + ",isWriteRequest=" + isWriteRequest
|
||||
+ ",permission=" + permission + "] : " + authzResult.getException().getMessage() );
|
||||
}
|
||||
|
||||
// Issue HTTP Challenge.
|
||||
|
@ -218,12 +252,9 @@ public class RepositoryServlet
|
|||
|
||||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
configuration = archivaConfiguration.getConfiguration();
|
||||
|
||||
if ( propertyName.startsWith( "repositories" ) )
|
||||
{
|
||||
log( "Triggering managed repository configuration change with " + propertyName + " set to " +
|
||||
propertyValue );
|
||||
log( "Triggering managed repository configuration change with " + propertyName + " set to " + propertyValue );
|
||||
getDavManager().removeAllServers();
|
||||
|
||||
try
|
||||
|
|
|
@ -25,17 +25,22 @@ import com.opensymphony.xwork.util.OgnlValueStack;
|
|||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.common.artifact.managed.ManagedArtifact;
|
||||
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
|
||||
import org.apache.maven.archiva.repositories.ActiveManagedRepositories;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.Constraint;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
|
||||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
|
||||
import org.apache.maven.archiva.repository.layout.LayoutException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -56,7 +61,12 @@ public class DownloadArtifact
|
|||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ActiveManagedRepositories managedRepositories;
|
||||
private ArchivaDAO dao;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private BidirectionalRepositoryLayoutFactory layoutFactory;
|
||||
|
||||
private HttpServletRequest req;
|
||||
|
||||
|
@ -77,8 +87,7 @@ public class DownloadArtifact
|
|||
this.res = (HttpServletResponse) pageContext.getResponse();
|
||||
try
|
||||
{
|
||||
managedRepositories = (ActiveManagedRepositories) PlexusTagUtil.lookup( pageContext,
|
||||
ActiveManagedRepositories.ROLE );
|
||||
dao = (ArchivaDAO) PlexusTagUtil.lookup( pageContext, ArchivaDAO.ROLE );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
|
@ -92,25 +101,36 @@ public class DownloadArtifact
|
|||
|
||||
try
|
||||
{
|
||||
ManagedArtifact managedArtifact = managedRepositories.findArtifact( groupId, artifactId, version );
|
||||
Constraint constraint = new ArtifactsRelatedConstraint( groupId, artifactId, version );
|
||||
List relatedArtifacts = dao.getArtifactDAO().queryArtifacts( constraint );
|
||||
|
||||
if ( managedArtifact != null )
|
||||
if ( relatedArtifacts != null )
|
||||
{
|
||||
RepositoryConfiguration repoConfig = managedRepositories.getRepositoryConfiguration( managedArtifact
|
||||
.getRepositoryId() );
|
||||
String prefix = req.getContextPath() + "/repository/" + repoConfig.getUrlName();
|
||||
String repoId = ( (ArchivaArtifact) relatedArtifacts.get( 0 ) ).getModel().getRepositoryId();
|
||||
ArchivaRepository repo = dao.getRepositoryDAO().getRepository( repoId );
|
||||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repo.getLayoutType() );
|
||||
|
||||
String prefix = req.getContextPath() + "/repository/" + repoId;
|
||||
|
||||
if ( mini )
|
||||
{
|
||||
appendMini( sb, prefix, managedArtifact );
|
||||
appendMini( sb, prefix, repo, layout, relatedArtifacts );
|
||||
}
|
||||
else
|
||||
{
|
||||
appendNormal( sb, prefix, managedArtifact );
|
||||
appendNormal( sb, prefix, repo, layout, relatedArtifacts );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
catch ( ObjectNotFoundException e )
|
||||
{
|
||||
appendError( sb, e );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
appendError( sb, e );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
appendError( sb, e );
|
||||
}
|
||||
|
@ -127,17 +147,19 @@ public class DownloadArtifact
|
|||
return super.end( writer, body );
|
||||
}
|
||||
|
||||
private void appendError( StringBuffer sb, ProjectBuildingException e )
|
||||
private void appendError( StringBuffer sb, Exception e )
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
private void appendMini( StringBuffer sb, String prefix, ManagedArtifact managedArtifact )
|
||||
private void appendMini( StringBuffer sb, String prefix, ArchivaRepository repo,
|
||||
BidirectionalRepositoryLayout layout, List relatedArtifacts )
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
private void appendNormal( StringBuffer sb, String prefix, ManagedArtifact managedArtifact )
|
||||
private void appendNormal( StringBuffer sb, String prefix, ArchivaRepository repo,
|
||||
BidirectionalRepositoryLayout layout, List relatedArtifacts )
|
||||
{
|
||||
/*
|
||||
* <div class="download">
|
||||
|
@ -161,33 +183,25 @@ public class DownloadArtifact
|
|||
|
||||
// Heading
|
||||
sb.append( "<h2>" );
|
||||
if ( managedArtifact.getAttached().isEmpty() )
|
||||
if ( relatedArtifacts.size() > 1 )
|
||||
{
|
||||
sb.append( "Download" );
|
||||
sb.append( "Downloads" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( "Downloads" );
|
||||
sb.append( "Download" );
|
||||
}
|
||||
sb.append( "</h2>" );
|
||||
|
||||
// Body
|
||||
sb.append( "<p class=\"body\">" );
|
||||
|
||||
appendLink( sb, prefix, managedArtifact.getPath(), "main" );
|
||||
|
||||
Iterator it = managedArtifact.getAttached().entrySet().iterator();
|
||||
Iterator it = relatedArtifacts.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
Map.Entry entry = (Entry) it.next();
|
||||
String type = (String) entry.getKey();
|
||||
String path = (String) entry.getValue();
|
||||
ArchivaArtifact artifact = (ArchivaArtifact) it.next();
|
||||
|
||||
if ( StringUtils.isNotBlank( path ) )
|
||||
{
|
||||
sb.append( "<br/>" );
|
||||
appendLink( sb, prefix, path, type );
|
||||
}
|
||||
appendLink( sb, prefix, layout, artifact );
|
||||
}
|
||||
|
||||
sb.append( "</div>" ); // close "downloadbox.bd.c"
|
||||
|
@ -197,9 +211,12 @@ public class DownloadArtifact
|
|||
sb.append( "</div>" ); // close "download"
|
||||
}
|
||||
|
||||
private void appendLink( StringBuffer sb, String prefix, String path, String type )
|
||||
private void appendLink( StringBuffer sb, String prefix, BidirectionalRepositoryLayout layout,
|
||||
ArchivaArtifact artifact )
|
||||
{
|
||||
StringBuffer url = new StringBuffer();
|
||||
String path = layout.toPath( artifact );
|
||||
String type = artifact.getType();
|
||||
|
||||
url.append( prefix );
|
||||
url.append( "/" ).append( path );
|
||||
|
|
Loading…
Reference in New Issue