Search in sources :

Example 21 with Artifact

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

the class ApplicationRunParameters method resetFrom.

@Override
public void resetFrom(@NotNull AndroidRunConfiguration configuration) {
    InstallOption installOption = getDeployOption(configuration.DEPLOY, configuration.ARTIFACT_NAME);
    myDeployOptionCombo.setSelectedItem(installOption);
    if (installOption == InstallOption.CUSTOM_ARTIFACT) {
        String artifactName = StringUtil.notNullize(configuration.ARTIFACT_NAME);
        List<Artifact> artifacts = Lists.newArrayList(getAndroidArtifacts());
        Artifact selectedArtifact = findArtifactByName(artifacts, artifactName);
        if (selectedArtifact != null) {
            myArtifactCombo.setModel(new DefaultComboBoxModel(artifacts.toArray()));
            myArtifactCombo.setSelectedItem(selectedArtifact);
        } else {
            List<Object> items = Lists.newArrayList(artifacts.toArray());
            items.add(artifactName);
            myArtifactCombo.setModel(new DefaultComboBoxModel(items.toArray()));
            myArtifactCombo.setSelectedItem(artifactName);
        }
    }
    myPmOptionsLabeledComponent.getComponent().setText(configuration.PM_INSTALL_OPTIONS);
    for (LaunchOption option : AndroidRunConfiguration.LAUNCH_OPTIONS) {
        LaunchOptionState state = configuration.getLaunchOptionState(option.getId());
        assert state != null : "State is null for option: " + option.getDisplayName();
        myConfigurables.get(option.getId()).resetFrom(state);
    }
    LaunchOption launchOption = getLaunchOption(configuration.MODE);
    myLaunchOptionCombo.setSelectedItem(launchOption);
    myAmOptionsLabeledComponent.getComponent().setText(configuration.ACTIVITY_EXTRA_FLAGS);
}
Also used : Artifact(com.intellij.packaging.artifacts.Artifact)

Example 22 with Artifact

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

the class CompileDriver method compileInExternalProcess.

