use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class AppEngineFacetImporter method resolve.
@Override
public void resolve(Project project, MavenProject mavenProject, NativeMavenProjectHolder nativeMavenProject, MavenEmbedderWrapper embedder, ResolveContext context) throws MavenProcessCanceledException {
String version = getVersion(mavenProject);
if (version != null) {
List<MavenRemoteRepository> repos = mavenProject.getRemoteRepositories();
MavenArtifactInfo artifactInfo = new MavenArtifactInfo("com.google.appengine", "appengine-java-sdk", version, "zip", null);
MavenArtifact artifact = embedder.resolve(artifactInfo, repos);
File file = artifact.getFile();
File unpackedSdkPath = new File(file.getParentFile(), "appengine-java-sdk");
if (file.exists() && !AppEngineSdkUtil.checkPath(FileUtil.toSystemIndependentName(unpackedSdkPath.getAbsolutePath())).isOk()) {
try {
ZipUtil.extract(file, unpackedSdkPath, null, false);
} catch (IOException e) {
MavenLog.LOG.warn("cannot unpack AppEngine SDK", e);
}
}
}
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenSearcher method sort.
private void sort(List<RESULT_TYPE> result) {
for (RESULT_TYPE each : result) {
if (each.versions.size() > 1) {
TreeMap<MavenVersionComparable, MavenArtifactInfo> tree = new TreeMap<>(Collections.reverseOrder());
for (MavenArtifactInfo artifactInfo : each.versions) {
tree.put(new MavenVersionComparable(artifactInfo.getVersion()), artifactInfo);
}
each.versions.clear();
each.versions.addAll(tree.values());
}
}
Collections.sort(result, (o1, o2) -> makeSortKey(o1).compareTo(makeSortKey(o2)));
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenClassSearcher method processResults.
protected Collection<MavenClassSearchResult> processResults(Set<MavenArtifactInfo> infos, String pattern, int maxResult) {
if (pattern.length() == 0 || pattern.equals("*")) {
pattern = "^/(.*)$";
} else {
pattern = pattern.replace(".", "/");
int lastDot = pattern.lastIndexOf("/");
String packagePattern = lastDot == -1 ? "" : (pattern.substring(0, lastDot) + "/");
String classNamePattern = lastDot == -1 ? pattern : pattern.substring(lastDot + 1);
packagePattern = packagePattern.replaceAll("\\*", ".*?");
classNamePattern = classNamePattern.replaceAll("\\*", "[^/]*?");
pattern = packagePattern + classNamePattern;
pattern = ".*?/" + pattern;
pattern = "^(" + pattern + ")$";
}
Pattern p;
try {
p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
} catch (PatternSyntaxException e) {
return Collections.emptyList();
}
Map<String, MavenClassSearchResult> result = new THashMap<>();
for (MavenArtifactInfo each : infos) {
if (each.getClassNames() == null)
continue;
Matcher matcher = p.matcher(each.getClassNames());
while (matcher.find()) {
String classFQName = matcher.group(1);
classFQName = classFQName.replace("/", ".");
classFQName = StringUtil.trimStart(classFQName, ".");
String key = makeKey(classFQName, each);
MavenClassSearchResult classResult = result.get(key);
if (classResult == null) {
classResult = new MavenClassSearchResult();
int pos = classFQName.lastIndexOf(".");
if (pos == -1) {
classResult.packageName = "default package";
classResult.className = classFQName;
} else {
classResult.packageName = classFQName.substring(0, pos);
classResult.className = classFQName.substring(pos + 1);
}
result.put(key, classResult);
}
classResult.versions.add(each);
if (result.size() > maxResult)
break;
}
}
return result.values();
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenArtifactSearchPanel method resortUsingDependencyVersionMap.
private void resortUsingDependencyVersionMap(List<MavenArtifactSearchResult> result) {
for (MavenArtifactSearchResult searchResult : result) {
if (searchResult.versions.isEmpty())
continue;
MavenArtifactInfo artifactInfo = searchResult.versions.get(0);
final String managedVersion = myManagedDependenciesMap.get(Pair.create(artifactInfo.getGroupId(), artifactInfo.getArtifactId()));
if (managedVersion != null) {
Collections.sort(searchResult.versions, (o1, o2) -> {
String v1 = o1.getVersion();
String v2 = o2.getVersion();
if (Comparing.equal(v1, v2))
return 0;
if (managedVersion.equals(v1))
return -1;
if (managedVersion.equals(v2))
return 1;
return 0;
});
}
}
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class MavenArtifactSearchPanel method getResult.
@NotNull
public List<MavenId> getResult() {
List<MavenId> result = new ArrayList<>();
for (TreePath each : myResultList.getSelectionPaths()) {
Object sel = each.getLastPathComponent();
MavenArtifactInfo info;
if (sel instanceof MavenArtifactInfo) {
info = (MavenArtifactInfo) sel;
} else {
info = ((MavenArtifactSearchResult) sel).versions.get(0);
}
result.add(new MavenId(info.getGroupId(), info.getArtifactId(), info.getVersion()));
}
return result;
}
Aggregations