Index: AntHelper.java =================================================================== --- AntHelper.java (revision 0) +++ AntHelper.java (revision 0) @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.ivy.ant; + +import java.util.Iterator; +import java.util.List; + +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.XSLTProcess; + +public class AntHelper { + + // Since Ant 1.7 this method is part of org.apache.tools.ant.taskdefs.Task. + // In Ant this is just a "normal" (instead of static) method. + public static void bindToOwner(Task task, Task owner) { + task.setProject(owner.getProject()); + task.setOwningTarget(owner.getOwningTarget()); + task.setTaskName(owner.getTaskName()); + task.setDescription(owner.getDescription()); + task.setLocation(owner.getLocation()); + task.setTaskType(owner.getTaskType()); + } + + public static XSLTProcess getXslt(Task owner) { + XSLTProcess xslt = new XSLTProcess(); + bindToOwner(xslt, owner); + xslt.init(); + return xslt; + } + + public static void addXsltParam(XSLTProcess xslt, String key, String value) { + XSLTProcess.Param param = xslt.createParam(); + param.setName(key); + param.setExpression(value); + } + + public static void addAllXsltParams(XSLTProcess xslt, List params) { + for (Iterator it = params.iterator(); it.hasNext();) { + XSLTProcess.Param param = (XSLTProcess.Param) it.next(); + addXsltParam(xslt, param.getName(), param.getExpression()); + } + } + +} Index: IvyPublish.java =================================================================== --- IvyPublish.java (revision 554896) +++ IvyPublish.java (working copy) @@ -277,8 +277,8 @@ module, pubRevision, "ivy", "ivy", "xml")); if (publishivy && (!ivyFile.exists() || forcedeliver)) { IvyDeliver deliver = new IvyDeliver(); + AntHelper.bindToOwner(deliver, this); deliver.setSettingsRef(getSettingsRef()); - deliver.setProject(getProject()); deliver.setCache(getCache()); deliver.setDeliverpattern(getSrcivypattern()); deliver.setDelivertarget(deliverTarget); Index: IvyReport.java =================================================================== --- IvyReport.java (revision 554896) +++ IvyReport.java (working copy) @@ -272,11 +272,7 @@ out = new File("."); } - XSLTProcess xslt = new XSLTProcess(); - xslt.setTaskName(getTaskName()); - xslt.setProject(getProject()); - xslt.init(); - + XSLTProcess xslt = AntHelper.getXslt(this); xslt.setDestdir(out); xslt.setBasedir(cache); @@ -296,21 +292,10 @@ } xslt.setStyle(style); - XSLTProcess.Param param = xslt.createParam(); - param.setName("confs"); - param.setExpression(conf); - param = xslt.createParam(); - param.setName("extension"); - param.setExpression(xslext); + AntHelper.addXsltParam(xslt, "confs", conf); + AntHelper.addXsltParam(xslt, "extension", xslext); + AntHelper.addAllXsltParams(xslt, params); - // add the provided XSLT parameters - for (Iterator it = params.iterator(); it.hasNext();) { - param = (XSLTProcess.Param) it.next(); - XSLTProcess.Param realParam = xslt.createParam(); - realParam.setName(param.getName()); - realParam.setExpression(param.getExpression()); - } - xslt.execute(); } Index: IvyRepositoryReport.java =================================================================== --- IvyRepositoryReport.java (revision 554896) +++ IvyRepositoryReport.java (working copy) @@ -136,29 +136,16 @@ private void genreport(CacheManager cache, String organisation, String module) throws IOException { // first process the report with xslt - XSLTProcess xslt = new XSLTProcess(); - xslt.setTaskName(getTaskName()); - xslt.setProject(getProject()); - xslt.init(); + XSLTProcess xslt = AntHelper.getXslt(this); String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default")); xslt.setOut(new File(todir, outputname + "." + xslext)); xslt.setStyle(xslFile); + AntHelper.addXsltParam(xslt, "extension", xslext); + AntHelper.addAllXsltParams(xslt, params); - XSLTProcess.Param param = xslt.createParam(); - param.setName("extension"); - param.setExpression(xslext); - - // add the provided XSLT parameters - for (Iterator it = params.iterator(); it.hasNext();) { - param = (XSLTProcess.Param) it.next(); - XSLTProcess.Param realParam = xslt.createParam(); - realParam.setName(param.getName()); - realParam.setExpression(param.getExpression()); - } - xslt.execute(); } @@ -191,10 +178,7 @@ private void gen(CacheManager cache, String organisation, String module, String style, String ext) throws IOException { - XSLTProcess xslt = new XSLTProcess(); - xslt.setTaskName(getTaskName()); - xslt.setProject(getProject()); - xslt.init(); + XSLTProcess xslt = AntHelper.getXslt(this); String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default"));