use bean rather than passing string. return back repositoryId used.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1341937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-05-23 16:26:02 +00:00
parent 52790f9eea
commit 1130d556c2
5 changed files with 67 additions and 37 deletions

View File

@ -35,16 +35,21 @@ public class ArtifactContentEntry
private int depth;
private String repositoryId;
public ArtifactContentEntry()
{
// no op
}
public ArtifactContentEntry( String path, boolean file, int depth )
public ArtifactContentEntry( String path, boolean file, int depth, String repositoryId )
{
this.path = path;
this.file = file;
this.depth = depth;
this.repositoryId = repositoryId;
}
public String getPath()
@ -77,6 +82,17 @@ public class ArtifactContentEntry
this.depth = depth;
}
public String getRepositoryId()
{
return repositoryId;
}
public void setRepositoryId( String repositoryId )
{
this.repositoryId = repositoryId;
}
@Override
public boolean equals( Object o )
{
@ -99,7 +115,11 @@ public class ArtifactContentEntry
{
return false;
}
if ( path != null ? !path.equals( that.path ) : that.path != null )
if ( !path.equals( that.path ) )
{
return false;
}
if ( !repositoryId.equals( that.repositoryId ) )
{
return false;
}
@ -110,20 +130,23 @@ public class ArtifactContentEntry
@Override
public int hashCode()
{
int result = path != null ? path.hashCode() : 0;
int result = path.hashCode();
result = 31 * result + ( file ? 1 : 0 );
result = 31 * result + depth;
result = 31 * result + repositoryId.hashCode();
return result;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder();
sb.append( "ArtifactContentEntry" );
sb.append( "{text='" ).append( path ).append( '\'' );
sb.append( "{path='" ).append( path ).append( '\'' );
sb.append( ", file=" ).append( file );
sb.append( ", depth=" ).append( depth );
sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
sb.append( '}' );
return sb.toString();
}

View File

@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.rest.api.model.Artifact;
import org.apache.archiva.rest.api.model.ArtifactContent;
import org.apache.archiva.rest.api.model.ArtifactContentEntry;
import org.apache.archiva.rest.api.model.ArtifactDownloadInfo;
import org.apache.archiva.rest.api.model.BrowseResult;
@ -172,14 +173,14 @@ public interface BrowseService
@Path( "artifactContentText/{g}/{a}/{v}" )
@GET
@Produces( MediaType.TEXT_PLAIN )
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
/**
* if path is empty content of the file is returned (for pom view)
*/
String getArtifactContentText( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId,
@PathParam( "v" ) String version, @QueryParam( "c" ) String classifier,
@QueryParam( "t" ) String type, @QueryParam( "p" ) String path,
@QueryParam( "repositoryId" ) String repositoryId )
ArtifactContent getArtifactContentText( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId,
@PathParam( "v" ) String version, @QueryParam( "c" ) String classifier,
@QueryParam( "t" ) String type, @QueryParam( "p" ) String path,
@QueryParam( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
}

View File

@ -39,6 +39,7 @@ import org.apache.archiva.repository.RepositoryContentFactory;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryNotFoundException;
import org.apache.archiva.rest.api.model.Artifact;
import org.apache.archiva.rest.api.model.ArtifactContent;
import org.apache.archiva.rest.api.model.ArtifactContentEntry;
import org.apache.archiva.rest.api.model.ArtifactDownloadInfo;
import org.apache.archiva.rest.api.model.BrowseResult;
@ -635,7 +636,7 @@ public class DefaultBrowseService
File file = managedRepositoryContent.toFile( archivaArtifact );
if ( file.exists() )
{
return readFileEntries( file, path );
return readFileEntries( file, path, repoId );
}
}
}
@ -714,8 +715,8 @@ public class DefaultBrowseService
return artifactDownloadInfos;
}
public String getArtifactContentText( String groupId, String artifactId, String version, String classifier,
String type, String path, String repositoryId )
public ArtifactContent getArtifactContentText( String groupId, String artifactId, String version, String classifier,
String type, String path, String repositoryId )
throws ArchivaRestServiceException
{
List<String> selectedRepos = getSelectedRepos( repositoryId );
@ -743,14 +744,14 @@ public class DefaultBrowseService
InputStream inputStream = jarFile.getInputStream( zipEntry );
try
{
return IOUtils.toString( inputStream );
return new ArtifactContent( IOUtils.toString( inputStream ), repoId );
}
finally
{
IOUtils.closeQuietly( inputStream );
}
}
return FileUtils.readFileToString( file );
return new ArtifactContent( FileUtils.readFileToString( file ), repoId );
}
}
catch ( IOException e )
@ -774,14 +775,14 @@ public class DefaultBrowseService
log.debug( "artifact: {}:{}:{}:{}:{} not found",
Arrays.asList( groupId, artifactId, version, classifier, type ).toArray( new String[5] ) );
// 404 ?
return "";
return new ArtifactContent();
}
//---------------------------
// internals
//---------------------------
protected List<ArtifactContentEntry> readFileEntries( File file, String filterPath )
protected List<ArtifactContentEntry> readFileEntries( File file, String filterPath, String repoId )
throws IOException
{
Map<String, ArtifactContentEntry> artifactContentEntryMap = new HashMap<String, ArtifactContentEntry>();
@ -808,7 +809,7 @@ public class DefaultBrowseService
artifactContentEntryMap.put( entryRootPath,
new ArtifactContentEntry( entryRootPath, !currentEntry.isDirectory(),
depth ) );
depth, repoId ) );
}
else
{
@ -817,7 +818,7 @@ public class DefaultBrowseService
{
artifactContentEntryMap.put( cleanedEntryName, new ArtifactContentEntry( cleanedEntryName,
!currentEntry.isDirectory(),
depth ) );
depth, repoId ) );
}
}
}

