Java Code Examples for org.gradle.util.CollectionUtils#collect()

The following examples show how to use org.gradle.util.CollectionUtils#collect() . 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: CachingModuleVersionRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void resolveAndCacheModuleArtifacts(ComponentMetaData component, ArtifactResolveContext context, BuildableArtifactSetResolveResult result) {
    final CachingModuleSource cachedModuleSource = (CachingModuleSource) component.getSource();
    ModuleArtifactsCache.CachedArtifacts cachedModuleArtifacts = moduleArtifactsCache.getCachedArtifacts(delegate, component.getId(), context.getId());
    BigInteger moduleDescriptorHash = cachedModuleSource.getDescriptorHash();

    if (cachedModuleArtifacts != null) {
        if (!cachePolicy.mustRefreshModuleArtifacts(component.getId(), null, cachedModuleArtifacts.getAgeMillis(),
                cachedModuleSource.isChangingModule(), moduleDescriptorHash.equals(cachedModuleArtifacts.getDescriptorHash()))) {
            Set<ModuleVersionArtifactMetaData> artifactMetaDataSet = CollectionUtils.collect(cachedModuleArtifacts.getArtifacts(), new ArtifactIdToMetaData());
            result.resolved(artifactMetaDataSet);
            return;
        }

        LOGGER.debug("Artifact listing has expired: will perform fresh resolve of '{}' for '{}' in '{}'", context.getDescription(), component.getId(), delegate.getName());
    }

    delegate.resolveModuleArtifacts(component.withSource(cachedModuleSource.getDelegate()), context, result);

    if (result.getFailure() == null) {
        Set<ModuleVersionArtifactIdentifier> artifactIdentifierSet = CollectionUtils.collect(result.getArtifacts(), new ArtifactMetaDataToId());
        moduleArtifactsCache.cacheArtifacts(delegate, component.getId(), context.getId(), moduleDescriptorHash, artifactIdentifierSet);
    }
}
 
Example 2
Source File: ModelPathSuggestionProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<ModelPath> transform(final ModelPath unavailable) {
    Iterable<Suggestion> suggestions = Iterables.transform(availablePaths, new Function<ModelPath, Suggestion>() {
        public Suggestion apply(ModelPath available) {
            int distance = StringUtils.getLevenshteinDistance(unavailable.toString(), available.toString());
            boolean suggest = distance <= Math.min(3, unavailable.toString().length() / 2);
            if (suggest) {
                return new Suggestion(distance, available);
            } else {
                // avoid excess creation of Suggestion objects
                return null;
            }
        }
    });

    suggestions = Iterables.filter(suggestions, REMOVE_NULLS);
    List<Suggestion> sortedSuggestions = CollectionUtils.sort(suggestions);
    return CollectionUtils.collect(sortedSuggestions, Suggestion.EXTRACT_PATH);
}
 
Example 3
Source File: IvyXmlModuleDescriptorParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Map<String, String> populateProperties() {
    HashMap<String, String> properties = new HashMap<String, String>();
    String baseDir = new File(".").getAbsolutePath();
    properties.put("ivy.default.settings.dir", baseDir);
    properties.put("ivy.basedir", baseDir);

    Set<String> propertyNames = CollectionUtils.collect(System.getProperties().entrySet(), new Transformer<String, Map.Entry<Object, Object>>() {
        public String transform(Map.Entry<Object, Object> entry) {
            return entry.getKey().toString();
        }
    });

    for (String property : propertyNames) {
        properties.put(property, System.getProperty(property));
    }
    return properties;
}
 
Example 4
Source File: LocallyAvailableResourceFinderSearchableFileStoreAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public LocallyAvailableResourceFinderSearchableFileStoreAdapter(final FileStoreSearcher<C> fileStore) {
    super(new Transformer<Factory<List<File>>, C>() {
        public Factory<List<File>> transform(final C criterion) {
            return new Factory<List<File>>() {
                public List<File> create() {
                    Set<? extends LocallyAvailableResource> entries = fileStore.search(criterion);
                    return CollectionUtils.collect(entries, new ArrayList<File>(entries.size()), new Transformer<File, LocallyAvailableResource>() {
                        public File transform(LocallyAvailableResource original) {
                            return original.getFile();
                        }
                    });
                }
            };
        }
    });
}
 
Example 5
Source File: ModelPathSuggestionProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public List<ModelPath> transform(final ModelPath unavailable) {
    Iterable<Suggestion> suggestions = Iterables.transform(availablePaths, new Function<ModelPath, Suggestion>() {
        public Suggestion apply(ModelPath available) {
            int distance = StringUtils.getLevenshteinDistance(unavailable.toString(), available.toString());
            boolean suggest = distance <= Math.min(3, unavailable.toString().length() / 2);
            if (suggest) {
                return new Suggestion(distance, available);
            } else {
                // avoid excess creation of Suggestion objects
                return null;
            }
        }
    });

    suggestions = Iterables.filter(suggestions, REMOVE_NULLS);
    List<Suggestion> sortedSuggestions = CollectionUtils.sort(suggestions);
    return CollectionUtils.collect(sortedSuggestions, Suggestion.EXTRACT_PATH);
}
 
