Search in sources :

Example 1 with MavenArtifact

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

the class MavenModuleImporter method configDependencies.

private void configDependencies() {
    THashSet<String> dependencyTypesFromSettings = new THashSet<>();
    AccessToken accessToken = ReadAction.start();
    try {
        if (myModule.getProject().isDisposed())
            return;
        dependencyTypesFromSettings.addAll(MavenProjectsManager.getInstance(myModule.getProject()).getImportingSettings().getDependencyTypesAsSet());
    } finally {
        accessToken.finish();
    }
    for (MavenArtifact artifact : myMavenProject.getDependencies()) {
        String dependencyType = artifact.getType();
        if (!dependencyTypesFromSettings.contains(dependencyType) && !myMavenProject.getDependencyTypesFromImporters(SupportedRequestType.FOR_IMPORT).contains(dependencyType)) {
            continue;
        }
        DependencyScope scope = selectScope(artifact.getScope());
        MavenProject depProject = myMavenTree.findProject(artifact.getMavenId());
        if (depProject != null) {
            if (depProject == myMavenProject)
                continue;
            String moduleName = myMavenProjectToModuleName.get(depProject);
            if (moduleName == null || myMavenTree.isIgnored(depProject)) {
                MavenArtifact projectsArtifactInRepository = new MavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getBaseVersion(), dependencyType, artifact.getClassifier(), artifact.getScope(), artifact.isOptional(), artifact.getExtension(), null, myMavenProject.getLocalRepository(), false, false);
                myRootModelAdapter.addLibraryDependency(projectsArtifactInRepository, scope, myModifiableModelsProvider, myMavenProject);
            } else {
                boolean isTestJar = MavenConstants.TYPE_TEST_JAR.equals(dependencyType) || "tests".equals(artifact.getClassifier());
                myRootModelAdapter.addModuleDependency(moduleName, scope, isTestJar);
                Element buildHelperCfg = depProject.getPluginGoalConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "attach-artifact");
                if (buildHelperCfg != null) {
                    addAttachArtifactDependency(buildHelperCfg, scope, depProject, artifact);
                }
                if (IMPORTED_CLASSIFIERS.contains(artifact.getClassifier()) && !isTestJar && !"system".equals(artifact.getScope()) && !"false".equals(System.getProperty("idea.maven.classifier.dep"))) {
                    MavenArtifact a = new MavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getBaseVersion(), dependencyType, artifact.getClassifier(), artifact.getScope(), artifact.isOptional(), artifact.getExtension(), null, myMavenProject.getLocalRepository(), false, false);
                    myRootModelAdapter.addLibraryDependency(a, scope, myModifiableModelsProvider, myMavenProject);
                }
            }
        } else if ("system".equals(artifact.getScope())) {
            myRootModelAdapter.addSystemDependency(artifact, scope);
        } else {
            myRootModelAdapter.addLibraryDependency(artifact, scope, myModifiableModelsProvider, myMavenProject);
        }
    }
    configSurefirePlugin();
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Element(org.jdom.Element) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) THashSet(gnu.trove.THashSet)

Example 2 with MavenArtifact

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

the class MavenProjectImporter method scheduleRefreshResolvedArtifacts.

private void scheduleRefreshResolvedArtifacts(List<MavenProjectsProcessorTask> postTasks) {
    // We have to refresh all the resolved artifacts manually in order to
    // update all the VirtualFilePointers. It is not enough to call
    // VirtualFileManager.refresh() since the newly created files will be only
    // picked by FS when FileWatcher finishes its work. And in the case of import
    // it doesn't finish in time.
    // I couldn't manage to write a test for this since behaviour of VirtualFileManager
    // and FileWatcher differs from real-life execution.
    List<MavenArtifact> artifacts = new ArrayList<>();
    for (MavenProject each : myProjectsToImportWithChanges.keySet()) {
        artifacts.addAll(each.getDependencies());
    }
    final Set<File> files = new THashSet<>();
    for (MavenArtifact each : artifacts) {
        if (each.isResolved())
            files.add(each.getFile());
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        doRefreshFiles(files);
    } else {
        postTasks.add(new MavenProjectsProcessorTask() {

            public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
                indicator.setText("Refreshing files...");
                doRefreshFiles(files);
            }
        });
    }
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with MavenArtifact

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

