Search in sources :

Example 1 with DefaultExternalDependencyId

use of org.jetbrains.plugins.gradle.DefaultExternalDependencyId in project intellij-community by JetBrains.

the class GradleProjectResolverUtil method buildDependencies.

public static void buildDependencies(@NotNull ProjectResolverContext resolverCtx, @NotNull Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap, @NotNull final Map<String, String> artifactsMap, @NotNull DataNode<? extends ExternalEntityData> ownerDataNode, @NotNull Collection<ExternalDependency> dependencies, @Nullable DataNode<ProjectData> ideProject) throws IllegalStateException {
    Map<ExternalDependencyId, ExternalDependency> dependencyMap = ContainerUtil.newHashMap();
    Queue<ExternalDependency> queue = ContainerUtil.newLinkedList(dependencies);
    while (!queue.isEmpty()) {
        final ExternalDependency dependency = queue.remove();
        ExternalDependency seenDependency = dependencyMap.get(dependency.getId());
        if (seenDependency != null) {
            if (dependency instanceof ExternalLibraryDependency) {
                if (seenDependency instanceof ExternalLibraryDependency && !FileUtil.filesEqual(((ExternalLibraryDependency) seenDependency).getFile(), ((ExternalLibraryDependency) dependency).getFile())) {
                    DefaultExternalMultiLibraryDependency mergedDependency = new DefaultExternalMultiLibraryDependency();
                    mergedDependency.setName(dependency.getId().getName());
                    mergedDependency.setGroup(dependency.getId().getGroup());
                    mergedDependency.setVersion(dependency.getId().getVersion());
                    mergedDependency.setPackaging(dependency.getId().getPackaging());
                    mergedDependency.setClassifier(dependency.getId().getClassifier());
                    mergedDependency.setScope(dependency.getScope());
                    mergedDependency.setClasspathOrder(dependency.getClasspathOrder());
                    mergedDependency.getDependencies().addAll(dependency.getDependencies());
                    mergedDependency.getFiles().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) seenDependency).getFile(), ((ExternalLibraryDependency) dependency).getFile()));
                    mergedDependency.getSources().addAll((ContainerUtil.packNullables(((ExternalLibraryDependency) seenDependency).getSource(), ((ExternalLibraryDependency) dependency).getSource())));
                    mergedDependency.getJavadoc().addAll((ContainerUtil.packNullables(((ExternalLibraryDependency) seenDependency).getJavadoc(), ((ExternalLibraryDependency) dependency).getJavadoc())));
                    dependencyMap.put(dependency.getId(), mergedDependency);
                    continue;
                } else if (seenDependency instanceof DefaultExternalMultiLibraryDependency) {
                    DefaultExternalMultiLibraryDependency mergedDependency = (DefaultExternalMultiLibraryDependency) seenDependency;
                    mergedDependency.getFiles().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) dependency).getFile()));
                    mergedDependency.getSources().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) dependency).getSource()));
                    mergedDependency.getJavadoc().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) dependency).getJavadoc()));
                    continue;
                }
            }
            DependencyScope prevScope = seenDependency.getScope() == null ? DependencyScope.COMPILE : DependencyScope.valueOf(seenDependency.getScope());
            DependencyScope currentScope = dependency.getScope() == null ? DependencyScope.COMPILE : DependencyScope.valueOf(dependency.getScope());
            if (prevScope.isForProductionCompile())
                continue;
            if (prevScope.isForProductionRuntime() && currentScope.isForProductionRuntime())
                continue;
        }
        dependencyMap.put(new DefaultExternalDependencyId(dependency.getId()), dependency);
        queue.addAll(dependency.getDependencies());
    }
    doBuildDependencies(resolverCtx, sourceSetMap, artifactsMap, dependencyMap, ownerDataNode, dependencies, ideProject);
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) DefaultExternalDependencyId(org.jetbrains.plugins.gradle.DefaultExternalDependencyId) ExternalDependencyId(org.jetbrains.plugins.gradle.ExternalDependencyId) DefaultExternalDependencyId(org.jetbrains.plugins.gradle.DefaultExternalDependencyId)

Example 2 with DefaultExternalDependencyId

use of org.jetbrains.plugins.gradle.DefaultExternalDependencyId in project intellij-community by JetBrains.

the class ExternalProjectSerializer method configureKryo.