Example 6
Source File: MavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected ArtifactResolver createArtifactResolver(ModuleSource moduleSource) {

    if (moduleSource instanceof TimestampedModuleSource) {

        final String timestampedVersion = ((TimestampedModuleSource) moduleSource).getTimestampedVersion();
        Transformer<String, String> patternTransformer = new Transformer<String, String>() {
            public String transform(String original) {
                return original.replaceFirst("\\-\\[revision\\]", "-" + timestampedVersion);
            }
        };
        return new ArtifactResolver(
                CollectionUtils.collect(getIvyPatterns(), patternTransformer),
                CollectionUtils.collect(getArtifactPatterns(), patternTransformer));
    }

    return super.createArtifactResolver(moduleSource);
}
 
Example 7
Source File: CachingModuleVersionRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void localListModuleVersions(DependencyMetaData dependency, BuildableModuleVersionSelectionResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    final ModuleIdentifier moduleId = moduleExtractor.transform(requested);
    ModuleVersionsCache.CachedModuleVersionList cachedModuleVersionList = moduleVersionsCache.getCachedModuleResolution(delegate, moduleId);
    if (cachedModuleVersionList != null) {
        ModuleVersionListing versionList = cachedModuleVersionList.getModuleVersions();
        Set<ModuleVersionIdentifier> versions = CollectionUtils.collect(versionList.getVersions(), new Transformer<ModuleVersionIdentifier, Versioned>() {
            public ModuleVersionIdentifier transform(Versioned original) {
                return new DefaultModuleVersionIdentifier(moduleId, original.getVersion());
            }
        });
        if (cachePolicy.mustRefreshVersionList(moduleId, versions, cachedModuleVersionList.getAgeMillis())) {
            LOGGER.debug("Version listing in dynamic revision cache is expired: will perform fresh resolve of '{}' in '{}'", requested, delegate.getName());
        } else {
            if (cachedModuleVersionList.getAgeMillis() == 0) {
                // Verified since the start of this build, assume still missing
                result.listed(versionList);
            } else {
                // Was missing last time we checked
                result.probablyListed(versionList);
            }
        }
    }
}
 
Example 8
Source File: GenerateBuildDashboard.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Set<Report> getEnabledInputReports() {
    Set<NamedDomainObjectSet<? extends Report>> enabledReportSets = CollectionUtils.collect(aggregated, new Transformer<NamedDomainObjectSet<? extends Report>, Reporting<? extends ReportContainer<?>>>() {
        public NamedDomainObjectSet<? extends Report> transform(Reporting<? extends ReportContainer<?>> reporting) {
            return reporting.getReports().getEnabled();
        }
    });
    return new LinkedHashSet<Report>(CollectionUtils.flattenCollections(Report.class, enabledReportSets));
}
 
Example 9
Source File: TaskReportContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Input
public SortedSet<String> getEnabledReportNames() {
    return CollectionUtils.collect(getEnabled(), new TreeSet<String>(), new Transformer<String, Report>() {
        public String transform(Report report) {
            return report.getName();
        }
    });        
}
 
Example 10
Source File: ModelRegistryDslHelperStatementGenerator.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addCreator(String path, ClosureExpression creator, Set<String> referencedPaths) {
    VariableExpression subject = new VariableExpression("modelRegistryHelper");
    List<Expression> pathValueExpressions = CollectionUtils.collect((Iterable<String>)referencedPaths, new Transformer<Expression, String>() {
        public Expression transform(String s) {
            return new ConstantExpression(s);
        }
    });

    ArgumentListExpression arguments = new ArgumentListExpression(new ConstantExpression(path), creator, new ListExpression(pathValueExpressions));
    MethodCallExpression methodCallExpression = new MethodCallExpression(subject, "addCreator", arguments);
    generatedStatements.add(new ExpressionStatement(methodCallExpression));
}
 
Example 11
Source File: NativeBinaryResolveResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<NativeDependencySet> getAllResults() {
    return CollectionUtils.collect(getAllResolutions(), new Transformer<NativeDependencySet, NativeBinaryRequirementResolveResult>() {
        public NativeDependencySet transform(NativeBinaryRequirementResolveResult original) {
            return original.getNativeDependencySet();
        }
    });
}
 
Example 12
Source File: GenerateBuildDashboard.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Set<Report> getEnabledInputReports() {
    Set<NamedDomainObjectSet<? extends Report>> enabledReportSets = CollectionUtils.collect(aggregated, new Transformer<NamedDomainObjectSet<? extends Report>, Reporting<? extends ReportContainer<?>>>() {
        public NamedDomainObjectSet<? extends Report> transform(Reporting<? extends ReportContainer<?>> reporting) {
            return reporting.getReports().getEnabled();
        }
    });
    return new LinkedHashSet<Report>(CollectionUtils.flattenCollections(Report.class, enabledReportSets));
}
 
