protected void reimportFacet(MavenModifiableModelsProvider modelsProvider, Module module,
MavenRootModelAdapter mavenRootModelAdapter, OsmorcFacet osmorcFacet,
MavenProjectsTree mavenProjectsTree, MavenProject mavenProject,
MavenProjectChanges changes, Map<MavenProject, String> mavenProjectStringMap,
List<MavenProjectsProcessorTask> mavenProjectsProcessorPostConfigurationTasks) {
OsmorcFacetConfiguration conf = osmorcFacet.getConfiguration();
if (conf.isDoNotSynchronizeWithMaven()) {
return;
}
// first off, we get the defaults
MavenId id = mavenProject.getMavenId();
conf.setBundleSymbolicName(id.getGroupId() + "." + id.getArtifactId());
conf.setBundleVersion(ImporterUtil.cleanupVersion(id.getVersion()));
MavenPlugin plugin = mavenProject.findPlugin(myPluginGroupID, myPluginArtifactID);
if (plugin == null) {
return;
}
// Check if there are any overrides set up in the maven plugin settings
conf.setBundleSymbolicName(computeSymbolicName(mavenProject)); // IDEA-63243
Map<String, String> props = ContainerUtil.newLinkedHashMap(); // to preserve the order of elements
Map<String, String> modelMap = mavenProject.getModelMap();
String description = modelMap.get("description");
if (!StringUtil.isEmptyOrSpaces(description)) {
props.put(Constants.BUNDLE_DESCRIPTION, description);
}
String licenses = modelMap.get("licenses");
if (!StringUtil.isEmptyOrSpaces(licenses)) {
props.put("Bundle-License", licenses);
}
String vendor = modelMap.get("organization.name");
if (!StringUtil.isEmpty(vendor)) {
props.put(Constants.BUNDLE_VENDOR, vendor);
}
String docUrl = modelMap.get("organization.url");
if (!StringUtil.isEmptyOrSpaces(docUrl)) {
props.put(Constants.BUNDLE_DOCURL, docUrl);
}
// load versions if any
Map<String, String> versions = cleanVersions(plugin);
// now find any additional properties that might have been set up:
Element instructionsNode = getConfig(mavenProject, "instructions");
if (instructionsNode != null) {
boolean useExistingManifest = false;
for (Element child : instructionsNode.getChildren()) {
String name = child.getName();
String value = child.getTextTrim();
value = value.replaceAll("\\p{Blank}*[\r\n]\\p{Blank}*", "");
value = substituteVersions(value, versions);
if (INCLUDE_MANIFEST.equals(name)) {
conf.setManifestLocation(value);
conf.setManifestGenerationMode(ManifestGenerationMode.Manually);
conf.setUseProjectDefaultManifestFileLocation(false);
useExistingManifest = true;
}
else if (Constants.BUNDLE_VERSION.equals(name)) {
conf.setBundleVersion(value);
}
else if (Constants.BUNDLE_ACTIVATOR.equals(name)) {
conf.setBundleActivator(value);
}
else if (!StringUtil.isEmpty(value) && !Constants.BUNDLE_SYMBOLICNAME.equals(name)) {
if (StringUtil.startsWithChar(name, '_')) {
name = "-" + name.substring(1); // sanitize instructions
}
props.put(name, value);
}
}
if (!useExistingManifest) {
conf.setManifestLocation("");
conf.setManifestGenerationMode(ManifestGenerationMode.OsmorcControlled);
conf.setUseProjectDefaultManifestFileLocation(true);
}
// check if bundle name exists, if not compute it (IDEA-63244)
if (!props.containsKey(Constants.BUNDLE_NAME)) {
props.put(Constants.BUNDLE_NAME, computeBundleName(mavenProject));
}
}
// now post-process the settings, to make Embed-Dependency work
ImporterUtil.postProcessAdditionalProperties(props, mavenProject);
// Fix for IDEA-63242 - don't merge it with the existing settings, overwrite them
conf.importAdditionalProperties(props, true);
// Fix for IDEA-66235 - inherit jar filename from maven
String jarFileName = mavenProject.getFinalName() + ".jar";
// FiX for IDEA-67088, preserve existing output path settings on reimport.
switch (conf.getOutputPathType()) {
case OsgiOutputPath:
conf.setJarFileLocation(jarFileName, OutputPathType.OsgiOutputPath);
break;
case SpecificOutputPath:
String path = new File(conf.getJarFilePath(), jarFileName).getPath();
conf.setJarFileLocation(path, OutputPathType.SpecificOutputPath);
break;
default:
conf.setJarFileLocation(jarFileName, OutputPathType.CompilerOutputPath);
}
}