Skip to content

BWCE-8783 Support [MACIF SAM] : Customer facing issue with changing the snapsho… #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.jar.Attributes.Name;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -104,9 +105,8 @@ public void execute() throws MojoExecutionException {
archiveConfiguration = new MavenArchiveConfiguration();
moduleVersionMap = new HashMap<String, String>();
manifest = ManifestParser.parseManifest(projectBasedir);
ManifestWriter.updateManifestVersion(project, manifest, Constants.TIMESTAMP);
ManifestWriter.udpateManifestAttributes(project, manifest, Constants.TIMESTAMP);
getLog().info("Updated the Manifest version ");
updateManifestVersion();
getLog().info("Adding Modules to the EAR file");
addModules();
getLog().info("Adding EAR Information to the EAR File");
Expand Down Expand Up @@ -628,13 +628,4 @@ private void cleanup() {
}
getLog().debug("cleaned up the temporary files.");
}
/**
* Updated the Application manifest just like the module one
*/
private void updateManifestVersion() {
String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
String qualifierVersion = VersionParser.getcalculatedOSGiVersion(version, Constants.TIMESTAMP);
getLog().info("The OSGi verion is " + qualifierVersion + " for Maven version of " + version);
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, qualifierVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Set;
import java.util.jar.Manifest;
import java.util.jar.Attributes.Name;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
Expand Down Expand Up @@ -99,12 +100,12 @@ public void execute() throws MojoExecutionException {
throw new Exception("Failed to parse MANIFEST.MF for project -> "+ projectBasedir);
}
getLog().info("Updated the Manifest version ");

ManifestWriter.updateManifestVersion(project, manifest, qualifierReplacement);
updateManifestVersion();
ManifestWriter.udpateManifestAttributes(project, manifest, qualifierReplacement);

getLog().info("Removing the externals entries if any. ");
removeExternals();

ManifestParser.updateWriteManifest(projectBasedir, manifest);

File pluginFile = getPluginJAR();
getLog().info("Created Plugin JAR with name " + pluginFile.toString());
Expand Down Expand Up @@ -267,7 +268,7 @@ public boolean endVisit(DependencyNode node) {
}

private File getPluginJAR() {
String qualifierVersion = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
String qualifierVersion = manifest.getMainAttributes().getValue(Constants.ARCHIVE_FILE_VERSION);
if(qualifierVersion != null && qualifierVersion.endsWith(".")) {
qualifierVersion = qualifierVersion.substring(0, qualifierVersion.lastIndexOf("."));
}
Expand Down Expand Up @@ -354,12 +355,6 @@ protected boolean isCXFProject(){
return false;
}
}
private void updateManifestVersion() {
String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
String qualifierVersion = VersionParser.getcalculatedOSGiVersion(version, qualifierReplacement);
getLog().info("The OSGi verion is " + qualifierVersion + " for Maven version of " + version);
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, qualifierVersion);
}

