List of usage examples for java.util.jar Manifest getMainAttributes
public Attributes getMainAttributes()
From source file:com.redhat.ceylon.compiler.java.test.cmr.CMRTests.java
@Test public void testMdlOsgiManifestExportsSharedPackages() throws IOException { compile("modules/osgi/a/module.ceylon", "modules/osgi/a/package.ceylon", "modules/osgi/a/A.ceylon", "modules/osgi/a/b/package.ceylon", "modules/osgi/a/b/B.ceylon", "modules/osgi/a/c/package.ceylon", "modules/osgi/a/c/C.ceylon"); final String moduleName = "com.redhat.ceylon.compiler.java.test.cmr.modules.osgi.a"; final String moduleVersion = "1.1.0"; final Manifest manifest = getManifest(moduleName, moduleVersion); assertNotNull(manifest);//from ww w .ja va2 s . c o m Attributes attr = manifest.getMainAttributes(); String attribute = (String) attr.get(OsgiUtil.OsgiManifest.Export_Package); String[] exportPackage = attribute.split(","); assertEquals(2, exportPackage.length); assertThat(Arrays.asList(exportPackage), CoreMatchers.hasItems( "com.redhat.ceylon.compiler.java.test.cmr.modules.osgi.a;version=" + moduleVersion, "com.redhat.ceylon.compiler.java.test.cmr.modules.osgi.a.c;version=" + moduleVersion)); assertThat(Arrays.asList(exportPackage), CoreMatchers.not(CoreMatchers .hasItem("com.redhat.ceylon.compiler.java.test.cmr.modules.osgi.a.b;version=" + moduleVersion))); }
From source file:org.jboss.tools.tycho.sitegenerator.FetchSourcesFromManifests.java
public void execute() throws MojoExecutionException, MojoFailureException { if (!skip) {/*from w w w. ja v a 2 s . c om*/ if (this.zipCacheFolder == null) { this.zipCacheFolder = new File(project.getBasedir() + File.separator + "cache" + File.separator); } if (this.zipCacheFolder != null && !this.zipCacheFolder.isDirectory()) { try { if (!this.zipCacheFolder.exists()) { this.zipCacheFolder.mkdirs(); } } catch (Exception ex) { throw new MojoExecutionException("'zipCacheFolder' must be a directory", ex); } } if (this.outputFolder == null) { this.outputFolder = new File(project.getBasedir() + File.separator + "zips" + File.separator); } if (this.outputFolder.equals(this.zipCacheFolder)) { throw new MojoExecutionException("zipCacheFolder and outputFolder can not be the same folder"); } zipsDirectory = new File(this.outputFolder, "all"); if (!zipsDirectory.exists()) { zipsDirectory.mkdirs(); } File digestFile = new File(this.outputFolder, "ALL_REVISIONS.txt"); FileWriter dfw; StringBuffer sb = new StringBuffer(); String branch = project.getProperties().getProperty("mvngit.branch"); sb.append("-=> " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + columnSeparator + branch + " <=-\n"); String pluginPath = project.getBasedir() + File.separator + "target" + File.separator + "repository" + File.separator + "plugins"; String sep = " " + columnSeparator + " "; if (sourceFetchMap == null) { getLog().warn( "No <sourceFetchMap> defined in pom. Can't fetch sources without a list of plugins. Did you forget to enable fetch-source-zips profile?"); } else { for (String projectName : this.sourceFetchMap.keySet()) { String pluginNameOrBuildInfoJsonUrl = this.sourceFetchMap.get(projectName); // jbosstools-base = org.jboss.tools.common getLog().debug("For project " + projectName + ": plugin name or buildinfo.json = " + pluginNameOrBuildInfoJsonUrl); String SHA = null; String qualifier = null; String SHASource = null; // if the value is a buildinfo.json URL, not a plugin name if ((pluginNameOrBuildInfoJsonUrl.startsWith("http") || pluginNameOrBuildInfoJsonUrl.startsWith("ftp")) && pluginNameOrBuildInfoJsonUrl.matches(".+buildinfo.*json")) { getLog().debug("Read JSON from: " + pluginNameOrBuildInfoJsonUrl); ModelNode obj; try { obj = ModelNode.fromJSONStream((new URL(pluginNameOrBuildInfoJsonUrl)).openStream()); } catch (IOException e) { throw new MojoExecutionException( "Problem occurred reading " + pluginNameOrBuildInfoJsonUrl, e); } SHA = getSHA(obj); getLog().debug("Found SHA = " + SHA); // create qualifier from buildinfo.json BUILD_ALIAS and ZIPSUFFIX qualifier = getProperty(obj, "BUILD_ALIAS") + "-" + getProperty(obj, "ZIPSUFFIX"); getLog().debug("Found qualifier = " + qualifier); SHASource = pluginNameOrBuildInfoJsonUrl; } else { // find the first matching plugin jar, eg., target/repository/plugins/org.jboss.tools.common_3.6.0.Alpha2-v20140304-0055-B440.jar File[] matchingFiles = listFilesMatching(new File(pluginPath), pluginNameOrBuildInfoJsonUrl + "_.+\\.jar"); // for (File file : matchingFiles) getLog().debug(file.toString()); if (matchingFiles.length < 1) { throw new MojoExecutionException("No matching plugin found in " + pluginPath + " for " + pluginNameOrBuildInfoJsonUrl + "_.+\\.jar.\nCheck your pom.xml for this line: <" + projectName + ">" + pluginNameOrBuildInfoJsonUrl + "</" + projectName + ">"); } File jarFile = matchingFiles[0]; File manifestFile = null; try { FileInputStream fin = new FileInputStream(jarFile); manifestFile = File.createTempFile(MANIFEST, ""); OutputStream out = new FileOutputStream(manifestFile); BufferedInputStream bin = new BufferedInputStream(fin); ZipInputStream zin = new ZipInputStream(bin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { // getLog().debug(ze.getName()); if (ze.getName().equals("META-INF/" + MANIFEST)) { // getLog().debug("Found " + ze.getName() + " in " + // jarFile); byte[] buffer = new byte[8192]; int len; while ((len = zin.read(buffer)) != -1) { out.write(buffer, 0, len); } out.close(); break; } } zin.close(); // getLog().debug("Saved " + jarFile + "!/META-INF/" + MANIFEST); } catch (Exception ex) { throw new MojoExecutionException("Error extracting " + MANIFEST + " from " + jarFile, ex); } // retrieve the MANIFEST.MF file, eg., org.jboss.tools.usage_1.2.100.Alpha2-v20140221-1555-B437.jar!/META-INF/MANIFEST.MF Manifest manifest; try { manifest = new Manifest(new FileInputStream(manifestFile)); } catch (Exception ex) { throw new MojoExecutionException("Error while reading manifest file " + MANIFEST, ex); } // parse out the commitId from Eclipse-SourceReferences: // scm:git:https://github.com/jbosstools/jbosstools-base.git;path="usage/plugins/org.jboss.tools.usage";commitId=184e18cc3ac7c339ce406974b6a4917f73909cc4 Attributes attr = manifest.getMainAttributes(); String ESR = null; SHA = null; ESR = attr.getValue("Eclipse-SourceReferences"); // getLog().debug(ESR); if (ESR != null) { SHA = ESR.substring(ESR.lastIndexOf(";commitId=") + 10); // getLog().debug(SHA); } else { SHA = "UNKNOWN"; } // cleanup manifestFile.delete(); qualifier = getQualifier(pluginNameOrBuildInfoJsonUrl, jarFile.toString(), true); SHASource = removePrefix(jarFile.toString(), pluginPath) + " " + MANIFEST; } // fetch github source archive for that SHA, eg., https://github.com/jbosstools/jbosstools-base/archive/184e18cc3ac7c339ce406974b6a4917f73909cc4.zip // to jbosstools-base_184e18cc3ac7c339ce406974b6a4917f73909cc4_sources.zip String URL = ""; String outputZipName = ""; try { if (SHA == null || SHA.equals("UNKNOWN")) { getLog().warn("Cannot fetch " + projectName + " sources: no Eclipse-SourceReferences in " + SHASource); } else { URL = "https://github.com/jbosstools/" + projectName + "/archive/" + SHA + ".zip"; outputZipName = projectName + "_" + SHA + "_sources.zip"; fetchUpstreamSourcesZip(projectName, SHA); } } catch (Exception ex) { throw new MojoExecutionException("Error while downloading github source archive", ex); } // github project, plugin, version, SHA, origin/branch@SHA, remote zipfile, local zipfile String revisionLine = projectName + sep + pluginNameOrBuildInfoJsonUrl + sep + qualifier + sep + SHA + sep + "origin/" + branch + "@" + SHA + sep + URL + sep + outputZipName + "\n"; // getLog().debug(revisionLine); sb.append(revisionLine); } } /* JBIDE-19467 check if SHA in buildinfo_projectName.json matches projectName_65cb06bb81773714b9e3fc1c312e33aaa068dc33_sources.zip. Note: this may fail if you've built stuff locally because those plugins will use different SHAs (eg., from a pull-request topic branch) To test this is working via commandline shell equivalent cd jbosstools-build-sites/aggregate/site for j in target/buildinfo/buildinfo_jbosstools-*; do echo -n $j; k=${j##*_}; k=${k/.json}; echo " :: $k"; cat $j | grep HEAD | head -1 | sed "s#[\t\w\ ]\+\"HEAD\" : \"\(.\+\)\",#0: \1#"; ls cache/${k}_*_sources.zip | sed -e "s#cache/${k}_\(.\+\)_sources.zip#1: \1#"; echo ""; done */ if (skipCheckSHAs) { getLog().warn( "skipCheckSHAs=true :: Skip check that buildinfo_*.json HEAD SHA matches MANIFEST.MF Eclipse-SourceReferences commitId SHA."); } else { File buildinfoFolder = new File(this.project.getBuild().getDirectory(), "buildinfo"); if (buildinfoFolder.isDirectory()) { try { File[] buildInfoFiles = listFilesMatching(buildinfoFolder, "buildinfo_.+.json"); for (int i = 0; i < buildInfoFiles.length; i++) { InputStream in = null; ModelNode obj = null; String upstreamSHA = null; String upstreamProjectName = buildInfoFiles[i].toString() .replaceAll(".+buildinfo_(.+).json", "$1"); getLog().debug(i + ": " + buildInfoFiles[i].toString() + " :: " + upstreamProjectName); try { getLog().debug("Read JSON from: " + buildInfoFiles[i].toString()); in = new FileInputStream(buildInfoFiles[i]); obj = ModelNode.fromJSONStream(in); upstreamSHA = getSHA(obj); getLog().debug("Found SHA = " + upstreamSHA); // check if there's a file called upstreamProjectName_upstreamSHA_sources.zip String outputZipName = upstreamProjectName + "_" + upstreamSHA + "_sources.zip"; File outputZipFile = new File(zipsDirectory, outputZipName); if (!outputZipFile.isFile()) { getLog().debug("Check " + outputFolder.toString() + " for " + upstreamProjectName + "_.+_sources.zip"); // find the sources we DID download, eg., jbosstools-browsersim_9255a5b7c04fb10768c14942e60092e860881d6b_sources.zip File[] wrongZipFiles = listFilesMatching(zipsDirectory, upstreamProjectName + "_.+_sources.zip"); String wrongZips = ""; for (int j = 0; j < wrongZipFiles.length; j++) { getLog().debug(wrongZipFiles[j].toString()); wrongZips += (wrongZips.isEmpty() ? "" : ", ") + wrongZipFiles[j].toString() .replaceAll(".+" + upstreamProjectName + "_(.+)_sources.zip", "$1"); } if (!wrongZips.isEmpty()) { throw new MojoFailureException("\n\n" + buildInfoFiles[i].toString() + "\ncontains " + upstreamSHA + ", but upstream " + upstreamProjectName + " project's MANIFEST.MF has Eclipse-SourceReferences \n" + "commitId " + wrongZips + ". \n\n" + "If you have locally built projects which are being aggregated here, ensure \n" + "they are built from the latest SHA from HEAD, not a local topic branch. \n\n" + "It's also possible that some recent changes have not yet been built upstream. \n" + "If that's the case, trigger a build for the " + upstreamProjectName + " project \n" + "to ensure that the latest commits have been built and can be aggregated here. \n\n" + "Or, use -DskipCheckSHAs=true to bypass this check.\n\n"); // JBIDE-22808 } else { getLog().warn("\n" + buildInfoFiles[i].toString() + "\ncontains " + upstreamSHA + ", but upstream " + upstreamProjectName + " project's MANIFEST.MF has no Eclipse-SourceReferences commitId.\n" + "Using sources from " + upstreamSHA + "."); // fetch sources from upstreamProjectName's upstreamSHA (but do not log in the digestFile) fetchUpstreamSourcesZip(upstreamProjectName, upstreamSHA); } } } finally { IOUtils.closeQuietly(in); } } } catch (Exception ex) { throw new MojoExecutionException("Problem occurred checking upstream buildinfo.json files!", ex); } } } /* JBIDE-19467 check if SHA in buildinfo_projectName.json matches projectName_65cb06bb81773714b9e3fc1c312e33aaa068dc33_sources.zip. Note: this may fail if you've built stuff locally because those plugins will use different SHAs (eg., from a pull-request topic branch) To test this is working via commandline shell equivalent cd jbosstools-build-sites/aggregate/site for j in target/buildinfo/buildinfo_jbosstools-*; do echo -n $j; k=${j##*_}; k=${k/.json}; echo " :: $k"; cat $j | grep HEAD | head -1 | sed "s#[\t\w\ ]\+\"HEAD\" : \"\(.\+\)\",#0: \1#"; ls cache/${k}_*_sources.zip | sed -e "s#cache/${k}_\(.\+\)_sources.zip#1: \1#"; echo ""; done */ if (skipCheckSHAs) { getLog().warn( "skipCheckSHAs=true :: Skip check that buildinfo_*.json HEAD SHA matches MANIFEST.MF Eclipse-SourceReferences commitId SHA."); } else { File buildinfoFolder = new File(this.project.getBuild().getDirectory(), "buildinfo"); if (buildinfoFolder.isDirectory()) { try { File[] buildInfoFiles = listFilesMatching(buildinfoFolder, "buildinfo_.+.json"); for (int i = 0; i < buildInfoFiles.length; i++) { InputStream in = null; ModelNode obj = null; String upstreamSHA = null; String upstreamProjectName = buildInfoFiles[i].toString() .replaceAll(".+buildinfo_(.+).json", "$1"); getLog().debug(i + ": " + buildInfoFiles[i].toString() + " :: " + upstreamProjectName); try { getLog().debug("Read JSON from: " + buildInfoFiles[i].toString()); in = new FileInputStream(buildInfoFiles[i]); obj = ModelNode.fromJSONStream(in); upstreamSHA = getSHA(obj); getLog().debug("Found SHA = " + upstreamSHA); // check if there's a file called upstreamProjectName_upstreamSHA_sources.zip String outputZipName = upstreamProjectName + "_" + upstreamSHA + "_sources.zip"; File outputZipFile = new File(zipsDirectory, outputZipName); if (!outputZipFile.isFile()) { getLog().debug("Check " + outputFolder.toString() + " for " + upstreamProjectName + "_.+_sources.zip"); // find the sources we DID download, eg., jbosstools-browsersim_9255a5b7c04fb10768c14942e60092e860881d6b_sources.zip File[] wrongZipFiles = listFilesMatching(zipsDirectory, upstreamProjectName + "_.+_sources.zip"); String wrongZips = ""; for (int j = 0; j < wrongZipFiles.length; j++) { getLog().debug(wrongZipFiles[j].toString()); wrongZips += (wrongZips.isEmpty() ? "" : ", ") + wrongZipFiles[j].toString() .replaceAll(".+" + upstreamProjectName + "_(.+)_sources.zip", "$1"); } if (!wrongZips.isEmpty()) { throw new MojoFailureException("\n" + buildInfoFiles[i].toString() + "\ncontains " + upstreamSHA + ", but upstream " + upstreamProjectName + " project's MANIFEST.MF has Eclipse-SourceReferences\ncommitId " + wrongZips + ". \nIf you have locally built projects which are aggregated here, \nensure they are built from the latest SHA from HEAD, not a local topic branch.\n" + "Or, use -DskipCheckSHAs=true to bypass this check."); } else { getLog().warn("\n" + buildInfoFiles[i].toString() + "\ncontains " + upstreamSHA + ", but upstream " + upstreamProjectName + " project's MANIFEST.MF has no Eclipse-SourceReferences commitId.\n" + "Using sources from " + upstreamSHA + "."); // fetch sources from upstreamProjectName's upstreamSHA (but do not log in the digestFile) fetchUpstreamSourcesZip(upstreamProjectName, upstreamSHA); } } } finally { IOUtils.closeQuietly(in); } } } catch (Exception ex) { throw new MojoExecutionException("Problem occurred checking upstream buildinfo.json files!", ex); } } } // JBDS-3364 JBDS-3208 JBIDE-19467 when not using publish.sh, unpack downloaded source zips and combine them into a single zip createCombinedZipFile(zipsDirectory, zipFiles, CACHE_ZIPS); // getLog().debug("Generating aggregate site metadata"); try { { File buildPropertiesAllXml = new File(this.outputFolder, "build.properties.all.xml"); if (!buildPropertiesAllXml.exists()) { buildPropertiesAllXml.createNewFile(); } FileOutputStream xmlOut = new FileOutputStream(buildPropertiesAllXml); allBuildProperties.storeToXML(xmlOut, null); xmlOut.close(); } { File buildPropertiesFileTxt = new File(this.outputFolder, "build.properties.file.txt"); if (!buildPropertiesFileTxt.exists()) { buildPropertiesFileTxt.createNewFile(); } FileOutputStream textOut = new FileOutputStream(buildPropertiesFileTxt); allBuildProperties.store(textOut, null); textOut.close(); } } catch (Exception ex) { throw new MojoExecutionException("Error while creating 'metadata' files", ex); } try { dfw = new FileWriter(digestFile); dfw.write(sb.toString()); dfw.close(); } catch (Exception ex) { throw new MojoExecutionException("Error writing to " + digestFile.toString(), ex); } // getLog().debug("Written to " + digestFile.toString() + ":\n\n" + sb.toString()); } else { getLog().info("fetch-sources-from-manifests (fetch-sources) :: skipped."); } }
From source file:com.redhat.ceylon.compiler.java.test.cmr.CMRTests.java
@Test public void testMdlOsgiManifestWithJavaImportRequiresJavaSECapability() throws IOException { compile("modules/osgi/java/module.ceylon", "modules/osgi/java/package.ceylon", "modules/osgi/java/foo.ceylon"); final String moduleName = "com.redhat.ceylon.compiler.java.test.cmr.modules.osgi.java"; final String moduleVersion = "1.1.0"; final Manifest manifest = getManifest(moduleName, moduleVersion); assertEquals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version>=1.7))\"", manifest.getMainAttributes().get(OsgiUtil.OsgiManifest.Require_Capability)); }
From source file:hudson.ClassicPluginStrategy.java
@Override public PluginWrapper createPluginWrapper(File archive) throws IOException { final Manifest manifest; URL baseResourceURL = null;/* w w w . j a v a 2 s .c o m*/ File expandDir = null; // if .hpi, this is the directory where war is expanded boolean isLinked = isLinked(archive); if (isLinked) { manifest = loadLinkedManifest(archive); } else { if (archive.isDirectory()) {// already expanded expandDir = archive; } else { expandDir = new File(archive.getParentFile(), getBaseName(archive.getName())); explode(archive, expandDir); } File manifestFile = new File(expandDir, PluginWrapper.MANIFEST_FILENAME); if (!manifestFile.exists()) { throw new IOException("Plugin installation failed. No manifest at " + manifestFile); } FileInputStream fin = new FileInputStream(manifestFile); try { manifest = new Manifest(fin); } finally { fin.close(); } } final Attributes atts = manifest.getMainAttributes(); // TODO: define a mechanism to hide classes // String export = manifest.getMainAttributes().getValue("Export"); List<File> paths = new ArrayList<File>(); if (isLinked) { parseClassPath(manifest, archive, paths, "Libraries", ","); parseClassPath(manifest, archive, paths, "Class-Path", " +"); // backward compatibility baseResourceURL = resolve(archive, atts.getValue("Resource-Path")).toURI().toURL(); } else { File classes = new File(expandDir, "WEB-INF/classes"); if (classes.exists()) paths.add(classes); File lib = new File(expandDir, "WEB-INF/lib"); File[] libs = lib.listFiles(JAR_FILTER); if (libs != null) paths.addAll(Arrays.asList(libs)); try { Class pathJDK7 = Class.forName("java.nio.file.Path"); Object toPath = File.class.getMethod("toPath").invoke(expandDir); URI uri = (URI) pathJDK7.getMethod("toUri").invoke(toPath); baseResourceURL = uri.toURL(); } catch (NoSuchMethodException e) { throw new Error(e); } catch (ClassNotFoundException e) { baseResourceURL = expandDir.toURI().toURL(); } catch (InvocationTargetException e) { throw new Error(e); } catch (IllegalAccessException e) { throw new Error(e); } } File disableFile = new File(archive.getPath() + ".disabled"); if (disableFile.exists()) { LOGGER.info("Plugin " + archive.getName() + " is disabled"); } // compute dependencies List<PluginWrapper.Dependency> dependencies = new ArrayList<PluginWrapper.Dependency>(); List<PluginWrapper.Dependency> optionalDependencies = new ArrayList<PluginWrapper.Dependency>(); String v = atts.getValue("Plugin-Dependencies"); if (v != null) { for (String s : v.split(",")) { PluginWrapper.Dependency d = new PluginWrapper.Dependency(s); if (d.optional) { optionalDependencies.add(d); } else { dependencies.add(d); } } } for (DetachedPlugin detached : DETACHED_LIST) detached.fix(atts, optionalDependencies); // Register global classpath mask. This is useful for hiding JavaEE APIs that you might see from the container, // such as database plugin for JPA support. The Mask-Classes attribute is insufficient because those classes // also need to be masked by all the other plugins that depend on the database plugin. String masked = atts.getValue("Global-Mask-Classes"); if (masked != null) { for (String pkg : masked.trim().split("[ \t\r\n]+")) coreClassLoader.add(pkg); } ClassLoader dependencyLoader = new DependencyClassLoader(coreClassLoader, archive, Util.join(dependencies, optionalDependencies)); dependencyLoader = getBaseClassLoader(atts, dependencyLoader); return new PluginWrapper(pluginManager, archive, manifest, baseResourceURL, createClassLoader(paths, dependencyLoader, atts), disableFile, dependencies, optionalDependencies); }
From source file:test.BuilderTest.java
/** * Check of the use of x- directives are not skipped. bnd allows x- * directives in the import/export clauses but strips other ones. * //from ww w .ja v a 2 s . c o m * @throws Exception */ public static void testXDirectives() throws Exception { Builder b = new Builder(); try { b.addClasspath(IO.getFile("jar/osgi.jar")); b.setProperty("Export-Package", "org.osgi.framework;x-foo:=true;bar:=false"); Jar jar = b.build(); assertTrue(b.check("bar:")); Manifest m = jar.getManifest(); String s = m.getMainAttributes().getValue("Export-Package"); assertTrue(s.contains("x-foo:")); } finally { b.close(); } }
From source file:test.BuilderTest.java
public static void testHardcodedImport() throws Exception { File cp[] = { IO.getFile("jar/asm.jar") }; Builder bmaker = new Builder(); try {// w w w . jav a 2 s . com Properties p = new Properties(); p.setProperty("Import-Package", "whatever,*"); p.setProperty("Export-Package", "org.*"); bmaker.setProperties(p); bmaker.setClasspath(cp); Jar jar = bmaker.build(); assertTrue(bmaker.check()); Manifest m = jar.getManifest(); String ip = m.getMainAttributes().getValue("Import-Package"); assertTrue(ip.indexOf("whatever") >= 0); } finally { bmaker.close(); } }
From source file:test.BuilderTest.java
public static void testNoExport() throws Exception { File cp[] = { IO.getFile("jar/asm.jar") }; Builder bmaker = new Builder(); try {//from ww w . j a va 2 s. c o m Properties p = new Properties(); p.setProperty("Import-Package", "*"); p.setProperty("Export-Package", "org.*'"); bmaker.setProperties(p); bmaker.setClasspath(cp); Jar jar = bmaker.build(); assertTrue(bmaker.check()); jar.getManifest().write(System.err); Manifest m = jar.getManifest(); String ip = m.getMainAttributes().getValue("Export-Package"); assertTrue(ip.indexOf("org.objectweb.asm") >= 0); } finally { bmaker.close(); } }
From source file:test.BuilderTest.java
/** * Export a package that was loaded with resources * /*from www . j a va 2 s. c om*/ * @throws Exception */ public static void testExportSyntheticPackage() throws Exception { Builder bmaker = new Builder(); try { Properties p = new Properties(); p.setProperty("-resourceonly", "true"); p.setProperty("Include-Resource", "resources=jar"); p.setProperty("-exportcontents", "resources"); bmaker.setProperties(p); Jar jar = bmaker.build(); assertTrue(bmaker.check()); Manifest manifest = jar.getManifest(); String header = manifest.getMainAttributes().getValue("Export-Package"); System.err.println(header); assertTrue(header.indexOf("resources") >= 0); } finally { bmaker.close(); } }
From source file:test.BuilderTest.java
/** * Exporting packages in META-INF//from ww w . j a v a 2s. c o m * * @throws Exception */ public static void testMETAINF() throws Exception { File cp[] = { new File("src"), IO.getFile("jar/asm.jar") }; Builder bmaker = new Builder(); try { Properties p = new Properties(); p.setProperty("Include-Resource", "META-INF/xyz/asm.jar=jar/asm.jar"); p.setProperty("Export-Package", "META-INF/xyz, org.*"); bmaker.setProperties(p); bmaker.setClasspath(cp); Jar jar = bmaker.build(); assertTrue(bmaker.check("Invalid package name: 'META-INF")); jar.getManifest().write(System.err); Manifest manifest = jar.getManifest(); String header = manifest.getMainAttributes().getValue("Export-Package"); assertTrue(header.indexOf("META-INF.xyz") >= 0); } finally { bmaker.close(); } }
From source file:test.BuilderTest.java
/** * Test where the version comes from: Manifest or packageinfo * /*w w w . ja v a2s. c o m*/ * @throws Exception */ public static void testExportVersionSource() throws Exception { Manifest manifest = new Manifest(); manifest.getMainAttributes().putValue("Export-Package", "org.osgi.service.event;version=100"); // Remove packageinfo Jar manifestOnly = new Jar(IO.getFile("jar/osgi.jar")); try { manifestOnly.remove("org/osgi/service/event/packageinfo"); manifestOnly.setManifest(manifest); // Remove manifest Jar packageInfoOnly = new Jar(IO.getFile("jar/osgi.jar")); packageInfoOnly.setManifest(new Manifest()); Jar both = new Jar(IO.getFile("jar/osgi.jar")); both.setManifest(manifest); // Only version in manifest Builder bms = new Builder(); try { bms.addClasspath(manifestOnly); bms.setProperty("Export-Package", "org.osgi.service.event"); bms.build(); assertTrue(bms.check()); String s = bms.getExports().getByFQN("org.osgi.service.event").get("version"); assertEquals("100", s); // Only version in packageinfo Builder bpinfos = new Builder(); bpinfos.addClasspath(packageInfoOnly); bpinfos.setProperty("Export-Package", "org.osgi.service.event"); bpinfos.build(); assertTrue(bpinfos.check()); s = bpinfos.getExports().getByFQN("org.osgi.service.event").get("version"); assertEquals("1.0.1", s); } finally { bms.close(); } } finally { manifestOnly.close(); } }