KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > queries > AntArtifactProviderImpl


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.apisupport.project.queries;
21
22 import java.io.File JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URISyntaxException JavaDoc;
25 import org.netbeans.api.java.project.JavaProjectConstants;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.api.project.ant.AntArtifact;
28 import org.netbeans.modules.apisupport.project.NbModuleProject;
29 import org.netbeans.spi.project.ant.AntArtifactProvider;
30 import org.netbeans.spi.project.support.ant.AntProjectHelper;
31 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
32 import org.netbeans.spi.project.support.ant.PropertyUtils;
33
34 /**
35  * Provide the module JAR as an exported artifact that other projects could import.
36  */

37 public final class AntArtifactProviderImpl implements AntArtifactProvider {
38     
39     private final NbModuleProject project;
40     private final PropertyEvaluator eval;
41     private final AntProjectHelper helper;
42     
43     public AntArtifactProviderImpl(NbModuleProject project, AntProjectHelper helper, PropertyEvaluator eval) {
44         this.project = project;
45         this.eval = eval;
46         this.helper = helper;
47     }
48     
49     public AntArtifact[] getBuildArtifacts() {
50         return new AntArtifact[] {
51             new NbmAntArtifact(),
52         };
53     }
54     
55     private final class NbmAntArtifact extends AntArtifact {
56         
57         public NbmAntArtifact() {}
58
59         public String JavaDoc getID() {
60             return "module"; // NOI18N
61
}
62
63         public File JavaDoc getScriptLocation() {
64             return helper.resolveFile("build.xml"); // NOI18N
65
}
66
67         public String JavaDoc getType() {
68             return JavaProjectConstants.ARTIFACT_TYPE_JAR;
69         }
70
71         public URI JavaDoc[] getArtifactLocations() {
72             String JavaDoc jarloc = eval.evaluate("${cluster}/${module.jar}"); // NOI18N
73
File JavaDoc jar = helper.resolveFile(jarloc); // probably absolute anyway, now
74
String JavaDoc reldir = PropertyUtils.relativizeFile(project.getProjectDirectoryFile(), jar);
75             if (reldir != null) {
76                 try {
77                     return new URI JavaDoc[] {new URI JavaDoc(null, null, reldir, null)};
78                 } catch (URISyntaxException JavaDoc e) {
79                     throw new AssertionError JavaDoc(e);
80                 }
81             } else {
82                 return new URI JavaDoc[] {jar.toURI()};
83             }
84             // XXX should it add in class path extensions?
85
}
86         
87         public String JavaDoc getTargetName() {
88             return "netbeans"; // NOI18N
89
}
90
91         public String JavaDoc getCleanTargetName() {
92             return "clean"; // NOI18N
93
}
94
95         public Project getProject() {
96             return project;
97         }
98
99     }
100     
101 }
102
Popular Tags