Search in sources :

Example 1 with ArtifactManager

use of com.intellij.packaging.artifacts.ArtifactManager in project intellij-community by JetBrains.

the class ArtifactBySourceFileFinderImpl method computeFileToArtifactsMap.

private MultiValuesMap<VirtualFile, Artifact> computeFileToArtifactsMap() {
    final MultiValuesMap<VirtualFile, Artifact> result = new MultiValuesMap<>();
    final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);
    for (final Artifact artifact : artifactManager.getArtifacts()) {
        final PackagingElementResolvingContext context = artifactManager.getResolvingContext();
        ArtifactUtil.processPackagingElements(artifact, null, new PackagingElementProcessor<PackagingElement<?>>() {

            @Override
            public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
                if (element instanceof FileOrDirectoryCopyPackagingElement<?>) {
                    final VirtualFile root = ((FileOrDirectoryCopyPackagingElement) element).findFile();
                    if (root != null) {
                        result.put(root, artifact);
                    }
                } else if (element instanceof ModuleOutputPackagingElement) {
                    for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) {
                        result.put(sourceRoot, artifact);
                    }
                }
                return true;
            }
        }, context, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) PackagingElement(com.intellij.packaging.elements.PackagingElement) FileOrDirectoryCopyPackagingElement(com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement) Artifact(com.intellij.packaging.artifacts.Artifact) ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)

Example 2 with ArtifactManager

use of com.intellij.packaging.artifacts.ArtifactManager in project intellij-community by JetBrains.

the class ArtifactsTestUtil method findArtifact.

public static Artifact findArtifact(Project project, String artifactName) {
    final ArtifactManager manager = ArtifactManager.getInstance(project);
    final Artifact artifact = manager.findArtifact(artifactName);
    assertNotNull("'" + artifactName + "' artifact not found", artifact);
    return artifact;
}
Also used : ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 3 with ArtifactManager

use of com.intellij.packaging.artifacts.ArtifactManager in project intellij-community by JetBrains.

the class AppEngineSupportProvider method findOrCreateWebArtifact.

@NotNull
private static Artifact findOrCreateWebArtifact(AppEngineFacet appEngineFacet) {
    Module module = appEngineFacet.getModule();
    ArtifactType webArtifactType = AppEngineWebIntegration.getInstance().getAppEngineWebArtifactType();
    final Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module);
    for (Artifact artifact : artifacts) {
        if (webArtifactType.equals(artifact.getArtifactType())) {
            return artifact;
        }
    }
    ArtifactManager artifactManager = ArtifactManager.getInstance(module.getProject());
    PackagingElementFactory elementFactory = PackagingElementFactory.getInstance();
    ArtifactRootElement<?> root = elementFactory.createArtifactRootElement();
    elementFactory.getOrCreateDirectory(root, "WEB-INF/classes").addOrFindChild(elementFactory.createModuleOutput(module));
    return artifactManager.addArtifact(module.getName(), webArtifactType, root);
}
Also used : ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) ArtifactType(com.intellij.packaging.artifacts.ArtifactType) PackagingElementFactory(com.intellij.packaging.elements.PackagingElementFactory) Module(com.intellij.openapi.module.Module) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ArtifactManager

use of com.intellij.packaging.artifacts.ArtifactManager in project android by JetBrains.

the class NonGradleApkProviderTest method testGetApksWithArtifactName.

public void testGetApksWithArtifactName() throws Exception {
    IDevice device = Mockito.mock(IDevice.class);
    ArtifactManager artifactManager = ArtifactManager.getInstance(myFacet.getModule().getProject());
    CompositePackagingElement<?> archive = PackagingElementFactory.getInstance().createArchive("right.apk");
    archive.addFirstChild(new AndroidFinalPackageElement(myFacet.getModule().getProject(), myFacet));
    artifactManager.addArtifact("customApk", AndroidApplicationArtifactType.getInstance(), archive);
    myFacet.getProperties().APK_PATH = "wrong.apk";
    NonGradleApkProvider provider = new NonGradleApkProvider(myFacet, new NonGradleApplicationIdProvider(myFacet), "customApk");
    Collection<ApkInfo> apks = provider.getApks(device);
    assertNotNull(apks);
    assertEquals(1, apks.size());
    ApkInfo apk = apks.iterator().next();
    assertEquals("p1.p2", apk.getApplicationId());
    assertTrue(apk.getFile().getPath().endsWith("right.apk"));
}
Also used : ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) AndroidFinalPackageElement(org.jetbrains.android.compiler.artifact.AndroidFinalPackageElement) IDevice(com.android.ddmlib.IDevice)

Example 5 with ArtifactManager

use of com.intellij.packaging.artifacts.ArtifactManager in project intellij-community by JetBrains.

the class ArtifactCompileScope method getArtifactsToBuild.

public static Set<Artifact> getArtifactsToBuild(final Project project, final CompileScope compileScope, final boolean addIncludedArtifactsWithOutputPathsOnly) {
    final Artifact[] artifactsFromScope = getArtifacts(compileScope);
    final ArtifactManager artifactManager = ArtifactManager.getInstance(project);
    PackagingElementResolvingContext context = artifactManager.getResolvingContext();
    if (artifactsFromScope != null) {
        return addIncludedArtifacts(Arrays.asList(artifactsFromScope), context, addIncludedArtifactsWithOutputPathsOnly);
    }
    final Set<Artifact> cached = compileScope.getUserData(CACHED_ARTIFACTS_KEY);
    if (cached != null) {
        return cached;
    }
    Set<Artifact> artifacts = new HashSet<>();
    final Set<Module> modules = new HashSet<>(Arrays.asList(compileScope.getAffectedModules()));
    final List<Module> allModules = Arrays.asList(ModuleManager.getInstance(project).getModules());
    for (Artifact artifact : artifactManager.getArtifacts()) {
        if (artifact.isBuildOnMake()) {
            if (modules.containsAll(allModules) || containsModuleOutput(artifact, modules, context)) {
                artifacts.add(artifact);
            }
        }
    }
    Set<Artifact> result = addIncludedArtifacts(artifacts, context, addIncludedArtifactsWithOutputPathsOnly);
    compileScope.putUserData(CACHED_ARTIFACTS_KEY, result);
    return result;
}
Also used : ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) Module(com.intellij.openapi.module.Module) Artifact(com.intellij.packaging.artifacts.Artifact)

Aggregations

ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)8 Artifact (com.intellij.packaging.artifacts.Artifact)5 Module (com.intellij.openapi.module.Module)2 PackagingElementResolvingContext (com.intellij.packaging.elements.PackagingElementResolvingContext)2 IDevice (com.android.ddmlib.IDevice)1 MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)1 FileOrDirectoryCopyPackagingElement (com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement)1 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)1 ArrayList (java.util.ArrayList)1 AndroidFinalPackageElement (org.jetbrains.android.compiler.artifact.AndroidFinalPackageElement)1 NotNull (org.jetbrains.annotations.NotNull)1