This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 44035
Collapse All | Expand All

(-)a/java.project/apichanges.xml (-2 / +50 lines)
Lines 40-47 Link Here
40
Version 2 license, then the option applies only if the new code is
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
41
made subject to such option by the copyright holder.
42
-->
42
-->
43
<?xml-stylesheet type="text/xml" href="../../nbbuild/javadoctools/apichanges.xsl"?>
43
<?xml-stylesheet type="text/xml" href="../nbbuild/javadoctools/apichanges.xsl"?>
44
<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../../nbbuild/javadoctools/apichanges.dtd">
44
<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../nbbuild/javadoctools/apichanges.dtd">
45
45
46
<!--
46
<!--
47
47
Lines 106-111 Link Here
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
107
108
    <changes>
108
    <changes>
109
        <change id="ant-project-libraries">
110
            <api name="general"/>
111
            <summary>Support for project-specific libraries</summary>
112
            <version major="1" minor="15"/>
113
            <date day="7" month="2" year="2008"/>
114
            <author login="mkleint"/>
115
            <compatibility addition="yes"/>
116
            <description>
117
                <p> A new utility class for helping project types create UI for
118
                sharable Libraries.
119
                </p>
120
                <p> An additional protected method for use in <code>ProjectClassPathModifierImplementation</code> subclasses named
121
                <code>performSharabilityHeuristics(URL,AntProjectHelper)</code> that takes classpath roots and tries to find the best way to reference that jar/folder.
122
                </p>
123
                
124
            </description>
125
            <class package="org.netbeans.spi.java.project.support.ui" name="SharableLibrariesUtils"/>
126
            <class package="org.netbeans.spi.java.project.classpath" name="ProjectClassPathModifierImplementation"/>
127
            <issue number="44035"/>
128
        </change>        
129
    <change id="AttachJavadocSourceToJar">
130
        <api name="ui"/>
131
        <summary>Added support classes for attaching javadoc/source to jar-based classpath items</summary>
132
        <version major="1" minor="14"/>
133
        <date day="21" month="1" year="2008"/>
134
        <author login="mkleint"/>
135
        <compatibility addition="yes"/>
136
        <description>
137
            3 new utility classes to allow attaching javadoc/source to existing jar dependencies of an Ant-based project.
138
            These classes are for use by project type owners. Specifically
139
            <ul>
140
                <li><code>ExtraSourceJavadocSupport.createExtraSourceQueryImplementation()</code> and 
141
                <code>ExtraSourceJavadocSupport.createExtraJavadocQueryImplementation()</code> 
142
                create instances to be added to project's Lookup.</li>
143
                <li><code>LookupMergerSupport.createSFBLookupMerger()</code> and <code>LookupMergerSupport.createJFBLookupMerger()</code>
144
                provide simple implementations of lookup mergers for respective query implementations. 
145
                A typical project implementation will put the lookup merger and the Extra*Support's instance in the project's lookup.</li>
146
                <li><code>EditJarSupport.showEditDialog()</code> is a facotry method for creating editing UI. To be added to Project's properties dialog
147
                preferably the "Libraries" panel. Client code (project type owner) is assumed to write down the ant properties
148
               source.reference.__name__ and javadoc.reference.__name__ in the same manner as file.reference.__name__ is persisted.</li>
149
            </ul>
150
        </description>
151
        <class package="org.netbeans.spi.java.project.support" name="ExtraSourceJavadocSupport"/>
152
        <class package="org.netbeans.spi.java.project.support" name="LookupMergerSupport"/>
153
        <class package="org.netbeans.spi.java.project.support.ui" name="EditJarSupport"/>
154
        <issue number="70497"/>
155
    </change>
156
        
109
    <change id="IncludeExcludeVisualizer">
157
    <change id="IncludeExcludeVisualizer">
110
        <api name="ui"/>
158
        <api name="ui"/>
111
        <summary>Added <code>IncludeExcludeVisualizer</code> support class</summary>
159
        <summary>Added <code>IncludeExcludeVisualizer</code> support class</summary>
