Class Manifests
- java.lang.Object
-
- com.jcabi.manifests.Manifests
-
- All Implemented Interfaces:
MfMap
public final class Manifests extends Object implements MfMap
Static reader ofMETA-INF/MANIFEST.MFfiles. The class provides convenient methods to read allMANIFEST.MFfiles available in classpath and all attributes from them.This mechanism may be very useful for transferring information from continuous integration environment to the production environment. For example, you want your site to show project version and the date of
WARfile packaging. First, you configuremaven-war-pluginto add this information toMANIFEST.MF:<plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <archive> <manifestEntries> <Foo-Version>${project.version}</Foo-Version> <Foo-Date>${maven.build.timestamp}</Foo-Date> </manifestEntries> </archive> </configuration> </plugin>maven-war-pluginwill add these attributes to yourMANIFEST.MFfile and the project will be deployed to the production environment. Then, you can read these attributes where it's necessary (in one of your JAXB annotated objects, for example) and show to users:import com.jcabi.manifests.Manifest; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; @XmlRootElement public final class Page { @XmlElement public String version() { return Manifests.read("Foo-Version"); } @XmlElement public Date date() { return new SimpleDateFormat("yyyy.MM.dd", Locale.ENGLISH).parse( Manifests.read("Foo-Date"); ); } }If you want to add more manifests to the collection, use its static instance:
Manifests.singleton().append(new FilesMfs(new File("MANIFEST.MF")));You can also modify the map directly:
Manifests.singleton().put("Hello", "world");The only dependency you need (check the latest version at jcabi-manifests):
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-manifests</artifactId> </dependency>
- Since:
- 0.7
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(Mfs mfs)Append this collection of MANIFEST.MF files.booleancontainsKey(String key)Check if attributes map contains the given key.booleancontainsValue(String value)Check if attributes map contains the given value.static booleanexists(String name)Check whether attribute exists in any ofMANIFEST.MFfiles.Stringget(String key)Get attribute value by its key.Map<String,String>getAsMap()Get a copy of attributes map.booleanisEmpty()Check if attributes map is empty.Set<String>keySet()Get a copy of a set of attributes keys.static Stringread(String name)Read one attribute available in one ofMANIFEST.MFfiles.static MfMapsingleton()Get the singleton.intsize()Get size of attributes map.
-
-
-
Method Detail
-
singleton
public static MfMap singleton()
Get the singleton.- Returns:
- The singleton
- Since:
- 2.0.0
-
size
public int size()
Description copied from interface:MfMapGet size of attributes map.
-
isEmpty
public boolean isEmpty()
Description copied from interface:MfMapCheck if attributes map is empty.
-
containsKey
public boolean containsKey(String key)
Description copied from interface:MfMapCheck if attributes map contains the given key.- Specified by:
containsKeyin interfaceMfMap- Parameters:
key- Attribute name- Returns:
- True if attributes map contains the given key and false otherwise
-
containsValue
public boolean containsValue(String value)
Description copied from interface:MfMapCheck if attributes map contains the given value.- Specified by:
containsValuein interfaceMfMap- Parameters:
value- Attribute value- Returns:
- True if attributes map contains the given value and false otherwise
-
get
public String get(String key)
Description copied from interface:MfMapGet attribute value by its key.
-
getAsMap
public Map<String,String> getAsMap()
Description copied from interface:MfMapGet a copy of attributes map.
-
keySet
public Set<String> keySet()
Description copied from interface:MfMapGet a copy of a set of attributes keys.
-
append
public void append(Mfs mfs) throws IOException
Description copied from interface:MfMapAppend this collection of MANIFEST.MF files. This method changes the original instance.- Specified by:
appendin interfaceMfMap- Parameters:
mfs- Content to append- Throws:
IOException- If fails on I/O problem
-
read
public static String read(String name)
Read one attribute available in one ofMANIFEST.MFfiles.If such a attribute doesn't exist
IllegalArgumentExceptionwill be thrown. If you're not sure whether the attribute is present or not useexists(String)beforehand.The method is thread-safe.
- Parameters:
name- Name of the attribute- Returns:
- The value of the attribute retrieved
-
exists
public static boolean exists(String name)
Check whether attribute exists in any ofMANIFEST.MFfiles.Use this method before
read(String)to check whether an attribute exists, in order to avoid a runtime exception.The method is thread-safe.
- Parameters:
name- Name of the attribute to check- Returns:
- Returns
TRUEif it exists,FALSEotherwise
-
-