org.gradle.api.artifacts.Configuration.isCanBeResolved()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中org.gradle.api.artifacts.Configuration.isCanBeResolved()方法的一些代码示例,展示了Configuration.isCanBeResolved()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.isCanBeResolved()方法的具体详情如下:
包路径:org.gradle.api.artifacts.Configuration
类名称:Configuration
方法名:isCanBeResolved

Configuration.isCanBeResolved介绍

暂无

代码示例

代码示例来源:origin: uber/okbuck

@Nullable
public static Configuration useful(@Nullable Configuration configuration) {
 if (configuration != null && configuration.isCanBeResolved()) {
  return configuration;
 }
 return null;
}

代码示例来源:origin: ManbangGroup/Phantom

private Set<String> getCompileArtifactsForAgp2x() {
  Set<String> compileLibs = new HashSet<>();
  Configuration configuration = project.getConfigurations().getByName("compile");
  if (configuration.isCanBeResolved()) {
    ResolvableDependencies incoming = configuration.getIncoming();
    ResolutionResult resolutionResult = incoming.getResolutionResult();
    Set<ResolvedComponentResult> components = resolutionResult.getAllComponents();
    for (ResolvedComponentResult result : components) {
      ModuleVersionIdentifier identifier = result.getModuleVersion();
      if (identifier != null && !"unspecified".equals(identifier.getVersion())) {
        compileLibs.add(
            String.join(":", identifier.getGroup(), identifier.getName(), identifier.getVersion()));
      }
    }
  }
  return compileLibs;
}

代码示例来源:origin: gradle.plugin.org.kiirun/joda-beans-gradle-plugin

/**
 * Obtains the classloader from a set of file paths.
 *
 * @return the classloader, not null
 */
private ClassLoader obtainClassLoader() {
  final List<URL> compileClasspath = new ArrayList<>();
  for (final String configName : CONFIGURATIONS_TO_SEARCH) {
    final Configuration config = getProject().getConfigurations().findByName(configName);
    if (config != null && config.isCanBeResolved()) {
      for (final File classpathFile : config.getFiles()) {
        try {
          compileClasspath.add(classpathFile.toURI().toURL());
        } catch (final MalformedURLException e) {
          getLogger().debug(
              "Skipping " + classpathFile.getAbsolutePath() + " from the compile classpath.");
        }
      }
    }
  }
  return new URLClassLoader(compileClasspath.toArray(new URL[compileClasspath.size()]),
      AbstractJodaBeansTask.class.getClassLoader());
}

代码示例来源:origin: me.seeber.gradle/gradle-project-config

/**
 * Find a resolved artifact in a project
 *
 * @param project Project to search
 * @param configurationPredicate Predicate to test configurations
 * @param artifactPredicate Predicate to test artifacts
 * @return Found element or empty value
 */
public static Optional<ProjectElement<ResolvedArtifact>> findResolvedArtifact(Project project,
    Predicate<@NonNull Configuration> configurationPredicate,
    Predicate<@NonNull ResolvedArtifact> artifactPredicate) {
  Optional<ProjectElement<ResolvedArtifact>> info = Optional.empty();
  for (@NonNull Configuration configuration : project.getConfigurations()) {
    if (configuration.isCanBeResolved() && configurationPredicate.test(configuration)) {
      info = findResolvedArtifact(project, configuration, artifactPredicate);
      if (info.isPresent()) {
        break;
      }
    }
  }
  return info;
}

代码示例来源:origin: gradle.plugin.me.seeber.gradle/gradle-project-config

/**
 * Find a resolved artifact in a project
 *
 * @param project Project to search
 * @param configurationPredicate Predicate to test configurations
 * @param artifactPredicate Predicate to test artifacts
 * @return Found element or empty value
 */
public static Optional<ProjectElement<ResolvedArtifact>> findResolvedArtifact(Project project,
    Predicate<@NonNull Configuration> configurationPredicate,
    Predicate<@NonNull ResolvedArtifact> artifactPredicate) {
  Optional<ProjectElement<ResolvedArtifact>> info = Optional.empty();
  for (@NonNull Configuration configuration : project.getConfigurations()) {
    if (configuration.isCanBeResolved() && configurationPredicate.test(configuration)) {
      info = findResolvedArtifact(project, configuration, artifactPredicate);
      if (info.isPresent()) {
        break;
      }
    }
  }
  return info;
}

代码示例来源:origin: google/play-services-plugins

