Search in sources :

Example 1 with DefaultProjectComponentIdentifier

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);
    }
}
Also used : MavenUniqueSnapshotComponentIdentifier(org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) LibraryBinaryIdentifier(org.gradle.api.artifacts.component.LibraryBinaryIdentifier) DefaultLibraryBinaryIdentifier(org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)

Example 2 with DefaultProjectComponentIdentifier

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());
    }
}
Also used : MavenUniqueSnapshotComponentIdentifier(org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) LibraryBinaryIdentifier(org.gradle.api.artifacts.component.LibraryBinaryIdentifier) DefaultLibraryBinaryIdentifier(org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)

Example 3 with DefaultProjectComponentIdentifier

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);
}
Also used : Path(org.gradle.util.Path) DefaultLibraryBinaryIdentifier(org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier) MavenUniqueSnapshotComponentIdentifier(org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier) File(java.io.File)

Example 4 with DefaultProjectComponentIdentifier

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());
}
Also used : ForeignBuildIdentifier(org.gradle.api.internal.artifacts.ForeignBuildIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)

Example 5 with DefaultProjectComponentIdentifier

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);
}
Also used : Path(org.gradle.util.Path) DefaultBuildIdentifier(org.gradle.api.internal.artifacts.DefaultBuildIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)

Aggregations

DefaultProjectComponentIdentifier (org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)7 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)3 MavenUniqueSnapshotComponentIdentifier (org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier)3 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)3 DefaultLibraryBinaryIdentifier (org.gradle.internal.component.local.model.DefaultLibraryBinaryIdentifier)3 OpaqueComponentArtifactIdentifier (org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier)3 Path (org.gradle.util.Path)3 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)2 LibraryBinaryIdentifier (org.gradle.api.artifacts.component.LibraryBinaryIdentifier)2 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)2 File (java.io.File)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 DefaultBuildIdentifier (org.gradle.api.internal.artifacts.DefaultBuildIdentifier)1 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)1 ForeignBuildIdentifier (org.gradle.api.internal.artifacts.ForeignBuildIdentifier)1 StateTransitionControllerFactory (org.gradle.internal.model.StateTransitionControllerFactory)1