use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.
the class ArtifactsGenerator method createArtifactTarget.
private Target createArtifactTarget(Artifact artifact) {
final StringBuilder depends = new StringBuilder(INIT_ARTIFACTS_TARGET);
ArtifactUtil.processRecursivelySkippingIncludedArtifacts(artifact, packagingElement -> {
if (packagingElement instanceof ArtifactPackagingElement) {
final Artifact included = ((ArtifactPackagingElement) packagingElement).findArtifact(myResolvingContext);
if (included != null) {
if (depends.length() > 0)
depends.append(", ");
depends.append(myContext.getTargetName(included));
}
} else if (packagingElement instanceof ModuleOutputPackagingElement) {
final Module module = ((ModuleOutputPackagingElement) packagingElement).findModule(myResolvingContext);
if (module != null) {
if (depends.length() > 0)
depends.append(", ");
depends.append(BuildProperties.getCompileTargetName(module.getName()));
}
}
return true;
}, myResolvingContext);
final Couple<String> xmlNs = getArtifactXmlNs(artifact.getArtifactType());
final Target artifactTarget = new Target(myContext.getTargetName(artifact), depends.toString(), "Build '" + artifact.getName() + "' artifact", null, xmlNs != null ? xmlNs.first : null, xmlNs != null ? xmlNs.second : null);
if (myContext.shouldBuildIntoTempDirectory(artifact)) {
final String outputDirectory = BuildProperties.propertyRelativePath(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY, FileUtil.sanitizeFileName(artifact.getName()));
artifactTarget.add(new Property(myContext.getArtifactOutputProperty(artifact), outputDirectory));
}
final String outputPath = BuildProperties.propertyRef(myContext.getArtifactOutputProperty(artifact));
artifactTarget.add(new Mkdir(outputPath));
generateTasksForArtifacts(artifact, artifactTarget, true);
final DirectoryAntCopyInstructionCreator creator = new DirectoryAntCopyInstructionCreator(outputPath);
List<Generator> copyInstructions = new ArrayList<>();
if (needAntArtifactInstructions(artifact.getArtifactType())) {
copyInstructions.addAll(artifact.getRootElement().computeAntInstructions(myResolvingContext, creator, myContext, artifact.getArtifactType()));
}
for (Generator generator : myContext.getAndClearBeforeCurrentArtifact()) {
artifactTarget.add(generator);
}
for (Generator tag : copyInstructions) {
artifactTarget.add(tag);
}
generateTasksForArtifacts(artifact, artifactTarget, false);
return artifactTarget;
}
use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.
the class InlineArtifactAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final LayoutTreeComponent treeComponent = myEditor.getLayoutTreeComponent();
final LayoutTreeSelection selection = treeComponent.getSelection();
final PackagingElement<?> element = selection.getElementIfSingle();
final PackagingElementNode<?> node = selection.getNodeIfSingle();
if (node == null || !(element instanceof ArtifactPackagingElement))
return;
final CompositePackagingElement<?> parent = node.getParentElement(element);
final CompositePackagingElementNode parentNode = node.getParentNode();
if (parent == null || parentNode == null) {
return;
}
if (!treeComponent.checkCanModifyChildren(parent, parentNode, Collections.singletonList(node)))
return;
treeComponent.editLayout(() -> {
parent.removeChild(element);
final ArtifactEditorContext context = myEditor.getContext();
final Artifact artifact = ((ArtifactPackagingElement) element).findArtifact(context);
if (artifact != null) {
final CompositePackagingElement<?> rootElement = artifact.getRootElement();
if (rootElement instanceof ArtifactRootElement<?>) {
for (PackagingElement<?> child : rootElement.getChildren()) {
parent.addOrFindChild(ArtifactUtil.copyWithChildren(child, context.getProject()));
}
} else {
parent.addOrFindChild(ArtifactUtil.copyWithChildren(rootElement, context.getProject()));
}
}
});
treeComponent.rebuildTree();
}
use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.
the class ExtractArtifactAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
final LayoutTreeSelection selection = treeComponent.getSelection();
final CompositePackagingElement<?> parent = selection.getCommonParentElement();
if (parent == null)
return;
final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
if (parentNode == null)
return;
if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
return;
}
final Collection<? extends PackagingElement> selectedElements = selection.getElements();
String initialName = "artifact";
if (selectedElements.size() == 1) {
initialName = PathUtil.suggestFileName(ContainerUtil.getFirstItem(selectedElements, null).createPresentation(myArtifactEditor.getContext()).getPresentableName());
}
IExtractArtifactDialog dialog = showDialog(treeComponent, initialName);
if (dialog == null)
return;
final Project project = myArtifactEditor.getContext().getProject();
final ModifiableArtifactModel model = myArtifactEditor.getContext().getOrCreateModifiableArtifactModel();
final ModifiableArtifact artifact = model.addArtifact(dialog.getArtifactName(), dialog.getArtifactType());
treeComponent.editLayout(() -> {
for (PackagingElement<?> element : selectedElements) {
artifact.getRootElement().addOrFindChild(ArtifactUtil.copyWithChildren(element, project));
}
for (PackagingElement element : selectedElements) {
parent.removeChild(element);
}
parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact, myArtifactEditor.getContext().getArtifactModel())));
});
treeComponent.rebuildTree();
}
use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.
the class InlineArtifactAction method update.
@Override
public void update(AnActionEvent e) {
final LayoutTreeSelection selection = myEditor.getLayoutTreeComponent().getSelection();
final PackagingElementNode<?> node = selection.getNodeIfSingle();
PackagingElement<?> element = selection.getElementIfSingle();
e.getPresentation().setEnabled(element instanceof ArtifactPackagingElement && node != null && node.getParentElement(element) != null);
}
use of com.intellij.packaging.impl.elements.ArtifactPackagingElement in project intellij-community by JetBrains.
the class ArtifactExternalDependenciesImporterImpl method applyChanges.
@Override
public void applyChanges(ModifiableArtifactModel artifactModel, final PackagingElementResolvingContext context) {
myManifestFiles.saveManifestFiles();
final List<Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>>> elementsToInclude = new ArrayList<>();
for (Artifact artifact : artifactModel.getArtifacts()) {
ArtifactUtil.processPackagingElements(artifact, ArtifactElementType.ARTIFACT_ELEMENT_TYPE, new PackagingElementProcessor<ArtifactPackagingElement>() {
@Override
public boolean process(@NotNull ArtifactPackagingElement artifactPackagingElement, @NotNull PackagingElementPath path) {
final Artifact included = artifactPackagingElement.findArtifact(context);
final CompositePackagingElement<?> parent = path.getLastParent();
if (parent != null && included != null) {
final List<PackagingElement<?>> elements = myExternalDependencies.get(included);
if (elements != null) {
elementsToInclude.add(Pair.create(parent, elements));
}
}
return true;
}
}, context, false);
}
for (Pair<? extends CompositePackagingElement<?>, List<PackagingElement<?>>> pair : elementsToInclude) {
pair.getFirst().addOrFindChildren(pair.getSecond());
}
}
Aggregations