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()
this.depth = depth;
}
+ public String getRepositoryId()
+ {
+ return repositoryId;
+ }
+
+ public void setRepositoryId( String repositoryId )
+ {
+ this.repositoryId = repositoryId;
+ }
+
+
@Override
public boolean equals( Object o )
{
{
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;
}
@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();
}
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;
@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;
}
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;
File file = managedRepositoryContent.toFile( archivaArtifact );
if ( file.exists() )
{
- return readFileEntries( file, path );
+ return readFileEntries( file, path, repoId );
}
}
}
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 );
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 )
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>();
artifactContentEntryMap.put( entryRootPath,
new ArtifactContentEntry( entryRootPath, !currentEntry.isDirectory(),
- depth ) );
+ depth, repoId ) );
}
else
{
{
artifactContentEntryMap.put( cleanedEntryName, new ArtifactContentEntry( cleanedEntryName,
!currentEntry.isDirectory(),
- depth ) );
+ depth, repoId ) );
}
}
}
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" ) );
}
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" ) );
}
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" ) );
}
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" ) );
}
"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" ) );
}
"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" ) );
}
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 );
}
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 );
}
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 );
}
{
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 );
{
String text =
browseService.getArtifactContentText( "commons-logging", "commons-logging", "1.1", null, "pom", null,
- testRepoId );
+ testRepoId ).getContent();
log.info( "text: {}", text );