use of java.util.jar.JarEntry in project hudson-2.x by hudson.
the class JellyTestSuiteBuilder method build.
/**
* Given a jar file or a class file directory, recursively search all the Jelly files and build a {@link TestSuite}
* that performs static syntax checks.
*/
public static TestSuite build(File res) throws Exception {
TestSuite ts = new JellyTestSuite();
final JellyClassLoaderTearOff jct = new MetaClassLoader(JellyTestSuiteBuilder.class.getClassLoader()).loadTearOff(JellyClassLoaderTearOff.class);
if (res.isDirectory()) {
for (final File jelly : (Collection<File>) FileUtils.listFiles(res, new String[] { "jelly" }, true)) ts.addTest(new JellyCheck(jelly.toURI().toURL(), jct));
}
if (res.getName().endsWith(".jar")) {
String jarUrl = res.toURI().toURL().toExternalForm();
JarFile jf = new JarFile(res);
Enumeration<JarEntry> e = jf.entries();
while (e.hasMoreElements()) {
JarEntry ent = e.nextElement();
if (ent.getName().endsWith(".jelly"))
ts.addTest(new JellyCheck(new URL("jar:" + jarUrl + "!/" + ent.getName()), jct));
}
jf.close();
}
return ts;
}
use of java.util.jar.JarEntry in project head by mifos.
the class ApplicationInitializer method copyResources.
private void copyResources(ServletContext sc) throws IOException {
URL protocol = ETLReportDWHelper.class.getClassLoader().getResource("sql/release-upgrades.txt");
ConfigurationLocator configurationLocator = new ConfigurationLocator();
String configPath = configurationLocator.getConfigurationDirectory();
String destinationDirectoryForJobs = configPath + "/ETL/MifosDataWarehouseETL";
String destinationDirectoryForJar = configPath + "/ETL/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
String destinationDirectoryForReportJobs = configPath + "/uploads/report";
String pathFromJar = "/WEB-INF/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
String pathFromJobs = "/WEB-INF/MifosDataWarehouseETL/";
if (File.separatorChar == '\\') {
destinationDirectoryForJobs = destinationDirectoryForJobs.replaceAll("/", "\\\\");
destinationDirectoryForJar = destinationDirectoryForJar.replaceAll("/", "\\\\");
destinationDirectoryForReportJobs = destinationDirectoryForReportJobs.replaceAll("/", "\\\\");
}
File directory = new File(destinationDirectoryForJobs);
directory.mkdirs();
File jarDest = new File(destinationDirectoryForJar);
File reportDirectory = new File(destinationDirectoryForReportJobs);
reportDirectory.mkdirs();
if (protocol.getProtocol().equals("jar")) {
FileUtils.cleanDirectory(directory);
// Mifos WAR
URL fullPath = sc.getResource(pathFromJar);
File f = new File(sc.getResource(pathFromJobs).toString().replace("file:", ""));
for (File fileEntry : f.listFiles()) {
FileUtils.copyFileToDirectory(fileEntry, directory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + directory);
}
FileUtils.copyURLToFile(fullPath, jarDest);
logger.info("Copy file: " + fullPath + " to: " + directory);
String jarPath = "/WEB-INF/lib/mifos-reporting-1.12-SNAPSHOT.jar";
String jarName = sc.getResource(jarPath).toString().replace("file:", "");
JarInputStream jarFileStream = new JarInputStream(new FileInputStream(jarName));
JarEntry jarEntry;
while (true) {
jarEntry = jarFileStream.getNextJarEntry();
if (jarEntry == null) {
break;
}
// Skip irrelevant folders
String jarEntryName = jarEntry.getName();
if (!jarEntryName.startsWith("birt/report") && !jarEntryName.startsWith("pentaho")) {
continue;
}
int lastIndexOfDot = jarEntryName.lastIndexOf('.');
if (lastIndexOfDot != -1 && !jarEntry.isDirectory()) {
String destinationDirectory = destinationDirectoryForReportJobs;
String birtReportFolderName = "birt/report";
if (jarEntryName.startsWith(birtReportFolderName)) {
int indexOfLastSlash = jarEntryName.lastIndexOf('/');
String folderName = jarEntryName.substring(birtReportFolderName.length(), indexOfLastSlash).replaceAll("/", "");
File birtSubFolder = new File(destinationDirectoryForReportJobs + File.separatorChar + folderName);
birtSubFolder.mkdirs();
destinationDirectory = destinationDirectoryForReportJobs + File.separatorChar + folderName;
}
InputStream inputStream = MifosViewerServletContextListener.class.getClassLoader().getResourceAsStream(jarEntryName);
int lastIndexOfSlash = jarEntryName.lastIndexOf('/');
String reportFileName = jarEntryName.substring(lastIndexOfSlash + 1);
File reportFile = new File(destinationDirectory + File.separatorChar + reportFileName);
FileUtils.copyInputStreamToFile(inputStream, reportFile);
logger.info("Copy file: " + jarEntryName + " to: " + reportFile);
}
}
} else {
try {
// Mifos Cloud Foundry WAR
URL fullPath = sc.getResource(pathFromJar);
File f = new File(sc.getRealPath("/") + pathFromJobs);
if (f.listFiles().equals(null)) {
throw new NullPointerException();
}
FileUtils.cleanDirectory(directory);
for (File fileEntry : f.listFiles()) {
FileUtils.copyFileToDirectory(fileEntry, directory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + directory);
}
FileUtils.copyURLToFile(fullPath, jarDest);
logger.info("Copy file: " + fullPath + " to: " + directory);
String sourceBirtReportPath = "/report";
String sourcePentahoReportPath = "/WEB-INF/classes/pentaho";
File birtReports = new File(sc.getRealPath("/") + sourceBirtReportPath);
File pentahoReports = new File(sc.getRealPath("/") + sourcePentahoReportPath);
for (File fileEntry : birtReports.listFiles()) {
if (fileEntry.isDirectory()) {
File destinationDirectory = new File(destinationDirectoryForReportJobs + File.separatorChar + fileEntry.getName());
FileUtils.copyDirectory(fileEntry, destinationDirectory);
logger.info("Copy directory: " + fileEntry.getName() + " to: " + destinationDirectory);
continue;
}
FileUtils.copyFileToDirectory(fileEntry, reportDirectory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + reportDirectory);
}
for (File fileEntry : pentahoReports.listFiles()) {
FileUtils.copyFileToDirectory(fileEntry, reportDirectory);
logger.info("Copy file: " + fileEntry.getName() + " to: " + reportDirectory);
}
} catch (NullPointerException e) {
// Eclipse
logger.info("Could not copy Birt/Pentaho report files to Mifos config directory.");
}
}
}
use of java.util.jar.JarEntry in project morphia by mongodb.
the class ReflectionUtils method getFromJARFile.
/**
* Returns the classes in a package found in a jar
*
* @param loader the ClassLoader to use
* @param jar the jar to scan
* @param packageName the package to scan
* @param mapSubPackages whether to map the sub-packages while scanning
* @return the list of classes
* @throws IOException thrown if an error is encountered scanning packages
* @throws ClassNotFoundException thrown if a class can not be found
*/
public static Set<Class<?>> getFromJARFile(final ClassLoader loader, final String jar, final String packageName, final boolean mapSubPackages) throws IOException, ClassNotFoundException {
final Set<Class<?>> classes = new HashSet<Class<?>>();
final JarInputStream jarFile = new JarInputStream(new FileInputStream(jar));
try {
JarEntry jarEntry;
do {
jarEntry = jarFile.getNextJarEntry();
if (jarEntry != null) {
String className = jarEntry.getName();
if (className.endsWith(".class")) {
String classPackageName = getPackageName(className);
if (classPackageName.equals(packageName) || (mapSubPackages && isSubPackage(classPackageName, packageName))) {
className = stripFilenameExtension(className);
classes.add(Class.forName(className.replace('/', '.'), true, loader));
}
}
}
} while (jarEntry != null);
} finally {
jarFile.close();
}
return classes;
}
use of java.util.jar.JarEntry in project OpenGrok by OpenGrok.
the class AuthorizationFramework method reload.
/**
* Calling this function forces the framework to reload its plugins.
*
* Plugins are taken from the pluginDirectory (set in web.xml).
*
* Old instances of plugins are removed and new list of plugins is
* constructed. Unload and load event is fired on each plugin.
*
* @see IAuthorizationPlugin#load()
* @see IAuthorizationPlugin#unload()
*/
@SuppressWarnings("unchecked")
public synchronized void reload() {
if (directory == null || !directory.isDirectory() || !directory.canRead()) {
return;
}
LOGGER.log(Level.INFO, "Plugins are being reloaded from " + directory.getAbsolutePath());
removeAll();
// trashing out the old instance of the loaded enables us
// to reaload the plugins at runtime
loader = (AuthorizationPluginClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new AuthorizationPluginClassLoader(directory);
}
});
removeAll();
plugins = new ArrayList<>();
List<File> classfiles = listFilesRec(".class");
List<File> jarfiles = listFiles(".jar");
for (File file : classfiles) {
String classname = getClassName(file);
if (classname.isEmpty()) {
continue;
}
handleLoadClass(classname);
}
for (File file : jarfiles) {
try (JarFile jar = new JarFile(file)) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String classname = getClassName(entry);
if (!entry.getName().endsWith(".class") || classname.isEmpty()) {
continue;
}
handleLoadClass(classname);
}
} catch (IOException ex) {
LOGGER.log(Level.INFO, "Could not manipulate with file because of: ", ex);
}
}
for (IAuthorizationPlugin plugin : getPlugins()) {
try {
plugin.load();
} catch (Throwable ex) {
// remove faulty plugin
LOGGER.log(Level.SEVERE, "Plugin \"" + plugin.getClass().getName() + "\" has failed while loading with exception:", ex);
removePlugin(plugin);
}
}
}
use of java.util.jar.JarEntry in project OpenGrok by OpenGrok.
the class AnalyzerGuruTest method testJar.
@Test
public void testJar() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(baos);
jos.putNextEntry(new JarEntry("dummy"));
jos.closeEntry();
jos.close();
InputStream in = new ByteArrayInputStream(baos.toByteArray());
FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "dummy");
assertSame(JarAnalyzer.class, fa.getClass());
}
Aggregations