Example 13
Source File: ExternalResourceResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<String> getIvyPatterns() {
    return CollectionUtils.collect(ivyPatterns, new Transformer<String, ResourcePattern>() {
        public String transform(ResourcePattern original) {
            return original.getPattern();
        }
    });
}
 
Example 14
Source File: PlayRunAdapterV23X.java    From playframework with Apache License 2.0 5 votes vote down vote up
@Override
protected ClassLoader createAssetsClassLoader(File assetsJar, Iterable<File> assetsDirs, ClassLoader classLoader) {
    List<AssetsClassLoader.AssetDir> assetDirs = CollectionUtils.collect(assetsDirs, file -> {
        // TODO: This prefix shouldn't be hardcoded
        return new AssetsClassLoader.AssetDir("public", file);
    });
    return new AssetsClassLoader(classLoader, assetDirs);
}
 
Example 15
Source File: TaskReportContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Input
public SortedSet<String> getEnabledReportNames() {
    return CollectionUtils.collect(getEnabled(), new TreeSet<String>(), new Transformer<String, Report>() {
        public String transform(Report report) {
            return report.getName();
        }
    });        
}
 
Example 16
Source File: MavenProjectsCreator.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, PlexusConfigurationException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
    //using jarjar for maven3 classes affects the contents of the effective pom
    //references to certain Maven standard plugins contain jarjar in the fqn
    //not sure if this is a problem.
    ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration()
            .setClassWorld(new ClassWorld("plexus.core", ClassWorld.class.getClassLoader()))
            .setName("mavenCore");

    DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
    ProjectBuilder builder = container.lookup(ProjectBuilder.class);
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    final Properties properties = new Properties();
    properties.putAll(SystemProperties.asMap());
    executionRequest.setSystemProperties(properties);
    MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
    populator.populateFromSettings(executionRequest, settings);
    populator.populateDefaults(executionRequest);
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.setProcessPlugins(false);
    MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
    Set<MavenProject> reactorProjects = new LinkedHashSet<MavenProject>();

    //TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
    //the converter should not depend on the order of reactor projects.
    //we should add coverage for nested multi-project builds with multiple parents.
    reactorProjects.add(mavenProject);
    List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
    CollectionUtils.collect(allProjects, reactorProjects, new Transformer<MavenProject, ProjectBuildingResult>() {
        public MavenProject transform(ProjectBuildingResult original) {
            return original.getProject();
        }
    });

    MavenExecutionResult result = new DefaultMavenExecutionResult();
    result.setProject(mavenProject);
    RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
    session.setCurrentProject(mavenProject);

    return reactorProjects;
}
 
Example 17
Source File: EscapeUserArgs.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public List<String> transform(List<String> args) {
    return CollectionUtils.collect(args, this);
}
 
Example 18
Source File: TaskReportContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@OutputDirectories
public Set<File> getEnabledDirectoryReportDestinations() {
    return CollectionUtils.collect(CollectionUtils.filter(getEnabled(), IS_DIRECTORY_OUTPUT_TYPE), toFile);
}
 
Example 19
Source File: CachingModuleComponentRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void maybeCache(ComponentResolveMetaData component, BuildableArtifactSetResolveResult result, CachingModuleSource moduleSource, String contextId) {
    if (result.getFailure() == null) {
        Set<ModuleComponentArtifactIdentifier> artifactIdentifierSet = CollectionUtils.collect(result.getArtifacts(), new ArtifactMetaDataToId());
        moduleArtifactsCache.cacheArtifacts(delegate, component.getId(), contextId, moduleSource.getDescriptorHash(), artifactIdentifierSet);
    }
}
 
Example 20
Source File: MavenProjectsCreator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, PlexusConfigurationException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
    //using jarjar for maven3 classes affects the contents of the effective pom
    //references to certain Maven standard plugins contain jarjar in the fqn
    //not sure if this is a problem.
    ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration()
            .setClassWorld(new ClassWorld("plexus.core", ClassWorld.class.getClassLoader()))
            .setName("mavenCore");

    DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
    ProjectBuilder builder = container.lookup(ProjectBuilder.class);
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    final Properties properties = new Properties();
    properties.putAll(SystemProperties.asMap());
    executionRequest.setSystemProperties(properties);
    MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
    populator.populateFromSettings(executionRequest, settings);
    populator.populateDefaults(executionRequest);
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.setProcessPlugins(false);
    MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
    Set<MavenProject> reactorProjects = new LinkedHashSet<MavenProject>();

    //TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
    //the converter should not depend on the order of reactor projects.
    //we should add coverage for nested multi-project builds with multiple parents.
    reactorProjects.add(mavenProject);
    List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
    CollectionUtils.collect(allProjects, reactorProjects, new Transformer<MavenProject, ProjectBuildingResult>() {
        public MavenProject transform(ProjectBuildingResult original) {
            return original.getProject();
        }
    });

    MavenExecutionResult result = new DefaultMavenExecutionResult();
    result.setProject(mavenProject);
    RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
    session.setCurrentProject(mavenProject);

    return reactorProjects;
}