KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > classpath > ClassPathProviderImpl


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.bluej.classpath;
21
22 import java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.StringTokenizer JavaDoc;
27 import org.netbeans.api.java.classpath.ClassPath;
28 import org.netbeans.api.java.platform.JavaPlatformManager;
29 import org.netbeans.bluej.BluejProject;
30 import org.netbeans.bluej.options.BlueJSettings;
31 import org.netbeans.spi.java.classpath.ClassPathFactory;
32 import org.netbeans.spi.java.classpath.ClassPathImplementation;
33 import org.netbeans.spi.java.classpath.ClassPathProvider;
34 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
35 import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport;
36 import org.openide.filesystems.FileObject;
37 import org.openide.filesystems.FileUtil;
38
39 /**
40  *
41  * @author mkleint
42  */

43 public class ClassPathProviderImpl implements ClassPathProvider {
44
45     private BluejProject project;
46     
47     private ClassPath boot;
48     private ClassPath source;
49     private ClassPath compile;
50     private ClassPath[] boots;
51     private ClassPath[] sources;
52     private ClassPath[] compiles;
53     
54     private CPImpl cpimpl;
55     
56     
57     /** Creates a new instance of ClassPathProviderImpl */
58     public ClassPathProviderImpl(BluejProject prj) {
59         project = prj;
60     }
61     
62     public CPImpl getBluejCPImpl() {
63         return cpimpl;
64     }
65
66     public ClassPath findClassPath(FileObject file, String JavaDoc type) {
67         if (type.equals(ClassPath.COMPILE)) {
68             return getCompileTimeClasspath(file);
69         } else if (type.equals(ClassPath.EXECUTE)) {
70             return getRunTimeClasspath(file);
71         } else if (type.equals(ClassPath.SOURCE)) {
72             return getSourcepath(file);
73         } else if (type.equals(ClassPath.BOOT)) {
74             return getBootClassPath();
75         } else {
76             return null;
77         }
78     }
79
80     private ClassPath getBootClassPath() {
81         if (boot == null) {
82             boot = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
83         }
84         return boot;
85     }
86
87     private ClassPath getSourcepath(FileObject file) { //NOPMD we don't care about the file passed in.. always the project dir is root
88
if (source == null) {
89             source = ClassPathSupport.createClassPath(new FileObject[] { project.getProjectDirectory() });
90         }
91         return source;
92     }
93
94     private ClassPath getRunTimeClasspath(FileObject file) { //NOPMD we don't care about the file passed in.. always the project dir is root
95
return null;
96     }
97
98     private ClassPath getCompileTimeClasspath(FileObject file) { //NOPMD we don't care about the file passed in.. always the project dir is root
99
if (compile == null) {
100             // do we need ant cp as it is?
101
ClassPath antcp = ClassPathFactory.createClassPath(
102                     ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
103                     FileUtil.toFile(project.getProjectDirectory()), project.getAntProjectHelper().getStandardPropertyEvaluator(),
104                 new String JavaDoc[] {"javac.classpath"})); // NOI18N
105
cpimpl = new CPImpl(project);
106             ClassPath bluejcp = ClassPathFactory.createClassPath(cpimpl);
107             compile = ClassPathSupport.createProxyClassPath( new ClassPath[] {antcp, bluejcp} );
108         }
109         return compile;
110     }
111     
112     public ClassPath[] getCompileTimeClasspath() {
113         if (compiles == null) {
114             compiles = new ClassPath[] { getCompileTimeClasspath(project.getProjectDirectory()),
115                                          //make source path, becuase it's equal with the built output path..
116
ClassPathSupport.createClassPath(new FileObject[] { project.getProjectDirectory() })};
117         }
118         return compiles;
119     }
120     
121     public ClassPath[] getSourcePath() {
122         if (sources == null) {
123             sources = new ClassPath[] { getSourcepath(project.getProjectDirectory()) };
124         }
125         return sources;
126     }
127     
128     public ClassPath[] getBootPath() {
129         if (boots == null) {
130             boots = new ClassPath[] { getBootClassPath() };
131         }
132         return boots;
133     }
134     
135 }
136
Popular Tags