Search in sources :

Example 6 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project pom-manipulation-ext by release-engineering.

the class GalleyInfrastructure method init.

private void init(final File targetDirectory, final List<ArtifactRepository> remoteRepositories, final ArtifactRepository localRepository, final Settings settings, final List<String> activeProfiles, final Location customLocation, final Transport customTransport, File cacheDir_) throws ManipulationException {
    LocationExpander locationExpander;
    try {
        final List<Location> custom = customLocation == null ? Collections.<Location>emptyList() : Collections.singletonList(customLocation);
        locationExpander = new MavenLocationExpander(custom, remoteRepositories, localRepository, mirrorSelector, settings, activeProfiles);
    } catch (final MalformedURLException e) {
        throw new ManipulationException("Failed to setup Maven-specific LocationExpander: %s", e, e.getMessage());
    }
    xml = new XMLInfrastructure();
    xpaths = new XPathManager();
    final TransportManager transports;
    if (customTransport != null) {
        transports = new TransportManagerImpl(customTransport);
    } else {
        transports = new TransportManagerImpl(new HttpClientTransport(new HttpImpl(new MemoryPasswordManager())), new FileTransport(), new ZipJarTransport());
    }
    cacheDir = cacheDir_;
    if (cacheDir == null) {
        cacheDir = new File(targetDirectory, "manipulator-cache");
    }
    final FileEventManager fileEvents = new NoOpFileEventManager();
    final CacheProvider cache = new FileCacheProvider(cacheDir, new HashedLocationPathGenerator(), fileEvents, new NoOpTransferDecorator());
    final NotFoundCache nfc = new MemoryNotFoundCache();
    executor = Executors.newCachedThreadPool();
    final TransportManagerConfig config = new TransportManagerConfig();
    final TransferManager transfers = new TransferManagerImpl(transports, cache, nfc, fileEvents, new DownloadHandler(nfc, config, executor), new UploadHandler(nfc, config, executor), new ListingHandler(nfc), new ExistenceHandler(nfc), new SpecialPathManagerImpl(), executor);
    final TypeMapper types = new StandardTypeMapper();
    final ArtifactMetadataManager metadataManager = new ArtifactMetadataManagerImpl(transfers, locationExpander);
    final VersionResolver versionResolver = new VersionResolverImpl(new MavenMetadataReader(xml, locationExpander, metadataManager, xpaths));
    artifactManager = new ArtifactManagerImpl(transfers, locationExpander, types, versionResolver);
    // TODO: auto-adjust this to the current Maven runtime!
    final MavenPluginDefaults pluginDefaults = new StandardMaven304PluginDefaults();
    final MavenPluginImplications pluginImplications = new StandardMavenPluginImplications(xml);
    pomReader = new MavenPomReader(xml, locationExpander, artifactManager, xpaths, pluginDefaults, pluginImplications);
    metadataReader = new MavenMetadataReader(xml, locationExpander, metadataManager, xpaths);
}
Also used : StandardTypeMapper(org.commonjava.maven.galley.maven.internal.type.StandardTypeMapper) TypeMapper(org.commonjava.maven.galley.maven.spi.type.TypeMapper) MalformedURLException(java.net.MalformedURLException) NoOpTransferDecorator(org.commonjava.maven.galley.io.NoOpTransferDecorator) TransferManagerImpl(org.commonjava.maven.galley.internal.TransferManagerImpl) VersionResolverImpl(org.commonjava.maven.galley.maven.internal.version.VersionResolverImpl) MavenPluginDefaults(org.commonjava.maven.galley.maven.spi.defaults.MavenPluginDefaults) XPathManager(org.commonjava.maven.galley.maven.model.view.XPathManager) HttpImpl(org.commonjava.maven.galley.transport.htcli.HttpImpl) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) LocationExpander(org.commonjava.maven.galley.spi.transport.LocationExpander) StandardMavenPluginImplications(org.commonjava.maven.galley.maven.internal.defaults.StandardMavenPluginImplications) MavenPluginImplications(org.commonjava.maven.galley.maven.spi.defaults.MavenPluginImplications) ArtifactMetadataManager(org.commonjava.maven.galley.maven.ArtifactMetadataManager) MavenMetadataReader(org.commonjava.maven.galley.maven.parse.MavenMetadataReader) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) UploadHandler(org.commonjava.maven.galley.internal.xfer.UploadHandler) StandardTypeMapper(org.commonjava.maven.galley.maven.internal.type.StandardTypeMapper) ExistenceHandler(org.commonjava.maven.galley.internal.xfer.ExistenceHandler) FileCacheProvider(org.commonjava.maven.galley.cache.FileCacheProvider) TransferManager(org.commonjava.maven.galley.TransferManager) ListingHandler(org.commonjava.maven.galley.internal.xfer.ListingHandler) TransportManagerImpl(org.commonjava.maven.galley.transport.TransportManagerImpl) HashedLocationPathGenerator(org.commonjava.maven.galley.io.HashedLocationPathGenerator) DownloadHandler(org.commonjava.maven.galley.internal.xfer.DownloadHandler) TransportManagerConfig(org.commonjava.maven.galley.config.TransportManagerConfig) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) MemoryPasswordManager(org.commonjava.maven.galley.auth.MemoryPasswordManager) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) FileCacheProvider(org.commonjava.maven.galley.cache.FileCacheProvider) StandardMavenPluginImplications(org.commonjava.maven.galley.maven.internal.defaults.StandardMavenPluginImplications) ArtifactMetadataManagerImpl(org.commonjava.maven.galley.maven.internal.ArtifactMetadataManagerImpl) NoOpFileEventManager(org.commonjava.maven.galley.event.NoOpFileEventManager) StandardMaven304PluginDefaults(org.commonjava.maven.galley.maven.internal.defaults.StandardMaven304PluginDefaults) HttpClientTransport(org.commonjava.maven.galley.transport.htcli.HttpClientTransport) NoOpFileEventManager(org.commonjava.maven.galley.event.NoOpFileEventManager) FileEventManager(org.commonjava.maven.galley.spi.event.FileEventManager) VersionResolver(org.commonjava.maven.galley.maven.spi.version.VersionResolver) FileTransport(org.commonjava.maven.galley.filearc.FileTransport) ZipJarTransport(org.commonjava.maven.galley.filearc.ZipJarTransport) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) XMLInfrastructure(org.commonjava.maven.galley.maven.parse.XMLInfrastructure) ArtifactManagerImpl(org.commonjava.maven.galley.maven.internal.ArtifactManagerImpl) TransportManager(org.commonjava.maven.galley.spi.transport.TransportManager) MavenPomReader(org.commonjava.maven.galley.maven.parse.MavenPomReader) File(java.io.File) Location(org.commonjava.maven.galley.model.Location)

