use of org.gradle.api.artifacts.component.LibraryBinaryIdentifier in project gradle by gradle.
the class JvmTestSuiteBasePlugin method runtimeDependencies.
private static List<DependencySpec> runtimeDependencies(JvmTestSuiteBinarySpecInternal testBinary) {
List<DependencySpec> dependencies = Lists.newArrayList(testBinary.getDependencies());
JvmBinarySpec testedBinary = testBinary.getTestedBinary();
dependencies.add(DefaultLibraryBinaryDependencySpec.of(testBinary.getId()));
if (testedBinary != null) {
JvmBinarySpecInternal binary = (JvmBinarySpecInternal) testedBinary;
LibraryBinaryIdentifier id = binary.getId();
dependencies.add(DefaultLibraryBinaryDependencySpec.of(id));
}
addSourceSetSpecificDependencies(dependencies, testBinary.getSources());
addSourceSetSpecificDependencies(dependencies, testBinary.getTestSuite().getSources());
return dependencies;
}
use of org.gradle.api.artifacts.component.LibraryBinaryIdentifier in project gradle by gradle.
the class JvmTestSuiteBasePlugin method createResolveContext.
private static JvmLibraryResolveContext createResolveContext(JvmTestSuiteBinarySpecInternal testBinary, ModelSchema<? extends JvmTestSuiteBinarySpec> schema, ImmutableModuleIdentifierFactory moduleIdentifierFactory) {
// TODO:Cedric find out why if we use the same ID directly, it fails resolution by trying to get the artifacts
// from the resolving metadata instead of the resolved metadata
LibraryBinaryIdentifier id = testBinary.getId();
LibraryBinaryIdentifier thisId = new DefaultLibraryBinaryIdentifier(id.getProjectPath(), id.getLibraryName() + "Test", id.getVariant());
return new JvmLibraryResolveContext(thisId, DefaultVariantsMetaData.extractFrom(testBinary, schema), runtimeDependencies(testBinary), UsageKind.RUNTIME, testBinary.getDisplayName(), moduleIdentifierFactory);
}
use of org.gradle.api.artifacts.component.LibraryBinaryIdentifier in project gradle by gradle.
the class JvmTestSuiteRules method createJvmTestSuiteBinary.
private static <T extends JvmTestSuiteBinarySpec> void createJvmTestSuiteBinary(final ModelMap<BinarySpec> testBinaries, Class<T> testSuiteBinaryClass, final JvmTestSuiteSpec testSuite, final JvmBinarySpec testedBinary, final JavaToolChainRegistry toolChains, PlatformResolvers platformResolver) {
final List<JavaPlatform> javaPlatforms = resolvePlatforms(platformResolver);
final JavaPlatform platform = testedBinary != null ? testedBinary.getTargetPlatform() : javaPlatforms.get(0);
final BinaryNamingScheme namingScheme = namingSchemeFor(testSuite, testedBinary, javaPlatforms, platform);
testBinaries.create(namingScheme.getBinaryName(), testSuiteBinaryClass, new Action<T>() {
@Override
public void execute(T binary) {
JvmTestSuiteBinarySpecInternal testBinary = (JvmTestSuiteBinarySpecInternal) binary;
testBinary.setNamingScheme(namingScheme);
testBinary.setTargetPlatform(platform);
testBinary.setToolChain(toolChains.getForPlatform(platform));
testBinary.setTestedBinary(testedBinary);
addTestSuiteDependencies(testBinary);
configureCompileClasspath(testBinary);
}
private boolean addTestSuiteDependencies(JvmTestSuiteBinarySpecInternal testBinary) {
return testBinary.getDependencies().addAll(testSuite.getDependencies().getDependencies());
}
private void configureCompileClasspath(JvmTestSuiteBinarySpecInternal testSuiteBinary) {
if (testedBinary != null) {
Collection<DependencySpec> dependencies = testSuiteBinary.getDependencies();
BinarySpecInternal binary = (BinarySpecInternal) testedBinary;
LibraryBinaryIdentifier id = binary.getId();
dependencies.add(DefaultLibraryBinaryDependencySpec.of(id));
if (testedBinary instanceof JarBinarySpecInternal) {
dependencies.addAll(((JarBinarySpecInternal) testedBinary).getApiDependencies());
}
}
}
});
}
use of org.gradle.api.artifacts.component.LibraryBinaryIdentifier in project gradle by gradle.
the class ComponentIdentifierSerializer method write.
public void write(Encoder encoder, ComponentIdentifier value) throws IOException {
if (value == null) {
throw new IllegalArgumentException("Provided component identifier may not be null");
}
Implementation implementation = resolveImplementation(value);
encoder.writeByte(implementation.getId());
if (implementation == Implementation.MODULE) {
ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier) value;
encoder.writeString(moduleComponentIdentifier.getGroup());
encoder.writeString(moduleComponentIdentifier.getModule());
encoder.writeString(moduleComponentIdentifier.getVersion());
} else if (implementation == Implementation.BUILD) {
ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier) value;
BuildIdentifier build = projectComponentIdentifier.getBuild();
buildIdentifierSerializer.write(encoder, build);
encoder.writeString(projectComponentIdentifier.getProjectPath());
} else if (implementation == Implementation.LIBRARY) {
LibraryBinaryIdentifier libraryIdentifier = (LibraryBinaryIdentifier) value;
encoder.writeString(libraryIdentifier.getProjectPath());
encoder.writeString(libraryIdentifier.getLibraryName());
encoder.writeString(libraryIdentifier.getVariant());
} else {
throw new IllegalStateException("Unsupported implementation type: " + implementation);
}
}
use of org.gradle.api.artifacts.component.LibraryBinaryIdentifier in project gradle by gradle.
the class JvmVariantSelector method selectVariants.
@Override
public Collection<? extends BinarySpec> selectVariants(VariantComponent componentSpec, @Nullable String requestedVariant) {
// We know that Jvm binaries are BinarySpec instances
Collection<BinarySpec> allBinaries = Lists.newArrayList();
for (Binary binary : componentSpec.getVariants()) {
allBinaries.add((BinarySpec) binary);
}
if (requestedVariant != null) {
// Choose explicit variant
for (Binary binarySpec : allBinaries) {
BinarySpecInternal binary = (BinarySpecInternal) binarySpec;
LibraryBinaryIdentifier id = binary.getId();
if (Objects.equal(requestedVariant, id.getVariant())) {
return Collections.singleton(binary);
}
}
return Collections.emptySet();
}
return variantsMatcher.filterBinaries(variantsMetaData, allBinaries);
}
Aggregations