Search in sources :

Example 1 with ModifiableArtifactModel

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

the class ArtifactLoadingErrorDescription method ignoreInvalidElement.

@Override
public void ignoreInvalidElement() {
    final ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel();
    model.removeArtifact(myArtifact);
    new WriteAction() {

        protected void run(@NotNull final Result result) {
            model.commit();
        }
    }.execute();
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Result(com.intellij.openapi.application.Result)

Example 2 with ModifiableArtifactModel

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

the class ArtifactVirtualFileListener method filePathChanged.

private void filePathChanged(@NotNull final String oldPath, @NotNull final String newPath) {
    final Collection<Artifact> artifacts = myParentPathsToArtifacts.getValue().get(oldPath);
    if (artifacts != null) {
        final ModifiableArtifactModel model = myArtifactManager.createModifiableModel();
        for (Artifact artifact : artifacts) {
            final Artifact copy = model.getOrCreateModifiableArtifact(artifact);
            ArtifactUtil.processFileOrDirectoryCopyElements(copy, new PackagingElementProcessor<FileOrDirectoryCopyPackagingElement<?>>() {

                @Override
                public boolean process(@NotNull FileOrDirectoryCopyPackagingElement<?> element, @NotNull PackagingElementPath pathToElement) {
                    final String path = element.getFilePath();
                    if (FileUtil.startsWith(path, oldPath)) {
                        element.setFilePath(newPath + path.substring(oldPath.length()));
                    }
                    return true;
                }
            }, myArtifactManager.getResolvingContext(), false);
        }
        model.commit();
    }
}
Also used : FileOrDirectoryCopyPackagingElement(com.intellij.packaging.impl.elements.FileOrDirectoryCopyPackagingElement) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 3 with ModifiableArtifactModel

use of com.intellij.packaging.artifacts.ModifiableArtifactModel in project azure-tools-for-java by Microsoft.

the class AzureWebDeployAction method onActionPerformed.

public void onActionPerformed(AnActionEvent e) {
    //        Module module = LangDataKeys.MODULE.getData(e.getDataContext());
    //        Module module1 = e.getData(LangDataKeys.MODULE);
    Project project = DataKeys.PROJECT.getData(e.getDataContext());
    JFrame frame = WindowManager.getInstance().getFrame(project);
    try {
        if (!AzureSignInAction.doSignIn(AuthMethodManager.getInstance(), project))
            return;
        //Project project = module.getProject();
        ModifiableArtifactModel artifactModel = ProjectStructureConfigurable.getInstance(project).getArtifactsStructureConfigurable().getModifiableArtifactModel();
        Artifact artifactToDeploy = null;
        Collection<? extends Artifact> artifacts = artifactModel.getArtifactsByType(ArtifactType.findById("war"));
        List<String> issues = new LinkedList<>();
        if (artifacts.size() == 0) {
            issues.add("A web archive (WAR) Artifact has not been configured yet. The artifact configurations are managed in the <b>Project Structure</b> dialog (<b>File | Project Structure | Artifacts</b>).");
            ArtifactValidationWindow.go(project, issues);
            return;
        } else if (artifacts.size() > 1) {
            WarSelectDialog d = WarSelectDialog.go(project, new ArrayList<>(artifacts));
            if (d == null) {
                return;
            }
            artifactToDeploy = d.getSelectedArtifact();
        } else {
            artifactToDeploy = (Artifact) artifacts.toArray()[0];
        }
        // check artifact name is valid
        String name = artifactToDeploy.getName();
        if (!name.matches("^[A-Za-z0-9]*[A-Za-z0-9]$")) {
            issues.add("The artifact name <b>'" + name + "'</b> is invalid. An artifact name may contain only the ASCII letters 'a' through 'z' (case-insensitive),\nand the digits '0' through '9'.");
        }
        boolean exists = Files.exists(Paths.get(artifactToDeploy.getOutputFilePath()));
        if (!exists) {
            issues.add("The Artifact has not been built yet. You can initiate building an artifact using <b>Build | Build Artifacts...</b> menu.");
        }
        if (issues.size() > 0) {
            ArtifactValidationWindow.go(project, issues);
            return;
        }
        WebAppDeployDialog d = WebAppDeployDialog.go(project, artifactToDeploy);
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("actionPerformed", ex);
        ErrorWindow.show(project, ex.getMessage(), "Azure Web Deploy Action Error");
    }
}
Also used : WebAppDeployDialog(com.microsoft.azuretools.ijidea.ui.WebAppDeployDialog) WarSelectDialog(com.microsoft.azuretools.ijidea.ui.WarSelectDialog) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) LinkedList(java.util.LinkedList) Project(com.intellij.openapi.project.Project) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel)

Example 4 with ModifiableArtifactModel

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

the class ArtifactCompilerTestCase method deleteArtifact.

protected void deleteArtifact(final Artifact artifact) {
    final ModifiableArtifactModel model = getArtifactManager().createModifiableModel();
    model.removeArtifact(artifact);
    commitModel(model);
}
Also used : ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel)

Example 5 with ModifiableArtifactModel

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

the class ModulesConfigurator method addModule.

@Nullable
public List<Module> addModule(Component parent, boolean anImport) {
    if (myProject.isDefault())
        return null;
    final ProjectBuilder builder = runModuleWizard(parent, anImport);
    if (builder != null) {
        final List<Module> modules = new ArrayList<>();
        final List<Module> committedModules;
        if (builder instanceof ProjectImportBuilder<?>) {
            final ModifiableArtifactModel artifactModel = ProjectStructureConfigurable.getInstance(myProject).getArtifactsStructureConfigurable().getModifiableArtifactModel();
            committedModules = ((ProjectImportBuilder<?>) builder).commit(myProject, myModuleModel, this, artifactModel);
        } else {
            committedModules = builder.commit(myProject, myModuleModel, this);
        }
        if (committedModules != null) {
            modules.addAll(committedModules);
        }
        ApplicationManager.getApplication().runWriteAction(() -> {
            for (Module module : modules) {
                getOrCreateModuleEditor(module);
            }
        });
        return modules;
    }
    return null;
}
Also used : ProjectBuilder(com.intellij.ide.util.projectWizard.ProjectBuilder) ProjectImportBuilder(com.intellij.projectImport.ProjectImportBuilder) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)7 Project (com.intellij.openapi.project.Project)3 Module (com.intellij.openapi.module.Module)2 ProjectImportBuilder (com.intellij.projectImport.ProjectImportBuilder)2 Nullable (org.jetbrains.annotations.Nullable)2 ProjectBuilder (com.intellij.ide.util.projectWizard.ProjectBuilder)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationNamesInfo (com.intellij.openapi.application.ApplicationNamesInfo)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1 FileChooser (com.intellij.openapi.fileChooser.FileChooser)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1 ModuleManagerImpl (com.intellij.openapi.module.impl.ModuleManagerImpl)1