(-)a/java.project/src/org/netbeans/api/java/project/classpath/ProjectClassPathModifier.java (-3 / +14 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.api.java.project.classpath;
42
package org.netbeans.api.java.project.classpath;
43
43
44
import java.io.File;
44
import java.io.IOException;
45
import java.io.IOException;
45
import java.net.URI;
46
import java.net.URI;
46
import java.net.URL;
47
import java.net.URL;
Lines 52-57 Link Here
52
import org.netbeans.api.project.libraries.Library;
53
import org.netbeans.api.project.libraries.Library;
53
import org.netbeans.modules.java.project.classpath.ProjectClassPathModifierAccessor;
54
import org.netbeans.modules.java.project.classpath.ProjectClassPathModifierAccessor;
54
import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation;
55
import org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation;
56
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
57
import org.netbeans.spi.project.support.ant.PropertyUtils;
55
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
59
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.URLMapper;
60
import org.openide.filesystems.URLMapper;
Lines 129-135 Link Here
129
    /**
132
    /**
130
     * Adds archive files or folders into the project's classpath if the
133
     * Adds archive files or folders into the project's classpath if the
131
     * entries are not already there.
134
     * entries are not already there.
132
     * @param classPathRoots roots to be added, each root has to be either a root of an archive or a folder
135
     * @param classPathRoots roots to be added, each root has to be either a root of an archive or a folder url can be absolute or relative
133
     * @param projectArtifact a file whose classpath should be extended
136
     * @param projectArtifact a file whose classpath should be extended
134
     * @param classPathType the type of classpath to be extended, @see ClassPath
137
     * @param classPathType the type of classpath to be extended, @see ClassPath
135
     * @return true in case the classpath was changed, (at least one classpath root was added to the classpath),
138
     * @return true in case the classpath was changed, (at least one classpath root was added to the classpath),
Lines 149-160 Link Here
149
            }
152
            }
150
            else if (extensible.pcpe != null) {
153
            else if (extensible.pcpe != null) {
151
                boolean result = false;
154
                boolean result = false;
155
                final Project project = FileOwnerQuery.getOwner(projectArtifact);
156
                final File projectFolderFile = FileUtil.toFile(project.getProjectDirectory());
152
                for (int i=0; i< classPathRoots.length; i++) {
157
                for (int i=0; i< classPathRoots.length; i++) {
153
                    URL urlToAdd = classPathRoots[i];
158
                    URL urlToAdd = classPathRoots[i];
154
                    if ("jar".equals(urlToAdd.getProtocol())) {
159
                    if ("jar".equals(urlToAdd.getProtocol())) {
155
                        urlToAdd = FileUtil.getArchiveFile (urlToAdd);
160
                        urlToAdd = FileUtil.getArchiveFile (urlToAdd);
156
                    }
161
                    }
157
                    final FileObject fo = URLMapper.findFileObject(urlToAdd);
162
                    final FileObject fo;
163
                    if (LibrariesSupport.isAbsoluteURL(urlToAdd)) {
164
                        fo = URLMapper.findFileObject(urlToAdd);
165
                    } else {
166
                        File f = PropertyUtils.resolveFile(projectFolderFile, LibrariesSupport.convertURLToFilePath(urlToAdd));
167
                        fo = FileUtil.toFileObject(f);
168
                    }
158
                    if (fo == null) {
169
                    if (fo == null) {
159
                        throw new UnsupportedOperationException ("Adding of a non existent root is not supported by project.");  //NOI18N
170
                        throw new UnsupportedOperationException ("Adding of a non existent root is not supported by project.");  //NOI18N
160
                    }
171
                    }
Lines 251-257 Link Here
251
        throw new UnsupportedOperationException ();
262
        throw new UnsupportedOperationException ();
252
    }
263
    }
253
    
264
    
254
    
265
255
    /**
266
    /**
256
     * Returns {@link ProjectClassPathModifier#Extensible} for given project artifact and classpath type. 
267
     * Returns {@link ProjectClassPathModifier#Extensible} for given project artifact and classpath type. 
257
     * An Extensible implies a classpath to be extended. Different project type may provide different types
268
     * An Extensible implies a classpath to be extended. Different project type may provide different types
(-)a/java.project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathModifierImplementation.java (-1 / +95 lines)
Lines 41-54 Link Here
41
41
42
package org.netbeans.spi.java.project.classpath;
42
package org.netbeans.spi.java.project.classpath;
43
43
44
import java.io.File;
44
import java.io.IOException;
45
import java.io.IOException;
45
import java.net.URI;
46
import java.net.URI;
47
import java.net.URISyntaxException;
46
import java.net.URL;
48
import java.net.URL;
47
import org.netbeans.api.project.SourceGroup;
49
import org.netbeans.api.project.SourceGroup;
48
import org.netbeans.api.project.ant.AntArtifact;
50
import org.netbeans.api.project.ant.AntArtifact;
49
import org.netbeans.api.project.libraries.Library;
51
import org.netbeans.api.project.libraries.Library;
52
import org.netbeans.api.queries.CollocationQuery;
50
import org.netbeans.modules.java.project.classpath.ProjectClassPathModifierAccessor;
53
import org.netbeans.modules.java.project.classpath.ProjectClassPathModifierAccessor;
54
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
55
import org.netbeans.spi.project.support.ant.AntProjectHelper;
56
import org.netbeans.spi.project.support.ant.PropertyUtils;
51
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileUtil;
52
59
53
/**
60
/**
54
 * An SPI for project's classpaths modification.
61
 * An SPI for project's classpaths modification.
Lines 184-190 Link Here
184
     * removing of an artifact from the classpath of the given type.
191
     * removing of an artifact from the classpath of the given type.
185
     */
192
     */
186
    protected abstract boolean removeAntArtifacts (AntArtifact[] artifacts, URI[] artifactElements, SourceGroup sourceGroup, String type) throws IOException, UnsupportedOperationException;
193
    protected abstract boolean removeAntArtifacts (AntArtifact[] artifacts, URI[] artifactElements, SourceGroup sourceGroup, String type) throws IOException, UnsupportedOperationException;
187
194
    
195
    /**
196
     * Takes a classpath root and tries to figure the best way to reference that file for that particular project.
197
     * The possible actions include relativization of path, copying to sharable libraries folder etc.
198
     * @param classpathRoot passed in through the <code>addRoots()</code> and <code>removeRoots()</code> methods
199
     * @param helper
200
     * @return a relative or absolute path to the original jar/folder or to a copy of it.
201
     * @throws java.net.URISyntaxException
202
     * @since org.netbeans.modules.java.project/1 1.15
203
     */
204
    protected final String performSharabilityHeuristics(URL classpathRoot, AntProjectHelper helper) throws URISyntaxException, IOException {
205
        assert classpathRoot != null;
206
        assert classpathRoot.toExternalForm().endsWith("/");    //NOI18N
207
        URL toAdd = FileUtil.getArchiveFile(classpathRoot);
208
        if (toAdd == null) {
209
            toAdd = classpathRoot;
210
        }
211
        File prjRoot = FileUtil.toFile(helper.getProjectDirectory());
212
        assert LibrariesSupport.isAbsoluteURL(toAdd);
213
        final File file = new File(toAdd.toURI());
214
        String f;
215
        if (CollocationQuery.areCollocated(file, prjRoot)) {
216
            //colocated get always relative path
217
            f = PropertyUtils.relativizeFile(prjRoot, file);
218
        } else {
219
            if (helper.isSharableProject()) {
220
                //library location is not collocated..
221
                //-> use absolute path
222
                // sort of heuristics to have the
223
                File library = PropertyUtils.resolveFile(prjRoot, helper.getLibrariesLocation());
224
                boolean fileLibraryCol = CollocationQuery.areCollocated(library.getParentFile(), file);
225
                boolean libraryAbsolute = LibrariesSupport.isAbsoluteURL(LibrariesSupport.convertFilePathToURL(helper.getLibrariesLocation()));
226
                // when library location is absolute, we are most probably dealing with the famous X: drive location
227
                // since the library is absolute, it shoudl be safe to reference everything under it as absolute as well.
228
                if (libraryAbsolute && fileLibraryCol) {
229
                    f = file.getAbsolutePath();
230
                } else if (libraryAbsolute && !fileLibraryCol) {
231
                    File fl = copyFile(file, FileUtil.toFileObject(library.getParentFile()));
232
                    f = fl.getAbsolutePath();
233
                } else if (!libraryAbsolute && fileLibraryCol) {
234
                    f = PropertyUtils.relativizeFile(prjRoot, file);
235
                } else { // if (!libraryAbsolute && !fileLibraryCol)
236
                    File fl = copyFile(file, FileUtil.toFileObject(library.getParentFile()));
237
                    f = PropertyUtils.relativizeFile(prjRoot, fl);
238
                }
239
            } else {
240
                //nonsharable project are ok with absolute path
241
                f = file.getAbsolutePath();
242
            }
243
        }
244
        return f;
245
    }
246
    
247
    private File copyFile(File file, FileObject newRoot) throws IOException {
248
        FileObject fo = FileUtil.toFileObject(file);
249
        if (fo.isFolder()) {
250
            return FileUtil.toFile(copyFolderRecursively(fo, newRoot));
251
        } else {
252
            FileObject foExists = newRoot.getFileObject(fo.getName(), fo.getExt());
253
            if (foExists != null) {
254
                foExists.delete();
255
            }
256
            return FileUtil.toFile(FileUtil.copyFile(fo, newRoot, fo.getName(), fo.getExt()));
257
        }
258
    }
259
    
260
    
261
    //copied from FileChooserAccessory
262
    private FileObject copyFolderRecursively(FileObject sourceFolder, FileObject destination) throws IOException {
263
        assert sourceFolder.isFolder() : sourceFolder;
264
        assert destination.isFolder() : destination;
265
        FileObject destinationSubFolder = destination.getFileObject(sourceFolder.getName());
266
        if (destinationSubFolder == null) {
267
            destinationSubFolder = destination.createFolder(sourceFolder.getName());
268
        }
269
        for (FileObject fo : sourceFolder.getChildren()) {
270
            if (fo.isFolder()) {
271
                copyFolderRecursively(fo, destinationSubFolder);
272
            } else {
273
                FileObject foExists = destinationSubFolder.getFileObject(fo.getName(), fo.getExt());
274
                if (foExists != null) {
275
                    foExists.delete();
276
                }
277
                FileUtil.copyFile(fo, destinationSubFolder, fo.getName(), fo.getExt());
278
            }
279
        }
280
        return destinationSubFolder;
281
    }
188
    
282
    
189
    private static class Accessor extends ProjectClassPathModifierAccessor {        
283
    private static class Accessor extends ProjectClassPathModifierAccessor {        
190
        
284
        
(-)ffef4cca2ff4 (+88 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
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]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.project.support;
41
42
import org.netbeans.api.project.Project;
43
import org.netbeans.modules.java.project.ExtraProjectSourceForBinaryQueryImpl;
44
import org.netbeans.modules.java.project.ExtraProjectJavadocForBinaryQueryImpl;
45
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
46
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
47
import org.netbeans.spi.project.support.ant.AntProjectHelper;
48
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
49
50
/**
51
 * Utility factory class for ant-based project implementors, the created instances, once
52
 * put into project's lookup, make sure the javadoc and source references in project properties
53
 * are correctly recognized and used by the java infrastructure.
54
 * The format of project properties used is as follows:
55
 * <ul>
56
 *      <li>file.reference.__jarName__ - the binary file reference used to point to files on project classpath. </li>
57
 *      <li>javadoc.reference.__jarName__ - the file reference pointing to javadoc for file.reference.__jarName__ </li>
58
 *      <li>source.reference.__jarName__ - the file reference pointing to sources for file.reference.__jarName__ </li>
59
 * </ul>
60
 * @author mkleint
61
 * @since org.netbeans.modules.java.project 1.14
62
 */
63
public class ExtraSourceJavadocSupport {
64
65
    /**
66
     * Create project's SourceForBinaryQueryImplementation object for handling 
67
     * property based sources
68
     * @param helper project's AntProjectHelper instance
69
     * @param eval project's PropertyEvaluator instance
70
     * @return object to use in project's lookup.
71
     */
72
    public static SourceForBinaryQueryImplementation createExtraSourceQueryImplementation (Project project, AntProjectHelper helper, PropertyEvaluator eval) {
73
        return new ExtraProjectSourceForBinaryQueryImpl(project, helper, eval);
74
    }
75
    
76
    /**
77
     * Create project's JavadocForBinaryQueryImplementation object for handling 
78
     * property based javadoc
79
     * @param helper project's AntProjectHelper instance
80
     * @param eval project's PropertyEvaluator instance
81
     * @return object to use in project's lookup.
82
     */
83
    public static JavadocForBinaryQueryImplementation createExtraJavadocQueryImplementation (Project project, AntProjectHelper helper, PropertyEvaluator eval) {
84
        return new ExtraProjectJavadocForBinaryQueryImpl(project, helper, eval);
85
    }
86
87
88
}
(-)ffef4cca2ff4 (+142 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
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]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.project.support;
41
42
import java.net.URL;
43
import java.util.Collection;
44
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
45
import org.netbeans.api.java.queries.SourceForBinaryQuery;
46
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
47
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
48
import org.netbeans.spi.project.LookupMerger;
49
import org.openide.util.Lookup;
50
51
52
/**
53
 * Factory class for creation of {@link org.netbeans.spi.project.LookupMerger} instances.
54
 * @author mkleint
55
 * @since org.netbeans.modules.java.project 1.14
56
 */
57
public final class LookupMergerSupport {
58
59
    /**
60
     * Create a simple instance of LookupMerger for SourceForBinaryQueryImplementation. It takes
61
     * all implemntations it finds inthe provided lookup and iterates them until a result
62
     * is found.
63
     * @return
64
     */
65
    public static LookupMerger<SourceForBinaryQueryImplementation> createSFBLookupMerger() {
66
        return new SFBLookupMerger();
67
    }
68
69
    /**
70
     * Create a simple instance of LookupMerger for JavadocForBinaryQueryImplementation. It takes
71
     * all implemntations it finds inthe provided lookup and iterates them until a result
72
     * is found.
73
     * @return
74
     */
75
    public static LookupMerger<JavadocForBinaryQueryImplementation> createJFBLookupMerger() {
76
        return new JFBLookupMerger();
77
    }
78
    
79
    private static class SFBLookupMerger implements LookupMerger<SourceForBinaryQueryImplementation> {
80
81
        public Class<SourceForBinaryQueryImplementation> getMergeableClass() {
82
            return SourceForBinaryQueryImplementation.class;
83
        }
84
85
        public SourceForBinaryQueryImplementation merge(Lookup lookup) {
86
            return new SFBIMerged(lookup);
87
        }
88
        
89
    }
90
    
91
    private static class SFBIMerged implements SourceForBinaryQueryImplementation {
92
        private Lookup lookup;
93
        
94
        public SFBIMerged(Lookup lkp) {
95
            lookup = lkp;
96
        }
97
        public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
98
            Collection<? extends SourceForBinaryQueryImplementation> col = lookup.lookupAll(SourceForBinaryQueryImplementation.class);
99
            for (SourceForBinaryQueryImplementation impl : col) {
100
                SourceForBinaryQuery.Result res = impl.findSourceRoots(binaryRoot);
101
                if (res != null) {
102
                    return res;
103
                }
104
            }
105
            return null;
106
        }
107
        
108
    }
109
    
110
    private static class JFBLookupMerger implements LookupMerger<JavadocForBinaryQueryImplementation> {
111
112
        public Class<JavadocForBinaryQueryImplementation> getMergeableClass() {
113
            return JavadocForBinaryQueryImplementation.class;
114
        }
115
116
        public JavadocForBinaryQueryImplementation merge(Lookup lookup) {
117
            return new JFBIMerged(lookup);
118
        }
119
        
120
    }
121
    
122
    private static class JFBIMerged implements JavadocForBinaryQueryImplementation {
123
        private Lookup lookup;
124
        
125
        public JFBIMerged(Lookup lkp) {
126
            lookup = lkp;
127
        }
128
        
129
        public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) {
130
            Collection<? extends JavadocForBinaryQueryImplementation> col = lookup.lookupAll(JavadocForBinaryQueryImplementation.class);
131
            for (JavadocForBinaryQueryImplementation impl : col) {
132
                JavadocForBinaryQuery.Result res = impl.findJavadoc(binaryRoot);
133
                if (res != null) {
134
                    return res;
135
                }
136
            }
137
            return null;
138
        }
139
        
140
    }
141
    
142
}
(-)a/java.project/src/org/netbeans/spi/java/project/support/ui/BrokenReferencesSupport.java (-1 / +1 lines)
Lines 107-113 Link Here
107
     */
107
     */
108
    public static boolean isBroken(AntProjectHelper projectHelper, 
108
    public static boolean isBroken(AntProjectHelper projectHelper, 
109
            ReferenceHelper referenceHelper, String[] properties, String[] platformProperties) {
109
            ReferenceHelper referenceHelper, String[] properties, String[] platformProperties) {
110
        return BrokenReferencesModel.isBroken(projectHelper, 
110
        return BrokenReferencesModel.isBroken(projectHelper, referenceHelper,
111
            projectHelper.getStandardPropertyEvaluator(), properties, platformProperties);
111
            projectHelper.getStandardPropertyEvaluator(), properties, platformProperties);
112
    }
112
    }
113
    
113
    
(-)ffef4cca2ff4 (+282 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
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]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.project.support.ui;
41
42
import java.io.File;
43
import java.io.IOException;
44
import java.util.Arrays;
45
import java.util.Collection;
46
import javax.swing.JFileChooser;
47
import javax.swing.SwingUtilities;
48
import javax.swing.filechooser.FileFilter;
49
import org.netbeans.api.project.ant.FileChooser;
50
import org.netbeans.spi.java.project.support.ui.EditJarSupport;
51
import org.netbeans.spi.project.support.ant.AntProjectHelper;
52
import org.openide.filesystems.FileUtil;
53
import org.openide.util.Exceptions;
54
import org.openide.util.NbBundle;
55
56
/**
57
 *
58
 * @author  mkleint
59
 */
60
class EditJarPanel extends javax.swing.JPanel {
61
62
    private EditJarSupport.Item item;
63
    private AntProjectHelper helper;
64
65
    /** Creates new form EditJarPanel */
66
    private EditJarPanel() {
67
        initComponents();
68
    }
69
70
    EditJarPanel(EditJarSupport.Item item, AntProjectHelper helper) {
71
        this();
72
        this.item = item;
73
        this.helper = helper;
74
        txtJar.setText(item.getJarFile());
75
        if (item.getSourceFile() != null) {
76
            txtSource.setText(item.getSourceFile());
77
        }
78
        if (item.getJavadocFile() != null) {
79
            txtJavadoc.setText(item.getJavadocFile());
80
        }
81
    }
82
83
    EditJarSupport.Item assignValues() {
84
        if (txtSource.getText() != null && txtSource.getText().trim().length() > 0) {
85
            item.setSourceFile(txtSource.getText().trim());
86
        } else {
87
            item.setSourceFile(null);
88
        }
89
        if (txtJavadoc.getText() != null && txtJavadoc.getText().trim().length() > 0) {
90
            item.setJavadocFile(txtJavadoc.getText().trim());
91
        } else {
92
            item.setJavadocFile(null);
93
        }
94
        return item;
95
    }
96
97
    /** This method is called from within the constructor to
98
     * initialize the form.
99
     * WARNING: Do NOT modify this code. The content of this method is
100
     * always regenerated by the Form Editor.
101
     */
102
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
103
    private void initComponents() {
104
105
        lblJar = new javax.swing.JLabel();
106
        txtJar = new javax.swing.JTextField();
107
        lblJavadoc = new javax.swing.JLabel();
108
        txtJavadoc = new javax.swing.JTextField();
109
        btnJavadoc = new javax.swing.JButton();
110
        lblSource = new javax.swing.JLabel();
111
        txtSource = new javax.swing.JTextField();
112
        btnSource = new javax.swing.JButton();
113
114
        lblJar.setLabelFor(txtJar);
115
        org.openide.awt.Mnemonics.setLocalizedText(lblJar, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblJar.text")); // NOI18N
116
117
        txtJar.setEditable(false);
118
119
        lblJavadoc.setLabelFor(txtJavadoc);
120
        org.openide.awt.Mnemonics.setLocalizedText(lblJavadoc, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblJavadoc.text")); // NOI18N
121
122
        org.openide.awt.Mnemonics.setLocalizedText(btnJavadoc, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.btnJavadoc.text")); // NOI18N
123
        btnJavadoc.addActionListener(new java.awt.event.ActionListener() {
124
            public void actionPerformed(java.awt.event.ActionEvent evt) {
125
                btnJavadocActionPerformed(evt);
126
            }
127
        });
128
129
        lblSource.setLabelFor(txtSource);
130
        org.openide.awt.Mnemonics.setLocalizedText(lblSource, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblSource.text")); // NOI18N
131
132
        org.openide.awt.Mnemonics.setLocalizedText(btnSource, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.btnSource.text")); // NOI18N
133
        btnSource.addActionListener(new java.awt.event.ActionListener() {
134
            public void actionPerformed(java.awt.event.ActionEvent evt) {
135
                btnSourceActionPerformed(evt);
136
            }
137
        });
138
139
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
140
        this.setLayout(layout);
141
        layout.setHorizontalGroup(
142
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
143
            .add(layout.createSequentialGroup()
144
                .addContainerGap()
145
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
146
                    .add(lblJar)
147
                    .add(lblJavadoc)
148
                    .add(lblSource))
149
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
150
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
151
                    .add(layout.createSequentialGroup()
152
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153
                            .add(txtSource, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
154
                            .add(txtJavadoc, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE))
155
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
156
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
157
                            .add(btnSource)
158
                            .add(btnJavadoc)))
159
                    .add(txtJar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE))
160
                .addContainerGap())
161
        );
162
        layout.setVerticalGroup(
163
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164
            .add(layout.createSequentialGroup()
165
                .addContainerGap()
166
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
167
                    .add(lblJar)
168
                    .add(txtJar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
169
                .add(18, 18, 18)
170
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
171
                    .add(lblJavadoc)
172
                    .add(btnJavadoc)
173
                    .add(txtJavadoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
174
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
175
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
176
                    .add(lblSource)
177
                    .add(btnSource)
178
                    .add(txtSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
179
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
180
        );
181
182
        lblJavadoc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditJarPanel.class, "ACSD_lblJavadoc")); // NOI18N
183
        btnJavadoc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditJarPanel.class, "ACSD_btnJavadoc")); // NOI18N
184
        lblSource.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditJarPanel.class, "ACSD_lblSource")); // NOI18N
185
        btnSource.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditJarPanel.class, "ACSD_btnSource")); // NOI18N
186
    }// </editor-fold>//GEN-END:initComponents
