Lines 42-51
Link Here
|
42 |
package org.netbeans.modules.web.clientproject; |
42 |
package org.netbeans.modules.web.clientproject; |
43 |
|
43 |
|
44 |
import java.io.BufferedReader; |
44 |
import java.io.BufferedReader; |
|
|
45 |
import java.io.Closeable; |
45 |
import java.io.IOException; |
46 |
import java.io.IOException; |
46 |
import java.io.InputStreamReader; |
47 |
import java.io.InputStreamReader; |
47 |
import java.io.Reader; |
48 |
import java.io.Reader; |
48 |
import java.nio.charset.Charset; |
|
|
49 |
import java.nio.charset.StandardCharsets; |
49 |
import java.nio.charset.StandardCharsets; |
50 |
import java.util.concurrent.Callable; |
50 |
import java.util.concurrent.Callable; |
51 |
import java.util.logging.Level; |
51 |
import java.util.logging.Level; |
Lines 56-74
Link Here
|
56 |
import org.netbeans.api.annotations.common.CheckForNull; |
56 |
import org.netbeans.api.annotations.common.CheckForNull; |
57 |
import org.netbeans.api.annotations.common.NonNull; |
57 |
import org.netbeans.api.annotations.common.NonNull; |
58 |
import org.netbeans.api.java.classpath.ClassPath; |
58 |
import org.netbeans.api.java.classpath.ClassPath; |
59 |
import org.netbeans.api.project.FileOwnerQuery; |
|
|
60 |
import org.netbeans.api.project.Project; |
59 |
import org.netbeans.api.project.Project; |
61 |
import org.netbeans.modules.web.clientproject.api.util.StringUtilities; |
60 |
import org.netbeans.modules.web.clientproject.api.util.StringUtilities; |
62 |
import org.netbeans.modules.web.clientproject.createprojectapi.ClientSideProjectGenerator; |
61 |
import org.netbeans.modules.web.clientproject.createprojectapi.ClientSideProjectGenerator; |
63 |
import org.netbeans.modules.web.clientproject.createprojectapi.CreateProjectProperties; |
62 |
import org.netbeans.modules.web.clientproject.createprojectapi.CreateProjectProperties; |
64 |
import org.netbeans.spi.java.classpath.ClassPathProvider; |
63 |
import org.netbeans.spi.java.classpath.ClassPathProvider; |
65 |
import org.netbeans.spi.project.ui.ProjectConvertor; |
64 |
import org.netbeans.spi.project.ui.ProjectConvertor; |
66 |
import org.netbeans.spi.queries.FileEncodingQueryImplementation; |
65 |
import org.netbeans.spi.project.ui.support.ProjectConvertors; |
67 |
import org.openide.filesystems.FileObject; |
66 |
import org.openide.filesystems.FileObject; |
68 |
import org.openide.util.ImageUtilities; |
67 |
import org.openide.util.ImageUtilities; |
69 |
import org.openide.util.Lookup; |
68 |
import org.openide.util.Lookup; |
70 |
import org.openide.util.lookup.Lookups; |
|
|
71 |
import org.openide.util.lookup.ProxyLookup; |
72 |
|
69 |
|
73 |
/** |
70 |
/** |
74 |
* The {@link ProjectConvertor} implements for web client project. |
71 |
* The {@link ProjectConvertor} implements for web client project. |
Lines 104-115
Link Here
|
104 |
// should not happen often |
101 |
// should not happen often |
105 |
displayName = projectDirectory.getNameExt(); |
102 |
displayName = projectDirectory.getNameExt(); |
106 |
} |
103 |
} |
107 |
final TransientLookup transientLkp = new TransientLookup( |
104 |
final Lookup transientLkp = ProjectConvertors.createProjectConvertorLookup( |
108 |
new ConvertorClassPathProvider(), |
105 |
new ConvertorClassPathProvider(), |
109 |
new ConvertorFileEncodingQuery()); |
106 |
ProjectConvertors.createFileEncodingQuery()); |
110 |
return new Result( |
107 |
return new Result( |
111 |
transientLkp, |
108 |
transientLkp, |
112 |
new Factory(projectDirectory, displayName, transientLkp), |
109 |
new Factory(projectDirectory, displayName, (Closeable)transientLkp), |
113 |
displayName, |
110 |
displayName, |
114 |
ImageUtilities.image2Icon(ImageUtilities.loadImage(ClientSideProject.HTML5_PROJECT_ICON))); |
111 |
ImageUtilities.image2Icon(ImageUtilities.loadImage(ClientSideProject.HTML5_PROJECT_ICON))); |
115 |
} |
112 |
} |
Lines 144-153
Link Here
|
144 |
|
141 |
|
145 |
private final FileObject projectDirectory; |
142 |
private final FileObject projectDirectory; |
146 |
private final String displayName; |
143 |
private final String displayName; |
147 |
private final TransientLookup transientLkp; |
144 |
private final Closeable transientLkp; |
148 |
|
145 |
|
149 |
|
146 |
|
150 |
Factory(FileObject projectDirectory, String displayName, TransientLookup transientLkp) { |
147 |
Factory(FileObject projectDirectory, String displayName, Closeable transientLkp) { |
151 |
assert projectDirectory != null; |
148 |
assert projectDirectory != null; |
152 |
assert displayName != null : projectDirectory; |
149 |
assert displayName != null : projectDirectory; |
153 |
assert transientLkp != null: projectDirectory; |
150 |
assert transientLkp != null: projectDirectory; |
Lines 158-166
Link Here
|
158 |
|
155 |
|
159 |
@Override |
156 |
@Override |
160 |
public Project call() throws Exception { |
157 |
public Project call() throws Exception { |
161 |
transientLkp.hide( |
158 |
transientLkp.close(); |
162 |
ConvertorClassPathProvider.class, |
|
|
163 |
ConvertorFileEncodingQuery.class); |
164 |
return ClientSideProjectGenerator.createProject(new CreateProjectProperties(projectDirectory, displayName) |
159 |
return ClientSideProjectGenerator.createProject(new CreateProjectProperties(projectDirectory, displayName) |
165 |
.setSourceFolder("") // NOI18N |
160 |
.setSourceFolder("") // NOI18N |
166 |
.setSiteRootFolder(detectSiteRoot()) |
161 |
.setSiteRootFolder(detectSiteRoot()) |
Lines 180-243
Link Here
|
180 |
|
175 |
|
181 |
} |
176 |
} |
182 |
|
177 |
|
183 |
private static final class TransientLookup extends ProxyLookup { |
|
|
184 |
|
185 |
private final Lookup base; |
186 |
|
187 |
public TransientLookup(Object... services) { |
188 |
this(Lookups.fixed(services)); |
189 |
} |
190 |
|
191 |
private TransientLookup(Lookup base) { |
192 |
super(base); |
193 |
this.base = base; |
194 |
} |
195 |
|
196 |
void hide(Class<?>... clzs) { |
197 |
setLookups(Lookups.exclude(base, clzs)); |
198 |
} |
199 |
} |
200 |
|
201 |
private static class ConvertorClassPathProvider implements ClassPathProvider { |
178 |
private static class ConvertorClassPathProvider implements ClassPathProvider { |
202 |
|
|
|
203 |
@Override |
179 |
@Override |
204 |
@CheckForNull |
180 |
@CheckForNull |
205 |
public ClassPath findClassPath( |
181 |
public ClassPath findClassPath( |
206 |
@NonNull final FileObject file, |
182 |
@NonNull final FileObject file, |
207 |
@NonNull final String type) { |
183 |
@NonNull final String type) { |
208 |
if (ClassPathProviderImpl.SOURCE_CP.equals(type)) { |
184 |
if (ClassPathProviderImpl.SOURCE_CP.equals(type)) { |
209 |
final ClientSideProject csp = findClientSideProject(file); |
185 |
final Project p = ProjectConvertors.getNonConvertorOwner(file); |
210 |
if (csp != null) { |
186 |
if (p != null) { |
211 |
return csp.getLookup().lookup(ClassPathProvider.class).findClassPath(file, type); |
187 |
return p.getLookup().lookup(ClassPathProvider.class).findClassPath(file, type); |
212 |
} |
188 |
} |
213 |
} |
189 |
} |
214 |
return null; |
190 |
return null; |
215 |
} |
191 |
} |
216 |
} |
192 |
} |
217 |
|
|
|
218 |
private static class ConvertorFileEncodingQuery extends FileEncodingQueryImplementation { |
219 |
|
220 |
@Override |
221 |
@CheckForNull |
222 |
public Charset getEncoding(FileObject file) { |
223 |
final ClientSideProject csp = findClientSideProject(file); |
224 |
return csp != null ? |
225 |
csp.getLookup().lookup(FileEncodingQueryImplementation.class).getEncoding(file) : |
226 |
null; |
227 |
} |
228 |
} |
229 |
|
230 |
@CheckForNull |
231 |
@SuppressWarnings("NestedAssignment") |
232 |
private static ClientSideProject findClientSideProject(@NonNull final FileObject file) { |
233 |
for (FileObject parent = file.getParent(); parent != null; parent = parent.getParent()) { |
234 |
ClientSideProject csPrj; |
235 |
final Project prj = FileOwnerQuery.getOwner(parent); |
236 |
if (prj != null && (csPrj = prj.getLookup().lookup(ClientSideProject.class)) != null) { |
237 |
return csPrj; |
238 |
} |
239 |
} |
240 |
return null; |
241 |
} |
242 |
|
243 |
} |
193 |
} |