@Override public void create(final Action<? super T> action) { state.assertCanMutate(); String name = String.valueOf(modelNode.getLinkCount(ModelNodes.withType(elementType))); ModelPath childPath = modelNode.getPath().child(name); final ModelRuleDescriptor descriptor = this.descriptor.append("create()"); NodeInitializer nodeInitializer = creatorStrategy.initializer(elementType, Specs.<ModelType<?>>satisfyAll()); ModelRegistration registration = ModelRegistrations.of(childPath, nodeInitializer) .descriptor(descriptor) .action(ModelActionRole.Initialize, NoInputsModelAction.of(ModelReference.of(childPath, elementType), descriptor, action)) .build(); modelNode.addLink(registration); }
private ClassPath resolvePluginDependencies(final PluginUseMetaData metadata) { DependencyResolutionServices resolution = dependencyResolutionServicesFactory.create(); RepositoryHandler repositories = resolution.getResolveRepositoryHandler(); final String repoUrl = metadata.implementation.get("repo"); repositories.maven(new Action<MavenArtifactRepository>() { public void execute(MavenArtifactRepository mavenArtifactRepository) { mavenArtifactRepository.setUrl(repoUrl); } }); Dependency dependency = resolution.getDependencyHandler().create(metadata.implementation.get("gav")); ConfigurationContainerInternal configurations = (ConfigurationContainerInternal) resolution.getConfigurationContainer(); ConfigurationInternal configuration = configurations.detachedConfiguration(dependency); try { Set<File> files = configuration.getResolvedConfiguration().getFiles(Specs.satisfyAll()); return new DefaultClassPath(files); } catch (ResolveException e) { throw new DependencyResolutionException("Failed to resolve all plugin dependencies from " + repoUrl, e.getCause()); } }
public Spec<FileTreeElement> createExcludeSpec(PatternSet patternSet) { List<Spec<FileTreeElement>> allExcludeSpecs = new ArrayList<Spec<FileTreeElement>>(2 + patternSet.getExcludeSpecs().size()); if (!patternSet.getExcludes().isEmpty()) { allExcludeSpecs.add(createSpec(patternSet.getExcludes(), false, patternSet.isCaseSensitive())); } List<String> defaultExcludes = Arrays.asList(DirectoryScanner.getDefaultExcludes()); if (!defaultExcludes.isEmpty()) { allExcludeSpecs.add(createSpec(defaultExcludes, false, patternSet.isCaseSensitive())); } allExcludeSpecs.addAll(patternSet.getExcludeSpecs()); if (allExcludeSpecs.isEmpty()) { return Specs.satisfyNone(); } else { return Specs.union(allExcludeSpecs); } }
private void collectArtifacts(Configuration configuration, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) { Set<ResolvedArtifact> allArtifacts; if (!extraModelInfo.getMode().equals(STANDARD)) { allArtifacts = configuration.getResolvedConfiguration().getLenientConfiguration().getArtifacts( Specs.satisfyAll()); } else { allArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts(); } for (ResolvedArtifact artifact : allArtifacts) { ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); List<ResolvedArtifact> moduleArtifacts = artifacts.get(id); if (moduleArtifacts == null) { moduleArtifacts = Lists.newArrayList(); artifacts.put(id, moduleArtifacts); } if (!moduleArtifacts.contains(artifact)) { moduleArtifacts.add(artifact); } } }
private void copyFileDependencies(Configuration configuration, String toPrint, Project project, boolean isPackagerJarToBeAdded, final File libDir, Set<String> foundLibs) { project.getLogger().info("Copying defined " + toPrint + "-dependency-files..."); // inside "getFiles" all non-maven dependencies (like packager.jar) will be available configuration.getResolvedConfiguration().getFiles(Specs.SATISFIES_ALL).forEach(someFile -> { try{ Path artifactPath = someFile.toPath(); String artifactFileName = artifactPath.getFileName().toString(); if( "packager.jar".equals(artifactFileName) && !isPackagerJarToBeAdded ){ project.getLogger().info("Skipped adding packager.jar."); return; } // add this lib only, when not already present (could happen on file-dependencies ... which behaves different from maven-model) if( !foundLibs.contains(artifactFileName) ){ Files.copy(artifactPath, libDir.toPath().resolve(artifactFileName), StandardCopyOption.REPLACE_EXISTING); foundLibs.add(artifactFileName); } } catch(IOException ex){ project.getLogger().warn("Couldn't copy dependency " + someFile.getName(), ex); } }); }
/** * Recursive, includes unsuccessfully resolved artifacts * * @param dependencySpec dependency spec */ public Set<ResolvedArtifact> getAllArtifacts(Spec<? super Dependency> dependencySpec) { //this is not very nice might be good enough until we get rid of ResolvedConfiguration and friends //avoid traversing the graph causing the full ResolvedDependency graph to be loaded for the most typical scenario if (dependencySpec == Specs.SATISFIES_ALL) { return results.getArtifacts(); } CachingDirectedGraphWalker<ResolvedDependency, ResolvedArtifact> walker = new CachingDirectedGraphWalker<ResolvedDependency, ResolvedArtifact>(new ResolvedDependencyArtifactsGraph()); Set<ResolvedDependency> firstLevelModuleDependencies = getFirstLevelModuleDependencies(dependencySpec); Set<ResolvedArtifact> artifacts = new LinkedHashSet<ResolvedArtifact>(); for (ResolvedDependency resolvedDependency : firstLevelModuleDependencies) { artifacts.addAll(resolvedDependency.getParentArtifacts(results.more().getRoot())); walker.add(resolvedDependency); } artifacts.addAll(walker.findValues()); return artifacts; }
private void configureTestTasks(Set<Test> allTestTasksToRun) { for (Test task : allTestTasksToRun) { task.setIgnoreFailures(true); task.getFilter().setFailOnNoMatchingTests(false); task.getOutputs().upToDateWhen(Specs.SATISFIES_NONE); } }
/** * Recursive, includes unsuccessfully resolved artifacts * * @param dependencySpec dependency spec */ private void visitArtifacts(Spec<? super Dependency> dependencySpec, AttributeContainerInternal requestedAttributes, SelectedArtifactResults artifactResults, SelectedFileDependencyResults fileDependencyResults, ArtifactVisitor visitor) { ArtifactVisitor transformingVisitor = artifactTransformer.visitor(visitor, requestedAttributes); //this is not very nice might be good enough until we get rid of ResolvedConfiguration and friends //avoid traversing the graph causing the full ResolvedDependency graph to be loaded for the most typical scenario if (dependencySpec == Specs.SATISFIES_ALL) { if (transformingVisitor.includeFiles()) { fileDependencyResults.getFiles().visit(transformingVisitor); } artifactResults.getArtifacts().visit(transformingVisitor); return; } if (transformingVisitor.includeFiles()) { for (Map.Entry<FileCollectionDependency, ResolvedArtifactSet> entry: fileDependencyResults.getFirstLevelFiles().entrySet()) { if (dependencySpec.isSatisfiedBy(entry.getKey())) { entry.getValue().visit(transformingVisitor); } } } CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact> walker = new CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact>(new ResolvedDependencyArtifactsGraph(transformingVisitor, fileDependencyResults)); DependencyGraphNodeResult rootNode = loadTransientGraphResults(artifactResults).getRootNode(); for (DependencyGraphNodeResult node : getFirstLevelNodes(dependencySpec)) { node.getArtifactsForIncomingEdge(rootNode).visit(transformingVisitor); walker.add(node); } walker.findValues(); }
public void resolveGraph(ConfigurationInternal configuration, ResolverResults results) { List<ResolutionAwareRepository> resolutionAwareRepositories = CollectionUtils.collect(repositories, Transformers.cast(ResolutionAwareRepository.class)); StoreSet stores = storeFactory.createStoreSet(); BinaryStore oldModelStore = stores.nextBinaryStore(); Store<TransientConfigurationResults> oldModelCache = stores.oldModelCache(); TransientConfigurationResultsBuilder oldTransientModelBuilder = new TransientConfigurationResultsBuilder(oldModelStore, oldModelCache); DefaultResolvedConfigurationBuilder oldModelBuilder = new DefaultResolvedConfigurationBuilder(oldTransientModelBuilder); ResolvedConfigurationDependencyGraphVisitor oldModelVisitor = new ResolvedConfigurationDependencyGraphVisitor(oldModelBuilder); BinaryStore newModelStore = stores.nextBinaryStore(); Store<ResolvedComponentResult> newModelCache = stores.newModelCache(); StreamingResolutionResultBuilder newModelBuilder = new StreamingResolutionResultBuilder(newModelStore, newModelCache); ResolvedLocalComponentsResultGraphVisitor localComponentsVisitor = new ResolvedLocalComponentsResultGraphVisitor(); DefaultResolvedArtifactsBuilder artifactsBuilder = new DefaultResolvedArtifactsBuilder(buildProjectDependencies); FileDependencyCollectingGraphVisitor fileDependencyVisitor = new FileDependencyCollectingGraphVisitor(); DependencyGraphVisitor graphVisitor = new CompositeDependencyGraphVisitor(oldModelVisitor, newModelBuilder, localComponentsVisitor, fileDependencyVisitor); DependencyArtifactsVisitor artifactsVisitor = new CompositeDependencyArtifactsVisitor(oldModelVisitor, artifactsBuilder); resolver.resolve(configuration, resolutionAwareRepositories, metadataHandler, Specs.<DependencyMetadata>satisfyAll(), graphVisitor, artifactsVisitor, attributesSchema); ArtifactTransformer transformer = new ArtifactTransformer(configuration.getResolutionStrategy(), attributesSchema); VisitedArtifactsResults artifactsResults = artifactsBuilder.complete(); results.graphResolved(newModelBuilder.complete(), localComponentsVisitor, new BuildDependenciesOnlyVisitedArtifactSet(artifactsResults, fileDependencyVisitor, transformer)); results.retainState(new ArtifactResolveState(oldModelBuilder.complete(), artifactsResults, fileDependencyVisitor, oldTransientModelBuilder)); }
public Spec<FileTreeElement> createIncludeSpec(PatternSet patternSet) { List<Spec<FileTreeElement>> allIncludeSpecs = new ArrayList<Spec<FileTreeElement>>(1 + patternSet.getIncludeSpecs().size()); if (!patternSet.getIncludes().isEmpty()) { allIncludeSpecs.add(createSpec(patternSet.getIncludes(), true, patternSet.isCaseSensitive())); } allIncludeSpecs.addAll(patternSet.getIncludeSpecs()); return Specs.union(allIncludeSpecs); }
protected Spec<FileTreeElement> createSpec(Collection<String> patterns, boolean include, boolean caseSensitive) { if (patterns.isEmpty()) { return include ? Specs.<FileTreeElement>satisfyAll() : Specs.<FileTreeElement>satisfyNone(); } List<Spec<RelativePath>> matchers = new ArrayList<Spec<RelativePath>>(patterns.size()); for (String pattern : patterns) { Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(include, caseSensitive, pattern); matchers.add(patternMatcher); } return new RelativePathSpec(Specs.union(matchers)); }
private <S extends TaskInternal> S process(S task) { TaskClassInfo taskClassInfo = taskClassInfoStore.getTaskClassInfo(task.getClass()); if (taskClassInfo.isIncremental()) { // Add a dummy upToDateWhen spec: this will force TaskOutputs.hasOutputs() to be true. task.getOutputs().upToDateWhen(new Spec<Task>() { public boolean isSatisfiedBy(Task element) { return true; } }); } for (Factory<Action<Task>> actionFactory : taskClassInfo.getTaskActions()) { task.prependParallelSafeAction(actionFactory.create()); } TaskClassValidator validator = taskClassInfo.getValidator(); if (validator.hasAnythingToValidate()) { task.prependParallelSafeAction(validator); validator.addInputsAndOutputs(task); } // Enabled caching if task type is annotated with @CacheableTask if (taskClassInfo.isCacheable()) { task.getOutputs().cacheIf(Specs.SATISFIES_ALL); } return task; }
public CopySpec filesMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) { if (!patterns.iterator().hasNext()) { throw new InvalidUserDataException("must provide at least one pattern to match"); } List<Spec> matchers = new ArrayList<Spec>(); for (String pattern : patterns) { matchers.add(PatternMatcherFactory.getPatternMatcher(true, isCaseSensitive(), pattern)); } Spec unionMatcher = Specs.union(matchers.toArray(new Spec[matchers.size()])); return eachFile(new MatchingCopyAction(unionMatcher, action)); }
public CopySpec filesNotMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) { if (!patterns.iterator().hasNext()) { throw new InvalidUserDataException("must provide at least one pattern to not match"); } List<Spec> matchers = new ArrayList<Spec>(); for (String pattern : patterns) { matchers.add(PatternMatcherFactory.getPatternMatcher(true, isCaseSensitive(), pattern)); } Spec unionMatcher = Specs.union(matchers.toArray(new Spec[matchers.size()])); return eachFile(new MatchingCopyAction(Specs.<RelativePath>negate(unionMatcher), action)); }
public void configure(BuildExecutionContext context) { GradleInternal gradle = context.getGradle(); Set<String> excludedTaskNames = gradle.getStartParameter().getExcludedTaskNames(); if (!excludedTaskNames.isEmpty()) { final Set<Spec<Task>> filters = new HashSet<Spec<Task>>(); for (String taskName : excludedTaskNames) { filters.add(taskSelector.getFilter(taskName)); } gradle.getTaskGraph().useFilter(Specs.intersect(filters)); } context.proceed(); }
private void collectArtifacts( Configuration configuration, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) { Set<ResolvedArtifact> allArtifacts; if (extraModelInfo.getMode() != STANDARD) { allArtifacts = configuration.getResolvedConfiguration().getLenientConfiguration().getArtifacts( Specs.satisfyAll()); } else { allArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts(); } for (ResolvedArtifact artifact : allArtifacts) { ModuleVersionIdentifier id = artifact.getModuleVersion().getId(); List<ResolvedArtifact> moduleArtifacts = artifacts.get(id); if (moduleArtifacts == null) { moduleArtifacts = Lists.newArrayList(); artifacts.put(id, moduleArtifacts); } if (!moduleArtifacts.contains(artifact)) { moduleArtifacts.add(artifact); } } }
private Spec<RelativePath> getAsExcludeSpec(boolean caseSensitive) { Collection<String> allExcludes = new LinkedHashSet<String>(myFilePattern.excludes); List<Spec<RelativePath>> matchers = new ArrayList<Spec<RelativePath>>(); for (String exclude : allExcludes) { Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(false, caseSensitive, exclude); matchers.add(patternMatcher); } return Specs.or(false, matchers); }
private Spec<RelativePath> getAsIncludeSpec(boolean caseSensitive) { List<Spec<RelativePath>> matchers = new ArrayList<Spec<RelativePath>>(); for (String include : myFilePattern.includes) { Spec<RelativePath> patternMatcher = PatternMatcherFactory.getPatternMatcher(true, caseSensitive, include); matchers.add(patternMatcher); } return Specs.or(true, matchers); }
public void configure(BuildExecutionContext context) { GradleInternal gradle = context.getGradle(); Set<String> excludedTaskNames = gradle.getStartParameter().getExcludedTaskNames(); if (!excludedTaskNames.isEmpty()) { final Set<Spec<Task>> filters = new HashSet<Spec<Task>>(); for (String taskName : excludedTaskNames) { filters.add(taskSelector.getFilter(taskName)); } gradle.getTaskGraph().useFilter(Specs.and(filters)); } context.proceed(); }
@Inject public GenerateMavenPom(FileResolver fileResolver) { this.fileResolver = fileResolver; // Never up to date; we don't understand the data structures. getOutputs().upToDateWhen(Specs.satisfyNone()); }
@Inject public GenerateIvyDescriptor(FileResolver fileResolver) { this.fileResolver = fileResolver; // Never up to date; we don't understand the data structures. getOutputs().upToDateWhen(Specs.satisfyNone()); }
private ResolveResult resolve() { ResolveResult result = new ResolveResult(); dependencyResolver.resolve(resolveContext, remoteRepositories, globalRules, Specs.<DependencyMetadata>satisfyAll(), result, result, attributesSchema); return result; }
public static <T> NodeInitializerContext<T> forType(ModelType<T> type) { return new NodeInitializerContext<T>(type, Specs.<ModelType<?>>satisfyAll(), Optional.<PropertyContext>absent()); }
public static <T> NodeInitializerContext<T> forProperty(ModelType<T> type, ManagedProperty<?> property, ModelType<?> containingType) { return new NodeInitializerContext<T>(type, Specs.<ModelType<?>>satisfyAll(), Optional.of(new PropertyContext(property.getName(), property.getType(), property.isWritable(), property.isDeclaredAsHavingUnmanagedType(), containingType))); }
public GenerateMavenPom() { // Never up to date; we don't understand the data structures. getOutputs().upToDateWhen(Specs.satisfyNone()); }
private <K, V extends Response<?>> V maybeFetch(String operationName, final PersistentIndexedCache<K, V> cache, final K key, Factory<V> factory) { return maybeFetch(operationName, cache, key, factory, Specs.SATISFIES_NONE); }
@Override public Set<File> getFiles() { return getFiles(Specs.<Dependency>satisfyAll()); }
@Override public Set<ResolvedArtifact> getArtifacts() { return getArtifacts(Specs.<Dependency>satisfyAll()); }
private SpecRuleAction<? super ComponentSelection> createAllSpecRulesAction(RuleAction<? super ComponentSelection> ruleAction) { return new SpecRuleAction<ComponentSelection>(ruleAction, Specs.<ComponentSelection>satisfyAll()); }
@Override public Set<File> getFiles() throws ResolveException { return getFiles(Specs.<Dependency>satisfyAll()); }
public Set<ResolvedArtifact> getResolvedArtifacts() throws ResolveException { rethrowFailure(); ArtifactCollectingVisitor visitor = new ArtifactCollectingVisitor(); configuration.select(Specs.<Dependency>satisfyAll(), attributes).visitArtifacts(visitor); return visitor.artifacts; }
private SpecRuleAction<? super ComponentMetadataDetails> createAllSpecRuleAction(RuleAction<? super ComponentMetadataDetails> ruleAction) { return new SpecRuleAction<ComponentMetadataDetails>(ruleAction, Specs.<ComponentMetadataDetails>satisfyAll()); }
public Set<File> getFiles() { return doGetFiles(Specs.<Dependency>satisfyAll(), configurationAttributes); }
public TaskDependency getBuildDependencies() { assertResolvingAllowed(); return doGetTaskDependency(Specs.<Dependency>satisfyAll(), configurationAttributes); }
public Configuration copy(Closure dependencySpec) { return copy(Specs.<Dependency>convertClosureToSpec(dependencySpec)); }
public Configuration copyRecursive(Closure dependencySpec) { return copyRecursive(Specs.<Dependency>convertClosureToSpec(dependencySpec)); }
private ConfigurationFileCollection(Closure dependencySpecClosure) { this(Specs.convertClosureToSpec(dependencySpecClosure)); }
public FileCollection getFiles() { return new ConfigurationFileCollection(Specs.<Dependency>satisfyAll()); }