@Nullable
private TaskFuture compileInExternalProcess(@NotNull final CompileContextImpl compileContext, final boolean onlyCheckUpToDate) throws Exception {
    final CompileScope scope = compileContext.getCompileScope();
    final Collection<String> paths = CompileScopeUtil.fetchFiles(compileContext);
    List<TargetTypeBuildScope> scopes = getBuildScopes(compileContext, scope, paths);
    // need to pass scope's user data to server
    final Map<String, String> builderParams;
    if (onlyCheckUpToDate) {
        builderParams = Collections.emptyMap();
    } else {
        final Map<Key, Object> exported = scope.exportUserData();
        if (!exported.isEmpty()) {
            builderParams = new HashMap<>();
            for (Map.Entry<Key, Object> entry : exported.entrySet()) {
                final String _key = entry.getKey().toString();
                final String _value = entry.getValue().toString();
                builderParams.put(_key, _value);
            }
        } else {
            builderParams = Collections.emptyMap();
        }
    }
    final MessageBus messageBus = myProject.getMessageBus();
    final MultiMap<String, Artifact> outputToArtifact = ArtifactCompilerUtil.containsArtifacts(scopes) ? ArtifactCompilerUtil.createOutputToArtifactMap(myProject) : null;
    final BuildManager buildManager = BuildManager.getInstance();
    buildManager.cancelAutoMakeTasks(myProject);
    return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), onlyCheckUpToDate, scopes, paths, builderParams, new DefaultMessageHandler(myProject) {

        @Override
        public void sessionTerminated(final UUID sessionId) {
            if (compileContext.shouldUpdateProblemsView()) {
                final ProblemsView view = ProblemsView.SERVICE.getInstance(myProject);
                view.clearProgress();
                view.clearOldMessages(compileContext.getCompileScope(), compileContext.getSessionId());
            }
        }

        @Override
        public void handleFailure(UUID sessionId, CmdlineRemoteProto.Message.Failure failure) {
            compileContext.addMessage(CompilerMessageCategory.ERROR, failure.hasDescription() ? failure.getDescription() : "", null, -1, -1);
            final String trace = failure.hasStacktrace() ? failure.getStacktrace() : null;
            if (trace != null) {
                LOG.info(trace);
            }
            compileContext.putUserData(COMPILE_SERVER_BUILD_STATUS, ExitStatus.ERRORS);
        }

        @Override
        protected void handleCompileMessage(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
            final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
            //System.out.println(compilerMessage.getText());
            final String messageText = message.getText();
            if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.PROGRESS) {
                final ProgressIndicator indicator = compileContext.getProgressIndicator();
                indicator.setText(messageText);
                if (message.hasDone()) {
                    indicator.setFraction(message.getDone());
                }
            } else {
                final CompilerMessageCategory category = kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR ? CompilerMessageCategory.ERROR : kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.WARNING ? CompilerMessageCategory.WARNING : CompilerMessageCategory.INFORMATION;
                String sourceFilePath = message.hasSourceFilePath() ? message.getSourceFilePath() : null;
                if (sourceFilePath != null) {
                    sourceFilePath = FileUtil.toSystemIndependentName(sourceFilePath);
                }
                final long line = message.hasLine() ? message.getLine() : -1;
                final long column = message.hasColumn() ? message.getColumn() : -1;
                final String srcUrl = sourceFilePath != null ? VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, sourceFilePath) : null;
                compileContext.addMessage(category, messageText, srcUrl, (int) line, (int) column);
                if (compileContext.shouldUpdateProblemsView() && kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.JPS_INFO) {
                    // treat JPS_INFO messages in a special way: add them as info messages to the problems view
                    final Project project = compileContext.getProject();
                    ProblemsView.SERVICE.getInstance(project).addMessage(new CompilerMessageImpl(project, category, messageText), compileContext.getSessionId());
                }
            }
        }

        @Override
        protected void handleBuildEvent(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
            final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Type eventType = event.getEventType();
            switch(eventType) {
                case FILES_GENERATED:
                    final List<CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile> generated = event.getGeneratedFilesList();
                    final CompilationStatusListener publisher = !myProject.isDisposed() ? messageBus.syncPublisher(CompilerTopics.COMPILATION_STATUS) : null;
                    Set<String> writtenArtifactOutputPaths = outputToArtifact != null ? new THashSet<>(FileUtil.PATH_HASHING_STRATEGY) : null;
                    for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : generated) {
                        final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
                        final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
                        if (publisher != null) {
                            publisher.fileGenerated(root, relativePath);
                        }
                        if (outputToArtifact != null) {
                            Collection<Artifact> artifacts = outputToArtifact.get(root);
                            if (!artifacts.isEmpty()) {
                                for (Artifact artifact : artifacts) {
                                    ArtifactsCompiler.addChangedArtifact(compileContext, artifact);
                                }
                                writtenArtifactOutputPaths.add(FileUtil.toSystemDependentName(DeploymentUtil.appendToPath(root, relativePath)));
                            }
                        }
                    }
                    if (writtenArtifactOutputPaths != null && !writtenArtifactOutputPaths.isEmpty()) {
                        ArtifactsCompiler.addWrittenPaths(compileContext, writtenArtifactOutputPaths);
                    }
                    break;
                case BUILD_COMPLETED:
                    ExitStatus status = ExitStatus.SUCCESS;
                    if (event.hasCompletionStatus()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status completionStatus = event.getCompletionStatus();
                        switch(completionStatus) {
                            case CANCELED:
                                status = ExitStatus.CANCELLED;
                                break;
                            case ERRORS:
                                status = ExitStatus.ERRORS;
                                break;
                            case SUCCESS:
                                status = ExitStatus.SUCCESS;
                                break;
                            case UP_TO_DATE:
                                status = ExitStatus.UP_TO_DATE;
                                break;
                        }
                    }
                    compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, status);
                    break;
                case CUSTOM_BUILDER_MESSAGE:
                    if (event.hasCustomBuilderMessage()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.CustomBuilderMessage message = event.getCustomBuilderMessage();
                        if (GlobalOptions.JPS_SYSTEM_BUILDER_ID.equals(message.getBuilderId()) && GlobalOptions.JPS_UNPROCESSED_FS_CHANGES_MESSAGE_ID.equals(message.getMessageType())) {
                            final String text = message.getMessageText();
                            if (!StringUtil.isEmpty(text)) {
                                compileContext.addMessage(CompilerMessageCategory.INFORMATION, text, null, -1, -1);
                            }
                        }
                    }
                    break;
            }
        }
    });
}
Also used : THashSet(gnu.trove.THashSet) MessageBus(com.intellij.util.messages.MessageBus) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) DefaultMessageHandler(com.intellij.compiler.server.DefaultMessageHandler) CmdlineRemoteProto(org.jetbrains.jps.api.CmdlineRemoteProto) Artifact(com.intellij.packaging.artifacts.Artifact) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) MessageType(com.intellij.openapi.ui.MessageType) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) BuildManager(com.intellij.compiler.server.BuildManager) HashMap(com.intellij.util.containers.HashMap) MultiMap(com.intellij.util.containers.MultiMap) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with Artifact

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

