buildframework/helium/sf/java/legacy/src/com/nokia/ant/TypedefURIFix.java
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 628 7c4a911dc066
permissions -rw-r--r--
helium_9.0-a7879c935424
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
package com.nokia.ant;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
 *  Licensed to the Apache Software Foundation (ASF) under one or more
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
 *  contributor license agreements.  See the NOTICE file distributed with
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
 *  this work for additional information regarding copyright ownership.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
 *  The ASF licenses this file to You under the Apache License, Version 2.0
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
 *  (the "License"); you may not use this file except in compliance with
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
 *  the License.  You may obtain a copy of the License at
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
 *      http://www.apache.org/licenses/LICENSE-2.0
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
 *  Unless required by applicable law or agreed to in writing, software
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
 *  distributed under the License is distributed on an "AS IS" BASIS,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
 *  See the License for the specific language governing permissions and
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
 *  limitations under the License.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
 * package org.apache.tools.ant.taskdefs;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
/* * Portion Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import java.io.File;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import java.io.IOException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import java.io.InputStream;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import java.net.URL;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import java.net.MalformedURLException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import java.util.Map;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import java.util.HashMap;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import java.util.Enumeration;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
import java.util.Locale;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import java.util.NoSuchElementException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
import java.util.Properties;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
import org.apache.tools.ant.*;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
import org.apache.tools.ant.taskdefs.*;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
import org.apache.tools.ant.util.FileUtils;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
import org.apache.tools.ant.types.EnumeratedAttribute;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
 * Base class for Taskdef and Typedef - handles all
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
 * the attributes for Typedef. The uri and class
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
 * handling is handled by DefBase
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
 * @since Ant 1.4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
public class TypedefURIFix extends Definer {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
     * the extension of an antlib file for autoloading.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
     * {@value[
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
    private static final String ANTLIB_XML = "/antlib.xml";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    private static class ResourceStack extends ThreadLocal<Map<URL, Location>> {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        public Map<URL, Location> initialValue() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
            return new HashMap<URL, Location>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        Map<URL, Location> getStack() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
            return get();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    private static ResourceStack resourceStack = new ResourceStack();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    private String name;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    private String classname;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    private File file;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    private String resource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    private   int    format = Format.PROPERTIES;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
    private   boolean definerSet;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
    private   int         onError = OnError.FAIL;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    private   String      adapter;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    private   String      adaptTo;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
    private   Class<?>       adapterClass;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
    private   Class<?>       adaptToClass;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
     * Enumerated type for onError attribute
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
     * @see EnumeratedAttribute
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
    public static class OnError extends EnumeratedAttribute {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        /** Enumerated values */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        public static final int  FAIL = 0, REPORT = 1, IGNORE = 2, FAIL_ALL = 3;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
         * text value of onerror option {@value}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        public static final String POLICY_FAIL = "fail";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
         * text value of onerror option {@value}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        public static final String POLICY_REPORT = "report";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
         * text value of onerror option {@value}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        public static final String POLICY_IGNORE = "ignore";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
         * text value of onerror option {@value}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        public static final String POLICY_FAILALL = "failall";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
         * Constructor
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        public OnError() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
            super();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
         * Constructor using a string.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
         * @param value the value of the attribute
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        public OnError(String value) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
            setValue(value);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
         * get the values
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
         * @return an array of the allowed values for this attribute.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        public String[] getValues() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
            return new String[] { POLICY_FAIL, POLICY_REPORT, POLICY_IGNORE, POLICY_FAILALL };
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
     * Enumerated type for format attribute
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
     * @see EnumeratedAttribute
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
    public static class Format extends EnumeratedAttribute {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
        /** Enumerated values */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        public static final int PROPERTIES = 0, XML = 1;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
         * get the values
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
         * @return an array of the allowed values for this attribute.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
         */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        public String[] getValues() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
            return new String[] {"properties", "xml"};
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
     * What to do if there is an error in loading the class.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
     * <dl>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
     *   <li>error - throw build exception</li>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
     *   <li>report - output at warning level</li>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
     *   <li>ignore - output at debug level</li>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
     * </dl>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
     * @param onError an <code>OnError</code> value
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
    public void setOnError(OnError onError) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
        this.onError = onError.getIndex();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
     * Sets the format of the file or resource
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
     * @param format the enumerated value - xml or properties
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
    public void setFormat(Format format) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
        this.format = format.getIndex();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
     * @return the name for this definition
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
    public String getName() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
        return name;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
     * @return the file containing definitions
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
    public File getFile() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
        return file;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
     * @return the resource containing definitions
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
    public String getResource() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
        return resource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
     * Run the definition.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
     * @exception BuildException if an error occurs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
    public void execute() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
        ClassLoader al = createLoader();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
        if (!definerSet) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
            //we arent fully defined yet. this is an error unless
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
            //we are in an antlib, in which case the resource name is determined
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
            //automatically.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
            //NB: URIs in the ant core package"" at this point.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
            if (getURI() == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
                throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
                        "name, file or resource attribute of "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
                                + getTaskName() + " is undefined",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
                        getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
            if (getURI().startsWith(MagicNames.ANTLIB_PREFIX)) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
                //convert the URI to a resource
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
                String uri1 = getURI();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
                setResource(makeResourceFromURI(uri1));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
            } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
                throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
                        "Only antlib URIs can be located from the URI alone,"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
                                + "not the URI " + getURI());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        if (name != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
            if (classname == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
                throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
                    "classname attribute of " + getTaskName() + " element "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
                    + "is undefined", getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
            addDefinition(al, name, classname);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
        } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
            if (classname != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
                String msg = "You must not specify classname "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
                    + "together with file or resource.";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
                throw new BuildException(msg, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
            Enumeration<URL> urls = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
            if (file != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
                final URL url = fileToURL();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
                if (url == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
                    return;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
                urls = new Enumeration<URL>() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
                    private boolean more = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
                    public boolean hasMoreElements() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
                        return more;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
                    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
                    public URL nextElement() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
                        if (more) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
                            more = false;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
                            return url;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
                        } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
                            throw new NoSuchElementException();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
                        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
                    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
                };
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
            } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
                urls = resourceToURLs(al);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
            while (urls.hasMoreElements()) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
                URL url = urls.nextElement();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
                int fmt = this.format;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
                if (url.toString().toLowerCase(Locale.US).endsWith(".xml")) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
                    fmt = Format.XML;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
                if (fmt == Format.PROPERTIES) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
                    loadProperties(al, url);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
                    break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
                } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
                    if (resourceStack.getStack().get(url) != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
                        log("Warning: Recursive loading of " + url
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
                            + " ignored"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
                            + " at " + getLocation()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
                            + " originally loaded at "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
                            + resourceStack.getStack().get(url),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   276
                            Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
                    } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
                        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   279
                            resourceStack.getStack().put(url, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   280
                            loadAntlib(al, url);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   281
                        } finally {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
                            resourceStack.getStack().remove(url);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
                        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   284
                    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   286
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   291
     * This is where the logic to map from a URI to an antlib resource
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
     * is kept.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
     * @param uri the xml namespace uri that to convert.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   294
     * @return the name of a resource. It may not exist
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   295
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   296
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
    public static String makeResourceFromURI(String uri) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   298
        String path = uri.substring(MagicNames.ANTLIB_PREFIX.length());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
        String resource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   300
        if (path.startsWith("//")) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   301
            //handle new style full paths to an antlib, in which
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   302
            //all but the forward slashes are allowed.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
            resource = path.substring("//".length());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
            if (!resource.endsWith(".xml")) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   305
                //if we haven't already named an XML file, it gets antlib.xml
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   306
                resource = resource + ANTLIB_XML;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   307
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
        } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
            //convert from a package to a path
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   310
            resource = path.replace('.', '/') + ANTLIB_XML;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   311
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   312
        return resource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   313
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   314
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   315
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   316
     * Convert a file to a file: URL.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   317
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   318
     * @return the URL, or null if it isn't valid and the active error policy
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   319
     * is not to raise a fault
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   320
     * @throws BuildException if the file is missing/not a file and the
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   321
     * policy requires failure at this point.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   322
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   323
    private URL fileToURL() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   324
        String message = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   325
        if (!(file.exists())) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   326
            message = "File " + file + " does not exist";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   327
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   328
        if (message == null && !(file.isFile())) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   329
            message = "File " + file + " is not a file";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   330
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   331
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   332
            if (message == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   333
                return file.toURI().toURL();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   334
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   335
        } catch (MalformedURLException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   336
            message =
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   337
                "File " + file + " cannot use as URL: "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   338
                + ex.toString();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   339
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   340
        // Here if there is an error
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   341
        switch (onError) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   342
            case OnError.FAIL_ALL:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   343
                throw new BuildException(message);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   344
            case OnError.FAIL:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   345
                // Fall Through
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   346
            case OnError.REPORT:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   347
                log(message, Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   348
                break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   349
            case OnError.IGNORE:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   350
                // log at a lower level
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   351
                log(message, Project.MSG_VERBOSE);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   352
                break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   353
            default:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   354
                // Ignore the problem
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   355
                break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   356
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   357
        return null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   358
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   359
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   360
    private Enumeration<URL> resourceToURLs(ClassLoader classLoader) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   361
        Enumeration<URL> ret;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   362
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   363
            ret = classLoader.getResources(resource);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   364
        } catch (IOException e) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   365
            throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   366
                "Could not fetch resources named " + resource,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   367
                e, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   368
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   369
        if (!ret.hasMoreElements()) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   370
            String message = "Could not load definitions from resource "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   371
                + resource + ". It could not be found.";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   372
            switch (onError) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   373
                case OnError.FAIL_ALL:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   374
                    throw new BuildException(message);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   375
                case OnError.FAIL:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   376
                case OnError.REPORT:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   377
                    log(message, Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   378
                    break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   379
                case OnError.IGNORE:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   380
                    log(message, Project.MSG_VERBOSE);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   381
                    break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   382
                default:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   383
                    // Ignore the problem
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   384
                    break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   385
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   386
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   387
        return ret;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   388
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   389
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   390
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   391
     * Load type definitions as properties from a URL.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   392
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   393
     * @param al the classloader to use
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   394
     * @param url the url to get the definitions from
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   395
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   396
    protected void loadProperties(ClassLoader al, URL url) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   397
        InputStream is = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   398
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   399
            is = url.openStream();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   400
            if (is == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   401
                log("Could not load definitions from " + url,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   402
                    Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   403
                return;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   404
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   405
            Properties props = new Properties();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   406
            props.load(is);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   407
            Enumeration keys = props.keys();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   408
            while (keys.hasMoreElements()) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   409
                name = (String) keys.nextElement();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   410
                classname = props.getProperty(name);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   411
                addDefinition(al, name, classname);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   412
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   413
        } catch (IOException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   414
            throw new BuildException(ex, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   415
        } finally {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   416
            FileUtils.close(is);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   417
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   418
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   419
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   420
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   421
     * Load an antlib from a URL.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   422
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   423
     * @param classLoader the classloader to use.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   424
     * @param url the url to load the definitions from.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   425
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   426
    private void loadAntlib(ClassLoader classLoader, URL url) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   427
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   428
            Antlib antlib = Antlib.createAntlib(getProject(), url, getURI());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   429
            antlib.setClassLoader(classLoader);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   430
            antlib.setURI(getURI());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   431
            antlib.execute();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   432
        } catch (BuildException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   433
            throw ProjectHelper.addLocationToBuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   434
                ex, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   435
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   436
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   437
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   438
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   439
     * Name of the property file  to load
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   440
     * ant name/classname pairs from.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   441
     * @param file the file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   442
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   443
    public void setFile(File file) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   444
        if (definerSet) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   445
            tooManyDefinitions();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   446
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   447
        definerSet = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   448
        this.file = file;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   449
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   450
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   451
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   452
     * Name of the property resource to load
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   453
     * ant name/classname pairs from.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   454
     * @param res the resource to use
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   455
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   456
    public void setResource(String res) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   457
        if (definerSet) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   458
            tooManyDefinitions();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   459
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   460
        definerSet = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   461
        this.resource = res;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   462
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   463
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   464
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   465
     * Antlib attribute, sets resource and uri.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   466
     * uri is set the antlib value and, resource is set
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   467
     * to the antlib.xml resource in the classpath.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   468
     * For example antlib="antlib:org.acme.bland.cola"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   469
     * corresponds to uri="antlib:org.acme.bland.cola"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   470
     * resource="org/acme/bland/cola/antlib.xml".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   471
     * @param antlib the value to set.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   472
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   473
    public void setAntlib(String antlib) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   474
        if (definerSet) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   475
            tooManyDefinitions();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   476
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   477
        if (!antlib.startsWith("antlib:")) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   478
            throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   479
                "Invalid antlib attribute - it must start with antlib:");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   480
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   481
        setURI(antlib);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   482
        this.resource = antlib.substring("antlib:".length()).replace('.', '/')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   483
            + "/antlib.xml";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   484
        definerSet = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   485
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   486
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   487
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   488
     * Name of the definition
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   489
     * @param name the name of the definition
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   490
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   491
    public void setName(String name) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   492
        if (definerSet) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   493
            tooManyDefinitions();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   494
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   495
        definerSet = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   496
        this.name = name;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   497
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   498
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   499
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   500
     * Returns the classname of the object we are defining.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   501
     * May be <code>null</code>.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   502
     * @return the class name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   503
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   504
    public String getClassname() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   505
        return classname;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   506
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   507
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   508
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   509
     * The full class name of the object being defined.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   510
     * Required, unless file or resource have
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   511
     * been specified.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   512
     * @param classname the name of the class
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   513
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   514
    public void setClassname(String classname) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   515
        this.classname = classname;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   516
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   517
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   518
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   519
     * Set the class name of the adapter class.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   520
     * An adapter class is used to proxy the
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   521
     * definition class. It is used if the
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   522
     * definition class is not assignable to
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   523
     * the adaptto class, or if the adaptto
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   524
     * class is not present.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   525
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   526
     * @param adapter the name of the adapter class
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   527
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   528
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   529
    public void setAdapter(String adapter) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   530
        this.adapter = adapter;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   531
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   532
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   533
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   534
     * Set the adapter class.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   535
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   536
     * @param adapterClass the class to use to adapt the definition class
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   537
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   538
    protected void setAdapterClass(Class adapterClass) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   539
        this.adapterClass = adapterClass;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   540
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   541
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   542
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   543
     * Set the classname of the class that the definition
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   544
     * must be compatible with, either directly or
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   545
     * by use of the adapter class.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   546
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   547
     * @param adaptTo the name of the adaptto class
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   548
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   549
    public void setAdaptTo(String adaptTo) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   550
        this.adaptTo = adaptTo;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   551
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   552
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   553
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   554
     * Set the class for adaptToClass, to be
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   555
     * used by derived classes, used instead of
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   556
     * the adaptTo attribute.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   557
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   558
     * @param adaptToClass the class for adapto.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   559
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   560
    protected void setAdaptToClass(Class adaptToClass) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   561
        this.adaptToClass = adaptToClass;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   562
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   563
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   564
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   565
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   566
     * Add a definition using the attributes of Definer
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   567
     *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   568
     * @param al the ClassLoader to use
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   569
     * @param name the name of the definition
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   570
     * @param classname the classname of the definition
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   571
     * @exception BuildException if an error occurs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   572
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   573
    protected void addDefinition(ClassLoader al, String name, String classname)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   574
    {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   575
        Class<?> cl = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   576
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   577
            try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   578
                name = ProjectHelper.genComponentName(getURI(), name);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   579
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   580
                if (onError != OnError.IGNORE) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   581
                    cl = Class.forName(classname, true, al);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   582
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   583
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   584
                if (adapter != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   585
                    adapterClass = Class.forName(adapter, true, al);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   586
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   588
                if (adaptTo != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   589
                    adaptToClass = Class.forName(adaptTo, true, al);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   590
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   591
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   592
                AntTypeDefinition def = new AntTypeDefinition();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   593
                def.setName(name);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   594
                def.setClassName(classname);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   595
                def.setClass(cl);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   596
                def.setAdapterClass(adapterClass);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   597
                def.setAdaptToClass(adaptToClass);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   598
                def.setClassLoader(al);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   599
                if (cl != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   600
                    def.checkClass(getProject());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   601
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   602
                ComponentHelper.getComponentHelper(getProject())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   603
                    .addDataTypeDefinition(def);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   604
            } catch (ClassNotFoundException cnfe) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   605
                String msg = getTaskName() + " class " + classname
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   606
                    + " cannot be found";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   607
                throw new BuildException(msg, cnfe, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   608
            } catch (NoClassDefFoundError ncdfe) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   609
                String msg = getTaskName() + " A class needed by class "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   610
                    + classname + " cannot be found: " + ncdfe.getMessage();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   611
                throw new BuildException(msg, ncdfe, getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   612
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   613
        } catch (BuildException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   614
            switch (onError) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   615
                case OnError.FAIL_ALL:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   616
                case OnError.FAIL:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   617
                    throw ex;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   618
                case OnError.REPORT:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   619
                    log(ex.getLocation() + "Warning: " + ex.getMessage(),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   620
                        Project.MSG_WARN);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   621
                    break;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   622
                default:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   623
                    log(ex.getLocation() + ex.getMessage(),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   624
                        Project.MSG_DEBUG);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   625
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   626
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   627
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   628
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   629
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   630
     * handle too many definitions by raising an exception.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   631
     * @throws BuildException always.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   632
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   633
    private void tooManyDefinitions() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   634
        throw new BuildException(
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   635
            "Only one of the attributes name, file and resource"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   636
            + " can be set", getLocation());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   637
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   638
}