org.gradle.internal.Factory Java Examples

The following examples show how to use org.gradle.internal.Factory. 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 vote down vote up
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: LanguageBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void apply(final Project target) {
    target.getExtensions().create("sources", DefaultProjectSourceSet.class, instantiator);
    final BinaryContainer binaries = target.getExtensions().create("binaries", DefaultBinaryContainer.class, instantiator);

    modelRules.register("binaries", BinaryContainer.class, new Factory<BinaryContainer>() {
        public BinaryContainer create() {
            return binaries;
        }
    });

    binaries.withType(BinaryInternal.class).all(new Action<BinaryInternal>() {
        public void execute(BinaryInternal binary) {
            Task binaryLifecycleTask = target.task(binary.getNamingScheme().getLifecycleTaskName());
            binaryLifecycleTask.setGroup(BUILD_GROUP);
            binaryLifecycleTask.setDescription(String.format("Assembles %s.", binary));
            binary.setLifecycleTask(binaryLifecycleTask);
        }
    });
}
 
Example #3
Source File: DownloadingRepositoryArtifactCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public LocallyAvailableExternalResource downloadAndCacheArtifactFile(final ModuleVersionArtifactMetaData artifact, ExternalResourceDownloader resourceDownloader, final ExternalResource resource) throws IOException {
    final File tmpFile = temporaryFileProvider.createTemporaryFile("gradle_download", "bin");
    try {
        resourceDownloader.download(resource, tmpFile);
        return cacheLockingManager.useCache(String.format("Store %s", artifact), new Factory<LocallyAvailableExternalResource>() {
            public LocallyAvailableExternalResource create() {
                LocallyAvailableResource cachedResource = fileStore.move(artifact, tmpFile);
                File fileInFileStore = cachedResource.getFile();
                ExternalResourceMetaData metaData = resource.getMetaData();
                artifactUrlCachedResolutionIndex.store(metaData.getLocation(), fileInFileStore, metaData);
                return new DefaultLocallyAvailableExternalResource(resource.getName(), cachedResource, metaData);
            }
        });
    } finally {
        tmpFile.delete();
    }
}
 
Example #4
Source File: DefaultCacheAccess.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #5
Source File: TransientConfigurationResultsBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TransientConfigurationResults load(final ResolvedContentsMapping mapping) {
    synchronized (lock) {
        return cache.load(new Factory<TransientConfigurationResults>() {
            public TransientConfigurationResults create() {
                try {
                    return binaryData.read(new BinaryStore.ReadAction<TransientConfigurationResults>() {
                        public TransientConfigurationResults read(Decoder decoder) throws IOException {
                            return deserialize(decoder, mapping);
                        }
                    });
                } finally {
                    try {
                        binaryData.close();
                    } catch (IOException e) {
                        throw throwAsUncheckedException(e);
                    }
                }
            }
        });
    }
}
 
Example #6
Source File: FileResourceConnector.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #7
Source File: LoggingServiceRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Factory<LoggingManagerInternal> createLoggingManagerFactory() {
    OutputEventRenderer renderer = get(OutputEventRenderer.class);
    // Don't configure anything
    return new DefaultLoggingManagerFactory(renderer,
            renderer,
            new NoOpLoggingSystem(),
            new NoOpLoggingSystem());
}
 
Example #8
Source File: MavenPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Inject
public MavenPlugin(Factory<LoggingManagerInternal> loggingManagerFactory, FileResolver fileResolver,
                   ProjectPublicationRegistry publicationRegistry, ProjectConfigurationActionContainer configurationActionContainer) {
    this.loggingManagerFactory = loggingManagerFactory;
    this.fileResolver = fileResolver;
    this.publicationRegistry = publicationRegistry;
    this.configurationActionContainer = configurationActionContainer;
}
 
Example #9
Source File: DefaultServiceRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> Factory<T> getFactory(Class<T> type) {
    synchronized (lock) {
        if (closed) {
            throw new IllegalStateException(String.format("Cannot locate factory for objects of type %s, as %s has been closed.", format(type), displayName));
        }

        DefaultLookupContext context = new DefaultLookupContext();
        ServiceProvider factory = allServices.getFactory(context, type);
        if (factory != null) {
            return (Factory<T>) factory.get();
        }

        throw new UnknownServiceException(type, String.format("No factory for objects of type %s available in %s.", format(type), displayName));
    }
}
 
