Search in sources :

Example 6 with MavenId

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

the class MavenModuleBuilderTest method testCreatingFromArchetype.

public void testCreatingFromArchetype() throws Exception {
    if (!hasMavenInstallation())
        return;
    setArchetype(new MavenArchetype("org.apache.maven.archetypes", "maven-archetype-quickstart", "1.0", null, null));
    MavenId id = new MavenId("org.foo", "module", "1.0");
    createNewModule(id);
    List<MavenProject> projects = MavenProjectsManager.getInstance(myProject).getProjects();
    assertEquals(1, projects.size());
    MavenProject project = projects.get(0);
    assertEquals(id, project.getMavenId());
    assertNotNull(myProjectRoot.findFileByRelativePath("src/main/java/org/foo/App.java"));
    assertNotNull(myProjectRoot.findFileByRelativePath("src/test/java/org/foo/AppTest.java"));
    assertSources("module", "src/main/java");
    assertTestSources("module", "src/test/java");
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype)

Example 7 with MavenId

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

the class Maven3ServerIndexerImpl method addArtifact.

@Override
public MavenId addArtifact(int indexId, File artifactFile) throws RemoteException, 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 8 with MavenId

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

the class Maven2ServerIndexerImpl method processArtifacts.

public void processArtifacts(int indexId, MavenServerIndicesProcessor processor) throws 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 9 with MavenId

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

the class MavenServerEmbedderTest method _testUnresolvedArtifacts.

public void _testUnresolvedArtifacts() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>fff</groupId>" + "    <artifactId>zzz</artifactId>" + "    <version>666</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("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)

Example 10 with MavenId

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

the class MavenServerEmbedderTest method _testUnresolvedSystemArtifactsWithoutPath.

public void _testUnresolvedSystemArtifactsWithoutPath() throws Exception {
    // need to repair model before resolving
    if (ignore())
        return;
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>fff</groupId>" + "    <artifactId>zzz</artifactId>" + "    <version>666</version>" + "    <scope>system</scope>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result);
    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