use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.
the class DevClassLoadingHook method findFragmentSource.
private Generation findFragmentSource(Generation hostGeneration, String cp, ClasspathManager manager, boolean fromFragment) {
if (hostGeneration != manager.getGeneration())
return hostGeneration;
File file = new File(cp);
if (!file.isAbsolute())
return hostGeneration;
FragmentClasspath[] fragCP = manager.getFragmentClasspaths();
for (int i = 0; i < fragCP.length; i++) {
BundleFile fragBase = fragCP[i].getGeneration().getBundleFile();
File fragFile = fragBase.getBaseFile();
if (fragFile != null && file.getPath().startsWith(fragFile.getPath()))
return fragCP[i].getGeneration();
}
return fromFragment ? null : hostGeneration;
}
use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.
the class SignatureBlockProcessor method process.
public SignedContentImpl process() throws IOException, InvalidKeyException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException {
BundleFile wrappedBundleFile = signedBundle.getBundleFile();
BundleEntry be = wrappedBundleFile.getEntry(META_INF_MANIFEST_MF);
if (be == null)
return createUnsignedContent();
// read all the signature block file names into a list
Enumeration<String> en = wrappedBundleFile.getEntryPaths(META_INF);
List<String> signers = new ArrayList<>(2);
while (en.hasMoreElements()) {
String name = en.nextElement();
if ((name.endsWith(DOT_DSA) || name.endsWith(DOT_RSA)) && name.indexOf('/') == name.lastIndexOf('/'))
signers.add(name);
}
// this means the jar is not signed
if (signers.size() == 0)
return createUnsignedContent();
byte[] manifestBytes = readIntoArray(be);
for (Iterator<String> iSigners = signers.iterator(); iSigners.hasNext(); ) processSigner(wrappedBundleFile, manifestBytes, iSigners.next());
// done processing now create a SingedContent to return
SignerInfo[] allSigners = signerInfos.toArray(new SignerInfo[signerInfos.size()]);
for (Iterator<Map.Entry<String, Object>> iResults = contentMDResults.entrySet().iterator(); iResults.hasNext(); ) {
Map.Entry<String, Object> entry = iResults.next();
@SuppressWarnings("unchecked") List<Object>[] value = (List<Object>[]) entry.getValue();
SignerInfo[] entrySigners = value[0].toArray(new SignerInfo[value[0].size()]);
byte[][] entryResults = value[1].toArray(new byte[value[1].size()][]);
entry.setValue(new Object[] { entrySigners, entryResults });
}
SignedContentImpl result = new SignedContentImpl(allSigners, (supportFlags & SignedBundleHook.VERIFY_RUNTIME) != 0 ? contentMDResults : null);
result.setContent(signedBundle);
result.setTSASignerInfos(tsaSignerInfos);
return result;
}
use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.
the class Storage method createBundleFile.
public BundleFile createBundleFile(File content, Generation generation, boolean isDirectory, boolean isBase) {
BundleFile result;
try {
if (isDirectory) {
boolean strictPath = Boolean.parseBoolean(equinoxContainer.getConfiguration().getConfiguration(EquinoxConfiguration.PROPERTY_STRICT_BUNDLE_ENTRY_PATH, Boolean.FALSE.toString()));
result = new DirBundleFile(content, strictPath);
} else {
result = new ZipBundleFile(content, generation, mruList, getConfiguration().getDebug());
}
} catch (IOException e) {
// $NON-NLS-1$
throw new RuntimeException("Could not create bundle file.", e);
}
return wrapBundleFile(result, generation, isBase);
}
use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.
the class Storage method findEntries.
public static Enumeration<URL> findEntries(List<Generation> generations, String path, String filePattern, int options) {
List<BundleFile> bundleFiles = new ArrayList<>(generations.size());
for (Generation generation : generations) bundleFiles.add(generation.getBundleFile());
// search all the bundle files
List<String> pathList = listEntryPaths(bundleFiles, path, filePattern, options);
// return null if no entries found
if (pathList.size() == 0)
return null;
// create an enumeration to enumerate the pathList
final String[] pathArray = pathList.toArray(new String[pathList.size()]);
final Generation[] generationArray = generations.toArray(new Generation[generations.size()]);
return new Enumeration<URL>() {
private int curPathIndex = 0;
private int curDataIndex = 0;
private URL nextElement = null;
public boolean hasMoreElements() {
if (nextElement != null)
return true;
getNextElement();
return nextElement != null;
}
public URL nextElement() {
if (!hasMoreElements())
throw new NoSuchElementException();
URL result = nextElement;
// force the next element search
getNextElement();
return result;
}
private void getNextElement() {
nextElement = null;
if (curPathIndex >= pathArray.length)
// reached the end of the pathArray; no more elements
return;
while (nextElement == null && curPathIndex < pathArray.length) {
String curPath = pathArray[curPathIndex];
// search the generation until we have searched them all
while (nextElement == null && curDataIndex < generationArray.length) nextElement = generationArray[curDataIndex++].getEntry(curPath);
// we have searched all datas then advance to the next path
if (curDataIndex >= generationArray.length) {
curPathIndex++;
curDataIndex = 0;
}
}
}
};
}
use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.
the class Storage method listEntryPaths.
/**
* Returns the names of resources available from a list of bundle files.
* No duplicate resource names are returned, each name is unique.
* @param bundleFiles the list of bundle files to search in
* @param path The path name in which to look.
* @param filePattern The file name pattern for selecting resource names in
* the specified path.
* @param options The options for listing resource names.
* @return a list of resource names. If no resources are found then
* the empty list is returned.
* @see BundleWiring#listResources(String, String, int)
*/
public static List<String> listEntryPaths(List<BundleFile> bundleFiles, String path, String filePattern, int options) {
// Use LinkedHashSet for optimized performance of contains() plus
// ordering guarantees.
LinkedHashSet<String> pathList = new LinkedHashSet<>();
Filter patternFilter = null;
Hashtable<String, String> patternProps = null;
if (filePattern != null) {
// Avoid pattern matching and use BundleFile.getEntry() if recursion was not requested.
if ((options & BundleWiring.FINDENTRIES_RECURSE) == 0 && filePattern.indexOf('*') == -1 && filePattern.indexOf('\\') == -1) {
if (path.length() == 0)
path = filePattern;
else
path += path.charAt(path.length() - 1) == '/' ? filePattern : '/' + filePattern;
for (BundleFile bundleFile : bundleFiles) {
if (bundleFile.getEntry(path) != null && !pathList.contains(path))
pathList.add(path);
}
return new ArrayList<>(pathList);
}
// For when the file pattern includes a wildcard.
try {
// create a file pattern filter with 'filename' as the key
// $NON-NLS-1$ //$NON-NLS-2$
patternFilter = FilterImpl.newInstance("(filename=" + sanitizeFilterInput(filePattern) + ")");
// create a single hashtable to be shared during the recursive search
patternProps = new Hashtable<>(2);
} catch (InvalidSyntaxException e) {
// eventPublisher.publishFrameworkEvent(FrameworkEvent.ERROR, b, e);
return new ArrayList<>(pathList);
}
}
// find the entry paths for the datas
for (BundleFile bundleFile : bundleFiles) {
listEntryPaths(bundleFile, path, patternFilter, patternProps, options, pathList);
}
return new ArrayList<>(pathList);
}
Aggregations