the class MavenArtifactIndex method findArtifacts.

@NotNull
public List<MavenArtifact> findArtifacts(@Nullable String groupId, @Nullable String artifactId, @Nullable String version) {
    Map<String, List<MavenArtifact>> groupMap = myData.get(groupId);
    if (groupMap == null)
        return Collections.emptyList();
    List<MavenArtifact> artifacts = groupMap.get(artifactId);
    if (artifacts == null)
        return Collections.emptyList();
    List<MavenArtifact> res = new SmartList<>();
    for (MavenArtifact artifact : artifacts) {
        if (Comparing.equal(version, artifact.getVersion())) {
            res.add(artifact);
        }
    }
    return res;
}
Also used : List(java.util.List) SmartList(com.intellij.util.SmartList) SmartList(com.intellij.util.SmartList) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact 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 5 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-plugins by JetBrains.

the class DependencyEmbedder method processHeaders.

public void processHeaders(Analyzer analyzer) throws DependencyEmbedderException {
    StringBuilder includeResource = new StringBuilder();
    StringBuilder bundleClassPath = new StringBuilder();
    StringBuilder embeddedArtifacts = new StringBuilder();
    myInlinePaths.clear();
    myEmbeddedArtifacts.clear();
    String embedDependencyHeader = analyzer.getProperty(EMBED_DEPENDENCY);
    if (StringUtil.isNotEmpty(embedDependencyHeader)) {
        myEmbedDirectory = analyzer.getProperty(EMBED_DIRECTORY);
        myEmbedStripGroup = analyzer.getProperty(EMBED_STRIP_GROUP, "true");
        myEmbedStripVersion = analyzer.getProperty(EMBED_STRIP_VERSION);
        processInstructions(embedDependencyHeader);
        for (String inlinePath : myInlinePaths) {
            inlineDependency(inlinePath, includeResource);
        }
        for (MavenArtifact embeddedArtifact : myEmbeddedArtifacts) {
            embedDependency(embeddedArtifact, includeResource, bundleClassPath, embeddedArtifacts);
        }
    }
    if (analyzer.getProperty(Constants.WAB) == null && bundleClassPath.length() > 0) {
        // set explicit default before merging dependency classpath
        if (analyzer.getProperty(Constants.BUNDLE_CLASSPATH) == null) {
            analyzer.setProperty(Constants.BUNDLE_CLASSPATH, ".");
        }
    }
    appendDependencies(analyzer, Constants.INCLUDE_RESOURCE, includeResource.toString());
    appendDependencies(analyzer, Constants.BUNDLE_CLASSPATH, bundleClassPath.toString());
    appendDependencies(analyzer, EMBEDDED_ARTIFACTS, embeddedArtifacts.toString());
}
Also used : MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact)

Aggregations

MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)21 File (java.io.File)5 NotNull (org.jetbrains.annotations.NotNull)4 MavenId (org.jetbrains.idea.maven.model.MavenId)4 MavenProject (org.jetbrains.idea.maven.project.MavenProject)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Library (com.intellij.openapi.roots.libraries.Library)2 SmartList (com.intellij.util.SmartList)2 THashSet (gnu.trove.THashSet)2 List (java.util.List)2 Map (java.util.Map)2 Attrs (aQute.bnd.header.Attrs)1 Parameters (aQute.bnd.header.Parameters)1 Analyzer (aQute.bnd.osgi.Analyzer)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Module (com.intellij.openapi.module.Module)1 DumbProgressIndicator (com.intellij.openapi.progress.DumbProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1