use of org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier in project gradle by gradle.
the class ComponentIdentifierSerializer method write.
@Override
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.SNAPSHOT) {
MavenUniqueSnapshotComponentIdentifier snapshotIdentifier = (MavenUniqueSnapshotComponentIdentifier) value;
encoder.writeString(snapshotIdentifier.getGroup());
encoder.writeString(snapshotIdentifier.getModule());
encoder.writeString(snapshotIdentifier.getVersion());
encoder.writeString(snapshotIdentifier.getTimestamp());
} else if (implementation == Implementation.ROOT_PROJECT) {
ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier) value;
BuildIdentifier build = projectComponentIdentifier.getBuild();
buildIdentifierSerializer.write(encoder, build);
encoder.writeString(projectComponentIdentifier.getProjectName());
} else if (implementation == Implementation.ROOT_BUILD_PROJECT) {
ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier) value;
BuildIdentifier build = projectComponentIdentifier.getBuild();
buildIdentifierSerializer.write(encoder, build);
encoder.writeString(projectComponentIdentifier.getProjectPath());
} else if (implementation == Implementation.OTHER_BUILD_ROOT_PROJECT) {
DefaultProjectComponentIdentifier projectComponentIdentifier = (DefaultProjectComponentIdentifier) value;
BuildIdentifier build = projectComponentIdentifier.getBuild();
buildIdentifierSerializer.write(encoder, build);
encoder.writeString(projectComponentIdentifier.getIdentityPath().getPath());
} else if (implementation == Implementation.OTHER_BUILD_PROJECT) {
DefaultProjectComponentIdentifier projectComponentIdentifier = (DefaultProjectComponentIdentifier) value;
BuildIdentifier build = projectComponentIdentifier.getBuild();
buildIdentifierSerializer.write(encoder, build);
encoder.writeString(projectComponentIdentifier.getIdentityPath().getPath());
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 if (implementation == Implementation.OPAQUE) {
OpaqueComponentArtifactIdentifier opaqueComponentIdentifier = (OpaqueComponentArtifactIdentifier) value;
encoder.writeString(opaqueComponentIdentifier.getFile().getPath());
} else {
throw new IllegalStateException("Unsupported implementation type: " + implementation);
}
}
use of org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier in project gradle by gradle.
the class ComponentIdentifierSerializer method resolveImplementation.
private Implementation resolveImplementation(ComponentIdentifier value) {
if (value instanceof MavenUniqueSnapshotComponentIdentifier) {
return Implementation.SNAPSHOT;
} else if (value instanceof ModuleComponentIdentifier) {
return Implementation.MODULE;
} else if (value instanceof DefaultProjectComponentIdentifier) {
DefaultProjectComponentIdentifier projectComponentIdentifier = (DefaultProjectComponentIdentifier) value;
// Special case some common combinations of names and paths
boolean isARootProject = projectComponentIdentifier.projectPath().equals(Path.ROOT);
if (projectComponentIdentifier.getIdentityPath().equals(Path.ROOT) && isARootProject) {
return Implementation.ROOT_PROJECT;
}
if (projectComponentIdentifier.getIdentityPath().equals(projectComponentIdentifier.projectPath()) && projectComponentIdentifier.projectPath().getName().equals(projectComponentIdentifier.getProjectName())) {
return Implementation.ROOT_BUILD_PROJECT;
}
if (isARootProject && projectComponentIdentifier.getProjectName().equals(projectComponentIdentifier.getIdentityPath().getName())) {
return Implementation.OTHER_BUILD_ROOT_PROJECT;
}
return Implementation.OTHER_BUILD_PROJECT;
} else if (value instanceof LibraryBinaryIdentifier) {
return Implementation.LIBRARY;
} else if (value instanceof OpaqueComponentArtifactIdentifier) {
return Implementation.OPAQUE;
} else {
throw new IllegalArgumentException("Unsupported component identifier class: " + value.getClass());
}
}
use of org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier in project gradle by gradle.
the class ComponentIdentifierSerializer method read.
@Override
public ComponentIdentifier read(Decoder decoder) throws IOException {
byte id = decoder.readByte();
if (Implementation.ROOT_PROJECT.getId() == id) {
BuildIdentifier buildIdentifier = buildIdentifierSerializer.read(decoder);
String projectName = decoder.readString();
return new DefaultProjectComponentIdentifier(buildIdentifier, Path.ROOT, Path.ROOT, projectName);
} else if (Implementation.ROOT_BUILD_PROJECT.getId() == id) {
BuildIdentifier buildIdentifier = buildIdentifierSerializer.read(decoder);
Path projectPath = Path.path(decoder.readString());
return new DefaultProjectComponentIdentifier(buildIdentifier, projectPath, projectPath, projectPath.getName());
} else if (Implementation.OTHER_BUILD_ROOT_PROJECT.getId() == id) {
BuildIdentifier buildIdentifier = buildIdentifierSerializer.read(decoder);
Path identityPath = Path.path(decoder.readString());
return new DefaultProjectComponentIdentifier(buildIdentifier, identityPath, Path.ROOT, identityPath.getName());
} else if (Implementation.OTHER_BUILD_PROJECT.getId() == id) {
BuildIdentifier buildIdentifier = buildIdentifierSerializer.read(decoder);
Path identityPath = Path.path(decoder.readString());
Path projectPath = Path.path(decoder.readString());
return new DefaultProjectComponentIdentifier(buildIdentifier, identityPath, projectPath, identityPath.getName());
} else if (Implementation.MODULE.getId() == id) {
return new DefaultModuleComponentIdentifier(DefaultModuleIdentifier.newId(decoder.readString(), decoder.readString()), decoder.readString());
} else if (Implementation.SNAPSHOT.getId() == id) {
return new MavenUniqueSnapshotComponentIdentifier(DefaultModuleIdentifier.newId(decoder.readString(), decoder.readString()), decoder.readString(), decoder.readString());
} else if (Implementation.LIBRARY.getId() == id) {
return new DefaultLibraryBinaryIdentifier(decoder.readString(), decoder.readString(), decoder.readString());
} else if (Implementation.OPAQUE.getId() == id) {
return new OpaqueComponentArtifactIdentifier(new File(decoder.readString()));
}
throw new IllegalArgumentException("Unable to find component identifier type with id: " + id);
}
use of org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier in project gradle by gradle.
the class AbstractCompositeParticipantBuildState method idToReferenceProjectFromAnotherBuild.
@Override
public ProjectComponentIdentifier idToReferenceProjectFromAnotherBuild(ProjectComponentIdentifier identifier) {
// Need to use a 'foreign' build id to make BuildIdentifier.isCurrentBuild and BuildIdentifier.name work in dependency results
DefaultProjectComponentIdentifier original = (DefaultProjectComponentIdentifier) identifier;
String name = getIdentityPath().getName();
if (name == null) {
name = getBuildIdentifier().getName();
}
return new DefaultProjectComponentIdentifier(new ForeignBuildIdentifier(getBuildIdentifier().getName(), name), original.getIdentityPath(), original.projectPath(), original.getProjectName());
}
use of org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier in project gradle by gradle.
the class TestComponentIdentifiers method newProjectId.
public static ProjectComponentIdentifier newProjectId(String buildName, String projectPath) {
Path path = Path.path(projectPath);
String name = path.getName();
if (name == null) {
name = "root";
}
return new DefaultProjectComponentIdentifier(new DefaultBuildIdentifier(buildName), path, path, name);
}
Aggregations