private void configureKryo() {
    myKryo.setAutoReset(true);
    myKryo.setRegistrationRequired(true);
    Log.set(Log.LEVEL_WARN);
    myKryo.register(ArrayList.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new ArrayList();
        }
    });
    myKryo.register(HashMap.class, new MapSerializer() {

        @Override
        protected Map create(Kryo kryo, Input input, Class<Map> type) {
            return new HashMap();
        }
    });
    myKryo.register(HashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(File.class, new FileSerializer());
    myKryo.register(DefaultExternalProject.class, new FieldSerializer<DefaultExternalProject>(myKryo, DefaultExternalProject.class) {

        @Override
        protected DefaultExternalProject create(Kryo kryo, Input input, Class<DefaultExternalProject> type) {
            return new DefaultExternalProject();
        }
    });
    myKryo.register(DefaultExternalTask.class, new FieldSerializer<DefaultExternalTask>(myKryo, DefaultExternalTask.class) {

        @Override
        protected DefaultExternalTask create(Kryo kryo, Input input, Class<DefaultExternalTask> type) {
            return new DefaultExternalTask();
        }
    });
    myKryo.register(DefaultExternalPlugin.class, new FieldSerializer<DefaultExternalPlugin>(myKryo, DefaultExternalPlugin.class) {

        @Override
        protected DefaultExternalPlugin create(Kryo kryo, Input input, Class<DefaultExternalPlugin> type) {
            return new DefaultExternalPlugin();
        }
    });
    myKryo.register(DefaultExternalSourceSet.class, new FieldSerializer<DefaultExternalSourceSet>(myKryo, DefaultExternalSourceSet.class) {

        @Override
        protected DefaultExternalSourceSet create(Kryo kryo, Input input, Class<DefaultExternalSourceSet> type) {
            return new DefaultExternalSourceSet();
        }
    });
    myKryo.register(DefaultExternalSourceDirectorySet.class, new FieldSerializer<DefaultExternalSourceDirectorySet>(myKryo, DefaultExternalSourceDirectorySet.class) {

        @Override
        protected DefaultExternalSourceDirectorySet create(Kryo kryo, Input input, Class<DefaultExternalSourceDirectorySet> type) {
            return new DefaultExternalSourceDirectorySet();
        }
    });
    myKryo.register(DefaultExternalFilter.class, new FieldSerializer<DefaultExternalFilter>(myKryo, DefaultExternalFilter.class) {

        @Override
        protected DefaultExternalFilter create(Kryo kryo, Input input, Class<DefaultExternalFilter> type) {
            return new DefaultExternalFilter();
        }
    });
    myKryo.register(ExternalSystemSourceType.class, new DefaultSerializers.EnumSerializer(ExternalSystemSourceType.class));
    myKryo.register(DefaultExternalProjectDependency.class, new FieldSerializer<DefaultExternalProjectDependency>(myKryo, DefaultExternalProjectDependency.class) {

        @Override
        protected DefaultExternalProjectDependency create(Kryo kryo, Input input, Class<DefaultExternalProjectDependency> type) {
            return new DefaultExternalProjectDependency();
        }
    });
    myKryo.register(DefaultFileCollectionDependency.class, new FieldSerializer<DefaultFileCollectionDependency>(myKryo, DefaultFileCollectionDependency.class) {

        @Override
        protected DefaultFileCollectionDependency create(Kryo kryo, Input input, Class<DefaultFileCollectionDependency> type) {
            return new DefaultFileCollectionDependency();
        }
    });
    myKryo.register(DefaultExternalLibraryDependency.class, new FieldSerializer<DefaultExternalLibraryDependency>(myKryo, DefaultExternalLibraryDependency.class) {

        @Override
        protected DefaultExternalLibraryDependency create(Kryo kryo, Input input, Class<DefaultExternalLibraryDependency> type) {
            return new DefaultExternalLibraryDependency();
        }
    });
    myKryo.register(DefaultUnresolvedExternalDependency.class, new FieldSerializer<DefaultUnresolvedExternalDependency>(myKryo, DefaultUnresolvedExternalDependency.class) {

        @Override
        protected DefaultUnresolvedExternalDependency create(Kryo kryo, Input input, Class<DefaultUnresolvedExternalDependency> type) {
            return new DefaultUnresolvedExternalDependency();
        }
    });
    myKryo.register(DefaultExternalDependencyId.class, new FieldSerializer<DefaultExternalDependencyId>(myKryo, DefaultExternalDependencyId.class) {

        @Override
        protected DefaultExternalDependencyId create(Kryo kryo, Input input, Class<DefaultExternalDependencyId> type) {
            return new DefaultExternalDependencyId();
        }
    });
    myKryo.register(LinkedHashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new LinkedHashSet();
        }
    });
    myKryo.register(HashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(THashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new THashSet();
        }
    });
    myKryo.register(Set.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(THashMap.class, new MapSerializer() {

        @Override
        protected Map create(Kryo kryo, Input input, Class<Map> type) {
            return new THashMap();
        }
    });
}
Also used : THashMap(gnu.trove.THashMap) DefaultExternalDependencyId(org.jetbrains.plugins.gradle.DefaultExternalDependencyId) Input(com.esotericsoftware.kryo.io.Input) MapSerializer(com.esotericsoftware.kryo.serializers.MapSerializer) THashSet(gnu.trove.THashSet) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ExternalSystemSourceType(com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType) THashMap(gnu.trove.THashMap) DefaultSerializers(com.esotericsoftware.kryo.serializers.DefaultSerializers) CollectionSerializer(com.esotericsoftware.kryo.serializers.CollectionSerializer) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

DefaultExternalDependencyId (org.jetbrains.plugins.gradle.DefaultExternalDependencyId)2 Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 CollectionSerializer (com.esotericsoftware.kryo.serializers.CollectionSerializer)1 DefaultSerializers (com.esotericsoftware.kryo.serializers.DefaultSerializers)1 MapSerializer (com.esotericsoftware.kryo.serializers.MapSerializer)1 ExternalSystemSourceType (com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType)1 DependencyScope (com.intellij.openapi.roots.DependencyScope)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 ExternalDependencyId (org.jetbrains.plugins.gradle.ExternalDependencyId)1