View File

@ -58,12 +58,13 @@ public class ArtifactContentEntriesTests
File file = new File( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, null );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, null, "foo" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
new ArtifactContentEntry( "org", false, 0 ), new ArtifactContentEntry( "META-INF", false, 0 ) );
new ArtifactContentEntry( "org", false, 0, "foo" ),
new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
}
@ -75,12 +76,13 @@ public class ArtifactContentEntriesTests
File file = new File( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "", "foo" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
new ArtifactContentEntry( "org", false, 0 ), new ArtifactContentEntry( "META-INF", false, 0 ) );
new ArtifactContentEntry( "org", false, 0, "foo" ),
new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
}
@ -92,12 +94,13 @@ public class ArtifactContentEntriesTests
File file = new File( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "/" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "/", "foo" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
new ArtifactContentEntry( "org", false, 0 ), new ArtifactContentEntry( "META-INF", false, 0 ) );
new ArtifactContentEntry( "org", false, 0, "foo" ),
new ArtifactContentEntry( "META-INF", false, 0, "foo" ) );
}
@ -109,12 +112,12 @@ public class ArtifactContentEntriesTests
File file = new File( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "org" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "org", "foo" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
new ArtifactContentEntry( "org/apache", false, 1 ) );
new ArtifactContentEntry( "org/apache", false, 1, "foo" ) );
}
@ -127,12 +130,12 @@ public class ArtifactContentEntriesTests
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries =
browseService.readFileEntries( file, "org/apache/commons/logging/impl/" );
browseService.readFileEntries( file, "org/apache/commons/logging/impl/", "foo" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 16 ).contains(
new ArtifactContentEntry( "org/apache/commons/logging/impl/AvalonLogger.class", true, 5 ) );
new ArtifactContentEntry( "org/apache/commons/logging/impl/AvalonLogger.class", true, 5, "foo" ) );
}
@ -145,13 +148,13 @@ public class ArtifactContentEntriesTests
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries =
browseService.readFileEntries( file, "org/apache/commons/logging/" );
browseService.readFileEntries( file, "org/apache/commons/logging/", "foo" );
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 10 ).contains(
new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4 ),
new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4 ) );
new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4, "foo" ),
new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4, "foo" ) );
}

View File

@ -249,7 +249,8 @@ public class BrowseServiceTest
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
new ArtifactContentEntry( "org", false, 0 ), new ArtifactContentEntry( "META-INF", false, 0 ) );
new ArtifactContentEntry( "org", false, 0, testRepoId ),
new ArtifactContentEntry( "META-INF", false, 0, testRepoId ) );
deleteTestRepo( testRepoId );
}
@ -275,7 +276,7 @@ public class BrowseServiceTest
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 1 ).contains(
new ArtifactContentEntry( "org/apache", false, 1 ) );
new ArtifactContentEntry( "org/apache", false, 1, testRepoId ) );
deleteTestRepo( testRepoId );
}
@ -301,8 +302,8 @@ public class BrowseServiceTest
log.info( "artifactContentEntries: {}", artifactContentEntries );
assertThat( artifactContentEntries ).isNotNull().isNotEmpty().hasSize( 10 ).contains(
new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4 ),
new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4 ) );
new ArtifactContentEntry( "org/apache/commons/logging/impl", false, 4, testRepoId ),
new ArtifactContentEntry( "org/apache/commons/logging/LogSource.class", true, 4, testRepoId ) );
deleteTestRepo( testRepoId );
}
@ -351,7 +352,8 @@ public class BrowseServiceTest
{
String text =
browseService.getArtifactContentText( "commons-logging", "commons-logging", "1.1", "sources", null,
"org/apache/commons/logging/LogSource.java", testRepoId );
"org/apache/commons/logging/LogSource.java",
testRepoId ).getContent();
log.debug( "text: {}", text );
@ -386,7 +388,7 @@ public class BrowseServiceTest
{
String text =
browseService.getArtifactContentText( "commons-logging", "commons-logging", "1.1", null, "pom", null,
testRepoId );
testRepoId ).getContent();
log.info( "text: {}", text );