KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > eclipse > ProjectFactory


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.modules.projectimport.eclipse;
21
22 import java.io.File JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.logging.Logger JavaDoc;
25 import org.netbeans.modules.projectimport.LoggerFactory;
26 import org.netbeans.modules.projectimport.ProjectImporterException;
27
28 /**
29  * Able to load and fill up an <code>EclipseProject</code> from Eclipse project
30  * directory using a .project and .classpath file and eventually passed
31  * workspace. It is also able to load the basic information from workspace.
32  *
33  * @author mkrauskopf
34  */

35 public final class ProjectFactory {
36     
37     /** Logger for this class. */
38     private static final Logger JavaDoc logger =
39             LoggerFactory.getDefault().createLogger(ProjectFactory.class);
40     
41     /** singleton */
42     private static ProjectFactory instance = new ProjectFactory();
43     
44     private ProjectFactory() {/*empty constructor*/}
45     
46     /** Returns ProjectFactory instance. */
47     public static ProjectFactory getInstance() {
48         return instance;
49     }
50     
51     /**
52      * Loads a project contained in the given <code>projectDir</code> and tries
53      * if there is workspace in the parent directory (which works only for
54      * eclipse internal projects)
55      *
56      * @throws ProjectImporterException if project in the given
57      * <code>projectDir</code> is not a valid Eclipse project.
58      */

59     public EclipseProject load(File JavaDoc projectDir) throws
60             ProjectImporterException {
61         Workspace workspace = Workspace.createWorkspace(projectDir.getParentFile());
62         if (workspace != null) {
63             WorkspaceParser parser = new WorkspaceParser(workspace);
64             parser.parse();
65         }
66         return load(projectDir, workspace);
67     }
68     
69     /**
70      * Loads a project contained in the given <code>projectDir</code>.
71      *
72      * @throws ProjectImporterException if project in the given
73      * <code>projectDir</code> is not a valid Eclipse project.
74      */

75     EclipseProject load(File JavaDoc projectDir, Workspace workspace) throws
76             ProjectImporterException {
77         
78         EclipseProject project = EclipseProject.createProject(projectDir);
79         if (project != null) {
80             project.setWorkspace(workspace);
81             load(project);
82         }
83         return project;
84     }
85     
86     /**
87      * Fullfill given <code>project</code> with all needed information.
88      *
89      * @throws ProjectImporterException if project in the given
90      * <code>projectDir</code> is not a valid Eclipse project.
91      */

92     void load(EclipseProject project) throws ProjectImporterException {
93         logger.finest("Loading project: " + project.getDirectory().getAbsolutePath()); // NOI18N
94
ProjectParser.parse(project);
95         File JavaDoc cpFile = project.getClassPathFile();
96         // non-java project doesn't need to have a classpath file
97
if (cpFile != null && cpFile.exists()) {
98             project.setClassPath(ClassPathParser.parse(cpFile));
99             for (Iterator JavaDoc it = project.getClassPath().getEntries().iterator(); it.hasNext(); ) {
100                 project.setAbsolutePathForEntry((ClassPathEntry) it.next());
101             }
102         } else {
103             logger.finer("Project " + project.getName() + // NOI18N
104
" doesn't have java nature."); // NOI18N
105
project.setJavaNature(false);
106         }
107     }
108 }
109
110
111
Popular Tags