1 | /*
|
---|
2 | * Copyright 2002-2004 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 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.windows;
|
---|
19 |
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.taskdefs.ExecuteOn;
|
---|
22 | import org.apache.tools.ant.taskdefs.condition.Os;
|
---|
23 | import org.apache.tools.ant.types.FileSet;
|
---|
24 |
|
---|
25 | import java.io.File;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Attrib equivalent for Win32 environments.
|
---|
29 | * Note: Attrib parameters /S and /D are not handled.
|
---|
30 | *
|
---|
31 | *
|
---|
32 | * @since Ant 1.6
|
---|
33 | */
|
---|
34 | public class Attrib extends ExecuteOn {
|
---|
35 |
|
---|
36 | private static final String ATTR_READONLY = "R";
|
---|
37 | private static final String ATTR_ARCHIVE = "A";
|
---|
38 | private static final String ATTR_SYSTEM = "S";
|
---|
39 | private static final String ATTR_HIDDEN = "H";
|
---|
40 | private static final String SET = "+";
|
---|
41 | private static final String UNSET = "-";
|
---|
42 |
|
---|
43 | private boolean haveAttr = false;
|
---|
44 |
|
---|
45 | public Attrib() {
|
---|
46 | super.setExecutable("attrib");
|
---|
47 | super.setParallel(false);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void setFile(File src) {
|
---|
51 | FileSet fs = new FileSet();
|
---|
52 | fs.setFile(src);
|
---|
53 | addFileset(fs);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /** set the ReadOnly file attribute */
|
---|
57 | public void setReadonly(boolean value) {
|
---|
58 | addArg(value, ATTR_READONLY);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /** set the Archive file attribute */
|
---|
62 | public void setArchive(boolean value) {
|
---|
63 | addArg(value, ATTR_ARCHIVE);
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** set the System file attribute */
|
---|
67 | public void setSystem(boolean value) {
|
---|
68 | addArg(value, ATTR_SYSTEM);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /** set the Hidden file attribute */
|
---|
72 | public void setHidden(boolean value) {
|
---|
73 | addArg(value, ATTR_HIDDEN);
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected void checkConfiguration() {
|
---|
77 | if (!haveAttr()) {
|
---|
78 | throw new BuildException("Missing attribute parameter",
|
---|
79 | getLocation());
|
---|
80 | }
|
---|
81 | super.checkConfiguration();
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * @ant.attribute ignore="true"
|
---|
86 | */
|
---|
87 | public void setExecutable(String e) {
|
---|
88 | throw new BuildException(getTaskType()
|
---|
89 | + " doesn\'t support the executable attribute", getLocation());
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * @ant.attribute ignore="true"
|
---|
94 | */
|
---|
95 | public void setCommand(String e) {
|
---|
96 | throw new BuildException(getTaskType()
|
---|
97 | + " doesn\'t support the command attribute", getLocation());
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * @ant.attribute ignore="true"
|
---|
102 | */
|
---|
103 | public void setAddsourcefile(boolean b) {
|
---|
104 | throw new BuildException(getTaskType()
|
---|
105 | + " doesn\'t support the addsourcefile attribute", getLocation());
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * @ant.attribute ignore="true"
|
---|
110 | */
|
---|
111 | public void setSkipEmptyFilesets(boolean skip) {
|
---|
112 | throw new BuildException(getTaskType() + " doesn\'t support the "
|
---|
113 | + "skipemptyfileset attribute",
|
---|
114 | getLocation());
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * @ant.attribute ignore="true"
|
---|
119 | */
|
---|
120 | public void setParallel(boolean parallel) {
|
---|
121 | throw new BuildException(getTaskType()
|
---|
122 | + " doesn\'t support the parallel attribute",
|
---|
123 | getLocation());
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * @ant.attribute ignore="true"
|
---|
128 | */
|
---|
129 | public void setMaxParallel(int max) {
|
---|
130 | throw new BuildException(getTaskType()
|
---|
131 | + " doesn\'t support the maxparallel attribute",
|
---|
132 | getLocation());
|
---|
133 | }
|
---|
134 |
|
---|
135 | protected boolean isValidOs() {
|
---|
136 | return Os.isFamily("windows") && super.isValidOs();
|
---|
137 | }
|
---|
138 |
|
---|
139 | private static String getSignString(boolean attr) {
|
---|
140 | return (attr == true ? SET : UNSET);
|
---|
141 | }
|
---|
142 |
|
---|
143 | private void addArg(boolean sign, String attribute) {
|
---|
144 | createArg().setValue(getSignString(sign) + attribute);
|
---|
145 | haveAttr = true;
|
---|
146 | }
|
---|
147 |
|
---|
148 | private boolean haveAttr() {
|
---|
149 | return haveAttr;
|
---|
150 | }
|
---|
151 |
|
---|
152 | }
|
---|