private void mergeSection(String section, DefaultManifest mergedManifest, Attributes baseAttributes, Attributes mergeAttributes) { Map<String, Object> mergeOnlyAttributes = new LinkedHashMap<String, Object>(mergeAttributes); Set<DefaultManifestMergeDetails> mergeDetailsSet = new LinkedHashSet<DefaultManifestMergeDetails>(); for (Map.Entry<String, Object> baseEntry : baseAttributes.entrySet()) { Object mergeValue = mergeAttributes.get(baseEntry.getKey()); mergeDetailsSet.add(getMergeDetails(section, baseEntry.getKey(), baseEntry.getValue(), mergeValue)); mergeOnlyAttributes.remove(baseEntry.getKey()); } for (Map.Entry<String, Object> mergeEntry : mergeOnlyAttributes.entrySet()) { mergeDetailsSet.add(getMergeDetails(section, mergeEntry.getKey(), null, mergeEntry.getValue())); } for (DefaultManifestMergeDetails mergeDetails : mergeDetailsSet) { for (Action<? super ManifestMergeDetails> action : actions) { action.execute(mergeDetails); } addMergeDetailToManifest(section, mergedManifest, mergeDetails); } }
@Override public DefaultManifest getEffectiveManifest() { ContainedVersionAnalyzer analyzer = analyzerFactory.create(); DefaultManifest effectiveManifest = new DefaultManifest(null); try { setAnalyzerProperties(analyzer); Manifest osgiManifest = analyzer.calcManifest(); java.util.jar.Attributes attributes = osgiManifest.getMainAttributes(); for (Map.Entry<Object, Object> entry : attributes.entrySet()) { effectiveManifest.attributes(WrapUtil.toMap(entry.getKey().toString(), (String) entry.getValue())); } effectiveManifest.attributes(this.getAttributes()); for (Map.Entry<String, Attributes> ent : getSections().entrySet()) { effectiveManifest.attributes(ent.getValue(), ent.getKey()); } if (classesDir != null) { long mod = classesDir.lastModified(); if (mod > 0) { effectiveManifest.getAttributes().put(Analyzer.BND_LASTMODIFIED, mod); } } } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } return getEffectiveManifestInternal(effectiveManifest); }
private static String generateSingleLine(Attributes attributes) { StringBuilder sb = new StringBuilder("<componentelement "); //intentional extra space appendAttribute(sb, "name", attributes.get("keyname")); appendAttribute(sb, "vendor", attributes.get("keyvendor")); appendAttribute(sb, "componenttype", attributes.get("archivetype")); appendAttribute(sb, "subsystem", "NO_SUBSYS"); appendAttribute(sb, "location", attributes.get("keylocation")); appendAttribute(sb, "counter", attributes.get("keycounter")); appendAttribute(sb, "deltaversion", "F"); appendAttribute(sb, "updateversion", generateUpdateVersion(attributes)); appendAttribute(sb, "componentprovider", "SAP AG"); appendAttribute(sb, "archivetype", attributes.get("archivetype")); sb.append("/>"); return sb.toString(); }
public void addSapDefaults() { Attributes attributes = getAttributes(); attributes.put("Ext-SDM-SDA-Comp-Version", "1"); attributes.put("softwaretype", "J2EE"); attributes.put("JarSAP-Standalone-Version", "20090803.1000"); attributes.put("JarSAPProcessing-Version", "20090907.1000"); attributes.put("deployfile", "sda-dd.xml"); attributes.put("archivetype", "DC"); attributes.put("JarSAP-Version", "20090803.1000"); attributes.put("keyname", ""); //placeholder in (ordered) LinkedHashMap attributes.put("keyvendor", "sap.com"); attributes.put("keylocation", "localhost"); attributes.put("keycounter", generateManifestDate()); attributes.put("componentelement", ""); //placeholder in (ordered) LinkedHashMap attributes.put("dependencies", ""); //placeholder in (ordered) LinkedHashMap attributes.put("dependencyList", ""); //placeholder in (ordered) LinkedHashMap attributes.put("JarSL-Version", "20100616.1800"); attributes.put("compress", "true"); }
private static void addSectionAttributesToJavaManifest(org.gradle.api.java.archives.Manifest gradleManifest, Manifest javaManifest) { for (Map.Entry<String, Attributes> entry : gradleManifest.getSections().entrySet()) { String sectionName = entry.getKey(); java.util.jar.Attributes sectionAttributes = new java.util.jar.Attributes(); for (Map.Entry<String, Object> attribute : entry.getValue().entrySet()) { String attributeName = attribute.getKey(); String attributeValue = attribute.getValue().toString(); sectionAttributes.putValue(attributeName, attributeValue); } javaManifest.getEntries().put(sectionName, sectionAttributes); } }
private void addJavaManifestToSections(Manifest javaManifest) { for (Map.Entry<String, java.util.jar.Attributes> sectionEntry : javaManifest.getEntries().entrySet()) { String sectionName = sectionEntry.getKey(); DefaultAttributes sectionAttributes = new DefaultAttributes(); for (Object attributeKey : sectionEntry.getValue().keySet()) { String attributeName = attributeKey.toString(); String attributeValue = sectionEntry.getValue().getValue(attributeName); sectionAttributes.put(attributeName, attributeValue); } sections.put(sectionName, sectionAttributes); } }
@Override public Object put(String key, Object value) { if (key == null) { throw new ManifestException("The key of a manifest attribute must not be null."); } if (value == null) { throw new ManifestException(String.format("The value of a manifest attribute must not be null (Key=%s).", key)); } try { new java.util.jar.Attributes.Name(key); } catch (IllegalArgumentException e) { throw new ManifestException(String.format("The Key=%s violates the Manifest spec!", key)); } return attributes.put(key, value); }
private void addSectionAttributesToAnt(Manifest antManifest) { for (Map.Entry<String, Attributes> entry : sections.entrySet()) { Section section = new Section(); section.setName(entry.getKey()); try { antManifest.addConfiguredSection(section); for (Map.Entry<String, Object> attributeEntry : entry.getValue().entrySet()) { section.addConfiguredAttribute(new Attribute(attributeEntry.getKey(), attributeEntry.getValue().toString())); } } catch (ManifestException e) { throw new org.gradle.api.java.archives.ManifestException(e.getMessage(), e); } } }
public Object put(String key, Object value) { if (key == null) { throw new ManifestException("The key of a manifest attribute must not be null."); } if (value == null) { throw new ManifestException("The value of a manifest attribute must not be null."); } try { new java.util.jar.Attributes.Name(key); } catch(IllegalArgumentException e) { throw new ManifestException(String.format("The Key=%s violates the Manifest spec!", key)); } return attributes.put(key, value); }
private void addSectionAttributesToAnt(Manifest antManifest) { for (Map.Entry<String, Attributes> entry : sections.entrySet()) { Section section = new Section(); section.setName(entry.getKey()); try { antManifest.addConfiguredSection(section); for (Map.Entry<String, Object> attributeEntry : entry.getValue().entrySet()) { section.addConfiguredAttribute(new Attribute(attributeEntry.getKey().toString(), attributeEntry.getValue().toString())); } } catch (ManifestException e) { throw new org.gradle.api.java.archives.ManifestException(e.getMessage(), e); } } }
/** * Configures new MANIFEST.MF with some defaults. Can be overridden in build.gradle */ private void configureManifest(final Project project, final NWEarPluginConvention earPluginConvention, final NWEar earTask) { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); Manifest manifest = javaConvention.manifest(); //generates new DefaultManifest Attributes attributes = manifest.getAttributes(); String nowString = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); attributes.put("Implementation-Version", nowString); attributes.put("Implementation-Title", project.getName()); attributes.put("Implementation-Vendor-Id", project.getGroup().toString()); attributes.put("Specification-Vendor", "SAP AG"); earTask.setManifest(manifest); }
private static final String generateUpdateVersion(Attributes attributes) { try { String manifestDate = (String)attributes.get("keycounter"); if (manifestDate==null) { throw new ManifestException("keycounter not found in SAP_MANIFEST attributes"); } Date date = new SimpleDateFormat(SAPManifest.MANIFEST_DATE_FORMAT).parse(manifestDate); return "LB-" + (new SimpleDateFormat(UPDATEVERSION_DATE_FORMAT)).format(date); } catch (ParseException e) { throw new ManifestException(e.getMessage(), e); } }
@Override public DefaultManifest getEffectiveManifest() { Attributes attributes = getAttributes(); String keyname = (String)attributes.get("keyname"); if (keyname==null || keyname.isEmpty()) { throw new ManifestException("keyname needs to be set before getting effective manifest"); } attributes.put("componentelement", ComponentElementHelper.generate(attributes)); // System.out.println("SAPManifest.getEffectiveManifest~includeDependencies:" +includeDependencies); // System.out.println("SAPManifest.getEffectiveManifest~applicationJ2eeEngineFile:" +applicationJ2eeEngineFile); boolean hasDependencies = false; if (includeDependencies && applicationJ2eeEngineFile!=null) { //deferred application-j2ee-engine.xml parse final ApplicationJ2eeEngineHelper applicationJ2eeEngineHelper = new ApplicationJ2eeEngineHelper(); applicationJ2eeEngineHelper.setSourceFile(applicationJ2eeEngineFile).parse(); hasDependencies = applicationJ2eeEngineHelper.hasReferences(); if (hasDependencies) { String dependencies = applicationJ2eeEngineHelper.toDependencies().toString(); attributes.put("dependencies", ManifestStringSplitter.splitIt(dependencies)); //System.out.println(ManifestStringSplitter.splitIt(dependencies)); String dependencyList = applicationJ2eeEngineHelper.toDependencyList().toString(); attributes.put("dependencyList", ManifestStringSplitter.splitIt(dependencyList)); //System.out.println(ManifestStringSplitter.splitIt(dependencyList)); } } if (!hasDependencies) { attributes.remove("dependencies"); attributes.remove("dependencyList"); } //System.out.println("SAPManifest.getEffectiveManifest() - attributes.get("componentelement")); return super.getEffectiveManifest(); }
@Override public DefaultManifest writeTo(Writer writer) { Attributes attributes = getEffectiveManifest().getAttributes(); PrintWriter printWriter = new PrintWriter(writer); for (Map.Entry<String, Object> entry : attributes.entrySet()) { printWriter.println(entry.getKey() + ": " + entry.getValue()); } printWriter.println(); printWriter.flush(); return this; }
@Test public void testGenerateWithDefaults() { Attributes attributes = generateAttributes(); String generated = ComponentElementHelper.generate(attributes); System.out.println(generated); // Assert.assertEquals(EXPECTED, generated); }
@Test public void testGenerateWithProject() { Attributes attributes = generateAttributes(); attributes.put("keyname", "MyTestProject"); attributes.put("keyvendor", "example.com"); String generated = ComponentElementHelper.generate(attributes); System.out.println(generated); //Assert.assertEquals(EXPECTED, generated); }
/** * Add build timestamp to some manifest attributes in the execution phase, so that it does not count for the * up-to-date check. * * @param pTask the executing task * @param pAttributes the attributes map to add to */ public void addBuildTimestampDeferred(@Nonnull final Task pTask, @Nonnull final Attributes pAttributes) { pTask.doFirst(new Closure<Void>(pTask) { @Override @SuppressWarnings("MethodDoesntCallSuperMethod") public Void call() { addBuildTimestamp(pAttributes); return null; } }); }
@Override public Attributes getAttributes() { return attributes; }
@Override public Map<String, Attributes> getSections() { return sections; }
@Override public Attributes getAttributes() { return delegate.getAttributes(); }
@Override public Map<String, Attributes> getSections() { return delegate.getSections(); }
/** Takes an action on a Bnd jar. */ private static void takeBndAction(Project project, Throwing.Consumer<aQute.bnd.osgi.Jar> onBuilder) { ProjectPlugin.getPlugin(project, JavaPlugin.class); Jar jarTask = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME); Errors.rethrow().run(() -> { try (Builder builder = new Builder()) { // set the base folder builder.setBase(project.getProjectDir()); // copy all properties from jar.manifest.attributes into the bnd Builder Attributes attr = jarTask.getManifest().getEffectiveManifest().getAttributes(); for (Map.Entry<String, Object> entry : attr.entrySet()) { builder.set(entry.getKey(), entry.getValue().toString()); } // set the classpath for manifest calculation Set<File> runtimeConfig = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME).getFiles(); builder.addClasspath(runtimeConfig); // put the class files and resources into the jar JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSetOutput main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput(); // delete empty folders so that bnd doesn't make Export-Package entries for them deleteEmptyFoldersIfExists(main.getClassesDir()); deleteEmptyFoldersIfExists(main.getResourcesDir()); builder.set(Constants.INCLUDERESOURCE, main.getClassesDir() + "," + main.getResourcesDir()); // set the version if (builder.getBundleVersion() == null) { try { String version = project.getVersion().toString(); if (version.endsWith("-SNAPSHOT")) { version = version.replace("-SNAPSHOT", ".I" + dateQualifier()); } builder.setBundleVersion(version); } catch (Exception e) { project.getLogger().warn(e.getMessage() + " Must be 'major.minor.micro.qualifier'"); builder.setBundleVersion("0.0.0.ERRORSETVERSION"); } } // take an action with the builder onBuilder.accept(builder.build()); } }); }
public Attributes getAttributes() { return attributes; }
public Map<String, Attributes> getSections() { return sections; }
public static String generate(Attributes attributes) { String singleLine = generateSingleLine(attributes); return ManifestStringSplitter.splitIt(singleLine); }
public void updateProjectDetails(final Project project) { Attributes attributes = getAttributes(); attributes.put("keyname", project.getName()); attributes.put("keyvendor", project.getGroup().toString()); }
private Attributes generateAttributes() { SAPManifest createSAPManifest = SAPManifestTest.createSAPManifest(); Attributes attributes = createSAPManifest.getAttributes(); return attributes; }
private void setManifestAttributes(@Nonnull final Attributes pAttributes, @Nonnull final TaskInputs pInputs, @Nonnull final DependencyConfig pDepConfig, @Nonnull final Set<File> pPubLibs) { final String baseCsVersion = pDepConfig.getCheckstyleBaseVersion(); final Map<String, Object> inputProps = pInputs.getProperties(); final Jar jarTask = (Jar) getBuildUtil().getTask(TaskNames.jar, pDepConfig); pAttributes.clear(); pAttributes.put("Plugin-Name", inputProps.get("name")); pAttributes.put("Plugin-Base", "checkstyle"); pAttributes.put("Plugin-Key", inputProps.get("sqPluginKey")); pAttributes.put("Implementation-Build", inputProps.get("gitHash")); pAttributes.put("Plugin-Description", inputProps.get("description") + " (based on Checkstyle " + baseCsVersion + ")"); pAttributes.put("Plugin-Version", inputProps.get(BuildUtil.VERSION)); pAttributes.put("Plugin-Organization", inputProps.get("authorName")); pAttributes.put("Plugin-OrganizationUrl", inputProps.get("orgUrl")); pAttributes.put("Plugin-SourcesUrl", "https://github.com/checkstyle-addons/checkstyle-addons"); pAttributes.put("Plugin-IssueTrackerUrl", inputProps.get("issueTrackerUrl")); pAttributes.put("Plugin-Class", "com.thomasjensen.checkstyle.addons.sonarqube.CheckstyleExtensionPlugin"); pAttributes.put("Plugin-RequirePlugins", "java:" + pDepConfig.getSonarQubeMinJavaPluginVersion() // + ",checkstyle:" + pDepConfig.getSonarQubeMinCsPluginVersion()); pAttributes.put("Plugin-Dependencies", "META-INF/lib/" + jarTask.getArchiveName() // + (pPubLibs.size() > 0 ? " " : "") // + CreateJarEclipseTask.flattenPrefixLibs("META-INF/lib/", pPubLibs, ' ')); pAttributes.put("Plugin-License", "GPLv3"); pAttributes.put("Plugin-Homepage", inputProps.get("website")); //attrs.put("Plugin-TermsConditionsUrl", ""); // TODO use same SonarQube version in manifest and compile dependencies pAttributes.put("Sonar-Version", pDepConfig.getSonarQubeMinPlatformVersion()); pAttributes.putAll(CreateJarTask.mfAttrStd(getProject())); pAttributes.remove("Website"); doFirst(new Closure<Void>(this) { @Override @SuppressWarnings("MethodDoesntCallSuperMethod") public Void call() { final DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); // required by SonarQube pAttributes.put("Plugin-BuildDate", sdf.format(getBuildUtil().getExtraPropertyValue(ExtProp.BuildTimestamp))); return null; } }); }
private void addBuildTimestamp(@Nonnull final Attributes pAttributes) { pAttributes.put("Build-Timestamp", getExtraPropertyValue(ExtProp.BuildTimestamp).toString()); }