org.gradle.api.artifacts.component.ProjectComponentIdentifier Java Examples

The following examples show how to use org.gradle.api.artifacts.component.ProjectComponentIdentifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComponentIdentifierSerializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void write(Encoder encoder, ComponentIdentifier value) throws IOException {
    if(value == null) {
        throw new IllegalArgumentException("Provided component identifier may not be null");
    }

    if(value instanceof DefaultModuleComponentIdentifier) {
        ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier)value;
        encoder.writeByte(Implementation.MODULE.getId());
        encoder.writeString(moduleComponentIdentifier.getGroup());
        encoder.writeString(moduleComponentIdentifier.getModule());
        encoder.writeString(moduleComponentIdentifier.getVersion());
    } else if(value instanceof DefaultProjectComponentIdentifier) {
        ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)value;
        encoder.writeByte(Implementation.BUILD.getId());
        encoder.writeString(projectComponentIdentifier.getProjectPath());
    } else {
        throw new IllegalArgumentException("Unsupported component identifier class: " + value.getClass());
    }
}
 
Example #2
Source File: ComponentIdentifierSerializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void write(Encoder encoder, ComponentIdentifier value) throws IOException {
    if(value == null) {
        throw new IllegalArgumentException("Provided component identifier may not be null");
    }

    if(value instanceof DefaultModuleComponentIdentifier) {
        ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier)value;
        encoder.writeByte(Implementation.MODULE.getId());
        encoder.writeString(moduleComponentIdentifier.getGroup());
        encoder.writeString(moduleComponentIdentifier.getModule());
        encoder.writeString(moduleComponentIdentifier.getVersion());
    } else if(value instanceof DefaultProjectComponentIdentifier) {
        ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)value;
        encoder.writeByte(Implementation.BUILD.getId());
        encoder.writeString(projectComponentIdentifier.getProjectPath());
    } else {
        throw new IllegalArgumentException("Unsupported component identifier class: " + value.getClass());
    }
}
 
Example #3
Source File: ComponentIdentifierSerializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void write(Encoder encoder, ComponentIdentifier value) throws IOException {
    if(value == null) {
        throw new IllegalArgumentException("Provided component identifier may not be null");
    }

    if(value instanceof DefaultModuleComponentIdentifier) {
        ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier)value;
        encoder.writeByte(Implementation.MODULE.getId());
        encoder.writeString(moduleComponentIdentifier.getGroup());
        encoder.writeString(moduleComponentIdentifier.getModule());
        encoder.writeString(moduleComponentIdentifier.getVersion());
    } else if(value instanceof DefaultProjectComponentIdentifier) {
        ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)value;
        encoder.writeByte(Implementation.BUILD.getId());
        encoder.writeString(projectComponentIdentifier.getProjectPath());
    } else {
        throw new IllegalArgumentException("Unsupported component identifier class: " + value.getClass());
    }
}
 
Example #4
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Spec<ComponentIdentifier> getComponentFilter(
        @NonNull AndroidArtifacts.ArtifactScope scope) {
    switch (scope) {
        case ALL:
            return null;
        case EXTERNAL:
            // since we want both Module dependencies and file based dependencies in this case
            // the best thing to do is search for non ProjectComponentIdentifier.
            return id -> !(id instanceof ProjectComponentIdentifier);
        case MODULE:
            return id -> id instanceof ProjectComponentIdentifier;
        default:
            throw new RuntimeException("unknown ArtifactScope value");
    }
}
 
Example #5
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
@NonNull
public static String computeAddress(@NonNull AtlasDependencyGraph.HashableResolvedArtifactResult artifact) {
    ComponentIdentifier id = artifact.getId().getComponentIdentifier();
    if (id instanceof ProjectComponentIdentifier) {
        String variant = getVariant(artifact);
        if (variant == null) {
            return ((ProjectComponentIdentifier) id).getProjectPath().intern();
        } else {
            return (((ProjectComponentIdentifier) id).getProjectPath() + "::" + variant)
                    .intern();
        }
    } else if (id instanceof ModuleComponentIdentifier || id instanceof OpaqueComponentArtifactIdentifier) {
        MavenCoordinates coordinates = sMavenCoordinatesCache.get(artifact);
        Optional.of(coordinates);
        return coordinates.toString().intern();
    } else {
        throw new RuntimeException(
                "Don't know how to handle ComponentIdentifier '"
                        + id.getDisplayName()
                        + "'of type "
                        + id.getClass());
    }
}
 
