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);
}
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();
}
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));
}
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
}
}
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);
}
}
Aggregations