Search in sources :

Example 31 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class Maven2ServerIndexerImpl method addArtifact.

public MavenId addArtifact(int indexId, File artifactFile) throws MavenServerIndexerException {
    try {
        IndexingContext index = getIndex(indexId);
        ArtifactContext artifactContext = myArtifactContextProducer.getArtifactContext(index, artifactFile);
        if (artifactContext == null)
            return null;
        addArtifact(myIndexer, index, artifactContext);
        org.sonatype.nexus.index.ArtifactInfo a = artifactContext.getArtifactInfo();
        return new MavenId(a.groupId, a.artifactId, a.version);
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) IndexingContext(org.sonatype.nexus.index.context.IndexingContext) org.sonatype.nexus.index(org.sonatype.nexus.index) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ArchetypeDataSourceException(org.apache.maven.archetype.source.ArchetypeDataSourceException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException)

Example 32 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class Maven3ServerIndexerImpl method processArtifacts.

@Override
public void processArtifacts(int indexId, MavenServerIndicesProcessor processor) throws RemoteException, MavenServerIndexerException {
    try {
        final int CHUNK_SIZE = 10000;
        IndexReader r = getIndex(indexId).getIndexReader();
        int total = r.numDocs();
        List<MavenId> result = new ArrayList<MavenId>(Math.min(CHUNK_SIZE, total));
        for (int i = 0; i < total; i++) {
            if (r.isDeleted(i))
                continue;
            Document doc = r.document(i);
            String uinfo = doc.get(SEARCH_TERM_COORDINATES);
            if (uinfo == null)
                continue;
            List<String> parts = StringUtil.split(uinfo, "|");
            String groupId = parts.get(0);
            String artifactId = parts.get(1);
            String version = parts.get(2);
            if (groupId == null || artifactId == null || version == null)
                continue;
            result.add(new MavenId(groupId, artifactId, version));
            if (result.size() == CHUNK_SIZE) {
                processor.processArtifacts(result);
                result.clear();
            }
        }
        if (!result.isEmpty()) {
            processor.processArtifacts(result);
        }
    } catch (Exception e) {
        throw new MavenServerIndexerException(wrapException(e));
    }
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) IndexReader(org.apache.lucene.index.IndexReader) Document(org.apache.lucene.document.Document) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ArchetypeDataSourceException(org.apache.maven.archetype.source.ArchetypeDataSourceException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException)

Example 33 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class CustomMaven3RepositoryMetadataManager method resolve.

@Override
public void resolve(RepositoryMetadata metadata, RepositoryRequest request) throws RepositoryMetadataResolutionException {
    super.resolve(metadata, request);
    MavenWorkspaceMap map = myWorkspaceMap;
    if (map == null)
        return;
    Metadata data = metadata.getMetadata();
    Versioning versioning = data.getVersioning();
    if (versioning == null) {
        data.setVersioning(versioning = new Versioning());
    }
    for (MavenId each : map.getAvailableIds()) {
        if (each.equals(data.getGroupId(), data.getArtifactId())) {
            versioning.addVersion(each.getVersion());
        }
    }
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenWorkspaceMap(org.jetbrains.idea.maven.model.MavenWorkspaceMap)

Example 34 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenServerEmbedderTest method _testDependencyWithUnresolvedParent.

public void _testDependencyWithUnresolvedParent() throws Exception {
    File repo = new File(myDir, "/repo");
    setRepositoryPath(repo.getPath());
    initEmbedder();
    VirtualFile m = createModulePom("foo-parent", "<groupId>test</groupId>" + "<artifactId>foo-parent</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    myEmbedder.execute(m, Collections.<String>emptyList(), Collections.<String>emptyList(), Arrays.asList("install"));
    myEmbedder.reset();
    File fooParentFile = new File(repo, "test/foo-parent/1/foo-parent-1.pom");
    assertTrue(fooParentFile.exists());
    m = createModulePom("foo", "<artifactId>foo</artifactId>" + "<version>1</version>" + "<parent>" + "  <groupId>test</groupId>" + "  <artifactId>foo-parent</artifactId>" + "  <version>1</version>" + "</parent>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    myEmbedder.execute(m, Collections.<String>emptyList(), Collections.<String>emptyList(), Arrays.asList("install"));
    myEmbedder.reset();
    assertTrue(new File(repo, "test/foo/1/foo-1.pom").exists());
    FileUtil.delete(fooParentFile);
    // reset all caches
    initEmbedder();
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>test</groupId>" + "    <artifactId>foo</artifactId>" + "    <version>1</version>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result.projectData);
    assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("test", "foo-parent", "1"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 35 with MavenId

use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.

the class MavenServerEmbedderTest method _testUnresolvedSystemArtifacts.

public void _testUnresolvedSystemArtifacts() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>fff</groupId>" + "    <artifactId>zzz</artifactId>" + "    <version>666</version>" + "    <scope>system</scope>" + "    <systemPath>" + myProjectRoot.getPath() + "/foo.jar</systemPath>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result.projectData);
    assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("fff", "zzz", "666"));
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole)

Aggregations

MavenId (org.jetbrains.idea.maven.model.MavenId)59 MavenProject (org.jetbrains.idea.maven.project.MavenProject)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Module (com.intellij.openapi.module.Module)5 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 RemoteException (java.rmi.RemoteException)4 ArchetypeDataSourceException (org.apache.maven.archetype.source.ArchetypeDataSourceException)4 SoutMavenConsole (org.jetbrains.idea.maven.execution.SoutMavenConsole)4 MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)4 MavenServerExecutionResult (org.jetbrains.idea.maven.server.MavenServerExecutionResult)4 Project (com.intellij.openapi.project.Project)3 File (java.io.File)3 MavenArchetype (org.jetbrains.idea.maven.model.MavenArchetype)3 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2