01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.ant;
19:
20: import java.io.File;
21: import java.net.MalformedURLException;
22: import java.text.ParseException;
23:
24: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
25: import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser;
26: import org.apache.ivy.plugins.repository.url.URLResource;
27: import org.apache.tools.ant.BuildException;
28: import org.apache.tools.ant.Project;
29:
30: /**
31: * Convert a pom to an ivy file
32: */
33: public class IvyConvertPom extends IvyTask {
34: private File pomFile = null;
35:
36: private File ivyFile = null;
37:
38: public File getPomFile() {
39: return pomFile;
40: }
41:
42: public void setPomFile(File file) {
43: pomFile = file;
44: }
45:
46: public File getIvyFile() {
47: return ivyFile;
48: }
49:
50: public void setIvyFile(File ivyFile) {
51: this .ivyFile = ivyFile;
52: }
53:
54: public void doExecute() throws BuildException {
55: try {
56: if (pomFile == null) {
57: throw new BuildException(
58: "source pom file is required for convertpom task");
59: }
60: if (ivyFile == null) {
61: throw new BuildException(
62: "destination ivy file is required for convertpom task");
63: }
64: ModuleDescriptor md = PomModuleDescriptorParser
65: .getInstance().parseDescriptor(getSettings(),
66: pomFile.toURL(), false);
67: PomModuleDescriptorParser.getInstance().toIvyFile(
68: pomFile.toURL().openStream(),
69: new URLResource(pomFile.toURL()), getIvyFile(), md);
70: } catch (MalformedURLException e) {
71: throw new BuildException(
72: "unable to convert given pom file to url: "
73: + pomFile + ": " + e, e);
74: } catch (ParseException e) {
75: log(e.getMessage(), Project.MSG_ERR);
76: throw new BuildException("syntax errors in pom file "
77: + pomFile + ": " + e, e);
78: } catch (Exception e) {
79: throw new BuildException(
80: "impossible convert given pom file to ivy file: "
81: + e + " from=" + pomFile + " to=" + ivyFile,
82: e);
83: }
84: }
85: }
|