Revision: 5767 http://jnode.svn.sourceforge.net/jnode/?rev=5767&view=rev Author: lsantha Date: 2011-01-03 20:57:35 +0000 (Mon, 03 Jan 2011)
Log Message: ----------- Removed unneeded classes. Removed Paths: ------------- classlib6/builder/src/builder/org/jnode/build/AbstractPluginTask.java classlib6/builder/src/builder/org/jnode/build/PluginTask.java classlib6/builder/src/builder/org/jnode/build/packager/PluginBuilder.java Deleted: classlib6/builder/src/builder/org/jnode/build/AbstractPluginTask.java =================================================================== --- classlib6/builder/src/builder/org/jnode/build/AbstractPluginTask.java 2011-01-03 13:55:33 UTC (rev 5766) +++ classlib6/builder/src/builder/org/jnode/build/AbstractPluginTask.java 2011-01-03 20:57:35 UTC (rev 5767) @@ -1,218 +0,0 @@ -/* - * $Id: AbstractPluginTask.java 4971 2009-02-02 06:44:38Z lsantha $ - * - * Copyright (C) 2003-2009 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.build; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.LinkedList; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.Jar; -import org.apache.tools.ant.types.ZipFileSet; -import org.jnode.nanoxml.XMLElement; -import org.jnode.nanoxml.XMLParseException; -import org.jnode.plugin.Library; -import org.jnode.plugin.PluginDescriptor; -import org.jnode.plugin.PluginException; -import org.jnode.plugin.model.Factory; - -/** - * @author Ewout Prangsma (e...@users.sourceforge.net) - */ -public abstract class AbstractPluginTask extends Task { - - protected String targetArch; - private final LinkedList<LibAlias> aliases = new LinkedList<LibAlias>(); - - /** - * @return The target architecture - */ - protected String getTargetArch() { - return targetArch; - } - - /** - * @param string - */ - public void setTargetArch(String string) { - targetArch = string; - } - - protected PluginDescriptor readDescriptor(File descriptor) { - final PluginDescriptor descr; - try { - final XMLElement root = new XMLElement(new Hashtable(), true, false); - try { - final FileReader r = new FileReader(descriptor); - try { - root.parseFromReader(r); - } finally { - r.close(); - } - } catch (IOException ex) { - throw new BuildException("Building " + descriptor + " failed", ex); - } catch (XMLParseException ex) { - throw new BuildException("Building " + descriptor + " failed", ex); - } - descr = Factory.parseDescriptor(root); - } catch (PluginException ex) { - ex.printStackTrace(); - throw new BuildException("Building " + descriptor + " failed", ex); - } - - return descr; - } - - protected void processLibrary(Jar jarTask, Library lib, HashMap<File, ZipFileSet> fileSets, File srcDir) { - final String jarName = jarTask.getDestFile().getName(); - final LibAlias libAlias = getAlias(lib.getName()); - final File f; - if (libAlias == null) { - f = new File(srcDir, lib.getName()); - if (!f.exists()) { - throw new BuildException( - "file not found " + f.getAbsoluteFile() + " because " + lib.getName() + " has no alias"); - } - } else { - f = libAlias.getAlias(); - } - - ZipFileSet fs = fileSets.get(f); - if (fs == null) { - fs = new ZipFileSet(); - if (f.isFile()) { - fs.setSrc(f); - } else { - fs.setDir(f); - } - fileSets.put(f, fs); - jarTask.addFileset(fs); - } - fs.createExclude().setName("**/package.html"); - - final String[] exports = lib.getExports(); - for (int i = 0; i < exports.length; i++) { - final String export = exports[i]; - if (export.equals("*")) { - checkPackageExists(jarName, export, f); - fs.createInclude().setName("**/*"); - } else { - String exp = export.replace('.', '/'); - fs.createInclude().setName(exp + ".*"); - if (!exp.endsWith("*")) { - checkPackageExists(jarName, exp, f); - fs.createInclude().setName(exp + "*"); - } else { - checkPackageExists(jarName, exp, f); - fs.createInclude().setName(exp); - } - } - } - } - - private void checkPackageExists(String jarName, final String export, File src) { - String packageDir = export; - - if (!src.isFile()) { - if (packageDir.endsWith("/*")) { - packageDir = packageDir.substring(0, packageDir.length() - 2); - } else if (packageDir.endsWith("*")) { - packageDir = packageDir.substring(0, packageDir.length() - 1); - } - - File f = new File(src, packageDir); - if (!f.exists()) { - f = new File(src, packageDir + ".class"); - if (!f.exists()) { - System.err.println("WARNING : " + jarName + " doesn't contain package " + export); - } - } - } - } - - protected File pluginDir; - - /** - * @param file - */ - public void setPluginDir(File file) { - pluginDir = file; - } - - /** - * @return The plugin directory - */ - protected File getPluginDir() { - return pluginDir; - } - - public LibAlias createLibAlias() { - LibAlias a = new LibAlias(); - aliases.add(a); - return a; - } - - public LibAlias getAlias(String name) { - for (LibAlias a : aliases) { - if (name.equals(a.getName())) { - return a; - } - } - return null; - } - - public static class LibAlias { - private String name; - private File alias; - - /** - * @return The alias - */ - public final File getAlias() { - return this.alias; - } - - /** - * @param alias - */ - public final void setAlias(File alias) { - this.alias = alias; - } - - /** - * @return The name - */ - public final String getName() { - return this.name; - } - - /** - * @param name - */ - public final void setName(String name) { - this.name = name; - } - } -} Deleted: classlib6/builder/src/builder/org/jnode/build/PluginTask.java =================================================================== --- classlib6/builder/src/builder/org/jnode/build/PluginTask.java 2011-01-03 13:55:33 UTC (rev 5766) +++ classlib6/builder/src/builder/org/jnode/build/PluginTask.java 2011-01-03 20:57:35 UTC (rev 5767) @@ -1,240 +0,0 @@ -/* - * $Id: PluginTask.java 5071 2009-02-28 16:38:38Z fduminy $ - * - * Copyright (C) 2003-2009 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.build; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.taskdefs.Jar; -import org.apache.tools.ant.taskdefs.Manifest; -import org.apache.tools.ant.taskdefs.ManifestException; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.ZipFileSet; -import org.apache.tools.ant.util.FileUtils; -import org.jnode.build.packager.PluginBuilder; -import org.jnode.plugin.Library; -import org.jnode.plugin.PluginDescriptor; -import org.jnode.plugin.Runtime; - -/** - * @author Ewout Prangsma (e...@users.sourceforge.net) - */ -public class PluginTask extends AbstractPluginTask { - - private LinkedList<ZipFileSet> descriptorSets = new LinkedList<ZipFileSet>(); - private File todir; - private File tmpDir = new File(System.getProperty("java.io.tmpdir")); - - private PluginBuilder packager; - - public ZipFileSet createDescriptors() { - final ZipFileSet fs = new ZipFileSet(); - descriptorSets.add(fs); - return fs; - } - - /** - * @throws BuildException - * @see org.apache.tools.ant.Task#execute() - */ - public void execute() throws BuildException { - - if (descriptorSets.isEmpty()) { - throw new BuildException("At at least 1 descriptorset element"); - } - if (todir == null) { - throw new BuildException("The todir attribute must be set"); - } - if (getPluginDir() == null) { - throw new BuildException("The pluginDir attribute must be set"); - } - if (!todir.exists()) { - todir.mkdirs(); - } else if (!todir.isDirectory()) { - throw new BuildException("todir must be a directory"); - } - - int max_thread_count = 10; - int max_plugin_count = 500; - - final AtomicBoolean failure = new AtomicBoolean(false); - ThreadPoolExecutor executor = new ThreadPoolExecutor(max_thread_count, max_thread_count, 60, TimeUnit.SECONDS, - new ArrayBlockingQueue<Runnable>(max_plugin_count)) { - @Override - protected void afterExecute(Runnable r, Throwable t) { - if (t != null) { - failure.set(true); - } - } - }; - - final Map<String, File> descriptors = new HashMap<String, File>(); - for (FileSet fs : descriptorSets) { - final DirectoryScanner ds = fs.getDirectoryScanner(getProject()); - final String[] files = ds.getIncludedFiles(); - for (final String file : files) { - executor.execute(new Runnable() { - public void run() { - buildPlugin(descriptors, new File(ds.getBasedir(), file)); - } - }); - } - } - - if (packager != null) { - packager.execute(executor, descriptors); - } - - executor.shutdown(); - try { - executor.awaitTermination(10, TimeUnit.MINUTES); - } catch (InterruptedException ie) { - throw new RuntimeException("Building plugins interrupted"); - } - - if (failure.get()) { - throw new RuntimeException("At least one plugin task failed : see above errors"); - } - - if (packager != null) { - // that must be called after completion of all plugin tasks - packager.finish(); - } - } - - /** - * @param descriptors map of fullPluginId to File descriptor - * @param descriptor the plugin descriptor XML - * @throws BuildException on failure - */ - public void buildPlugin(Map<String, File> descriptors, File descriptor) throws BuildException { - final PluginDescriptor descr = readDescriptor(descriptor); - - final String fullId = descr.getId() + "_" + descr.getVersion(); - if (descriptors.containsKey(fullId)) { - File otherDesc = descriptors.get(fullId); - throw new BuildException("Same id(" + fullId + ") for 2 plugins: " + otherDesc + ", " + descriptor); - } - descriptors.put(fullId, descriptor); - - File destFile = new File(todir, fullId + ".jar"); - - final Jar jarTask = new Jar(); - jarTask.setProject(getProject()); - jarTask.setTaskName(getTaskName()); - jarTask.setDestFile(destFile); - jarTask.setCompress(false); - - // Add plugin.xml - final File tmpPluginDir; - final File tmpPluginXmlFile; - try { - tmpPluginDir = new File(tmpDir, "jnode-plugins" + File.separator + fullId); - tmpPluginDir.mkdirs(); - tmpPluginXmlFile = new File(tmpPluginDir, "plugin.xml"); - FileUtils.newFileUtils().copyFile(descriptor, tmpPluginXmlFile); - FileSet fs = new FileSet(); - fs.setDir(tmpPluginDir); - fs.createInclude().setName("plugin.xml"); - jarTask.addFileset(fs); - } catch (IOException ex) { - throw new BuildException(ex); - } - - // Create manifest - try { - jarTask.addConfiguredManifest(createManifest(descr)); - } catch (ManifestException ex) { - throw new BuildException(ex); - } - - // Add runtime resources - final Runtime rt = descr.getRuntime(); - if (rt != null) { - final HashMap<File, ZipFileSet> fileSets = new HashMap<File, ZipFileSet>(); - final Library[] libs = rt.getLibraries(); - for (int l = 0; l < libs.length; l++) { - processLibrary(jarTask, libs[l], fileSets, getPluginDir()); - } - } - - jarTask.execute(); - } - - /** - * Create a manifest for the given descriptor. - * - * @param descr plugin descriptor object - * @return the manifest - * @throws ManifestException - */ - protected Manifest createManifest(PluginDescriptor descr) throws ManifestException { - Manifest mf = new Manifest(); - - mf.addConfiguredAttribute(new Manifest.Attribute("Bundle-SymbolicName", descr.getId())); - mf.addConfiguredAttribute(new Manifest.Attribute("Bundle-ManifestVersion", "2")); - mf.addConfiguredAttribute(new Manifest.Attribute("Bundle-Version", descr.getVersion())); - - return mf; - } - - /** - * @return The destination directory - */ - public final File getTodir() { - return this.todir; - } - - /** - * @param todir - */ - public final void setTodir(File todir) { - this.todir = todir; - } - - /** - * @return The temp directory - */ - public final File getTmpDir() { - return this.tmpDir; - } - - /** - * @param tmpDir - */ - public final void setTmpDir(File tmpDir) { - this.tmpDir = tmpDir; - } - - public PluginBuilder createPackager() { - packager = new PluginBuilder(this); - return packager; - } -} Deleted: classlib6/builder/src/builder/org/jnode/build/packager/PluginBuilder.java =================================================================== --- classlib6/builder/src/builder/org/jnode/build/packager/PluginBuilder.java 2011-01-03 13:55:33 UTC (rev 5766) +++ classlib6/builder/src/builder/org/jnode/build/packager/PluginBuilder.java 2011-01-03 20:57:35 UTC (rev 5767) @@ -1,252 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003-2009 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.build.packager; - -import java.io.File; -import java.io.FileFilter; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadPoolExecutor; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.jnode.build.BuildException; -import org.jnode.build.PluginTask; -import org.jnode.build.AbstractPluginTask.LibAlias; - -/** - * Class building new jnode plugins from third party jars/resources. - * - * @author fabien - * - */ -public class PluginBuilder extends PackagerTask { - private final Task parent; - - /** - * List of user plugin ids. - */ - private StringBuilder userPluginIds = new StringBuilder(); - - /** - * {...@link Path} to third party jars for compilation purpose. - */ - private Path path; - - /** - * Construct a PluginBuilder from the given {...@link Task}, - * which will be used as a delegate to access ant context. - * - * @param parent - */ - public PluginBuilder(Task parent) { - this.parent = parent; - } - - /** - * Define the path reference for compilation. - * @param pathRefId - */ - public void setPathRefId(String pathRefId) { - this.path = (Path) parent.getProject().getReference(pathRefId); - } - - /** - * Main method for build the jnode plugin. - * - * @param executor - * @param descriptors - */ - public void execute(ThreadPoolExecutor executor, final Map<String, File> descriptors) { - if (isEnabled()) { - if (path == null) { - throw new BuildException("pathRefId is mandatory"); - } - - File[] userJars = userApplicationsDir.listFiles(new FileFilter() { - - @Override - public boolean accept(File pathname) { - return pathname.getName().endsWith(".jar") || pathname.isDirectory(); - } - - }); - - for (File userJar : userJars) { - processUserJar(executor, descriptors, userJar, userPluginIds); - } - } - } - - /** - * Do finalization tasks. For instance, it's writing the plugin ids to the properties file - */ - public void finish() { - if (isEnabled()) { - if ((userPluginIds.length() > 0) && (userPluginIds.charAt(userPluginIds.length() - 1) == ',')) { - userPluginIds.deleteCharAt(userPluginIds.length() - 1); - } - - // write properties - Properties properties = getProperties(); - properties.put(USER_PLUGIN_IDS, userPluginIds.toString()); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(getPropertiesFile()); - properties.store(fos, "File automatically generated by JNode Packager"); - } catch (IOException e) { - throw new BuildException("failed to write properties file", e); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - throw new BuildException("failed to close properties file", e); - } - } - } - } - } - - /** - * Attention : userPluginList must be a StringBuilder because it's accessed from multiple threads. - * @param executor - * @param descriptors - * @param userJar - * @param userPluginList - */ - private void processUserJar(ExecutorService executor, final Map<String, File> descriptors, final File userJar, - final StringBuilder userPluginList) { - final PluginTask task = (PluginTask) parent; - executor.execute(new Runnable() { - public void run() { - final String jarName = userJar.getName(); - final String pluginId; - - if (userJar.isFile()) { - pluginId = jarName.substring(0, jarName.length() - 4); // remove ".jar" - } else { - pluginId = jarName; // use directory name as plugin id - } - - userPluginList.append(pluginId + ","); - - // replace ".jar" by ".xml" - final String pluginDesc = pluginId + ".xml"; - - path.createPathElement().setLocation(userJar); - - // create the lib alias - final String alias = pluginId + ".jar"; - LibAlias libAlias = task.createLibAlias(); - libAlias.setName(alias); - libAlias.setAlias(userJar); - - final File descriptorFile = new File(userJar.getParent(), pluginDesc); - if (!descriptorFile.exists()) { - // build the descriptor from scratch - buildDescriptor(userJar, descriptorFile, pluginId, alias); - } - - if (userJar.isDirectory()) { - ScriptBuilder.build(userJar, getProperties()); - } - - task.buildPlugin(descriptors, descriptorFile); - } - }); - } - - /** - * Build the plugin descriptor. - * - * @param userJar - * @param descriptorFile - * @param pluginId - * @param alias - */ - private void buildDescriptor(File userJar, File descriptorFile, String pluginId, String alias) { - PrintStream out = null; - boolean success = false; - try { - out = new PrintStream(descriptorFile); - - out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); - out.println("<!DOCTYPE plugin SYSTEM \"jnode.dtd\">"); - - out.println("<plugin id=\"" + pluginId + "\""); - out.println(" name=\"" + pluginId + "\""); - out.println(" version=\"\""); - out.println(" class=\"org.jnode.plugin.AutoUnzipPlugin\""); - out.println(" auto-start=\"true\""); - out.println(" license-name=\"unspecified\">"); - - out.println(" <runtime>"); - out.println(" <library name=\"" + alias + "\">"); - out.println(" <export name=\"*\"/>"); - out.println(" </library>"); - out.println(" </runtime>"); - - if (userJar.isFile()) { - List<String> mainClasses = MainFinder.searchMain(userJar); - if (!mainClasses.isEmpty()) { - out.println(" <extension point=\"org.jnode.shell.aliases\">"); - for (String mainClass : mainClasses) { - int idx = mainClass.lastIndexOf('.'); - String name = (idx < 0) ? mainClass : mainClass.substring(idx + 1); - out.println(" <alias name=\"" + name + "\" class=\"" + mainClass + "\"/>"); - log(pluginId + " : added alias " + name + " for class " + mainClass, Project.MSG_INFO); - } - - out.println(" </extension>"); - } else { - log("no main found for plugin " + pluginId, Project.MSG_WARN); - } - } - - out.println(" <!-- FIXME : use more restricted permissions -->"); - out.println(" <extension point=\"org.jnode.security.permissions\">"); - out.println(" <permission class=\"java.security.AllPermission\" />"); - out.println(" </extension>"); - - out.println("</plugin>"); - success = true; - } catch (IOException ioe) { - throw new BuildException("failed to write plugin descriptor", ioe); - } finally { - if (out != null) { - out.close(); - } - - if (!success) { - // in case of failure, delete the incomplete descriptor file - descriptorFile.delete(); - } - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Jnode-svn-commits mailing list Jnode-svn-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits