From f309c374040dae7ee7aba46ee519841124733a97 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Sun, 18 Feb 2018 08:51:42 +0300 Subject: [PATCH 01/18] Gradle native plugin prototype --- .idea/modules.xml | 2 + .../gradle/native/intellij.gradle.native.iml | 18 ++ .../META-INF/gradle-native-plugin.xml | 24 +++ .../project/GradleNativeProjectResolver.java | 98 ++++++++++ .../intellij.gradle.native.tooling.iml | 16 ++ ...plugins.gradle.tooling.ModelBuilderService | 17 ++ .../tooling/src/builder/CppModelBuilder.java | 174 ++++++++++++++++++ .../tooling/src/model/CompilerDetails.java | 22 +++ .../native/tooling/src/model/CppBinary.java | 44 +++++ .../native/tooling/src/model/CppProject.java | 15 ++ .../tooling/src/model/FilePatternSet.java | 13 ++ .../tooling/src/model/LinkerDetails.java | 14 ++ .../tooling/src/model/SourceFolder.java | 14 ++ .../src/model/impl/CompilerDetailsImpl.java | 59 ++++++ .../tooling/src/model/impl/CppBinaryImpl.java | 84 +++++++++ .../src/model/impl/CppProjectImpl.java | 37 ++++ .../src/model/impl/FilePatternSetImpl.java | 49 +++++ .../src/model/impl/LinkerDetailsImpl.java | 29 +++ .../src/model/impl/SourceFolderImpl.java | 50 +++++ 19 files changed, 779 insertions(+) create mode 100644 plugins/gradle/native/intellij.gradle.native.iml create mode 100644 plugins/gradle/native/resources/META-INF/gradle-native-plugin.xml create mode 100644 plugins/gradle/native/src/project/GradleNativeProjectResolver.java create mode 100644 plugins/gradle/native/tooling/intellij.gradle.native.tooling.iml create mode 100644 plugins/gradle/native/tooling/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService create mode 100644 plugins/gradle/native/tooling/src/builder/CppModelBuilder.java create mode 100644 plugins/gradle/native/tooling/src/model/CompilerDetails.java create mode 100644 plugins/gradle/native/tooling/src/model/CppBinary.java create mode 100644 plugins/gradle/native/tooling/src/model/CppProject.java create mode 100644 plugins/gradle/native/tooling/src/model/FilePatternSet.java create mode 100644 plugins/gradle/native/tooling/src/model/LinkerDetails.java create mode 100644 plugins/gradle/native/tooling/src/model/SourceFolder.java create mode 100644 plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java create mode 100644 plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java create mode 100644 plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java create mode 100644 plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java create mode 100644 plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java create mode 100644 plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 0e824e3880a6..4f63fb23d71a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -438,6 +438,8 @@ + + diff --git a/plugins/gradle/native/intellij.gradle.native.iml b/plugins/gradle/native/intellij.gradle.native.iml new file mode 100644 index 000000000000..417f3fe90af0 --- /dev/null +++ b/plugins/gradle/native/intellij.gradle.native.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/gradle/native/resources/META-INF/gradle-native-plugin.xml b/plugins/gradle/native/resources/META-INF/gradle-native-plugin.xml new file mode 100644 index 000000000000..e2c86d1a939e --- /dev/null +++ b/plugins/gradle/native/resources/META-INF/gradle-native-plugin.xml @@ -0,0 +1,24 @@ + + + + + org.jetbrains.plugins.gradle + + + + + diff --git a/plugins/gradle/native/src/project/GradleNativeProjectResolver.java b/plugins/gradle/native/src/project/GradleNativeProjectResolver.java new file mode 100644 index 000000000000..eb285cf4deca --- /dev/null +++ b/plugins/gradle/native/src/project/GradleNativeProjectResolver.java @@ -0,0 +1,98 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.project; + +import com.intellij.openapi.externalSystem.model.DataNode; +import com.intellij.openapi.externalSystem.model.Key; +import com.intellij.openapi.externalSystem.model.ProjectKeys; +import com.intellij.openapi.externalSystem.model.project.ContentRootData; +import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType; +import com.intellij.openapi.externalSystem.model.project.ModuleData; +import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; +import com.intellij.openapi.externalSystem.util.Order; +import com.intellij.util.containers.ContainerUtil; +import org.gradle.tooling.model.idea.IdeaModule; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.builder.CppModelBuilder; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.*; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl.*; +import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension; +import org.jetbrains.plugins.gradle.util.GradleConstants; + +import java.io.File; +import java.util.Collections; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +@Order(ExternalSystemConstants.UNORDERED) +public class GradleNativeProjectResolver extends AbstractProjectResolverExtension { + @NotNull public static final Key CPP_PROJECT = Key.create(CppProject.class, ProjectKeys.MODULE.getProcessingWeight() + 1); + + @Override + public void populateModuleContentRoots(@NotNull IdeaModule gradleModule, @NotNull DataNode ideModule) { + CppProject cppProject = resolverCtx.getExtraProject(gradleModule, CppProject.class); + if (cppProject != null) { + // store a local process copy of the object to get rid of proxy types for further serialization + ideModule.createChild(CPP_PROJECT, copy(cppProject)); + + Set sourceFolders = cppProject.getSourceFolders(); + for (SourceFolder folder : sourceFolders) { + File baseDir = folder.getBaseDir(); + ContentRootData ideContentRoot = new ContentRootData(GradleConstants.SYSTEM_ID, baseDir.getAbsolutePath()); + ideContentRoot.storePath(ExternalSystemSourceType.SOURCE, baseDir.getAbsolutePath()); + ideModule.createChild(ProjectKeys.CONTENT_ROOT, ideContentRoot); + } + } + + nextResolver.populateModuleContentRoots(gradleModule, ideModule); + } + + @NotNull + @Override + public Set getExtraProjectModelClasses() { + return Collections.singleton(CppProject.class); + } + + @NotNull + @Override + public Set getToolingExtensionsClasses() { + return ContainerUtil.set( + // native-gradle-tooling jar + CppModelBuilder.class + ); + } + + @NotNull + private static CppProject copy(@NotNull CppProject cppProject) { + CppProjectImpl copy = new CppProjectImpl(); + for (CppBinary binary : cppProject.getBinaries()) { + copy.addBinary(copy(binary)); + } + for (SourceFolder sourceFolder : cppProject.getSourceFolders()) { + copy.addSourceFolder(copy(sourceFolder)); + } + return copy; + } + + private static SourceFolder copy(SourceFolder sourceFolder) { + FilePatternSet patterns = sourceFolder.getPatterns(); + return new SourceFolderImpl(sourceFolder.getBaseDir(), new FilePatternSetImpl(patterns.getIncludes(), + patterns.getExcludes())); + } + + @NotNull + private static CppBinary copy(@NotNull CppBinary binary) { + return new CppBinaryImpl(binary.getBaseName(), binary.getVariantName(), binary.getSources(), + copy(binary.getCompilerDetails()), copy(binary.getLinkerDetails()), binary.getTargetType()); + } + + private static LinkerDetails copy(LinkerDetails details) { + return new LinkerDetailsImpl(details.getLinkTaskName(), details.getOutputFile()); + } + + private static CompilerDetails copy(CompilerDetails details) { + return new CompilerDetailsImpl(details.getCompileTaskName(), details.getExecutable(), details.getArgs(), + details.getIncludePath(), details.getSystemIncludes()); + } +} diff --git a/plugins/gradle/native/tooling/intellij.gradle.native.tooling.iml b/plugins/gradle/native/tooling/intellij.gradle.native.tooling.iml new file mode 100644 index 000000000000..bb894f80c4cb --- /dev/null +++ b/plugins/gradle/native/tooling/intellij.gradle.native.tooling.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/gradle/native/tooling/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/gradle/native/tooling/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 000000000000..0754e2ae444c --- /dev/null +++ b/plugins/gradle/native/tooling/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1,17 @@ +# Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +# +# Copyright 2000-2018 JetBrains s.r.o. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.jetbrains.plugins.gradle.nativeplatform.tooling.builder.CppModelBuilder diff --git a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java new file mode 100644 index 000000000000..19adc22a1d12 --- /dev/null +++ b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java @@ -0,0 +1,174 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.builder; + +import org.gradle.api.Project; +import org.gradle.api.component.SoftwareComponent; +import org.gradle.api.file.FileCollection; +import org.gradle.api.internal.file.FileCollectionInternal; +import org.gradle.api.internal.file.FileCollectionVisitor; +import org.gradle.api.internal.file.FileTreeInternal; +import org.gradle.api.internal.file.collections.DirectoryFileTree; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.util.PatternSet; +import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils; +import org.gradle.internal.os.OperatingSystem; +import org.gradle.language.cpp.CppBinary; +import org.gradle.language.cpp.CppComponent; +import org.gradle.language.cpp.CppSharedLibrary; +import org.gradle.language.cpp.CppStaticLibrary; +import org.gradle.language.cpp.plugins.CppBasePlugin; +import org.gradle.language.cpp.tasks.CppCompile; +import org.gradle.language.nativeplatform.ComponentWithExecutable; +import org.gradle.nativeplatform.tasks.LinkExecutable; +import org.gradle.nativeplatform.toolchain.Clang; +import org.gradle.nativeplatform.toolchain.Gcc; +import org.gradle.nativeplatform.toolchain.NativeToolChain; +import org.gradle.nativeplatform.toolchain.internal.ToolType; +import org.gradle.nativeplatform.toolchain.internal.tools.CommandLineToolSearchResult; +import org.gradle.nativeplatform.toolchain.internal.tools.ToolSearchPath; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CompilerDetails; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppBinary.TargetType; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppProject; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.LinkerDetails; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl.*; +import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; + +import java.io.File; +import java.util.*; + +/** + * The prototype of the C++ project gradle tooling model builder. + * This implementation should be moved or replaced with the similar model builder from the Gradle distribution. + * + * @author Vladislav.Soroka + */ +public class CppModelBuilder implements ModelBuilderService { + + @Override + public boolean canBuild(String modelName) { + return CppProject.class.getName().equals(modelName); + } + + @Nullable + @Override + public Object buildAll(final String modelName, final Project project) { + final CppBasePlugin cppPlugin = project.getPlugins().findPlugin(CppBasePlugin.class); + if (cppPlugin == null) return null; + + final CppProjectImpl cppProject = new CppProjectImpl(); + for (SoftwareComponent component : project.getComponents()) { + if (component instanceof CppComponent) { + File cppCompilerExecutable = null; + CppComponent cppComponent = (CppComponent)component; + for (CppBinary cppBinary : cppComponent.getBinaries().get()) { + if (cppCompilerExecutable == null) { + cppCompilerExecutable = findCppCompilerExecutable(cppBinary); + } + + List compilerArgs = new ArrayList(); + Set compileIncludePath = cppBinary.getCompileIncludePath().getFiles(); + + Set sources = cppBinary.getCppSource().getFiles(); + String baseName = cppBinary.getBaseName().getOrElse(""); + String variantName = StringUtils.removeStart(cppBinary.getName(), "main"); + String compileTaskName = null; + Set systemIncludes = new LinkedHashSet(); + Provider compileTask = cppBinary.getCompileTask(); + if (compileTask.isPresent()) { + CppCompile cppCompile = compileTask.get(); + compileTaskName = cppCompile.getPath(); + compilerArgs.addAll(cppCompile.getCompilerArgs().getOrElse(Collections.emptyList())); + systemIncludes.addAll(cppCompile.getIncludes().getFiles()); + } + + File executableFile = null; + String linkTaskName = null; + boolean isExecutable = cppBinary instanceof ComponentWithExecutable; + if (isExecutable) { + Provider fileProvider = ((ComponentWithExecutable)cppBinary).getLinkTask(); + if (fileProvider.isPresent()) { + LinkExecutable linkExecutable = fileProvider.get(); + linkTaskName = linkExecutable.getPath(); + executableFile = linkExecutable.getBinaryFile().getAsFile().getOrNull(); + } + } + + TargetType targetType = null; + if (isExecutable) { + targetType = TargetType.EXECUTABLE; + } + else if (cppBinary instanceof CppSharedLibrary) { + targetType = TargetType.SHARED_LIBRARY; + } + else if (cppBinary instanceof CppStaticLibrary) { + targetType = TargetType.STATIC_LIBRARY; + } + + CompilerDetails compilerDetails = + new CompilerDetailsImpl(compileTaskName, cppCompilerExecutable, compilerArgs, compileIncludePath, systemIncludes); + LinkerDetails linkerDetails = new LinkerDetailsImpl(linkTaskName, executableFile); + cppProject.addBinary(new CppBinaryImpl(baseName, variantName, sources, compilerDetails, linkerDetails, targetType)); + } + + addSourceFolders(cppProject, cppComponent); + } + } + + return cppProject; + } + + private static void addSourceFolders(final CppProjectImpl cppProject, CppComponent cppComponent) { + for (File dir : cppComponent.getPrivateHeaderDirs()) { + cppProject.addSourceFolder( + new SourceFolderImpl(dir, new FilePatternSetImpl(Collections.emptySet(), Collections.emptySet()))); + } + + FileCollection cppSource = cppComponent.getCppSource(); + // try to resolve cpp source folders + ((FileCollectionInternal)cppSource).visitRootElements(new FileCollectionVisitor() { + @Override + public void visitCollection(FileCollectionInternal internal) { + } + + @Override + public void visitTree(FileTreeInternal internal) { + } + + @Override + public void visitDirectoryTree(DirectoryFileTree tree) { + File dir = tree.getDir(); + PatternSet patterns = tree.getPatterns(); + cppProject.addSourceFolder(new SourceFolderImpl(dir, new FilePatternSetImpl(patterns.getIncludes(), patterns.getExcludes()))); + } + }); + } + + @Nullable + private static File findCppCompilerExecutable(CppBinary cppBinary) { + NativeToolChain toolChain = cppBinary.getToolChain(); + String exeName; + if (toolChain instanceof Gcc) { + exeName = "g++"; + } + else if (toolChain instanceof Clang) { + exeName = "clang++"; + } + else { + return null; + } + ToolSearchPath toolSearchPath = new ToolSearchPath(OperatingSystem.current()); + CommandLineToolSearchResult searchResult = toolSearchPath.locate(ToolType.CPP_COMPILER, exeName); + return searchResult.isAvailable() ? searchResult.getTool() : null; + } + + @NotNull + @Override + public ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) { + return ErrorMessageBuilder.create( + project, e, "C++ project import errors" + ).withDescription("Unable to import C++ project"); + } +} diff --git a/plugins/gradle/native/tooling/src/model/CompilerDetails.java b/plugins/gradle/native/tooling/src/model/CompilerDetails.java new file mode 100644 index 000000000000..d197250c91df --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/CompilerDetails.java @@ -0,0 +1,22 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; + +import java.io.File; +import java.io.Serializable; +import java.util.List; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public interface CompilerDetails extends Serializable { + String getCompileTaskName(); + + Set getIncludePath(); + + Set getSystemIncludes(); + + File getExecutable(); + + List getArgs(); +} diff --git a/plugins/gradle/native/tooling/src/model/CppBinary.java b/plugins/gradle/native/tooling/src/model/CppBinary.java new file mode 100644 index 000000000000..b010751f3aaa --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/CppBinary.java @@ -0,0 +1,44 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; + +import java.io.File; +import java.io.Serializable; +import java.util.List; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public interface CppBinary extends Serializable { + /** + * Returns the base name of this component. This is used by Gradle to calculate output file names. + */ + String getBaseName(); + + /** + * Returns the binary variant name, e.g. Debug, Release etc. + */ + String getVariantName(); + + Set getSources(); + + CompilerDetails getCompilerDetails(); + + Set getCompileIncludePath(); + + File getCompilerExecutable(); + + List getCompilerArgs(); + + LinkerDetails getLinkerDetails(); + + File getOutputFile(); + + TargetType getTargetType(); + + enum TargetType { + EXECUTABLE, + STATIC_LIBRARY, + SHARED_LIBRARY + } +} diff --git a/plugins/gradle/native/tooling/src/model/CppProject.java b/plugins/gradle/native/tooling/src/model/CppProject.java new file mode 100644 index 000000000000..bb5dddac2e07 --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/CppProject.java @@ -0,0 +1,15 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; + + +import java.io.Serializable; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public interface CppProject extends Serializable { + Set getSourceFolders(); + + Set getBinaries(); +} diff --git a/plugins/gradle/native/tooling/src/model/FilePatternSet.java b/plugins/gradle/native/tooling/src/model/FilePatternSet.java new file mode 100644 index 000000000000..170562a408bf --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/FilePatternSet.java @@ -0,0 +1,13 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; + +import java.io.Serializable; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public interface FilePatternSet extends Serializable { + Set getIncludes(); + Set getExcludes(); +} diff --git a/plugins/gradle/native/tooling/src/model/LinkerDetails.java b/plugins/gradle/native/tooling/src/model/LinkerDetails.java new file mode 100644 index 000000000000..c79655e8f151 --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/LinkerDetails.java @@ -0,0 +1,14 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; + +import java.io.File; +import java.io.Serializable; + +/** + * @author Vladislav.Soroka + */ +public interface LinkerDetails extends Serializable { + File getOutputFile(); + + String getLinkTaskName(); +} diff --git a/plugins/gradle/native/tooling/src/model/SourceFolder.java b/plugins/gradle/native/tooling/src/model/SourceFolder.java new file mode 100644 index 000000000000..0192238b3abf --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/SourceFolder.java @@ -0,0 +1,14 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; + +import java.io.File; +import java.io.Serializable; + +/** + * @author Vladislav.Soroka + */ +public interface SourceFolder extends Serializable { + File getBaseDir(); + + FilePatternSet getPatterns(); +} diff --git a/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java b/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java new file mode 100644 index 000000000000..6d90f4db0271 --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java @@ -0,0 +1,59 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; + +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CompilerDetails; + +import java.io.File; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public class CompilerDetailsImpl implements CompilerDetails { + + private final Set myIncludePath; + private final Set mySystemIncludes; + private final String myCompileTaskName; + private File myExecutable; + private final List myArgs; + + public CompilerDetailsImpl(String compileTaskName, + File executable, + List args, + Set includePath, + Set systemIncludes) { + myCompileTaskName = compileTaskName; + myExecutable = executable; + myArgs = args; + myIncludePath = new LinkedHashSet(includePath); + mySystemIncludes = new LinkedHashSet(systemIncludes); + } + + @Override + public String getCompileTaskName() { + return myCompileTaskName; + } + + @Override + public Set getIncludePath() { + return Collections.unmodifiableSet(myIncludePath); + } + + @Override + public Set getSystemIncludes() { + return Collections.unmodifiableSet(mySystemIncludes); + } + + @Override + public File getExecutable() { + return myExecutable; + } + + @Override + public List getArgs() { + return Collections.unmodifiableList(myArgs); + } +} diff --git a/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java b/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java new file mode 100644 index 000000000000..67b7f56286b7 --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java @@ -0,0 +1,84 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; + +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CompilerDetails; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppBinary; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.LinkerDetails; + +import java.io.File; +import java.util.*; + +/** + * @author Vladislav.Soroka + */ +public class CppBinaryImpl implements CppBinary { + private final String myBaseName; + private final String myVariantName; + private final Set mySources; + private final CompilerDetails myCompilerDetails; + private final LinkerDetails myLinkerDetails; + private final TargetType myTargetType; + + public CppBinaryImpl(String baseName, String variantName, + Collection sources, + CompilerDetails compilerDetails, + LinkerDetails linkerDetails, + TargetType targetType) { + myBaseName = baseName; + myVariantName = variantName; + mySources = new LinkedHashSet(sources); + myCompilerDetails = compilerDetails; + myLinkerDetails = linkerDetails; + myTargetType = targetType; + } + + @Override + public String getBaseName() { + return myBaseName; + } + + @Override + public String getVariantName() { + return myVariantName; + } + + @Override + public Set getSources() { + return Collections.unmodifiableSet(mySources); + } + + @Override + public CompilerDetails getCompilerDetails() { + return myCompilerDetails; + } + + @Override + public Set getCompileIncludePath() { + return myCompilerDetails.getIncludePath(); + } + + @Override + public File getCompilerExecutable() { + return myCompilerDetails.getExecutable(); + } + + @Override + public List getCompilerArgs() { + return myCompilerDetails.getArgs(); + } + + @Override + public LinkerDetails getLinkerDetails() { + return myLinkerDetails; + } + + @Override + public File getOutputFile() { + return myLinkerDetails.getOutputFile(); + } + + @Override + public TargetType getTargetType() { + return myTargetType; + } +} diff --git a/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java b/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java new file mode 100644 index 000000000000..7072207cb65a --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java @@ -0,0 +1,37 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; + +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppBinary; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppProject; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.SourceFolder; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public class CppProjectImpl implements CppProject { + + private final Set mySourceFolders = new LinkedHashSet(); + private final Set binaries = new LinkedHashSet(); + + @Override + public Set getSourceFolders() { + return Collections.unmodifiableSet(mySourceFolders); + } + + public void addSourceFolder(SourceFolder folder) { + mySourceFolders.add(folder); + } + + @Override + public Set getBinaries() { + return Collections.unmodifiableSet(binaries); + } + + public void addBinary(CppBinary binary) { + binaries.add(binary); + } +} diff --git a/plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java b/plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java new file mode 100644 index 000000000000..98eeaab8e0df --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java @@ -0,0 +1,49 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; + +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.FilePatternSet; + +import java.util.Set; + +/** + * @author Vladislav.Soroka + */ +public class FilePatternSetImpl implements FilePatternSet { + private final Set includes; + private final Set excludes; + + public FilePatternSetImpl(Set includes, Set excludes) { + this.includes = includes; + this.excludes = excludes; + } + + @Override + public Set getIncludes() { + return includes; + } + + @Override + public Set getExcludes() { + return excludes; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + FilePatternSetImpl set = (FilePatternSetImpl)o; + + if (includes != null ? !includes.equals(set.includes) : set.includes != null) return false; + if (excludes != null ? !excludes.equals(set.excludes) : set.excludes != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = includes != null ? includes.hashCode() : 0; + result = 31 * result + (excludes != null ? excludes.hashCode() : 0); + return result; + } +} diff --git a/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java b/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java new file mode 100644 index 000000000000..3992f34d28ed --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java @@ -0,0 +1,29 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; + +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.LinkerDetails; + +import java.io.File; + +/** + * @author Vladislav.Soroka + */ +public class LinkerDetailsImpl implements LinkerDetails { + private final String myLinkTaskName; + private final File myOutputFile; + + public LinkerDetailsImpl(String linkTaskName, File outputFile) { + myLinkTaskName = linkTaskName; + myOutputFile = outputFile; + } + + @Override + public File getOutputFile() { + return myOutputFile; + } + + @Override + public String getLinkTaskName() { + return myLinkTaskName; + } +} diff --git a/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java b/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java new file mode 100644 index 000000000000..6a19753ef770 --- /dev/null +++ b/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java @@ -0,0 +1,50 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; + +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.FilePatternSet; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.SourceFolder; + +import java.io.File; + +/** + * @author Vladislav.Soroka + */ +public class SourceFolderImpl implements SourceFolder { + private final File myBaseDir; + private final FilePatternSet myPatterns; + + public SourceFolderImpl(File dir, FilePatternSet patterns) { + myBaseDir = dir; + myPatterns = patterns; + } + + @Override + public File getBaseDir() { + return myBaseDir; + } + + @Override + public FilePatternSet getPatterns() { + return myPatterns; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SourceFolderImpl folder = (SourceFolderImpl)o; + + if (myBaseDir != null ? !myBaseDir.equals(folder.myBaseDir) : folder.myBaseDir != null) return false; + if (myPatterns != null ? !myPatterns.equals(folder.myPatterns) : folder.myPatterns != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myBaseDir != null ? myBaseDir.hashCode() : 0; + result = 31 * result + (myPatterns != null ? myPatterns.hashCode() : 0); + return result; + } +} From 3e4c080abd6c537a7a168c3dc7a1cbb088ebbb78 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Mon, 19 Feb 2018 08:48:27 +0300 Subject: [PATCH 02/18] Gradle: extract gradle-java --- plugins/gradle/intellij.gradle.tests.iml | 2 +- .../java/src/service/project/JavaGradleProjectResolver.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/gradle/intellij.gradle.tests.iml b/plugins/gradle/intellij.gradle.tests.iml index 8a30037b3e04..bc4aacbf169d 100644 --- a/plugins/gradle/intellij.gradle.tests.iml +++ b/plugins/gradle/intellij.gradle.tests.iml @@ -14,7 +14,7 @@ - + diff --git a/plugins/gradle/java/src/service/project/JavaGradleProjectResolver.java b/plugins/gradle/java/src/service/project/JavaGradleProjectResolver.java index 1e327b5036e6..61c2bd46df3c 100644 --- a/plugins/gradle/java/src/service/project/JavaGradleProjectResolver.java +++ b/plugins/gradle/java/src/service/project/JavaGradleProjectResolver.java @@ -52,6 +52,8 @@ public class JavaGradleProjectResolver extends AbstractProjectResolverExtension } ideProject.createChild(JavaProjectData.KEY, javaProjectData); + + nextResolver.populateProjectExtraModels(gradleProject, ideProject); } @Override From 1149535540fd0e1ae53c3d38a023e11ddcbb49dd Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Mon, 19 Feb 2018 08:53:18 +0300 Subject: [PATCH 03/18] Gradle: extract gradle-java; test fix --- .../codeInsight/actions/AddGradleDslDependencyActionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gradle/java/testSources/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionTest.java b/plugins/gradle/java/testSources/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionTest.java index e5bfb432df42..a78650a21a77 100644 --- a/plugins/gradle/java/testSources/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionTest.java +++ b/plugins/gradle/java/testSources/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionTest.java @@ -51,7 +51,7 @@ public class AddGradleDslDependencyActionTest extends LightPlatformCodeInsightFi @Override protected String getBasePath() { - return "/plugins/gradle/testData"; + return "/plugins/gradle/java/testData"; } @Override From 21a82ef2048887f0b86e651fa546684cd908215f Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Sun, 4 Mar 2018 07:45:59 +0300 Subject: [PATCH 04/18] Gradle-native: expose compiler working dir --- .../src/project/GradleNativeProjectResolver.java | 2 +- .../native/tooling/src/builder/CppModelBuilder.java | 7 +++++-- .../native/tooling/src/model/CompilerDetails.java | 2 ++ .../tooling/src/model/impl/CompilerDetailsImpl.java | 10 +++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/gradle/native/src/project/GradleNativeProjectResolver.java b/plugins/gradle/native/src/project/GradleNativeProjectResolver.java index eb285cf4deca..948702e65357 100644 --- a/plugins/gradle/native/src/project/GradleNativeProjectResolver.java +++ b/plugins/gradle/native/src/project/GradleNativeProjectResolver.java @@ -92,7 +92,7 @@ public class GradleNativeProjectResolver extends AbstractProjectResolverExtensio } private static CompilerDetails copy(CompilerDetails details) { - return new CompilerDetailsImpl(details.getCompileTaskName(), details.getExecutable(), details.getArgs(), + return new CompilerDetailsImpl(details.getCompileTaskName(), details.getExecutable(), details.getWorkingDir(), details.getArgs(), details.getIncludePath(), details.getSystemIncludes()); } } diff --git a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java index 19adc22a1d12..f6b27eeb1980 100644 --- a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java +++ b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java @@ -107,8 +107,11 @@ public class CppModelBuilder implements ModelBuilderService { targetType = TargetType.STATIC_LIBRARY; } - CompilerDetails compilerDetails = - new CompilerDetailsImpl(compileTaskName, cppCompilerExecutable, compilerArgs, compileIncludePath, systemIncludes); + // resolve compiler working dir as compiler executable file parent dir + // https://github.com/gradle/gradle/blob/7422d5fc2e04d564dfd73bc539a37b62f8e2113a/subprojects/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/metadata/AbstractMetadataProvider.java#L61 + File compilerWorkingDir = cppCompilerExecutable == null ? null : cppCompilerExecutable.getParentFile(); + CompilerDetails compilerDetails = new CompilerDetailsImpl( + compileTaskName, cppCompilerExecutable, compilerWorkingDir, compilerArgs, compileIncludePath, systemIncludes); LinkerDetails linkerDetails = new LinkerDetailsImpl(linkTaskName, executableFile); cppProject.addBinary(new CppBinaryImpl(baseName, variantName, sources, compilerDetails, linkerDetails, targetType)); } diff --git a/plugins/gradle/native/tooling/src/model/CompilerDetails.java b/plugins/gradle/native/tooling/src/model/CompilerDetails.java index d197250c91df..db7d9e83e1fa 100644 --- a/plugins/gradle/native/tooling/src/model/CompilerDetails.java +++ b/plugins/gradle/native/tooling/src/model/CompilerDetails.java @@ -18,5 +18,7 @@ public interface CompilerDetails extends Serializable { File getExecutable(); + File getWorkingDir(); + List getArgs(); } diff --git a/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java b/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java index 6d90f4db0271..409f7475607f 100644 --- a/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java @@ -17,16 +17,19 @@ public class CompilerDetailsImpl implements CompilerDetails { private final Set myIncludePath; private final Set mySystemIncludes; private final String myCompileTaskName; - private File myExecutable; + private final File myExecutable; + private final File myWorkingDir; private final List myArgs; public CompilerDetailsImpl(String compileTaskName, File executable, + File workingDir, List args, Set includePath, Set systemIncludes) { myCompileTaskName = compileTaskName; myExecutable = executable; + myWorkingDir = workingDir; myArgs = args; myIncludePath = new LinkedHashSet(includePath); mySystemIncludes = new LinkedHashSet(systemIncludes); @@ -52,6 +55,11 @@ public class CompilerDetailsImpl implements CompilerDetails { return myExecutable; } + @Override + public File getWorkingDir() { + return myWorkingDir; + } + @Override public List getArgs() { return Collections.unmodifiableList(myArgs); From afaf54878af51743ba89e5a828116e1227a1cae7 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Sun, 4 Mar 2018 16:07:13 +0300 Subject: [PATCH 05/18] Gradle-native as a separate plugin --- platform/platform-resources/src/META-INF/PlatformLangPlugin.xml | 2 -- .../platform-resources/src/idea/PlatformLangActionManager.xml | 1 - 2 files changed, 3 deletions(-) diff --git a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml index 431309f292d5..e7aca583fd3c 100644 --- a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml @@ -14,14 +14,12 @@ - - diff --git a/platform/platform-resources/src/idea/PlatformLangActionManager.xml b/platform/platform-resources/src/idea/PlatformLangActionManager.xml index 5a6453c9756b..6c15d7e123fa 100644 --- a/platform/platform-resources/src/idea/PlatformLangActionManager.xml +++ b/platform/platform-resources/src/idea/PlatformLangActionManager.xml @@ -27,7 +27,6 @@ - From 142d65cb0ac7f4ae9e8f477974a50c466030cb1e Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Sun, 4 Mar 2018 18:51:17 +0300 Subject: [PATCH 06/18] Gradle-native: CppProject tooling model: use copying constructors --- .../project/GradleNativeProjectResolver.java | 40 ++----------------- .../src/model/impl/CompilerDetailsImpl.java | 5 +++ .../tooling/src/model/impl/CppBinaryImpl.java | 5 +++ .../src/model/impl/CppProjectImpl.java | 9 +++++ .../src/model/impl/LinkerDetailsImpl.java | 4 ++ .../src/model/impl/SourceFolderImpl.java | 5 +++ 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/plugins/gradle/native/src/project/GradleNativeProjectResolver.java b/plugins/gradle/native/src/project/GradleNativeProjectResolver.java index 948702e65357..924d0786f02e 100644 --- a/plugins/gradle/native/src/project/GradleNativeProjectResolver.java +++ b/plugins/gradle/native/src/project/GradleNativeProjectResolver.java @@ -13,8 +13,9 @@ import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.idea.IdeaModule; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.nativeplatform.tooling.builder.CppModelBuilder; -import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.*; -import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl.*; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppProject; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.SourceFolder; +import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl.CppProjectImpl; import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -34,7 +35,7 @@ public class GradleNativeProjectResolver extends AbstractProjectResolverExtensio CppProject cppProject = resolverCtx.getExtraProject(gradleModule, CppProject.class); if (cppProject != null) { // store a local process copy of the object to get rid of proxy types for further serialization - ideModule.createChild(CPP_PROJECT, copy(cppProject)); + ideModule.createChild(CPP_PROJECT, new CppProjectImpl(cppProject)); Set sourceFolders = cppProject.getSourceFolders(); for (SourceFolder folder : sourceFolders) { @@ -62,37 +63,4 @@ public class GradleNativeProjectResolver extends AbstractProjectResolverExtensio CppModelBuilder.class ); } - - @NotNull - private static CppProject copy(@NotNull CppProject cppProject) { - CppProjectImpl copy = new CppProjectImpl(); - for (CppBinary binary : cppProject.getBinaries()) { - copy.addBinary(copy(binary)); - } - for (SourceFolder sourceFolder : cppProject.getSourceFolders()) { - copy.addSourceFolder(copy(sourceFolder)); - } - return copy; - } - - private static SourceFolder copy(SourceFolder sourceFolder) { - FilePatternSet patterns = sourceFolder.getPatterns(); - return new SourceFolderImpl(sourceFolder.getBaseDir(), new FilePatternSetImpl(patterns.getIncludes(), - patterns.getExcludes())); - } - - @NotNull - private static CppBinary copy(@NotNull CppBinary binary) { - return new CppBinaryImpl(binary.getBaseName(), binary.getVariantName(), binary.getSources(), - copy(binary.getCompilerDetails()), copy(binary.getLinkerDetails()), binary.getTargetType()); - } - - private static LinkerDetails copy(LinkerDetails details) { - return new LinkerDetailsImpl(details.getLinkTaskName(), details.getOutputFile()); - } - - private static CompilerDetails copy(CompilerDetails details) { - return new CompilerDetailsImpl(details.getCompileTaskName(), details.getExecutable(), details.getWorkingDir(), details.getArgs(), - details.getIncludePath(), details.getSystemIncludes()); - } } diff --git a/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java b/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java index 409f7475607f..edcfec23348b 100644 --- a/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/CompilerDetailsImpl.java @@ -35,6 +35,11 @@ public class CompilerDetailsImpl implements CompilerDetails { mySystemIncludes = new LinkedHashSet(systemIncludes); } + public CompilerDetailsImpl(CompilerDetails details) { + this(details.getCompileTaskName(), details.getExecutable(), details.getWorkingDir(), details.getArgs(), + details.getIncludePath(), details.getSystemIncludes()); + } + @Override public String getCompileTaskName() { return myCompileTaskName; diff --git a/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java b/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java index 67b7f56286b7..ab6272989f11 100644 --- a/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/CppBinaryImpl.java @@ -32,6 +32,11 @@ public class CppBinaryImpl implements CppBinary { myTargetType = targetType; } + public CppBinaryImpl(CppBinary binary) { + this(binary.getBaseName(), binary.getVariantName(), binary.getSources(), + new CompilerDetailsImpl(binary.getCompilerDetails()), new LinkerDetailsImpl(binary.getLinkerDetails()), binary.getTargetType()); + } + @Override public String getBaseName() { return myBaseName; diff --git a/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java b/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java index 7072207cb65a..5699721087c8 100644 --- a/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java @@ -17,6 +17,15 @@ public class CppProjectImpl implements CppProject { private final Set mySourceFolders = new LinkedHashSet(); private final Set binaries = new LinkedHashSet(); + public CppProjectImpl(CppProject cppProject) { + for (CppBinary binary : cppProject.getBinaries()) { + addBinary(new CppBinaryImpl(binary)); + } + for (SourceFolder sourceFolder : cppProject.getSourceFolders()) { + addSourceFolder(new SourceFolderImpl(sourceFolder)); + } + } + @Override public Set getSourceFolders() { return Collections.unmodifiableSet(mySourceFolders); diff --git a/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java b/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java index 3992f34d28ed..c884c241c3e5 100644 --- a/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/LinkerDetailsImpl.java @@ -17,6 +17,10 @@ public class LinkerDetailsImpl implements LinkerDetails { myOutputFile = outputFile; } + public LinkerDetailsImpl(LinkerDetails details) { + this(details.getLinkTaskName(), details.getOutputFile()); + } + @Override public File getOutputFile() { return myOutputFile; diff --git a/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java b/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java index 6a19753ef770..9be0ec9ccb26 100644 --- a/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java @@ -18,6 +18,11 @@ public class SourceFolderImpl implements SourceFolder { myPatterns = patterns; } + public SourceFolderImpl(SourceFolder folder) { + this(folder.getBaseDir(), folder.getPatterns() != null + ? new FilePatternSetImpl(folder.getPatterns().getIncludes(), folder.getPatterns().getExcludes()) : null); + } + @Override public File getBaseDir() { return myBaseDir; From bc70445dcc3635782b0b4144faa10f83eb9508ee Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Sun, 4 Mar 2018 19:03:18 +0300 Subject: [PATCH 07/18] Gradle-native: CppProject tooling model: use copying constructors --- .../gradle/native/tooling/src/model/impl/CppProjectImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java b/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java index 5699721087c8..0b824063896f 100644 --- a/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/CppProjectImpl.java @@ -17,6 +17,9 @@ public class CppProjectImpl implements CppProject { private final Set mySourceFolders = new LinkedHashSet(); private final Set binaries = new LinkedHashSet(); + public CppProjectImpl() { + } + public CppProjectImpl(CppProject cppProject) { for (CppBinary binary : cppProject.getBinaries()) { addBinary(new CppBinaryImpl(binary)); From 70711918ac62274786b364f72b35b29a25e670c5 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Sun, 4 Mar 2018 19:05:12 +0300 Subject: [PATCH 08/18] Gradle: move FilePatternSet to common gradle tooling module --- ...esourceCompilerConfigurationGenerator.java | 4 +-- .../tooling/src/builder/CppModelBuilder.java | 1 + .../tooling/src/model/SourceFolder.java | 2 ++ .../src/model/impl/SourceFolderImpl.java | 3 +- .../model/ExternalSourceDirectorySet.java | 3 ++ .../plugins/gradle}/model/FilePatternSet.java | 2 +- .../DefaultExternalSourceDirectorySet.java | 32 ++++++++----------- .../gradle/model}/FilePatternSetImpl.java | 4 +-- 8 files changed, 25 insertions(+), 26 deletions(-) rename plugins/gradle/{native/tooling/src => tooling-extension-api/src/org/jetbrains/plugins/gradle}/model/FilePatternSet.java (83%) rename plugins/gradle/{native/tooling/src/model/impl => tooling-extension-impl/src/org/jetbrains/plugins/gradle/model}/FilePatternSetImpl.java (88%) diff --git a/plugins/gradle/java/src/config/GradleResourceCompilerConfigurationGenerator.java b/plugins/gradle/java/src/config/GradleResourceCompilerConfigurationGenerator.java index 9fa38bafb7db..aa08a95de091 100644 --- a/plugins/gradle/java/src/config/GradleResourceCompilerConfigurationGenerator.java +++ b/plugins/gradle/java/src/config/GradleResourceCompilerConfigurationGenerator.java @@ -273,11 +273,11 @@ public class GradleResourceCompilerConfigurationGenerator { rootConfiguration.targetPath = FileUtil.toSystemIndependentName(target); rootConfiguration.includes.clear(); - for (String include : directorySet.getIncludes()) { + for (String include : directorySet.getPatterns().getIncludes()) { rootConfiguration.includes.add(include.trim()); } rootConfiguration.excludes.clear(); - for (String exclude : directorySet.getExcludes()) { + for (String exclude : directorySet.getPatterns().getExcludes()) { rootConfiguration.excludes.add(exclude.trim()); } if (sourcesDirectorySet != null && sourcesDirectorySet.getSrcDirs().contains(file)) { diff --git a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java index f6b27eeb1980..6f34aa10dada 100644 --- a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java +++ b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java @@ -28,6 +28,7 @@ import org.gradle.nativeplatform.toolchain.internal.tools.CommandLineToolSearchR import org.gradle.nativeplatform.toolchain.internal.tools.ToolSearchPath; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.FilePatternSetImpl; import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CompilerDetails; import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppBinary.TargetType; import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.CppProject; diff --git a/plugins/gradle/native/tooling/src/model/SourceFolder.java b/plugins/gradle/native/tooling/src/model/SourceFolder.java index 0192238b3abf..e7ecff078ac9 100644 --- a/plugins/gradle/native/tooling/src/model/SourceFolder.java +++ b/plugins/gradle/native/tooling/src/model/SourceFolder.java @@ -1,6 +1,8 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; +import org.jetbrains.plugins.gradle.model.FilePatternSet; + import java.io.File; import java.io.Serializable; diff --git a/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java b/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java index 9be0ec9ccb26..8b09e905e4d4 100644 --- a/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java +++ b/plugins/gradle/native/tooling/src/model/impl/SourceFolderImpl.java @@ -1,7 +1,8 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; -import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.FilePatternSet; +import org.jetbrains.plugins.gradle.model.FilePatternSet; +import org.jetbrains.plugins.gradle.model.FilePatternSetImpl; import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.SourceFolder; import java.io.File; diff --git a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalSourceDirectorySet.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalSourceDirectorySet.java index 88b684b6faac..4e9676454b7a 100644 --- a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalSourceDirectorySet.java +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalSourceDirectorySet.java @@ -57,6 +57,9 @@ public interface ExternalSourceDirectorySet extends Serializable { @NotNull Set getIncludes(); + @NotNull + FilePatternSet getPatterns(); + @NotNull List getFilters(); } diff --git a/plugins/gradle/native/tooling/src/model/FilePatternSet.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/FilePatternSet.java similarity index 83% rename from plugins/gradle/native/tooling/src/model/FilePatternSet.java rename to plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/FilePatternSet.java index 170562a408bf..daf01cf112ae 100644 --- a/plugins/gradle/native/tooling/src/model/FilePatternSet.java +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/FilePatternSet.java @@ -1,5 +1,5 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package org.jetbrains.plugins.gradle.nativeplatform.tooling.model; +package org.jetbrains.plugins.gradle.model; import java.io.Serializable; import java.util.Set; diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java index d102773caa53..07a311c433ed 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java @@ -33,10 +33,7 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector private Set mySrcDirs; private File myOutputDir; private final List myGradleOutputDirs; - @NotNull - private Set myExcludes; - @NotNull - private Set myIncludes; + private final FilePatternSet myPatterns; @NotNull private List myFilters; @@ -44,10 +41,9 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector public DefaultExternalSourceDirectorySet() { mySrcDirs = new HashSet(); - myExcludes = new HashSet(); - myIncludes = new HashSet(); myFilters = new ArrayList(); myGradleOutputDirs = new ArrayList(); + myPatterns = new FilePatternSetImpl(new LinkedHashSet(), new LinkedHashSet()); } public DefaultExternalSourceDirectorySet(ExternalSourceDirectorySet sourceDirectorySet) { @@ -57,8 +53,8 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector myOutputDir = sourceDirectorySet.getOutputDir(); myGradleOutputDirs.addAll(sourceDirectorySet.getGradleOutputDirs()); - myExcludes = new HashSet(sourceDirectorySet.getExcludes()); - myIncludes = new HashSet(sourceDirectorySet.getIncludes()); + myPatterns.getIncludes().addAll(sourceDirectorySet.getPatterns().getIncludes()); + myPatterns.getExcludes().addAll(sourceDirectorySet.getPatterns().getExcludes()); for (ExternalFilter filter : sourceDirectorySet.getFilters()) { myFilters.add(new DefaultExternalFilter(filter)); } @@ -117,28 +113,26 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector return myInheritedCompilerOutput; } - public void setInheritedCompilerOutput(boolean inheritedCompilerOutput) { - myInheritedCompilerOutput = inheritedCompilerOutput; + @NotNull + @Override + public Set getExcludes() { + return myPatterns.getExcludes(); } @NotNull @Override public Set getIncludes() { - return myIncludes; - } - - public void setIncludes(@NotNull Set includes) { - myIncludes = includes; + return myPatterns.getIncludes(); } @NotNull @Override - public Set getExcludes() { - return myExcludes; + public FilePatternSet getPatterns() { + return myPatterns; } - public void setExcludes(@NotNull Set excludes) { - myExcludes = excludes; + public void setInheritedCompilerOutput(boolean inheritedCompilerOutput) { + myInheritedCompilerOutput = inheritedCompilerOutput; } @NotNull diff --git a/plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/FilePatternSetImpl.java similarity index 88% rename from plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java rename to plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/FilePatternSetImpl.java index 98eeaab8e0df..46c8f8f2c07c 100644 --- a/plugins/gradle/native/tooling/src/model/impl/FilePatternSetImpl.java +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/FilePatternSetImpl.java @@ -1,7 +1,5 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package org.jetbrains.plugins.gradle.nativeplatform.tooling.model.impl; - -import org.jetbrains.plugins.gradle.nativeplatform.tooling.model.FilePatternSet; +package org.jetbrains.plugins.gradle.model; import java.util.Set; From a892cf62eb0c45ca54b08e7bc78eaf310fb34596 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Mon, 5 Mar 2018 14:56:22 +0300 Subject: [PATCH 09/18] Gradle: fix plugin optional dependencies configuration (cherry picked from commit 37389f3) --- ...ugin.xml => gradle-groovy-integration.xml} | 67 +------------------ .../META-INF/gradle-java-integration.xml | 63 +++++++++++++++++ .../plugin-resources/META-INF/plugin.xml | 21 +----- 3 files changed, 68 insertions(+), 83 deletions(-) rename plugins/gradle/plugin-resources/META-INF/{gradle-java-plugin.xml => gradle-groovy-integration.xml} (51%) create mode 100644 plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml diff --git a/plugins/gradle/plugin-resources/META-INF/gradle-java-plugin.xml b/plugins/gradle/plugin-resources/META-INF/gradle-groovy-integration.xml similarity index 51% rename from plugins/gradle/plugin-resources/META-INF/gradle-java-plugin.xml rename to plugins/gradle/plugin-resources/META-INF/gradle-groovy-integration.xml index e5efa4832003..bc6c118bf216 100644 --- a/plugins/gradle/plugin-resources/META-INF/gradle-java-plugin.xml +++ b/plugins/gradle/plugin-resources/META-INF/gradle-groovy-integration.xml @@ -1,40 +1,16 @@ - + - - - + org.jetbrains.plugins.gradle org.intellij.groovy - org.jetbrains.idea.maven - com.intellij.modules.coverage - - - - - - @@ -49,35 +25,17 @@ - - - - - - - - - - - - - - - - @@ -90,27 +48,6 @@ bundle="org.jetbrains.plugins.gradle.codeInspection.GradleInspectionBundle" key="multiple.repository.urls" groupKey="group.names.probable.bugs" groupBundle="messages.InspectionsBundle" enabledByDefault="true" level="WARNING" implementationClass="org.jetbrains.plugins.gradle.codeInspection.MultipleRepositoryUrlsInspection"/> - - - - - - - - - - - - - - - diff --git a/plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml b/plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml new file mode 100644 index 000000000000..1f6281574e22 --- /dev/null +++ b/plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml @@ -0,0 +1,63 @@ + + + + + org.jetbrains.plugins.gradle + org.jetbrains.idea.maven + com.intellij.modules.coverage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/gradle/plugin-resources/META-INF/plugin.xml b/plugins/gradle/plugin-resources/META-INF/plugin.xml index a113efd1689d..554d92ce48e6 100644 --- a/plugins/gradle/plugin-resources/META-INF/plugin.xml +++ b/plugins/gradle/plugin-resources/META-INF/plugin.xml @@ -1,20 +1,4 @@ - - - + Gradle org.jetbrains.plugins.gradle JetBrains @@ -37,7 +21,8 @@ com.intellij.modules.lang - com.intellij.modules.java + com.intellij.modules.java + org.intellij.groovy i18n.GradleBundle From 7ac47ff8f81959e7f107aa4165d3f08cb2e11db8 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Fri, 9 Mar 2018 08:13:10 +0300 Subject: [PATCH 10/18] Gradle: add setter for internal DefaultExternalSourceDirectorySet to fix compatibility with groovy code --- .../project/data/ExternalProjectSerializer.java | 10 ++++++++++ .../model/DefaultExternalSourceDirectorySet.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/ExternalProjectSerializer.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/ExternalProjectSerializer.java index 0fa3323e4bb7..5774c9b33b19 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/ExternalProjectSerializer.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/ExternalProjectSerializer.java @@ -190,6 +190,16 @@ public class ExternalProjectSerializer { } ); + myKryo.register( + FilePatternSetImpl.class, + new FieldSerializer(myKryo, FilePatternSetImpl.class) { + @Override + protected FilePatternSetImpl create(Kryo kryo, Input input, Class type) { + return new FilePatternSetImpl(new LinkedHashSet<>(), new LinkedHashSet<>()); + } + } + ); + myKryo.register(LinkedHashSet.class, new CollectionSerializer() { @Override protected Collection create(Kryo kryo, Input input, Class type) { diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java index 07a311c433ed..09caf28d63e8 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalSourceDirectorySet.java @@ -119,12 +119,22 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector return myPatterns.getExcludes(); } + public void setExcludes(Set excludes) { + myPatterns.getExcludes().clear(); + myPatterns.getExcludes().addAll(excludes); + } + @NotNull @Override public Set getIncludes() { return myPatterns.getIncludes(); } + public void setIncludes(Set includes) { + myPatterns.getIncludes().clear(); + myPatterns.getIncludes().addAll(includes); + } + @NotNull @Override public FilePatternSet getPatterns() { From 426b8f0c7456f395ffa5ac1f93e7f3d130923254 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Fri, 9 Mar 2018 08:40:17 +0300 Subject: [PATCH 11/18] IDEA-187835 External build systems support for non-java IDEs --- .../ExternalSystemRunConfiguration.java | 58 +++++++++++-------- .../manage/AbstractModuleDataService.java | 6 +- .../ExternalSystemExtensionPoints.xml | 37 ++++++------ 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemRunConfiguration.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemRunConfiguration.java index 87a88682139f..fba213bb6be9 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemRunConfiguration.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemRunConfiguration.java @@ -63,6 +63,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.ArrayUtil; +import com.intellij.util.PlatformUtils; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.net.NetUtils; @@ -267,30 +268,7 @@ public class ExternalSystemRunConfiguration extends LocatableConfigurationBase i throw new ExecutionException(ExternalSystemBundle.message("run.error.undefined.task")); } - final JavaParameters extensionsJP = new JavaParameters(); - final RunConfigurationExtension[] extensions = Extensions.getExtensions(RunConfigurationExtension.EP_NAME); - for (RunConfigurationExtension ext : extensions) { - ext.updateJavaParameters(myConfiguration, extensionsJP, myEnv.getRunnerSettings()); - } - - String jvmAgentSetup; - if (myDebugPort > 0) { - jvmAgentSetup = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=" + myDebugPort; - } - else { - ParametersList parametersList = extensionsJP.getVMParametersList(); - final ParametersList data = myEnv.getUserData(ExternalSystemTaskExecutionSettings.JVM_AGENT_SETUP_KEY); - if (data != null) { - parametersList.addAll(data.getList()); - } - for (String parameter : parametersList.getList()) { - if (parameter.startsWith("-agentlib:")) continue; - if (parameter.startsWith("-agentpath:")) continue; - if (parameter.startsWith("-javaagent:")) continue; - throw new ExecutionException(ExternalSystemBundle.message("run.invalid.jvm.agent.configuration", parameter)); - } - jvmAgentSetup = parametersList.getParametersString(); - } + String jvmAgentSetup = getJvmAgentSetup(); ApplicationManager.getApplication().assertIsDispatchThread(); FileDocumentManager.getInstance().saveAllDocuments(); @@ -454,6 +432,38 @@ public class ExternalSystemRunConfiguration extends LocatableConfigurationBase i return executionResult; } + @Nullable + private String getJvmAgentSetup() throws ExecutionException { + // todo [Vlad, IDEA-187832]: extract to `external-system-java` module + if(!PlatformUtils.isIntelliJ()) return null; + + final JavaParameters extensionsJP = new JavaParameters(); + final RunConfigurationExtension[] extensions = Extensions.getExtensions(RunConfigurationExtension.EP_NAME); + for (RunConfigurationExtension ext : extensions) { + ext.updateJavaParameters(myConfiguration, extensionsJP, myEnv.getRunnerSettings()); + } + + String jvmAgentSetup; + if (myDebugPort > 0) { + jvmAgentSetup = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=" + myDebugPort; + } + else { + ParametersList parametersList = extensionsJP.getVMParametersList(); + final ParametersList data = myEnv.getUserData(ExternalSystemTaskExecutionSettings.JVM_AGENT_SETUP_KEY); + if (data != null) { + parametersList.addAll(data.getList()); + } + for (String parameter : parametersList.getList()) { + if (parameter.startsWith("-agentlib:")) continue; + if (parameter.startsWith("-agentpath:")) continue; + if (parameter.startsWith("-javaagent:")) continue; + throw new ExecutionException(ExternalSystemBundle.message("run.invalid.jvm.agent.configuration", parameter)); + } + jvmAgentSetup = parametersList.getParametersString(); + } + return jvmAgentSetup; + } + private BuildProgressListener createBuildView(ExternalSystemTaskId id, String executionName, String workingDir, diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/AbstractModuleDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/AbstractModuleDataService.java index 86a1f8e7b78f..57b650adea9d 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/AbstractModuleDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/AbstractModuleDataService.java @@ -105,7 +105,11 @@ public abstract class AbstractModuleDataService extends Ab setModuleOptions(module, node); ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module); syncPaths(module, modifiableRootModel, node.getData()); - setLanguageLevel(modifiableRootModel, node.getData()); + + if(ModuleTypeId.JAVA_MODULE.equals(module.getModuleTypeName())) { + // todo [Vlad, IDEA-187832]: extract to `external-system-java` module + setLanguageLevel(modifiableRootModel, node.getData()); + } setSdk(modifiableRootModel, node.getData()); } } diff --git a/platform/platform-resources/src/META-INF/ExternalSystemExtensionPoints.xml b/platform/platform-resources/src/META-INF/ExternalSystemExtensionPoints.xml index ae12151e0429..aadd25701337 100644 --- a/platform/platform-resources/src/META-INF/ExternalSystemExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/ExternalSystemExtensionPoints.xml @@ -1,35 +1,38 @@ - - + - - - - - - - - - - - - - - - + + \ No newline at end of file From c45f7f064f0f59fc9d68dd5759954d5948077f40 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Fri, 9 Mar 2018 08:40:36 +0300 Subject: [PATCH 12/18] IDEA-187833 Gradle: provide the plugin distribution for non-java IDEs --- plugins/gradle/plugin-resources/META-INF/plugin.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/gradle/plugin-resources/META-INF/plugin.xml b/plugins/gradle/plugin-resources/META-INF/plugin.xml index 554d92ce48e6..ad855af13337 100644 --- a/plugins/gradle/plugin-resources/META-INF/plugin.xml +++ b/plugins/gradle/plugin-resources/META-INF/plugin.xml @@ -1,4 +1,4 @@ - + Gradle org.jetbrains.plugins.gradle JetBrains @@ -21,6 +21,9 @@ com.intellij.modules.lang + + + com.intellij.modules.java org.intellij.groovy From 9e3d7bb19d95fca33a6e1a57eb7b70cb67761f48 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 14 Mar 2018 07:14:51 +0300 Subject: [PATCH 13/18] Grade: workaround for java IDE dependent gradle extensions (cherry picked from commit c6b1b3b) --- .../settings/ExternalProjectSettings.java | 3 +- .../util/ExternalSystemApiUtil.java | 14 +++++++ .../ExternalSystemRunConfiguration.java | 2 +- .../plugins/gradle/GradleManager.java | 38 ++++++++++++++++++- .../project/GradleProjectResolver.java | 14 ++++++- .../settings/GradleProjectSettings.java | 3 +- 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/ExternalProjectSettings.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/ExternalProjectSettings.java index d8926c31ed90..2156b25ea2a3 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/ExternalProjectSettings.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/ExternalProjectSettings.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.externalSystem.settings; +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.util.Comparing; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +46,7 @@ public abstract class ExternalProjectSettings implements Comparable compute() { List result = ContainerUtilRt.newArrayList(); - Collections.addAll(result, GradleProjectResolverExtension.EP_NAME.getExtensions()); + + // It's possible usecase when 'java' subsystem dependent plugins bundled with the non-java IDE using fat plugin distribution. + // This approach can lead to unwanted/incompatible extensions to be loaded. + // The workaround extensionsFilter should be removed when the IntelliJ java subsystem will become a regular plugin + // or those plugins will be fixed using the optional plugin dependency on 'org.jetbrains.plugins.gradle.java' + boolean isJavaIde = ExternalSystemApiUtil.isJavaCompatibleIde(); + if(!isJavaIde) { + ExtensionPoint point = + Extensions.getRootArea().getExtensionPoint(GradleProjectResolverExtension.EP_NAME); + if(point instanceof ExtensionPointImpl) { + ((ExtensionPointImpl)point).removeUnloadableExtensions(); + } + } + Set javaIdeDependentExtensions = ContainerUtil.set( + "org.jetbrains.kotlin.idea.configuration.KotlinGradleProjectResolverExtension", + "org.jetbrains.kotlin.kapt.idea.KaptProjectResolverExtension", + "org.jetbrains.kotlin.allopen.ide.AllOpenProjectResolverExtension", + "org.jetbrains.kotlin.noarg.ide.NoArgProjectResolverExtension", + "org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverProjectResolverExtension" + ); + Predicate extensionsFilter = ext -> + isJavaIde || !javaIdeDependentExtensions.contains(ext.getClass().getName()); + + ExtensionPoint extensionPoint = + Extensions.getRootArea().getExtensionPoint(GradleProjectResolverExtension.EP_NAME); + extensionPoint.addExtensionPointListener(new ExtensionPointListener.Adapter<>()); + + Arrays.stream(GradleProjectResolverExtension.EP_NAME.getExtensions()) + .filter(extensionsFilter) + .forEach(result::add); + ExternalSystemApiUtil.orderAwareSort(result); return result; } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java index e7e9b0f4209e..97285d81e3f3 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java @@ -218,7 +218,12 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver buildActionExecutor = resolverCtx.getConnection().action(projectImportAction); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleProjectSettings.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleProjectSettings.java index eeb97fe8a81d..d63336fee280 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleProjectSettings.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleProjectSettings.java @@ -3,6 +3,7 @@ package org.jetbrains.plugins.gradle.settings; import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil; import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings; +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.util.SmartList; import com.intellij.util.ThreeState; import com.intellij.util.containers.ContainerUtil; @@ -25,7 +26,7 @@ public class GradleProjectSettings extends ExternalProjectSettings { @Nullable private String myGradleJvm = ExternalSystemJdkUtil.USE_PROJECT_JDK; @Nullable private DistributionType distributionType; private boolean disableWrapperSourceDistributionNotification; - private boolean resolveModulePerSourceSet = true; + private boolean resolveModulePerSourceSet = ExternalSystemApiUtil.isJavaCompatibleIde(); @Nullable private CompositeBuild myCompositeBuild; private ThreeState storeProjectFilesExternally = ThreeState.NO; From 6262e682e18b6b631743cf2f337d2cbaee2f468f Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 14 Mar 2018 16:28:49 +0300 Subject: [PATCH 14/18] External System: mark temporary method as deprecated to avoid non-intentional usages (cherry picked from commit 90762be) --- .../openapi/externalSystem/util/ExternalSystemApiUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java index 9769576522bd..e3da91c3605c 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java @@ -878,6 +878,7 @@ public class ExternalSystemApiUtil { * @return check if the current IDE is compatible with the 'java' IntelliJ subsystem */ @ApiStatus.Experimental + @Deprecated public static boolean isJavaCompatibleIde() { return isIdeaUltimate() || isIdeaCommunity() || "AndroidStudio".equals(getPlatformPrefix()); } From b369fe5a7766f0dafab6da26c291d34e50d365dc Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Fri, 23 Mar 2018 13:19:30 +0300 Subject: [PATCH 15/18] Cleanup (cherry picked from commit b36dfa5) --- .../src/org/jetbrains/plugins/gradle/GradleManager.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/GradleManager.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/GradleManager.java index 77b26304ecfc..44383c4b21bb 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/GradleManager.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/GradleManager.java @@ -140,10 +140,6 @@ public class GradleManager Predicate extensionsFilter = ext -> isJavaIde || !javaIdeDependentExtensions.contains(ext.getClass().getName()); - ExtensionPoint extensionPoint = - Extensions.getRootArea().getExtensionPoint(GradleProjectResolverExtension.EP_NAME); - extensionPoint.addExtensionPointListener(new ExtensionPointListener.Adapter<>()); - Arrays.stream(GradleProjectResolverExtension.EP_NAME.getExtensions()) .filter(extensionsFilter) .forEach(result::add); From 83eaf42f6cc27f79f34ddc1896b8dcfd626f9707 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 18 Apr 2018 19:25:43 +0300 Subject: [PATCH 16/18] Gradle/Native: merge fixes --- .../META-INF/gradle-java-integration.xml | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml diff --git a/plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml b/plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml deleted file mode 100644 index 1f6281574e22..000000000000 --- a/plugins/gradle/plugin-resources/META-INF/gradle-java-integration.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - org.jetbrains.plugins.gradle - org.jetbrains.idea.maven - com.intellij.modules.coverage - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 915371a51a176e8041a002406f5342d724d80cda Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 18 Apr 2018 20:13:44 +0300 Subject: [PATCH 17/18] External system: hide attach project action for non-java for the time being --- .../action/AttachExternalProjectAction.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java index 5c2b659b4a91..9dced4ce3ba2 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java @@ -20,6 +20,7 @@ import com.intellij.ide.actions.ImportModuleAction; import com.intellij.ide.util.newProjectWizard.AddModuleWizard; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.externalSystem.ExternalSystemManager; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.model.ProjectSystemId; @@ -43,14 +44,22 @@ public class AttachExternalProjectAction extends AnAction { @Override public void update(AnActionEvent e) { + Presentation presentation = e.getPresentation(); + // todo [Vlad, IDEA-187835]: provide java subsystem independent implementation + if (!ExternalSystemApiUtil.isJavaCompatibleIde()) { + presentation.setVisible(false); + presentation.setEnabled(false); + return; + } + ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(e.getDataContext()); if (externalSystemId != null) { String name = externalSystemId.getReadableName(); - e.getPresentation().setText(ExternalSystemBundle.message("action.attach.external.project.text", name)); - e.getPresentation().setDescription(ExternalSystemBundle.message("action.attach.external.project.description", name)); + presentation.setText(ExternalSystemBundle.message("action.attach.external.project.text", name)); + presentation.setDescription(ExternalSystemBundle.message("action.attach.external.project.description", name)); } - - e.getPresentation().setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add); + + presentation.setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add); } @Override From 00c0a001dd0c6298770d1a98cb353dcbec23822e Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 18 Apr 2018 21:14:59 +0300 Subject: [PATCH 18/18] Gradle/Native: fix link task api change in Gradle 4.7 --- .../tooling/src/builder/CppModelBuilder.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java index 6f34aa10dada..2ebdc7d2bb63 100644 --- a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java +++ b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java @@ -4,6 +4,7 @@ package org.jetbrains.plugins.gradle.nativeplatform.tooling.builder; import org.gradle.api.Project; import org.gradle.api.component.SoftwareComponent; import org.gradle.api.file.FileCollection; +import org.gradle.api.file.RegularFileProperty; import org.gradle.api.internal.file.FileCollectionInternal; import org.gradle.api.internal.file.FileCollectionVisitor; import org.gradle.api.internal.file.FileTreeInternal; @@ -26,6 +27,7 @@ import org.gradle.nativeplatform.toolchain.NativeToolChain; import org.gradle.nativeplatform.toolchain.internal.ToolType; import org.gradle.nativeplatform.toolchain.internal.tools.CommandLineToolSearchResult; import org.gradle.nativeplatform.toolchain.internal.tools.ToolSearchPath; +import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.FilePatternSetImpl; @@ -93,7 +95,7 @@ public class CppModelBuilder implements ModelBuilderService { if (fileProvider.isPresent()) { LinkExecutable linkExecutable = fileProvider.get(); linkTaskName = linkExecutable.getPath(); - executableFile = linkExecutable.getBinaryFile().getAsFile().getOrNull(); + executableFile = getExecutableFile(linkExecutable); } } @@ -124,6 +126,29 @@ public class CppModelBuilder implements ModelBuilderService { return cppProject; } + @Nullable + private static File getExecutableFile(LinkExecutable linkExecutable) { + File executableFile; + RegularFileProperty binaryFile = null; + if (GradleVersion.current().compareTo(GradleVersion.version("4.7")) < 0) { + binaryFile = linkExecutable.getBinaryFile(); + } + else { + try { + Object linkedFile = linkExecutable.getClass().getMethod("getLinkedFile").invoke(linkExecutable); + if (linkedFile instanceof RegularFileProperty) { + binaryFile = (RegularFileProperty)linkedFile; + } + } + catch (Exception e) { + //noinspection CallToPrintStackTrace + e.printStackTrace(); + } + } + executableFile = binaryFile != null ? binaryFile.getAsFile().getOrNull() : null; + return executableFile; + } + private static void addSourceFolders(final CppProjectImpl cppProject, CppComponent cppComponent) { for (File dir : cppComponent.getPrivateHeaderDirs()) { cppProject.addSourceFolder(