+++ /dev/null
-package org.apache.maven.archiva.database.browsing;
-
-/*
- * 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 java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.PredicateUtils;
-import org.apache.commons.collections.functors.NotPredicate;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionUtil;
-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.database.constraints.ProjectsByArtifactUsageConstraint;
-import org.apache.maven.archiva.database.constraints.UniqueArtifactIdConstraint;
-import org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint;
-import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
-import org.apache.maven.archiva.database.updater.DatabaseUpdater;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.model.Keys;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * DefaultRepositoryBrowsing
- *
- * @version $Id$
- * @plexus.component role="org.apache.maven.archiva.database.browsing.RepositoryBrowsing"
- */
-public class DefaultRepositoryBrowsing
- implements RepositoryBrowsing
-{
- private Logger log = LoggerFactory.getLogger( DefaultRepositoryBrowsing.class );
-
- /**
- * @plexus.requirement role-hint="jdo"
- */
- private ArchivaDAO dao;
-
- /**
- * @plexus.requirement role-hint="jdo"
- */
- private DatabaseUpdater dbUpdater;
-
- /**
- * @see RepositoryBrowsing#getRoot(String, List)
- */
- @SuppressWarnings("unchecked")
- public BrowsingResults getRoot( final String principal, final List<String> observableRepositoryIds )
- {
- final BrowsingResults results = new BrowsingResults();
-
- if ( !observableRepositoryIds.isEmpty() )
- {
- final List<String> groups = (List<String>) dao.query( new UniqueGroupIdConstraint( observableRepositoryIds ) );
- results.setSelectedRepositoryIds( observableRepositoryIds );
- results.setGroupIds( GroupIdFilter.filterGroups( groups ) );
- }
- return results;
- }
-
- /**
- * @see RepositoryBrowsing#selectArtifactId(String, List, String, String)
- */
- @SuppressWarnings("unchecked")
- public BrowsingResults selectArtifactId( final String principal, final List<String> observableRepositoryIds,
- final String groupId, final String artifactId )
- {
- final BrowsingResults results = new BrowsingResults( groupId, artifactId );
-
- if ( !observableRepositoryIds.isEmpty() )
- {
- // NOTE: No group Id or artifact Id's should be returned here.
- List<String> versions =
- (List<String>) dao.query( new UniqueVersionConstraint( observableRepositoryIds, groupId, artifactId ) );
- results.setSelectedRepositoryIds( observableRepositoryIds );
-
- results.setVersions( processSnapshots( versions ) );
- }
- return results;
- }
-
- /**
- * @see RepositoryBrowsing#selectGroupId(String, List, String)
- */
- @SuppressWarnings("unchecked")
- public BrowsingResults selectGroupId( final String principal, final List<String> observableRepositoryIds,
- final String groupId )
- {
- final BrowsingResults results = new BrowsingResults( groupId );
-
- if ( !observableRepositoryIds.isEmpty() )
- {
- final List<String> groups = (List<String>) dao.query( new UniqueGroupIdConstraint( observableRepositoryIds, groupId ) );
- final List<String> artifacts =
- (List<String>) dao.query( new UniqueArtifactIdConstraint( observableRepositoryIds, groupId ) );
-
- // Remove searched for groupId from groups list.
- // Easier to do this here, vs doing it in the SQL query.
- CollectionUtils.filter( groups, NotPredicate.getInstance( PredicateUtils.equalPredicate( groupId ) ) );
-
- results.setSelectedRepositoryIds( observableRepositoryIds );
- results.setGroupIds( groups );
- results.setArtifacts( artifacts );
- }
-
- return results;
- }
-
- /**
- * @see RepositoryBrowsing#selectVersion(String, List, String, String, String)
- */
- public ArchivaProjectModel selectVersion( final String principal, final List<String> observableRepositoryIds,
- final String groupId, final String artifactId, final String version )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- if ( observableRepositoryIds.isEmpty() )
- {
- throw new ArchivaDatabaseException( "There are no observable repositories for the user " + principal );
- }
-
- ArchivaArtifact pomArtifact = getArtifact( principal, observableRepositoryIds, groupId, artifactId, version );
- ArchivaProjectModel model;
-
- if ( !pomArtifact.getModel().isProcessed() )
- {
- // Process it.
- dbUpdater.updateUnprocessed( pomArtifact );
- }
-
- model = getProjectModel( groupId, artifactId, pomArtifact.getVersion() );
-
- if ( model.getPackaging() == null || "".equals( model.getPackaging() ) )
- {
- model.setPackaging( pomArtifact.getType() );
- }
-
- return model;
- }
-
- public String getRepositoryId( final String principal, final List<String> observableRepositoryIds,
- final String groupId, final String artifactId, final String version )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- if ( observableRepositoryIds.isEmpty() )
- {
- throw new ArchivaDatabaseException( "There are no observable repositories for the user " + principal );
- }
-
- try
- {
- ArchivaArtifact pomArchivaArtifact =
- getArtifact( principal, observableRepositoryIds, groupId, artifactId, version );
-
- return pomArchivaArtifact.getModel().getRepositoryId();
- }
- catch ( ObjectNotFoundException e )
- {
- return getNoPomArtifactRepoId( principal, observableRepositoryIds, groupId, artifactId, version,
- observableRepositoryIds.get( 0 ) );
- }
- }
-
- /**
- * @see RepositoryBrowsing#getOtherSnapshotVersions(List, String, String, String)
- */
- @SuppressWarnings("unchecked")
- public List<String> getOtherSnapshotVersions( List<String> observableRepositoryIds, String groupId,
- String artifactId, String version )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- List<String> timestampedVersions = new ArrayList<String>();
-
- if ( VersionUtil.isSnapshot( version ) )
- {
- List<String> versions =
- (List<String>) dao.query( new UniqueVersionConstraint( observableRepositoryIds, groupId, artifactId ) );
-
- for ( String uniqueVersion : versions )
- {
- if ( VersionUtil.getBaseVersion( uniqueVersion ).equals( version ) ||
- VersionUtil.getBaseVersion( uniqueVersion ).equals( VersionUtil.getBaseVersion( version ) ) )
- {
- if ( !timestampedVersions.contains( uniqueVersion ) )
- {
- timestampedVersions.add( uniqueVersion );
- }
- }
- }
- }
-
- return timestampedVersions;
- }
-
- private ArchivaArtifact getArtifact( final String principal, final List<String> observableRepositoryIds,
- final String groupId, final String artifactId, final String version )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- ArchivaArtifact pomArtifact = null;
- Constraint constraint = new ArtifactsRelatedConstraint( groupId, artifactId, version );
-
- try
- {
- List<ArchivaArtifact> artifacts = dao.getArtifactDAO().queryArtifacts( constraint );
-
- // it's possible that similar artifacts reside in different repos
- if ( !artifacts.isEmpty() )
- {
- for ( ArchivaArtifact artifact : artifacts )
- {
- if ( observableRepositoryIds.contains( artifact.getRepositoryId() ) )
- {
- pomArtifact = artifact;
- break;
- }
- }
- }
- }
- catch ( ArchivaDatabaseException e )
- {
- log.warn( "ArchivaDatabaseException occurred while querying for artifact '" + groupId + ":" + artifactId +
- ":" + version + "'." );
- }
-
- if ( pomArtifact == null )
- {
- for ( final String repositoryId : observableRepositoryIds )
- {
- pomArtifact = handleGenericSnapshots( groupId, artifactId, version, repositoryId );
-
- if ( pomArtifact != null )
- {
- break;
- }
- }
- }
-
- // throw exception if pom artifact is still null!
- if ( pomArtifact == null )
- {
- throw new ObjectNotFoundException( "Unable to find artifact " + Keys.toKey( groupId, artifactId, version ) +
- " in observable repository [" + StringUtils.join( observableRepositoryIds.iterator(), ", " ) +
- "] for user " + principal );
- }
-
- return pomArtifact;
- }
-
- public List<ArchivaProjectModel> getUsedBy( final String principal, final List<String> observableRepositoryIds,
- final String groupId, final String artifactId, final String version )
- throws ArchivaDatabaseException
- {
- ProjectsByArtifactUsageConstraint constraint =
- new ProjectsByArtifactUsageConstraint( groupId, artifactId, version );
- List<ArchivaProjectModel> results = dao.getProjectModelDAO().queryProjectModels( constraint );
- if ( results == null )
- {
- // defensive. to honor contract as specified. never null.
- return Collections.emptyList();
- }
-
- return results;
- }
-
- /**
- * Removes SNAPSHOT versions with build numbers. Retains only the generic SNAPSHOT version.
- * Example, if the list of versions are:
- * - 2.0
- * - 2.0.1
- * - 2.1-20070522.143249-1
- * - 2.1-20070522.157829-2
- *
- * the returned version list would contain 2.0, 2.0.1 and 2.1-SNAPSHOT.
- *
- * @param versions
- */
- private List<String> processSnapshots( List<String> versions )
- {
- List<String> cleansedVersions = new ArrayList<String>();
-
- for ( String version : versions )
- {
- if ( VersionUtil.isSnapshot( version ) )
- {
- String baseVersion = VersionUtil.getBaseVersion( version );
- if ( !cleansedVersions.contains( baseVersion ) )
- {
- cleansedVersions.add( baseVersion );
- }
- }
- else
- {
- cleansedVersions.add( version );
- }
- }
-
- return cleansedVersions;
- }
-
- /**
- * Handles querying of generic (*-SNAPSHOT) snapshot version. Process: - Get all the timestamped/unique versions of
- * the artifact from the db - Sort the queried project models - Reverse the list of queried project models to get
- * the latest timestamp version - Loop through the list and get the first one to match the generic (*-SNAPHOT)
- * version
- *
- * @param groupId
- * @param artifactId
- * @param version
- * @param pomArtifact
- * @throws ArchivaDatabaseException
- */
- @SuppressWarnings("unchecked")
- private ArchivaArtifact handleGenericSnapshots( final String groupId, final String artifactId,
- final String version, final String repositoryId )
- throws ArchivaDatabaseException
- {
- ArchivaArtifact result = null;
-
- if ( VersionUtil.isGenericSnapshot( version ) )
- {
- final List<String> versions = (List<String>) dao.query( new UniqueVersionConstraint( groupId, artifactId ) );
- Collections.sort( versions );
- Collections.reverse( versions );
-
- for ( String uniqueVersion : versions )
- {
- if ( VersionUtil.getBaseVersion( uniqueVersion ).equals( version ) )
- {
- try
- {
- log.debug( "Retrieving artifact with version " + uniqueVersion );
- Constraint constraint = new ArtifactsRelatedConstraint( groupId, artifactId, uniqueVersion );
- List<ArchivaArtifact> artifacts = dao.getArtifactDAO().queryArtifacts( constraint );
-
- for ( ArchivaArtifact artifact : artifacts )
- {
- if ( artifact.getRepositoryId().equals( repositoryId ) )
- {
- result = artifact;
- break;
- }
- }
- }
- catch ( ObjectNotFoundException e )
- {
- log.debug( "Artifact '" + groupId + ":" + artifactId + ":" + uniqueVersion +
- "' in repository '" + repositoryId + "' not found in the database." );
- continue;
- }
- }
- }
- }
- return result;
- }
-
- /**
- * Get the project model from the database.
- *
- * @param groupId
- * @param artifactId
- * @param version
- * @return
- * @throws ArchivaDatabaseException
- */
- private ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
- throws ArchivaDatabaseException
- {
- ArchivaProjectModel model = null;
-
- try
- {
- model = dao.getProjectModelDAO().getProjectModel( groupId, artifactId, version );
- }
- catch ( ObjectNotFoundException e )
- {
- log.debug( "Unable to find project model for [" + Keys.toKey( groupId, artifactId, version ) + "]", e );
- }
-
- if ( model == null )
- {
- model = new ArchivaProjectModel();
- model.setGroupId( groupId );
- model.setArtifactId( artifactId );
- model.setVersion( version );
- }
-
- return model;
- }
-
- private String getNoPomArtifactRepoId( String principal, List<String> observableRepos, String groupId,
- String artifactId, String version, String repositoryId )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- ArchivaArtifact artifact = null;
-
- String type = getArtifactType( groupId, artifactId, version );
-
- artifact = dao.getArtifactDAO().createArtifact( groupId, artifactId, version, null, type, repositoryId );
-
- if ( artifact == null )
- {
- // Lets not persist these
- artifact = new ArchivaArtifact( groupId, artifactId, version, null, type, repositoryId );
- }
-
- // Allowed to see this?
- if ( !observableRepos.contains( artifact.getModel().getRepositoryId() ) )
- {
- throw new ObjectNotFoundException( "Unable to find artifact " + Keys.toKey( groupId, artifactId, version ) +
- " in observable repository [" + StringUtils.join( observableRepos.iterator(), ", " ) + "] for user " +
- principal );
- }
-
- return artifact.getModel().getRepositoryId();
- }
-
- private String getArtifactType( String groupId, String artifactId, String version )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- String type = "jar";
-
- try
- {
- List<ArchivaArtifact> artifacts =
- dao.getArtifactDAO().queryArtifacts( new ArtifactsRelatedConstraint( groupId, artifactId, version ) );
-
- if ( artifacts.size() > 0 )
- {
- type = artifacts.get( 0 ).getType();
- }
- }
- catch ( ObjectNotFoundException e )
- {
- // swallow exception?
- }
-
- return type;
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.database.browsing;
-
-/*
- * 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.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.model.ArchivaProjectModel;
-
-import java.util.List;
-
-/**
- * Repository Browsing component
- *
- * @version $Id$
- */
-public interface RepositoryBrowsing
-{
- /**
- * Get the {@link BrowsingResults} for the root of the repository.
- *
- * @return the root browsing results.
- */
- public BrowsingResults getRoot( String principle, List<String> observableRepositoryIds );
-
- /**
- * Get the {@link BrowsingResults} for the selected groupId.
- *
- * @param groupId the groupId to select.
- * @return the {@link BrowsingResults} for the specified groupId.
- */
- public BrowsingResults selectGroupId( String principle, List<String> observableRepositoryIds, String groupId );
-
- /**
- * Get the {@link BrowsingResults} for the selected groupId & artifactId.
- *
- * @param groupId the groupId selected
- * @param artifactId the artifactId selected
- * @return the {@link BrowsingResults} for the specified groupId / artifactId combo.
- */
- public BrowsingResults selectArtifactId( String principle, List<String> observableRepositoryIds, String groupId,
- String artifactId );
-
- /**
- * Get the {@link ArchivaProjectModel} for the selected groupId / artifactId / version combo.
- *
- * @param groupId the groupId selected
- * @param artifactId the artifactId selected
- * @param version the version selected
- * @return the {@link ArchivaProjectModel} for the selected groupId / artifactId / version combo.
- * @throws ObjectNotFoundException if the artifact object or project object isn't found in the database.
- * @throws ArchivaDatabaseException if there is a fundamental database error.
- */
- public ArchivaProjectModel selectVersion( String principle, List<String> observableRepositoryIds, String groupId,
- String artifactId, String version )
- throws ObjectNotFoundException, ArchivaDatabaseException;
-
- /**
- * Get the {@link List} of {@link ArchivaProjectModel} that are used by the provided
- * groupId, artifactId, and version specified.
- *
- * @param groupId the groupId selected
- * @param artifactId the artifactId selected
- * @param version the version selected
- * @return the {@link List} of {@link ArchivaProjectModel} objects. (never null, but can be empty)
- * @throws ArchivaDatabaseException if there is a fundamental database error.
- */
- public List<ArchivaProjectModel> getUsedBy( String principle, List<String> observableRepositoryIds, String groupId,
- String artifactId, String version )
- throws ArchivaDatabaseException;
-
-
- public String getRepositoryId( String principle, List<String> observableRepositoryIds, String groupId,
- String artifactId, String version )
- throws ObjectNotFoundException, ArchivaDatabaseException;
-
- /**
- * Get the other versions of the given SNAPSHOT version.
- *
- * @param observableRepositoryIds
- * @param groupId
- * @param artifactId
- * @param version
- * @return
- * @throws ObjectNotFoundException
- * @throws ArchivaDatabaseException
- */
- public List<String> getOtherSnapshotVersions( List<String> observableRepositoryIds,
- String groupId, String artifactId, String version )
- throws ObjectNotFoundException, ArchivaDatabaseException;
-
-}
+++ /dev/null
-package org.apache.maven.archiva.database.browsing;
-
-/*
- * 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.maven.archiva.database.AbstractArchivaDatabaseTestCase;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-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.ArchivaProjectModel;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-/**
- * RepositoryBrowsingTest
- *
- * @version $Id$
- */
-public class RepositoryBrowsingTest
- extends AbstractArchivaDatabaseTestCase
-{
- private static final List<String> GUEST_REPO_IDS;
-
- private static final String USER_GUEST = "guest";
-
- static
- {
- GUEST_REPO_IDS = new ArrayList<String>();
- GUEST_REPO_IDS.add( "snapshots" );
- GUEST_REPO_IDS.add( "central" );
- }
-
- private ArtifactDAO artifactDao;
-
- private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
- {
- ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar", "central" );
- artifact.getModel().setLastModified( new Date() ); // mandatory field.
- artifact.getModel().setRepositoryId( "central" );
- return artifact;
- }
-
- private RepositoryBrowsing lookupBrowser()
- throws Exception
- {
- RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class );
- assertNotNull( "RepositoryBrowsing should not be null.", browser );
- return browser;
- }
-
- private void saveTestData()
- throws Exception
- {
- ArchivaArtifact artifact;
-
- // Setup artifacts in fresh DB.
- artifact = createArtifact( "commons-lang", "commons-lang", "2.0" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "commons-lang", "commons-lang", "2.0" );
-
- artifact = createArtifact( "commons-lang", "commons-lang", "2.1" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "commons-lang", "commons-lang", "2.1" );
-
- artifact = createArtifact( "org.apache.maven.test", "test-one", "1.2" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.test", "test-one", "1.2" );
-
- artifact = createArtifact( "org.apache.maven.test.foo", "test-two", "1.0" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.test.foo", "test-two", "1.0" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.0" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-two", "2.0" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-20070522.143249-1" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-two", "2.1-20070522.143249-1" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-20070522.153141-2" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-two", "2.1-20070522.153141-2" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1.1" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-two", "2.1.1" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-alpha-1" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-two", "2.1-alpha-1" );
-
- artifact = createArtifact( "org.apache.maven.shared", "test-bar", "2.1" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.maven.shared", "test-bar", "2.1" );
-
- artifact = createArtifact( "org.codehaus.modello", "modellong", "3.0" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.codehaus.modello", "modellong", "3.0" );
-
- artifact = createArtifact( "org.apache.archiva", "archiva-indexer", "1.0-20070522.143249-1" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.archiva", "archiva-indexer", "1.0-20070522.143249-1" );
-
- artifact = createArtifact( "org.apache.archiva", "archiva-indexer", "1.0-20070522.153141-2" );
- artifactDao.saveArtifact( artifact );
- assertArtifactWasSaved( "org.apache.archiva", "archiva-indexer", "1.0-20070522.153141-2" );
- }
-
- private void assertArtifactWasSaved(String groupId, String artifactId, String version)
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- Constraint constraint = new ArtifactsRelatedConstraint( groupId, artifactId, version );
- List<ArchivaArtifact> artifacts = artifactDao.queryArtifacts( constraint );
-
- assertFalse( "Artifact '" + groupId + ":" + artifactId + ":" + version + "' should have been found.",
- artifacts.isEmpty() );
- }
-
- public void testBrowseIntoGroupWithSubgroups()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- BrowsingResults results = browser.selectGroupId( USER_GUEST, GUEST_REPO_IDS, "org.apache.maven.test" );
- assertNotNull( "Browsing Results should not be null.", results );
-
- String expectedSubGroupIds[] = new String[] { "org.apache.maven.test.foo" };
- assertGroupIds( "Browsing Results (subgroup org.apache.maven.test)", results.getGroupIds(), expectedSubGroupIds );
- }
-
- public void testSimpleBrowse()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- BrowsingResults results = browser.getRoot( USER_GUEST, GUEST_REPO_IDS );
- assertNotNull( "Browsing Results should not be null.", results );
-
- String expectedRootGroupIds[] = new String[] { "commons-lang", "org" };
-
- assertGroupIds( "Browsing Results (root)", results.getGroupIds(), expectedRootGroupIds );
- }
-
- public void testViewArtifact()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- ArchivaProjectModel artifact = browser.selectVersion( USER_GUEST, GUEST_REPO_IDS, "commons-lang", "commons-lang", "2.0" );
- assertNotNull( "Artifact should not be null.", artifact );
- assertEquals( "commons-lang", artifact.getGroupId() );
- assertEquals( "commons-lang", artifact.getArtifactId() );
- assertEquals( "2.0", artifact.getVersion() );
- assertEquals( "jar", artifact.getPackaging() );
-
- // MRM-1278
- String repoId = browser.getRepositoryId( USER_GUEST, GUEST_REPO_IDS, "commons-lang", "commons-lang", "2.0" );
- assertEquals( "central", repoId );
- }
-
- public void testViewArtifactWithMultipleTimestampedVersions()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- ArchivaProjectModel artifact = browser.selectVersion( USER_GUEST, GUEST_REPO_IDS, "org.apache.archiva", "archiva-indexer", "1.0-SNAPSHOT" );
- assertNotNull( "Artifact should not be null.", artifact );
- assertEquals( "org.apache.archiva", artifact.getGroupId() );
- assertEquals( "archiva-indexer", artifact.getArtifactId() );
- assertEquals( "1.0-20070522.143249-1", artifact.getVersion() );
- assertEquals( "jar", artifact.getPackaging() );
-
- String repoId = browser.getRepositoryId( USER_GUEST, GUEST_REPO_IDS, "org.apache.archiva", "archiva-indexer", "1.0-SNAPSHOT" );
- assertEquals( "central", repoId );
- }
-
- public void testSelectArtifactId()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- BrowsingResults results =
- browser.selectArtifactId( USER_GUEST, GUEST_REPO_IDS, "org.apache.maven.shared", "test-two" );
- assertNotNull( "Browsing results should not be null.", results );
- assertEquals( 4, results.getVersions().size() );
- assertTrue( results.getVersions().contains( "2.0" ) );
- assertTrue( results.getVersions().contains( "2.1-SNAPSHOT" ) );
- assertTrue( results.getVersions().contains( "2.1.1" ) );
- assertTrue( results.getVersions().contains( "2.1-alpha-1" ) );
- }
-
- public void testGetOtherSnapshotVersionsRequestedVersionIsGeneric()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- List<String> results =
- browser.getOtherSnapshotVersions( GUEST_REPO_IDS, "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" );
- assertNotNull( "Returned list of versions should not be null.", results );
- assertEquals( 3, results.size() );
- assertTrue( results.contains( "2.1-SNAPSHOT" ) );
- assertTrue( results.contains( "2.1-20070522.143249-1" ) );
- assertTrue( results.contains( "2.1-20070522.153141-2" ) );
- }
-
- public void testGetOtherSnapshotVersionsRequestedVersionIsUnique()
- throws Exception
- {
- RepositoryBrowsing browser = lookupBrowser();
- List<String> results =
- browser.getOtherSnapshotVersions( GUEST_REPO_IDS, "org.apache.maven.shared", "test-two", "2.1-20070522.143249-1" );
- assertNotNull( "Returned list of versions should not be null.", results );
- assertEquals( 3, results.size() );
- assertTrue( results.contains( "2.1-SNAPSHOT" ) );
- assertTrue( results.contains( "2.1-20070522.143249-1" ) );
- assertTrue( results.contains( "2.1-20070522.153141-2" ) );
- }
-
- private void assertGroupIds( String msg, List<String> actualGroupIds, String[] expectedGroupIds )
- {
- assertEquals( msg + ": groupIds.length", expectedGroupIds.length, actualGroupIds.size() );
-
- for ( int i = 0; i < expectedGroupIds.length; i++ )
- {
- String expectedGroupId = expectedGroupIds[i];
- assertTrue( msg + ": actual groupIds.contains(" + expectedGroupId + ")", actualGroupIds
- .contains( expectedGroupId ) );
- }
- }
-
- @Override
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- artifactDao = dao.getArtifactDAO();
- saveTestData();
- }
-}
}
// TODO: test with restricted observable repos
- // not currently relevant since it is controlled at the DefaultRepositoryBrowsing level
// TODO: current behaviour is to ignore values that differ between models - instead, pick the latest and use that.
// Need to update the tests to verify this as models are currently the same
List<Artifact> artifacts = new ArrayList<Artifact>();
// 1. get observable repositories
- // 2. use RepositoryBrowsing method to query uniqueVersions? (but with date)
+ // 2. use metadata repository to query uniqueVersions? (but with date)
return artifacts;
}