diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ModuleDependencyData.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ModuleDependencyData.java index b97378d112e7..77fb70041996 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ModuleDependencyData.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ModuleDependencyData.java @@ -2,6 +2,8 @@ package com.intellij.openapi.externalSystem.model.project; import org.jetbrains.annotations.NotNull; +import java.util.Collection; + /** * @author Denis Zhdanov * @since 8/10/11 6:40 PM @@ -10,6 +12,7 @@ public class ModuleDependencyData extends AbstractDependencyData { private static final long serialVersionUID = 1L; private boolean myProductionOnTestDependency; + private Collection myModuleDependencyArtifacts; public ModuleDependencyData(@NotNull ModuleData ownerModule, @NotNull ModuleData module) { super(ownerModule, module); @@ -23,15 +26,31 @@ public class ModuleDependencyData extends AbstractDependencyData { myProductionOnTestDependency = productionOnTestDependency; } + public Collection getModuleDependencyArtifacts() { + return myModuleDependencyArtifacts; + } + + public void setModuleDependencyArtifacts(Collection moduleDependencyArtifacts) { + myModuleDependencyArtifacts = moduleDependencyArtifacts; + } + @Override public boolean equals(Object o) { if (!super.equals(o)) return false; ModuleDependencyData that = (ModuleDependencyData)o; - return myProductionOnTestDependency == that.myProductionOnTestDependency; + if (myProductionOnTestDependency != that.myProductionOnTestDependency) return false; + if (myModuleDependencyArtifacts != null ? !myModuleDependencyArtifacts.equals(that.myModuleDependencyArtifacts) + : that.myModuleDependencyArtifacts != null) { + return false; + } + return true; } @Override public int hashCode() { - return 31 * super.hashCode() + (myProductionOnTestDependency ? 1 : 0); + int result = super.hashCode(); + result = 31 * result + (myProductionOnTestDependency ? 1 : 0); + result = 31 * result + (myModuleDependencyArtifacts != null ? myModuleDependencyArtifacts.hashCode() : 0); + return result; } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java index 8b481884763e..753093996591 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java @@ -17,21 +17,25 @@ package org.jetbrains.plugins.gradle.integrations.javaee; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.model.DataNode; +import com.intellij.openapi.externalSystem.model.project.DependencyData; import com.intellij.openapi.externalSystem.model.project.ModuleData; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; import com.intellij.openapi.externalSystem.util.Order; +import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.util.BooleanFunction; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.idea.IdeaModule; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.data.*; +import org.jetbrains.plugins.gradle.model.ear.EarConfiguration; import org.jetbrains.plugins.gradle.model.web.WebConfiguration; import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension; +import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil; import org.jetbrains.plugins.gradle.util.GradleConstants; -import java.util.Collections; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -47,33 +51,63 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve @Override public void populateModuleExtraModels(@NotNull IdeaModule gradleModule, @NotNull final DataNode ideModule) { - final List warModels; final WebConfiguration webConfiguration = resolverCtx.getExtraProject(gradleModule, WebConfiguration.class); - if (webConfiguration != null) { - warModels = ContainerUtil.map(webConfiguration.getWarModels(), new Function() { - @Override - public War fun(WebConfiguration.WarModel model) { - War war = new War(model.getWarName(), model.getWebAppDirName(), model.getWebAppDir()); - war.setWebXml(model.getWebXml()); - war.setWebResources(map(model.getWebResources())); - war.setClasspath(model.getClasspath()); - war.setManifestContent(model.getManifestContent()); - return war; - } - }); - final String mainSourceSetModuleId = ideModule.getData().getId() + ":main"; - DataNode targetModuleNode = - ExternalSystemApiUtil.find(ideModule, GradleSourceSetData.KEY, new BooleanFunction>() { - @Override - public boolean fun(DataNode node) { - return mainSourceSetModuleId.equals(node.getData().getId()); - } - }); - if(targetModuleNode == null) { - targetModuleNode = ideModule; + final NotNullLazyValue> findTargetModuleNode = new NotNullLazyValue>() { + @NotNull + @Override + protected DataNode compute() { + final String mainSourceSetModuleId = ideModule.getData().getId() + ":main"; + DataNode targetModuleNode = + ExternalSystemApiUtil.find(ideModule, GradleSourceSetData.KEY, new BooleanFunction>() { + @Override + public boolean fun(DataNode node) { + return mainSourceSetModuleId.equals(node.getData().getId()); + } + }); + if (targetModuleNode == null) { + targetModuleNode = ideModule; + } + return targetModuleNode; } - targetModuleNode.createChild(WebConfigurationModelData.KEY, new WebConfigurationModelData(GradleConstants.SYSTEM_ID, warModels)); + }; + if (webConfiguration != null) { + final List warModels = ContainerUtil.map(webConfiguration.getWarModels(), new Function() { + @Override + public War fun(WebConfiguration.WarModel model) { + War war = new War(model.getWarName(), model.getWebAppDirName(), model.getWebAppDir()); + war.setWebXml(model.getWebXml()); + war.setWebResources(mapWebResources(model.getWebResources())); + war.setClasspath(model.getClasspath()); + war.setManifestContent(model.getManifestContent()); + return war; + } + }); + findTargetModuleNode.getValue().createChild( + WebConfigurationModelData.KEY, new WebConfigurationModelData(GradleConstants.SYSTEM_ID, warModels)); + } + + final EarConfiguration earConfiguration = resolverCtx.getExtraProject(gradleModule, EarConfiguration.class); + if (earConfiguration != null) { + final List warModels = ContainerUtil.map(earConfiguration.getEarModels(), new Function() { + @Override + public Ear fun(EarConfiguration.EarModel model) { + Ear ear = new Ear(model.getEarName(), model.getAppDirName(), model.getLibDirName()); + ear.setManifestContent(model.getManifestContent()); + ear.setDeploymentDescriptor(model.getDeploymentDescriptor()); + ear.setResources(mapEarResources(model.getResources())); + return ear; + } + }); + + final Collection deployDependencies = + GradleProjectResolverUtil.getIdeDependencies(findTargetModuleNode.getValue(), earConfiguration.getDeployDependencies()); + final Collection earlibDependencies = + GradleProjectResolverUtil.getIdeDependencies(findTargetModuleNode.getValue(), earConfiguration.getEarlibDependencies()); + + findTargetModuleNode.getValue().createChild( + EarConfigurationModelData.KEY, + new EarConfigurationModelData(GradleConstants.SYSTEM_ID, warModels, deployDependencies, earlibDependencies)); } nextResolver.populateModuleExtraModels(gradleModule, ideModule); } @@ -81,10 +115,10 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve @NotNull @Override public Set getExtraProjectModelClasses() { - return Collections.singleton(WebConfiguration.class); + return ContainerUtil.set(WebConfiguration.class, EarConfiguration.class); } - private static List map(List webResources) { + private static List mapWebResources(List webResources) { return ContainerUtil.mapNotNull(webResources, new Function() { @Override public WebResource fun(WebConfiguration.WebResource resource) { @@ -95,4 +129,16 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve } }); } + + private static List mapEarResources(List resources) { + return ContainerUtil.mapNotNull(resources, new Function() { + @Override + public EarResource fun(EarConfiguration.EarResource resource) { + if (resource == null) return null; + + return new EarResource(resource.getEarDirectory(), resource.getRelativePath(), resource.getFile()); + } + }); + } + } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/Ear.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/Ear.java new file mode 100644 index 000000000000..39b4240ee3b6 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/Ear.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.model.data; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 11/11/2015 + */ +public class Ear extends Jar { + private static final long serialVersionUID = 1L; + + @NotNull + private final String myAppDirName; + @NotNull + private final String myLibDirName; + private String myDeploymentDescriptor; + @NotNull + private List myResources = Collections.emptyList(); + + public Ear(@NotNull String name, @NotNull String appDirName, @NotNull String libDirName) { + super(name); + myAppDirName = appDirName; + myLibDirName = libDirName; + } + + @NotNull + public String getAppDirName() { + return myAppDirName; + } + + @NotNull + public String getLibDirName() { + return myLibDirName; + } + + public void setDeploymentDescriptor(String deploymentDescriptor) { + myDeploymentDescriptor = deploymentDescriptor; + } + + public String getDeploymentDescriptor() { + return myDeploymentDescriptor; + } + + @NotNull + public List getResources() { + return myResources; + } + + public void setResources(@NotNull List resources) { + myResources = resources; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Ear)) return false; + if (!super.equals(o)) return false; + + Ear that = (Ear)o; + if (!myAppDirName.equals(that.myAppDirName)) return false; + if (!myLibDirName.equals(that.myLibDirName)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + myAppDirName.hashCode(); + result = 31 * result + myLibDirName.hashCode(); + return result; + } + + @Override + public String toString() { + return "Ear{" + + "appDirName='" + myAppDirName + '\'' + + ", libDirName='" + myLibDirName + '\'' + + '}'; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/EarConfigurationModelData.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/EarConfigurationModelData.java new file mode 100644 index 000000000000..31989c4dde9e --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/EarConfigurationModelData.java @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.model.data; + +import com.intellij.openapi.externalSystem.model.Key; +import com.intellij.openapi.externalSystem.model.ProjectSystemId; +import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData; +import com.intellij.openapi.externalSystem.model.project.DependencyData; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 11/11/2015 + */ +public class EarConfigurationModelData extends AbstractExternalEntityData { + private static final long serialVersionUID = 1L; + + @NotNull + public static final Key KEY = + Key.create(EarConfigurationModelData.class, WebConfigurationModelData.KEY.getProcessingWeight() + 1); + + @NotNull + private final List myEars; + @NotNull + private final Collection myDeployDependencies; + @NotNull + private final Collection myEarlibDependencies; + + public EarConfigurationModelData(@NotNull ProjectSystemId owner, + @NotNull List ears, + @NotNull Collection deployDependencies, + @NotNull Collection earlibDependencies) { + super(owner); + myEars = ears; + myDeployDependencies = deployDependencies; + myEarlibDependencies = earlibDependencies; + } + + @NotNull + public List getEars() { + return myEars; + } + + @NotNull + public Collection getDeployDependencies() { + return myDeployDependencies; + } + + @NotNull + public Collection getEarlibDependencies() { + return myEarlibDependencies; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof EarConfigurationModelData)) return false; + if (!super.equals(o)) return false; + + EarConfigurationModelData data = (EarConfigurationModelData)o; + + if (!myEars.equals(data.myEars)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + myEars.hashCode(); + return result; + } + + @Override + public String toString() { + return "ears='" + myEars + '\''; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/EarResource.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/EarResource.java new file mode 100644 index 000000000000..12982c4cf0d3 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/EarResource.java @@ -0,0 +1,91 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.model.data; + +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.Serializable; + +/** + * @author Vladislav.Soroka + * @since 11/11/2015 + */ +public class EarResource implements Serializable { + private static final long serialVersionUID = 1L; + + @NotNull + private final String myEarDirectory; + @NotNull + private final String relativePath; + @NotNull + private final File file; + + public EarResource(@NotNull String earDirectory, @NotNull String relativePath, @NotNull File file) { + myEarDirectory = earDirectory; + this.relativePath = getAdjustedPath(relativePath); + this.file = file; + } + + @NotNull + public String getEarDirectory() { + return myEarDirectory; + } + + @NotNull + public String getRelativePath() { + return relativePath; + } + + @NotNull + public File getFile() { + return file; + } + + private static String getAdjustedPath(final @NotNull String path) { + return path.isEmpty() || path.charAt(0) != '/' ? '/' + path : path; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof EarResource)) return false; + + EarResource resource = (EarResource)o; + if (!file.getPath().equals(resource.file.getPath())) return false; + if (myEarDirectory != resource.myEarDirectory) return false; + if (!relativePath.equals(resource.relativePath)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myEarDirectory.hashCode(); + result = 31 * result + relativePath.hashCode(); + result = 31 * result + file.getPath().hashCode(); + return result; + } + + @Override + public String toString() { + return "Resource{" + + "earDirectory=" + myEarDirectory + + ", relativePath='" + relativePath + '\'' + + ", file=" + file + + '}'; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/Jar.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/Jar.java new file mode 100644 index 000000000000..5f8862fac922 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/Jar.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.model.data; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Serializable; + +/** + * @author Vladislav.Soroka + * @since 11/21/2015 + */ +public class Jar implements Serializable { + private static final long serialVersionUID = 1L; + + @NotNull + private final String myName; + @Nullable + private String myManifestContent; + + public Jar(@NotNull String name) { + myName = name; + } + + @NotNull + public String getName() { + return myName; + } + + @Nullable + public String getManifestContent() { + return myManifestContent; + } + + public void setManifestContent(@Nullable String manifestContent) { + myManifestContent = manifestContent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Jar that = (Jar)o; + if (!myName.equals(that.myName)) return false; + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + myName.hashCode(); + return result; + } + + @Override + public String toString() { + return "Jar{'" + myName + "'}"; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/War.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/War.java index b183324f735c..4a6e8ecc744c 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/War.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/War.java @@ -28,12 +28,9 @@ import java.util.Set; * @author Vladislav.Soroka * @since 2/10/14 */ -public class War implements Serializable { +public class War extends Jar { private static final long serialVersionUID = 1L; - @NotNull - private final String myName; - @NotNull private final String myWebAppDirName; @NotNull @@ -44,23 +41,16 @@ public class War implements Serializable { private List myWebResources; @NotNull private Set myClasspath; - @Nullable - private String myManifestContent; public War(@NotNull String name, @NotNull String webAppDirName, @NotNull File webAppDir) { - myName = name; + super(name); myWebAppDirName = webAppDirName; myWebAppDir = webAppDir; myWebResources = Collections.emptyList(); myClasspath = Collections.emptySet(); } - @NotNull - public String getName() { - return myName; - } - @NotNull public String getWebAppDirName() { return myWebAppDirName; @@ -98,26 +88,17 @@ public class War implements Serializable { return myClasspath; } - public void setManifestContent(@Nullable String manifestContent) { - myManifestContent = manifestContent; - } - - @Nullable - public String getManifestContent() { - return myManifestContent; - } - @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof War)) return false; if (!super.equals(o)) return false; - War that = (War)o; + War war = (War)o; - if (!myName.equals(that.myName)) return false; - if (!myWebAppDirName.equals(that.myWebAppDirName)) return false; - if (!myWebResources.equals(that.myWebResources)) return false; + if (!myWebAppDirName.equals(war.myWebAppDirName)) return false; + if (!myWebResources.equals(war.myWebResources)) return false; + if (!myClasspath.equals(war.myClasspath)) return false; return true; } @@ -125,7 +106,6 @@ public class War implements Serializable { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + myName.hashCode(); result = 31 * result + myWebAppDirName.hashCode(); result = 31 * result + myWebResources.hashCode(); return result; @@ -134,11 +114,11 @@ public class War implements Serializable { @Override public String toString() { return "War{" + - "myName='" + myName + '\'' + - ", myWebAppDirName='" + myWebAppDirName + '\'' + - ", myWebAppDir=" + myWebAppDir + - ", myWebXml=" + myWebXml + - ", myWebResources=" + myWebResources + + "name='" + getName() + '\'' + + ", webAppDirName='" + myWebAppDirName + '\'' + + ", webAppDir=" + myWebAppDir + + ", webXml=" + myWebXml + + ", webResources=" + myWebResources + '}'; } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java index 17df607d3987..9658e8f37cd2 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java @@ -47,6 +47,7 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtilRt; import com.intellij.util.net.HttpConfigurable; import com.intellij.util.text.CharArrayUtil; +import gnu.trove.TObjectHashingStrategy; import groovy.lang.GroovyObject; import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling; import org.gradle.tooling.ProjectConnection; @@ -137,14 +138,15 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver // org.gradle.tooling.model.idea.IdeaLanguageLevel.getLevel() returns something like JDK_1_6 final String languageLevel = ideaProject.getLanguageLevel().getLevel(); for (LanguageLevel level : LanguageLevel.values()) { - if(level.name().equals(languageLevel)) { + if (level.name().equals(languageLevel)) { resolvedLanguageLevel = level; break; } } - if(resolvedLanguageLevel != null) { + if (resolvedLanguageLevel != null) { javaProjectData.setLanguageLevel(resolvedLanguageLevel); - } else { + } + else { javaProjectData.setLanguageLevel(languageLevel); } return javaProjectData; @@ -218,14 +220,23 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver sourceSetData.setSourceCompatibility(sourceSet.getSourceCompatibility()); sourceSetData.setTargetCompatibility(sourceSet.getTargetCompatibility()); + final Set artifacts = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY); if ("main".equals(sourceSet.getName())) { - final List artifacts = ContainerUtil.newArrayList(); final Set defaultArtifacts = externalProject.getArtifactsByConfiguration().get("default"); if (defaultArtifacts != null) { artifacts.addAll(defaultArtifacts); } - sourceSetData.setArtifacts(artifacts); + final Set archivesArtifacts = externalProject.getArtifactsByConfiguration().get("archives"); + if (archivesArtifacts != null) { + artifacts.addAll(archivesArtifacts); + } + } else if("test".equals(sourceSet.getName())) { + final Set testsArtifacts = externalProject.getArtifactsByConfiguration().get("tests"); + if (testsArtifacts != null) { + artifacts.addAll(testsArtifacts); + } } + sourceSetData.setArtifacts(ContainerUtil.newArrayList(artifacts)); DataNode sourceSetDataNode = mainModuleNode.createChild(GradleSourceSetData.KEY, sourceSetData); final Map, ExternalSourceSet>> sourceSetMap = @@ -407,60 +418,7 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver processSourceSets(externalProject, ideModule, new SourceSetsProcessor() { @Override public void process(@NotNull DataNode dataNode, @NotNull ExternalSourceSet sourceSet) { - Map dependencyMap = ContainerUtil.newHashMap(); - - Queue queue = ContainerUtil.newLinkedList(sourceSet.getDependencies()); - 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()); - } - - buildSourceSetDependency(sourceSetMap, dependencyMap, dataNode, sourceSet.getDependencies(), ideProject); + buildDependencies(sourceSetMap, dataNode, sourceSet.getDependencies(), ideProject); } }); @@ -557,10 +515,8 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver @Override public Set getExtraProjectModelClasses() { Set result = ContainerUtil.set(GradleBuild.class, ModuleExtendedModel.class); - if (!ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID) || !resolverCtx.isPreviewMode()) { - result.add(BuildScriptClasspathModel.class); - } - result.add(resolverCtx.isPreviewMode() ? ExternalProjectPreview.class : ExternalProject.class); + result.add(BuildScriptClasspathModel.class); + result.add(ExternalProject.class); return result; } @@ -869,7 +825,7 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver @NotNull DataNode ownerModule, @NotNull IdeaSingleEntryLibraryDependency dependency, @NotNull DataNode ideProject) - throws IllegalStateException { + throws IllegalStateException { File binaryPath = dependency.getFile(); if (binaryPath == null) { throw new IllegalStateException(String.format( @@ -961,145 +917,13 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver library.addPath(LibraryPathType.DOC, javadocPath.getAbsolutePath()); } - if(level == LibraryLevel.PROJECT) { + if (level == LibraryLevel.PROJECT) { linkProjectLibrary(ideProject, library); } return new LibraryDependencyData(ownerModule.getData(), library, level); } - private static void buildSourceSetDependency(@NotNull Map, ExternalSourceSet>> sourceSetMap, - @NotNull Map mergedDependencyMap, - @NotNull DataNode ownerDataNode, - @NotNull Collection dependencies, - @NotNull DataNode ideProject) throws IllegalStateException { - - Map dependencyMap = ContainerUtil.newLinkedHashMap(); - for (ExternalDependency dependency : dependencies) { - dependencyMap.put(dependency.getId(), dependency); - } - - for (ExternalDependency dependency : dependencyMap.values()) { - final ExternalDependency mergedDependency = ContainerUtil.getOrElse(mergedDependencyMap, dependency.getId(), dependency); - DependencyScope dependencyScope = getDependencyScope(mergedDependency.getScope()); - - ModuleData ownerModule = null; - if (ownerDataNode.getData() instanceof ModuleData) { - ownerModule = (ModuleData)ownerDataNode.getData(); - } - else if (ownerDataNode.getData() instanceof DependencyData) { - ownerModule = ((DependencyData)ownerDataNode.getData()).getOwnerModule(); - } - - assert ownerModule != null; - - if (mergedDependency instanceof ExternalProjectDependency) { - String moduleId = getModuleId((ExternalProjectDependency)mergedDependency); - Pair, ExternalSourceSet> projectPair = sourceSetMap.get(moduleId); - ModuleDependencyData moduleDependencyData = new ModuleDependencyData(ownerModule, projectPair.first.getData()); - moduleDependencyData.setScope(dependencyScope); - if ("test".equals(projectPair.second.getName())) { - moduleDependencyData.setProductionOnTestDependency(true); - } - moduleDependencyData.setOrder(mergedDependency.getClasspathOrder()); - moduleDependencyData.setExported(mergedDependency.getExported()); - DataNode ideModuleDependencyNode = - ownerDataNode.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData); - buildSourceSetDependency(sourceSetMap, mergedDependencyMap, ideModuleDependencyNode, dependency.getDependencies(), ideProject); - } - if (mergedDependency instanceof ExternalLibraryDependency) { - final LibraryLevel level = LibraryLevel.PROJECT; - String libraryName = mergedDependency.getId().getPresentableName(); - final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName); - LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); - libraryDependencyData.setScope(dependencyScope); - libraryDependencyData.setOrder(mergedDependency.getClasspathOrder()); - libraryDependencyData.setExported(mergedDependency.getExported()); - - library.addPath(LibraryPathType.BINARY, ((ExternalLibraryDependency)mergedDependency).getFile().getAbsolutePath()); - File sourcePath = ((ExternalLibraryDependency)mergedDependency).getSource(); - if (sourcePath != null) { - library.addPath(LibraryPathType.SOURCE, sourcePath.getAbsolutePath()); - } - File javaDocPath = ((ExternalLibraryDependency)mergedDependency).getJavadoc(); - if (javaDocPath != null) { - library.addPath(LibraryPathType.DOC, javaDocPath.getAbsolutePath()); - } - DataNode libraryDependencyDataNode = - ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); - - linkProjectLibrary(ideProject, library); - - buildSourceSetDependency(sourceSetMap, mergedDependencyMap, libraryDependencyDataNode, dependency.getDependencies(), ideProject); - } - if (mergedDependency instanceof ExternalMultiLibraryDependency) { - final LibraryLevel level = LibraryLevel.MODULE; - String libraryName = mergedDependency.getId().getPresentableName(); - final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName); - LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); - libraryDependencyData.setScope(dependencyScope); - libraryDependencyData.setOrder(mergedDependency.getClasspathOrder()); - libraryDependencyData.setExported(mergedDependency.getExported()); - - for (File file : ((ExternalMultiLibraryDependency)mergedDependency).getFiles()) { - library.addPath(LibraryPathType.BINARY, file.getAbsolutePath()); - } - for (File file : ((ExternalMultiLibraryDependency)mergedDependency).getSources()) { - library.addPath(LibraryPathType.SOURCE, file.getAbsolutePath()); - } - for (File file : ((ExternalMultiLibraryDependency)mergedDependency).getJavadoc()) { - library.addPath(LibraryPathType.DOC, file.getAbsolutePath()); - } - - DataNode libraryDependencyDataNode = - ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); - - buildSourceSetDependency(sourceSetMap, mergedDependencyMap, libraryDependencyDataNode, dependency.getDependencies(), ideProject); - } - if (mergedDependency instanceof FileCollectionDependency) { - final LibraryLevel level = LibraryLevel.MODULE; - String libraryName = ""; - final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName); - LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); - libraryDependencyData.setScope(dependencyScope); - libraryDependencyData.setOrder(mergedDependency.getClasspathOrder()); - libraryDependencyData.setExported(mergedDependency.getExported()); - - for (File file : ((FileCollectionDependency)mergedDependency).getFiles()) { - library.addPath(LibraryPathType.BINARY, file.getAbsolutePath()); - } - - ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); - } - if (mergedDependency instanceof UnresolvedExternalDependency) { - final LibraryLevel level = LibraryLevel.PROJECT; - String libraryName = mergedDependency.getId().getPresentableName(); - final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName, true); - LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); - libraryDependencyData.setScope(dependencyScope); - final String failureMessage = ((UnresolvedExternalDependency)mergedDependency).getFailureMessage(); - if (failureMessage != null) { - library.addPath(LibraryPathType.BINARY, failureMessage); - } - ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); - linkProjectLibrary(ideProject, library); - } - } - } - - private static void linkProjectLibrary(@NotNull DataNode ideProject, @NotNull final LibraryData library) { - DataNode libraryData = - ExternalSystemApiUtil.find(ideProject, ProjectKeys.LIBRARY, new BooleanFunction>() { - @Override - public boolean fun(DataNode node) { - return library.equals(node.getData()); - } - }); - if (libraryData == null) { - ideProject.createChild(ProjectKeys.LIBRARY, library); - } - } - interface SourceSetsProcessor { void process(@NotNull DataNode dataNode, @NotNull ExternalSourceSet sourceSet); } 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 7f2ea67a5bb8..5f7cf97109d6 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 @@ -142,6 +142,12 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver commandLineArgs = ContainerUtil.newArrayList(); final Set toolingExtensionClasses = ContainerUtil.newHashSet(); + if(resolverCtx.isPreviewMode()){ + commandLineArgs.add("-Didea.isPreviewMode=true"); + final Set previewLightWeightToolingModels = ContainerUtil.set(ExternalProjectPreview.class); + projectImportAction.addExtraProjectModelClasses(previewLightWeightToolingModels); + } + final GradleImportCustomizer importCustomizer = GradleImportCustomizer.get(); for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; @@ -150,8 +156,11 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver moduleDataNode = pair.first; final IdeaModule ideaModule = pair.second; projectResolverChain.populateModuleDependencies(ideaModule, moduleDataNode, projectDataNode); + projectResolverChain.populateModuleExtraModels(ideaModule, moduleDataNode); } mergeSourceSetContentRoots(moduleMap, resolverCtx); mergeLibraryAndModuleDependencyData(projectDataNode, gradleHomeDir, gradleVersion); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverUtil.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverUtil.java index f86e16f96c67..c53def95c073 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverUtil.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverUtil.java @@ -16,34 +16,42 @@ package org.jetbrains.plugins.gradle.service.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.LibraryData; -import com.intellij.openapi.externalSystem.model.project.LibraryPathType; -import com.intellij.openapi.externalSystem.model.project.ModuleData; -import com.intellij.openapi.externalSystem.model.project.ProjectData; +import com.intellij.openapi.externalSystem.model.project.*; import com.intellij.openapi.externalSystem.model.task.TaskData; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; +import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; import com.intellij.openapi.roots.DependencyScope; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.BooleanFunction; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.GradleProject; import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel; -import org.jetbrains.plugins.gradle.model.ExternalProject; -import org.jetbrains.plugins.gradle.model.ExternalProjectDependency; -import org.jetbrains.plugins.gradle.model.ExternalSourceSet; +import org.jetbrains.plugins.gradle.DefaultExternalDependencyId; +import org.jetbrains.plugins.gradle.ExternalDependencyId; +import org.jetbrains.plugins.gradle.model.*; +import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData; +import org.jetbrains.plugins.gradle.util.GradleConstants; import java.io.File; +import java.util.Collection; +import java.util.Map; +import java.util.Queue; /** * @author Vladislav.Soroka * @since 10/6/2015 */ public class GradleProjectResolverUtil { + @NotNull + private static final Key CONTAINER_KEY = Key.create(Object.class, ExternalSystemConstants.UNORDERED); @NotNull public static String getModuleId(@NotNull IdeaModule gradleModule) { @@ -128,6 +136,232 @@ public class GradleProjectResolverUtil { } } + @SuppressWarnings("unchecked") + public static Collection getIdeDependencies(@NotNull DataNode moduleDataNode, + @NotNull Collection dependencies) + throws IllegalStateException { + + final DataNode ideProject = ExternalSystemApiUtil.findParent(moduleDataNode, ProjectKeys.PROJECT); + assert ideProject != null; + + final Map, ExternalSourceSet>> sourceSetMap = + ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS); + assert sourceSetMap != null; + + DataNode fakeNode = new DataNode(CONTAINER_KEY, moduleDataNode.getData(), null); + buildDependencies(sourceSetMap, fakeNode, dependencies, null); + final Collection> dataNodes = + ExternalSystemApiUtil.findAllRecursively(fakeNode, new BooleanFunction>() { + @Override + public boolean fun(DataNode node) { + return node.getData() instanceof DependencyData; + } + }); + return ContainerUtil.map(dataNodes, new Function, DependencyData>() { + @Override + public DependencyData fun(DataNode node) { + return (DependencyData)node.getData(); + } + }); + } + + public static void buildDependencies(@NotNull Map, ExternalSourceSet>> sourceSetMap, + @NotNull DataNode ownerDataNode, + @NotNull Collection dependencies, + @Nullable DataNode ideProject) throws IllegalStateException { + Map dependencyMap = ContainerUtil.newHashMap(); + + Queue 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(sourceSetMap, dependencyMap, ownerDataNode, dependencies, ideProject); + } + + private static void doBuildDependencies(@NotNull Map, ExternalSourceSet>> sourceSetMap, + @NotNull Map mergedDependencyMap, + @NotNull DataNode ownerDataNode, + @NotNull Collection dependencies, + @Nullable DataNode ideProject) throws IllegalStateException { + + Map dependencyMap = ContainerUtil.newLinkedHashMap(); + for (ExternalDependency dependency : dependencies) { + dependencyMap.put(dependency.getId(), dependency); + } + + for (ExternalDependency dependency : dependencyMap.values()) { + final ExternalDependency mergedDependency = ContainerUtil.getOrElse(mergedDependencyMap, dependency.getId(), dependency); + DependencyScope dependencyScope = getDependencyScope(mergedDependency.getScope()); + + ModuleData ownerModule = null; + if (ownerDataNode.getData() instanceof ModuleData) { + ownerModule = (ModuleData)ownerDataNode.getData(); + } + else if (ownerDataNode.getData() instanceof DependencyData) { + ownerModule = ((DependencyData)ownerDataNode.getData()).getOwnerModule(); + } + + assert ownerModule != null; + + if (mergedDependency instanceof ExternalProjectDependency) { + final ExternalProjectDependency projectDependency = (ExternalProjectDependency)mergedDependency; + String moduleId = getModuleId(projectDependency); + Pair, ExternalSourceSet> projectPair = sourceSetMap.get(moduleId); + ModuleDependencyData moduleDependencyData = new ModuleDependencyData(ownerModule, projectPair.first.getData()); + moduleDependencyData.setScope(dependencyScope); + if ("test".equals(projectPair.second.getName())) { + moduleDependencyData.setProductionOnTestDependency(true); + } + moduleDependencyData.setOrder(mergedDependency.getClasspathOrder()); + moduleDependencyData.setExported(mergedDependency.getExported()); + moduleDependencyData.setModuleDependencyArtifacts(projectDependency.getProjectDependencyArtifacts()); + + DataNode ideModuleDependencyNode = + ownerDataNode.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData); + doBuildDependencies(sourceSetMap, mergedDependencyMap, ideModuleDependencyNode, dependency.getDependencies(), ideProject); + } + if (mergedDependency instanceof ExternalLibraryDependency) { + final LibraryLevel level = LibraryLevel.PROJECT; + String libraryName = mergedDependency.getId().getPresentableName(); + final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName); + LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); + libraryDependencyData.setScope(dependencyScope); + libraryDependencyData.setOrder(mergedDependency.getClasspathOrder()); + libraryDependencyData.setExported(mergedDependency.getExported()); + + library.addPath(LibraryPathType.BINARY, ((ExternalLibraryDependency)mergedDependency).getFile().getAbsolutePath()); + File sourcePath = ((ExternalLibraryDependency)mergedDependency).getSource(); + if (sourcePath != null) { + library.addPath(LibraryPathType.SOURCE, sourcePath.getAbsolutePath()); + } + File javaDocPath = ((ExternalLibraryDependency)mergedDependency).getJavadoc(); + if (javaDocPath != null) { + library.addPath(LibraryPathType.DOC, javaDocPath.getAbsolutePath()); + } + DataNode libraryDependencyDataNode = + ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); + + linkProjectLibrary(ideProject, library); + + doBuildDependencies(sourceSetMap, mergedDependencyMap, libraryDependencyDataNode, dependency.getDependencies(), ideProject); + } + if (mergedDependency instanceof ExternalMultiLibraryDependency) { + final LibraryLevel level = LibraryLevel.MODULE; + String libraryName = mergedDependency.getId().getPresentableName(); + final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName); + LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); + libraryDependencyData.setScope(dependencyScope); + libraryDependencyData.setOrder(mergedDependency.getClasspathOrder()); + libraryDependencyData.setExported(mergedDependency.getExported()); + + for (File file : ((ExternalMultiLibraryDependency)mergedDependency).getFiles()) { + library.addPath(LibraryPathType.BINARY, file.getAbsolutePath()); + } + for (File file : ((ExternalMultiLibraryDependency)mergedDependency).getSources()) { + library.addPath(LibraryPathType.SOURCE, file.getAbsolutePath()); + } + for (File file : ((ExternalMultiLibraryDependency)mergedDependency).getJavadoc()) { + library.addPath(LibraryPathType.DOC, file.getAbsolutePath()); + } + + DataNode libraryDependencyDataNode = + ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); + + doBuildDependencies(sourceSetMap, mergedDependencyMap, libraryDependencyDataNode, dependency.getDependencies(), ideProject); + } + if (mergedDependency instanceof FileCollectionDependency) { + final LibraryLevel level = LibraryLevel.MODULE; + String libraryName = ""; + final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName); + LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); + libraryDependencyData.setScope(dependencyScope); + libraryDependencyData.setOrder(mergedDependency.getClasspathOrder()); + libraryDependencyData.setExported(mergedDependency.getExported()); + + for (File file : ((FileCollectionDependency)mergedDependency).getFiles()) { + library.addPath(LibraryPathType.BINARY, file.getAbsolutePath()); + } + + ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); + } + if (mergedDependency instanceof UnresolvedExternalDependency) { + final LibraryLevel level = LibraryLevel.PROJECT; + String libraryName = mergedDependency.getId().getPresentableName(); + final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName, true); + LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level); + libraryDependencyData.setScope(dependencyScope); + final String failureMessage = ((UnresolvedExternalDependency)mergedDependency).getFailureMessage(); + if (failureMessage != null) { + library.addPath(LibraryPathType.BINARY, failureMessage); + } + ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData); + linkProjectLibrary(ideProject, library); + } + } + } + + public static void linkProjectLibrary(@Nullable DataNode ideProject, @NotNull final LibraryData library) { + if (ideProject == null) return; + + DataNode libraryData = + ExternalSystemApiUtil.find(ideProject, ProjectKeys.LIBRARY, new BooleanFunction>() { + @Override + public boolean fun(DataNode node) { + return library.equals(node.getData()); + } + }); + if (libraryData == null) { + ideProject.createChild(ProjectKeys.LIBRARY, library); + } + } + public static boolean isIdeaTask(final String taskName, @Nullable String group) { if ((group == null || "ide".equalsIgnoreCase(group)) && StringUtil.containsIgnoreCase(taskName, "idea")) return true; return "other".equalsIgnoreCase(group) && StringUtil.containsIgnoreCase(taskName, "idea"); diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/GradleProjectWizardTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/GradleProjectWizardTest.java index 300225e6f810..40fe15abf229 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/GradleProjectWizardTest.java +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/GradleProjectWizardTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -62,12 +62,12 @@ public class GradleProjectWizardTest extends NewProjectWizardTestCase { assertEquals(projectName, module.getName()); VirtualFile root = ProjectRootManager.getInstance(project).getContentRoots()[0]; - VirtualFile settingsScript = root.findChild("settings.gradle"); + VirtualFile settingsScript = VfsUtilCore.findRelativeFile("settings.gradle", root); assertNotNull(settingsScript); assertEquals(String.format("rootProject.name = '%s'\n\n", projectName), StringUtil.convertLineSeparators(VfsUtilCore.loadText(settingsScript))); - VirtualFile buildScript = root.findChild("build.gradle"); + VirtualFile buildScript = VfsUtilCore.findRelativeFile("build.gradle", root); assertNotNull(buildScript); assertEquals("group '" + projectName + "'\n" + "version '1.0-SNAPSHOT'\n" + diff --git a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalProjectDependency.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalProjectDependency.java index 47dfdee26d0f..524e8258a793 100644 --- a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalProjectDependency.java +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExternalProjectDependency.java @@ -15,6 +15,8 @@ */ package org.jetbrains.plugins.gradle.model; +import java.util.Collection; + /** * @author Vladislav.Soroka * @since 7/14/2014 @@ -23,4 +25,5 @@ public interface ExternalProjectDependency extends ExternalDependency { String getProjectPath(); + Collection getProjectDependencyArtifacts(); } diff --git a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ear/EarConfiguration.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ear/EarConfiguration.java new file mode 100644 index 000000000000..ef518352cd43 --- /dev/null +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ear/EarConfiguration.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.model.ear; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ExternalDependency; + +import java.io.File; +import java.io.Serializable; +import java.util.Collection; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 11/10/2015 + */ +public interface EarConfiguration extends Serializable { + List getEarModels(); + + @NotNull + Collection getDeployDependencies(); + + @NotNull + Collection getEarlibDependencies(); + + interface EarModel extends Serializable { + @NotNull + String getEarName(); + + String getManifestContent(); + + @NotNull + String getAppDirName(); + + String getLibDirName(); + + List getResources(); + + String getDeploymentDescriptor(); + } + + interface EarResource extends Serializable { + + @NotNull + String getEarDirectory(); + + @NotNull + String getRelativePath(); + + @NotNull + File getFile(); + } +} diff --git a/plugins/gradle/tooling-extension-impl/gradle-tooling-extension-impl.iml b/plugins/gradle/tooling-extension-impl/gradle-tooling-extension-impl.iml index c5ce2d33e492..10d19638bf77 100644 --- a/plugins/gradle/tooling-extension-impl/gradle-tooling-extension-impl.iml +++ b/plugins/gradle/tooling-extension-impl/gradle-tooling-extension-impl.iml @@ -68,10 +68,12 @@ + + diff --git a/plugins/gradle/tooling-extension-impl/lib/gradle-ear-2.5.jar b/plugins/gradle/tooling-extension-impl/lib/gradle-ear-2.5.jar new file mode 100644 index 000000000000..dcab048bb8a5 Binary files /dev/null and b/plugins/gradle/tooling-extension-impl/lib/gradle-ear-2.5.jar differ diff --git a/plugins/gradle/tooling-extension-impl/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/gradle/tooling-extension-impl/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService index 816ef05c1e4d..d5580bcf4b3c 100644 --- a/plugins/gradle/tooling-extension-impl/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService +++ b/plugins/gradle/tooling-extension-impl/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -14,6 +14,7 @@ # limitations under the License. # org.jetbrains.plugins.gradle.tooling.builder.WarModelBuilderImpl +org.jetbrains.plugins.gradle.tooling.builder.EarModelBuilderImpl org.jetbrains.plugins.gradle.tooling.builder.ModuleExtendedModelBuilderImpl org.jetbrains.plugins.gradle.tooling.builder.ModelBuildScriptClasspathBuilderImpl org.jetbrains.plugins.gradle.tooling.builder.ScalaModelBuilderImpl diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalProjectDependency.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalProjectDependency.java index 9bb9c64e9fd0..d97895ffa767 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalProjectDependency.java +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/DefaultExternalProjectDependency.java @@ -17,6 +17,9 @@ package org.jetbrains.plugins.gradle.model; import com.google.common.base.Objects; +import java.util.ArrayList; +import java.util.Collection; + /** * @author Vladislav.Soroka * @since 12/24/2014 @@ -25,23 +28,37 @@ public class DefaultExternalProjectDependency extends AbstractExternalDependency private static final long serialVersionUID = 1L; - private String projectPath; + private String myProjectPath; + private Collection myProjectDependencyArtifacts; public DefaultExternalProjectDependency() { } public DefaultExternalProjectDependency(ExternalProjectDependency dependency) { super(dependency); - projectPath = dependency.getProjectPath(); + myProjectPath = dependency.getProjectPath(); + myProjectDependencyArtifacts = + dependency.getProjectDependencyArtifacts() == null + ? new ArrayList() + : new ArrayList(dependency.getProjectDependencyArtifacts()); } @Override public String getProjectPath() { - return projectPath; + return myProjectPath; } public void setProjectPath(String projectPath) { - this.projectPath = projectPath; + this.myProjectPath = projectPath; + } + + @Override + public Collection getProjectDependencyArtifacts() { + return myProjectDependencyArtifacts; + } + + public void setProjectDependencyArtifacts(Collection projectArtifacts) { + myProjectDependencyArtifacts = projectArtifacts; } @Override @@ -50,16 +67,16 @@ public class DefaultExternalProjectDependency extends AbstractExternalDependency if (!(o instanceof DefaultExternalProjectDependency)) return false; if (!super.equals(o)) return false; DefaultExternalProjectDependency that = (DefaultExternalProjectDependency)o; - return Objects.equal(projectPath, that.projectPath); + return Objects.equal(myProjectPath, that.myProjectPath); } @Override public int hashCode() { - return Objects.hashCode(super.hashCode(), projectPath); + return Objects.hashCode(super.hashCode(), myProjectPath); } @Override public String toString() { - return "project dependency '" + projectPath + '\''; + return "project dependency '" + myProjectPath + '\''; } } diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/CopySpecWalker.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/CopySpecWalker.groovy new file mode 100644 index 000000000000..635b13a0df65 --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/CopySpecWalker.groovy @@ -0,0 +1,104 @@ +/* + * Copyright 2000-2015 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. + */ + +package org.jetbrains.plugins.gradle.tooling.builder + +import org.gradle.api.Action +import org.gradle.api.file.CopySpec +import org.gradle.api.file.FileVisitDetails +import org.gradle.api.file.FileVisitor +import org.gradle.util.GradleVersion + +/** + * @author Vladislav.Soroka + * @since 11/10/2015 + */ +class CopySpecWalker { + + static interface Visitor { + void visitSourcePath(String relativePath, String path) + + void visitDir(String relativePath, FileVisitDetails dirDetails) + + void visitFile(String relativePath, FileVisitDetails fileDetails) + } + + @SuppressWarnings("GrUnresolvedAccess") + static void walk(CopySpec copySpec, Visitor visitor) { + copySpec.setIncludeEmptyDirs(true) + if (!(copySpec.metaClass.respondsTo(copySpec, 'walk', Action))) { + return + } + + copySpec.walk({ def resolver -> + // def resolver -> + // in Gradle v1.x - org.gradle.api.internal.file.copy.CopySpecInternal + // in Gradle v2.x - org.gradle.api.internal.file.copy.CopySpecResolver + + if (resolver.metaClass.respondsTo(resolver, 'setIncludeEmptyDirs', boolean)) { + resolver.setIncludeEmptyDirs(true) + } + if (!resolver.metaClass.respondsTo(resolver, 'getDestPath') || + !resolver.metaClass.respondsTo(resolver, 'getSource')) { + throw new RuntimeException("${GradleVersion.current()} is not supported by JEE artifact importer") + } + + final String relativePath = resolver.destPath.pathString + def sourcePaths + + if (resolver.metaClass.respondsTo(resolver, 'getSourcePaths')) { + sourcePaths = resolver.getSourcePaths() + } + else if (resolver.hasProperty('sourcePaths')) { + sourcePaths = resolver.sourcePaths + } + else if (resolver.hasProperty('this$0') && resolver.this$0.metaClass.respondsTo(resolver, 'getSourcePaths')) { + sourcePaths = resolver.this$0.getSourcePaths() + } + else if (resolver.hasProperty('this$0') && resolver.this$0.hasProperty('sourcePaths')) { + sourcePaths = resolver.this$0.sourcePaths + } + + if (sourcePaths) { + (sourcePaths.flatten() as List).each { def path -> + if (path instanceof String) { + visitor.visitSourcePath(relativePath, path) + } + } + } + + resolver.source.visit(new FileVisitor() { + @Override + public void visitDir(FileVisitDetails dirDetails) { + try { + visitor.visitDir(relativePath, dirDetails) + } + catch (Exception ignore) { + } + } + + @Override + public void visitFile(FileVisitDetails fileDetails) { + try { + visitor.visitFile(relativePath, fileDetails) + } + catch (Exception ignore) { + } + } + }) + }) + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/EarModelBuilderImpl.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/EarModelBuilderImpl.groovy new file mode 100644 index 000000000000..811f509bbee7 --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/EarModelBuilderImpl.groovy @@ -0,0 +1,148 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.tooling.builder + +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.artifacts.Configuration +import org.gradle.api.file.FileVisitDetails +import org.gradle.api.java.archives.Manifest +import org.gradle.plugins.ear.Ear +import org.gradle.plugins.ear.EarPlugin +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable +import org.jetbrains.plugins.gradle.model.ear.EarConfiguration +import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService +import org.jetbrains.plugins.gradle.tooling.internal.ear.EarConfigurationImpl +import org.jetbrains.plugins.gradle.tooling.internal.ear.EarModelImpl +import org.jetbrains.plugins.gradle.tooling.internal.ear.EarResourceImpl +import org.jetbrains.plugins.gradle.tooling.util.DependencyResolver +import org.jetbrains.plugins.gradle.tooling.util.DependencyResolverImpl + +/** + * @author Vladislav.Soroka + * @since 11/10/2015 + */ +class EarModelBuilderImpl implements ModelBuilderService { + + private static final String APP_DIR_PROPERTY = "appDirName" + + @Override + public boolean canBuild(String modelName) { + return EarConfiguration.name.equals(modelName) + } + + @Nullable + @Override + public Object buildAll(String modelName, Project project) { + final EarPlugin earPlugin = project.plugins.findPlugin(EarPlugin) + if (earPlugin == null) return null + + final String appDirName = !project.hasProperty(APP_DIR_PROPERTY) ? + "src/main/application" : String.valueOf(project.property(APP_DIR_PROPERTY)) + def earModels = [] + + def deployConfiguration = project.configurations.findByName(EarPlugin.DEPLOY_CONFIGURATION_NAME) + def earlibConfiguration = project.configurations.findByName(EarPlugin.EARLIB_CONFIGURATION_NAME) + + DependencyResolver dependencyResolver = new DependencyResolverImpl(project, false, false, false) + def deployDependencies = dependencyResolver.resolveDependencies(deployConfiguration) + def earlibDependencies = dependencyResolver.resolveDependencies(earlibConfiguration) + def buildDirPath = project.getBuildDir().absolutePath + + project.tasks.each { Task task -> + if (task instanceof Ear) { + final EarModelImpl earModel = new EarModelImpl(task.archiveName, appDirName, task.getLibDirName()) + + final List earResources = [] + final Ear earTask = task as Ear + + try { + new CopySpecWalker().walk(earTask.rootSpec, new CopySpecWalker.Visitor() { + @Override + void visitSourcePath(String relativePath, String path) { + def file = new File(path) + addPath(buildDirPath, earResources, relativePath, "", file.absolute ? file : new File(earTask.project.projectDir, path), deployConfiguration, earlibConfiguration) + } + + @Override + void visitDir(String relativePath, FileVisitDetails dirDetails) { + addPath(buildDirPath, earResources, relativePath, dirDetails.path, dirDetails.file, deployConfiguration, earlibConfiguration) + } + + @Override + void visitFile(String relativePath, FileVisitDetails fileDetails) { + addPath(buildDirPath, earResources, relativePath, fileDetails.path, fileDetails.file, deployConfiguration, earlibConfiguration) + } + }) + } + catch (Exception e) { + ErrorMessageBuilder builderError = getErrorMessageBuilder(project, e); + project.getLogger().error(builderError.build()); + } + + earModel.resources = earResources + + def deploymentDescriptor = earTask.deploymentDescriptor + if(deploymentDescriptor != null) { + def writer = new StringWriter() + deploymentDescriptor.writeTo(writer) + earModel.deploymentDescriptor = writer.toString() + } + + Manifest manifest = earTask.manifest + if (manifest != null) { + def writer = new StringWriter() + manifest.writeTo(writer) + earModel.manifestContent = writer.toString() + } + + earModels.add(earModel) + } + } + + new EarConfigurationImpl(earModels, deployDependencies, earlibDependencies) + } + + @NotNull + @Override + public ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) { + ErrorMessageBuilder.create( + project, e, "JEE project import errors" + ).withDescription("Ear Artifacts may not be configured properly") + } + + private static addPath( + String buildDirPath, + List earResources, + String earRelativePath, + String fileRelativePath, + File file, + Configuration... earConfigurations) { + + if(file.absolutePath.startsWith(buildDirPath)) return + + for (Configuration conf : earConfigurations) { + if (conf.files.contains(file)) return + } + + earRelativePath = earRelativePath == null ? "" : earRelativePath + + EarConfiguration.EarResource earResource = new EarResourceImpl(earRelativePath, fileRelativePath, file) + earResources.add(earResource) + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy index b1db0c0e056f..45abd4e855cb 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy @@ -18,11 +18,9 @@ package org.jetbrains.plugins.gradle.tooling.builder import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.file.FileVisitDetails -import org.gradle.api.file.FileVisitor import org.gradle.api.java.archives.Manifest import org.gradle.api.plugins.WarPlugin import org.gradle.api.tasks.bundling.War -import org.gradle.util.GradleVersion import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable import org.jetbrains.plugins.gradle.model.web.WebConfiguration @@ -68,70 +66,27 @@ class WarModelBuilderImpl implements ModelBuilderService { final List webResources = [] final War warTask = task as War warModel.webXml = warTask.webXml - warTask.rootSpec.setIncludeEmptyDirs(true) - try { - warTask.rootSpec.walk({ def resolver -> - // def resolver -> - // in Gradle v1.x - org.gradle.api.internal.file.copy.CopySpecInternal - // in Gradle v2.x - org.gradle.api.internal.file.copy.CopySpecResolver - - if (resolver.metaClass.respondsTo(resolver, 'setIncludeEmptyDirs', boolean)) { - resolver.setIncludeEmptyDirs(true) - } - if (!resolver.metaClass.respondsTo(resolver, 'getDestPath') || - !resolver.metaClass.respondsTo(resolver, 'getSource')) { - throw new RuntimeException("${GradleVersion.current()} is not supported by web artifact importer") + CopySpecWalker.walk(warTask.rootSpec, new CopySpecWalker.Visitor() { + @Override + void visitSourcePath(String relativePath, String path) { + def file = new File(path) + addPath(webResources, relativePath, "", file.absolute ? file : new File(warTask.project.projectDir, path)) } - final String relativePath = resolver.destPath.pathString - def sourcePaths - - if (resolver.metaClass.respondsTo(resolver, 'getSourcePaths')) { - sourcePaths = resolver.getSourcePaths() - } else if (resolver.hasProperty('sourcePaths')) { - sourcePaths = resolver.sourcePaths - } else if (resolver.hasProperty('this$0') && resolver.this$0.metaClass.respondsTo(resolver, 'getSourcePaths')) { - sourcePaths = resolver.this$0.getSourcePaths() - } else if (resolver.hasProperty('this$0') && resolver.this$0.hasProperty('sourcePaths')) { - sourcePaths = resolver.this$0.sourcePaths - } /*else { - throw new RuntimeException("${GradleVersion.current()} is not supported by web artifact importer") - }*/ - - if(sourcePaths) { - (sourcePaths.flatten() as List).each { def path -> - if (path instanceof String) { - def file = new File(path) - addPath(webResources, relativePath, "", file.absolute ? file : new File(warTask.project.projectDir, path)) - } - } + @Override + void visitDir(String relativePath, FileVisitDetails dirDetails) { + addPath(webResources, relativePath, dirDetails.path, dirDetails.file) } - resolver.source.visit(new FileVisitor() { - @Override - public void visitDir(FileVisitDetails dirDetails) { - try { - addPath(webResources, relativePath, dirDetails.path, dirDetails.file) - } - catch (Exception ignore) { - } + @Override + void visitFile(String relativePath, FileVisitDetails fileDetails) { + if (warTask.webXml == null || + !fileDetails.file.canonicalPath.equals(warTask.webXml.canonicalPath)) { + addPath(webResources, relativePath, fileDetails.path, fileDetails.file) } - - @Override - public void visitFile(FileVisitDetails fileDetails) { - try { - if (warTask.webXml == null || - !fileDetails.file.canonicalPath.equals(warTask.webXml.canonicalPath)) { - addPath(webResources, relativePath, fileDetails.path, fileDetails.file) - } - } - catch (Exception ignore) { - } - } - }) + } }) - warModel.classpath = warTask.classpath.files } catch (Exception ignore) { @@ -158,7 +113,7 @@ class WarModelBuilderImpl implements ModelBuilderService { @Override public ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) { ErrorMessageBuilder.create( - project, e, "Web project import errors" + project, e, "JEE project import errors" ).withDescription("Web Facets/Artifacts will not be configured properly") } diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarConfigurationImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarConfigurationImpl.java new file mode 100644 index 000000000000..ebd9242f9be4 --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarConfigurationImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.tooling.internal.ear; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ExternalDependency; +import org.jetbrains.plugins.gradle.model.ear.EarConfiguration; + +import java.util.Collection; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 11/10/2015 + */ +public class EarConfigurationImpl implements EarConfiguration { + + @NotNull + private final List myEarModels; + @NotNull + private final Collection myDeployDependencies; + @NotNull + private final Collection myEarlibDependencies; + + public EarConfigurationImpl(@NotNull List earModels, + @NotNull Collection deployDependencies, + @NotNull Collection earlibDependencies) { + myEarModels = earModels; + myDeployDependencies = deployDependencies; + myEarlibDependencies = earlibDependencies; + } + + @Override + public List getEarModels() { + return myEarModels; + } + + @NotNull + @Override + public Collection getDeployDependencies() { + return myDeployDependencies; + } + + @NotNull + @Override + public Collection getEarlibDependencies() { + return myEarlibDependencies; + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarModelImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarModelImpl.java new file mode 100644 index 000000000000..41a8c695ec92 --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarModelImpl.java @@ -0,0 +1,85 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.tooling.internal.ear; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ear.EarConfiguration; + +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 11/10/2015 + */ +public class EarModelImpl implements EarConfiguration.EarModel { + @NotNull + private final String myEarName; + private final String myAppDirName; + private final String myLibDirName; + private List myEarResources; + private String myManifestContent; + private String myDeploymentDescriptor; + + public EarModelImpl(@NotNull String name, @NotNull String appDirName, String libDirName) { + myEarName = name; + myAppDirName = appDirName; + myLibDirName = libDirName; + } + + @NotNull + @Override + public String getEarName() { + return myEarName; + } + + @NotNull + @Override + public String getAppDirName() { + return myAppDirName; + } + + @Override + public String getLibDirName() { + return myLibDirName; + } + + @Override + public List getResources() { + return myEarResources; + } + + public void setResources(List earResources) { + myEarResources = earResources; + } + + public void setManifestContent(String manifestContent) { + myManifestContent = manifestContent; + } + + @Override + public String getManifestContent() { + return myManifestContent; + } + + @Override + public String getDeploymentDescriptor() { + return myDeploymentDescriptor; + } + + public void setDeploymentDescriptor(String deploymentDescriptor) { + myDeploymentDescriptor = deploymentDescriptor; + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarResourceImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarResourceImpl.java new file mode 100644 index 000000000000..37f5277026f0 --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ear/EarResourceImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright 2000-2015 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. + */ +package org.jetbrains.plugins.gradle.tooling.internal.ear; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ear.EarConfiguration; + +import java.io.File; + +/** + * @author Vladislav.Soroka + * @since 2/10/14 + */ +public class EarResourceImpl implements EarConfiguration.EarResource { + @NotNull + private final String myEarDirectory; + @NotNull + private final String myRelativePath; + @NotNull + private final File file; + + public EarResourceImpl(@NotNull String earDirectory, @NotNull String relativePath, @NotNull File file) { + myEarDirectory = earDirectory; + this.myRelativePath = relativePath; + this.file = file; + } + + @NotNull + @Override + public String getEarDirectory() { + return myEarDirectory; + } + + @NotNull + @Override + public String getRelativePath() { + return myRelativePath; + } + + @NotNull + @Override + public File getFile() { + return file; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof EarResourceImpl)) return false; + + EarResourceImpl resource = (EarResourceImpl)o; + if (!file.getPath().equals(resource.file.getPath())) return false; + if (myEarDirectory != resource.myEarDirectory) return false; + if (!myRelativePath.equals(resource.myRelativePath)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myEarDirectory.hashCode(); + result = 31 * result + myRelativePath.hashCode(); + result = 31 * result + file.getPath().hashCode(); + return result; + } + + @Override + public String toString() { + return "EarResource{" + + "earDirectory=" + myEarDirectory + + ", warRelativePath='" + myRelativePath + '\'' + + ", file=" + file + + '}'; + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/util/DependencyResolverImpl.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/util/DependencyResolverImpl.groovy index e1b021a49697..521df59d04af 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/util/DependencyResolverImpl.groovy +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/util/DependencyResolverImpl.groovy @@ -565,8 +565,9 @@ class DependencyResolverImpl implements DependencyResolver { group: project.group, version: project.version, scope: scope, - projectPath: project.path + projectPath: project.path, ) + projectDependency.projectDependencyArtifacts = it.projectConfiguration.allArtifacts.files.collect {it.path} result.add(projectDependency) } else if (it instanceof Dependency) { @@ -639,6 +640,7 @@ class DependencyResolverImpl implements DependencyResolver { selectionReason: selectionReason, projectPath: componentSelector.projectPath ) + dependency.projectDependencyArtifacts = artifactMap.get(componentResult.moduleVersion).collect {it.file.path} if (componentResult != dependencyResult.from) { dependency.dependencies.addAll( transform(handledDependencyResults, componentResult.dependencies, artifactMap, componentResultsMap, scope)