Commit 38f7417d authored by Laszlo Kishalmi's avatar Laszlo Kishalmi
Browse files

[NETBEANS-5161] Prevent IAE when resolving composite project dependencies

parent 77a06476
...@@ -247,7 +247,7 @@ public final class GradleModuleFileCache21 { ...@@ -247,7 +247,7 @@ public final class GradleModuleFileCache21 {
int firstColon = gav.indexOf(':'); int firstColon = gav.indexOf(':');
int lastColon = gav.lastIndexOf(':'); int lastColon = gav.lastIndexOf(':');
if (firstColon == -1 || firstColon == lastColon) { if (firstColon == -1 || firstColon == lastColon) {
throw new IllegalArgumentException("Invalig GAV format: " + gav); throw new IllegalArgumentException("Invalid GAV format: " + gav); //NOI18N
} }
return new String[] { return new String[] {
gav.substring(0, firstColon), gav.substring(0, firstColon),
......
...@@ -32,7 +32,7 @@ import java.util.List; ...@@ -32,7 +32,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.netbeans.api.project.Project; import org.netbeans.api.project.Project;
import org.openide.filesystems.FileUtil; import org.netbeans.modules.gradle.GradleModuleFileCache21;
/** /**
* This object holds the basic information of the Gradle project. * This object holds the basic information of the Gradle project.
...@@ -255,11 +255,8 @@ public final class GradleBaseProject implements Serializable, ModuleSearchSuppor ...@@ -255,11 +255,8 @@ public final class GradleBaseProject implements Serializable, ModuleSearchSuppor
} }
@Override @Override
public Set<GradleDependency.ModuleDependency> findModules(String gav) { public Set<GradleDependency.ModuleDependency> findModules(String gav) throws IllegalArgumentException {
String parts[] = GradleDependency.gavSplit(gav); String parts[] = GradleModuleFileCache21.gavSplit(gav);
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid gav filter: " + gav);
}
String groupId = parts[0].isEmpty() ? null : parts[0]; String groupId = parts[0].isEmpty() ? null : parts[0];
String artifactId = parts[1].isEmpty() ? null : parts[1]; String artifactId = parts[1].isEmpty() ? null : parts[1];
String ver = parts[2].isEmpty() ? null : parts[2]; String ver = parts[2].isEmpty() ? null : parts[2];
......
...@@ -196,8 +196,13 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result { ...@@ -196,8 +196,13 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result {
conf.modules.add(dep); conf.modules.add(dep);
} else { } else {
dep = resolveModuleDependency(gradleUserHome, c); dep = resolveModuleDependency(gradleUserHome, c);
components.put(c, dep); if (dep != null) {
conf.modules.add(dep); components.put(c, dep);
conf.modules.add(dep);
} else {
// NETBEANS-5161: This could happen on composite projects
// TODO: Implement composite project module dependency
}
} }
} }
} }
...@@ -259,19 +264,24 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result { ...@@ -259,19 +264,24 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result {
private ModuleDependency resolveModuleDependency(File gradleUserHome, String c) { private ModuleDependency resolveModuleDependency(File gradleUserHome, String c) {
GradleModuleFileCache21 moduleCache = GradleModuleFileCache21.getGradleFileCache(gradleUserHome.toPath()); GradleModuleFileCache21 moduleCache = GradleModuleFileCache21.getGradleFileCache(gradleUserHome.toPath());
GradleModuleFileCache21.CachedArtifactVersion artVersion = moduleCache.resolveModule(c); try {
Set<File> binaries = artifactSore.getBinaries(c); GradleModuleFileCache21.CachedArtifactVersion artVersion = moduleCache.resolveModule(c);
if (((binaries == null) || binaries.isEmpty()) && (artVersion.getBinary() != null)) { Set<File> binaries = artifactSore.getBinaries(c);
binaries = Collections.singleton(artVersion.getBinary().getPath().toFile()); if (((binaries == null) || binaries.isEmpty()) && (artVersion.getBinary() != null)) {
} binaries = Collections.singleton(artVersion.getBinary().getPath().toFile());
ModuleDependency ret = new ModuleDependency(c, binaries); }
if (artVersion.getSources() != null) { ModuleDependency ret = new ModuleDependency(c, binaries);
ret.sources = Collections.singleton(artVersion.getSources().getPath().toFile()); if (artVersion.getSources() != null) {
} ret.sources = Collections.singleton(artVersion.getSources().getPath().toFile());
if (artVersion.getJavaDoc() != null) { }
ret.javadoc = Collections.singleton(artVersion.getJavaDoc().getPath().toFile()); if (artVersion.getJavaDoc() != null) {
ret.javadoc = Collections.singleton(artVersion.getJavaDoc().getPath().toFile());
}
return ret;
} catch (IllegalArgumentException iae) {
// NETBEANS-5161: This could happen on composite projects
return null;
} }
return ret;
} }
private void processDependencyPlugins() { private void processDependencyPlugins() {
......
...@@ -23,6 +23,7 @@ import java.io.Serializable; ...@@ -23,6 +23,7 @@ import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.netbeans.modules.gradle.GradleModuleFileCache21;
/** /**
* This object represents a configuration in a Gradle project. * This object represents a configuration in a Gradle project.
...@@ -86,10 +87,7 @@ public final class GradleConfiguration implements Serializable, ModuleSearchSupp ...@@ -86,10 +87,7 @@ public final class GradleConfiguration implements Serializable, ModuleSearchSupp
@Override @Override
public Set<GradleDependency.ModuleDependency> findModules(String gav) { public Set<GradleDependency.ModuleDependency> findModules(String gav) {
String parts[] = GradleDependency.gavSplit(gav); String parts[] = GradleModuleFileCache21.gavSplit(gav);
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid gav filter: " + gav);
}
String group = parts[0].isEmpty() ? null : parts[0]; String group = parts[0].isEmpty() ? null : parts[0];
String artifact = parts[1].isEmpty() ? null : parts[1]; String artifact = parts[1].isEmpty() ? null : parts[1];
String version = parts[2].isEmpty() ? null : parts[2]; String version = parts[2].isEmpty() ? null : parts[2];
......
...@@ -24,6 +24,7 @@ import java.io.Serializable; ...@@ -24,6 +24,7 @@ import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.netbeans.modules.gradle.GradleModuleFileCache21;
/** /**
* This object represents a Gradle dependency element in a {@link GradleConfiguration}. * This object represents a Gradle dependency element in a {@link GradleConfiguration}.
...@@ -63,19 +64,6 @@ public abstract class GradleDependency implements Serializable, Comparable<Gradl ...@@ -63,19 +64,6 @@ public abstract class GradleDependency implements Serializable, Comparable<Gradl
public abstract Type getType(); public abstract Type getType();
static final String[] gavSplit(String gav) {
int firstColon = gav.indexOf(':');
int lastColon = gav.lastIndexOf(':');
if (firstColon == -1 || firstColon == lastColon) {
throw new IllegalArgumentException("Invalig GAV format: " + gav);
}
return new String[] {
gav.substring(0, firstColon),
gav.substring(firstColon + 1, lastColon),
gav.substring(lastColon + 1)
};
}
/** /**
* Dependency for modules usually downloaded from a remote repository. * Dependency for modules usually downloaded from a remote repository.
* @since 1.0 * @since 1.0
...@@ -92,7 +80,7 @@ public abstract class GradleDependency implements Serializable, Comparable<Gradl ...@@ -92,7 +80,7 @@ public abstract class GradleDependency implements Serializable, Comparable<Gradl
ModuleDependency(String id, Set<File> artifacts) { ModuleDependency(String id, Set<File> artifacts) {
super(id); super(id);
this.artifacts = artifacts; this.artifacts = artifacts;
String[] parts = gavSplit(id); String[] parts = GradleModuleFileCache21.gavSplit(id);
group = parts[0]; group = parts[0];
name = parts[1]; name = parts[1];
version = parts[2]; version = parts[2];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment