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.ejbjarproject.queries;
43
import java.beans.PropertyChangeEvent;
44
import java.beans.PropertyChangeListener;
46
import java.net.MalformedURLException;
48
import javax.swing.event.ChangeListener;
49
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
50
import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
51
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
52
import org.netbeans.spi.project.support.ant.AntProjectHelper;
53
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
54
import org.openide.filesystems.FileUtil;
55
import org.openide.util.ChangeSupport;
56
import org.openide.util.Exceptions;
57
import org.openide.util.WeakListeners;
61
* Finds Javadoc (if it is built) corresponding to binaries in web project.
62
* @author David Konecny, Jesse Glick
64
public class JavadocForBinaryQueryImpl implements JavadocForBinaryQueryImplementation {
66
private final AntProjectHelper helper;
67
private final PropertyEvaluator evaluator;
69
public JavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) {
71
this.evaluator = evaluator;
74
public JavadocForBinaryQuery.Result findJavadoc(final URL binaryRoot) {
76
class R implements JavadocForBinaryQuery.Result, PropertyChangeListener {
78
private final ChangeSupport changeSupport = new ChangeSupport(this);
82
JavadocForBinaryQueryImpl.this.evaluator.addPropertyChangeListener (WeakListeners.propertyChange(this,JavadocForBinaryQueryImpl.this.evaluator));
85
public synchronized URL[] getRoots() {
86
if (this.result == null) {
87
String javadocDir = evaluator.getProperty(EjbJarProjectProperties.DIST_JAVADOC_DIR);
88
if (javadocDir != null) {
89
File f = helper.resolveFile(javadocDir);
91
URL url = f.toURI().toURL();
93
assert !url.toExternalForm().endsWith("/") : f; // NOI18N
94
url = new URL(url.toExternalForm() + "/"); // NOI18N
96
this.result = new URL[] {url};
97
} catch (MalformedURLException e) {
98
this.result = new URL[0];
99
Exceptions.printStackTrace(e);
103
this.result = new URL[0];
108
public void addChangeListener(final ChangeListener l) {
110
changeSupport.addChangeListener(l);
112
public void removeChangeListener(final ChangeListener l) {
114
changeSupport.removeChangeListener(l);
117
public void propertyChange (final PropertyChangeEvent event) {
118
if (EjbJarProjectProperties.DIST_JAVADOC_DIR.equals(event.getPropertyName())) {
119
synchronized (this) {
122
this.changeSupport.fireChange ();
126
if (isRootOwner(binaryRoot, EjbJarProjectProperties.BUILD_CLASSES_DIR) || isRootOwner (binaryRoot, EjbJarProjectProperties.DIST_JAR)) {
132
private boolean isRootOwner (URL binaryRoot, String binaryProperty) {
134
if (FileUtil.getArchiveFile(binaryRoot) != null) {
135
binaryRoot = FileUtil.getArchiveFile(binaryRoot);
136
// XXX check whether this is really the root
138
String outDir = evaluator.getProperty(binaryProperty);
139
if (outDir != null) {
140
File f = helper.resolveFile (outDir);
141
URL url = f.toURI().toURL();
142
if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) { // NOI18N
143
assert !url.toExternalForm().endsWith("/") : f; // NOI18N
144
url = new URL(url.toExternalForm() + "/"); // NOI18N
146
return url.equals(binaryRoot) ||
147
binaryRoot.toExternalForm().startsWith(url.toExternalForm());
149
} catch (MalformedURLException malformedURL) {
150
Exceptions.printStackTrace(malformedURL);
155
// private URL getJavadoc(URL binaryRoot, String binaryProperty, String javadocProperty) {
157
// if (FileUtil.getArchiveFile(binaryRoot) != null) {
158
// binaryRoot = FileUtil.getArchiveFile(binaryRoot);
160
// String outDir = evaluator.getProperty(binaryProperty);
161
// if (outDir != null) {
162
// File f = helper.resolveFile (outDir);
163
// URL url = f.toURI().toURL();
164
// if (!f.exists() && !f.getPath().toLowerCase().endsWith(".jar")) {
165
// assert !url.toExternalForm().endsWith("/") : f;
166
// url = new URL(url.toExternalForm() + "/");
168
// if (url.equals(binaryRoot) ||
169
// binaryRoot.toExternalForm().startsWith(url.toExternalForm())) {
170
// String javadocDir = evaluator.getProperty(javadocProperty);
171
// if (javadocDir != null) {
172
// f = helper.resolveFile(javadocDir);
173
// return f.toURI().toURL();
177
// } catch (MalformedURLException malformedURL) {
178
// ErrorManager.getDefault().notify(malformedURL);