Example 7 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project indy by Commonjava.

the class AbstractIndyFunctionalTest method sleepAndRunFileGC.

protected void sleepAndRunFileGC(long milliseconds) {
    try {
        Thread.sleep(milliseconds);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    CacheProvider cacheProvider = CDI.current().select(CacheProvider.class).get();
    cacheProvider.asAdminView().gc();
}
Also used : CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider)

Example 8 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project galley by Commonjava.

the class CacheProviderTCK method writeAndReadFile.

@Test
public void writeAndReadFile() throws Exception {
    final String content = "This is a test";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname = "/path/to/my/file.txt";
    final CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
    out.write(content.getBytes("UTF-8"));
    out.close();
    final InputStream in = provider.openInputStream(new ConcreteResource(loc, fname));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int read = -1;
    final byte[] buf = new byte[512];
    while ((read = in.read(buf)) > -1) {
        baos.write(buf, 0, read);
    }
    final String result = new String(baos.toByteArray(), "UTF-8");
    assertThat(result, equalTo(content));
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 9 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project galley by Commonjava.

the class RoutingCacheProviderWrapperTest method test.

@Test
public void test() throws Exception {
    final RoutingCacheProviderWrapper router = (RoutingCacheProviderWrapper) new RoutingCacheProviderFactory(selector, fastLocalFac, partylineFac).create(pathgen, decorator, events);
    final CacheProvider partyline = partylineFac.create(pathgen, decorator, events);
    final CacheProvider fastLocal = fastLocalFac.create(pathgen, decorator, events);
    final String fname = "/path/to/my/file.txt";
    Location loc = new SimpleLocation("remote:foo/com");
    ConcreteResource resource = new ConcreteResource(loc, fname);
    CacheProvider get = router.getRoutedProvider(resource);
    assertThat(get, equalTo(partyline));
    loc = new SimpleLocation("hosted:foo/com");
    resource = new ConcreteResource(loc, fname);
    get = router.getRoutedProvider(resource);
    assertThat(get, equalTo(fastLocal));
    loc = new SimpleLocation("group:foo/com");
    resource = new ConcreteResource(loc, fname);
    get = router.getRoutedProvider(resource);
    assertThat(get, equalTo(partyline));
    loc = new SimpleLocation("http://foo.com");
    resource = new ConcreteResource(loc, fname);
    get = router.getRoutedProvider(resource);
    assertThat(get, equalTo(partyline));
    resource = new ConcreteResource(null, null);
    get = router.getRoutedProvider(resource);
    assertThat(get, equalTo(partyline));
    get = router.getRoutedProvider(null);
    assertThat(get, equalTo(partyline));
    resource = new ConcreteResource(loc, fname);
    try {
        router.asAdminView().getDetachedFile(resource);
        fail("Should have thrown exception");
    } catch (UnsupportedOperationException ex) {
    // Pass
    }
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 10 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project galley by Commonjava.

the class CacheProviderTCK method lockThenWriteViaTransferSucceedsInSameThread.

@Test
public void lockThenWriteViaTransferSucceedsInSameThread() throws Exception {
    final Location loc = new SimpleLocation("http://foo.com");
    final String path = "my/path.txt";
    final ConcreteResource res = new ConcreteResource(loc, path);
    final CacheProvider cache = getCacheProvider();
    cache.lockWrite(res);
    final Transfer txfr = new Transfer(res, cache, new TestFileEventManager(), new TestTransferDecorator());
    OutputStream out = null;
    try {
        out = txfr.openOutputStream(TransferOperation.UPLOAD);
        IOUtils.write("this is a test", out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}
Also used : TestTransferDecorator(org.commonjava.maven.galley.cache.testutil.TestTransferDecorator) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) TestFileEventManager(org.commonjava.maven.galley.cache.testutil.TestFileEventManager) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)12 Location (org.commonjava.maven.galley.model.Location)11 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)10 Test (org.junit.Test)10 OutputStream (java.io.OutputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 File (java.io.File)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 TransferManager (org.commonjava.maven.galley.TransferManager)1 MemoryPasswordManager (org.commonjava.maven.galley.auth.MemoryPasswordManager)1 FileCacheProvider (org.commonjava.maven.galley.cache.FileCacheProvider)1 TestFileEventManager (org.commonjava.maven.galley.cache.testutil.TestFileEventManager)1 TestTransferDecorator (org.commonjava.maven.galley.cache.testutil.TestTransferDecorator)1 TransportManagerConfig (org.commonjava.maven.galley.config.TransportManagerConfig)1 NoOpFileEventManager (org.commonjava.maven.galley.event.NoOpFileEventManager)1 FileTransport (org.commonjava.maven.galley.filearc.FileTransport)1