187
    private void btnJavadocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnJavadocActionPerformed
188
        // Let user search for the Jar file
189
        FileChooser chooser = new FileChooser(helper, true);
190
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
191
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
192
        chooser.setMultiSelectionEnabled(false);
193
        chooser.setDialogTitle(NbBundle.getMessage(EditJarPanel.class, "LBL_Edit_Jar_Panel_browse"));
194
        //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
195
        chooser.setAcceptAllFileFilterUsed(false);
196
        chooser.setFileFilter(new SimpleFileFilter(
197
                "Javadoc Entry (folder, ZIP or JAR file)", 
198
                new String[]{"ZIP", "JAR"}));   // NOI18N 
199
        File curDir = helper.resolveFile(item.getJarFile());
200
        chooser.setCurrentDirectory(curDir);
201
        int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser
202
203
        if (option == JFileChooser.APPROVE_OPTION) {
204
            String files[];
205
            try {
206
                files = chooser.getSelectedPaths();
207
            } catch (IOException ex) {
208
                // TODO: add localized message
209
                Exceptions.printStackTrace(ex);
210
                return;
211
            }
212
            txtJavadoc.setText(files[0]);
213
        }
214
        
215
    }//GEN-LAST:event_btnJavadocActionPerformed
216
217
    private void btnSourceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSourceActionPerformed
218
        FileChooser chooser = new FileChooser(helper, true);
219
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
220
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
221
        chooser.setMultiSelectionEnabled(false);
222
        chooser.setDialogTitle(NbBundle.getMessage(EditJarPanel.class, "LBL_Edit_Jar_Panel_browse"));
223
        //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
224
        chooser.setAcceptAllFileFilterUsed(false);
225
        chooser.setFileFilter(new SimpleFileFilter(
226
                "Source Entry (folder, ZIP or JAR file)", 
227
                new String[]{"ZIP", "JAR"}));   // NOI18N 
228
        File curDir = helper.resolveFile(item.getJarFile());
229
        chooser.setCurrentDirectory(curDir);
230
        int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser
231
232
        if (option == JFileChooser.APPROVE_OPTION) {
233
            String files[];
234
            try {
235
                files = chooser.getSelectedPaths();
236
            } catch (IOException ex) {
237
                // TODO: add localized message
238
                Exceptions.printStackTrace(ex);
239
                return;
240
            }
241
            txtSource.setText(files[0]);
242
        }
243
244
    }//GEN-LAST:event_btnSourceActionPerformed
245
    // Variables declaration - do not modify//GEN-BEGIN:variables
246
    private javax.swing.JButton btnJavadoc;
247
    private javax.swing.JButton btnSource;
248
    private javax.swing.JLabel lblJar;
249
    private javax.swing.JLabel lblJavadoc;
250
    private javax.swing.JLabel lblSource;
251
    private javax.swing.JTextField txtJar;
252
    private javax.swing.JTextField txtJavadoc;
253
    private javax.swing.JTextField txtSource;
254
    // End of variables declaration//GEN-END:variables
255
    private static class SimpleFileFilter extends FileFilter {
256
257
        private String description;
258
        private Collection extensions;
259
260
        public SimpleFileFilter(String description, String[] extensions) {
261
            this.description = description;
262
            this.extensions = Arrays.asList(extensions);
263
        }
264
265
        public boolean accept(File f) {
266
            if (f.isDirectory()) {
267
                return true;
268
            }
269
            String name = f.getName();
270
            int index = name.lastIndexOf('.');   //NOI18N
271
            if (index <= 0 || index == name.length() - 1) {
272
                return false;
273
            }
274
            String extension = name.substring(index + 1).toUpperCase();
275
            return this.extensions.contains(extension);
276
        }
277
278
        public String getDescription() {
279
            return this.description;
280
        }
281
    }
282
}
(-)ffef4cca2ff4 (+118 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
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]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.project.support.ui;
41
42
import org.netbeans.spi.project.support.ant.AntProjectHelper;
43
import org.openide.DialogDescriptor;
44
import org.openide.DialogDisplayer;
45
46
/**
47
 * Factory for creating a dialog for editing jar/folder-based classpath dependencies 
48
 * for Ant based projects. Allows to add/modify/remove source and javadoc jars.
49
 * @author mkleint
50
 * 
51
 * @since org.netbeans.modules.java.project 1.14
52
 */
53
public final class EditJarSupport {
54
    
55
    /**
56
     * Show dialog that allows to edit source and javadoc jar/folder locations
57
     * for a given jar/folder on the classpath. Returns null when dialog was cancelled,
58
     * otherwise returns EditJarSupport.Item bean with new values.
59
     * 
60
     * @param helper
61
     * @param item - bean with currently used values for classpath jar, source and javadoc jars location
62
     * @return null if dialog cancelled, or the original item with modified values
63
     */
64
    public static Item showEditDialog(AntProjectHelper helper, Item item) {
65
        EditJarPanel panel = new EditJarPanel(item, helper);
66
        DialogDescriptor dd = new DialogDescriptor(panel, "Edit jar reference");
67
        Object ret = DialogDisplayer.getDefault().notify(dd);
68
        if (DialogDescriptor.OK_OPTION == ret) {
69
            return panel.assignValues();
70
        }
71
        return null;
72
    }
73
    
74
    /**
75
     * Simple object holding information used for passing information in and out of the 
76
     * <code>EditJarSupport.showEditDialog</code> method.
77
     * 
78
     */
79
    public static final class Item {
80
        private String jarFile;
81
        private String sourceFile;
82
        private String javadocFile;
83
84
        /**
85
         * classpath file location, can be relative or absolute path (relative to project basedir)
86
         */
87
        public String getJarFile() {
88
            return jarFile;
89
        }
90
91
        public void setJarFile(String jarFile) {
92
            this.jarFile = jarFile;
93
        }
94
95
        /**
96
         * source file location, can be relative or absolute path (relative to project basedir)
97
         */
98
        public String getSourceFile() {
99
            return sourceFile;
100
        }
101
102
        public void setSourceFile(String sourceFile) {
103
            this.sourceFile = sourceFile;
104
        }
105
106
        /**
107
         * javadoc file location, can be relative or absolute path (relative to project basedir)
108
         */
109
        public String getJavadocFile() {
110
            return javadocFile;
111
        }
112
113
        public void setJavadocFile(String javadocFile) {
114
            this.javadocFile = javadocFile;
115
        }
116
    }
117
118
}
(-)ffef4cca2ff4 (+218 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
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]"
23
 *
24
 * Contributor(s):
25
 *
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.
29
 *
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.
40
 */
41
package org.netbeans.spi.java.project.support.ui;
42
43
import java.io.File;
44
import javax.swing.JPanel;
45
import javax.swing.event.DocumentEvent;
46
import javax.swing.event.DocumentListener;
47
import org.netbeans.api.queries.CollocationQuery;
48
import org.netbeans.spi.project.support.ant.AntProjectHelper;
49
import org.netbeans.spi.project.support.ant.PropertyUtils;
50
import org.openide.WizardDescriptor;
51
import org.openide.filesystems.FileUtil;
52
import org.openide.util.ChangeSupport;
53
import org.openide.util.NbBundle;
54
55
56
final class MakeSharableVisualPanel1 extends JPanel {
57
58
    private AntProjectHelper helper;
59
    private ChangeSupport support;
60
    private WizardDescriptor settings;
61
    private DocumentListener docListener;
62
63
    /** Creates new form MakeSharableVisualPanel1 */
64
    public MakeSharableVisualPanel1(ChangeSupport supp) {
65
        initComponents();
66
        this.support = supp;
67
        docListener = new DocumentListener() {
68
            public void insertUpdate(DocumentEvent e) { 
69
                support.fireChange();
70
            }
71
72
            public void removeUpdate(DocumentEvent e) {
73
                support.fireChange();
74
            }
75
76
            public void changedUpdate(DocumentEvent e) {
77
                support.fireChange();
78
            }
79
            
80
        };
81
        txtDefinition.getDocument().addDocumentListener(docListener);
82
    }
83
84
    @Override
85
    public String getName() {
86
        return NbBundle.getMessage(MakeSharableVisualPanel1.class, "TIT_LibraryDefinitionSelection"); //NOI18N
87
    }
88
89
    boolean isValidPanel() {
90
        String location = getLibraryLocation();
91
        boolean wrong = false;
92
        if (new File(location).isAbsolute()) {
93
            settings.putProperty("WizardPanel_errorMessage", // NOI18N
94
                    org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "WARN_MakeSharable.absolutePath"));
95
            wrong = true;
96
        } else {
97
            File projectLoc = helper.resolveFile(location);
98
            File libLoc = PropertyUtils.resolveFile(projectLoc, location);
99
            if (!CollocationQuery.areCollocated(projectLoc, libLoc)) {
100
                settings.putProperty("WizardPanel_errorMessage", // NOI18N
101
                        org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "WARN_makeSharable.relativePath"));
102
                wrong = true;
103
            }
104
        }
105
        if (!wrong) {
106
            settings.putProperty("WizardPanel_errorMessage", null);// NOI18N
107
        }
108
109
        return true;
110
    }
111
112
    private String getLibraryLocation() {
113
        return txtDefinition.getText().trim();
114
    }
115
116
    private void setLibraryLocation(String loc) {
117
        txtDefinition.setText(loc);
118
    }
119
120
    void readSettings(WizardDescriptor wiz) {
121
        settings = wiz;
122
        String loc = (String) wiz.getProperty(SharableLibrariesUtils.PROP_LOCATION);
123
        helper = (AntProjectHelper) wiz.getProperty(SharableLibrariesUtils.PROP_HELPER);
124
        if (loc == null) {
125
            loc = ".." + File.separator + "libraries"; //NOI18N
126
        } else {
127
            loc.substring(loc.length() - SharableLibrariesUtils.DEFAULT_LIBRARIES_FILENAME.length(), loc.length());
128
        }
129
        setLibraryLocation(loc);
130
        support.fireChange();
131
    }
132
133
    void storeSettings(WizardDescriptor wiz) {
134
        String librariesDefinition = getLibraryLocation();
135
        if (librariesDefinition != null) {
136
            if (!librariesDefinition.endsWith(File.separator)) {
137
                librariesDefinition += File.separatorChar;
138
            }
139
            librariesDefinition += SharableLibrariesUtils.DEFAULT_LIBRARIES_FILENAME;
140
        }
141
142
        wiz.putProperty(SharableLibrariesUtils.PROP_LOCATION, librariesDefinition);
143
    }
144
145
    /** This method is called from within the constructor to
146
     * initialize the form.
147
     * WARNING: Do NOT modify this code. The content of this method is
148
     * always regenerated by the Form Editor.
149
     */
150
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
151
    private void initComponents() {
152
153
        lblDefinition = new javax.swing.JLabel();
154
        txtDefinition = new javax.swing.JTextField();
155
        btnDefinition = new javax.swing.JButton();
156
        lblNote = new javax.swing.JLabel();
157
158
        lblDefinition.setLabelFor(txtDefinition);
159
        org.openide.awt.Mnemonics.setLocalizedText(lblDefinition, org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "MakeSharableVisualPanel1.lblDefinition.text")); // NOI18N
160
161
        org.openide.awt.Mnemonics.setLocalizedText(btnDefinition, org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "MakeSharableVisualPanel1.btnDefinition.text")); // NOI18N
162
        btnDefinition.addActionListener(new java.awt.event.ActionListener() {
163
            public void actionPerformed(java.awt.event.ActionEvent evt) {
164
                btnDefinitionActionPerformed(evt);
165
            }
166
        });
167
168
        org.openide.awt.Mnemonics.setLocalizedText(lblNote, org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "MakeSharableVisualPanel1.lblNote.text")); // NOI18N
169
        lblNote.setVerticalAlignment(javax.swing.SwingConstants.TOP);
170
171
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
172
        this.setLayout(layout);
173
        layout.setHorizontalGroup(
174
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
175
            .add(layout.createSequentialGroup()
176
                .add(lblDefinition)
177
                .add(10, 10, 10)
178
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
179
                    .add(lblNote, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
180
                    .add(layout.createSequentialGroup()
181
                        .add(txtDefinition, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
182
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
183
                        .add(btnDefinition))))
184
        );
185
        layout.setVerticalGroup(
186
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
187
            .add(layout.createSequentialGroup()
188
                .addContainerGap()
189
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
190
                    .add(btnDefinition)
191
                    .add(lblDefinition)
192
                    .add(txtDefinition, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
193
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
194
                .add(lblNote, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
195
                .addContainerGap(116, Short.MAX_VALUE))
196
        );
197
198
        lblDefinition.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "ACSD_lblDefinition")); // NOI18N
199
        btnDefinition.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel1.class, "ACSD_btnDefinition")); // NOI18N
200
    }// </editor-fold>//GEN-END:initComponents
201
202
private void btnDefinitionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDefinitionActionPerformed
203
        File f = FileUtil.toFile(helper.getProjectDirectory()); // NOI18N
204
        String curr = SharableLibrariesUtils.browseForLibraryLocation(getLibraryLocation(), this, f);
205
        if (curr != null) {
206
            setLibraryLocation(curr);
207
        }
208
209
}//GEN-LAST:event_btnDefinitionActionPerformed
210
211
    // Variables declaration - do not modify//GEN-BEGIN:variables
212
    private javax.swing.JButton btnDefinition;
213
    private javax.swing.JLabel lblDefinition;
214
    private javax.swing.JLabel lblNote;
215
    private javax.swing.JTextField txtDefinition;
216
    // End of variables declaration//GEN-END:variables
217
}
218
(-)ffef4cca2ff4 (+471 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
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]"
23
 *
24
 * Contributor(s):
25
 *
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.
29
 *
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.
40
 */
41
package org.netbeans.spi.java.project.support.ui;
42
43
import java.awt.Component;
44
import java.io.File;
45
import java.net.MalformedURLException;
46
import java.net.URL;
47
import java.util.ArrayList;
48
import java.util.List;
49
import java.util.logging.Logger;
50
import javax.swing.Action;
51
import javax.swing.DefaultCellEditor;
52
import javax.swing.DefaultComboBoxModel;
53
import javax.swing.DefaultListCellRenderer;
54
import javax.swing.JComboBox;
55
import javax.swing.JList;
56
import javax.swing.JPanel;
57
import javax.swing.JTable;
58
import javax.swing.ListSelectionModel;
59
import javax.swing.event.ListSelectionEvent;
60
import javax.swing.event.ListSelectionListener;
61
import javax.swing.table.DefaultTableCellRenderer;
62
import javax.swing.table.DefaultTableModel;
63
import javax.swing.table.TableColumn;
64
import org.netbeans.api.project.ant.AntArtifact;
65
import org.netbeans.api.project.libraries.Library;
66
import org.netbeans.api.project.libraries.LibraryManager;
67
import org.netbeans.api.queries.CollocationQuery;
68
import org.netbeans.spi.project.libraries.LibraryTypeProvider;
69
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
70
import org.netbeans.spi.project.support.ant.AntProjectHelper;
71
import org.netbeans.spi.project.support.ant.ReferenceHelper;
72
import org.openide.WizardDescriptor;
73
import org.openide.filesystems.FileObject;
74
import org.openide.filesystems.FileUtil;
75
import org.openide.filesystems.URLMapper;
76
import org.openide.util.Exceptions;
77
import org.openide.util.NbBundle;
78
79
80
final class MakeSharableVisualPanel2 extends JPanel {
81
82
    DefaultTableModel model;
83
    private String location = null;
84
    AntProjectHelper helper;
85
    private ReferenceHelper refhelper;
86
    String ACTION_COPY = "copy"; //NOI18N
87
    String ACTION_RELATIVE = "keep"; //NOI18N
88
    String ACTION_ABSOLUTE = "abs"; //NOI18N
89
    String ACTION_USE_LOCAL_LIBRARY = "use";
90
    String[] comboValues = new String[]{
91
        ACTION_COPY, ACTION_RELATIVE, ACTION_ABSOLUTE, ACTION_USE_LOCAL_LIBRARY
92
    };
93
    String[] comboValuesJar = new String[]{
94
        ACTION_COPY, ACTION_RELATIVE, ACTION_ABSOLUTE
95
    };
96
97
    /** Creates new form MakeSharableVisualPanel2 */
98
    public MakeSharableVisualPanel2() {
99
        initComponents();
100
        createTableDefinition();
101
102
    }
103
104
    @Override
105
    public String getName() {
106
        return NbBundle.getMessage(MakeSharableVisualPanel2.class, "MakeSharablePanel2.LBL_Actions");
107
    }
108
109
    void readSettings(WizardDescriptor wiz) {
110
        String loc = (String) wiz.getProperty(SharableLibrariesUtils.PROP_LOCATION);
111
        helper = (AntProjectHelper) wiz.getProperty(SharableLibrariesUtils.PROP_HELPER);
112
        refhelper = (ReferenceHelper) wiz.getProperty(SharableLibrariesUtils.PROP_REFERENCE_HELPER);
113
        List<String> libraries = (List<String>) wiz.getProperty(SharableLibrariesUtils.PROP_LIBRARIES);
114
        List<String> jars = (List<String>) wiz.getProperty(SharableLibrariesUtils.PROP_JAR_REFS);
115
        if (!loc.equals(location)) {
116
            location = loc;
117
            populateTable(helper, libraries, jars);
118
            populateDescriptionField();
119
        }
120
    }
121
122
    void storeSettings(WizardDescriptor wiz) {
123
        refhelper = (ReferenceHelper) wiz.getProperty(SharableLibrariesUtils.PROP_REFERENCE_HELPER);
124
        helper = (AntProjectHelper) wiz.getProperty(SharableLibrariesUtils.PROP_HELPER);
125
126
        List<Action> actions = new ArrayList<Action>();
127
        for (int i = 0; i < model.getRowCount(); i++) {
128
            Object item = model.getValueAt(i, 0);
129
            String action = (String) model.getValueAt(i, 1);
130
            if (item instanceof Library) {
131
                Library lib = (Library) item;
132
                if (ACTION_ABSOLUTE.equals(action)) {
133
                    actions.add(new SharableLibrariesUtils.KeepLibraryAtLocation(lib, false, helper));
134
                } else if (ACTION_RELATIVE.equals(action)) {
135
                    actions.add(new SharableLibrariesUtils.KeepLibraryAtLocation(lib, true, helper));
136
                } else if (ACTION_COPY.equals(action)) {
137
                    actions.add(new SharableLibrariesUtils.CopyLibraryJars(refhelper, lib));
138
                } else if (ACTION_USE_LOCAL_LIBRARY.equals(action)) {
139
                    //do nothing
140
                } else {
141
                    assert false : "No handling defined for action: " + action;
142
                }
143
            } else if (item instanceof String) {
144
                //file reference
145
                String ref = (String) item;
146
                if (ACTION_ABSOLUTE.equals(action)) {
147
                    actions.add(new SharableLibrariesUtils.KeepJarAtLocation(ref, false, helper, refhelper));
148
                } else if (ACTION_RELATIVE.equals(action)) {
149
                    actions.add(new SharableLibrariesUtils.KeepJarAtLocation(ref, true, helper, refhelper));
150
                } else if (ACTION_COPY.equals(action)) {
151
                    actions.add(new SharableLibrariesUtils.CopyJars(refhelper, helper, ref));
152
                } else {
153
                    assert false : "no handling defined for action: " + action;
154
                }
155
            } else if (item instanceof AntArtifact) {
156
                //project dependency.. do we want to handle? proably not..
157
            }
158
        }
159
        wiz.putProperty(SharableLibrariesUtils.PROP_ACTIONS, actions);
160
161
    }
162
163
    private void createTableDefinition() {
164
        model = new DefaultTableModel() {
165
166
            @Override
167
            public boolean isCellEditable(int row, int col) {
168
                return col == 1;
169
            }
170
        };
171
        model.addColumn("jar");
172
        model.addColumn("action");
173
        tblJars.setModel(model);
174
        TableColumn col1 = tblJars.getColumn("jar");
175
        col1.setHeaderValue(NbBundle.getMessage(MakeSharableVisualPanel2.class, "tblJars.header1"));
176
        col1.setResizable(true);
177
        col1.setCellRenderer(new DefaultTableCellRenderer() {
178
179
            @Override
180
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
181
                String text = "";
182
                if (value instanceof Library) {
183
                    Library lib = (Library) value;
184
                    text = lib.getDisplayName();
185
                } else if (value instanceof String) {
186
                    String v = helper.getStandardPropertyEvaluator().evaluate((String) value);
187
                    File absFile = helper.resolveFile(v);
188
                    text = absFile.getAbsolutePath();
189
                }
190
191
                return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
192
            }
193
        });
194
        TableColumn col2 = tblJars.getColumn("action");
195
        col2.setHeaderValue(NbBundle.getMessage(MakeSharableVisualPanel2.class, "tblJars.header2"));
196
        col2.sizeWidthToFit();
197
198
        JComboBox editorBox = new JComboBox(comboValues);
199
        editorBox.setEditable(false);
200
        DefaultCellEditor ed = new MyCellEditor(editorBox);
201
        col2.setCellEditor(ed);
202
        col2.setCellRenderer(new DefaultTableCellRenderer() {
203
204
            @Override
205
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
206
                String val = (String) value;
207
                if (table.getValueAt(row, 0) instanceof Library) {
208
                    if (ACTION_ABSOLUTE.equals(val)) {
209
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_Absolute");
210
                    } else if (ACTION_COPY.equals(val)) {
211
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_Copy");
212
                    } else if (ACTION_RELATIVE.equals(val)) {
213
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_Keep");
214
                    } else if (ACTION_USE_LOCAL_LIBRARY.equals(val)) {
215
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_UseLocal");
216
                    }
217
                } else {
218
                    if (ACTION_ABSOLUTE.equals(val)) {
219
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_AbsoluteJar");
220
                    } else if (ACTION_COPY.equals(val)) {
221
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_CopyJar");
222
                    } else if (ACTION_RELATIVE.equals(val)) {
223
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_KeepJar");
224
                    }
225
                }
226
                return super.getTableCellRendererComponent(table, val, isSelected, hasFocus, row, column);
227
            }
228
        });
229
        tblJars.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
230
231
            public void valueChanged(ListSelectionEvent e) {
232
                populateDescriptionField();
233
            }
234
        });
235
        tblJars.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
236
    }
237
238
    /** This method is called from within the constructor to
239
     * initialize the form.
240
     * WARNING: Do NOT modify this code. The content of this method is
241
     * always regenerated by the Form Editor.
242
     */
243
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
244
    private void initComponents() {
245
246
        lblHint = new javax.swing.JLabel();
247
        lblJars = new javax.swing.JLabel();
248
        jScrollPane1 = new javax.swing.JScrollPane();
249
        tblJars = new javax.swing.JTable();
250
        lblDetails = new javax.swing.JLabel();
251
        jScrollPane2 = new javax.swing.JScrollPane();
252
        taDetails = new javax.swing.JTextArea();
253
254
        org.openide.awt.Mnemonics.setLocalizedText(lblHint, org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel2.class, "MakeSharableVisualPanel2.lblHint.text")); // NOI18N
255
        lblHint.setVerticalAlignment(javax.swing.SwingConstants.TOP);
256
257
        lblJars.setLabelFor(tblJars);
258
        org.openide.awt.Mnemonics.setLocalizedText(lblJars, org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel2.class, "MakeSharableVisualPanel2.lblJars.text")); // NOI18N
259
260
        jScrollPane1.setViewportView(tblJars);
261
262
        lblDetails.setLabelFor(taDetails);
263
        org.openide.awt.Mnemonics.setLocalizedText(lblDetails, org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel2.class, "MakeSharableVisualPanel2.lblDetails.text")); // NOI18N
264
265
        taDetails.setColumns(20);
266
        taDetails.setRows(5);
267
        jScrollPane2.setViewportView(taDetails);
268
269
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
270
        this.setLayout(layout);
