Tinybundles 3.0.0 с использованием BND удаляет завершающее определение пакета с подстановочными знаками ",*" из Import-Packages. Это определение больше не нужно?
Я обновляю зависимость tinybundles с 1.0.0 до 3.0.0. В основном он работает практически без рефакторинга (просто изменяя оператор импорта), но есть одно изменение, которое непоследовательно, а именно то, что Tinybundles (или, скорее, bndlib 3.5.0) удаляет все завершающие,*
определения пакетов с подстановочными знаками из конца определения Import-Package. Например, вот код, который мы используем для создания пакета из файлов, загруженных пользователем:
/** Name of blueprint files to be generated. */
private static final String BLUEPRINT_FILENAME = "blueprint.xml";
/**
* Velocity template for generating a scripting phase blueprint.xml
* (currently stored under mail/templates directory)
*/
private static final String TEMPLATE_BLUEPRINT_SCRIPTING = "blueprint_scripting";
/**Correct Constants.BUNDLE_BLUEPRINT bnd constant which wrongly outputs Bundle-Copyright. */
private static final String BUNDLE_BLUEPRINT = "Bundle-Blueprint";
/** Value for the Import-Packages header of a scripting phase bundle. */
private static final String IMPORT_PACKAGES_SCRIPTING_PHASE = "phases.scripting.impl,phases.spi,*";
public File generateBundleScriptingPhase(String sourceLocation, String targetLocation,String phaseDisplayName, String phaseName,
String phaseVersion) throws ValidationException {
//Initiate the bundle
TinyBundle bundle = bundle();
// all uploaded resources in the source location (scripts, properties, etc) and the blueprint.xml
// must be added by using the "Include Resource" bundle header (from bnd) in order to include them in the generated bundle
File sourceDir = new File(sourceLocation);
File targetDir = new File(targetLocation);
Collection<File> sourceDirFiles = FileUtils.listFiles(sourceDir, null,true);
StringBuilder relativePathBuilder = new StringBuilder();
String targetJarFilePath = targetLocation + "/" + phaseName + "-" + phaseVersion + ".jar";
try {
boolean firstPath = true;
for (File file : sourceDirFiles) {
URL fileUrl = file.toURI().toURL();
String relativePath = file.getPath().substring(sourceLocation.length() + 1);
// convert back slashes to forward ones: needed by OSGI
relativePath = util.fileutils.FileUtils.separatorsToUnix(relativePath);
LOGGER.debug("Include-Resource header: adding resource with name=" + relativePath
+ ",URL=" + fileUrl);
bundle.add(relativePath, fileUrl);
if (!firstPath) {
relativePathBuilder.append(",");
}
relativePathBuilder.append(relativePath).append("=").append(relativePath);
firstPath = false;
}
// set all the relative resource paths as the value of the Include-Resource instruction
bundle.set(Constants.INCLUDE_RESOURCE, relativePathBuilder.toString());
// set all other Bundle Headers
bundle.set(Constants.BUNDLE_VERSION , phaseVersion);
bundle.set(Constants.BUNDLE_NAME, phaseDisplayName);
bundle.set(Constants.BUNDLE_SYMBOLICNAME , phaseName);
bundle.set(Constants.PRIVATE_PACKAGE, "");
bundle.set(Constants.IMPORT_PACKAGE , IMPORT_PACKAGES_SCRIPTING_PHASE);
//Constants.BUNDLE_BLUEPRINT bnd constant wrongly prints Bundle-Copyright, so made internal constant
bundle.set(BUNDLE_BLUEPRINT, "OSGI-INF" + "/" + BLUEPRINT_FILENAME);
// create the bundle as an inputstream with tinybundles and bnd
InputStream outputBundleJarInputStream = bundle.build(withBnd());
// Create the location if it does not exist
// if the target directory does not exist, create it
if (!targetDir.exists()) {
FileUtils.forceMkdir(targetDir);
}
// write the bundle jar
writeJar(outputBundleJarInputStream, targetJarFilePath);
} catch (IOException e) {
LOGGER.error("IOException while writing the bundle for the scripting phase bundle");
LOGGER.error(e);
Collection<ValidationAnnotation> annotations = new ArrayList<ValidationAnnotation>();
annotations.add(new ValidationAnnotation(MessageKeys.GLOBAL_ERROR,MessageKeys.ERROR_GENERATING_PHASE_BUNDLE,
new Object[] { e.getMessage() }));
throw new ValidationException(annotations);
} finally {
//delete temp file created by tinybundles, from java.io.tmpdir
String iotempdir = System.getProperty("java.io.tmpdir");
File dir = new File(iotempdir);
//we do not know the exact name of the temp tinybundles jar, so use wildcardfilter
FileFilter fileFilter = new WildcardFileFilter("mylitte*jar");
File[] files = dir.listFiles(fileFilter);
try {
for (int i = 0; i < files.length; i++) {
util.fileutils.FileUtils.deleteFile(files[i]);
}
} catch (IOException e) {
LOGGER.error("IOException while cleaning up temporary files for generating a scripting phase bundle");
LOGGER.error(e);
}
}
return new File(targetJarFilePath);
}
Этот код создает пакет, и он по-прежнему работает для создания этого пакета как до, так и после обновления зависимости, но Import-Package больше не имеет ,*
в конце оператора Import-Package, который я явно поместил в свой оператор import-packages. Я не знаю, если это,*
все еще необходимо. Это,*
все еще необходимо? Если это все еще необходимо в некоторых ситуациях, как я могу его повторно ввести?