1 | /*
|
---|
2 | * Copyright 2002,2004-2005 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.extension;
|
---|
18 |
|
---|
19 | import java.util.ArrayList;
|
---|
20 | import java.util.Arrays;
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 | import org.apache.tools.ant.types.DataType;
|
---|
24 | import org.apache.tools.ant.types.FileSet;
|
---|
25 | import org.apache.tools.ant.types.Reference;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * The Extension set lists a set of "Optional Packages" /
|
---|
29 | * "Extensions".
|
---|
30 | *
|
---|
31 | * @ant.data-type name="extension-set"
|
---|
32 | */
|
---|
33 | public class ExtensionSet
|
---|
34 | extends DataType {
|
---|
35 | /**
|
---|
36 | * ExtensionAdapter objects representing extensions.
|
---|
37 | */
|
---|
38 | private final ArrayList extensions = new ArrayList();
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Filesets specifying all the extensions wanted.
|
---|
42 | */
|
---|
43 | private final ArrayList extensionsFilesets = new ArrayList();
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Adds an extension that this library requires.
|
---|
47 | *
|
---|
48 | * @param extensionAdapter an extension that this library requires.
|
---|
49 | */
|
---|
50 | public void addExtension(final ExtensionAdapter extensionAdapter) {
|
---|
51 | extensions.add(extensionAdapter);
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Adds a set of files about which extensions data will be extracted.
|
---|
56 | *
|
---|
57 | * @param fileSet a set of files about which extensions data will be extracted.
|
---|
58 | */
|
---|
59 | public void addLibfileset(final LibFileSet fileSet) {
|
---|
60 | extensionsFilesets.add(fileSet);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Adds a set of files about which extensions data will be extracted.
|
---|
65 | *
|
---|
66 | * @param fileSet a set of files about which extensions data will be extracted.
|
---|
67 | */
|
---|
68 | public void addFileset(final FileSet fileSet) {
|
---|
69 | extensionsFilesets.add(fileSet);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Extract a set of Extension objects from the ExtensionSet.
|
---|
74 | *
|
---|
75 | * @param project the project instance.
|
---|
76 | * @return an array containing the Extensions from this set
|
---|
77 | * @throws BuildException if an error occurs
|
---|
78 | */
|
---|
79 | public Extension[] toExtensions(final Project project)
|
---|
80 | throws BuildException {
|
---|
81 | final ArrayList extensionsList = ExtensionUtil.toExtensions(extensions);
|
---|
82 | ExtensionUtil.extractExtensions(project, extensionsList, extensionsFilesets);
|
---|
83 | return (Extension[]) extensionsList.toArray(new Extension[extensionsList.size()]);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Makes this instance in effect a reference to another ExtensionSet
|
---|
88 | * instance.
|
---|
89 | *
|
---|
90 | * <p>You must not set another attribute or nest elements inside
|
---|
91 | * this element if you make it a reference.</p>
|
---|
92 | *
|
---|
93 | * @param reference the reference to which this instance is associated
|
---|
94 | * @exception BuildException if this instance already has been configured.
|
---|
95 | */
|
---|
96 | public void setRefid(final Reference reference)
|
---|
97 | throws BuildException {
|
---|
98 | if (!extensions.isEmpty() || !extensionsFilesets.isEmpty()) {
|
---|
99 | throw tooManyAttributes();
|
---|
100 | }
|
---|
101 | // change this to get the objects from the other reference
|
---|
102 | final Object object =
|
---|
103 | reference.getReferencedObject(getProject());
|
---|
104 | if (object instanceof ExtensionSet) {
|
---|
105 | final ExtensionSet other = (ExtensionSet) object;
|
---|
106 | extensions.addAll(other.extensions);
|
---|
107 | extensionsFilesets.addAll(other.extensionsFilesets);
|
---|
108 | } else {
|
---|
109 | final String message =
|
---|
110 | reference.getRefId() + " doesn\'t refer to a ExtensionSet";
|
---|
111 | throw new BuildException(message);
|
---|
112 | }
|
---|
113 |
|
---|
114 | super.setRefid(reference);
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * @see java.lang.Object#toString()
|
---|
119 | */
|
---|
120 | public String toString() {
|
---|
121 | return "ExtensionSet" + Arrays.asList(toExtensions(getProject()));
|
---|
122 | }
|
---|
123 | }
|
---|