Author: echatellier Date: 2010-03-05 15:10:03 +0100 (Fri, 05 Mar 2010) New Revision: 839 Log: Remove all classloader (useless, default classloader works fine) Modified: trunk/ant-eugene-task/src/main/java/org/nuiton/eugene/GeneratorTask.java Modified: trunk/ant-eugene-task/src/main/java/org/nuiton/eugene/GeneratorTask.java =================================================================== --- trunk/ant-eugene-task/src/main/java/org/nuiton/eugene/GeneratorTask.java 2010-03-05 11:15:08 UTC (rev 838) +++ trunk/ant-eugene-task/src/main/java/org/nuiton/eugene/GeneratorTask.java 2010-03-05 14:10:03 UTC (rev 839) @@ -24,7 +24,6 @@ import java.lang.reflect.Constructor; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -88,9 +87,6 @@ */ public class GeneratorTask extends MatchingTask { // GeneratorTask - /** Ant classpath to use. */ - protected Path classpath; - /** Template used in generation (comma separated). */ protected String templates; @@ -139,16 +135,6 @@ protected String buildDirectory = "build"; /** - * Set the optional classpath to the XSL processor - * - * @param classpath the classpath to use when loading the XSL processor - */ - public void setClasspath(Path classpath) { - Path antDefaulClasspath = createClasspath(); - antDefaulClasspath.append(classpath); - } - - /** * Set templates (fully-qualified-name) to use * * (comma-separated). @@ -175,18 +161,6 @@ } /** - * Set the optional classpath to the XSL processor - * - * @return a path instance to be configured by the Ant core. - */ - protected Path createClasspath() { - if (classpath == null) { - classpath = new Path(getProject()); - } - return classpath.createPath(); - } - - /** * Permet d'ajouter des properties. exemple: toto=1,package=org.nuiton * * @param properties properties @@ -290,7 +264,7 @@ throw new BuildException("src file \"" + srcFile + "\" does not exist or is not a file", getLocation()); } - + String[] templateGenerators = templates.split(","); Template<Model>[] generators = new Template[templateGenerators.length]; for (int i = 0; i < templateGenerators.length; i++) { @@ -302,13 +276,13 @@ generators[i].setProperties(properties); } catch (ClassCastException e) { - log("Generator don't herite Generator Class", e, Project.MSG_ERR); + log("Generator don't inherit Template Class", e, Project.MSG_ERR); } catch (ClassNotFoundException e) { - log("Unable to find generator" + templateName, e, Project.MSG_ERR); + log("Unable to find generator " + templateName, e, Project.MSG_ERR); } catch (InstantiationException e) { - log("Unable to instanciate template" + templateName, e, Project.MSG_ERR); + log("Unable to instanciate template " + templateName, e, Project.MSG_ERR); } catch (IllegalAccessException e) { - log("Unable to parse topia input file" + templateName, e, Project.MSG_ERR); + log("Unable to parse input file " + templateName, e, Project.MSG_ERR); } } @@ -356,11 +330,8 @@ protected void doExecute(List<File> srcFiles, File destDir, Template<Model>[] generators) throws BuildException { - // log classpath - log("Using classpath : " + classpath); - List<File> modelFiles = doConvertFiles(srcFiles, destDir); - + for (Template<Model> generator : generators) { if (generator != null) { File[] modelFilesArray = modelFiles.toArray(new File[0]); @@ -434,8 +405,7 @@ } String xmiName = currentFile.getName().substring(0, - currentFile.getName().lastIndexOf('.')) - + ".xmi"; + currentFile.getName().lastIndexOf('.')) + ".xmi"; currentFile = new File(unzipDirectory, xmiName); } @@ -536,8 +506,7 @@ /** * Test if file is an archive. * - * @param file - * file to test + * @param file file to test * @return test result */ protected boolean isArchiveFile(File file) { @@ -551,8 +520,7 @@ /** * Test if file is a xmi. * - * @param file - * file to test + * @param file file to test * @return test result */ protected boolean isXmiFile(File file) { @@ -565,8 +533,7 @@ /** * Test if file is a model * - * @param file - * file to test + * @param file file to test * @return test result */ protected boolean isModelFile(File file) { @@ -580,8 +547,7 @@ /** * Try to find xmi version on a file. * - * @param xmiFile - * file to inspect + * @param xmiFile file to inspect * @return version or null if version can't have been found */ protected String getXmiVersion(File xmiFile) { @@ -642,35 +608,17 @@ /** * Do XSLT transformation on given file using specific stylesheet. * - * @param xmiFile - * xmi file to transform - * @param modelFile - * result of transformation - * @param stylesheet - * stylesheet to use + * @param xmiFile xmi file to transform + * @param modelFile result of transformation + * @param stylesheet stylesheet to use */ protected void executeXSLT(File xmiFile, File modelFile, String stylesheet) { // Transformation XSL try { - - // transform ant classpath into - // URLclassloader - ClassLoader urlLoader = null; - if (classpath != null) { - String[] jars = classpath.list(); - URL[] jarsURL = new URL[jars.length]; - for (int i = 0; i < jars.length; i++) { - jarsURL[i] = new File(jars[i]).toURI().toURL(); - } - urlLoader = new URLClassLoader(jarsURL); - } else { - urlLoader = Thread.currentThread().getContextClassLoader(); - } - // Load Transformer with service loader Iterator<TransformerFactory> itTransformerFactory = ServiceLoader - .load(TransformerFactory.class, urlLoader).iterator(); + .load(TransformerFactory.class/*, urlLoader*/).iterator(); if (!itTransformerFactory.hasNext()) { throw new BuildException("No XSLT Transformer found"); } @@ -678,6 +626,7 @@ TransformerFactory transformerFactory = itTransformerFactory.next(); URL uxsl = Resource.getURL(stylesheet); StreamSource stylesource = new StreamSource(uxsl.openStream()); + Transformer transformer = transformerFactory .newTransformer(stylesource); @@ -692,8 +641,7 @@ } if (resolver != null && !resolver.isEmpty()) { - Class<?> clazz = (Class<?>) Class.forName(resolver, true, - urlLoader); + Class<?> clazz = (Class<?>) Class.forName(resolver/*, true, urlLoader*/); URIResolver tresolver = null; // Try to set the base using the constructor @@ -732,8 +680,9 @@ } catch (ClassNotFoundException e) { throw new BuildException("Can't find resolver", e); } catch (IOException e) { - throw new BuildException("Error while trying to access stylesheet", - e); + throw new BuildException("Error while trying to access stylesheet", e); + } catch (SecurityException e) { + throw new BuildException("Error while trying to access stylesheet", e); } }