private void removeExternals() {
String bundlePath = manifest.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;

Expand Down Expand Up @@ -38,6 +40,16 @@ public static Manifest parseManifest(File baseDir) {
return mf;
}


public static void updateWriteManifest(File baseDir, Manifest mf) {
File mfile = new File(baseDir , "META-INF/MANIFEST.MF");
try {
OutputStream outStream = new FileOutputStream(mfile);
mf.write(outStream);
} catch (IOException e) {
e.printStackTrace();
}
}

public static Manifest parseManifestFromJAR(File jarFile)
{
Expand All @@ -59,9 +71,12 @@ public static Manifest parseManifestFromJAR(File jarFile)

public static String getUpdatedProvideCapabilities(Manifest manifest, String oldVersion){
String updatedProvidesCapabilities = ""; //$NON-NLS-1$
String newVersion = oldVersion;

Version versionObject = VersionParser.parseVersion(oldVersion);
String newVersion = versionObject.getMajor() + "." + versionObject.getMinor() + "." + versionObject.getMicro();
if (newVersion != null && newVersion.contains(".qualifier")) {
String vers[] = newVersion.split(".qualifier");
newVersion = vers[0];
}

if(manifest != null){
String capabilities = manifest.getMainAttributes().getValue(Constants.BUNDLE_PROVIDE_CAPABILITY);
Expand Down Expand Up @@ -96,4 +111,36 @@ public static String getUpdatedProvideCapabilities(Manifest manifest, String old

return updatedProvidesCapabilities;
}


public static String getRequiredCapabilities(String reqCapbilitySource, String newVersion){
if (newVersion != null && newVersion.contains(".qualifier")) {
String vers[] = newVersion.split(".qualifier");
newVersion = vers[0];
}

String processedText = "";
String[] entries = reqCapbilitySource.split(",");
for(int i = 0; i<entries.length; i++){
String entry = entries[i];
String[] filters = entry.split(";");
if(filters[0].trim().equals("com.tibco.bw.module") ){
if (filters[1].contains("version=")) {
String dependencies[] = filters[1].split("version=");
processedText += "," + filters[0] + ";";
processedText += dependencies[0];
processedText += "version=" + newVersion + "))\"";
}else {
processedText += "," + entry;
}
}else {
if (processedText.length() > 0) {
processedText += ",";
}
processedText += entry;
}
}

return processedText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,38 @@ public static File updateManifest(MavenProject project , Manifest mf) throws IOE
}


public static void updateManifestVersion(MavenProject project , Manifest mf, String qualifierReplacement)
public static void udpateManifestAttributes(MavenProject project , Manifest mf, String qualifierReplacement)
{
Attributes attributes = mf.getMainAttributes();

String projectVersion = project.getVersion();
if( projectVersion.indexOf("-SNAPSHOT") != -1 )
String bundleVersion = project.getVersion();
String archiveVersion = bundleVersion;
if( bundleVersion.indexOf("-SNAPSHOT") != -1 )
{
projectVersion = projectVersion.replace("-SNAPSHOT", ".qualifier");
projectVersion = getManifestVersion(mf, projectVersion, qualifierReplacement);
archiveVersion = bundleVersion.replace("-SNAPSHOT", ".qualifier");
bundleVersion = archiveVersion;
}

attributes.put(Name.MANIFEST_VERSION, projectVersion);
attributes.putValue(Constants.BUNDLE_VERSION, projectVersion );

archiveVersion = getManifestVersion(mf, archiveVersion, qualifierReplacement);
attributes.putValue(Constants.BUNDLE_VERSION, bundleVersion);
attributes.putValue(Constants.ARCHIVE_FILE_VERSION, archiveVersion);
//Updating provide capability for Shared Modules
if(BWProjectUtils.getModuleType(mf) == MODULE.SHAREDMODULE){
String updatedProvide = ManifestParser.getUpdatedProvideCapabilities(mf, projectVersion);
String updatedProvide = ManifestParser.getUpdatedProvideCapabilities(mf, bundleVersion);
attributes.putValue(Constants.BUNDLE_PROVIDE_CAPABILITY, updatedProvide);
}


if(BWProjectUtils.getModuleType(mf) == MODULE.APPLICATION || BWProjectUtils.getModuleType(mf) == MODULE.APPMODULE){
String reqCapbilityValue = attributes.getValue(Constants.BUNDLE_REQUIRE_CAPABILITY);
if (reqCapbilityValue != null) {
String requiredCapability = ManifestParser.getRequiredCapabilities(reqCapbilityValue, bundleVersion);
attributes.putValue(Constants.BUNDLE_REQUIRE_CAPABILITY, requiredCapability);
}
}
}

private static String getManifestVersion( Manifest manifest , String version, String qualifierReplacement)
{
return VersionParser.getcalculatedOSGiVersion(version, qualifierReplacement);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ public void execute() throws MojoExecutionException {
archiveConfiguration = new MavenArchiveConfiguration();
moduleVersionMap = new HashMap<String, String>();
manifest = ManifestParser.parseManifest(projectBasedir);
ManifestWriter.updateManifestVersion(project, manifest, Constants.TIMESTAMP);
ManifestWriter.udpateManifestAttributes(project, manifest, Constants.TIMESTAMP);
getLog().info("Updated the Manifest version ");
updateManifestVersion();
getLog().info("Adding Modules to the EAR file");
addModules();
getLog().info("Adding EAR Information to the EAR File");
Expand Down Expand Up @@ -436,24 +435,6 @@ public boolean accept(File pathname) {
return fileList[0];
}

// /**
// * Finds the JAR file for the Module.
// *
// * @param target the Module Output directory which is the target directory.
// *
// * @return the Module JAR.
// *
// * @throws Exception
// */
// private File getModuleJar(File target) throws Exception {
// File[] files = BWFileUtils.getFilesForType(target, ".jar");
// files = BWFileUtils.sortFilesByDateDesc(files);
// if(files.length == 0) {
// throw new Exception("Module is not built yet. Please check your Application PO for the Module entry.");
// }
// return files[0];
// }

/**
* Gets the Tibco XML file with the updated Module versions.
*
Expand Down Expand Up @@ -551,13 +532,4 @@ private void cleanup() {
}
getLog().debug("cleaned up the temporary files.");
}
/**
* Updated the Application manifest just like the module one
*/
private void updateManifestVersion() {
String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
String qualifierVersion = VersionParser.getcalculatedOSGiVersion(version, Constants.TIMESTAMP);
getLog().info("The OSGi verion is " + qualifierVersion + " for Maven version of " + version);
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, qualifierVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public void execute() throws MojoExecutionException {

getLog().info("Updated the Manifest version ");

ManifestWriter.updateManifestVersion(project, manifest, qualifierReplacement);
updateManifestVersion();
ManifestWriter.udpateManifestAttributes(project, manifest, qualifierReplacement);

getLog().info("Removing the externals entries if any. ");
removeExternals();
Expand Down Expand Up @@ -301,13 +300,6 @@ protected boolean isSharedModule(){
return manifest.getMainAttributes().getValue(Constants.TIBCO_SHARED_MODULE) == null ? false : true;
}

private void updateManifestVersion() {
String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
String qualifierVersion = VersionParser.getcalculatedOSGiVersion(version, qualifierReplacement);
getLog().info("The OSGi verion is " + qualifierVersion + " for Maven version of " + version);
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, qualifierVersion);
}

private void removeExternals() {
String bundlePath = manifest.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
getLog().debug("Bundle Classpath before removing externals is " + bundlePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
public interface Constants {
public static final String ADMINEXEC = "bwadmin";
public static final String BUNDLE_VERSION = "Bundle-Version";
public static final String ARCHIVE_FILE_VERSION = "Archive-File-Version";
public static final String BUNDLE_CLASSPATH = "Bundle-ClassPath";
public static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName";
public static final String BUNDLE_PROVIDE_CAPABILITY = "Provide-Capability";
public static final String BUNDLE_REQUIRE_CAPABILITY = "Require-Capability";
public static final String TIBCO_BW_EDITION = "TIBCO-BW-Edition";
public static final String BWCF = "bwcf";
public static final String PACKAGING_MODEL_NAMESPACE_URI = "http://schemas.tibco.com/tra/model/core/PackagingModel";
Expand Down