Example #10
Source File: ForkingGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public GradleHandle doStart() {
    return createGradleHandle(getResultAssertion(), getDefaultCharacterEncoding(), new Factory<ExecHandleBuilder>() {
        public ExecHandleBuilder create() {
            return createExecHandleBuilder();
        }
    }).start();
}
 
Example #11
Source File: TestGlobalScopeServices.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Factory<LoggingManagerInternal> createLoggingManagerFactory() {
    return new Factory<LoggingManagerInternal>() {
        public LoggingManagerInternal create() {
            return new NoOpLoggingManager();
        }
    };
}
 
Example #12
Source File: DefaultExternalResourceRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void doPut(final byte[] source, URI destination) throws IOException {
    LOGGER.debug("Attempting to put resource {}.", destination);
    uploader.upload(new Factory<InputStream>() {
        public InputStream create() {
            return new ByteArrayInputStream(source);
        }
    }, (long)source.length, destination);
}
 
Example #13
Source File: InProcessGradleExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected GradleHandle doStart() {
    return new ForkingGradleHandle(getResultAssertion(), getDefaultCharacterEncoding(), new Factory<JavaExecHandleBuilder>() {
        public JavaExecHandleBuilder create() {
            JavaExecHandleBuilder builder = new JavaExecHandleBuilder(TestFiles.resolver());
            builder.workingDir(getWorkingDir());
            Set<File> classpath = new DefaultModuleRegistry().getFullClasspath();
            builder.classpath(classpath);
            builder.setMain(Main.class.getName());
            builder.args(getAllArgs());
            return builder;
        }
    }).start();
}
 
Example #14
Source File: SingleMessageLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <T> T whileDisabled(Factory<T> factory) {
    ENABLED.set(false);
    try {
        return factory.create();
    } finally {
        ENABLED.set(true);
    }
}
 
Example #15
Source File: DefaultJarSnapshotCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<File, JarSnapshot> getJarSnapshots(final Map<File, byte[]> jarHashes) {
    return cache.getCacheAccess().useCache("loading jar snapshots", new Factory<Map<File, JarSnapshot>>() {
        public Map<File, JarSnapshot> create() {
            final Map<File, JarSnapshot> out = new HashMap<File, JarSnapshot>();
            for (Map.Entry<File, byte[]> entry : jarHashes.entrySet()) {
                JarSnapshot snapshot = new JarSnapshot(cache.getCache().get(entry.getValue()));
                out.put(entry.getKey(), snapshot);
            }
            return out;
        }
    });
}
 
Example #16
Source File: CacheBackedTaskHistoryRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private TaskHistory loadHistory(final TaskInternal task) {
    return cacheAccess.useCache("Load task history", new Factory<TaskHistory>() {
        public TaskHistory create() {
            ClassLoader original = serializer.getClassLoader();
            serializer.setClassLoader(task.getClass().getClassLoader());
            try {
                TaskHistory history = taskHistoryCache.get(task.getPath());
                return history == null ? new TaskHistory() : history;
            } finally {
                serializer.setClassLoader(original);
            }
        }
    });
}
 
Example #17
Source File: InMemoryCacheFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #18
Source File: DefaultDeployerFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultDeployerFactory(MavenFactory mavenFactory, Factory<LoggingManagerInternal> loggingManagerFactory, FileResolver fileResolver, MavenPomMetaInfoProvider pomMetaInfoProvider,
                              ConfigurationContainer configurationContainer, Conf2ScopeMappingContainer scopeMapping) {
    this.mavenFactory = mavenFactory;
    this.loggingManagerFactory = loggingManagerFactory;
    this.fileResolver = fileResolver;
    this.pomMetaInfoProvider = pomMetaInfoProvider;
    this.configurationContainer = configurationContainer;
    this.scopeMapping = scopeMapping;
}
 