Example #6
Source File: BuildAtlasEnvTask.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Spec<ComponentIdentifier> getComponentFilter(
        @NonNull AndroidArtifacts.ArtifactScope scope) {
    switch (scope) {
        case ALL:
            return null;
        case EXTERNAL:
            // since we want both Module dependencies and file based dependencies in this case
            // the best thing to do is search for non ProjectComponentIdentifier.
            return id -> !(id instanceof ProjectComponentIdentifier);
        case MODULE:
            return id -> id instanceof ProjectComponentIdentifier;
        default:
            throw new RuntimeException("unknown ArtifactScope value");
    }
}
 
Example #7
Source File: PlayDistributionPlugin.java    From playframework with Apache License 2.0 6 votes vote down vote up
private Map<File, String> calculate() {
    Map<File, String> files = new HashMap<>();
    for (ResolvedArtifactResult artifact : getResolvedArtifacts()) {
        ComponentIdentifier componentId = artifact.getId().getComponentIdentifier();
        if (componentId instanceof ProjectComponentIdentifier) {
            // rename project dependencies
            ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier) componentId;
            files.put(artifact.getFile(), renameForProject(projectComponentIdentifier, artifact.getFile()));
        } else if (componentId instanceof ModuleComponentIdentifier) {
            ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier) componentId;
            files.put(artifact.getFile(), renameForModule(moduleComponentIdentifier, artifact.getFile()));
        } else {
            // don't rename other types of dependencies
            files.put(artifact.getFile(), artifact.getFile().getName());
        }
    }
    return Collections.unmodifiableMap(files);
}
 
Example #8
Source File: ComponentIdentifierSerializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void write(Encoder encoder, ComponentIdentifier value) throws IOException {
    if(value == null) {
        throw new IllegalArgumentException("Provided component identifier may not be null");
    }

    if(value instanceof DefaultModuleComponentIdentifier) {
        ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier)value;
        encoder.writeByte(Implementation.MODULE.getId());
        encoder.writeString(moduleComponentIdentifier.getGroup());
        encoder.writeString(moduleComponentIdentifier.getModule());
        encoder.writeString(moduleComponentIdentifier.getVersion());
    } else if(value instanceof DefaultProjectComponentIdentifier) {
        ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)value;
        encoder.writeByte(Implementation.BUILD.getId());
        encoder.writeString(projectComponentIdentifier.getProjectPath());
    } else {
        throw new IllegalArgumentException("Unsupported component identifier class: " + value.getClass());
    }
}
 
Example #9
Source File: DefaultIdeDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets IDE project dependencies.
 *
 * @param configuration Configuration
 * @param project Project
 * @return IDE project dependencies
 */
public List<IdeProjectDependency> getIdeProjectDependencies(Configuration configuration, Project project) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    List<ResolvedComponentResult> projectComponents = findAllResolvedDependencyResults(result.getRoot().getDependencies(), ProjectComponentIdentifier.class);

    List<IdeProjectDependency> ideProjectDependencies = new ArrayList<IdeProjectDependency>();

    for (ResolvedComponentResult projectComponent : projectComponents) {
        Project resolvedProject = project.project(((ProjectComponentIdentifier) projectComponent.getId()).getProjectPath());
        ideProjectDependencies.add(new IdeProjectDependency(configuration, resolvedProject));
    }

    return ideProjectDependencies;
}
 
Example #10
Source File: DefaultIdeDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets IDE project dependencies.
 *
 * @param configuration Configuration
 * @param project Project
 * @return IDE project dependencies
 */
