+ protected BundlePackage processBundleDir(File dir, boolean willGenerate)
+ throws Exception {
+ File manifestFile = manifestFileFromDir(dir);
+ String artifactId = dir.getName();
+ File destFile = new File(packagedBundlesDir.getPath() + File.separator
+ + artifactId + ".jar");
+
+ String manifestStr = FileUtils.readFileToString(manifestFile);
+ char lastChar = manifestStr.charAt(manifestStr.length() - 1);
+ if (lastChar != '\n')
+ throw new RuntimeException("Manifest " + manifestFile
+ + " is not valid,"
+ + " it does not end with and endline character.");
+
+ Manifest manifest = readManifest(manifestFile);
+ // Symbolic name
+ String symbolicNameMf = manifest.getMainAttributes().getValue(
+ "Bundle-SymbolicName");
+ if (!artifactId.equals(symbolicNameMf)) {
+ String msg = "Symbolic name " + symbolicNameMf
+ + " does not match with directory name " + artifactId;
+ if (strictSymbolicName)
+ throw new RuntimeException(msg);
+ else
+ getLog().warn(msg);
+ }
+
+ // Version
+ String versionMf = manifest.getMainAttributes().getValue(
+ "Bundle-Version");
+ int qIndex = versionMf.lastIndexOf(".SNAPSHOT");
+ String versionMfMain;
+ if (qIndex >= 0)
+ versionMfMain = versionMf.substring(0, qIndex);
+ else
+ versionMfMain = versionMf;
+
+ int sIndex = project.getModel().getVersion().lastIndexOf("-SNAPSHOT");
+ String versionMain;
+ String buildId;
+ boolean isSnapshot = false;
+ if (sIndex >= 0) {// SNAPSHOT
+ versionMain = project.getVersion().substring(0, sIndex);
+ // buildId = "D_" + sdf.format(new Date());// D for dev
+ buildId = "SNAPSHOT";
+ isSnapshot = true;
+ } else {
+ versionMain = project.getVersion();
+ // buildId = "R_" + sdf.format(new Date());// R for release
+ buildId = "";
+ }
+
+ if (!versionMain.equals(versionMfMain)) {
+ String msg = "Main manifest version " + versionMfMain
+ + " of bundle " + artifactId
+ + " do not match with main project version " + versionMain;
+ if (strictManifestVersion)
+ throw new RuntimeException(msg);
+ else
+ getLog().warn(msg);
+ }
+
+ String newVersionMf = versionMfMain + "." + buildId;
+ String newVersionArt;
+ if (isSnapshot) {
+ newVersionArt = versionMfMain + "-SNAPSHOT";
+ } else {
+ newVersionArt = versionMfMain;
+ }
+
+ //boolean debug = true;
+ boolean debug = getLog().isDebugEnabled();
+ if (debug && willGenerate) {
+ getLog().info("\n## " + artifactId);
+ getLog().info("project.getVersion()=" + project.getVersion());
+ // getLog().info(
+ // "project.getModel().getVersion()="
+ // + project.getModel().getVersion());
+ // getLog().info("versionMf=" + versionMf);
+ // getLog().info("buildId=" + buildId);
+ getLog().info("newVersionMf=" + newVersionMf);
+ }
+
+ manifest.getMainAttributes().putValue("Bundle-Version", newVersionMf);
+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION,
+ "1.0");
+
+ Artifact artifact = artifactFactory.createBuildArtifact(project
+ .getGroupId(), artifactId, newVersionArt, "jar");
+ return new BundlePackage(artifact, dir, new Manifest(manifest),
+ destFile);
+ }
+