KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > BJClassPathExtender


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.bluej;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import org.netbeans.api.project.ant.AntArtifact;
27 import org.netbeans.bluej.classpath.ClassPathProviderImpl;
28 import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.FileUtil;
31 import org.openide.filesystems.URLMapper;
32
33 /**
34  *
35  * @author mkleint
36  */

37 public class BJClassPathExtender implements ProjectClassPathExtender{
38
39     private BluejProject project;
40     
41     /** Creates a new instance of BJClassPathExtender */
42     public BJClassPathExtender(BluejProject proj) {
43         project = proj;
44     }
45
46     public boolean addLibrary(org.netbeans.api.project.libraries.Library library) throws IOException JavaDoc {
47         FileObject libs = project.getProjectDirectory().getFileObject("+libs"); //NOI18N
48
if (libs == null) {
49             libs = project.getProjectDirectory().createFolder("+libs"); //NOI18N
50
}
51         Iterator JavaDoc it = library.getContent("classpath").iterator(); //NOI18N
52
while (it.hasNext()) {
53             URL JavaDoc url = (URL JavaDoc) it.next();
54             if (FileUtil.getArchiveFile(url) != null) {
55                 url = FileUtil.getArchiveFile(url);
56             }
57             FileObject fo = URLMapper.findFileObject(url);
58             FileObject newLib = libs.getFileObject(fo.getNameExt());
59             if (newLib == null) {
60                 FileUtil.copyFile(fo, libs, fo.getName());
61             }
62         }
63         ClassPathProviderImpl prov = (ClassPathProviderImpl) project.getLookup().lookup(ClassPathProviderImpl.class);
64         prov.getBluejCPImpl().fireChange();
65         return true;
66     }
67
68     public boolean addArchiveFile(FileObject archiveFile) throws IOException JavaDoc {
69         FileObject libs = project.getProjectDirectory().getFileObject("+libs"); //NOI18N
70
if (libs == null) {
71             libs = project.getProjectDirectory().createFolder("+libs"); //NOI18N
72
}
73         FileObject newLib = libs.getFileObject(archiveFile.getNameExt());
74         if (newLib == null) {
75             FileUtil.copyFile(archiveFile, libs, archiveFile.getName());
76         }
77         ClassPathProviderImpl prov = (ClassPathProviderImpl) project.getLookup().lookup(ClassPathProviderImpl.class);
78         prov.getBluejCPImpl().fireChange();
79         return true;
80     }
81
82     public boolean addAntArtifact(AntArtifact artifact, URI JavaDoc artifactElement) throws IOException JavaDoc {
83         throw new IOException JavaDoc("It is not possible to create project dependencies in BlueJ projects. Please convert the project to J2SE Project first.");
84     }
85     
86 }
87
Popular Tags