repository libraries: add option to exclude transitive dependencies (IDEA-178557)

This commit is contained in:
nik
2017-09-07 12:28:59 +02:00
parent 75e52e4513
commit 1db28ad354
22 changed files with 201 additions and 54 deletions
@@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -30,5 +31,6 @@
<orderEntry type="library" exported="" name="commons-codec" level="project" />
<orderEntry type="library" exported="" name="commons-logging" level="project" />
<orderEntry type="library" exported="" name="Slf4j" level="project" />
<orderEntry type="module" module-name="testFramework" scope="TEST" />
</component>
</module>
@@ -124,35 +124,39 @@ public class ArtifactRepositoryManager {
myRemoteRepositories.add(createRemoteRepository(id, url));
}
public Collection<File> resolveDependency(String groupId, String artifactId, String version) throws Exception {
public Collection<File> resolveDependency(String groupId, String artifactId, String version, boolean includeTransitiveDependencies) throws Exception {
final List<File> files = new ArrayList<>();
for (Artifact artifact : resolveDependencyAsArtifact(groupId, artifactId, version, EnumSet.of(ArtifactKind.ARTIFACT))) {
for (Artifact artifact : resolveDependencyAsArtifact(groupId, artifactId, version, EnumSet.of(ArtifactKind.ARTIFACT), includeTransitiveDependencies)) {
files.add(artifact.getFile());
}
return files;
}
@NotNull
public Collection<Artifact> resolveDependencyAsArtifact(String groupId,
String artifactId,
String versionConstraint,
final Set<ArtifactKind> artifactKinds) throws Exception {
final List<Artifact> artifacts = new ArrayList<>();
public Collection<Artifact> resolveDependencyAsArtifact(String groupId, String artifactId, String versionConstraint, Set<ArtifactKind> artifactKinds, boolean includeTransitiveDependencies) throws Exception {final List<Artifact> artifacts = new ArrayList<>();
final Set<VersionConstraint> constraints = Collections.singleton(asVersionConstraint(versionConstraint));
for (ArtifactKind kind : artifactKinds) {
//RepositorySystem.resolveDependencies() ignores classifiers, so we need to collect dependencies for the default classifier, and then
// resolve artifacts with specified classifiers for each found dependency
try {
final CollectResult collectResult = ourSystem.collectDependencies(
mySession, createCollectRequest(groupId, artifactId, constraints, EnumSet.of(kind))
);
final ArtifactRequestBuilder builder = new ArtifactRequestBuilder(kind);
collectResult.getRoot().accept(new TreeDependencyVisitor(
new FilteringDependencyVisitor(builder, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE))
));
final List<ArtifactRequest> requests = builder.getRequests();
final List<ArtifactRequest> requests;
if (includeTransitiveDependencies) {
final CollectResult collectResult = ourSystem.collectDependencies(
mySession, createCollectRequest(groupId, artifactId, constraints, EnumSet.of(kind))
);
final ArtifactRequestBuilder builder = new ArtifactRequestBuilder(kind);
collectResult.getRoot().accept(new TreeDependencyVisitor(
new FilteringDependencyVisitor(builder, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE))
));
requests = builder.getRequests();
}
else {
requests = new ArrayList<>();
for (Artifact artifact : toArtifacts(groupId, artifactId, constraints, artifactKinds)) {
requests.add(new ArtifactRequest(artifact, Collections.unmodifiableList(myRemoteRepositories), null));
}
}
if (!requests.isEmpty()) {
try {
for (ArtifactResult result : ourSystem.resolveArtifacts(mySession, requests)) {
@@ -276,8 +280,8 @@ public class ArtifactRepositoryManager {
final Dependency dep = node.getDependency();
if (dep != null) {
myRequests.add(new ArtifactRequest(
new ArtifactWithChangedClassifier(node.getDependency().getArtifact(), myKind.getClassifier()),
node.getRepositories(),
new ArtifactWithChangedClassifier(node.getDependency().getArtifact(), myKind.getClassifier()),
node.getRepositories(),
node.getRequestContext()
));
}
@@ -0,0 +1,47 @@
/*
* Copyright 2000-2017 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.idea.maven.aether;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
import java.io.File;
import java.util.Collection;
/**
* @author nik
*/
public class ArtifactRepositoryManagerTest extends UsefulTestCase {
private ArtifactRepositoryManager myRepositoryManager;
@Override
public void setUp() throws Exception {
super.setUp();
final File localRepo = new File(SystemProperties.getUserHome(), ".m2/repository");
myRepositoryManager = new ArtifactRepositoryManager(localRepo);
}
public void testResolveTransitively() throws Exception {
Collection<File> files = myRepositoryManager.resolveDependency("junit", "junit", "4.12", true);
assertSameElements(ContainerUtil.map(files, File::getName), "junit-4.12.jar", "hamcrest-core-1.3.jar");
}
public void testResolveNonTransitively() throws Exception {
Collection<File> files = myRepositoryManager.resolveDependency("junit", "junit", "4.12", false);
assertSameElements(ContainerUtil.map(files, File::getName), "junit-4.12.jar");
}
}
@@ -98,10 +98,11 @@ public class JarRepositoryManager {
final String coord = dialog.getCoordinateText();
final boolean attachSources = dialog.getAttachSources();
final boolean attachJavaDoc = dialog.getAttachJavaDoc();
boolean includeTransitiveDependencies = dialog.getIncludeTransitiveDependencies();
final String copyTo = dialog.getDirectoryPath();
final NewLibraryConfiguration config = resolveAndDownload(
project, coord, attachSources, attachJavaDoc, copyTo, RemoteRepositoriesConfiguration.getInstance(project).getRepositories()
project, coord, attachSources, attachJavaDoc, includeTransitiveDependencies, copyTo, RemoteRepositoriesConfiguration.getInstance(project).getRepositories()
);
if (config == null) {
Messages.showErrorDialog(parentComponent, "No files were downloaded for " + coord, CommonBundle.getErrorTitle());
@@ -114,9 +115,10 @@ public class JarRepositoryManager {
String coord,
boolean attachSources,
boolean attachJavaDoc,
boolean includeTransitiveDependencies,
String copyTo,
Collection<RemoteRepositoryDescription> repositories) {
RepositoryLibraryProperties props = new RepositoryLibraryProperties(coord);
RepositoryLibraryProperties props = new RepositoryLibraryProperties(coord, includeTransitiveDependencies);
final Collection<OrderRoot> roots = loadDependenciesModal(
project, props, attachSources, attachJavaDoc, copyTo, repositories
);
@@ -188,7 +190,7 @@ public class JarRepositoryManager {
boolean loadJavadoc,
@Nullable String copyTo,
@Nullable Collection<RemoteRepositoryDescription> repositories, boolean modal) {
final JpsMavenRepositoryLibraryDescriptor libDescriptor = new JpsMavenRepositoryLibraryDescriptor(libraryProps.getGroupId(), libraryProps.getArtifactId(), libraryProps.getVersion());
final JpsMavenRepositoryLibraryDescriptor libDescriptor = libraryProps.getRepositoryLibraryDescriptor();
if (libDescriptor.getMavenId() != null) {
if (repositories == null || repositories.isEmpty()) {
repositories = RemoteRepositoriesConfiguration.getInstance(project).getRepositories();
@@ -235,7 +237,7 @@ public class JarRepositoryManager {
}
loadDependenciesAsync(
project,
new JpsMavenRepositoryLibraryDescriptor(libraryProps.getGroupId(), libraryProps.getArtifactId(), libraryProps.getVersion()),
libraryProps.getRepositoryLibraryDescriptor(),
kinds, repos, copyTo, resultProcessor
);
}
@@ -292,7 +294,7 @@ public class JarRepositoryManager {
template = new RepositoryArtifactDescription(null, null, null, "jar", null, coord, null);
}
else {
template = new RepositoryArtifactDescription(new RepositoryLibraryProperties(coord), "jar", null);
template = new RepositoryArtifactDescription(new RepositoryLibraryProperties(coord, true), "jar", null);
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {
@@ -539,7 +541,8 @@ public class JarRepositoryManager {
protected Collection<Artifact> perform(ProgressIndicator progress, ArtifactRepositoryManager manager) throws Exception {
final String version = myDesc.getVersion();
try {
return manager.resolveDependencyAsArtifact(myDesc.getGroupId(), myDesc.getArtifactId(), version, myKinds);
return manager.resolveDependencyAsArtifact(myDesc.getGroupId(), myDesc.getArtifactId(), version, myKinds,
myDesc.isIncludeTransitiveDependencies());
}
catch (TransferCancelledException e) {
throw new ProcessCanceledException(e);
@@ -553,7 +556,8 @@ public class JarRepositoryManager {
throw e;
}
try {
return manager.resolveDependencyAsArtifact(myDesc.getGroupId(), myDesc.getArtifactId(), resolvedVersion, myKinds);
return manager.resolveDependencyAsArtifact(myDesc.getGroupId(), myDesc.getArtifactId(), resolvedVersion, myKinds,
myDesc.isIncludeTransitiveDependencies());
}
catch (TransferCancelledException e1) {
throw new ProcessCanceledException(e1);
@@ -70,7 +70,7 @@ public class RepositoryAddLibraryAction extends IntentionAndQuickFixAction {
module.getProject(),
model,
libraryDescription,
false);
false, true);
if (!dialog.showAndGet()) {
return;
}
@@ -71,7 +71,7 @@
<text value=""/>
</properties>
</component>
<grid id="8a0e6" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="8a0e6" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -81,7 +81,7 @@
<children>
<component id="e800f" class="javax.swing.JCheckBox" binding="mySourcesCheckBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Sources"/>
@@ -89,7 +89,7 @@
</component>
<component id="63ac5" class="javax.swing.JCheckBox" binding="myJavaDocCheckBox">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Java&amp;Docs"/>
@@ -100,6 +100,15 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="dcc0d" class="com.intellij.ui.components.JBCheckBox" binding="myIncludeTransitiveDepsCheckBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="&amp;Transitive depedencies"/>
</properties>
</component>
</children>
</grid>
<component id="65473" class="com.intellij.ui.components.JBCheckBox" binding="myDownloadToCheckBox">
@@ -90,6 +90,7 @@ public class RepositoryAttachDialog extends DialogWrapper {
private JBCheckBox myDownloadToCheckBox;
private JBLabel myCaptionLabel;
private JPanel myDownloadOptionsPanel;
private JBCheckBox myIncludeTransitiveDepsCheckBox;
private final JComboBox myCombobox;
@@ -217,6 +218,10 @@ public class RepositoryAttachDialog extends DialogWrapper {
return mySourcesCheckBox.isSelected();
}
public boolean getIncludeTransitiveDependencies() {
return myIncludeTransitiveDepsCheckBox.isSelected();
}
@Nullable
public String getDirectoryPath() {
return myDownloadToCheckBox.isSelected()? myDirectoryField.getText() : null;
@@ -38,7 +38,7 @@ public class RepositoryLibrarySupportInModuleConfigurable extends FrameworkSuppo
public RepositoryLibrarySupportInModuleConfigurable(@Nullable Project project, @NotNull RepositoryLibraryDescription libraryDescription) {
this.libraryDescription = libraryDescription;
RepositoryLibraryProperties defaultProperties = libraryDescription.createDefaultProperties();
this.model = new RepositoryLibraryPropertiesModel(defaultProperties.getVersion(), false, false);
this.model = new RepositoryLibraryPropertiesModel(defaultProperties.getVersion(), false, false, defaultProperties.isIncludeTransitiveDependencies());
editor = new RepositoryLibraryPropertiesEditor(project, model, libraryDescription);
}
@@ -50,7 +50,7 @@ public class RepositoryLibraryWithDescriptionEditor
RepositoryLibraryPropertiesModel model = new RepositoryLibraryPropertiesModel(
properties.getVersion(),
RepositoryUtils.libraryHasSources(myEditorComponent.getLibraryEditor()),
RepositoryUtils.libraryHasJavaDocs(myEditorComponent.getLibraryEditor()));
RepositoryUtils.libraryHasJavaDocs(myEditorComponent.getLibraryEditor()), properties.isIncludeTransitiveDependencies());
final Project project = myEditorComponent.getProject();
assert project != null : "EditorComponent's project must not be null in order to be used with RepositoryLibraryWithDescriptionEditor";
@@ -59,11 +59,12 @@ public class RepositoryLibraryWithDescriptionEditor
project,
model,
RepositoryLibraryDescription.findDescription(properties),
true);
true, true);
if (!dialog.showAndGet()) {
return;
}
myEditorComponent.getProperties().changeVersion(model.getVersion());
myEditorComponent.getProperties().setIncludeTransitiveDependencies(model.isIncludeTransitiveDependencies());
if (wasGeneratedName) {
myEditorComponent.renameLibrary(RepositoryLibraryType.getInstance().getDescription(properties));
}
@@ -30,11 +30,11 @@ public class RepositoryLibraryPropertiesDialog extends DialogWrapper {
public RepositoryLibraryPropertiesDialog(@Nullable Project project,
RepositoryLibraryPropertiesModel model,
RepositoryLibraryDescription description,
final boolean changesRequired) {
final boolean changesRequired, final boolean allowExcludingTransitiveDependencies) {
super(project);
this.model = model;
propertiesEditor =
new RepositoryLibraryPropertiesEditor(project, model, description, new RepositoryLibraryPropertiesEditor.ModelChangeListener() {
new RepositoryLibraryPropertiesEditor(project, model, description, allowExcludingTransitiveDependencies, new RepositoryLibraryPropertiesEditor.ModelChangeListener() {
@Override
public void onChange(RepositoryLibraryPropertiesEditor editor) {
setOKActionEnabled(editor.isValid() && (!changesRequired || editor.hasChanges()));
@@ -120,7 +120,7 @@
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="1bd32" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="1bd32" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -151,6 +151,14 @@
<text value="Download &amp;JavaDocs"/>
</properties>
</component>
<component id="75440" class="com.intellij.ui.components.JBCheckBox" binding="myIncludeTransitiveDepsCheckBox">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Include &amp;transitive dependencies"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -61,6 +61,7 @@ public class RepositoryLibraryPropertiesEditor {
private JBCheckBox downloadSourcesCheckBox;
private JBCheckBox downloadJavaDocsCheckBox;
private JBLabel mavenCoordinates;
private JBCheckBox myIncludeTransitiveDepsCheckBox;
@NotNull private ModelChangeListener onChangeListener;
@@ -71,7 +72,7 @@ public class RepositoryLibraryPropertiesEditor {
public RepositoryLibraryPropertiesEditor(@Nullable Project project,
RepositoryLibraryPropertiesModel model,
RepositoryLibraryDescription description) {
this(project, model, description, new ModelChangeListener() {
this(project, model, description, true, new ModelChangeListener() {
@Override
public void onChange(RepositoryLibraryPropertiesEditor editor) {
@@ -83,12 +84,14 @@ public class RepositoryLibraryPropertiesEditor {
public RepositoryLibraryPropertiesEditor(@Nullable Project project,
final RepositoryLibraryPropertiesModel model,
RepositoryLibraryDescription description,
boolean allowExcludingTransitiveDependencies,
@NotNull final ModelChangeListener onChangeListener) {
this.initialModel = model.clone();
this.model = model;
this.project = project == null ? ProjectManager.getInstance().getDefaultProject() : project;
repositoryLibraryDescription = description;
mavenCoordinates.setCopyable(true);
myIncludeTransitiveDepsCheckBox.setVisible(allowExcludingTransitiveDependencies);
myReloadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -243,6 +246,14 @@ public class RepositoryLibraryPropertiesEditor {
onChangeListener.onChange(RepositoryLibraryPropertiesEditor.this);
}
});
myIncludeTransitiveDepsCheckBox.setSelected(model.isIncludeTransitiveDependencies());
myIncludeTransitiveDepsCheckBox.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
model.setIncludeTransitiveDependencies(myIncludeTransitiveDepsCheckBox.isSelected());
onChangeListener.onChange(RepositoryLibraryPropertiesEditor.this);
}
});
}
@@ -73,7 +73,8 @@ public class RepositoryLibrarySupport {
RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(
libraryDescription.getGroupId(),
libraryDescription.getArtifactId(),
model.getVersion());
model.getVersion(),
model.isIncludeTransitiveDependencies());
final LibraryEx library = (LibraryEx)modifiableModel.createLibrary(
LibraryEditingUtil.suggestNewLibraryName(modifiableModel, RepositoryLibraryType.getInstance().getDescription(libraryProperties)),
RepositoryLibraryType.REPOSITORY_LIBRARY_KIND);
@@ -21,21 +21,36 @@ public class RepositoryLibraryPropertiesModel {
private String version;
private boolean downloadSources;
private boolean downloadJavaDocs;
private boolean includeTransitiveDependencies;
public RepositoryLibraryPropertiesModel(String version, boolean downloadSources, boolean downloadJavaDocs) {
this(version, downloadSources, downloadJavaDocs, true);
}
public RepositoryLibraryPropertiesModel(String version, boolean downloadSources, boolean downloadJavaDocs,
boolean includeTransitiveDependencies) {
this.version = version;
this.downloadSources = downloadSources;
this.downloadJavaDocs = downloadJavaDocs;
this.includeTransitiveDependencies = includeTransitiveDependencies;
}
public RepositoryLibraryPropertiesModel clone() {
return new RepositoryLibraryPropertiesModel(version, downloadSources, downloadJavaDocs);
return new RepositoryLibraryPropertiesModel(version, downloadSources, downloadJavaDocs, includeTransitiveDependencies);
}
public boolean isValid() {
return !Strings.isNullOrEmpty(version);
}
public boolean isIncludeTransitiveDependencies() {
return includeTransitiveDependencies;
}
public void setIncludeTransitiveDependencies(boolean includeTransitiveDependencies) {
this.includeTransitiveDependencies = includeTransitiveDependencies;
}
public boolean isDownloadSources() {
return downloadSources;
}
@@ -69,6 +84,7 @@ public class RepositoryLibraryPropertiesModel {
if (downloadSources != model.downloadSources) return false;
if (downloadJavaDocs != model.downloadJavaDocs) return false;
if (includeTransitiveDependencies != model.includeTransitiveDependencies) return false;
if (version != null ? !version.equals(model.version) : model.version != null) return false;
return true;
@@ -78,6 +94,7 @@ public class RepositoryLibraryPropertiesModel {
public int hashCode() {
int result = (downloadSources ? 1 : 0);
result = 31 * result + (downloadJavaDocs ? 1 : 0);
result = 31 * result + (includeTransitiveDependencies ? 1 : 0);
result = 31 * result + (version != null ? version.hashCode() : 0);
return result;
}
@@ -112,7 +112,7 @@ public class RepositoryLibraryDescription {
}
public RepositoryLibraryProperties createDefaultProperties() {
return new RepositoryLibraryProperties(getGroupId(), getArtifactId(), ReleaseVersionId);
return new RepositoryLibraryProperties(getGroupId(), getArtifactId(), ReleaseVersionId, true);
}
public String getDisplayName(String version) {
@@ -32,11 +32,15 @@ public class RepositoryLibraryProperties extends LibraryProperties<RepositoryLib
public RepositoryLibraryProperties() {
}
public RepositoryLibraryProperties(String mavenId) {
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(mavenId);
public RepositoryLibraryProperties(String mavenId, final boolean includeTransitiveDependencies) {
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(mavenId, includeTransitiveDependencies);
}
public RepositoryLibraryProperties(@NotNull String groupId, @NotNull String artifactId, @NotNull String version) {
this(groupId, artifactId, version, true);
}
public RepositoryLibraryProperties(@NotNull String groupId, @NotNull String artifactId, @NotNull String version, boolean includeTransitiveDependencies) {
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(groupId, artifactId, version);
}
@@ -66,7 +70,16 @@ public class RepositoryLibraryProperties extends LibraryProperties<RepositoryLib
}
public void setMavenId(String mavenId) {
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(mavenId);
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(mavenId, isIncludeTransitiveDependencies());
}
@Attribute("include-transitive-deps")
public boolean isIncludeTransitiveDependencies() {
return myDescriptor == null || myDescriptor.isIncludeTransitiveDependencies();
}
public void setIncludeTransitiveDependencies(boolean value) {
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(getMavenId(), value);
}
public String getGroupId() {
@@ -82,11 +95,16 @@ public class RepositoryLibraryProperties extends LibraryProperties<RepositoryLib
}
public void changeVersion(String version) {
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(getGroupId(), getArtifactId(), version);
myDescriptor = new JpsMavenRepositoryLibraryDescriptor(getGroupId(), getArtifactId(), version, myDescriptor.isIncludeTransitiveDependencies());
}
private String call(Function<JpsMavenRepositoryLibraryDescriptor, String> method) {
final JpsMavenRepositoryLibraryDescriptor descriptor = myDescriptor;
return descriptor != null ? method.apply(descriptor) : null;
}
@NotNull
public JpsMavenRepositoryLibraryDescriptor getRepositoryLibraryDescriptor() {
return myDescriptor != null ? myDescriptor : new JpsMavenRepositoryLibraryDescriptor(null, true);
}
}
@@ -147,7 +147,8 @@ public class DependencyResolvingBuilder extends ModuleLevelBuilder{
if (!required.isEmpty()) {
context.processMessage(new ProgressMessage("Resolving '" + lib.getName() + "' library..."));
LOG.debug("Downloading missing files for " + lib.getName() + " library: " + required);
final Collection<File> resolved = repoManager.resolveDependency(descriptor.getGroupId(), descriptor.getArtifactId(), descriptor.getVersion());
final Collection<File> resolved = repoManager.resolveDependency(descriptor.getGroupId(), descriptor.getArtifactId(),
descriptor.getVersion(), descriptor.isIncludeTransitiveDependencies());
if (!resolved.isEmpty()) {
syncPaths(required, resolved);
}
@@ -18,6 +18,8 @@ package org.jetbrains.jps.model.library;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
/**
* @author Eugene Zhuravlev
* Date: 13-Jun-16
@@ -27,16 +29,28 @@ public class JpsMavenRepositoryLibraryDescriptor {
private final String myGroupId;
private final String myArtifactId;
private final String myVersion;
private final boolean myIncludeTransitiveDependencies;
public JpsMavenRepositoryLibraryDescriptor(@NotNull String groupId, @NotNull String artifactId, @NotNull String version) {
this(groupId, artifactId, version, true);
}
public JpsMavenRepositoryLibraryDescriptor(@NotNull String groupId, @NotNull String artifactId, @NotNull String version,
boolean includeTransitiveDependencies) {
myGroupId = groupId;
myArtifactId = artifactId;
myVersion = version;
myIncludeTransitiveDependencies = includeTransitiveDependencies;
myMavenId = groupId + ":" + artifactId + ":" + version;
}
public JpsMavenRepositoryLibraryDescriptor(@Nullable String mavenId) {
this(mavenId, true);
}
public JpsMavenRepositoryLibraryDescriptor(@Nullable String mavenId, boolean includeTransitiveDependencies) {
myMavenId = mavenId;
myIncludeTransitiveDependencies = includeTransitiveDependencies;
if (mavenId == null) {
myGroupId = myArtifactId = myVersion = null;
}
@@ -61,6 +75,10 @@ public class JpsMavenRepositoryLibraryDescriptor {
return myArtifactId;
}
public boolean isIncludeTransitiveDependencies() {
return myIncludeTransitiveDependencies;
}
public String getVersion() {
return myVersion;
}
@@ -71,15 +89,12 @@ public class JpsMavenRepositoryLibraryDescriptor {
if (o == null || getClass() != o.getClass()) return false;
JpsMavenRepositoryLibraryDescriptor that = (JpsMavenRepositoryLibraryDescriptor)o;
if (myMavenId != null ? !myMavenId.equals(that.myMavenId) : that.myMavenId != null) return false;
return true;
return Objects.equals(myMavenId, that.myMavenId) && myIncludeTransitiveDependencies == that.myIncludeTransitiveDependencies;
}
@Override
public int hashCode() {
return myMavenId != null ? myMavenId.hashCode() : 0;
return Objects.hashCode(myMavenId) * 31 + (myIncludeTransitiveDependencies ? 1 : 0);
}
@Override
@@ -386,6 +386,7 @@ public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension
private static class JpsRepositoryLibraryPropertiesSerializer extends JpsLibraryPropertiesSerializer<JpsSimpleElement<JpsMavenRepositoryLibraryDescriptor>> {
private static final String MAVEN_ID_ATTRIBUTE = "maven-id";
private static final String INCLUDE_TRANSITIVE_DEPS_ATTRIBUTE = "include-transitive-deps";
public JpsRepositoryLibraryPropertiesSerializer() {
super(JpsRepositoryLibraryType.INSTANCE, JpsRepositoryLibraryType.INSTANCE.getTypeId());
@@ -394,7 +395,8 @@ public class JpsJavaModelSerializerExtension extends JpsModelSerializerExtension
@Override
public JpsSimpleElement<JpsMavenRepositoryLibraryDescriptor> loadProperties(@Nullable Element elem) {
return JpsElementFactory.getInstance().createSimpleElement(new JpsMavenRepositoryLibraryDescriptor(
elem != null? elem.getAttributeValue(MAVEN_ID_ATTRIBUTE, (String)null) : null
elem != null ? elem.getAttributeValue(MAVEN_ID_ATTRIBUTE, (String)null) : null,
elem == null || Boolean.parseBoolean(elem.getAttributeValue(INCLUDE_TRANSITIVE_DEPS_ATTRIBUTE, "true"))
));
}
@@ -50,6 +50,7 @@ org.jetbrains.idea.maven.embedder.*
org.jetbrains.idea.maven.execution.*
org.jetbrains.idea.maven.intentions.*
org.jetbrains.idea.maven.navigator.*
org.jetbrains.idea.maven.aether.*
[TASKS_INTEGRATION_TESTS]
com.intellij.tasks.integration.*
@@ -128,7 +128,8 @@ public abstract class JUnitAbstractIntegrationTest extends BaseConfigurationTest
JpsMavenRepositoryLibraryDescriptor descriptor,
ArtifactRepositoryManager repoManager) throws Exception {
Collection<File> files = repoManager.resolveDependency(descriptor.getGroupId(), descriptor.getArtifactId(), descriptor.getVersion());
Collection<File> files = repoManager.resolveDependency(descriptor.getGroupId(), descriptor.getArtifactId(), descriptor.getVersion(),
descriptor.isIncludeTransitiveDependencies());
for (File artifact : files) {
VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByIoFile(artifact);
assertNotNull(libJarLocal);
@@ -59,7 +59,7 @@ public class RepositoryAttachHandler {
List<MavenRepositoryInfo> repositories) {
final ArrayList<RemoteRepositoryDescription> repos =
repositories.stream().map(info -> toRemoteRepositoryDescription(info)).collect(Collectors.toCollection(ArrayList::new));
return JarRepositoryManager.resolveAndDownload(project, coord, attachSources, attachJavaDoc, copyTo, repos);
return JarRepositoryManager.resolveAndDownload(project, coord, attachSources, attachJavaDoc, true, copyTo, repos);
}
@NotNull
@@ -73,7 +73,7 @@ public class RepositoryAttachHandler {
final ArrayList<RemoteRepositoryDescription> repos =
repositories.stream().map(info -> toRemoteRepositoryDescription(info)).collect(Collectors.toCollection(ArrayList::new));
return new ArrayList<>(JarRepositoryManager.loadDependencies(
project, new RepositoryLibraryProperties(coord), attachSources, attachJavaDoc, copyTo, repos
project, new RepositoryLibraryProperties(coord, true), attachSources, attachJavaDoc, copyTo, repos
));
}