271
        layout.setHorizontalGroup(
272
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
273
            .add(lblHint, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
274
            .add(layout.createSequentialGroup()
275
                .add(lblJars)
276
                .addContainerGap())
277
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
278
            .add(layout.createSequentialGroup()
279
                .add(lblDetails)
280
                .addContainerGap())
281
            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
282
        );
283
        layout.setVerticalGroup(
284
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
285
            .add(layout.createSequentialGroup()
286
                .add(lblHint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
287
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
288
                .add(lblJars)
289
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
290
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
291
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
292
                .add(lblDetails)
293
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
294
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
295
        );
296
297
        lblJars.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel2.class, "ACSD_lblJars")); // NOI18N
298
        lblDetails.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MakeSharableVisualPanel2.class, "ACSD_lblDetails")); // NOI18N
299
    }// </editor-fold>//GEN-END:initComponents
300
    // Variables declaration - do not modify//GEN-BEGIN:variables
301
    private javax.swing.JScrollPane jScrollPane1;
302
    private javax.swing.JScrollPane jScrollPane2;
303
    private javax.swing.JLabel lblDetails;
304
    private javax.swing.JLabel lblHint;
305
    private javax.swing.JLabel lblJars;
306
    private javax.swing.JTextArea taDetails;
307
    private javax.swing.JTable tblJars;
308
    // End of variables declaration//GEN-END:variables
309
    private void populateTable(AntProjectHelper helper, List<String> libraries, List<String> jars) {
310
        createTableDefinition();
311
        try {
312
            File libraryFile = helper.resolveFile(location);
313
            File prjDir = FileUtil.toFile(helper.getProjectDirectory());
314
            boolean absoluteLibrary = LibrariesSupport.isAbsoluteURL(LibrariesSupport.convertFilePathToURL(location));
315
            LibraryManager newmanager = LibraryManager.forLocation(libraryFile.toURI().toURL());
316
            LibraryManager oldmanager = LibraryManager.getDefault(); //TODO once we support moving from one place to another, change this
317
            for (String lib : libraries) {
318
                Library library = oldmanager.getLibrary(lib);
319
                Library newLib = newmanager.getLibrary(lib);
320
                String action = ACTION_COPY;
321
                //TODO when library contents inside the same SCM or relative to new library location,
322
                // use the relative path as default..
323
                if (newLib != null) {
324
                    action = ACTION_USE_LOCAL_LIBRARY;
325
                }
326
                if (library != null) {
327
                    model.addRow(new Object[]{library, action});
328
                }
329
            }
330
            for (String jar : jars) {
331
                if (jar != null) {
332
                    String value = helper.getStandardPropertyEvaluator().evaluate(jar);
333
                    if (!value.startsWith("${")) {
334
                        File jarFile = helper.resolveFile(value);
335
                        String action = ACTION_COPY;
336
                        if (CollocationQuery.areCollocated(prjDir, jarFile)) {
337
                            // in the same VCS, without one project structure..
338
                            action = ACTION_RELATIVE;
339
                        } else if (absoluteLibrary && CollocationQuery.areCollocated(libraryFile.getParentFile(), jarFile)) {
340
                            // jar within the libraries folder or somehow relative to it.. 
341
                            // the path to libraries is absolute though.. absolute path is best guess then as well.
342
                            action = ACTION_ABSOLUTE;
343
                        } else if (CollocationQuery.areCollocated(libraryFile.getParentFile(), jarFile)) {
344
                            action = ACTION_RELATIVE;
345
                        }
346
                        model.addRow(new Object[]{jar, action});
347
                    } else {
348
                        Logger.getLogger(MakeSharableVisualPanel2.class.getName()).info("Cannot find jar reference:" + jar);
349
                    }
350
                } else {
351
                    Logger.getLogger(MakeSharableVisualPanel2.class.getName()).info("Cannot find jar reference:" + jar);
352
                }
353
            }
354
        } catch (MalformedURLException ex) {
355
            Exceptions.printStackTrace(ex);
356
        }
357
    }
358
359
    private void populateDescriptionField() {
360
        int row = tblJars.getSelectedRow();
361
        if (row != -1) {
362
            Object val = tblJars.getModel().getValueAt(row, 0);
363
            if (val instanceof Library) {
364
                Library lib = (Library) val;
365
                String type = lib.getType();
366
                LibraryTypeProvider provider = LibrariesSupport.getLibraryTypeProvider(type);
367
                assert provider != null;
368
                String typeString = provider.getDisplayName();
369
                String[] volumes = provider.getSupportedVolumeTypes();
370
                StringBuffer contents = new StringBuffer();
371
                for (String vol : volumes) {
372
                    List<URL> urls = lib.getContent(vol);
373
                    for (URL url : urls) {
374
                        FileObject fo = URLMapper.findFileObject(url);
375
                        if (fo != null) {
376
                            if (FileUtil.getArchiveFile(fo) != null) {
377
                                url = URLMapper.findURL(FileUtil.getArchiveFile(fo), URLMapper.EXTERNAL);
378
                            }
379
                        }
380
                        contents.append(url).append("\n");
381
                    }
382
                }
383
                taDetails.setText("Library (" + typeString + ")\n" +
384
                        "Contents:\n" + contents);
385
            } else if (val instanceof String) {
386
                String ref = (String) val;
387
                String text = "Jar/Folder\nBinary:";
388
                String value = helper.getStandardPropertyEvaluator().evaluate(ref);
389
                File absFile = helper.resolveFile(value);
390
                text = text + absFile.getAbsolutePath();
391
                String source = ref.replace("${file.reference", "${source.reference"); //NOI18N
392
                value = helper.getStandardPropertyEvaluator().evaluate(source);
393
                if (!value.startsWith("${source.")) { //NOI18N
394
                    absFile = helper.resolveFile(value);
395
                    text = text + "\nSources:" + absFile.getAbsolutePath();
396
                }
397
                String javadoc = ref.replace("${file.reference", "${javadoc.reference"); //NOI18N
398
                value = helper.getStandardPropertyEvaluator().evaluate(javadoc);
399
                if (!value.startsWith("${javadoc.")) { //NOI18N
400
                    absFile = helper.resolveFile(value);
401
                    text = text + "\nJavadoc:" + absFile.getAbsolutePath();
402
                }
403
404
405
                taDetails.setText(text);
406
            }
407
        } else {
408
            taDetails.setText("<No items selected>");
409
        }
410
    }
411
412
    private class MyCellEditor extends DefaultCellEditor {
413
414
415
        private JComboBox cb;
416
        private DefaultListCellRenderer library;
417
        private DefaultListCellRenderer jar;
418
419
        MyCellEditor(JComboBox combo) {
420
            super(combo);
421
            cb = combo;
422
            library = new DefaultListCellRenderer() {
423
                @Override
424
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
425
                    String val = (String) value;
426
                    if (ACTION_ABSOLUTE.equals(val)) {
427
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_Absolute");
428
                    } else if (ACTION_COPY.equals(val)) {
429
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_Copy");
430
                    } else if (ACTION_RELATIVE.equals(val)) {
431
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_Keep");
432
                    } else if (ACTION_USE_LOCAL_LIBRARY.equals(val)) {
433
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_UseLocal");
434
                    }
435
                    return super.getListCellRendererComponent(list, val, index, isSelected, cellHasFocus);
436
                }
437
            };
438
            jar = new DefaultListCellRenderer() {
439
                @Override
440
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
441
                    String val = (String) value;
442
                    if (ACTION_ABSOLUTE.equals(val)) {
443
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_AbsoluteJar");
444
                    } else if (ACTION_COPY.equals(val)) {
445
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_CopyJar");
446
                    } else if (ACTION_RELATIVE.equals(val)) {
447
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_KeepJar");
448
                    } else if (ACTION_USE_LOCAL_LIBRARY.equals(val)) {
449
                        val = NbBundle.getMessage(MakeSharableVisualPanel2.class, "TXT_UseLocalJar");
450
                    }
451
                    return super.getListCellRendererComponent(list, val, index, isSelected, cellHasFocus);
452
                }
453
            };
454
455
        }
456
457
        @Override
458
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
459
            if (table.getValueAt(row, 0) instanceof Library) {
460
                cb.setRenderer(library);
461
                cb.setModel(new DefaultComboBoxModel(comboValues));
462
            } else {
463
                cb.setRenderer(jar);
464
                cb.setModel(new DefaultComboBoxModel(comboValuesJar));
465
            }
466
            super.getTableCellEditorComponent(table, value, isSelected, row, column);
467
            return cb;
468
        }
469
    }
470
}
471
(-)ffef4cca2ff4 (+107 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
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]"
23
 *
24
 * Contributor(s):
25
 *
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.
29
 *
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.
40
 */
41
package org.netbeans.spi.java.project.support.ui;
42
43
import java.awt.Component;
44
import javax.swing.event.ChangeListener;
45
import org.openide.WizardDescriptor;
46
import org.openide.util.ChangeSupport;
47
import org.openide.util.HelpCtx;
48
49
class MakeSharableWizardPanel1 implements WizardDescriptor.Panel {
50
51
    /**
52
     * The visual component that displays this panel. If you need to access the
53
     * component from this class, just use getComponent().
54
     */
55
    private MakeSharableVisualPanel1 component;
56
    private ChangeSupport support = new ChangeSupport(this);
57
58
    // Get the visual component for the panel. In this template, the component
59
    // is kept separate. This can be more efficient: if the wizard is created
60
    // but never displayed, or not all panels are displayed, it is better to
61
    // create only those which really need to be visible.
62
    public Component getComponent() {
63
        if (component == null) {
64
            component = new MakeSharableVisualPanel1(support);
65
        }
66
        return component;
67
    }
68
69
    public HelpCtx getHelp() {
70
        // Show no Help button for this panel:
71
        return HelpCtx.DEFAULT_HELP;
72
    // If you have context help:
73
    // return new HelpCtx(SampleWizardPanel1.class);
74
    }
75
76
    public boolean isValid() {
77
        // If it is always OK to press Next or Finish, then:
78
        return component.isValidPanel();
79
    // If it depends on some condition (form filled out...), then:
80
    // return someCondition();
81
    // and when this condition changes (last form field filled in...) then:
82
    // fireChangeEvent();
83
    // and uncomment the complicated stuff below.
84
    }
85
86
    public final void addChangeListener(ChangeListener l) {
87
        support.addChangeListener(l);
88
    }
89
    public final void removeChangeListener(ChangeListener l) {
90
        support.removeChangeListener(l);
91
    }
92
93
    // You can use a settings object to keep track of state. Normally the
94
    // settings object will be the WizardDescriptor, so you can use
95
    // WizardDescriptor.getProperty & putProperty to store information entered
96
    // by the user.
97
    public void readSettings(Object settings) {
98
        WizardDescriptor wiz = (WizardDescriptor) settings;
99
        component.readSettings(wiz);
100
    }
101
102
    public void storeSettings(Object settings) {
103
        WizardDescriptor wiz = (WizardDescriptor) settings;
104
        component.storeSettings(wiz);
105
    }
106
}
107
(-)ffef4cca2ff4 (+127 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
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]"
23
 *
