public Scope build() { Configuration useful = DependencyUtils.useful(configuration); String key = useful != null ? useful.getName() : "--none--"; return ProjectCache.getScopeCache(project) .computeIfAbsent( key, t -> new Scope( project, useful, sourceDirs, javaResourceDirs, compilerOptions, depCache)); } }
public void download() { ImmutableSet.Builder<Configuration> runtimeDeps = ImmutableSet.builder(); Set<API> apisToDownload; Set<String> configuredApis = ProjectUtil.getOkBuckExtension(rootProject).getTestExtension().robolectricApis; if (configuredApis != null) { apisToDownload = configuredApis.stream().map(API::from).collect(Collectors.toSet()); } else { apisToDownload = EnumSet.allOf(API.class); } for (API api : apisToDownload) { Configuration runtimeApi = rootProject.getConfigurations().maybeCreate(ROBOLECTRIC_RUNTIME + "_" + api.name()); rootProject.getDependencies().add(runtimeApi.getName(), api.getCoordinates()); runtimeDeps.add(runtimeApi); } DependencyCache dependencyCache = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)); dependencies = runtimeDeps .build() .stream() .map(dependencyCache::build) .flatMap(Set::stream) .collect(com.uber.okbuck.core.util.MoreCollectors.toImmutableSet()); }
@Input @SuppressWarnings("unused") // lets Gradle know when to not skip the task public String getConfigurationName() { return getConfiguration().getName(); }
/** * Get the properties as a map * * @return Map containing the properties */ public Map<String, ?> getProperties() { Map<String, ?> properties = ImmutableMap.of("path", this.project.getPath(), "configuration", this.configuration.getName()); return properties; }
private static void createCqPackageConf(Project project) { LOG.debug("Creating configuration: {}", CqPackagePlugin.CQ_PACKAGE); val cqPackageConf = project.getConfigurations().create(CqPackagePlugin.CQ_PACKAGE); // attach to "runtime", but don't insist that it have to be there first (or will ever be there) project.getConfigurations().withType(Configuration.class, conf -> { if (conf.getName().equals("runtime")) { LOG.debug("Making {} extend from {}", CqPackagePlugin.CQ_PACKAGE, conf.getName()); cqPackageConf.extendsFrom(conf); } }); }
@SuppressWarnings( {"UnusedDeclaration"}) public void jdbcDependency(Object dependencyNotation) { project.getDependencies().add( jdbcDependencies.getName(), dependencyNotation ); } }
@SuppressWarnings( {"UnusedDeclaration"}) public void jdbcDependency(Object dependencyNotation) { project.getDependencies().add( jdbcDependencies.getName(), dependencyNotation ); } }
/** * @see java.lang.Object#hashCode() */ @Override public int hashCode() { int hash = 0; hash = (31 * hash) + getProject().getPath().hashCode(); hash = (31 * hash) + getConfiguration().getName().hashCode(); return hash; }
private String findManagedVersion(Configuration source, String group, String name) { for (Configuration configuration : source.getHierarchy()) { String managedVersion = dependencyManagementForConfiguration(configuration) .getManagedVersion(group, name); if (managedVersion != null) { logger.debug("Found managed version '{}' for dependency '{}:{}' in dependency management for " + "configuration '{}'", managedVersion, group, name, configuration.getName()); return managedVersion; } } return null; }
private Object generateDependencyNotation(Configuration configuration, DownPluginDefinition pluginDefinition) { Map<String, String> dependencyNotationMap = new HashMap<>(); dependencyNotationMap.put("group", DEPENDENCY_GROUP); dependencyNotationMap.put("name", getDependencyName(configuration, pluginDefinition)); dependencyNotationMap.put("version", getDependencyVersion(pluginDefinition)); project.getLogger().info("Adding dependency for {} in configuration {}: {}", pluginDefinition.getPlugin().getPluginName(), configuration.getName(), dependencyNotationMap); return dependencyNotationMap; }
private ClassLoader createLoader(final ClassLoader parent) { final Collection<URL> urls = new LinkedHashSet<>(64); addFiles(modules, urls); for (final Configuration cc : getProject().getConfigurations()) { if (applicationScopes.contains(cc.getName())) { addFiles(cc.getFiles(), urls); } } addFiles(classpath.getFiles(), urls); // use JVM loader to avoid the noise of gradle and its plugins return new URLClassLoader(urls.toArray(new URL[urls.size()]), new FilterGradleClassLoader(parent, classloaderFilteredPackages)); }
@Test public void testIsTest_fromHierarchy() { Configuration configuration = mock(Configuration.class); when(configuration.getName()).thenReturn("random"); Configuration parent = mock(Configuration.class); when(parent.getName()).thenReturn("testCompile"); Set<Configuration> hierarchy = new HashSet<>(); hierarchy.add(parent); when(configuration.getHierarchy()).thenReturn(hierarchy); assertTrue(dependencyTask.isTest(configuration)); }
@Test public void testIsTest_isTestCompile() { Configuration configuration = mock(Configuration.class); when(configuration.getName()).thenReturn("testCompile"); assertTrue(dependencyTask.isTest(configuration)); }
@Test public void testIsTest_isNotTest() { Configuration configuration = mock(Configuration.class); when(configuration.getName()).thenReturn("random"); assertFalse(dependencyTask.isTest(configuration)); }
@Test public void testAddArtifacts() { ResolvedConfiguration resolvedConfiguration = spy(ResolvedConfiguration.class); Set<ResolvedArtifact> artifacts = preppareArtifactSet(3); when(resolvedConfiguration.getResolvedArtifacts()).thenReturn(artifacts); Configuration configuration = mock(Configuration.class); when(configuration.isCanBeResolved()).thenReturn(true); when(configuration.getName()).thenReturn("compile"); when(configuration.getResolvedConfiguration()).thenReturn(resolvedConfiguration); dependencyTask.addArtifacts(artifacts); assertThat(dependencyTask.artifactInfos.size(), is(3)); }
@Override public void execute(Task packageTask) { project.getArtifacts().add( variantData.getVariantDependency().getPublishConfiguration().getName(), new ApkPublishArtifact( projectBaseName, null, (FileSupplier) packageTask)); }
@Test public void testGetResolvedArtifacts_ResolveException() { ResolvedConfiguration resolvedConfiguration = mock(ResolvedConfiguration.class); when(resolvedConfiguration.getResolvedArtifacts()).thenThrow(ResolveException.class); Configuration configuration = mock(Configuration.class); when(configuration.getName()).thenReturn("compile"); when(configuration.isCanBeResolved()).thenReturn(true); when(configuration.getResolvedConfiguration()).thenReturn(resolvedConfiguration); assertThat(dependencyTask.getResolvedArtifacts(configuration), is(nullValue())); }
@Test public void testGetResolvedArtifacts_isTest() { Configuration configuration = mock(Configuration.class); when(configuration.getName()).thenReturn("testCompile"); when(configuration.isCanBeResolved()).thenReturn(true); assertThat(dependencyTask.getResolvedArtifacts(configuration), is(nullValue())); }
@Override public Configuration findProjectConfiguration() { ConfigurationContainer dependencyConfigurations = getDependencyProject().getConfigurations(); String declaredConfiguration = getTargetConfiguration(); Configuration selectedConfiguration = dependencyConfigurations.getByName(GUtil.elvis(declaredConfiguration, Dependency.DEFAULT_CONFIGURATION)); if (!selectedConfiguration.isCanBeConsumed()) { throw new ConfigurationNotConsumableException(dependencyProject.getDisplayName(), selectedConfiguration.getName()); } return selectedConfiguration; }