use of org.jetbrains.osgi.jps.model.ManifestGenerationMode in project intellij-plugins by JetBrains.
the class OsgiBuildSession method doBuild.
private void doBuild() throws OsgiBuildException {
progress("Running Bnd to build the bundle");
if (myExtension.isUseBndFile()) {
String bndPath = myExtension.getBndFileLocation();
File bndFile = OsgiBuildUtil.findFileInModuleContentRoots(myModule, bndPath);
if (bndFile == null || !bndFile.isFile()) {
throw new OsgiBuildException("Bnd file missing '" + bndPath + "' - please check OSGi facet settings.");
}
mySourceToReport = bndFile.getAbsolutePath();
try {
myBndWrapper.build(bndFile, myClasses, mySources, myOutputJarFile);
} catch (Exception e) {
throw new OsgiBuildException("Unexpected build error", e, null);
}
mySourceToReport = null;
} else if (myExtension.isUseBundlorFile()) {
String bundlorPath = myExtension.getBundlorFileLocation();
File bundlorFile = OsgiBuildUtil.findFileInModuleContentRoots(myModule, bundlorPath);
if (bundlorFile == null) {
throw new OsgiBuildException("Bundlor file missing '" + bundlorPath + "' - please check OSGi facet settings.");
}
File tempFile = new File(myOutputJarFile.getAbsolutePath() + ".tmp.jar");
try {
Map<String, String> properties = Collections.singletonMap(Constants.CREATED_BY, "IntelliJ IDEA / OSGi Plugin");
myBndWrapper.build(properties, myClasses, mySources, tempFile);
} catch (Exception e) {
throw new OsgiBuildException("Unexpected build error", e, null);
}
progress("Running Bundlor to calculate the manifest");
try {
Properties properties = OsgiBuildUtil.getMavenProjectProperties(myContext, myModule);
List<String> warnings = new BundlorWrapper().wrapModule(properties, tempFile, myOutputJarFile, bundlorFile);
for (String warning : warnings) {
warning(warning, null, bundlorFile.getPath(), -1);
}
} finally {
if (!FileUtil.delete(tempFile)) {
warning("Can't delete temporary file '" + tempFile + "'", null, null, -1);
}
}
} else if (myExtension.isManifestManuallyEdited() || myExtension.isOsmorcControlsManifest()) {
Map<String, String> buildProperties = getBuildProperties();
if (LOG.isDebugEnabled()) {
LOG.debug("build properties: " + buildProperties);
}
mySourceToReport = getSourceFileToReport();
try {
myBndWrapper.build(buildProperties, myClasses, mySources, myOutputJarFile);
} catch (Exception e) {
throw new OsgiBuildException("Unexpected build error", e, null);
}
mySourceToReport = null;
} else {
ManifestGenerationMode mode = ((JpsOsmorcModuleExtensionImpl) myExtension).getProperties().myManifestGenerationMode;
throw new OsgiBuildException("Internal error (unknown build method `" + mode + "`)");
}
}
use of org.jetbrains.osgi.jps.model.ManifestGenerationMode in project intellij-plugins by JetBrains.
the class OsmorcFacetConfiguration method readExternal.
@Override
public void readExternal(Element element) {
if (element.getAttributeValue(MANIFEST_GENERATION_MODE) == null) {
// the new attribute is not there, so we got an old file, to be converted.
// legacy files containing boolean values
boolean osmorcControlsManifest = Boolean.parseBoolean(element.getAttributeValue(OSMORC_CONTROLS_MANIFEST, "true"));
boolean useBndFile = Boolean.parseBoolean(element.getAttributeValue(USE_BND_FILE, "false"));
boolean useBundlorFile = Boolean.parseBoolean(element.getAttributeValue(USE_BUNDLOR_FILE, "false"));
// default is that osmorc controls the manifest, so set this in case the config file has been manually edited or is otherwise invalid
setManifestGenerationMode(ManifestGenerationMode.OsmorcControlled);
if (osmorcControlsManifest && !useBndFile && !useBundlorFile) {
setManifestGenerationMode(ManifestGenerationMode.OsmorcControlled);
} else if ((!osmorcControlsManifest && useBndFile && !useBundlorFile) || (/* workaround */
osmorcControlsManifest && useBndFile && !useBundlorFile)) {
setManifestGenerationMode(ManifestGenerationMode.Bnd);
} else if (!osmorcControlsManifest && !useBndFile && useBundlorFile) {
setManifestGenerationMode(ManifestGenerationMode.Bundlor);
} else if (!osmorcControlsManifest && !useBndFile) {
setManifestGenerationMode(ManifestGenerationMode.Manually);
} else {
String message = "The configuration at least one OSGi facet is invalid and has been reset. Please check your facet settings!";
OsmorcProjectComponent.IMPORTANT_NOTIFICATIONS.createNotification(message, NotificationType.WARNING).notify(myFacet.getModule().getProject());
}
} else {
// attribute it there, read it.
String manifestGenerationModeName = element.getAttributeValue(MANIFEST_GENERATION_MODE, ManifestGenerationMode.OsmorcControlled.name());
ManifestGenerationMode manifestGenerationMode = ManifestGenerationMode.valueOf(manifestGenerationModeName);
setManifestGenerationMode(manifestGenerationMode);
}
setBndFileLocation(element.getAttributeValue(BND_FILE_LOCATION));
setBundlorFileLocation(element.getAttributeValue(BUNDLOR_FILE_LOCATION));
setManifestLocation(element.getAttributeValue(MANIFEST_LOCATION));
String outputPathTypeName = element.getAttributeValue(OUTPUT_PATH_TYPE, OutputPathType.SpecificOutputPath.name());
OutputPathType outputPathType = OutputPathType.valueOf(outputPathTypeName);
setJarFileLocation(element.getAttributeValue(JAR_FILE_LOCATION), outputPathType);
setBundleActivator(element.getAttributeValue(BUNDLE_ACTIVATOR));
setBundleSymbolicName(element.getAttributeValue(BUNDLE_SYMBOLIC_NAME));
setBundleVersion(element.getAttributeValue(BUNDLE_VERSION));
setIgnoreFilePattern(element.getAttributeValue(IGNORE_FILE_PATTERN));
setUseProjectDefaultManifestFileLocation(Boolean.parseBoolean(element.getAttributeValue(USE_PROJECT_DEFAULT_MANIFEST_FILE_LOCATION, "true")));
setAlwaysRebuildBundleJAR(Boolean.parseBoolean(element.getAttributeValue(ALWAYS_REBUILD_BUNDLE_JAR, "false")));
setDoNotSynchronizeWithMaven(Boolean.parseBoolean(element.getAttributeValue(DO_NOT_SYNCHRONIZE_WITH_MAVEN, "false")));
Element props = element.getChild(ADDITIONAL_PROPERTIES);
if (props != null) {
List children = props.getChildren();
if (children.isEmpty()) {
// ok this is a legacy file
setAdditionalProperties(props.getText());
} else {
StringBuilder builder = new StringBuilder();
// new handling as fix for OSMORC-43
for (Object child : children) {
Element prop = (Element) child;
builder.append(prop.getAttributeValue(KEY)).append(":").append(prop.getAttributeValue(VALUE)).append("\n");
}
setAdditionalProperties(builder.toString());
}
}
List<Pair<String, String>> additionalJARContents = getAdditionalJARContents();
Element additionalJARContentsElement = element.getChild("additionalJARContents");
if (additionalJARContentsElement != null) {
@SuppressWarnings({ "unchecked" }) List<Element> children = additionalJARContentsElement.getChildren("entry");
for (Element entryElement : children) {
additionalJARContents.add(Pair.create(entryElement.getAttributeValue("source"), entryElement.getAttributeValue("dest")));
}
}
myModificationCount++;
}
Aggregations