24
 * Contributor(s):
25
 *
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.
29
 *
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.
40
 */
41
package org.netbeans.spi.java.project.support.ui;
42
43
import java.awt.Component;
44
import javax.swing.event.ChangeListener;
45
import org.openide.WizardDescriptor;
46
import org.openide.util.HelpCtx;
47
48
class MakeSharableWizardPanel2 implements WizardDescriptor.Panel {
49
50
    /**
51
     * The visual component that displays this panel. If you need to access the
52
     * component from this class, just use getComponent().
53
     */
54
    private MakeSharableVisualPanel2 component;
55
56
    // Get the visual component for the panel. In this template, the component
57
    // is kept separate. This can be more efficient: if the wizard is created
58
    // but never displayed, or not all panels are displayed, it is better to
59
    // create only those which really need to be visible.
60
    public Component getComponent() {
61
        if (component == null) {
62
            component = new MakeSharableVisualPanel2();
63
        }
64
        return component;
65
    }
66
67
    public HelpCtx getHelp() {
68
        // Show no Help button for this panel:
69
        return HelpCtx.DEFAULT_HELP;
70
    // If you have context help:
71
    // return new HelpCtx(SampleWizardPanel1.class);
72
    }
73
74
    public boolean isValid() {
75
        // If it is always OK to press Next or Finish, then:
76
        return true;
77
    // If it depends on some condition (form filled out...), then:
78
    // return someCondition();
79
    // and when this condition changes (last form field filled in...) then:
80
    // fireChangeEvent();
81
    // and uncomment the complicated stuff below.
82
    }
83
84
    public final void addChangeListener(ChangeListener l) {
85
    }
86
87
    public final void removeChangeListener(ChangeListener l) {
88
    }
89
    /*
90
    private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1); // or can use ChangeSupport in NB 6.0
91
    public final void addChangeListener(ChangeListener l) {
92
    synchronized (listeners) {
93
    listeners.add(l);
94
    }
95
    }
96
    public final void removeChangeListener(ChangeListener l) {
97
    synchronized (listeners) {
98
    listeners.remove(l);
99
    }
100
    }
101
    protected final void fireChangeEvent() {
102
    Iterator<ChangeListener> it;
103
    synchronized (listeners) {
104
    it = new HashSet<ChangeListener>(listeners).iterator();
105
    }
106
    ChangeEvent ev = new ChangeEvent(this);
107
    while (it.hasNext()) {
108
    it.next().stateChanged(ev);
109
    }
110
    }
111
     */
112
113
    // You can use a settings object to keep track of state. Normally the
114
    // settings object will be the WizardDescriptor, so you can use
115
    // WizardDescriptor.getProperty & putProperty to store information entered
116
    // by the user.
117
    public void readSettings(Object settings) {
118
        WizardDescriptor wiz = (WizardDescriptor) settings;
119
        component.readSettings(wiz);
120
    }
121
122
    public void storeSettings(Object settings) {
123
        WizardDescriptor wiz = (WizardDescriptor) settings;
124
        component.storeSettings(wiz);
125
    }
126
}
127
(-)ffef4cca2ff4 (+465 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
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]"
23
 *
24
 * Contributor(s):
25
 *
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.
29
 *
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.
40
 */
41
package org.netbeans.spi.java.project.support.ui;
42
43
import java.awt.Component;
44
import java.awt.Dialog;
45
import java.awt.event.ActionEvent;
46
import java.io.File;
47
import java.io.IOException;
48
import java.net.MalformedURLException;
49
import java.net.URL;
50
import java.text.MessageFormat;
51
import java.util.ArrayList;
52
import java.util.HashMap;
53
import java.util.List;
54
import java.util.Map;
55
import javax.swing.AbstractAction;
56
import javax.swing.Action;
57
import javax.swing.JComponent;
58
import javax.swing.JFileChooser;
59
import org.netbeans.api.project.FileOwnerQuery;
60
import org.netbeans.api.project.ProjectManager;
61
import org.netbeans.api.project.ant.FileChooser;
62
import org.netbeans.api.project.libraries.Library;
63
import org.netbeans.api.project.libraries.LibraryManager;
64
import org.netbeans.spi.project.libraries.LibraryTypeProvider;
65
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
66
import org.netbeans.spi.project.support.ant.AntProjectHelper;
67
import org.netbeans.spi.project.support.ant.PropertyUtils;
68
import org.netbeans.spi.project.support.ant.ReferenceHelper;
69
import org.openide.DialogDisplayer;
70
import org.openide.WizardDescriptor;
71
import org.openide.filesystems.FileObject;
72
import org.openide.filesystems.FileSystem;
73
import org.openide.filesystems.FileUtil;
74
import org.openide.filesystems.URLMapper;
75
import org.openide.util.Exceptions;
76
import org.openide.util.Mutex;
77
import org.openide.util.MutexException;
78
import org.openide.util.NbBundle;
79
80
/**
81
 * Utility methods related to sharable libraries UI.
82
 * @since org.netbeans.modules.java.project 1.15
83
 * 
84
 */ 
85
public final class SharableLibrariesUtils {
86
87
    static final String PROP_LOCATION = "location"; //NOI18N
88
    static final String PROP_ACTIONS = "actions"; //NOI18N
89
    static final String PROP_HELPER = "helper"; //NOI18N
90
    static final String PROP_REFERENCE_HELPER = "refhelper"; //NOI18N
91
    static final String PROP_LIBRARIES = "libraries"; //NOI18N
92
    static final String PROP_JAR_REFS = "jars"; //NOI18N
93
    
94
    /**
95
     * The default filename for sharable library definition file.
96
     */
97
    public static final String DEFAULT_LIBRARIES_FILENAME = "nblibraries.properties";
98
    
99
    
100
    
101
    /**
102
     * File chooser implementation for browsing for shared library location.
103
     * @param current
104
     * @param comp
105
     * @param projectLocation
106
     * @return relative or absolute path to project libraries folder.
107
     */
108
    public static String browseForLibraryLocation(String current, Component comp, File projectLocation) {
109
        File lib = PropertyUtils.resolveFile(projectLocation, current);
110
        if (!lib.exists()) {
111
            lib = lib.getParentFile();
112
        }
113
        lib = FileUtil.normalizeFile(lib);
114
        FileChooser chooser = new FileChooser(projectLocation, null);
115
        chooser.setCurrentDirectory(lib);
116
        chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
117
        chooser.setDialogTitle(NbBundle.getMessage(SharableLibrariesUtils.class,"LBL_Browse_Libraries_Title"));
118
        chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SharableLibrariesUtils.class,"ASCD_Browse_Libraries_Title"));
119
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(comp)) {
120
            String[] files;
121
            try {
122
                files = chooser.getSelectedPaths();
123
            } catch (IOException ex) {
124
                Exceptions.printStackTrace(ex);
125
                return null;
126
            }
127
            if (files.length == 1) {
128
                String currentLibrariesLocation = files[0];
129
                return currentLibrariesLocation;
130
            }
131
        }
132
        return null;
133
    }    
134
135
    /**
136
     * Show a multistep wizard for converting a non-sharable project to a sharable, self-contained one.
137
     * @param helper
138
     * @param ref
139
     * @param libraryNames
140
     * @param jarReferences
141
     * @return true is migration was performed, false when aborted.
142
     */
143
    public static boolean showMakeSharableWizard(final AntProjectHelper helper, ReferenceHelper ref, List<String> libraryNames, List<String> jarReferences) {
144
145
        final WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels());
146
        // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
147
        wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
148
        wizardDescriptor.setTitle(NbBundle.getMessage(SharableLibrariesUtils.class, "TIT_MakeSharableWizard")); 
149
        wizardDescriptor.putProperty(PROP_HELPER, helper);
150
        wizardDescriptor.putProperty(PROP_REFERENCE_HELPER, ref);
151
        wizardDescriptor.putProperty(PROP_LIBRARIES, libraryNames);
152
        wizardDescriptor.putProperty(PROP_JAR_REFS, jarReferences);
153
        Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
154
        dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SharableLibrariesUtils.class, "ACSD_MakeSharableWizard"));
155
        dialog.setVisible(true);
156
        dialog.toFront();
157
        boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
158
        if (!cancelled) {
159
            final String loc = (String) wizardDescriptor.getProperty(PROP_LOCATION);
160
            assert loc != null;
161
            try {
162
                // create libraries property file if it does not exist:
163
                File f = new File(loc);
164
                if (!f.isAbsolute()) {
165
                    f = new File(FileUtil.toFile(helper.getProjectDirectory()), loc);
166
                }
167
                f = FileUtil.normalizeFile(f);
168
                if (!f.exists()) {
169
                    FileUtil.createData(f);
170
                }
171
172
                try {
173
                    ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
174
175
                        public Object run() throws IOException {
176
                            try {
177
                                helper.getProjectDirectory().getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
178
                                    public void run() throws IOException {
179
                                        helper.setLibrariesLocation(loc);
180
181
                                        // TODO or make just runnables?
182
                                        List<Action> actions = (List<Action>) wizardDescriptor.getProperty(PROP_ACTIONS);
183
                                        for (Action act : actions) {
184
                                            act.actionPerformed(null);
185
                                        }
186
                                        ProjectManager.getDefault().saveProject(FileOwnerQuery.getOwner(helper.getProjectDirectory()));
187
                                    }
188
                                });
189
                            } catch (IllegalArgumentException ex) {
190
                                Exceptions.printStackTrace(ex);
191
                            }
192
193
                            return null;
194
                        }
195
                    });
196
                } catch (MutexException ex) {
197
                    throw (IOException) ex.getException();
198
                }
199
            } catch (IOException ex) {
200
                Exceptions.printStackTrace(ex);
201
            }
202
203
204
        }
205
        return !cancelled;
206
    }
