本文整理汇总了Java中aQute.bnd.osgi.Jar类的典型用法代码示例。如果您正苦于以下问题:Java Jar类的具体用法?Java Jar怎么用?Java Jar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Jar类属于aQute.bnd.osgi包,在下文中一共展示了Jar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doWabStaging
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private void doWabStaging(Analyzer analyzer) throws Exception {
if (!isWab()) {
return;
}
String wab = analyzer.getProperty(analyzer.WAB);
Jar dot = analyzer.getJar();
log("wab %s", wab);
analyzer.setBundleClasspath("WEB-INF/classes," +
analyzer.getProperty(analyzer.BUNDLE_CLASSPATH));
Set<String> paths = new HashSet<String>(dot.getResources().keySet());
for (String path : paths) {
if (path.indexOf('/') > 0 && !Character.isUpperCase(path.charAt(0))) {
log("wab: moving: %s", path);
dot.rename(path, "WEB-INF/classes/" + path);
}
}
Path wabRoot = Paths.get(wab);
includeFiles(dot, null, wabRoot.toString());
}
示例2: doIncludeResources
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
/**
* Parse the Bundle-Includes header. Files in the bundles Include header are
* included in the jar. The source can be a directory or a file.
*
* @throws Exception
*/
private void doIncludeResources(Analyzer analyzer) throws Exception {
String includes = analyzer.getProperty(Analyzer.INCLUDE_RESOURCE);
if (includes == null) {
return;
}
Parameters clauses = analyzer.parseHeader(includes);
Jar jar = analyzer.getJar();
for (Map.Entry<String, Attrs> entry : clauses.entrySet()) {
String name = entry.getKey();
Map<String, String> extra = entry.getValue();
// TODO consider doing something with extras
String[] parts = name.split("\\s*=\\s*");
String source = parts[0];
String destination = parts[0];
if (parts.length == 2) {
source = parts[1];
}
includeFiles(jar, destination, source);
}
}
示例3: addFileToJar
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private boolean addFileToJar(Jar jar, String destination, String sourceAbsPath) {
if (includedResources.contains(sourceAbsPath)) {
log("Skipping already included resource: %s\n", sourceAbsPath);
return false;
}
File file = new File(sourceAbsPath);
if (!file.isFile()) {
throw new RuntimeException(
String.format("Skipping non-existent file: %s\n", sourceAbsPath));
}
Resource resource = new FileResource(file);
if (jar.getResource(destination) != null) {
warn("Skipping duplicate resource: %s\n", destination);
return false;
}
jar.putResource(destination, resource);
includedResources.add(sourceAbsPath);
log("Adding resource: %s\n", destination);
return true;
}
示例4: getAuxiliaryArchivesPackages
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private List<String> getAuxiliaryArchivesPackages(
Collection<Archive<?>> auxiliaryArchives)
throws IOException {
List<String> packages = new ArrayList<>();
for (Archive auxiliaryArchive : auxiliaryArchives) {
ZipExporter zipExporter = auxiliaryArchive.as(ZipExporter.class);
InputStream auxiliaryArchiveInputStream =
zipExporter.exportAsInputStream();
Jar jar = new Jar(
auxiliaryArchive.getName(), auxiliaryArchiveInputStream);
packages.addAll(jar.getPackages());
}
return packages;
}
示例5: tree
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
@Override
public Tree tree(Jar jar) throws Exception {
Tree result = null;
if (jar.getSource() != null && jar.getSource().isFile()) {
HashCode newCode = Files.hash(jar.getSource(), hashFunction);
result = cachedTrees.get(newCode);
if (result == null) {
result = delegate.tree(jar);
}
cachedTrees.put(newCode, result);
}
if (result == null) {
result = delegate.tree(jar);
}
return result;
}
示例6: doWabStaging
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private void doWabStaging(Analyzer analyzer) throws Exception {
if (!isWab()) {
return;
}
String wab = analyzer.getProperty(analyzer.WAB);
Jar dot = analyzer.getJar();
log("wab %s", wab);
analyzer.setBundleClasspath("WEB-INF/classes," +
analyzer.getProperty(analyzer.BUNDLE_CLASSPATH));
Set<String> paths = new HashSet<>(dot.getResources().keySet());
for (String path : paths) {
if (path.indexOf('/') > 0 && !Character.isUpperCase(path.charAt(0))) {
log("wab: moving: %s", path);
dot.rename(path, "WEB-INF/classes/" + path);
}
}
Path wabRoot = Paths.get(wab);
includeFiles(dot, null, wabRoot.toString());
}
示例7: doWabStaging
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private void doWabStaging(Analyzer analyzer) throws Exception {
if (!isWab()) {
return;
}
String wab = analyzer.getProperty(analyzer.WAB);
Jar dot = analyzer.getJar();
log("wab %s", wab);
analyzer.setBundleClasspath("WEB-INF/classes," +
analyzer.getProperty(analyzer.BUNDLE_CLASSPATH));
Set<String> paths = new HashSet<>(dot.getResources().keySet());
for (String path : paths) {
if (path.indexOf('/') > 0 && !Character.isUpperCase(path.charAt(0))) {
log("wab: moving: %s", path);
dot.rename(path, "WEB-INF/classes/" + path);
}
}
Path wabRoot = Paths.get(wab);
includeFiles(dot, null, wabRoot.toString());
}
示例8: includeFiles
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private void includeFiles(Jar jar, String destinationRoot, String sourceRoot)
throws IOException {
Path classesBasedPath = classesDir.resolve(sourceRoot);
Path sourceBasedPath = sourcesDir.resolve(sourceRoot);
File classFile = classesBasedPath.toFile();
File sourceFile = sourceBasedPath.toFile();
if (classFile.isFile()) {
addFileToJar(jar, destinationRoot, classesBasedPath.toAbsolutePath().toString());
} else if (sourceFile.isFile()) {
addFileToJar(jar, destinationRoot, sourceBasedPath.toAbsolutePath().toString());
} else if (classFile.isDirectory()) {
includeDirectory(jar, destinationRoot, classesBasedPath);
} else if (sourceFile.isDirectory()) {
includeDirectory(jar, destinationRoot, sourceBasedPath);
} else {
warn("Skipping resource in bundle %s: %s (File Not Found)\n",
bundleSymbolicName, sourceRoot);
}
}
示例9: includeDirectory
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private void includeDirectory(Jar jar, String destinationRoot, Path sourceRoot)
throws IOException {
// iterate through sources
// put each source on the jar
FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Path relativePath = sourceRoot.relativize(file);
String destination = destinationRoot != null ?
destinationRoot + "/" + relativePath.toString() : //TODO
relativePath.toString();
addFileToJar(jar, destination, file.toAbsolutePath().toString());
return FileVisitResult.CONTINUE;
}
};
walkFileTree(sourceRoot, visitor);
}
示例10: getRange
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private String getRange(Analyzer analyzer) throws Exception {
if (foundRange != null) {
return foundRange;
}
if (Strings.isNullOrEmpty(value)) {
for (Jar jar : analyzer.getClasspath()) {
if (isProvidedByJar(jar) && jar.getVersion() != null) {
foundRange = jar.getVersion();
return jar.getVersion();
}
}
// Cannot find a provider.
reporter.error("Cannot find a dependency providing " + name + " in the classpath");
return null;
} else {
return value;
}
}
示例11: computeClassPath
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
static Jar[] computeClassPath(File basedir) throws IOException {
List<Jar> list = new ArrayList<>();
File classes = new File(basedir, "target/classes");
if (classes.isDirectory()) {
list.add(new Jar("", classes));
}
Set<Artifact> artifacts = load(basedir).getTransitiveDependencies();
for (Artifact artifact : artifacts) {
if (!"test".equalsIgnoreCase(artifact.getScope())
&& artifact.getArtifactHandler().isAddedToClasspath()) {
File file = artifact.getFile();
if (file.getName().endsWith(".jar") && file.isFile()) {
list.add(new Jar(artifact.getArtifactId(), file));
}
}
}
Jar[] cp = new Jar[list.size()];
list.toArray(cp);
return cp;
}
示例12: includeFiles
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private void includeFiles(Jar jar, String destinationRoot, String sourceRoot)
throws IOException {
Path sourceRootPath = Paths.get(sourceRoot);
// iterate through sources
// put each source on the jar
FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Path relativePath = sourceRootPath.relativize(file);
String destination = destinationRoot != null ?
destinationRoot + "/" + relativePath.toString() : //TODO
relativePath.toString();
addFileToJar(jar, destination, file.toAbsolutePath().toString());
return FileVisitResult.CONTINUE;
}
};
File dir = new File(sourceRoot);
if (dir.isFile()) {
addFileToJar(jar, destinationRoot, dir.getAbsolutePath());
} else if (dir.isDirectory()) {
walkFileTree(sourceRootPath, visitor);
} else {
warn("Skipping resource in bundle %s: %s (File Not Found)\n",
bundleSymbolicName, sourceRoot);
}
}
示例13: wrap
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
/**
* Wrap the file associated with this instance of {@code JarWrapper} if it is not a bundle already.
* <p>
* If the source file is already a bundle, nothing is done and this method returns the original file.
* Notice that this means the returned file is not necessarily the same as the destination file.
*
* @param version version to give the bundle. If this is not a valid OSGi version, it will be converted to
* a {@link MavenVersion} and translated to a valid OSGi version.
* @return the bundle file
* @throws Exception if any error occurs while reading the source file or writing the destination bundle.
*/
public File wrap( String version ) throws Exception {
if ( !jarFile.isFile() ) {
throw new IllegalArgumentException( "Not a file: " + jarFile );
}
if ( version.trim().isEmpty() ) {
throw new IllegalArgumentException( "Version must not be empty" );
}
try ( ZipFile input = new ZipFile( jarFile, ZipFile.OPEN_READ ) ) {
if ( isBundle( input ) ) {
return jarFile;
}
}
final String name = ( artifactName == null ?
subtract( jarFile.getName(), ".jar" ) : artifactName );
try ( Jar newJar = new Jar( jarFile ) ) {
Analyzer analyzer = new Analyzer();
analyzer.setJar( newJar );
analyzer.setBundleVersion( Version.isVersion( version ) ?
Version.parseVersion( version ) :
MavenVersion.parseString( version ).getOSGiVersion() );
analyzer.setBundleSymbolicName( name );
analyzer.setImportPackage( importInstructions );
analyzer.setExportPackage( exportInstructions );
File bundle = destination == null ?
new File( jarFile.getParentFile(), name + "-osgi.jar" ) :
destination;
Manifest manifest = analyzer.calcManifest();
return updateManifest( newJar, bundle, manifest );
}
}
示例14: updateManifest
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
private static File updateManifest( Jar newJar, File bundle, Manifest manifest )
throws Exception {
verifyDestinationFileCanBeWritten( bundle );
newJar.setManifest( manifest );
newJar.write( bundle );
return bundle;
}
示例15: loadOldClassesFromFolder
import aQute.bnd.osgi.Jar; //导入依赖的package包/类
@Override
public void loadOldClassesFromFolder(File jarFile) throws RuntimeException {
try {
oldJar = new Jar(jarFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}