mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
separate 'build artifact' menu items replaced by 'build artifacts' dialog
This commit is contained in:
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2009 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.intellij.compiler.actions;
|
|
||||||
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
|
||||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
|
||||||
import com.intellij.openapi.compiler.CompilerManager;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
|
||||||
import com.intellij.packaging.artifacts.Artifact;
|
|
||||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
|
||||||
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author nik
|
|
||||||
*/
|
|
||||||
public class BuildAllArtifactsAction extends AnAction {
|
|
||||||
public BuildAllArtifactsAction() {
|
|
||||||
super("Build All Artifacts", "Build all configured artifacts", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(AnActionEvent e) {
|
|
||||||
e.getPresentation().setEnabled(e.getData(PlatformDataKeys.PROJECT) != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(AnActionEvent e) {
|
|
||||||
final Project project = e.getData(PlatformDataKeys.PROJECT);
|
|
||||||
if (project == null) return;
|
|
||||||
|
|
||||||
List<Artifact> toBuild = new ArrayList<Artifact>();
|
|
||||||
for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) {
|
|
||||||
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
|
|
||||||
toBuild.add(artifact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CompilerManager.getInstance(project).make(ArtifactCompileScope.createArtifactsScope(project, toBuild), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,54 +17,86 @@ package com.intellij.compiler.actions;
|
|||||||
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||||
|
import com.intellij.openapi.actionSystem.Presentation;
|
||||||
|
import com.intellij.openapi.compiler.CompilerManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDialog;
|
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import com.intellij.openapi.application.WriteAction;
|
|
||||||
import com.intellij.openapi.application.Result;
|
|
||||||
import com.intellij.openapi.compiler.CompilerManager;
|
|
||||||
import com.intellij.openapi.compiler.CompilerBundle;
|
|
||||||
import com.intellij.packaging.artifacts.Artifact;
|
import com.intellij.packaging.artifacts.Artifact;
|
||||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
import com.intellij.packaging.artifacts.ArtifactManager;
|
||||||
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
|
|
||||||
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
|
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
|
||||||
|
import com.intellij.packaging.impl.compiler.ArtifactsWorkspaceSettings;
|
||||||
|
import com.intellij.packaging.impl.ui.ChooseArtifactsDialog;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nik
|
* @author nik
|
||||||
*/
|
*/
|
||||||
public class BuildArtifactAction extends AnAction {
|
public class BuildArtifactAction extends AnAction {
|
||||||
private final Project myProject;
|
public BuildArtifactAction() {
|
||||||
private Artifact myArtifact;
|
super("Build Artifact");
|
||||||
|
}
|
||||||
|
|
||||||
public BuildArtifactAction(Project project, Artifact artifact) {
|
@Override
|
||||||
super(artifact.getName(), "Build Artifact '" + artifact.getName() + "'", artifact.getArtifactType().getIcon());
|
public void update(AnActionEvent e) {
|
||||||
myProject = project;
|
final Project project = e.getData(PlatformDataKeys.PROJECT);
|
||||||
myArtifact = artifact;
|
final Presentation presentation = e.getPresentation();
|
||||||
|
presentation.setEnabled(false);
|
||||||
|
if (project == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final List<Artifact> artifacts = getArtifactWithOutputPaths(project);
|
||||||
|
if (artifacts.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
presentation.setEnabled(true);
|
||||||
|
if (artifacts.size() == 1) {
|
||||||
|
presentation.setText("Build '" + StringUtil.first(artifacts.get(0).getName(), 40, true) + "' artifact");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
presentation.setText("Build Artifacts...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Artifact> getArtifactWithOutputPaths(Project project) {
|
||||||
|
final List<Artifact> result = new ArrayList<Artifact>();
|
||||||
|
for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) {
|
||||||
|
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
|
||||||
|
result.add(artifact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed(AnActionEvent e) {
|
public void actionPerformed(AnActionEvent e) {
|
||||||
final String outputPath = myArtifact.getOutputPath();
|
final Project project = e.getData(PlatformDataKeys.PROJECT);
|
||||||
if (StringUtil.isEmpty(outputPath)) {
|
if (project == null) return;
|
||||||
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
|
||||||
descriptor.setTitle(CompilerBundle.message("dialog.title.output.directory.for.artifact"));
|
final List<Artifact> artifacts = getArtifactWithOutputPaths(project);
|
||||||
descriptor.setDescription(CompilerBundle.message("chooser.description.select.output.directory.for.0.artifact", myArtifact.getName()));
|
if (artifacts.isEmpty()) return;
|
||||||
final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, myProject);
|
|
||||||
final VirtualFile[] files = chooser.choose(null, myProject);
|
if (artifacts.size() == 1) {
|
||||||
if (files.length != 1) return;
|
buildArtifacts(project, artifacts);
|
||||||
final ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel();
|
return;
|
||||||
model.getOrCreateModifiableArtifact(myArtifact).setOutputPath(files[0].getPath());
|
|
||||||
new WriteAction() {
|
|
||||||
protected void run(final Result result) {
|
|
||||||
model.commit();
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
}
|
||||||
CompilerManager.getInstance(myProject).make(ArtifactCompileScope.createArtifactsScope(myProject, Collections.singletonList(myArtifact)), null);
|
|
||||||
|
final ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(project, artifacts, "Choose Artifacts to Build", "Selected artifacts will be built with all dependencies");
|
||||||
|
final List<Artifact> initialSelection = ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild();
|
||||||
|
if (!initialSelection.isEmpty()) {
|
||||||
|
dialog.selectElements(initialSelection);
|
||||||
|
}
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
|
if (dialog.isOK()) {
|
||||||
|
final List<Artifact> selected = dialog.getChosenElements();
|
||||||
|
ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(selected);
|
||||||
|
buildArtifacts(project, selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void buildArtifacts(Project project, final List<Artifact> artifacts) {
|
||||||
|
CompilerManager.getInstance(project).make(ArtifactCompileScope.createArtifactsScope(project, artifacts), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2009 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.intellij.compiler.actions;
|
|
||||||
|
|
||||||
import com.intellij.openapi.actionSystem.*;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
|
||||||
import com.intellij.packaging.artifacts.Artifact;
|
|
||||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author nik
|
|
||||||
*/
|
|
||||||
public class BuildArtifactActionGroup extends ActionGroup {
|
|
||||||
public BuildArtifactActionGroup() {
|
|
||||||
super("Build Artifact", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public AnAction[] getChildren(@Nullable AnActionEvent e) {
|
|
||||||
if (e == null) return EMPTY_ARRAY;
|
|
||||||
final Project project = e.getData(PlatformDataKeys.PROJECT);
|
|
||||||
if (project == null) return EMPTY_ARRAY;
|
|
||||||
|
|
||||||
final Artifact[] artifacts = ArtifactManager.getInstance(project).getSortedArtifacts();
|
|
||||||
List<AnAction> actions = new ArrayList<AnAction>();
|
|
||||||
for (Artifact artifact : artifacts) {
|
|
||||||
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
|
|
||||||
actions.add(new BuildArtifactAction(project, artifact));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (actions.size() > 1) {
|
|
||||||
actions.add(0, new BuildAllArtifactsAction());
|
|
||||||
actions.add(1, Separator.getInstance());
|
|
||||||
}
|
|
||||||
return actions.toArray(new AnAction[actions.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2010 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.intellij.packaging.impl.compiler;
|
||||||
|
|
||||||
|
import com.intellij.openapi.components.PersistentStateComponent;
|
||||||
|
import com.intellij.openapi.components.ServiceManager;
|
||||||
|
import com.intellij.openapi.components.State;
|
||||||
|
import com.intellij.openapi.components.Storage;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.packaging.artifacts.Artifact;
|
||||||
|
import com.intellij.packaging.artifacts.ArtifactManager;
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
|
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||||
|
import com.intellij.util.xmlb.annotations.Tag;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author nik
|
||||||
|
*/
|
||||||
|
@State(name = "ArtifactsWorkspaceSettings",
|
||||||
|
storages = {
|
||||||
|
@Storage(id = "other", file = "$WORKSPACE_FILE$")
|
||||||
|
})
|
||||||
|
public class ArtifactsWorkspaceSettings implements PersistentStateComponent<ArtifactsWorkspaceSettings.ArtifactsWorkspaceSettingsState> {
|
||||||
|
private ArtifactsWorkspaceSettingsState myState = new ArtifactsWorkspaceSettingsState();
|
||||||
|
private final Project myProject;
|
||||||
|
|
||||||
|
public ArtifactsWorkspaceSettings(Project project) {
|
||||||
|
myProject = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArtifactsWorkspaceSettings getInstance(@NotNull Project project) {
|
||||||
|
return ServiceManager.getService(project, ArtifactsWorkspaceSettings.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Artifact> getArtifactsToBuild() {
|
||||||
|
final List<Artifact> result = new ArrayList<Artifact>();
|
||||||
|
final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);
|
||||||
|
for (String name : myState.myArtifactsToBuild) {
|
||||||
|
ContainerUtil.addIfNotNull(artifactManager.findArtifact(name), result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtifactsToBuild(@NotNull Collection<? extends Artifact> artifacts) {
|
||||||
|
myState.myArtifactsToBuild.clear();
|
||||||
|
for (Artifact artifact : artifacts) {
|
||||||
|
myState.myArtifactsToBuild.add(artifact.getName());
|
||||||
|
}
|
||||||
|
Collections.sort(myState.myArtifactsToBuild);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactsWorkspaceSettingsState getState() {
|
||||||
|
return myState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadState(ArtifactsWorkspaceSettingsState state) {
|
||||||
|
myState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ArtifactsWorkspaceSettingsState {
|
||||||
|
@Tag("artifacts-to-build")
|
||||||
|
@AbstractCollection(surroundWithTag = false, elementTag = "artifact", elementValueAttribute = "name")
|
||||||
|
public List<String> myArtifactsToBuild = new ArrayList<String>();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.intellij.openapi.roots.ui.configuration.artifacts;
|
package com.intellij.packaging.impl.ui;
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.ide.util.ChooseElementsDialog;
|
import com.intellij.ide.util.ChooseElementsDialog;
|
||||||
+1
@@ -37,6 +37,7 @@ import com.intellij.packaging.artifacts.ArtifactModel;
|
|||||||
import com.intellij.packaging.artifacts.ArtifactType;
|
import com.intellij.packaging.artifacts.ArtifactType;
|
||||||
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
|
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
|
||||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||||
|
import com.intellij.packaging.impl.ui.ChooseArtifactsDialog;
|
||||||
import com.intellij.packaging.ui.ArtifactEditor;
|
import com.intellij.packaging.ui.ArtifactEditor;
|
||||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||||
import com.intellij.packaging.ui.ManifestFileConfiguration;
|
import com.intellij.packaging.ui.ManifestFileConfiguration;
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ public abstract class ChooseElementsDialog<T> extends DialogWrapper {
|
|||||||
return myChooser.getSelectedElements();
|
return myChooser.getSelectedElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void selectElements(@NotNull List<T> elements) {
|
||||||
|
myChooser.selectElements(elements);
|
||||||
|
}
|
||||||
|
|
||||||
public JComponent getPreferredFocusedComponent() {
|
public JComponent getPreferredFocusedComponent() {
|
||||||
return myChooser.getComponent();
|
return myChooser.getComponent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,6 +370,9 @@
|
|||||||
<projectService serviceInterface="com.intellij.psi.controlFlow.ControlFlowFactory"
|
<projectService serviceInterface="com.intellij.psi.controlFlow.ControlFlowFactory"
|
||||||
serviceImplementation="com.intellij.psi.controlFlow.ControlFlowFactory"/>
|
serviceImplementation="com.intellij.psi.controlFlow.ControlFlowFactory"/>
|
||||||
|
|
||||||
|
<projectService serviceInterface="com.intellij.packaging.impl.compiler.ArtifactsWorkspaceSettings"
|
||||||
|
serviceImplementation="com.intellij.packaging.impl.compiler.ArtifactsWorkspaceSettings"/>
|
||||||
|
|
||||||
<projectService serviceInterface="com.intellij.compiler.CompilerWorkspaceConfiguration"
|
<projectService serviceInterface="com.intellij.compiler.CompilerWorkspaceConfiguration"
|
||||||
serviceImplementation="com.intellij.compiler.CompilerWorkspaceConfiguration"/>
|
serviceImplementation="com.intellij.compiler.CompilerWorkspaceConfiguration"/>
|
||||||
|
|
||||||
|
|||||||
@@ -186,8 +186,6 @@
|
|||||||
<add-to-group group-id="RefactoringMenu" anchor="after" relative-to-action="ReplaceMethodWithMethodObject"/>
|
<add-to-group group-id="RefactoringMenu" anchor="after" relative-to-action="ReplaceMethodWithMethodObject"/>
|
||||||
</action>
|
</action>
|
||||||
|
|
||||||
<action id="BuildAllArtifacts" class="com.intellij.compiler.actions.BuildAllArtifactsAction"/>
|
|
||||||
|
|
||||||
<group id="BuildMenu" popup="true">
|
<group id="BuildMenu" popup="true">
|
||||||
<action id="CompileDirty" class="com.intellij.compiler.actions.CompileDirtyAction" icon="/actions/compile.png"/>
|
<action id="CompileDirty" class="com.intellij.compiler.actions.CompileDirtyAction" icon="/actions/compile.png"/>
|
||||||
<action id="MakeModule" class="com.intellij.compiler.actions.MakeModuleAction"/>
|
<action id="MakeModule" class="com.intellij.compiler.actions.MakeModuleAction"/>
|
||||||
@@ -198,7 +196,7 @@
|
|||||||
<separator/>
|
<separator/>
|
||||||
<action id="GenerateAntBuild" class="com.intellij.compiler.actions.GenerateAntBuildAction"/>
|
<action id="GenerateAntBuild" class="com.intellij.compiler.actions.GenerateAntBuildAction"/>
|
||||||
<separator/>
|
<separator/>
|
||||||
<group id="BuildArtifactsGroup" class="com.intellij.compiler.actions.BuildArtifactActionGroup"/>
|
<action id="BuildArtifact" class="com.intellij.compiler.actions.BuildArtifactAction"/>
|
||||||
|
|
||||||
<add-to-group group-id="MainMenu" anchor="before" relative-to-action="RunMenu"/>
|
<add-to-group group-id="MainMenu" anchor="before" relative-to-action="RunMenu"/>
|
||||||
</group>
|
</group>
|
||||||
|
|||||||
Reference in New Issue
Block a user