mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-116974 Gradle Plugin doesn't handle 'providedCompile' dependencies in 'war' projects correctly
This commit is contained in:
+2
-1
@@ -77,6 +77,7 @@ public abstract class AbstractDependencyData<T extends AbstractExternalEntityDat
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + myScope.hashCode();
|
||||
result = 31 * result + myOwnerModule.hashCode();
|
||||
result = 31 * result + myTarget.hashCode();
|
||||
return result;
|
||||
@@ -88,7 +89,7 @@ public abstract class AbstractDependencyData<T extends AbstractExternalEntityDat
|
||||
return false;
|
||||
}
|
||||
AbstractDependencyData<?> that = (AbstractDependencyData<?>)o;
|
||||
return myOwnerModule.equals(that.myOwnerModule) && myTarget.equals(that.myTarget);
|
||||
return myScope.equals(that.myScope) && myOwnerModule.equals(that.myOwnerModule) && myTarget.equals(that.myTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -112,7 +112,7 @@ public class LibraryDependencyDataService extends AbstractDependencyDataService<
|
||||
// The trick is that we should perform module settings modification inside try/finally block against target root model.
|
||||
// That means that we need to prepare all necessary data, obtain a model and modify it as necessary.
|
||||
Map<Set<String>/* library paths */, LibraryDependencyData> moduleLibrariesToImport = ContainerUtilRt.newHashMap();
|
||||
Map<String/* library name */, LibraryDependencyData> projectLibrariesToImport = ContainerUtilRt.newHashMap();
|
||||
Map<String/* library name + scope */, LibraryDependencyData> projectLibrariesToImport = ContainerUtilRt.newHashMap();
|
||||
Set<LibraryDependencyData> toImport = ContainerUtilRt.newLinkedHashSet();
|
||||
|
||||
boolean hasUnresolved = false;
|
||||
@@ -132,7 +132,7 @@ public class LibraryDependencyDataService extends AbstractDependencyDataService<
|
||||
}
|
||||
break;
|
||||
case PROJECT:
|
||||
projectLibrariesToImport.put(ExternalSystemApiUtil.getLibraryName(libraryData), dependencyData);
|
||||
projectLibrariesToImport.put(ExternalSystemApiUtil.getLibraryName(libraryData) + dependencyData.getScope().name(), dependencyData);
|
||||
toImport.add(dependencyData);
|
||||
}
|
||||
}
|
||||
@@ -224,8 +224,8 @@ public class LibraryDependencyDataService extends AbstractDependencyDataService<
|
||||
else if (entry instanceof LibraryOrderEntry) {
|
||||
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
|
||||
final String libraryName = libraryOrderEntry.getLibraryName();
|
||||
final LibraryDependencyData existing = projectLibrariesToImport.remove(libraryName);
|
||||
if (existing != null && libraryOrderEntry.getScope() == existing.getScope()) {
|
||||
final LibraryDependencyData existing = projectLibrariesToImport.remove(libraryName + libraryOrderEntry.getScope().name());
|
||||
if (existing != null) {
|
||||
toImport.remove(existing);
|
||||
}
|
||||
else if (!hasUnresolvedLibraries) {
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class ExternalProjectServiceTest extends AbstractExternalSystemTest {
|
||||
dependencies[name]++
|
||||
}
|
||||
}
|
||||
ExternalSystemTestUtil.assertMapsEqual(['lib1': 1, 'lib2': 1], dependencies)
|
||||
ExternalSystemTestUtil.assertMapsEqual(['Test_external_system_id: lib1': 1, 'Test_external_system_id: lib2': 1], dependencies)
|
||||
}
|
||||
|
||||
void 'test changes in a project layout (content roots) could be detected on Refresh'() {
|
||||
|
||||
+3
-3
@@ -13,6 +13,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
org.jetbrains.plugins.gradle.model.impl.WarModelBuilderImpl
|
||||
org.jetbrains.plugins.gradle.model.impl.ModelDependenciesBuilderImpl
|
||||
org.jetbrains.plugins.gradle.model.impl.ModuleExtendedModelBuilderImpl
|
||||
org.jetbrains.plugins.gradle.model.builder.WarModelBuilderImpl
|
||||
org.jetbrains.plugins.gradle.model.builder.ModelDependenciesBuilderImpl
|
||||
org.jetbrains.plugins.gradle.model.builder.ModuleExtendedModelBuilderImpl
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public enum GradleDependencyScope {
|
||||
// Implicit scopes
|
||||
PROVIDED("provided", "provided", true, true, true, true),
|
||||
OPTIONAL("optional", "compile", true, true, true, true),
|
||||
|
||||
|
||||
// Java Plugin Scopes
|
||||
/**
|
||||
* Compile time dependencies
|
||||
*/
|
||||
COMPILE("compile", "compile", true, true, true, true),
|
||||
/**
|
||||
* Runtime dependencies
|
||||
*/
|
||||
RUNTIME("runtime", "runtime", false, true, false, true),
|
||||
/**
|
||||
* Additional dependencies for compiling tests.
|
||||
*/
|
||||
TEST_COMPILE("testCompile", "test", false, false, true, true),
|
||||
/**
|
||||
* Additional dependencies for running tests only.
|
||||
*/
|
||||
TEST_RUNTIME("testRuntime", "test", false, false, false, true),
|
||||
|
||||
|
||||
// War Plugin Scopes
|
||||
/**
|
||||
* the same scope as the compile scope dependencies, except that they are not added to the WAR archive.
|
||||
*/
|
||||
PROVIDED_COMPILE("providedCompile", "provided", true, true, true, true),
|
||||
/**
|
||||
* the same scope as the runtime scope dependencies, except that they are not added to the WAR archive.
|
||||
*/
|
||||
PROVIDED_RUNTIME("providedRuntime", "provided", false, true, false, true),
|
||||
|
||||
// Groovy Plugin Scopes
|
||||
/**
|
||||
* Compiles production Groovy source files.
|
||||
*/
|
||||
COMPILE_GROOVY("compileGroovy", "compile", true, true, true, true),
|
||||
/**
|
||||
* Compiles test Groovy source files.
|
||||
*/
|
||||
COMPILE_TEST_GROOVY("compileTestGroovy", "test", false, false, true, true),
|
||||
|
||||
// Scala Plugin Scopes
|
||||
/**
|
||||
* Compiles production Scala source files.
|
||||
*/
|
||||
COMPILE_SCALA("compileScala", "compile", true, true, true, true),
|
||||
/**
|
||||
* Compiles test Scala source files.
|
||||
*/
|
||||
COMPILE_TEST_SCALA("compileTestScala", "test", false, false, true, true);
|
||||
|
||||
private final String myGradleName;
|
||||
private final String myIdeaMappingName;
|
||||
private final boolean myForProductionCompile;
|
||||
private final boolean myForProductionRuntime;
|
||||
private final boolean myForTestCompile;
|
||||
private final boolean myForTestRuntime;
|
||||
|
||||
GradleDependencyScope(String gradleName,
|
||||
String ideaMappingName,
|
||||
boolean forProductionCompile,
|
||||
boolean forProductionRuntime,
|
||||
boolean forTestCompile,
|
||||
boolean forTestRuntime) {
|
||||
myGradleName = gradleName;
|
||||
myIdeaMappingName = ideaMappingName;
|
||||
myForProductionCompile = forProductionCompile;
|
||||
myForProductionRuntime = forProductionRuntime;
|
||||
myForTestCompile = forTestCompile;
|
||||
myForTestRuntime = forTestRuntime;
|
||||
}
|
||||
|
||||
public boolean isForProductionCompile() {
|
||||
return myForProductionCompile;
|
||||
}
|
||||
|
||||
public boolean isForProductionRuntime() {
|
||||
return myForProductionRuntime;
|
||||
}
|
||||
|
||||
public boolean isForTestCompile() {
|
||||
return myForTestCompile;
|
||||
}
|
||||
|
||||
public boolean isForTestRuntime() {
|
||||
return myForTestRuntime;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GradleDependencyScope fromName(final String scopeName) {
|
||||
for (GradleDependencyScope scope : values()) {
|
||||
if (scope.myGradleName.equals(scopeName)) return scope;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getIdeaMappingName() {
|
||||
return myIdeaMappingName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myGradleName;
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model;
|
||||
|
||||
import org.jetbrains.plugins.gradle.model.impl.GradleDependency;
|
||||
import org.jetbrains.plugins.gradle.model.impl.GradleDependencyImpl;
|
||||
import org.gradle.tooling.model.idea.IdeaDependency;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -29,5 +28,5 @@ public interface ProjectDependenciesModel extends Serializable {
|
||||
|
||||
String getProjectName();
|
||||
|
||||
List<GradleDependency> getDependencies();
|
||||
List<IdeaDependency> getDependencies();
|
||||
}
|
||||
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.builder;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ModuleVersionIdentifier;
|
||||
import org.gradle.plugins.ide.idea.IdeaPlugin;
|
||||
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
||||
import org.gradle.plugins.ide.internal.IdeDependenciesExtractor;
|
||||
import org.gradle.tooling.model.idea.IdeaDependency;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.model.GradleDependencyScope;
|
||||
import org.jetbrains.plugins.gradle.model.ModelBuilderService;
|
||||
import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel;
|
||||
import org.jetbrains.plugins.gradle.model.internal.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/5/13
|
||||
*/
|
||||
public class ModelDependenciesBuilderImpl implements ModelBuilderService {
|
||||
|
||||
@Override
|
||||
public boolean canBuild(String modelName) {
|
||||
return ProjectDependenciesModel.class.getName().equals(modelName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object buildAll(final String modelName, final Project project) {
|
||||
final List<IdeaDependency> dependencies = new ArrayList<IdeaDependency>();
|
||||
|
||||
final Map<DependencyVersionId, Scopes> scopesMap = new HashMap<DependencyVersionId, Scopes>();
|
||||
final IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor();
|
||||
|
||||
boolean offline = false;
|
||||
boolean downloadJavadoc = false;
|
||||
boolean downloadSources = true;
|
||||
|
||||
final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class);
|
||||
if (ideaPlugin != null) {
|
||||
IdeaModel ideaModel = ideaPlugin.getModel();
|
||||
if (ideaModel != null && ideaModel.getModule() == null) {
|
||||
offline = ideaModel.getModule().isOffline();
|
||||
downloadJavadoc = ideaModel.getModule().isDownloadJavadoc();
|
||||
downloadSources = ideaModel.getModule().isDownloadSources();
|
||||
}
|
||||
}
|
||||
|
||||
for (final Configuration configuration : project.getConfigurations()) {
|
||||
Collection<Configuration> plusConfigurations = new ArrayList<Configuration>();
|
||||
plusConfigurations.add(configuration);
|
||||
|
||||
final List<IdeDependenciesExtractor.IdeProjectDependency> ideProjectDependencies =
|
||||
dependenciesExtractor.extractProjectDependencies(plusConfigurations, new ArrayList<Configuration>());
|
||||
|
||||
for (IdeDependenciesExtractor.IdeProjectDependency ideProjectDependency : ideProjectDependencies) {
|
||||
merge(scopesMap, ideProjectDependency);
|
||||
}
|
||||
|
||||
if (!offline) {
|
||||
final Collection<IdeDependenciesExtractor.IdeRepoFileDependency> ideRepoFileDependencies =
|
||||
dependenciesExtractor.extractRepoFileDependencies(
|
||||
project.getConfigurations(), plusConfigurations, new ArrayList<Configuration>(), downloadSources, downloadJavadoc);
|
||||
for (IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency : ideRepoFileDependencies) {
|
||||
merge(scopesMap, repoFileDependency);
|
||||
}
|
||||
}
|
||||
|
||||
final List<IdeDependenciesExtractor.IdeLocalFileDependency> ideLocalFileDependencies =
|
||||
dependenciesExtractor.extractLocalFileDependencies(plusConfigurations, new ArrayList<Configuration>());
|
||||
for (IdeDependenciesExtractor.IdeLocalFileDependency fileDependency : ideLocalFileDependencies) {
|
||||
merge(scopesMap, fileDependency);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<DependencyVersionId, Scopes> entry : scopesMap.entrySet()) {
|
||||
DependencyVersionId versionId = entry.getKey();
|
||||
for (GradleDependencyScope scope : entry.getValue().getScopes()) {
|
||||
if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeRepoFileDependency) {
|
||||
IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency =
|
||||
(IdeDependenciesExtractor.IdeRepoFileDependency)versionId.getIdeDependency();
|
||||
IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl(
|
||||
new IdeaDependencyScopeImpl(scope),
|
||||
versionId.getName(),
|
||||
versionId.getGroup(),
|
||||
versionId.getVersion()
|
||||
);
|
||||
libraryDependency.setFile(repoFileDependency.getFile());
|
||||
libraryDependency.setSource(repoFileDependency.getSourceFile());
|
||||
libraryDependency.setJavadoc(repoFileDependency.getJavadocFile());
|
||||
dependencies.add(libraryDependency);
|
||||
}
|
||||
else if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeProjectDependency) {
|
||||
IdeaModuleDependencyImpl moduleDependency = new IdeaModuleDependencyImpl(
|
||||
new IdeaDependencyScopeImpl(scope),
|
||||
versionId.getName(),
|
||||
versionId.getGroup(),
|
||||
versionId.getVersion()
|
||||
);
|
||||
moduleDependency.setIdeaModule(new StubIdeaModule(versionId.getName()));
|
||||
dependencies.add(moduleDependency);
|
||||
}
|
||||
else if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeLocalFileDependency) {
|
||||
IdeDependenciesExtractor.IdeLocalFileDependency fileDependency =
|
||||
(IdeDependenciesExtractor.IdeLocalFileDependency)versionId.getIdeDependency();
|
||||
IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl(
|
||||
new IdeaDependencyScopeImpl(scope),
|
||||
versionId.getName(),
|
||||
versionId.getGroup(),
|
||||
versionId.getVersion()
|
||||
);
|
||||
libraryDependency.setFile(fileDependency.getFile());
|
||||
dependencies.add(libraryDependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ProjectDependenciesModelImpl(project.getPath(), dependencies);
|
||||
}
|
||||
|
||||
private static void merge(Map<DependencyVersionId, Scopes> map, IdeDependenciesExtractor.IdeProjectDependency dependency) {
|
||||
final String configurationName = dependency.getDeclaredConfiguration().getName();
|
||||
final GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
|
||||
if (scope == null) return;
|
||||
|
||||
final Project project = dependency.getProject();
|
||||
final String version = project.hasProperty("version") ? str(project.property("version")) : "";
|
||||
final String group = project.hasProperty("group") ? str(project.property("group")) : "";
|
||||
|
||||
DependencyVersionId versionId =
|
||||
new DependencyVersionId(dependency, project.getName(), group, version);
|
||||
Scopes scopes = map.get(versionId);
|
||||
if (scopes == null) {
|
||||
map.put(versionId, new Scopes(scope));
|
||||
}
|
||||
else {
|
||||
scopes.add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
private static String str(Object o) {
|
||||
return String.valueOf(o == null ? "" : o);
|
||||
}
|
||||
|
||||
private static void merge(Map<DependencyVersionId, Scopes> map, IdeDependenciesExtractor.IdeRepoFileDependency dependency) {
|
||||
final String configurationName = dependency.getDeclaredConfiguration().getName();
|
||||
final GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
|
||||
if (scope == null) return;
|
||||
|
||||
ModuleVersionIdentifier dependencyId = dependency.getId();
|
||||
DependencyVersionId versionId =
|
||||
new DependencyVersionId(dependency, dependencyId.getName(), dependencyId.getGroup(), dependencyId.getVersion());
|
||||
Scopes scopes = map.get(versionId);
|
||||
if (scopes == null) {
|
||||
map.put(versionId, new Scopes(scope));
|
||||
}
|
||||
else {
|
||||
scopes.add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
private static void merge(Map<DependencyVersionId, Scopes> map, IdeDependenciesExtractor.IdeLocalFileDependency dependency) {
|
||||
|
||||
final String configurationName = dependency.getDeclaredConfiguration().getName();
|
||||
final GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
|
||||
if (scope == null) return;
|
||||
|
||||
String path = dependency.getFile().getPath();
|
||||
DependencyVersionId versionId =
|
||||
new DependencyVersionId(dependency, path, "", "");
|
||||
Scopes scopes = map.get(versionId);
|
||||
if (scopes == null) {
|
||||
map.put(versionId, new Scopes(scope));
|
||||
}
|
||||
else {
|
||||
scopes.add(scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model.impl;
|
||||
package org.jetbrains.plugins.gradle.model.builder;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.plugins.gradle.model.ModelBuilderService;
|
||||
import org.jetbrains.plugins.gradle.model.ModuleExtendedModel;
|
||||
import org.jetbrains.plugins.gradle.model.internal.IdeaContentRootImpl;
|
||||
import org.jetbrains.plugins.gradle.model.internal.IdeaSourceDirectoryImpl;
|
||||
import org.jetbrains.plugins.gradle.model.internal.ModuleExtendedModelImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
+2
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model.impl;
|
||||
package org.jetbrains.plugins.gradle.model.builder;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
@@ -27,6 +27,7 @@ import org.gradle.api.tasks.bundling.War;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.model.ModelBuilderService;
|
||||
import org.jetbrains.plugins.gradle.model.WarModel;
|
||||
import org.jetbrains.plugins.gradle.model.internal.WarModelImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.impl;
|
||||
|
||||
import org.gradle.tooling.model.Dependency;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/8/13
|
||||
*/
|
||||
public interface GradleDependency extends Dependency, Serializable {
|
||||
String getConfigurationName();
|
||||
|
||||
String getDependencyName();
|
||||
|
||||
String getDependencyGroup();
|
||||
|
||||
String getDependencyVersion();
|
||||
}
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.impl;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.model.ModelBuilderService;
|
||||
import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/5/13
|
||||
*/
|
||||
public class ModelDependenciesBuilderImpl implements ModelBuilderService {
|
||||
|
||||
@Override
|
||||
public boolean canBuild(String modelName) {
|
||||
return ProjectDependenciesModel.class.getName().equals(modelName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object buildAll(String modelName, Project project) {
|
||||
List<GradleDependency> dependencies = new ArrayList<GradleDependency>();
|
||||
|
||||
for (Configuration configuration : project.getConfigurations()) {
|
||||
for (Dependency dependency : configuration.getDependencies()) {
|
||||
if (dependency instanceof ClientModule) {
|
||||
ClientModule clientModule = (ClientModule)dependency;
|
||||
for (ModuleDependency moduleDependency : clientModule.getDependencies()) {
|
||||
dependencies.add(
|
||||
new GradleDependencyImpl(
|
||||
configuration.getName(),
|
||||
moduleDependency.getName(),
|
||||
moduleDependency.getGroup(),
|
||||
moduleDependency.getVersion()
|
||||
));
|
||||
ResolvedDependency resolvedDependency =
|
||||
findResolvedDependency(moduleDependency, configuration.getResolvedConfiguration().getFirstLevelModuleDependencies());
|
||||
if (resolvedDependency != null) {
|
||||
addTransitiveDependencies(dependencies, configuration.getName(), resolvedDependency.getChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
dependencies.add(
|
||||
new GradleDependencyImpl(
|
||||
configuration.getName(),
|
||||
dependency.getName(),
|
||||
dependency.getGroup(),
|
||||
dependency.getVersion()
|
||||
));
|
||||
}
|
||||
}
|
||||
return new ProjectDependenciesModelImpl(project.getPath(), dependencies);
|
||||
}
|
||||
|
||||
private static void addTransitiveDependencies(List<GradleDependency> dependencies,
|
||||
String configurationName,
|
||||
Set<ResolvedDependency> resolvedDependencies) {
|
||||
if (resolvedDependencies == null) return;
|
||||
for (ResolvedDependency resolvedDependency : resolvedDependencies) {
|
||||
dependencies.add(
|
||||
new GradleDependencyImpl(
|
||||
configurationName,
|
||||
resolvedDependency.getModuleName(),
|
||||
resolvedDependency.getModuleGroup(),
|
||||
resolvedDependency.getModuleVersion()
|
||||
));
|
||||
addTransitiveDependencies(dependencies, configurationName, resolvedDependency.getChildren());
|
||||
}
|
||||
}
|
||||
|
||||
private static ResolvedDependency findResolvedDependency(ModuleDependency moduleDependency,
|
||||
Set<ResolvedDependency> resolvedDependencies) {
|
||||
for (ResolvedDependency resolvedDependency : resolvedDependencies) {
|
||||
ResolvedDependency dependency = findResolvedDependency(moduleDependency, resolvedDependency.getChildren());
|
||||
if (dependency != null) return dependency;
|
||||
if (isEqual(resolvedDependency.getModuleName(), moduleDependency.getName()) &&
|
||||
isEqual(resolvedDependency.getModuleGroup(), moduleDependency.getGroup()) &&
|
||||
isEqual(resolvedDependency.getModuleVersion(), moduleDependency.getVersion())) {
|
||||
return resolvedDependency;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isEqual(String str1, String str2) {
|
||||
return str1 != null ? str1.equals(str2) : str2 == null;
|
||||
}
|
||||
}
|
||||
+23
-16
@@ -13,41 +13,45 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model.impl;
|
||||
package org.jetbrains.plugins.gradle.model.internal;
|
||||
|
||||
import org.gradle.tooling.model.idea.IdeaDependencyScope;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/8/13
|
||||
*/
|
||||
public class GradleDependencyImpl implements GradleDependency {
|
||||
private final String configurationName;
|
||||
public abstract class AbstractGradleDependency implements Serializable {
|
||||
private final IdeaDependencyScope myScope;
|
||||
private final String dependencyName;
|
||||
private final String dependencyGroup;
|
||||
private final String dependencyVersion;
|
||||
|
||||
public GradleDependencyImpl(String configurationName, String dependencyName, String dependencyGroup, String dependencyVersion) {
|
||||
this.configurationName = configurationName;
|
||||
public AbstractGradleDependency(IdeaDependencyScope myScope, String dependencyName, String dependencyGroup, String dependencyVersion) {
|
||||
this.myScope = myScope;
|
||||
this.dependencyName = dependencyName;
|
||||
this.dependencyGroup = dependencyGroup;
|
||||
this.dependencyVersion = dependencyVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigurationName() {
|
||||
return configurationName;
|
||||
public IdeaDependencyScope getScope() {
|
||||
return myScope;
|
||||
}
|
||||
|
||||
public boolean getExported() {
|
||||
return "compile".equals(myScope.getScope()) || "runtime".equals(myScope.getScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDependencyName() {
|
||||
return dependencyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDependencyGroup() {
|
||||
return dependencyGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDependencyVersion() {
|
||||
return dependencyVersion;
|
||||
}
|
||||
@@ -55,20 +59,22 @@ public class GradleDependencyImpl implements GradleDependency {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!(o instanceof AbstractGradleDependency)) return false;
|
||||
|
||||
GradleDependencyImpl that = (GradleDependencyImpl)o;
|
||||
AbstractGradleDependency that = (AbstractGradleDependency)o;
|
||||
|
||||
if (dependencyGroup != null ? !dependencyGroup.equals(that.dependencyGroup) : that.dependencyGroup != null) return false;
|
||||
if (dependencyName != null ? !dependencyName.equals(that.dependencyName) : that.dependencyName != null) return false;
|
||||
if (dependencyVersion != null ? !dependencyVersion.equals(that.dependencyVersion) : that.dependencyVersion != null) return false;
|
||||
if (myScope != null ? !myScope.equals(that.myScope) : that.myScope != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = dependencyName != null ? dependencyName.hashCode() : 0;
|
||||
int result = myScope != null ? myScope.hashCode() : 0;
|
||||
result = 31 * result + (dependencyName != null ? dependencyName.hashCode() : 0);
|
||||
result = 31 * result + (dependencyGroup != null ? dependencyGroup.hashCode() : 0);
|
||||
result = 31 * result + (dependencyVersion != null ? dependencyVersion.hashCode() : 0);
|
||||
return result;
|
||||
@@ -76,11 +82,12 @@ public class GradleDependencyImpl implements GradleDependency {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GradleDependencyImpl{" +
|
||||
"configurationName='" + configurationName + '\'' +
|
||||
return "GradleDependency{" +
|
||||
"myScope=" + myScope +
|
||||
", dependencyName='" + dependencyName + '\'' +
|
||||
", dependencyGroup='" + dependencyGroup + '\'' +
|
||||
", dependencyVersion='" + dependencyVersion + '\'' +
|
||||
", exported=" + getExported() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.internal;
|
||||
|
||||
import org.gradle.plugins.ide.internal.IdeDependenciesExtractor;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public class DependencyVersionId {
|
||||
private final IdeDependenciesExtractor.IdeDependency myIdeDependency;
|
||||
private final String name;
|
||||
private final String group;
|
||||
private final String version;
|
||||
|
||||
public DependencyVersionId(IdeDependenciesExtractor.IdeDependency dependency, String name, String group, String version) {
|
||||
myIdeDependency = dependency;
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public IdeDependenciesExtractor.IdeDependency getIdeDependency() {
|
||||
return myIdeDependency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DependencyVersionId)) return false;
|
||||
|
||||
DependencyVersionId id = (DependencyVersionId)o;
|
||||
|
||||
if (group != null ? !group.equals(id.group) : id.group != null) return false;
|
||||
if (name != null ? !name.equals(id.name) : id.name != null) return false;
|
||||
if (version != null ? !version.equals(id.version) : id.version != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (group != null ? group.hashCode() : 0);
|
||||
result = 31 * result + (version != null ? version.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DependencyVersionId{" +
|
||||
"name='" + name + '\'' +
|
||||
", group='" + group + '\'' +
|
||||
", version='" + version + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.internal;
|
||||
|
||||
import org.gradle.tooling.model.idea.IdeaDependencyScope;
|
||||
import org.jetbrains.plugins.gradle.model.GradleDependencyScope;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public class IdeaDependencyScopeImpl implements IdeaDependencyScope, Serializable {
|
||||
|
||||
private final GradleDependencyScope myDependencyScope;
|
||||
|
||||
public IdeaDependencyScopeImpl(GradleDependencyScope scope) {
|
||||
myDependencyScope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope() {
|
||||
return myDependencyScope.getIdeaMappingName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof IdeaDependencyScopeImpl)) return false;
|
||||
|
||||
IdeaDependencyScopeImpl scope = (IdeaDependencyScopeImpl)o;
|
||||
|
||||
if (myDependencyScope != scope.myDependencyScope) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myDependencyScope != null ? myDependencyScope.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IdeaDependencyScope{" + myDependencyScope + '}';
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.internal;
|
||||
|
||||
import org.gradle.tooling.model.idea.IdeaDependencyScope;
|
||||
import org.gradle.tooling.model.idea.IdeaModule;
|
||||
import org.gradle.tooling.model.idea.IdeaModuleDependency;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public class IdeaModuleDependencyImpl extends AbstractGradleDependency
|
||||
implements IdeaModuleDependency, Serializable {
|
||||
private IdeaModule myIdeaModule;
|
||||
|
||||
public IdeaModuleDependencyImpl(IdeaDependencyScope myScope,
|
||||
String dependencyName,
|
||||
String dependencyGroup, String dependencyVersion) {
|
||||
super(myScope, dependencyName, dependencyGroup, dependencyVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdeaModule getDependencyModule() {
|
||||
return myIdeaModule;
|
||||
}
|
||||
|
||||
public void setIdeaModule(IdeaModule ideaModule) {
|
||||
myIdeaModule = ideaModule;
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.internal;
|
||||
|
||||
import org.gradle.tooling.model.GradleModuleVersion;
|
||||
import org.gradle.tooling.model.idea.IdeaDependencyScope;
|
||||
import org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public class IdeaSingleEntryLibraryDependencyImpl extends AbstractGradleDependency
|
||||
implements IdeaSingleEntryLibraryDependency, Serializable {
|
||||
|
||||
private File myFile;
|
||||
private File mySource;
|
||||
private File myJavadoc;
|
||||
|
||||
public IdeaSingleEntryLibraryDependencyImpl(IdeaDependencyScope myScope,
|
||||
String dependencyName,
|
||||
String dependencyGroup, String dependencyVersion) {
|
||||
super(myScope, dependencyName, dependencyGroup, dependencyVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return myFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getSource() {
|
||||
return mySource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getJavadoc() {
|
||||
return myJavadoc;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
myFile = file;
|
||||
}
|
||||
|
||||
public void setSource(File source) {
|
||||
mySource = source;
|
||||
}
|
||||
|
||||
public void setJavadoc(File javadoc) {
|
||||
myJavadoc = javadoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GradleModuleVersion getGradleModuleVersion() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model.impl;
|
||||
package org.jetbrains.plugins.gradle.model.internal;
|
||||
|
||||
import org.gradle.tooling.model.DomainObjectSet;
|
||||
import org.gradle.tooling.model.internal.ImmutableDomainObjectSet;
|
||||
+5
-4
@@ -13,8 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model.impl;
|
||||
package org.jetbrains.plugins.gradle.model.internal;
|
||||
|
||||
import org.gradle.tooling.model.idea.IdeaDependency;
|
||||
import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel;
|
||||
|
||||
import java.util.List;
|
||||
@@ -25,9 +26,9 @@ import java.util.List;
|
||||
*/
|
||||
public class ProjectDependenciesModelImpl implements ProjectDependenciesModel {
|
||||
private final String projectName;
|
||||
private final List<GradleDependency> myDependencies;
|
||||
private final List<IdeaDependency> myDependencies;
|
||||
|
||||
public ProjectDependenciesModelImpl(String projectName, List<GradleDependency> dependencies) {
|
||||
public ProjectDependenciesModelImpl(String projectName, List<IdeaDependency> dependencies) {
|
||||
this.projectName = projectName;
|
||||
myDependencies = dependencies;
|
||||
}
|
||||
@@ -38,7 +39,7 @@ public class ProjectDependenciesModelImpl implements ProjectDependenciesModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GradleDependency> getDependencies() {
|
||||
public List<IdeaDependency> getDependencies() {
|
||||
return myDependencies;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.internal;
|
||||
|
||||
import org.jetbrains.plugins.gradle.model.GradleDependencyScope;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public class Scopes {
|
||||
private boolean myForProductionCompile;
|
||||
private boolean myForProductionRuntime;
|
||||
private boolean myForTestCompile;
|
||||
private boolean myForTestRuntime;
|
||||
private boolean myIsProvided;
|
||||
|
||||
public Scopes(GradleDependencyScope scope) {
|
||||
myForProductionCompile = scope.isForProductionCompile();
|
||||
myForProductionRuntime = scope.isForProductionRuntime();
|
||||
myForTestCompile = scope.isForTestCompile();
|
||||
myForTestRuntime = scope.isForTestRuntime();
|
||||
myIsProvided = scope == GradleDependencyScope.PROVIDED_COMPILE || scope == GradleDependencyScope.PROVIDED_RUNTIME;
|
||||
}
|
||||
|
||||
public GradleDependencyScope[] getScopes() {
|
||||
if (myIsProvided) {
|
||||
if (myForProductionCompile && myForProductionRuntime && myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.PROVIDED_COMPILE};
|
||||
}
|
||||
else if (!myForProductionCompile && myForProductionRuntime && !myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.PROVIDED_RUNTIME};
|
||||
}
|
||||
else if (!myForProductionCompile && myForProductionRuntime && myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.TEST_COMPILE, GradleDependencyScope.PROVIDED_RUNTIME};
|
||||
}
|
||||
}
|
||||
|
||||
if (myForProductionCompile && myForProductionRuntime && myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.COMPILE};
|
||||
}
|
||||
else if (!myForProductionCompile && myForProductionRuntime && !myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.RUNTIME};
|
||||
}
|
||||
else if (!myForProductionCompile && !myForProductionRuntime && myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.TEST_COMPILE};
|
||||
}
|
||||
else if (!myForProductionCompile && !myForProductionRuntime && !myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.TEST_RUNTIME};
|
||||
}
|
||||
else if (!myForProductionCompile && myForProductionRuntime && myForTestCompile && myForTestRuntime) {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.TEST_COMPILE, GradleDependencyScope.RUNTIME};
|
||||
}
|
||||
else {
|
||||
return new GradleDependencyScope[]{GradleDependencyScope.COMPILE};
|
||||
}
|
||||
}
|
||||
|
||||
public void add(GradleDependencyScope scope) {
|
||||
myForProductionCompile = myForProductionCompile || scope.isForProductionCompile();
|
||||
myForProductionRuntime = myForProductionRuntime || scope.isForProductionRuntime();
|
||||
myForTestCompile = myForTestCompile || scope.isForTestCompile();
|
||||
myForTestRuntime = myForTestRuntime || scope.isForTestRuntime();
|
||||
myIsProvided = myIsProvided || scope == GradleDependencyScope.PROVIDED_COMPILE || scope == GradleDependencyScope.PROVIDED_RUNTIME;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.internal;
|
||||
|
||||
import org.gradle.tooling.model.DomainObjectSet;
|
||||
import org.gradle.tooling.model.GradleProject;
|
||||
import org.gradle.tooling.model.HierarchicalElement;
|
||||
import org.gradle.tooling.model.idea.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 11/25/13
|
||||
*/
|
||||
public class StubIdeaModule implements IdeaModule, Serializable {
|
||||
|
||||
private final String name;
|
||||
|
||||
public StubIdeaModule(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainObjectSet<? extends IdeaContentRoot> getContentRoots() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GradleProject getGradleProject() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdeaProject getParent() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainObjectSet<? extends HierarchicalElement> getChildren() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdeaProject getProject() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdeaCompilerOutput getCompilerOutput() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainObjectSet<? extends IdeaDependency> getDependencies() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.model.impl;
|
||||
package org.jetbrains.plugins.gradle.model.internal;
|
||||
|
||||
import org.jetbrains.plugins.gradle.model.WarModel;
|
||||
|
||||
+5
-25
@@ -34,7 +34,6 @@ import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.util.KeyValue;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.util.BooleanFunction;
|
||||
import com.intellij.util.PathUtil;
|
||||
@@ -53,7 +52,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot;
|
||||
import org.jetbrains.plugins.gradle.model.ModuleExtendedModel;
|
||||
import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel;
|
||||
import org.jetbrains.plugins.gradle.model.impl.GradleDependency;
|
||||
import org.jetbrains.plugins.gradle.util.GradleBundle;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
import org.jetbrains.plugins.gradle.util.GradleUtil;
|
||||
@@ -222,10 +220,11 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
|
||||
ProjectDependenciesModel dependenciesModel = resolverCtx.getExtraProject(gradleModule, ProjectDependenciesModel.class);
|
||||
|
||||
DomainObjectSet<? extends IdeaDependency> dependencies = gradleModule.getDependencies();
|
||||
if (dependencies == null) {
|
||||
return;
|
||||
}
|
||||
final List<? extends IdeaDependency> dependencies =
|
||||
dependenciesModel != null ? dependenciesModel.getDependencies() : gradleModule.getDependencies().getAll();
|
||||
|
||||
if (dependencies == null) return;
|
||||
|
||||
for (IdeaDependency dependency : dependencies) {
|
||||
if (dependency == null) {
|
||||
continue;
|
||||
@@ -243,10 +242,6 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
else if (dependency instanceof IdeaSingleEntryLibraryDependency) {
|
||||
LibraryDependencyData d = buildDependency(ideModule, (IdeaSingleEntryLibraryDependency)dependency, ideProject);
|
||||
d.setExported(dependency.getExported());
|
||||
if (dependenciesModel != null) {
|
||||
DependencyScope providedScope = parseProvidedScope(d, dependenciesModel.getDependencies());
|
||||
scope = providedScope == null ? scope : providedScope;
|
||||
}
|
||||
if (scope != null) {
|
||||
d.setScope(scope);
|
||||
}
|
||||
@@ -497,19 +492,4 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
private static boolean isIdeaTask(final String taskName) {
|
||||
return taskName.toLowerCase().contains("idea");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DependencyScope parseProvidedScope(LibraryDependencyData libraryDependencyData, List<GradleDependency> dependencies) {
|
||||
for (GradleDependency dependency : dependencies) {
|
||||
String s = dependency.getDependencyName() + '-' + dependency.getDependencyVersion();
|
||||
if (libraryDependencyData.getName().equals(s)) {
|
||||
String configurationName = dependency.getConfigurationName();
|
||||
if (StringUtil.startsWith(configurationName, "provided")) {
|
||||
return DependencyScope.PROVIDED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user