use of com.intellij.packaging.artifacts.Artifact 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();
}
}
use of com.intellij.packaging.artifacts.Artifact in project intellij-community by JetBrains.
the class BuildArtifactsBeforeRunTaskProvider method getTaskIcon.
@Override
public Icon getTaskIcon(BuildArtifactsBeforeRunTask task) {
List<ArtifactPointer> pointers = task.getArtifactPointers();
if (pointers == null || pointers.isEmpty())
return getIcon();
Artifact artifact = pointers.get(0).getArtifact();
if (artifact == null)
return getIcon();
return artifact.getArtifactType().getIcon();
}
use of com.intellij.packaging.artifacts.Artifact in project intellij-community by JetBrains.
the class PackageFileAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
final List<VirtualFile> files = getFilesToPackage(event, project);
Artifact[] allArtifacts = ArtifactManager.getInstance(project).getArtifacts();
PackageFileWorker.startPackagingFiles(project, files, allArtifacts, () -> setStatusText(project, files));
}
use of com.intellij.packaging.artifacts.Artifact in project intellij-community by JetBrains.
the class ArtifactsGenerator method generate.
public List<Generator> generate() {
final List<Generator> generators = new ArrayList<>();
final Target initTarget = new Target(INIT_ARTIFACTS_TARGET, null, null, null);
generators.add(initTarget);
initTarget.add(new Property(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY, BuildProperties.propertyRelativePath(BuildProperties.getProjectBaseDirProperty(), "__artifacts_temp")));
for (Artifact artifact : myAllArtifacts) {
if (!myContext.shouldBuildIntoTempDirectory(artifact)) {
generators.add(new CleanArtifactTarget(artifact, myContext));
}
final String outputPath = artifact.getOutputPath();
if (!StringUtil.isEmpty(outputPath)) {
initTarget.add(new Property(myContext.getConfiguredArtifactOutputProperty(artifact), myContext.getSubstitutedPath(outputPath)));
}
}
initTarget.add(new Mkdir(BuildProperties.propertyRef(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY)));
StringBuilder depends = new StringBuilder();
for (Artifact artifact : myAllArtifacts) {
Target target = createArtifactTarget(artifact);
generators.add(target);
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
if (depends.length() > 0)
depends.append(", ");
depends.append(myContext.getTargetName(artifact));
}
}
for (Generator generator : myContext.getBeforeBuildGenerators()) {
initTarget.add(generator);
}
initArtifacts(myResolvingContext.getProject(), initTarget);
Target buildAllArtifacts = new Target(BUILD_ALL_ARTIFACTS_TARGET, depends.toString(), "Build all artifacts", null);
for (Artifact artifact : myAllArtifacts) {
final String artifactOutputPath = artifact.getOutputPath();
if (!StringUtil.isEmpty(artifactOutputPath) && myContext.shouldBuildIntoTempDirectory(artifact)) {
final String outputPath = BuildProperties.propertyRef(myContext.getConfiguredArtifactOutputProperty(artifact));
buildAllArtifacts.add(new Mkdir(outputPath));
final Copy copy = new Copy(outputPath);
copy.add(new FileSet(BuildProperties.propertyRef(myContext.getArtifactOutputProperty(artifact))));
buildAllArtifacts.add(copy);
}
}
buildAllArtifacts.add(new Comment("Delete temporary files"), 1);
for (Generator generator : myContext.getAfterBuildGenerators()) {
buildAllArtifacts.add(generator);
}
buildAllArtifacts.add(new Delete(BuildProperties.propertyRef(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY)));
generators.add(buildAllArtifacts);
return generators;
}
use of com.intellij.packaging.artifacts.Artifact 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;
}
Aggregations