gradle: ear artifacts support

This commit is contained in:
Vladislav.Soroka
2015-11-23 15:25:02 +03:00
parent f858e8999e
commit 6cbdb7ef76
24 changed files with 1343 additions and 340 deletions
@@ -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<ModuleData> {
private static final long serialVersionUID = 1L;
private boolean myProductionOnTestDependency;
private Collection<String> myModuleDependencyArtifacts;
public ModuleDependencyData(@NotNull ModuleData ownerModule, @NotNull ModuleData module) {
super(ownerModule, module);
@@ -23,15 +26,31 @@ public class ModuleDependencyData extends AbstractDependencyData<ModuleData> {
myProductionOnTestDependency = productionOnTestDependency;
}
public Collection<String> getModuleDependencyArtifacts() {
return myModuleDependencyArtifacts;
}
public void setModuleDependencyArtifacts(Collection<String> 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;
}
}
@@ -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<ModuleData> ideModule) {
final List<War> warModels;
final WebConfiguration webConfiguration = resolverCtx.getExtraProject(gradleModule, WebConfiguration.class);
if (webConfiguration != null) {
warModels = ContainerUtil.map(webConfiguration.getWarModels(), new Function<WebConfiguration.WarModel, War>() {
@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<? extends ModuleData> targetModuleNode =
ExternalSystemApiUtil.find(ideModule, GradleSourceSetData.KEY, new BooleanFunction<DataNode<GradleSourceSetData>>() {
@Override
public boolean fun(DataNode<GradleSourceSetData> node) {
return mainSourceSetModuleId.equals(node.getData().getId());
}
});
if(targetModuleNode == null) {
targetModuleNode = ideModule;
final NotNullLazyValue<DataNode<? extends ModuleData>> findTargetModuleNode = new NotNullLazyValue<DataNode<? extends ModuleData>>() {
@NotNull
@Override
protected DataNode<? extends ModuleData> compute() {
final String mainSourceSetModuleId = ideModule.getData().getId() + ":main";
DataNode<? extends ModuleData> targetModuleNode =
ExternalSystemApiUtil.find(ideModule, GradleSourceSetData.KEY, new BooleanFunction<DataNode<GradleSourceSetData>>() {
@Override
public boolean fun(DataNode<GradleSourceSetData> 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<War> warModels = ContainerUtil.map(webConfiguration.getWarModels(), new Function<WebConfiguration.WarModel, War>() {
@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<Ear> warModels = ContainerUtil.map(earConfiguration.getEarModels(), new Function<EarConfiguration.EarModel, Ear>() {
@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<DependencyData> deployDependencies =
GradleProjectResolverUtil.getIdeDependencies(findTargetModuleNode.getValue(), earConfiguration.getDeployDependencies());
final Collection<DependencyData> 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<Class> getExtraProjectModelClasses() {
return Collections.<Class>singleton(WebConfiguration.class);
return ContainerUtil.<Class>set(WebConfiguration.class, EarConfiguration.class);
}
private static List<WebResource> map(List<WebConfiguration.WebResource> webResources) {
private static List<WebResource> mapWebResources(List<WebConfiguration.WebResource> webResources) {
return ContainerUtil.mapNotNull(webResources, new Function<WebConfiguration.WebResource, WebResource>() {
@Override
public WebResource fun(WebConfiguration.WebResource resource) {
@@ -95,4 +129,16 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve
}
});
}
private static List<EarResource> mapEarResources(List<EarConfiguration.EarResource> resources) {
return ContainerUtil.mapNotNull(resources, new Function<EarConfiguration.EarResource, EarResource>() {
@Override
public EarResource fun(EarConfiguration.EarResource resource) {
if (resource == null) return null;
return new EarResource(resource.getEarDirectory(), resource.getRelativePath(), resource.getFile());
}
});
}
}
@@ -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<EarResource> 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<EarResource> getResources() {
return myResources;
}
public void setResources(@NotNull List<EarResource> 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 + '\'' +
'}';
}
}
@@ -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<EarConfigurationModelData> KEY =
Key.create(EarConfigurationModelData.class, WebConfigurationModelData.KEY.getProcessingWeight() + 1);
@NotNull
private final List<Ear> myEars;
@NotNull
private final Collection<DependencyData> myDeployDependencies;
@NotNull
private final Collection<DependencyData> myEarlibDependencies;
public EarConfigurationModelData(@NotNull ProjectSystemId owner,
@NotNull List<Ear> ears,
@NotNull Collection<DependencyData> deployDependencies,
@NotNull Collection<DependencyData> earlibDependencies) {
super(owner);
myEars = ears;
myDeployDependencies = deployDependencies;
myEarlibDependencies = earlibDependencies;
}
@NotNull
public List<Ear> getEars() {
return myEars;
}
@NotNull
public Collection<DependencyData> getDeployDependencies() {
return myDeployDependencies;
}
@NotNull
public Collection<DependencyData> 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 + '\'';
}
}
@@ -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 +
'}';
}
}
@@ -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 + "'}";
}
}
@@ -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<WebResource> myWebResources;
@NotNull
private Set<File> 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 +
'}';
}
}
@@ -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<File> artifacts = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY);
if ("main".equals(sourceSet.getName())) {
final List<File> artifacts = ContainerUtil.newArrayList();
final Set<File> defaultArtifacts = externalProject.getArtifactsByConfiguration().get("default");
if (defaultArtifacts != null) {
artifacts.addAll(defaultArtifacts);
}
sourceSetData.setArtifacts(artifacts);
final Set<File> archivesArtifacts = externalProject.getArtifactsByConfiguration().get("archives");
if (archivesArtifacts != null) {
artifacts.addAll(archivesArtifacts);
}
} else if("test".equals(sourceSet.getName())) {
final Set<File> testsArtifacts = externalProject.getArtifactsByConfiguration().get("tests");
if (testsArtifacts != null) {
artifacts.addAll(testsArtifacts);
}
}
sourceSetData.setArtifacts(ContainerUtil.newArrayList(artifacts));
DataNode<GradleSourceSetData> sourceSetDataNode = mainModuleNode.createChild(GradleSourceSetData.KEY, sourceSetData);
final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap =
@@ -407,60 +418,7 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
processSourceSets(externalProject, ideModule, new SourceSetsProcessor() {
@Override
public void process(@NotNull DataNode<GradleSourceSetData> dataNode, @NotNull ExternalSourceSet sourceSet) {
Map<ExternalDependencyId, ExternalDependency> dependencyMap = ContainerUtil.newHashMap();
Queue<ExternalDependency> 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<Class> getExtraProjectModelClasses() {
Set<Class> result = ContainerUtil.<Class>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<ModuleData> ownerModule,
@NotNull IdeaSingleEntryLibraryDependency dependency,
@NotNull DataNode<ProjectData> 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<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap,
@NotNull Map<ExternalDependencyId, ExternalDependency> mergedDependencyMap,
@NotNull DataNode<? extends ExternalEntityData> ownerDataNode,
@NotNull Collection<ExternalDependency> dependencies,
@NotNull DataNode<ProjectData> ideProject) throws IllegalStateException {
Map<ExternalDependencyId, ExternalDependency> 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<DataNode<GradleSourceSetData>, 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<ModuleDependencyData> 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<LibraryDependencyData> 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<LibraryDependencyData> 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<ProjectData> ideProject, @NotNull final LibraryData library) {
DataNode<LibraryData> libraryData =
ExternalSystemApiUtil.find(ideProject, ProjectKeys.LIBRARY, new BooleanFunction<DataNode<LibraryData>>() {
@Override
public boolean fun(DataNode<LibraryData> node) {
return library.equals(node.getData());
}
});
if (libraryData == null) {
ideProject.createChild(ProjectKeys.LIBRARY, library);
}
}
interface SourceSetsProcessor {
void process(@NotNull DataNode<GradleSourceSetData> dataNode, @NotNull ExternalSourceSet sourceSet);
}
@@ -142,6 +142,12 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
final List<String> commandLineArgs = ContainerUtil.newArrayList();
final Set<Class> toolingExtensionClasses = ContainerUtil.newHashSet();
if(resolverCtx.isPreviewMode()){
commandLineArgs.add("-Didea.isPreviewMode=true");
final Set<Class> previewLightWeightToolingModels = ContainerUtil.<Class>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<Grad
resolverExtension.setProjectResolverContext(resolverCtx);
// pre-import checks
resolverExtension.preImportCheck();
// register classes of extra gradle project models required for extensions (e.g. com.android.builder.model.AndroidProject)
projectImportAction.addExtraProjectModelClasses(resolverExtension.getExtraProjectModelClasses());
if(!resolverCtx.isPreviewMode()){
// register classes of extra gradle project models required for extensions (e.g. com.android.builder.model.AndroidProject)
projectImportAction.addExtraProjectModelClasses(resolverExtension.getExtraProjectModelClasses());
}
if (importCustomizer == null || importCustomizer.useExtraJvmArgs()) {
// collect extra JVM arguments provided by gradle project resolver extensions
@@ -295,7 +304,6 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
}
}
projectResolverChain.populateModuleExtraModels(ideaModule, moduleDataNode);
projectResolverChain.populateModuleContentRoots(ideaModule, moduleDataNode);
projectResolverChain.populateModuleCompileOutputSettings(ideaModule, moduleDataNode);
if (!isBuildSrcProject) {
@@ -333,6 +341,7 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
final DataNode<ModuleData> moduleDataNode = pair.first;
final IdeaModule ideaModule = pair.second;
projectResolverChain.populateModuleDependencies(ideaModule, moduleDataNode, projectDataNode);
projectResolverChain.populateModuleExtraModels(ideaModule, moduleDataNode);
}
mergeSourceSetContentRoots(moduleMap, resolverCtx);
mergeLibraryAndModuleDependencyData(projectDataNode, gradleHomeDir, gradleVersion);
@@ -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<Object> 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<DependencyData> getIdeDependencies(@NotNull DataNode<? extends ModuleData> moduleDataNode,
@NotNull Collection<ExternalDependency> dependencies)
throws IllegalStateException {
final DataNode<ProjectData> ideProject = ExternalSystemApiUtil.findParent(moduleDataNode, ProjectKeys.PROJECT);
assert ideProject != null;
final Map<String, Pair<DataNode<GradleSourceSetData>, 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<DataNode<?>> dataNodes =
ExternalSystemApiUtil.findAllRecursively(fakeNode, new BooleanFunction<DataNode<?>>() {
@Override
public boolean fun(DataNode<?> node) {
return node.getData() instanceof DependencyData;
}
});
return ContainerUtil.map(dataNodes, new Function<DataNode<?>, DependencyData>() {
@Override
public DependencyData fun(DataNode<?> node) {
return (DependencyData)node.getData();
}
});
}
public static void buildDependencies(@NotNull Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap,
@NotNull DataNode<? extends ExternalEntityData> ownerDataNode,
@NotNull Collection<ExternalDependency> dependencies,
@Nullable DataNode<ProjectData> ideProject) throws IllegalStateException {
Map<ExternalDependencyId, ExternalDependency> dependencyMap = ContainerUtil.newHashMap();
Queue<ExternalDependency> queue = ContainerUtil.newLinkedList(dependencies);
while (!queue.isEmpty()) {
final ExternalDependency dependency = queue.remove();
ExternalDependency seenDependency = dependencyMap.get(dependency.getId());
if (seenDependency != null) {
if (dependency instanceof ExternalLibraryDependency) {
if (seenDependency instanceof ExternalLibraryDependency &&
!FileUtil.filesEqual(((ExternalLibraryDependency)seenDependency).getFile(),
((ExternalLibraryDependency)dependency).getFile())) {
DefaultExternalMultiLibraryDependency mergedDependency = new DefaultExternalMultiLibraryDependency();
mergedDependency.setName(dependency.getId().getName());
mergedDependency.setGroup(dependency.getId().getGroup());
mergedDependency.setVersion(dependency.getId().getVersion());
mergedDependency.setPackaging(dependency.getId().getPackaging());
mergedDependency.setClassifier(dependency.getId().getClassifier());
mergedDependency.setScope(dependency.getScope());
mergedDependency.setClasspathOrder(dependency.getClasspathOrder());
mergedDependency.getDependencies().addAll(dependency.getDependencies());
mergedDependency.getFiles().addAll(ContainerUtil.packNullables(
((ExternalLibraryDependency)seenDependency).getFile(), ((ExternalLibraryDependency)dependency).getFile()));
mergedDependency.getSources().addAll((ContainerUtil.packNullables(
((ExternalLibraryDependency)seenDependency).getSource(), ((ExternalLibraryDependency)dependency).getSource())));
mergedDependency.getJavadoc().addAll((ContainerUtil.packNullables(
((ExternalLibraryDependency)seenDependency).getJavadoc(), ((ExternalLibraryDependency)dependency).getJavadoc())));
dependencyMap.put(dependency.getId(), mergedDependency);
continue;
}
else if (seenDependency instanceof DefaultExternalMultiLibraryDependency) {
DefaultExternalMultiLibraryDependency mergedDependency = (DefaultExternalMultiLibraryDependency)seenDependency;
mergedDependency.getFiles().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency)dependency).getFile()));
mergedDependency.getSources().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency)dependency).getSource()));
mergedDependency.getJavadoc().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency)dependency).getJavadoc()));
continue;
}
}
DependencyScope prevScope =
seenDependency.getScope() == null ? DependencyScope.COMPILE : DependencyScope.valueOf(seenDependency.getScope());
DependencyScope currentScope =
dependency.getScope() == null ? DependencyScope.COMPILE : DependencyScope.valueOf(dependency.getScope());
if (prevScope.isForProductionCompile()) continue;
if (prevScope.isForProductionRuntime() && currentScope.isForProductionRuntime()) continue;
}
dependencyMap.put(new DefaultExternalDependencyId(dependency.getId()), dependency);
queue.addAll(dependency.getDependencies());
}
doBuildDependencies(sourceSetMap, dependencyMap, ownerDataNode, dependencies, ideProject);
}
private static void doBuildDependencies(@NotNull Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap,
@NotNull Map<ExternalDependencyId, ExternalDependency> mergedDependencyMap,
@NotNull DataNode<? extends ExternalEntityData> ownerDataNode,
@NotNull Collection<ExternalDependency> dependencies,
@Nullable DataNode<ProjectData> ideProject) throws IllegalStateException {
Map<ExternalDependencyId, ExternalDependency> 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<DataNode<GradleSourceSetData>, 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<ModuleDependencyData> 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<LibraryDependencyData> 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<LibraryDependencyData> 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<ProjectData> ideProject, @NotNull final LibraryData library) {
if (ideProject == null) return;
DataNode<LibraryData> libraryData =
ExternalSystemApiUtil.find(ideProject, ProjectKeys.LIBRARY, new BooleanFunction<DataNode<LibraryData>>() {
@Override
public boolean fun(DataNode<LibraryData> 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");
@@ -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" +
@@ -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<String> getProjectDependencyArtifacts();
}
@@ -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<? extends EarModel> getEarModels();
@NotNull
Collection<ExternalDependency> getDeployDependencies();
@NotNull
Collection<ExternalDependency> getEarlibDependencies();
interface EarModel extends Serializable {
@NotNull
String getEarName();
String getManifestContent();
@NotNull
String getAppDirName();
String getLibDirName();
List<EarResource> getResources();
String getDeploymentDescriptor();
}
interface EarResource extends Serializable {
@NotNull
String getEarDirectory();
@NotNull
String getRelativePath();
@NotNull
File getFile();
}
}
@@ -68,10 +68,12 @@
<root url="jar://$MODULE_DIR$/../tooling-extension-api/lib/gradle-scala-2.5.jar!/" />
<root url="jar://$MODULE_DIR$/../tooling-extension-api/lib/gradle-language-scala-2.5.jar!/" />
<root url="jar://$MODULE_DIR$/lib/gradle-reporting-2.5.jar!/" />
<root url="jar://$MODULE_DIR$/lib/gradle-ear-2.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../lib/gradle-2.5-src.zip!/gradle-2.5/subprojects/tooling-api/src/main/java" />
<root url="jar://$MODULE_DIR$/../lib/gradle-2.5-src.zip!/gradle-2.5/subprojects/ear/src/main/groovy" />
</SOURCES>
</library>
</orderEntry>
@@ -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
@@ -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<String> myProjectDependencyArtifacts;
public DefaultExternalProjectDependency() {
}
public DefaultExternalProjectDependency(ExternalProjectDependency dependency) {
super(dependency);
projectPath = dependency.getProjectPath();
myProjectPath = dependency.getProjectPath();
myProjectDependencyArtifacts =
dependency.getProjectDependencyArtifacts() == null
? new ArrayList<String>()
: new ArrayList<String>(dependency.getProjectDependencyArtifacts());
}
@Override
public String getProjectPath() {
return projectPath;
return myProjectPath;
}
public void setProjectPath(String projectPath) {
this.projectPath = projectPath;
this.myProjectPath = projectPath;
}
@Override
public Collection<String> getProjectDependencyArtifacts() {
return myProjectDependencyArtifacts;
}
public void setProjectDependencyArtifacts(Collection<String> 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 + '\'';
}
}
@@ -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) {
}
}
})
})
}
}
@@ -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<EarConfiguration.EarResource> 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<EarConfiguration.EarResource> 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)
}
}
@@ -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<WebConfiguration.WebResource> 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")
}
@@ -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<EarConfiguration.EarModel> myEarModels;
@NotNull
private final Collection<ExternalDependency> myDeployDependencies;
@NotNull
private final Collection<ExternalDependency> myEarlibDependencies;
public EarConfigurationImpl(@NotNull List<EarConfiguration.EarModel> earModels,
@NotNull Collection<ExternalDependency> deployDependencies,
@NotNull Collection<ExternalDependency> earlibDependencies) {
myEarModels = earModels;
myDeployDependencies = deployDependencies;
myEarlibDependencies = earlibDependencies;
}
@Override
public List<? extends EarConfiguration.EarModel> getEarModels() {
return myEarModels;
}
@NotNull
@Override
public Collection<ExternalDependency> getDeployDependencies() {
return myDeployDependencies;
}
@NotNull
@Override
public Collection<ExternalDependency> getEarlibDependencies() {
return myEarlibDependencies;
}
}
@@ -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<EarConfiguration.EarResource> 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<EarConfiguration.EarResource> getResources() {
return myEarResources;
}
public void setResources(List<EarConfiguration.EarResource> 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;
}
}
@@ -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 +
'}';
}
}
@@ -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)