KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > spi > project > support > rake > SimpleRakeArtifact


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ruby.spi.project.support.rake;
21
22 import java.io.File JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URISyntaxException JavaDoc;
25 import java.util.Collections JavaDoc;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.modules.ruby.api.project.rake.RakeArtifact;
28 import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
29 import org.openide.ErrorManager;
30
31 /**
32  * A basic RakeArtifact implementation.
33  * @see RakeProjectHelper#createSimpleRakeArtifact
34  * @author Jesse Glick
35  */

36 final class SimpleRakeArtifact extends RakeArtifact {
37
38     private final RakeProjectHelper h;
39     private final String JavaDoc type;
40     private final String JavaDoc locationProperty;
41     private final PropertyEvaluator eval;
42     private final String JavaDoc targetName;
43     private final String JavaDoc cleanTargetName;
44     
45     /**
46      * @see RakeProjectHelper#createSimpleRakeArtifact
47      */

48     public SimpleRakeArtifact(RakeProjectHelper helper, String JavaDoc type, String JavaDoc locationProperty, PropertyEvaluator eval, String JavaDoc targetName, String JavaDoc cleanTargetName) {
49         this.h = helper;
50         this.type = type;
51         this.locationProperty = locationProperty;
52         this.eval = eval;
53         this.targetName = targetName;
54         this.cleanTargetName = cleanTargetName;
55     }
56     
57     private URI JavaDoc getArtifactLocation0() {
58         String JavaDoc locationResolved = eval.getProperty(locationProperty);
59         if (locationResolved == null) {
60             return URI.create("file:/UNDEFINED"); // NOI18N
61
}
62         File JavaDoc locF = new File JavaDoc(locationResolved);
63         if (locF.isAbsolute()) {
64             return locF.toURI();
65         } else {
66             // Project-relative path.
67
try {
68                 return new URI JavaDoc(null, null, locationResolved.replace(File.separatorChar, '/'), null);
69             } catch (URISyntaxException JavaDoc e) {
70                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
71                 return URI.create("file:/BROKEN"); // NOI18N
72
}
73         }
74     }
75     
76     public URI JavaDoc[] getArtifactLocations() {
77         return new URI JavaDoc[]{getArtifactLocation0()};
78     }
79     
80     public String JavaDoc getCleanTargetName() {
81         return cleanTargetName;
82     }
83     
84     public File JavaDoc getScriptLocation() {
85         return h.resolveFile(GeneratedFilesHelper.BUILD_XML_PATH);
86     }
87     
88     public String JavaDoc getTargetName() {
89         return targetName;
90     }
91     
92     public String JavaDoc getType() {
93         return type;
94     }
95     
96     public Project getProject() {
97         return RakeBasedProjectFactorySingleton.getProjectFor(h);
98     }
99     
100     public String JavaDoc toString() {
101         return "SimpleRakeArtifact[helper=" + h + ",type=" + type + ",locationProperty=" + locationProperty + // NOI18N
102
",targetName=" + targetName + ",cleanTargetName=" + cleanTargetName + /*",props=" + eval.getProperties() +*/ "]"; // NOI18N
103
}
104     
105 }
106
Popular Tags