]> source.dussan.org Git - archiva.git/commitdiff
use bean rather than passing string. return back repositoryId used.
authorOlivier Lamy <olamy@apache.org>
Wed, 23 May 2012 16:26:02 +0000 (16:26 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 23 May 2012 16:26:02 +0000 (16:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1341937 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ArtifactContentEntry.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArtifactContentEntriesTests.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java

index b74a143b94c2045fd41aa45bcc3e1147ebbd1de3..7c2fac56e86f53b2c07e7bab54d8aa8624b29e1a 100644 (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();
     }
index 6cd280bd57dbcb3c0c7d5bda09318fbe88332bb5..22028c4ab275c68197d6098374e42896e8199062 100644 (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;
 }
index 37bb2f7fb94299659340c5db158291a21b47ce6f..1bad078d57c32debe4c4092b2de1d3fa29c39daf 100644 (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 ) );
                     }
                 }
             }
index 18c4942d993446187012ed4d1845901004e9be31..10820f8c9f6e1aae1e01722b49fd7572b98841a1 100644 (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" ) );
 
     }
 
index 8b3aa6e77fb3e6b53fed6315025bb5c6098ef715..86181269f375e29ccb76583fca79e619e481d6c7 100644 (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 );