Search in sources :

Example 1 with PackagingElementResolvingContext

use of com.intellij.packaging.elements.PackagingElementResolvingContext 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 PackagingElementResolvingContext

use of com.intellij.packaging.elements.PackagingElementResolvingContext in project intellij-community by JetBrains.

the class AppEngineUploader method createUploader.

@Nullable
public static AppEngineUploader createUploader(@NotNull Project project, @NotNull Artifact artifact, @NotNull AppEngineServerConfiguration configuration, @NotNull ServerRuntimeInstance.DeploymentOperationCallback callback, @NotNull LoggingHandler loggingHandler) {
    final String explodedPath = artifact.getOutputPath();
    if (explodedPath == null) {
        callback.errorOccurred("Output path isn't specified for '" + artifact.getName() + "' artifact");
        return null;
    }
    final AppEngineFacet appEngineFacet = AppEngineUtil.findAppEngineFacet(project, artifact);
    if (appEngineFacet == null) {
        callback.errorOccurred("App Engine facet not found in '" + artifact.getName() + "' artifact");
        return null;
    }
    final AppEngineSdk sdk = appEngineFacet.getSdk();
    if (!sdk.getAppCfgFile().exists()) {
        callback.errorOccurred("Path to App Engine SDK isn't specified correctly in App Engine Facet settings");
        return null;
    }
    PackagingElementResolvingContext context = ArtifactManager.getInstance(project).getResolvingContext();
    VirtualFile descriptorFile = ArtifactUtil.findSourceFileByOutputPath(artifact, "WEB-INF/appengine-web.xml", context);
    final AppEngineWebApp root = AppEngineFacet.getDescriptorRoot(descriptorFile, appEngineFacet.getModule().getProject());
    if (root != null) {
        final GenericDomValue<String> application = root.getApplication();
        if (StringUtil.isEmptyOrSpaces(application.getValue())) {
            final String name = Messages.showInputDialog(project, "<html>Application name is not specified in appengine-web.xml.<br>" + "Enter application name (see your <a href=\"http://appengine.google.com\">AppEngine account</a>):</html>", CommonBundle.getErrorTitle(), null, "", null);
            if (name == null)
                return null;
            final PsiFile file = application.getXmlTag().getContainingFile();
            new WriteCommandAction(project, file) {

                protected void run(@NotNull final Result result) {
                    application.setStringValue(name);
                }
            }.execute();
            final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document != null) {
                FileDocumentManager.getInstance().saveDocument(document);
            }
        }
    }
    AppEngineAuthData authData = AppEngineAccountDialog.createAuthData(project, configuration);
    if (authData == null)
        return null;
    return new AppEngineUploader(project, artifact, appEngineFacet, sdk, authData, callback, loggingHandler);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) Document(com.intellij.openapi.editor.Document) AppEngineWebApp(com.intellij.appengine.descriptor.dom.AppEngineWebApp) Result(com.intellij.openapi.application.Result) AppEngineFacet(com.intellij.appengine.facet.AppEngineFacet) PsiFile(com.intellij.psi.PsiFile) AppEngineSdk(com.intellij.appengine.sdk.AppEngineSdk) AppEngineAuthData(com.intellij.appengine.cloud.AppEngineAuthData) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PackagingElementResolvingContext

use of com.intellij.packaging.elements.PackagingElementResolvingContext in project android by JetBrains.

the class AndroidArtifactUtil method getPackagedFacet.

@Nullable
public static AndroidFacet getPackagedFacet(Project project, Artifact artifact) {
    final Ref<AndroidFinalPackageElement> elementRef = Ref.create(null);
    final PackagingElementResolvingContext resolvingContext = ArtifactManager.getInstance(project).getResolvingContext();
    ArtifactUtil.processPackagingElements(artifact, AndroidFinalPackageElementType.getInstance(), new Processor<AndroidFinalPackageElement>() {

        @Override
        public boolean process(AndroidFinalPackageElement e) {
            elementRef.set(e);
            return false;
        }
    }, resolvingContext, true);
    final AndroidFinalPackageElement element = elementRef.get();
    return element != null ? element.getFacet() : null;
}
Also used : PackagingElementResolvingContext(com.intellij.packaging.elements.PackagingElementResolvingContext) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PackagingElementResolvingContext

use of com.intellij.packaging.elements.PackagingElementResolvingContext 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

PackagingElementResolvingContext (com.intellij.packaging.elements.PackagingElementResolvingContext)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Artifact (com.intellij.packaging.artifacts.Artifact)2 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)2 Nullable (org.jetbrains.annotations.Nullable)2 AppEngineAuthData (com.intellij.appengine.cloud.AppEngineAuthData)1 AppEngineWebApp (com.intellij.appengine.descriptor.dom.AppEngineWebApp)1 AppEngineFacet (com.intellij.appengine.facet.AppEngineFacet)1 AppEngineSdk (com.intellij.appengine.sdk.AppEngineSdk)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1 Module (com.intellij.openapi.module.Module)1 MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 FileOrDirectoryCopyPackagingElement (com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement)1 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)1 PsiFile (com.intellij.psi.PsiFile)1