the class ArtifactBySourceFileFinderImpl method findArtifacts.

@Override
public Collection<? extends Artifact> findArtifacts(@NotNull VirtualFile sourceFile) {
    final MultiValuesMap<VirtualFile, Artifact> map = getFileToArtifactsMap().getValue();
    if (map.isEmpty()) {
        return Collections.emptyList();
    }
    List<Artifact> result = null;
    VirtualFile file = sourceFile;
    while (file != null) {
        final Collection<Artifact> artifacts = map.get(file);
        if (artifacts != null) {
            if (result == null) {
                result = new SmartList<>();
            }
            result.addAll(artifacts);
        }
        file = file.getParent();
    }
    return result != null ? result : Collections.<Artifact>emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 24 with Artifact

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

the class PackageFileAction method getFilesToPackage.

@NotNull
private static List<VirtualFile> getFilesToPackage(@NotNull AnActionEvent e, @NotNull Project project) {
    final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (files == null)
        return Collections.emptyList();
    List<VirtualFile> result = new ArrayList<>();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    for (VirtualFile file : files) {
        if (file == null || file.isDirectory() || fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && compilerManager.isCompilableFileType(file.getFileType())) {
            return Collections.emptyList();
        }
        final Collection<? extends Artifact> artifacts = ArtifactBySourceFileFinder.getInstance(project).findArtifacts(file);
        for (Artifact artifact : artifacts) {
            if (!StringUtil.isEmpty(artifact.getOutputPath())) {
                result.add(file);
                break;
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) CompilerManager(com.intellij.openapi.compiler.CompilerManager) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with Artifact

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

the class PackageFileWorker method packageFile.

public static void packageFile(@NotNull VirtualFile file, @NotNull Project project, final Artifact[] artifacts, final boolean packIntoArchives) throws IOException {
    LOG.debug("Start packaging file: " + file.getPath());
    final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts);
    File ioFile = VfsUtilCore.virtualToIoFile(file);
    for (Trinity<Artifact, PackagingElementPath, String> item : items) {
        final Artifact artifact = item.getFirst();
        final String outputPath = artifact.getOutputPath();
        if (!StringUtil.isEmpty(outputPath)) {
            PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird(), packIntoArchives);
            LOG.debug(" package to " + outputPath);
            worker.packageFile(outputPath, item.getSecond().getParents());
        }
    }
}
Also used : Trinity(com.intellij.openapi.util.Trinity) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File) Artifact(com.intellij.packaging.artifacts.Artifact)

Aggregations

Artifact (com.intellij.packaging.artifacts.Artifact)52 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Module (com.intellij.openapi.module.Module)7 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)5 File (java.io.File)5 PackagingElement (com.intellij.packaging.elements.PackagingElement)4 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)4 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)4 Nullable (org.jetbrains.annotations.Nullable)4 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)3 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)3 ReadAction (com.intellij.openapi.application.ReadAction)2 Result (com.intellij.openapi.application.Result)2 Pair (com.intellij.openapi.util.Pair)2 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2