public List<IdeProjectDependency> getIdeProjectDependencies(Configuration configuration, Project project) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    List<ResolvedComponentResult> projectComponents = findAllResolvedDependencyResults(result.getRoot().getDependencies(), ProjectComponentIdentifier.class);

    List<IdeProjectDependency> ideProjectDependencies = new ArrayList<IdeProjectDependency>();

    for (ResolvedComponentResult projectComponent : projectComponents) {
        Project resolvedProject = project.project(((ProjectComponentIdentifier) projectComponent.getId()).getProjectPath());
        ideProjectDependencies.add(new IdeProjectDependency(configuration, resolvedProject));
    }

    return ideProjectDependencies;
}
 
Example #11
Source File: DefaultIdeDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets IDE project dependencies.
 *
 * @param configuration Configuration
 * @param project Project
 * @return IDE project dependencies
 */
public List<IdeProjectDependency> getIdeProjectDependencies(Configuration configuration, Project project) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    List<ResolvedComponentResult> projectComponents = findAllResolvedDependencyResults(result.getRoot().getDependencies(), ProjectComponentIdentifier.class);

    List<IdeProjectDependency> ideProjectDependencies = new ArrayList<IdeProjectDependency>();

    for (ResolvedComponentResult projectComponent : projectComponents) {
        Project resolvedProject = project.project(((ProjectComponentIdentifier) projectComponent.getId()).getProjectPath());
        ideProjectDependencies.add(new IdeProjectDependency(configuration, resolvedProject));
    }

    return ideProjectDependencies;
}
 
Example #12
Source File: DefaultIdeDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets IDE project dependencies.
 *
 * @param configuration Configuration
 * @param project Project
 * @return IDE project dependencies
 */
public List<IdeProjectDependency> getIdeProjectDependencies(Configuration configuration, Project project) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    List<ResolvedComponentResult> projectComponents = findAllResolvedDependencyResults(result.getRoot().getDependencies(), ProjectComponentIdentifier.class);

    List<IdeProjectDependency> ideProjectDependencies = new ArrayList<IdeProjectDependency>();

    for (ResolvedComponentResult projectComponent : projectComponents) {
        Project resolvedProject = project.project(((ProjectComponentIdentifier) projectComponent.getId()).getProjectPath());
        ideProjectDependencies.add(new IdeProjectDependency(configuration, resolvedProject));
    }

    return ideProjectDependencies;
}
 
Example #13
Source File: AtlasDependencyGraph.java    From atlas with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Library instantiateLibrary(@NonNull AtlasDependencyGraph.HashableResolvedArtifactResult artifact) {
    Library library;
    ComponentIdentifier id = artifact.getId().getComponentIdentifier();
    String address = AtlasDependencyGraph.computeAddress(artifact);

    if (!(id instanceof ProjectComponentIdentifier) || artifact.isWrappedModule()) {
        if (artifact.getDependencyType() == DependencyType.ANDROID||artifact.getDependencyType() == DependencyType.AWB) {
            File explodedFolder = artifact.getFile();
            library =
                    new com.android.build.gradle.internal.ide.level2.AndroidLibraryImpl(
                            address,
                            artifact.bundleResult != null
                                    ? artifact.bundleResult.getFile()
                                    : explodedFolder, // fallback so that the value is non-null
                            explodedFolder,
                            findLocalJarsAsStrings(explodedFolder));
        } else {
            library = new JavaLibraryImpl(address, artifact.getFile());
        }
    } else {
        library =
                new ModuleLibraryImpl(
                        address,
                        ((ProjectComponentIdentifier) id).getProjectPath(),
                        getVariant(artifact));
    }

    synchronized (sGlobalLibrary) {
        sGlobalLibrary.put(library.getArtifactAddress(), library);
    }

    return library;
}
 
Example #14
Source File: PlayApplicationPlugin.java    From playframework with Apache License 2.0 5 votes vote down vote up
@Override
public FileCollectionInternal createDelegate() {
    Set<File> files = new HashSet<>();
    for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
        if ((artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) == matchProjectComponents) {
            files.add(artifact.getFile());
        }
    }
    return ImmutableFileCollection.of(Collections.unmodifiableSet(files));
}
 