Example #19
Source File: DefaultJarSnapshotCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JarSnapshot get(byte[] key, final Factory<JarSnapshot> factory) {
    return new JarSnapshot(cache.get(key, new Factory<JarSnapshotData>() {
        public JarSnapshotData create() {
            return factory.create().getData();
        }
    }));
}
 
Example #20
Source File: AnnotationProcessingTaskFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Factory<Action<Task>> createActionFactory(final Method method, final Class<?>[] parameterTypes) {
    return new Factory<Action<Task>>() {
        public Action<Task> create() {
            if (parameterTypes.length == 1) {
                return new IncrementalTaskAction(method);
            } else {
                return new StandardTaskAction(method);
            }
        }
    };
}
 
Example #21
Source File: DefaultCacheAccess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T longRunningOperation(String operationDisplayName, Factory<? extends T> action) {
    boolean wasEnded = startLongRunningOperation(operationDisplayName);
    try {
        return action.create();
    } finally {
        finishLongRunningOperation(wasEnded);
    }
}
 
Example #22
Source File: AbstractFileAccess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T readFile(final Callable<? extends T> action) throws LockTimeoutException, FileIntegrityViolationException {
    return readFile(new Factory<T>() {
        public T create() {
            try {
                return action.call();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    });
}
 
Example #23
Source File: InMemoryCachingPluginResolutionServiceClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #24
Source File: ForkingTestClassProcessor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ForkingTestClassProcessor(Factory<WorkerProcessBuilder> workerFactory, WorkerTestClassProcessorFactory processorFactory, JavaForkOptions options, Iterable<File> classPath, Action<WorkerProcessBuilder> buildConfigAction) {
    this.workerFactory = workerFactory;
    this.processorFactory = processorFactory;
    this.options = options;
    this.classPath = classPath;
    this.buildConfigAction = buildConfigAction;
}
 
Example #25
Source File: TestGlobalScopeServices.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Factory<LoggingManagerInternal> createLoggingManagerFactory() {
    return new Factory<LoggingManagerInternal>() {
        public LoggingManagerInternal create() {
            return new NoOpLoggingManager();
        }
    };
}
 
Example #26
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Project childrenDependOnMe() {
    DeprecationLogger.nagUserOfDiscontinuedMethod("Project.childrenDependOnMe()");
    DeprecationLogger.whileDisabled(new Factory<Void>() {
        public Void create() {
            for (Project project : childProjects.values()) {
                project.dependsOn(getPath(), false);
            }
            return null;
        }
    });

    return this;
}
 
Example #27
Source File: CachedStoreFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #28
Source File: ModuleMappingPluginResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PluginResolution resolve(final PluginRequest pluginRequest) {
    final Dependency dependency = mapper.map(pluginRequest, dependencyResolutionServices.getDependencyHandler());
    if (dependency == null) {
        return null;
    } else {
        // TODO the dependency resolution config of this guy needs to be externalized
        Factory<ClassPath> classPathFactory = new DependencyResolvingClasspathProvider(dependencyResolutionServices, dependency, repositoriesConfigurer);

        return new ClassPathPluginResolution(instantiator, pluginRequest.getId(), classPathFactory);
    }
}
 
Example #29
Source File: ProgressLoggingExternalResourceUploader.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void upload(final Factory<InputStream> source, final Long contentLength, URI destination) throws IOException {
    final ResourceOperation uploadOperation = createResourceOperation(destination.toString(), ResourceOperation.Type.upload, getClass(), contentLength);

    try {
        delegate.upload(new Factory<InputStream>() {
            public InputStream create() {
                return new ProgressLoggingInputStream(source.create(), uploadOperation);
            }
        }, contentLength, destination);
    } finally {
        uploadOperation.completed();
    }
}
 
Example #30
Source File: CacheBackedTaskHistoryRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public FileCollectionSnapshot getOutputFilesSnapshot() {
    if (outputFilesSnapshot == null) {
        outputFilesSnapshot = cacheAccess.useCache("fetch output files", new Factory<FileCollectionSnapshot>() {
            public FileCollectionSnapshot create() {
                return snapshotRepository.get(outputFilesSnapshotId);
            }
        });
    }
    return outputFilesSnapshot;
}