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.
Summary: | New Project wizard, whenever asking for an existing Java package root, should try to verify package structure | ||
---|---|---|---|
Product: | java | Reporter: | Jesse Glick <jglick> |
Component: | Project | Assignee: | Tomas Zezula <tzezula> |
Status: | NEW --- | ||
Severity: | blocker | CC: | anebuzelsky, johnjullion, jrojcek |
Priority: | P3 | Keywords: | API, UI |
Version: | 4.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: | |
Bug Depends on: | 49685, 51151 | ||
Bug Blocks: | 41535, 54165 |
Description
Jesse Glick
2004-06-17 15:48:58 UTC
May be too late for D. Should be considered a priority for E, however. An additional possible utility method would be to take a folder and scan for likely package roots inside of it. However I am not sure any of our existing wizards would use such a method. Package root verification would apply to j2seproject import; freeform project creation and customization; possibly to web app import, TBD. *** Issue 61234 has been marked as a duplicate of this issue. *** Please, reevaluate. Will this be done for F? Easy to do, it can be done to 4.2 as a fix Something like this: String WHITESPACE = "(?:\\s|/\\*(?:[^*]|\\*[^/])*\\*/)"; String IDENTIFIER = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)"; String QUALIFIED_IDENTIFIER = "(?:" + IDENTIFIER + "(?:\\." + IDENTIFIER + ")*)"; Pattern PACKAGE = Pattern.compile( "^" + WHITESPACE + "*(?:package" + WHITESPACE + "+(" + QUALIFIED_IDENTIFIER + ")|(?:import|public|final|abstract|strictfp|class|interface|enum))", Pattern.DOTALL); FileObject findRoot(FileObject file) { if (file.isFolder()) { // could also scan for contained files here return null; } // look for package statement try { InputStream is = file.getInputStream(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream((int) file.getSize()); FileUtil.copy(is, baos); String content = baos.toString(); // XXX default encoding OK? Matcher m = PACKAGE.matcher(content); if (m.find()) { String pkg = m.group(1); FileObject root = file.getParent(); List<String> components = new ArrayList<String>(); if (pkg != null) { StringTokenizer tok = new StringTokenizer(pkg, "."); while (tok.hasMoreTokens()) { components.add(tok.nextToken()); } Collections.reverse(components); } for (String component : components) { if (root == null || !root.getNameExt().equals(component)) { return null; } root = root.getParent(); } return root; } } finally { is.close(); } } catch (IOException x) { Exceptions.printStackTrace(x); } return null; } |