![JAR search and dependency download from the Maven repository](/logo.png)
org.carlspring.maven.commons.io.PomJarReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-commons Show documentation
Show all versions of maven-commons Show documentation
A library for common Maven operations.
The newest version!
package org.carlspring.maven.commons.io;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
/**
* @author mtodorov
*/
public class PomJarReader implements Closeable
{
public static final String PLUGIN_XML = "/META-INF/maven/plugin.xml";
private Path jarPath;
private FileSystem fileSystem;
public PomJarReader()
{
}
public PomJarReader(Path jarPath)
{
this.jarPath = jarPath;
}
public InputStream getInputStream()
throws IOException, URISyntaxException
{
URI jarUri = new URI("jar:" + jarPath.toUri().toString());
Map env = new HashMap<>();
fileSystem = FileSystems.newFileSystem(jarUri, env);
Path pathInZip = fileSystem.getPath(PLUGIN_XML);
return Files.newInputStream(pathInZip.toAbsolutePath());
}
public Path getJarPath()
{
return jarPath;
}
public void setJarPath(Path jarPath)
{
this.jarPath = jarPath;
}
@Override
public void close()
throws IOException
{
if (fileSystem != null)
{
fileSystem.close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy