use of com.intellij.packaging.impl.elements.ArchivePackagingElement in project intellij-community by JetBrains.
the class JavaFxChunkBuildExtension method generateTasksForArtifact.
@Override
public void generateTasksForArtifact(Artifact artifact, boolean preprocessing, ArtifactAntGenerationContext context, CompositeGenerator generator) {
if (preprocessing)
return;
if (!(artifact.getArtifactType() instanceof JavaFxApplicationArtifactType))
return;
final CompositePackagingElement<?> rootElement = artifact.getRootElement();
final List<PackagingElement<?>> children = new ArrayList<>();
String artifactFileName = rootElement.getName();
for (PackagingElement<?> child : rootElement.getChildren()) {
if (child instanceof ArchivePackagingElement) {
artifactFileName = ((ArchivePackagingElement) child).getArchiveFileName();
children.addAll(((ArchivePackagingElement) child).getChildren());
} else {
children.add(child);
}
}
final String artifactName = FileUtil.getNameWithoutExtension(artifactFileName);
final String tempDirPath = BuildProperties.propertyRef(context.createNewTempFileProperty("artifact.temp.output." + artifactName, artifactFileName));
final PackagingElementResolvingContext resolvingContext = ArtifactManager.getInstance(context.getProject()).getResolvingContext();
for (Generator childGenerator : computeChildrenGenerators(resolvingContext, new DirectoryAntCopyInstructionCreator(tempDirPath), context, artifact.getArtifactType(), children)) {
generator.add(childGenerator);
}
final JavaFxArtifactProperties properties = (JavaFxArtifactProperties) artifact.getProperties(JavaFxArtifactPropertiesProvider.getInstance());
final JavaFxArtifactProperties.JavaFxPackager javaFxPackager = new JavaFxArtifactProperties.JavaFxPackager(artifact, properties, context.getProject()) {
@Override
protected void registerJavaFxPackagerError(String message) {
}
};
final String tempDirDeployPath = tempDirPath + "/deploy";
final List<JavaFxAntGenerator.SimpleTag> tags = JavaFxAntGenerator.createJarAndDeployTasks(javaFxPackager, artifactFileName, artifact.getName(), tempDirPath, tempDirDeployPath, context.getProject().getBasePath());
for (JavaFxAntGenerator.SimpleTag tag : tags) {
buildTags(generator, tag);
}
if (properties.isEnabledSigning()) {
final boolean selfSigning = properties.isSelfSigning();
String vendor = properties.getVendor();
if (vendor != null) {
vendor = vendor.replaceAll(",", "\\\\,");
}
generator.add(new Property(artifactBasedProperty(ARTIFACT_VENDOR_SIGN_PROPERTY, artifactName), "CN=" + vendor));
final String alias = selfSigning ? "jb" : properties.getAlias();
generator.add(new Property(artifactBasedProperty(ARTIFACT_ALIAS_SIGN_PROPERTY, artifactName), alias));
final String keystore = selfSigning ? tempDirPath + File.separator + "jb-key.jks" : properties.getKeystore();
generator.add(new Property(artifactBasedProperty(ARTIFACT_KEYSTORE_SIGN_PROPERTY, artifactName), keystore));
final String storepass = selfSigning ? "storepass" : new String(Base64.getDecoder().decode(properties.getStorepass()), StandardCharsets.UTF_8);
generator.add(new Property(artifactBasedProperty(ARTIFACT_STOREPASS_SIGN_PROPERTY, artifactName), storepass));
final String keypass = selfSigning ? "keypass" : new String(Base64.getDecoder().decode(properties.getKeypass()), StandardCharsets.UTF_8);
generator.add(new Property(artifactBasedProperty(ARTIFACTKEYPASS_SIGN_PROPERTY, artifactName), keypass));
final Pair[] keysDescriptions = createKeysDescriptions(artifactName);
if (selfSigning) {
generator.add(new Tag("genkey", ArrayUtil.prepend(Couple.of("dname", BuildProperties.propertyRef(artifactBasedProperty(ARTIFACT_VENDOR_SIGN_PROPERTY, artifactName))), keysDescriptions)));
}
final Tag signjar = new Tag("signjar", keysDescriptions);
final Tag fileset = new Tag("fileset", Couple.of("dir", tempDirDeployPath));
fileset.add(new Tag("include", Couple.of("name", "*.jar")));
signjar.add(fileset);
generator.add(signjar);
}
final DirectoryAntCopyInstructionCreator creator = new DirectoryAntCopyInstructionCreator(BuildProperties.propertyRef(context.getConfiguredArtifactOutputProperty(artifact)));
generator.add(creator.createDirectoryContentCopyInstruction(tempDirDeployPath));
final Tag deleteTag = new Tag("delete", Couple.of("includeemptydirs", "true"));
deleteTag.add(new Tag("fileset", Couple.of("dir", tempDirPath)));
generator.add(deleteTag);
}
use of com.intellij.packaging.impl.elements.ArchivePackagingElement in project intellij-community by JetBrains.
the class PackageFileWorker method copyFile.
private void copyFile(String outputPath, List<CompositePackagingElement<?>> parents) throws IOException {
if (parents.isEmpty()) {
final String fullOutputPath = DeploymentUtil.appendToPath(outputPath, myRelativeOutputPath);
File target = new File(fullOutputPath);
if (FileUtil.filesEqual(myFile, target)) {
LOG.debug(" skipping copying file to itself");
} else {
LOG.debug(" copying to " + fullOutputPath);
FileUtil.copy(myFile, target);
}
return;
}
final CompositePackagingElement<?> element = parents.get(0);
final String nextOutputPath = outputPath + "/" + element.getName();
final List<CompositePackagingElement<?>> parentsTrail = parents.subList(1, parents.size());
if (element instanceof ArchivePackagingElement) {
if (myPackIntoArchives) {
packFile(nextOutputPath, "", parentsTrail);
}
} else {
copyFile(nextOutputPath, parentsTrail);
}
}
use of com.intellij.packaging.impl.elements.ArchivePackagingElement in project intellij-community by JetBrains.
the class PackageFileWorker method packFile.
private void packFile(String archivePath, String pathInArchive, List<CompositePackagingElement<?>> parents) throws IOException {
final File archiveFile = new File(archivePath);
if (parents.isEmpty()) {
LOG.debug(" adding to archive " + archivePath);
JBZipFile file = getOrCreateZipFile(archiveFile);
try {
final String fullPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, myRelativeOutputPath));
final JBZipEntry entry = file.getOrCreateEntry(fullPathInArchive);
entry.setData(FileUtil.loadFileBytes(myFile));
} finally {
file.close();
}
return;
}
final CompositePackagingElement<?> element = parents.get(0);
final String nextPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, element.getName()));
final List<CompositePackagingElement<?>> parentsTrail = parents.subList(1, parents.size());
if (element instanceof ArchivePackagingElement) {
JBZipFile zipFile = getOrCreateZipFile(archiveFile);
try {
final JBZipEntry entry = zipFile.getOrCreateEntry(nextPathInArchive);
LOG.debug(" extracting to temp file: " + nextPathInArchive + " from " + archivePath);
final File tempFile = FileUtil.createTempFile("packageFile" + FileUtil.sanitizeFileName(nextPathInArchive), FileUtilRt.getExtension(PathUtil.getFileName(nextPathInArchive)));
if (entry.getSize() != -1) {
FileUtil.writeToFile(tempFile, entry.getData());
}
packFile(FileUtil.toSystemIndependentName(tempFile.getAbsolutePath()), "", parentsTrail);
entry.setData(FileUtil.loadFileBytes(tempFile));
FileUtil.delete(tempFile);
} finally {
zipFile.close();
}
} else {
packFile(archivePath, nextPathInArchive, parentsTrail);
}
}
Aggregations