Skip to content
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

Add support for Jakarta EE 9.1 and higher #60

Merged
merged 3 commits into from
Jul 3, 2023
Merged
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
26 changes: 22 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<version>1.37.1</version>
</parent>
<artifactId>jcabi-manifests</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jcabi-manifests</name>
<description>Manager of MANIFEST.MF files</description>
<properties>
<snapshotVersion>2.0-SNAPSHOT</snapshotVersion>
<snapshotVersion>2.1.0-SNAPSHOT</snapshotVersion>
</properties>
<issueManagement>
<system>github</system>
Expand Down Expand Up @@ -69,14 +69,13 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</dependency>
<dependency>
<!--
Javax Servlet API 2.4. We're using this old version intentionally,
Javax Servlet API 2.5. We're using this old version intentionally,
in order to make the framework compatible with all possible (incl.
very old) web containers. See ticket #42 for more information.
-->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -85,6 +84,25 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<!--
Jakarta Servlet API 5.0.0. We're using this old version intentionally,
in order to make the framework compatible with all possible Jakarta
web containers (Jakarta 9.1 or higher)
-->
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/jcabi/manifests/JakartaServletMfs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2012-2022, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.manifests;

import com.jcabi.log.Logger;
import jakarta.servlet.ServletContext;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;

/**
* Manifests in servlet context.
*
* Append attributes from the web application {@code MANIFEST.MF}.
*
* <p>You can use this class in your own
* {@link jakarta.servlet.Filter} or
* {@link jakarta.servlet.ServletContextListener},
* in order to inject {@code MANIFEST.MF} attributes to the class:
*
* <pre> Manifests.append(new ServletMfs(context));</pre>
*
* <p>The class is thread-safe.
*
* @since 1.0
*/
public final class JakartaServletMfs implements Mfs {

/**
* Servlet context.
*/
private final transient ServletContext ctx;

/**
* Ctor.
* @param context Context
*/
public JakartaServletMfs(final ServletContext context) {
this.ctx = context;
}

@Override
public Collection<InputStream> fetch() throws IOException {
final URL main = this.ctx.getResource("/META-INF/MANIFEST.MF");
final Collection<InputStream> streams = new ArrayList<>(1);
if (main == null) {
Logger.warn(this, "MANIFEST.MF not found in WAR package");
} else {
streams.add(main.openStream());
}
return streams;
}

}
66 changes: 4 additions & 62 deletions src/main/java/com/jcabi/manifests/Manifests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package com.jcabi.manifests;

import com.jcabi.log.Logger;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
Expand All @@ -44,7 +43,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import javax.servlet.ServletContext;

/**
* Static reader of {@code META-INF/MANIFEST.MF} files.
Expand Down Expand Up @@ -77,12 +75,12 @@
* these attributes where it's necessary (in one of your JAXB annotated objects,
* for example) and show to users:
*
* <pre> import com.jcabi.manifests.Manifest;
* <pre> import com.jcabi.manifests.Manifest;
* import java.text.SimpleDateFormat;
* import java.util.Date;
* import java.util.Locale;
* import javax.xml.bind.annotation.XmlElement;
* import javax.xml.bind.annotation.XmlRootElement;
* import jakarta.xml.bind.annotation.XmlElement;
* import jakarta.xml.bind.annotation.XmlRootElement;
* &#64;XmlRootElement
* public final class Page {
* &#64;XmlElement
Expand Down Expand Up @@ -115,7 +113,7 @@
* &lt;/dependency></pre>
*
* @since 0.7
* @link <a href="http://download.oracle.com/javase/1,5.0/docs/guide/jar/jar.html#JAR%20Manifest">JAR Manifest</a>
* @link <a href="http://download.oracle.com/javase/1.5.0/docs/guide/jar/jar.html#JAR%20Manifest">JAR Manifest</a>
* @link <a href="http://maven.apache.org/shared/maven-archiver/index.html">Maven Archiver</a>
* @link <a href="http://manifests.jcabi.com/index.html">manifests.jcabi.com</a>
* @link <a href="http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html">How to Read MANIFEST.MF Files</a>
Expand Down Expand Up @@ -288,62 +286,6 @@ public static boolean exists(final String name) {
return Manifests.singleton().containsKey(name);
}

/**
* Append attributes from the web application {@code MANIFEST.MF}.
*
* <p>The method is deprecated. Instead, use this code:
*
* <pre>Manifests.DEFAULT.append(new ServletMfs());</pre>
*
* @param ctx Servlet context
* @see #Manifests()
* @throws IOException If some I/O problem inside
* @deprecated Use {@link #append(Mfs)} and {@link ServletMfs} instead
*/
@Deprecated
public static void append(final ServletContext ctx) throws IOException {
Manifests.singleton().append(new ServletMfs(ctx));
}

/**
* Append attributes from the file.
*
* <p>The method is deprecated. Instead, use this code:
*
* <pre>Manifests.DEFAULT.append(new FilesMfs(file));</pre>
*
* @param file The file to load attributes from
* @throws IOException If some I/O problem inside
* @deprecated Use {@link #append(Mfs)} and {@link FilesMfs} instead
*/
@Deprecated
public static void append(final File file) throws IOException {
if (file == null) {
throw new IllegalArgumentException("file can't be NULL");
}
Manifests.singleton().append(new FilesMfs(file));
}

/**
* Append attributes from input stream.
*
* <p>The method is deprecated. Instead, use this code:
*
* <pre>Manifests.DEFAULT.append(new StreamsMfs(stream));</pre>
*
* @param stream Stream to use
* @throws IOException If some I/O problem inside
* @since 0.8
* @deprecated Use {@link #append(Mfs)} and {@link StreamsMfs} instead
*/
@Deprecated
public static void append(final InputStream stream) throws IOException {
if (stream == null) {
throw new IllegalArgumentException("input stream can't be NULL");
}
Manifests.singleton().append(new StreamsMfs(stream));
}

/**
* Load attributes from input stream.
*
Expand Down
6 changes: 3 additions & 3 deletions src/site/apt/index.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ Foo-Version: 1.0-SNAPSHOT

+--
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
+--
Expand Down
Loading