@Test
public void testGetResolvedArtifacts_returnArtifact() {
 Set<ResolvedArtifact> artifactSet = (Set<ResolvedArtifact>) mock(Set.class);
 ResolvedConfiguration resolvedConfiguration = mock(ResolvedConfiguration.class);
 when(resolvedConfiguration.getResolvedArtifacts()).thenReturn(artifactSet);
 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(artifactSet));
}

代码示例来源:origin: google/play-services-plugins

@Test
public void testCanBeResolved_isFalse() {
 Configuration configuration = mock(Configuration.class);
 when(configuration.isCanBeResolved()).thenReturn(false);
 assertFalse(dependencyTask.canBeResolved(configuration));
}

代码示例来源:origin: google/play-services-plugins

@Test
public void testCanBeResolved_isTrue() {
 Configuration configuration = mock(Configuration.class);
 when(configuration.isCanBeResolved()).thenReturn(true);
 assertTrue(dependencyTask.canBeResolved(configuration));
}

代码示例来源:origin: google/play-services-plugins

@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()));
}

代码示例来源:origin: google/play-services-plugins

@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));
}

代码示例来源:origin: google/play-services-plugins

@Test
public void testAddArtifacts_willNotAddDuplicate() {
 ResolvedConfiguration resolvedConfiguration = spy(ResolvedConfiguration.class);
 Set<ResolvedArtifact> artifacts = preppareArtifactSet(2);
 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);
 String[] keySets = new String[] {"location1", "location2"};
 dependencyTask.artifactSet = new HashSet<>(Arrays.asList(keySets));
 dependencyTask.addArtifacts(artifacts);
 assertThat(dependencyTask.artifactInfos.size(), is(1));
}

代码示例来源:origin: google/play-services-plugins

@Test
public void testGetResolvedArtifacts_cannotResolve() {
 Configuration configuration = mock(Configuration.class);
 when(configuration.isCanBeResolved()).thenReturn(false);
 assertThat(dependencyTask.getResolvedArtifacts(configuration), is(nullValue()));
}

代码示例来源:origin: google/play-services-plugins

@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()));
}

代码示例来源:origin: me.seeber.gradle/gradle-project-config

/**
 * Create Eclipse annotations tasks
 *
 * @param tasks Task container
 * @param configurations Container to access configurations
 * @param buildDir Build directory
 */
@Mutate
public void createEclipseAnnotationsTasks(ModelMap<Task> tasks, ConfigurationContainer configurations,
    @Path("buildDir") File buildDir) {
  tasks.create("eclipseAnnotations", EclipseAnnotationsTask.class, t -> {
    t.setDescription("Generates external nullability annotations for dependencies.");
    t.setGroup("IDE");
    ConventionMapping parameters = t.getConventionMapping();
    parameters.map("jars", () -> {
      Set<File> jars = configurations.stream()
          .filter(c -> c.isCanBeResolved()
              && !c.getName().equals(JavaConfigPlugin.ANNOTATIONS_CONFIGURATION))
          .map(c -> c.getResolvedConfiguration().getLenientConfiguration())
          .flatMap(c -> c.getArtifacts().stream()
              .filter(a -> !(a.getId()
                  .getComponentIdentifier() instanceof ProjectComponentIdentifier)
                  && a.getType().equals("jar"))
              .map(a -> a.getFile()))
          .collect(Collectors.toSet());
      return jars;
    });
  });
}

代码示例来源:origin: gradle.plugin.me.seeber.gradle/gradle-project-config

/**
 * Create Eclipse annotations tasks
 *
 * @param tasks Task container
 * @param configurations Container to access configurations
 * @param buildDir Build directory
 */
@Mutate
public void createEclipseAnnotationsTasks(ModelMap<Task> tasks, ConfigurationContainer configurations,
    @Path("buildDir") File buildDir) {
  tasks.create("eclipseAnnotations", EclipseAnnotationsTask.class, t -> {
    t.setDescription("Generates external nullability annotations for dependencies.");
    t.setGroup("IDE");
    ConventionMapping parameters = t.getConventionMapping();
    parameters.map("jars", () -> {
      Set<File> jars = configurations.stream()
          .filter(c -> c.isCanBeResolved()
              && !c.getName().equals(JavaConfigPlugin.ANNOTATIONS_CONFIGURATION))
          .map(c -> c.getResolvedConfiguration().getLenientConfiguration())
          .flatMap(c -> c.getArtifacts().stream()
              .filter(a -> !(a.getId()
                  .getComponentIdentifier() instanceof ProjectComponentIdentifier)
                  && a.getType().equals("jar"))
              .map(a -> a.getFile()))
          .collect(Collectors.toSet());
      return jars;
    });
  });
}

相关文章