Java Code Examples for org.gradle.internal.Factory#create()
The following examples show how to use
org.gradle.internal.Factory#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SftpResourceUploader.java From pushfish-android with BSD 2-Clause "Simplified" License | 7 votes |
public void upload(Factory<InputStream> sourceFactory, Long contentLength, URI destination) throws IOException { LockableSftpClient client = sftpClientFactory.createSftpClient(destination, credentials); try { ChannelSftp channel = client.getSftpClient(); ensureParentDirectoryExists(channel, destination); InputStream sourceStream = sourceFactory.create(); try { channel.put(sourceStream, destination.getPath()); } finally { sourceStream.close(); } } catch (com.jcraft.jsch.SftpException e) { throw new SftpException(String.format("Could not write to resource '%s'.", destination), e); } finally { sftpClientFactory.releaseSftpClient(client); } }
Example 2
Source File: DefaultCacheAccess.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public <T> T useCache(String operationDisplayName, Factory<? extends T> factory) { if (lockOptions != null && lockOptions.getMode() == FileLockManager.LockMode.Shared) { throw new UnsupportedOperationException("Not implemented yet."); } takeOwnership(operationDisplayName); boolean wasStarted = false; try { wasStarted = onStartWork(); return factory.create(); } finally { lock.lock(); try { try { if (wasStarted) { onEndWork(); } } finally { releaseOwnership(); } } finally { lock.unlock(); } } }
Example 3
Source File: DefaultCacheAccess.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public <T> T useCache(String operationDisplayName, Factory<? extends T> factory) { if (lockOptions != null && lockOptions.getMode() == FileLockManager.LockMode.Shared) { throw new UnsupportedOperationException("Not implemented yet."); } takeOwnership(operationDisplayName); boolean wasStarted = false; try { wasStarted = onStartWork(); return factory.create(); } finally { lock.lock(); try { try { if (wasStarted) { onEndWork(); } } finally { releaseOwnership(); } } finally { lock.unlock(); } } }
Example 4
Source File: FileResourceConnector.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void upload(Factory<InputStream> source, Long contentLength, URI destination) throws IOException { File target = getFile(destination); if (!target.canWrite()) { target.delete(); } // if target is writable, the copy will overwrite it without requiring a delete GFileUtils.mkdirs(target.getParentFile()); FileOutputStream fileOutputStream = new FileOutputStream(target); try { InputStream sourceInputStream = source.create(); try { IOUtils.copyLarge(sourceInputStream, fileOutputStream); } finally { sourceInputStream.close(); } } finally { fileOutputStream.close(); } }
Example 5
Source File: MinimalPersistentCache.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public V get(final K key, Factory<V> factory) { V cached = cacheAccess.useCache("Loading " + cacheName, new Factory<V>() { public V create() { return cache.get(key); } }); if (cached != null) { return cached; } final V value = factory.create(); //don't synchronize value creation //we could potentially avoid creating value that is already being created by a different thread. cacheAccess.useCache("Storing " + cacheName, new Runnable() { public void run() { cache.put(key, value); } }); return value; }
Example 6
Source File: InMemoryCacheFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T useCache(String operationDisplayName, Factory<? extends T> action) { assertNotClosed(); // The contract of useCache() means we have to provide some basic synchronization. synchronized (this) { return action.create(); } }
Example 7
Source File: Synchronizer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T synchronize(Factory<T> factory) { lock.lock(); try { return factory.create(); } finally { lock.unlock(); } }
Example 8
Source File: SingleMessageLogger.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public static <T> T whileDisabled(Factory<T> factory) { ENABLED.set(false); try { return factory.create(); } finally { ENABLED.set(true); } }
Example 9
Source File: DefaultCacheAccess.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T longRunningOperation(String operationDisplayName, Factory<? extends T> action) { boolean wasEnded = startLongRunningOperation(operationDisplayName); try { return action.create(); } finally { finishLongRunningOperation(wasEnded); } }
Example 10
Source File: DefaultCacheAccess.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T longRunningOperation(String operationDisplayName, Factory<? extends T> action) { boolean wasEnded = startLongRunningOperation(operationDisplayName); try { return action.create(); } finally { finishLongRunningOperation(wasEnded); } }
Example 11
Source File: DefaultToolingImplementationLoader.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters) { LOGGER.debug("Using tooling provider from {}", distribution.getDisplayName()); ClassLoader classLoader = createImplementationClassLoader(distribution, progressLoggerFactory, connectionParameters.getGradleUserHomeDir()); ServiceLocator serviceLocator = new ServiceLocator(classLoader); try { Factory<ConnectionVersion4> factory = serviceLocator.findFactory(ConnectionVersion4.class); if (factory == null) { return new NoToolingApiConnection(distribution); } // ConnectionVersion4 is a part of the protocol and cannot be easily changed. ConnectionVersion4 connection = factory.create(); ProtocolToModelAdapter adapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider()); ModelMapping modelMapping = new ModelMapping(); // Adopting the connection to a refactoring friendly type that the consumer owns AbstractConsumerConnection adaptedConnection; if (connection instanceof ModelBuilder && connection instanceof InternalBuildActionExecutor) { adaptedConnection = new ActionAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder) { adaptedConnection = new ModelBuilderBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof BuildActionRunner) { adaptedConnection = new BuildActionRunnerBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalConnection) { adaptedConnection = new InternalConnectionBackedConsumerConnection(connection, modelMapping, adapter); } else { adaptedConnection = new ConnectionVersion4BackedConsumerConnection(connection, modelMapping, adapter); } adaptedConnection.configure(connectionParameters); return adaptedConnection; } catch (UnsupportedVersionException e) { throw e; } catch (Throwable t) { throw new GradleConnectionException(String.format("Could not create an instance of Tooling API implementation using the specified %s.", distribution.getDisplayName()), t); } }
Example 12
Source File: Synchronizer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public <T> T synchronize(Factory<T> factory) { lock.lock(); try { return factory.create(); } finally { lock.unlock(); } }
Example 13
Source File: SingleMessageLogger.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public static <T> T whileDisabled(Factory<T> factory) { ENABLED.set(false); try { return factory.create(); } finally { ENABLED.set(true); } }
Example 14
Source File: CachedStoreFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public T load(Factory<T> createIfNotPresent) { T out = cache.getIfPresent(id); if (out != null) { stats.readFromCache(); return out; } long start = System.currentTimeMillis(); T value = createIfNotPresent.create(); stats.readFromDisk(start); cache.put(id, value); return value; }
Example 15
Source File: PersistentCachingPluginResolutionServiceClient.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private <K, V extends Response<?>> V fetch(String operationName, final PersistentIndexedCache<K, V> cache, final K key, Factory<V> factory) { final V value = factory.create(); if (value.isError()) { return value; } cacheAccess.useCache(operationName + " - write", new Runnable() { public void run() { cache.put(key, value); } }); return value; }
Example 16
Source File: InMemoryCachingPluginResolutionServiceClient.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private <K, V> Response<V> getResponse(Key<K> key, Cache<Key<K>, Response<V>> cache, Factory<Response<V>> responseFactory, Transformer<Key<K>, ? super Response<V>> keyGenerator) { Response<V> response = key == null ? null : cache.getIfPresent(key); if (response != null) { return response; } else { response = responseFactory.create(); if (!response.isError()) { Key<K> actualKey = keyGenerator.transform(response); cache.put(actualKey, response); } return response; } }
Example 17
Source File: DefaultFileLockManager.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public <T> T readFile(Factory<? extends T> action) throws LockTimeoutException, FileIntegrityViolationException { assertOpenAndIntegral(); return action.create(); }
Example 18
Source File: ExternalResourceMetaDataCompare.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public static boolean isDefinitelyUnchanged(@Nullable ExternalResourceMetaData local, Factory<ExternalResourceMetaData> remoteFactory) { if (local == null) { return false; } String localEtag = local.getEtag(); Date localLastModified = local.getLastModified(); if (localEtag == null && localLastModified == null) { return false; } long localContentLength = local.getContentLength(); if (localEtag == null && localContentLength < 1) { return false; } // We have enough local data to make a comparison, get the remote metadata ExternalResourceMetaData remote = remoteFactory.create(); if (remote == null) { return false; } String remoteEtag = remote.getEtag(); if (localEtag != null && remoteEtag != null) { return localEtag.equals(remoteEtag); } Date remoteLastModified = remote.getLastModified(); if (remoteLastModified == null) { return false; } long remoteContentLength = remote.getContentLength(); //noinspection SimplifiableIfStatement if (remoteContentLength < 1) { return false; } return localContentLength == remoteContentLength && remoteLastModified.equals(localLastModified); }
Example 19
Source File: InMemoryCacheFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public <T> T longRunningOperation(String operationDisplayName, Factory<? extends T> action) { return action.create(); }
Example 20
Source File: ExternalResourceMetaDataCompare.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public static boolean isDefinitelyUnchanged(@Nullable ExternalResourceMetaData local, Factory<ExternalResourceMetaData> remoteFactory) { if (local == null) { return false; } String localEtag = local.getEtag(); Date localLastModified = local.getLastModified(); if (localEtag == null && localLastModified == null) { return false; } long localContentLength = local.getContentLength(); if (localEtag == null && localContentLength < 1) { return false; } // We have enough local data to make a comparison, get the remote metadata ExternalResourceMetaData remote = remoteFactory.create(); if (remote == null) { return false; } String remoteEtag = remote.getEtag(); if (localEtag != null && remoteEtag != null) { return localEtag.equals(remoteEtag); } Date remoteLastModified = remote.getLastModified(); if (remoteLastModified == null) { return false; } long remoteContentLength = remote.getContentLength(); //noinspection SimplifiableIfStatement if (remoteContentLength < 1) { return false; } return localContentLength == remoteContentLength && remoteLastModified.equals(localLastModified); }