207
208
    /**
209
     * Initialize panels representing individual wizard's steps and sets
210
     * various properties for them influencing wizard appearance.
211
     */
212
    private static WizardDescriptor.Panel[] getPanels() {
213
        WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[]{
214
            new MakeSharableWizardPanel1(),
215
            new MakeSharableWizardPanel2()
216
        };
217
        String[] steps = new String[panels.length];
218
        for (int i = 0; i < panels.length; i++) {
219
            Component c = panels[i].getComponent();
220
            // Default step name to component name of panel. Mainly useful
221
            // for getting the name of the target chooser to appear in the
222
            // list of steps.
223
            steps[i] = c.getName();
224
            if (c instanceof JComponent) { // assume Swing components
225
                JComponent jc = (JComponent) c;
226
                // Sets step number of a component
227
                jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
228
                // Sets steps names for a panel
229
                jc.putClientProperty("WizardPanel_contentData", steps);
230
                // Turn on subtitle creation on each step
231
                jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
232
                // Show steps on the left side with the image on the background
233
                jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
234
                // Turn on numbering of all steps
235
                jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
236
            }
237
        }
238
        return panels;
239
    }
240
241
    static class CopyJars extends AbstractAction {
242
        private ReferenceHelper refhelper;
243
        private AntProjectHelper ahelper;
244
        private String reference;
245
246
        public CopyJars(ReferenceHelper helper, AntProjectHelper anthelper, String ref) {
247
            this.reference = ref;
248
            this.ahelper = anthelper;
249
            refhelper = helper;
250
        }
251
252
        public void actionPerformed(ActionEvent e) {
253
            String value = ahelper.getStandardPropertyEvaluator().evaluate(reference);
254
            File absFile = ahelper.resolveFile(value);
255
            String location = ahelper.getLibrariesLocation();
256
            File libraryFile = ahelper.resolveFile(location);
257
            File directory = libraryFile.getParentFile();
258
            if (!directory.exists()) {
259
                directory.mkdirs();
260
                FileUtil.refreshFor(directory);
261
            }
262
            FileObject dir = FileUtil.toFileObject(directory);
263
            updateReference(absFile, reference, true, dir);
264
            //now process source reference
265
            String source = reference.replace("${file.reference", "${source.reference"); //NOI18N
266
            value = ahelper.getStandardPropertyEvaluator().evaluate(source);
267
            if (!value.startsWith("${source.")) { //NOI18N
268
                absFile = ahelper.resolveFile(value);
269
                updateReference(absFile, source.replace("${", "").replace("}", ""), false, dir);
270
            }
271
            //now process javadoc reference
272
            String javadoc = reference.replace("${file.reference", "${javadoc.reference"); //NOI18N
273
            value = ahelper.getStandardPropertyEvaluator().evaluate(javadoc);
274
            if (!value.startsWith("${javadoc.")) { //NOI18N
275
                absFile = ahelper.resolveFile(value);
276
                updateReference(absFile, javadoc.replace("${", "").replace("}", ""), false, dir);
277
            }
278
        }
279
        
280
        private void updateReference(File oldFile, String key, boolean main, FileObject dir) {
281
            FileObject src = FileUtil.toFileObject(oldFile);
282
            FileObject newFile;
283
            try {
284
                //TODO it could actually already exist..
285
                newFile = FileUtil.copyFile(src, dir, src.getName());
286
            } catch (IOException ex) {
287
                Exceptions.printStackTrace(ex);
288
                newFile = src;
289
            }
290
            File absFile = FileUtil.toFile(newFile);
291
        //always relative when possible.
292
        // assume we have relative path to library as well, thus relative path is
293
        //good default value. 
294
            String newVal = PropertyUtils.relativizeFile(FileUtil.toFile(ahelper.getProjectDirectory()), absFile);
295
            if (newVal == null) {
296
                //fallback
297
                newVal = absFile.getAbsolutePath();
298
            }
299
            if (main) {
300
                // mkleint: why isn't there a way to set the reference, but one always have to create it
301
                // creating will create a unique key..
302
                refhelper.destroyReference(key);
303
                refhelper.createForeignFileReferenceAsIs(newVal, key);
304
            } else {
305
                refhelper.destroyReference(key);
306
                refhelper.createExtraForeignFileReferenceAsIs(newVal, key);
307
            }
308
        }
309
        
310
    }
311
312
    static class KeepJarAtLocation extends AbstractAction {
313
        private ReferenceHelper refhelper;
314
        private AntProjectHelper ahelper;
315
        private String reference;
316
        private boolean relative;
317
318
        public KeepJarAtLocation(String ref, boolean b, AntProjectHelper anthelper, ReferenceHelper helper) {
319
            this.reference = ref;
320
            this.ahelper = anthelper;
321
            refhelper = helper;
322
            relative = b;
323
        }
324
325
        public void actionPerformed(ActionEvent e) {
326
            String value = ahelper.getStandardPropertyEvaluator().evaluate(reference);
327
            updateReference(value, reference, true);
328
            //now process source reference
329
            String source = reference.replace("${file.reference", "${source.reference"); //NOI18N
330
            value = ahelper.getStandardPropertyEvaluator().evaluate(source);
331
            if (!value.startsWith("${source.")) { //NOI18N
332
                updateReference(value, source.replace("${", "").replace("}", ""), false);
333
            }
334
            //now process javadoc reference
335
            String javadoc = reference.replace("${file.reference", "${javadoc.reference"); //NOI18N
336
            value = ahelper.getStandardPropertyEvaluator().evaluate(javadoc);
337
            if (!value.startsWith("${javadoc.")) { //NOI18N
338
                updateReference(value, javadoc.replace("${", "").replace("}", ""), false);
339
            }
340
        }
341
342
        private void updateReference(String value, String key, boolean main) {
343
            File absFile = ahelper.resolveFile(value);
344
            String newVal = relative ? PropertyUtils.relativizeFile(FileUtil.toFile(ahelper.getProjectDirectory()), absFile) : absFile.getAbsolutePath();
345
            if (newVal == null) {
346
                //fallback
347
                newVal = absFile.getAbsolutePath();
348
            }
349
            if (!newVal.equals(value)) {
350
                if (main) {
351
                    refhelper.createForeignFileReferenceAsIs(newVal, key);
352
                } else {
353
                    refhelper.createExtraForeignFileReferenceAsIs(newVal, key);
354
                }
355
            }
356
        }
357
    }
358
    
359
    static class KeepLibraryAtLocation extends AbstractAction {
360
        private boolean keepRelativeLocations;
361
        private Library library;
362
        private AntProjectHelper helper;
363
364
        KeepLibraryAtLocation(Library l , boolean relative, AntProjectHelper h) {
365
            library = l;
366
            keepRelativeLocations = relative;
367
            helper = h;
368
        }
369
        public void actionPerformed(ActionEvent e) {
370
            String loc = helper.getLibrariesLocation();
371
            assert loc != null;
372
            File mainPropertiesFile = helper.resolveFile(loc);
373
            try {
374
                LibraryManager man = LibraryManager.forLocation(mainPropertiesFile.toURI().toURL());
375
                Map<String, List<URL>> volumes = new HashMap<String, List<URL>>();
376
                LibraryTypeProvider provider = LibrariesSupport.getLibraryTypeProvider(library.getType());
377
                assert provider != null;
378
                for (String volume : provider.getSupportedVolumeTypes()) {
379
                    List<URL> urls = library.getContent(volume);
380
                    List<URL> newurls = new ArrayList<URL>();
381
                    for (URL url : urls) {
382
                        String jarFolder = null;
383
                        boolean isArchive = false;
384
                        if ("jar".equals(url.getProtocol())) { // NOI18N
385
                            jarFolder = getJarFolder(url);
386
                            url = FileUtil.getArchiveFile(url);
387
                            isArchive = true;
388
                        }
389
                        FileObject fo = URLMapper.findFileObject(url);
390
391
                        if (fo != null) {
392
                            if (keepRelativeLocations) {
393
                                File path = FileUtil.toFile(fo);
394
                                String str = PropertyUtils.relativizeFile(mainPropertiesFile.getParentFile(), path);
395
                                url = LibrariesSupport.convertFilePathToURL(str);
396
                            } else {
397
                                url = fo.getURL();
398
                            }
399
                            if (isArchive) {
400
                                url = FileUtil.getArchiveRoot(url);
401
                            }
402
                            if (jarFolder != null) {
403
                                 url = appendJarFolder(url, jarFolder);
404
                            }
405
                            
406
                        }
407
                        
408
409
                        newurls.add(url);
410
                    }
411
                    volumes.put(volume, newurls);
412
                }
413
                
414
                man.createLibrary(library.getType(), library.getName(), volumes);
415
            } catch (IOException ex) {
416
                Exceptions.printStackTrace(ex);
417
            }
418
        }
419
        
420
    }
421
    
422
    static class CopyLibraryJars extends AbstractAction {
423
        private Library library;
424
        private ReferenceHelper refHelper;
425
 
426
        CopyLibraryJars(ReferenceHelper h, Library l) {
427
            refHelper = h;
428
            library = l;
429
        }
430
431
        public void actionPerformed(ActionEvent e) {
432
            assert library.getManager() == LibraryManager.getDefault() : "Only converting from non-sharable to sharable is supported."; //NOi18N
433
            try {
434
                refHelper.copyLibrary(library);
435
            } catch (IOException ex) {
436
                Exceptions.printStackTrace(ex);
437
            }
438
        }
439
        
440
    }
441
    
442
443
    
444
    
445
    /** for jar url this method returns path wihtin jar or null*/
446
    private static String getJarFolder(URL url) {
447
        assert "jar".equals(url.getProtocol()) : url;
448
        String u = url.toExternalForm();
449
        int index = u.indexOf("!/"); //NOI18N
450
        if (index != -1 && index + 2 < u.length()) {
451
            return u.substring(index + 2);
452
        }
453
        return null;
454
    }
455
456
    /** append path to given jar root url */
457
    private static URL appendJarFolder(URL u, String jarFolder) {
458
        assert "jar".equals(u.getProtocol()) && u.toExternalForm().endsWith("!/") : u;
459
        try {
460
            return new URL(u + jarFolder.replace('\\', '/')); //NOI18N
461
        } catch (MalformedURLException e) {
462
            throw new AssertionError(e);
463
        }
464
    }         
465
}

Return to bug 44035