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 {
int firstColon = gav.indexOf(':');
int lastColon = gav.lastIndexOf(':');
if (firstColon == -1 || firstColon == lastColon) {
throw new IllegalArgumentException("Invalig GAV format: " + gav);
throw new IllegalArgumentException("Invalid GAV format: " + gav); //NOI18N
}
return new String[] {
gav.substring(0, firstColon),
......
......@@ -32,7 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
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.
......@@ -255,11 +255,8 @@ public final class GradleBaseProject implements Serializable, ModuleSearchSuppor
}
@Override
public Set<GradleDependency.ModuleDependency> findModules(String gav) {
String parts[] = GradleDependency.gavSplit(gav);
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid gav filter: " + gav);
}
public Set<GradleDependency.ModuleDependency> findModules(String gav) throws IllegalArgumentException {
String parts[] = GradleModuleFileCache21.gavSplit(gav);
String groupId = parts[0].isEmpty() ? null : parts[0];
String artifactId = parts[1].isEmpty() ? null : parts[1];
String ver = parts[2].isEmpty() ? null : parts[2];
......
......@@ -196,8 +196,13 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result {
conf.modules.add(dep);
} else {
dep = resolveModuleDependency(gradleUserHome, c);
if (dep != null) {
components.put(c, dep);
conf.modules.add(dep);
} else {
// NETBEANS-5161: This could happen on composite projects
// TODO: Implement composite project module dependency
}
}
}
}
......@@ -259,6 +264,7 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result {
private ModuleDependency resolveModuleDependency(File gradleUserHome, String c) {
GradleModuleFileCache21 moduleCache = GradleModuleFileCache21.getGradleFileCache(gradleUserHome.toPath());
try {
GradleModuleFileCache21.CachedArtifactVersion artVersion = moduleCache.resolveModule(c);
Set<File> binaries = artifactSore.getBinaries(c);
if (((binaries == null) || binaries.isEmpty()) && (artVersion.getBinary() != null)) {
......@@ -272,6 +278,10 @@ class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result {
ret.javadoc = Collections.singleton(artVersion.getJavaDoc().getPath().toFile());
}
return ret;
} catch (IllegalArgumentException iae) {
// NETBEANS-5161: This could happen on composite projects
return null;
}
}
private void processDependencyPlugins() {
......
......@@ -23,6 +23,7 @@ import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.netbeans.modules.gradle.GradleModuleFileCache21;
/**
* This object represents a configuration in a Gradle project.
......@@ -86,10 +87,7 @@ public final class GradleConfiguration implements Serializable, ModuleSearchSupp
@Override
public Set<GradleDependency.ModuleDependency> findModules(String gav) {
String parts[] = GradleDependency.gavSplit(gav);
if (parts.length != 3) {
throw new IllegalArgumentException("Invalid gav filter: " + gav);
}
String parts[] = GradleModuleFileCache21.gavSplit(gav);
String group = parts[0].isEmpty() ? null : parts[0];
String artifact = parts[1].isEmpty() ? null : parts[1];
String version = parts[2].isEmpty() ? null : parts[2];
......
......@@ -24,6 +24,7 @@ import java.io.Serializable;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import org.netbeans.modules.gradle.GradleModuleFileCache21;
/**
* This object represents a Gradle dependency element in a {@link GradleConfiguration}.
......@@ -63,19 +64,6 @@ public abstract class GradleDependency implements Serializable, Comparable<Gradl
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.
* @since 1.0
......@@ -92,7 +80,7 @@ public abstract class GradleDependency implements Serializable, Comparable<Gradl
ModuleDependency(String id, Set<File> artifacts) {
super(id);
this.artifacts = artifacts;
String[] parts = gavSplit(id);
String[] parts = GradleModuleFileCache21.gavSplit(id);
group = parts[0];
name = parts[1];
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