use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.
the class PutSourceItemIntoDefaultLocationAction method update.
@Override
public void update(AnActionEvent e) {
final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
boolean enabled = false;
final Presentation presentation = e.getPresentation();
if (!items.isEmpty()) {
enabled = true;
Set<String> paths = new HashSet<>();
for (PackagingSourceItem item : items) {
final String path = getDefaultPath(item);
if (path == null) {
enabled = false;
break;
}
paths.add(StringUtil.trimStart(StringUtil.trimEnd(path, "/"), "/"));
}
presentation.setText("Put into " + getTargetLocationText(paths));
}
presentation.setVisible(enabled);
presentation.setEnabled(enabled);
}
use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.
the class PutSourceItemIntoParentAndLinkViaManifestAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
ParentElementsInfo parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
if (parentsInfo == null) {
return;
}
final Artifact artifact = parentsInfo.getGrandparentArtifact();
final ArtifactEditorContext context = myArtifactEditor.getContext();
//todo[nik] improve
final Runnable emptyRunnable = EmptyRunnable.getInstance();
context.editLayout(artifact, emptyRunnable);
context.editLayout(parentsInfo.getParentArtifact(), emptyRunnable);
//find elements under modifiable root
parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
if (parentsInfo == null) {
return;
}
final CompositePackagingElement<?> grandParent = parentsInfo.getGrandparentElement();
final List<String> classpath = new ArrayList<>();
context.editLayout(artifact, () -> {
for (PackagingSourceItem item : items) {
final List<? extends PackagingElement<?>> elements = item.createElements(context);
grandParent.addOrFindChildren(elements);
classpath.addAll(ManifestFileUtil.getClasspathForElements(elements, context, artifact.getArtifactType()));
}
});
final ArtifactEditor parentArtifactEditor = context.getOrCreateEditor(parentsInfo.getParentArtifact());
parentArtifactEditor.addToClasspath(parentsInfo.getParentElement(), classpath);
((ArtifactEditorImpl) context.getOrCreateEditor(parentsInfo.getGrandparentArtifact())).rebuildTries();
}
use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.
the class ModulesAndLibrariesSourceItemsProvider method createClasspathItems.
@NotNull
private static Collection<? extends PackagingSourceItem> createClasspathItems(@NotNull ArtifactEditorContext editorContext, @NotNull Artifact artifact, @NotNull Module module) {
final List<PackagingSourceItem> items = new ArrayList<>();
final ModuleRootModel rootModel = editorContext.getModulesProvider().getRootModel(module);
List<Library> libraries = new ArrayList<>();
for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry;
final Library library = libraryEntry.getLibrary();
final DependencyScope scope = libraryEntry.getScope();
if (library != null && scope.isForProductionRuntime()) {
libraries.add(library);
}
}
}
for (Module toAdd : getNotAddedModules(editorContext, artifact, module)) {
items.add(new ModuleOutputSourceItem(toAdd));
}
for (Library library : getNotAddedLibraries(editorContext, artifact, libraries)) {
items.add(new LibrarySourceItem(library));
}
return items;
}
use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.
the class ExtractIntoDefaultLocationAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final String pathForClasses = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.DIRECTORIES_WITH_CLASSES);
if (pathForClasses != null) {
final List<PackagingElement<?>> extracted = new ArrayList<>();
for (PackagingSourceItem item : mySourceItemsTree.getSelectedItems()) {
final ArtifactEditorContext context = myArtifactEditor.getContext();
final List<? extends PackagingElement<?>> elements = item.createElements(context);
ArtifactUtil.processElementsWithSubstitutions(elements, context, context.getArtifactType(), PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
@Override
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
if (element instanceof FileCopyPackagingElement) {
final VirtualFile file = ((FileCopyPackagingElement) element).findFile();
if (file != null) {
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarRoot != null) {
extracted.add(PackagingElementFactory.getInstance().createExtractedDirectory(jarRoot));
}
}
}
return true;
}
});
}
myArtifactEditor.getLayoutTreeComponent().putElements(pathForClasses, extracted);
}
}
use of com.intellij.packaging.ui.PackagingSourceItem in project intellij-community by JetBrains.
the class LayoutTreeComponent method putIntoDefaultLocations.
public void putIntoDefaultLocations(@NotNull final List<? extends PackagingSourceItem> items) {
final List<PackagingElement<?>> toSelect = new ArrayList<>();
editLayout(() -> {
final CompositePackagingElement<?> rootElement = getArtifact().getRootElement();
final ArtifactType artifactType = getArtifact().getArtifactType();
for (PackagingSourceItem item : items) {
final String path = artifactType.getDefaultPathFor(item);
if (path != null) {
final CompositePackagingElement<?> parent;
if (path.endsWith(URLUtil.JAR_SEPARATOR)) {
parent = PackagingElementFactory.getInstance().getOrCreateArchive(rootElement, StringUtil.trimEnd(path, URLUtil.JAR_SEPARATOR));
} else {
parent = PackagingElementFactory.getInstance().getOrCreateDirectory(rootElement, path);
}
final List<? extends PackagingElement<?>> elements = item.createElements(myContext);
toSelect.addAll(parent.addOrFindChildren(elements));
}
}
});
myArtifactsEditor.getSourceItemsTree().rebuildTree();
updateAndSelect(myTree.getRootPackagingNode(), toSelect);
}
Aggregations