Example #15
Source File: PlayDistributionPlugin.java    From playframework with Apache License 2.0 5 votes vote down vote up
static String renameForProject(ProjectComponentIdentifier id, File file) {
    String fileName = file.getName();
    if (shouldBeRenamed(file)) {
        String projectPath = id.getProjectPath();
        projectPath = projectPathToSafeFileName(projectPath);
        return maybePrefix(projectPath, file);
    }
    return fileName;
}
 
Example #16
Source File: ProjectArtifactResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean isProjectModule(ComponentIdentifier componentId) {
    return componentId instanceof ProjectComponentIdentifier;
}
 
Example #17
Source File: ProjectArtifactResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean isProjectModule(ComponentIdentifier componentId) {
    return componentId instanceof ProjectComponentIdentifier;
}
 
Example #18
Source File: DefaultProjectComponentIdentifier.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ProjectComponentIdentifier newId(String projectPath) {
    return new DefaultProjectComponentIdentifier(projectPath);
}
 
Example #19
Source File: DefaultProjectComponentIdentifier.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ProjectComponentIdentifier newId(String projectPath) {
    return new DefaultProjectComponentIdentifier(projectPath);
}
 
Example #20
Source File: DefaultProjectComponentIdentifier.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ProjectComponentIdentifier newId(String projectPath) {
    return new DefaultProjectComponentIdentifier(projectPath);
}
 
Example #21
Source File: ProjectArtifactResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean isProjectModule(ComponentIdentifier componentId) {
    return componentId instanceof ProjectComponentIdentifier;
}
 
Example #22
Source File: ProjectArtifactResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private boolean isProjectModule(ComponentIdentifier componentId) {
    return componentId instanceof ProjectComponentIdentifier;
}
 
Example #23
Source File: DefaultProjectComponentIdentifier.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ProjectComponentIdentifier newId(String projectPath) {
    return new DefaultProjectComponentIdentifier(projectPath);
}
 
Example #24
Source File: AppModelGradleResolver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void collectDependencies(Configuration config, AppModel.Builder appBuilder,
        final List<Dependency> directExtensionDeps,
        final List<AppDependency> userDeps, Map<AppArtifactKey, AppDependency> versionMap,
        Map<ModuleIdentifier, ModuleVersionIdentifier> userModules) {

    final ResolvedConfiguration resolvedConfig = config.getResolvedConfiguration();
    for (ResolvedArtifact a : resolvedConfig.getResolvedArtifacts()) {
        if (!isDependency(a)) {
            continue;
        }
        userModules.put(getModuleId(a), a.getModuleVersion().getId());

        final AppDependency dependency = toAppDependency(a);
        final AppArtifactKey artifactGa = new AppArtifactKey(dependency.getArtifact().getGroupId(),
                dependency.getArtifact().getArtifactId());

        // If we are running in dev mode we prefer directories of classes and resources over the JARs
        // for local project dependencies
        if (LaunchMode.DEVELOPMENT.equals(launchMode)
                && (a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier)) {
            final Project depProject = project.getRootProject()
                    .findProject(((ProjectComponentIdentifier) a.getId().getComponentIdentifier()).getProjectPath());
            final JavaPluginConvention javaConvention = depProject.getConvention().findPlugin(JavaPluginConvention.class);
            if (javaConvention != null) {
                SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                final PathsCollection.Builder paths = PathsCollection.builder();
                final Path classesDir = Paths
                        .get(QuarkusGradleUtils.getClassesDir(mainSourceSet, depProject.getBuildDir(), false));
                if (Files.exists(classesDir)) {
                    paths.add(classesDir);
                }
                for (File resourcesDir : mainSourceSet.getResources().getSourceDirectories()) {
                    if (resourcesDir.exists()) {
                        paths.add(resourcesDir.toPath());
                    }
                }
                dependency.getArtifact().setPaths(paths.build());
            }
        }

        if (!dependency.getArtifact().isResolved()) {
            throw new IllegalStateException("Failed to resolve " + a.getId());
        }

        userDeps.add(dependency);
        versionMap.put(artifactGa, dependency);
    }

    collectExtensionDeps(resolvedConfig.getFirstLevelModuleDependencies(), versionMap, appBuilder, directExtensionDeps,
            true, new HashSet<>());
}