use of com.intellij.packaging.impl.artifacts.PackagingElementPath 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());
}
}
}
use of com.intellij.packaging.impl.artifacts.PackagingElementPath 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.impl.artifacts.PackagingElementPath in project intellij-community by JetBrains.
the class ArtifactProjectStructureElement method getUsagesInElement.
@Override
public List<ProjectStructureElementUsage> getUsagesInElement() {
final Artifact artifact = myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
final List<ProjectStructureElementUsage> usages = new ArrayList<>();
final CompositePackagingElement<?> rootElement = myArtifactsStructureContext.getRootElement(artifact);
ArtifactUtil.processPackagingElements(rootElement, null, new PackagingElementProcessor<PackagingElement<?>>() {
@Override
public boolean process(@NotNull PackagingElement<?> packagingElement, @NotNull PackagingElementPath path) {
ProjectStructureElement element = getProjectStructureElementFor(packagingElement, ArtifactProjectStructureElement.this.myContext, ArtifactProjectStructureElement.this.myArtifactsStructureContext);
if (element != null) {
usages.add(createUsage(packagingElement, element, path.getPathStringFrom("/", rootElement)));
}
return true;
}
}, myArtifactsStructureContext, false, artifact.getArtifactType());
return usages;
}
use of com.intellij.packaging.impl.artifacts.PackagingElementPath in project intellij-community by JetBrains.
the class ManifestFileUtil method suggestManifestFileDirectory.
@Nullable
public static VirtualFile suggestManifestFileDirectory(@NotNull CompositePackagingElement<?> root, PackagingElementResolvingContext context, ArtifactType artifactType) {
final VirtualFile metaInfDir = ArtifactUtil.findSourceFileByOutputPath(root, MANIFEST_DIR_NAME, context, artifactType);
if (metaInfDir != null) {
return metaInfDir;
}
final Ref<VirtualFile> sourceDir = Ref.create(null);
final Ref<VirtualFile> sourceFile = Ref.create(null);
ArtifactUtil.processElementsWithSubstitutions(root.getChildren(), context, artifactType, 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) {
sourceFile.set(file);
}
} else if (element instanceof DirectoryCopyPackagingElement) {
final VirtualFile file = ((DirectoryCopyPackagingElement) element).findFile();
if (file != null) {
sourceDir.set(file);
return false;
}
}
return true;
}
});
if (!sourceDir.isNull()) {
return sourceDir.get();
}
final Project project = context.getProject();
return suggestBaseDir(project, sourceFile.get());
}
use of com.intellij.packaging.impl.artifacts.PackagingElementPath 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