Search in sources :

Example 1 with IdeaSingleEntryLibraryDependency

use of org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency in project meghanada-server by mopemope.

the class GradleProject method analyzeDependencies.

private Set<ProjectDependency> analyzeDependencies(final IdeaModule ideaModule) {
    final Set<ProjectDependency> dependencies = new HashSet<>(16);
    for (final IdeaDependency dependency : ideaModule.getDependencies().getAll()) {
        if (dependency instanceof IdeaSingleEntryLibraryDependency) {
            final IdeaSingleEntryLibraryDependency libraryDependency = (IdeaSingleEntryLibraryDependency) dependency;
            final File file = libraryDependency.getFile();
            final GradleModuleVersion gradleModuleVersion = libraryDependency.getGradleModuleVersion();
            String scope = libraryDependency.getScope().getScope();
            String id;
            String version;
            if (isNull(gradleModuleVersion)) {
                id = file.getName();
                // dummy
                version = "1.0.0";
            } else {
                id = String.join(":", gradleModuleVersion.getGroup(), gradleModuleVersion.getName(), gradleModuleVersion.getVersion());
                version = gradleModuleVersion.getVersion();
            }
            if (isNull(scope)) {
                scope = "COMPILE";
            }
            if (!scope.equals("PROVIDED")) {
                final ProjectDependency.Type type = ProjectDependency.getFileType(file);
                final ProjectDependency projectDependency = new ProjectDependency(id, scope, version, file, type);
                dependencies.add(projectDependency);
            }
        } else if (dependency instanceof IdeaModuleDependency) {
            final IdeaModuleDependency moduleDependency = (IdeaModuleDependency) dependency;
            final String scope = moduleDependency.getScope().getScope();
            final String moduleName = moduleDependency.getTargetModuleName();
            this.allModules.computeIfPresent(moduleName, (key, projectRoot) -> {
                final ProjectDependency projectDependency = new ProjectDependency(key, scope, "1.0.0", projectRoot, ProjectDependency.Type.PROJECT);
                dependencies.add(projectDependency);
                return projectRoot;
            });
            if (!this.allModules.containsKey(moduleName)) {
                log.warn("missing module:{}", moduleName);
            }
        } else {
            log.warn("dep ??? class={}", dependency.getClass());
        }
    }
    return dependencies;
}
Also used : Config.debugTimeItF(meghanada.config.Config.debugTimeItF) IdeaDependency(org.gradle.tooling.model.idea.IdeaDependency) ProjectParseException(meghanada.project.ProjectParseException) IdeaJavaLanguageSettings(org.gradle.tooling.model.idea.IdeaJavaLanguageSettings) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) StringUtils(org.apache.commons.lang3.StringUtils) PipedInputStream(java.io.PipedInputStream) Map(java.util.Map) GradleConnector(org.gradle.tooling.GradleConnector) Objects.isNull(java.util.Objects.isNull) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Splitter(com.google.common.base.Splitter) GradleVersion(org.gradle.util.GradleVersion) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) BuildLauncher(org.gradle.tooling.BuildLauncher) CompileResult(meghanada.analyze.CompileResult) AndroidProject(com.android.builder.model.AndroidProject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ResultHandler(org.gradle.tooling.ResultHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) IdeaContentRoot(org.gradle.tooling.model.idea.IdeaContentRoot) IdeaSingleEntryLibraryDependency(org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) Project(meghanada.project.Project) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) GradleConnectionException(org.gradle.tooling.GradleConnectionException) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Files(com.google.common.io.Files) ConfigFactory(com.typesafe.config.ConfigFactory) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) IdeaModuleDependency(org.gradle.tooling.model.idea.IdeaModuleDependency) DomainObjectSet(org.gradle.tooling.model.DomainObjectSet) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion) ProjectConnection(org.gradle.tooling.ProjectConnection) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) IdeaSingleEntryLibraryDependency(org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency) IdeaDependency(org.gradle.tooling.model.idea.IdeaDependency) IdeaModuleDependency(org.gradle.tooling.model.idea.IdeaModuleDependency) ProjectDependency(meghanada.project.ProjectDependency) File(java.io.File) HashSet(java.util.HashSet) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)1 Joiner (com.google.common.base.Joiner)1 Splitter (com.google.common.base.Splitter)1 Files (com.google.common.io.Files)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects.isNull (java.util.Objects.isNull)1 Objects.nonNull (java.util.Objects.nonNull)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1