2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.modules.j2ee.clientproject.classpath;
43
import java.beans.PropertyChangeEvent;
45
import java.net.MalformedURLException;
46
import java.util.List;
47
import java.util.ArrayList;
48
import java.util.Collections;
49
import java.beans.PropertyChangeListener;
50
import java.beans.PropertyChangeSupport;
52
import org.netbeans.spi.java.classpath.ClassPathImplementation;
53
import org.netbeans.spi.java.classpath.PathResourceImplementation;
54
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
55
import org.netbeans.modules.j2ee.clientproject.SourceRoots;
56
import org.netbeans.spi.project.support.ant.AntProjectHelper;
57
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
58
import org.openide.util.Exceptions;
62
* Implementation of a single classpath that is derived from one Ant property.
64
final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener {
66
private static final String PROP_BUILD_DIR = "build.dir"; //NOI18N
68
private final PropertyChangeSupport support = new PropertyChangeSupport(this);
69
private List<PathResourceImplementation> resources;
70
private final SourceRoots sourceRoots;
71
private final AntProjectHelper projectHelper;
72
private final PropertyEvaluator evaluator;
75
* Construct the implementation.
76
* @param sourceRoots used to get the roots information and events
78
public SourcePathImplementation(SourceRoots sourceRoots) {
79
assert sourceRoots != null;
80
this.sourceRoots = sourceRoots;
81
this.projectHelper = null;
82
this.evaluator = null;
83
sourceRoots.addPropertyChangeListener (this);
87
* Construct the implementation.
88
* @param sourceRoots used to get the roots information and events
89
* @param projectHelper used to obtain the project root
91
public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper, PropertyEvaluator evaluator) {
92
assert sourceRoots != null && projectHelper != null && evaluator != null;
93
this.sourceRoots = sourceRoots;
94
sourceRoots.addPropertyChangeListener (this);
95
this.projectHelper = projectHelper;
96
this.evaluator = evaluator;
97
evaluator.addPropertyChangeListener (this);
100
public List<PathResourceImplementation> getResources() {
101
synchronized (this) {
102
if (this.resources != null) {
103
return this.resources;
106
URL[] roots = sourceRoots.getRootURLs();
107
String buildDir = null;
108
if (projectHelper != null) {
109
buildDir = projectHelper.getStandardPropertyEvaluator().getProperty(PROP_BUILD_DIR);
111
synchronized (this) {
112
if (this.resources == null) {
113
List<PathResourceImplementation> result = new ArrayList<PathResourceImplementation>(roots.length);
114
for (int i = 0; i < roots.length; i++) {
115
PathResourceImplementation res = ClassPathSupport.createResource(roots[i]);
118
// adds build/generated/wsclient and build/generated/wsimport/client to resources to be available for code completion
119
if (projectHelper!=null) {
121
if (buildDir != null) {
122
// generated/wsclient
123
File f = new File (this.projectHelper.resolveFile (buildDir),"generated/wsclient"); //NOI18N
124
URL url = f.toURI().toURL();
125
if (!f.exists()) { //NOI18N
126
assert !url.toExternalForm().endsWith("/"); //NOI18N
127
url = new URL (url.toExternalForm()+'/'); //NOI18N
129
result.add(ClassPathSupport.createResource(url));
130
// generated/wsimport/client
131
f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); //NOI18N
132
url = f.toURI().toURL();
133
if (!f.exists()) { //NOI18N
134
assert !url.toExternalForm().endsWith("/"); //NOI18N
135
url = new URL (url.toExternalForm()+'/'); //NOI18N
137
result.add(ClassPathSupport.createResource(url));
139
} catch (MalformedURLException ex) {
140
Exceptions.printStackTrace(ex);
143
this.resources = Collections.unmodifiableList(result);
145
return this.resources;
149
public void addPropertyChangeListener(PropertyChangeListener listener) {
150
support.addPropertyChangeListener (listener);
153
public void removePropertyChangeListener(PropertyChangeListener listener) {
154
support.removePropertyChangeListener (listener);
158
public void propertyChange(PropertyChangeEvent evt) {
159
if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) {
160
synchronized (this) {
161
this.resources = null;
163
this.support.firePropertyChange (PROP_RESOURCES,null,null);
165
else if (this.evaluator != null && evt.getSource() == this.evaluator &&
166
(evt.getPropertyName() == null || PROP_BUILD_DIR.equals(evt.getPropertyName()))) {
167
synchronized (this) {
168
this.resources = null;
170
this.support.firePropertyChange (PROP_RESOURCES,null,null);