001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.spi.project.support.ant;
043:
044: import java.io.File;
045: import java.net.URI;
046: import java.net.URISyntaxException;
047: import java.util.Collections;
048: import org.netbeans.api.project.Project;
049: import org.netbeans.api.project.ant.AntArtifact;
050: import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
051: import org.openide.ErrorManager;
052:
053: /**
054: * A basic AntArtifact implementation.
055: * @see AntProjectHelper#createSimpleAntArtifact
056: * @author Jesse Glick
057: */
058: final class SimpleAntArtifact extends AntArtifact {
059:
060: private final AntProjectHelper h;
061: private final String type;
062: private final String locationProperty;
063: private final PropertyEvaluator eval;
064: private final String targetName;
065: private final String cleanTargetName;
066:
067: /**
068: * @see AntProjectHelper#createSimpleAntArtifact
069: */
070: public SimpleAntArtifact(AntProjectHelper helper, String type,
071: String locationProperty, PropertyEvaluator eval,
072: String targetName, String cleanTargetName) {
073: this .h = helper;
074: this .type = type;
075: this .locationProperty = locationProperty;
076: this .eval = eval;
077: this .targetName = targetName;
078: this .cleanTargetName = cleanTargetName;
079: }
080:
081: private URI getArtifactLocation0() {
082: String locationResolved = eval.getProperty(locationProperty);
083: if (locationResolved == null) {
084: return URI.create("file:/UNDEFINED"); // NOI18N
085: }
086: File locF = new File(locationResolved);
087: if (locF.isAbsolute()) {
088: return locF.toURI();
089: } else {
090: // Project-relative path.
091: try {
092: return new URI(null, null, locationResolved.replace(
093: File.separatorChar, '/'), null);
094: } catch (URISyntaxException e) {
095: ErrorManager.getDefault().notify(
096: ErrorManager.INFORMATIONAL, e);
097: return URI.create("file:/BROKEN"); // NOI18N
098: }
099: }
100: }
101:
102: public URI[] getArtifactLocations() {
103: return new URI[] { getArtifactLocation0() };
104: }
105:
106: public String getCleanTargetName() {
107: return cleanTargetName;
108: }
109:
110: public File getScriptLocation() {
111: return h.resolveFile(GeneratedFilesHelper.BUILD_XML_PATH);
112: }
113:
114: public String getTargetName() {
115: return targetName;
116: }
117:
118: public String getType() {
119: return type;
120: }
121:
122: public Project getProject() {
123: return AntBasedProjectFactorySingleton.getProjectFor(h);
124: }
125:
126: public String toString() {
127: return "SimpleAntArtifact[helper=" + h + ",type=" + type
128: + ",locationProperty="
129: + locationProperty
130: + // NOI18N
131: ",targetName=" + targetName + ",cleanTargetName="
132: + cleanTargetName
133: + /*",props=" + eval.getProperties() +*/"]"; // NOI18N
134: }
135:
136: }
|