Search in sources :

Example 6 with MavenArtifactInfo

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);
            }
        }
    }
}
Also used : MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) IOException(java.io.IOException) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) File(java.io.File)

Example 7 with MavenArtifactInfo

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)));
}
Also used : MavenVersionComparable(org.jetbrains.idea.maven.dom.MavenVersionComparable) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo)

Example 8 with MavenArtifactInfo

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();
}
Also used : Pattern(java.util.regex.Pattern) THashMap(gnu.trove.THashMap) Matcher(java.util.regex.Matcher) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 9 with MavenArtifactInfo

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;
            });
        }
    }
}
Also used : MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo)

Example 10 with MavenArtifactInfo

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;
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) TreePath(javax.swing.tree.TreePath) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MavenArtifactInfo (org.jetbrains.idea.maven.model.MavenArtifactInfo)15 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 THashMap (gnu.trove.THashMap)2 THashSet (gnu.trove.THashSet)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 RemoteException (java.rmi.RemoteException)2 Document (org.apache.lucene.document.Document)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 TopDocs (org.apache.lucene.search.TopDocs)2 ArchetypeDataSourceException (org.apache.maven.archetype.source.ArchetypeDataSourceException)2 IndexingContext (org.sonatype.nexus.index.context.IndexingContext)2 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Matcher (java.util.regex.Matcher)1