package org.carlspring.strongbox.providers.layout;

import org.carlspring.strongbox.artifact.coordinates.ArtifactCoordinates;
import org.carlspring.strongbox.artifact.coordinates.P2ArtifactCoordinates;
import org.carlspring.strongbox.providers.layout.p2.P2ArtifactReader;
import org.carlspring.strongbox.storage.Storage;
import org.carlspring.strongbox.storage.repository.Repository;

import java.io.FilenameFilter;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class P2LayoutProvider
        extends AbstractLayoutProvider<P2ArtifactCoordinates>
{

    private static final Logger logger = LoggerFactory.getLogger(P2LayoutProvider.class);

    public static final String ALIAS = "P2 Repository";

    @Autowired
    private LayoutProviderRegistry layoutProviderRegistry;

    @Override
    public void register()
    {
        layoutProviderRegistry.addProvider(ALIAS, this);

        logger.info("Registered layout provider '" + getClass().getCanonicalName() + "' with alias '" + ALIAS + "'.");
    }

    @Override
    public String getAlias()
    {
        return ALIAS;
    }

    @Override
    public P2ArtifactCoordinates getArtifactCoordinates(String path)
    {
        return P2ArtifactCoordinates.create(path);
    }

    protected boolean isMetadata(String path)
    {
        return "content.xml".equals(path) || "artifacts.xml".equals(path) || "artifacts.jar".equals(path) ||
               "content.jar".equals(path);
    }

    @Override
    protected boolean isChecksum(String path)
    {
        return false;
    }

    @Override
    public void deleteMetadata(String storageId,
                               String repositoryId,
                               String metadataPath)
            throws IOException
    {

    }

    @Override
    public void rebuildMetadata(String storageId,
                                String repositoryId,
                                String basePath)
            throws IOException,
                   NoSuchAlgorithmException,
                   XmlPullParserException
    {
        throw new UnsupportedOperationException("Not yet implemented!");
    }

    @Override
    public void rebuildIndexes(String storageId,
                               String repositoryId,
                               String basePath,
                               boolean forceRegeneration)
            throws IOException
    {
        throw new UnsupportedOperationException("Not yet implemented!");
    }

    @Override
    public void regenerateChecksums(String storageId,
                                    String repositoryId,
                                    String basePath,
                                    boolean forceRegeneration)
            throws IOException
    {
        throw new UnsupportedOperationException("Not yet implemented!");
    }

    @Override
    public boolean containsArtifact(Repository repository,
                                    ArtifactCoordinates coordinates)
            throws IOException
    {
        if (coordinates != null)
        {
            P2ArtifactCoordinates artifact = P2ArtifactReader.getArtifact(repository.getBasedir(),
                                                                          coordinates.toPath());
            return coordinates.equals(artifact);
        }
        return false;
    }

    @Override
    public boolean contains(String storageId,
                            String repositoryId,
                            String path)
            throws IOException
    {
        Storage storage = getConfiguration().getStorage(storageId);
        Repository repository = storage.getRepository(repositoryId);

        return containsArtifact(repository, P2ArtifactCoordinates.create(path));
    }

    @Override
    public boolean containsPath(Repository repository,
                                String path)
            throws IOException
    {
        return containsArtifact(repository, P2ArtifactCoordinates.create(path));
    }

    @Override
    public FilenameFilter getMetadataFilenameFilter()
    {
        throw new UnsupportedOperationException("Not yet implemented!");
    }

}

@@ -187,32 +187,174 @@
 actCoordinates;%0A
+import org.carlspring.strongbox.client.ArtifactTransportException;%0Aimport org.carlspring.strongbox.providers.ProviderImplementationException;%0A
 import org.carls
@@ -518,16 +518,99 @@
 ository;
+%0Aimport org.carlspring.strongbox.storage.repository.UnknownRepositoryTypeException;
 %0A%0Aimport
@@ -700,32 +700,55 @@
 orithmException;
+%0Aimport java.util.List;
 %0A%0Aimport org.cod
@@ -2970,32 +2970,37 @@
 ecksums(
-String storageId
+Repository repository
 ,%0A      
@@ -3029,35 +3029,47 @@
         
+List%3C
 String
- repositoryId
+%3E versionDirectories
 ,%0A      
@@ -3102,109 +3102,251 @@
     
-String basePath,%0A                                    boolean forceRegeneration)%0A            throws IO
+boolean forceRegeneration)%0A            throws IOException,%0A                   NoSuchAlgorithmException,%0A                   ProviderImplementationException,%0A                   UnknownRepositoryTypeException,%0A                   ArtifactTransport
 Exce
@@ -3429,32 +3429,33 @@
 nted!%22);%0A    %7D%0A%0A
+%0A
     @Override%0A  

Edit P2LayoutProvider .