001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.project;
042:
043: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
044: import java.io.File;
045: import java.io.IOException;
046: import org.netbeans.api.project.Project;
047: import org.netbeans.api.project.ProjectManager;
048: import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
049: import org.netbeans.spi.project.support.ant.AntProjectHelper;
050: import org.netbeans.spi.project.support.ant.EditableProperties;
051: import org.netbeans.spi.project.support.ant.ProjectGenerator;
052: import org.openide.filesystems.FileObject;
053: import org.openide.filesystems.FileUtil;
054: import org.openide.filesystems.Repository;
055: import org.openide.util.NbBundle;
056: import org.w3c.dom.Document;
057: import org.w3c.dom.Element;
058: import java.nio.charset.Charset;
059: import org.netbeans.api.queries.FileEncodingQuery;
060:
061: /**
062: * Create a fresh EjbProject from scratch or by importing and exisitng web module
063: * in one of the recognized directory structures.
064: *
065: * @author Pavel Buzek
066: */
067: public class SQLproProjectGenerator {
068:
069: private static final String DEFAULT_DOC_BASE_FOLDER = "conf"; //NOI18N
070: private static final String DEFAULT_SRC_FOLDER = "src"; //NOI18N
071: private static final String DEFAULT_RESOURCE_FOLDER = "setup"; //NOI18N
072: private static final String DEFAULT_BPELASA_FOLDER = "bpelasa"; //NOI18N
073: private static final String DEFAULT_BUILD_DIR = "build"; //NOI18N
074:
075: private static final String DEFAULT_NBPROJECT_DIR = "nbproject"; //NOI18N
076:
077: private SQLproProjectGenerator() {
078: }
079:
080: /**
081: * Create a new empty J2SE project.
082: * @param dir the top-level directory (need not yet exist but if it does it must be empty)
083: * @param name the code name for the project
084: * @return the helper object permitting it to be further customized
085: * @throws IOException in case something went wrong
086: */
087: public static AntProjectHelper createProject(File dir, String name,
088: String j2eeLevel) throws IOException {
089: dir.mkdirs();
090: // XXX clumsy way to refresh, but otherwise it doesn't work for new folders
091: File rootF = dir;
092: while (rootF.getParentFile() != null) {
093: rootF = rootF.getParentFile();
094: }
095: FileObject fo = FileUtil.toFileObject(rootF);
096: assert fo != null : "At least disk roots must be mounted! "
097: + rootF;
098: fo.getFileSystem().refresh(false);
099: fo = FileUtil.toFileObject(dir);
100:
101: // vlv # 113228
102: if (fo == null) {
103: throw new IOException("Can't create " + dir.getName());
104: }
105: assert fo.isFolder() : "Not really a dir: " + dir;
106: assert fo.getChildren().length == 0 : "Dir must have been empty: "
107: + dir;
108: AntProjectHelper h = setupProject(fo, name, j2eeLevel);
109: FileObject srcRoot = fo.createFolder(DEFAULT_SRC_FOLDER); // NOI18N
110: FileObject bpelasaRoot = srcRoot;
111: FileObject sqlmapFile = FileUtil
112: .copyFile(
113: Repository
114: .getDefault()
115: .getDefaultFileSystem()
116: .findResource(
117: "org-netbeans-modules-sql-project/connectivityInfo.xml"),
118: bpelasaRoot, "connectivityInfo"); //NOI18N
119:
120: FileObject nbProjectRoot = FileUtil.toFileObject(new File(dir,
121: DEFAULT_NBPROJECT_DIR)); // NOI18N
122:
123: EditableProperties ep = h
124: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
125: ep
126: .put(IcanproProjectProperties.SOURCE_ROOT,
127: DEFAULT_SRC_FOLDER); //NOI18N
128: ep.setProperty(IcanproProjectProperties.META_INF, "${"
129: + IcanproProjectProperties.SOURCE_ROOT + "}/"
130: + DEFAULT_DOC_BASE_FOLDER); //NOI18N
131: ep.setProperty(IcanproProjectProperties.SRC_DIR, "${"
132: + IcanproProjectProperties.SOURCE_ROOT + "}"); //NOI18N
133: ep.setProperty(IcanproProjectProperties.RESOURCE_DIR,
134: DEFAULT_RESOURCE_FOLDER);
135: h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
136:
137: Project p = ProjectManager.getDefault().findProject(
138: h.getProjectDirectory());
139: ProjectManager.getDefault().saveProject(p);
140:
141: return h;
142: }
143:
144: private static AntProjectHelper setupProject(FileObject dirFO,
145: String name, String j2eeLevel) throws IOException {
146: AntProjectHelper h = ProjectGenerator.createProject(dirFO,
147: SQLproProjectType.TYPE);
148: Element data = h.getPrimaryConfigurationData(true);
149: Document doc = data.getOwnerDocument();
150: Element nameEl = doc.createElementNS(
151: SQLproProjectType.PROJECT_CONFIGURATION_NAMESPACE,
152: "name"); // NOI18N
153: nameEl.appendChild(doc.createTextNode(name));
154: data.appendChild(nameEl);
155: Element minant = doc.createElementNS(
156: SQLproProjectType.PROJECT_CONFIGURATION_NAMESPACE,
157: "minimum-ant-version"); // NOI18N
158: minant.appendChild(doc.createTextNode("1.6")); // NOI18N
159: data.appendChild(minant);
160: h.putPrimaryConfigurationData(data, true);
161:
162: EditableProperties ep = h
163: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
164: // ep.setProperty(IcanproProjectProperties.JAVAC_CLASSPATH, "${libs.j2ee14.classpath}");
165: ep.setProperty(IcanproProjectProperties.DIST_DIR, "dist");
166: ep.setProperty(IcanproProjectProperties.DIST_JAR, "${"
167: + IcanproProjectProperties.DIST_DIR + "}/" + name
168: + ".zip");
169: ep.setProperty(IcanproProjectProperties.J2EE_PLATFORM,
170: j2eeLevel);
171: ep
172: .setProperty(IcanproProjectProperties.JAR_NAME, name
173: + ".jar");
174: ep.setProperty(IcanproProjectProperties.JAR_COMPRESS, "false");
175: // ep.setProperty(IcanproProjectProperties.JAR_CONTENT_ADDITIONAL, "");
176:
177: Deployment deployment = Deployment.getDefault();
178: String serverInstanceID = deployment
179: .getDefaultServerInstanceID();
180: if (serverInstanceID != null) {
181: ep.setProperty(IcanproProjectProperties.J2EE_SERVER_TYPE,
182: deployment.getServerID(serverInstanceID));
183: }
184: ep.setProperty(IcanproProjectProperties.JAVAC_SOURCE, "1.4");
185: ep.setProperty(IcanproProjectProperties.JAVAC_DEBUG, "true");
186: ep.setProperty(IcanproProjectProperties.JAVAC_DEPRECATION,
187: "false");
188:
189: ep.setProperty(IcanproProjectProperties.JAVAC_TARGET, "1.4");
190:
191: ep.setProperty(IcanproProjectProperties.BUILD_DIR,
192: DEFAULT_BUILD_DIR);
193: ep.setProperty(IcanproProjectProperties.BUILD_GENERATED_DIR,
194: "${" + IcanproProjectProperties.BUILD_DIR
195: + "}/generated");
196: ep.setProperty(IcanproProjectProperties.BUILD_CLASSES_DIR, "${"
197: + IcanproProjectProperties.BUILD_DIR + "}/jar");
198: ep.setProperty(IcanproProjectProperties.BUILD_CLASSES_EXCLUDES,
199: "**/*.java,**/*.form,**/.nbattrs");
200: ep.setProperty(IcanproProjectProperties.DIST_JAVADOC_DIR, "${"
201: + IcanproProjectProperties.DIST_DIR + "}/javadoc");
202: ep.setProperty(IcanproProjectProperties.JAVA_PLATFORM,
203: "default_platform");
204: ep.setProperty(IcanproProjectProperties.DEBUG_CLASSPATH, "${"
205: + IcanproProjectProperties.JAVAC_CLASSPATH + "}:${"
206: + IcanproProjectProperties.BUILD_CLASSES_DIR + "}");
207: Charset enc = FileEncodingQuery.getDefaultEncoding();
208: ep.setProperty(IcanproProjectProperties.SOURCE_ENCODING, enc
209: .name());
210:
211: //============= Start of IcanPro========================================//
212: ep.setProperty(IcanproProjectProperties.JBI_SETYPE_PREFIX,
213: "sun-sql-engine"); // NOI18N
214: ep.setProperty(IcanproProjectProperties.ASSEMBLY_UNIT_ALIAS,
215: "This Assembly Unit"); // NOI18N
216: ep.setProperty(
217: IcanproProjectProperties.ASSEMBLY_UNIT_DESCRIPTION,
218: "Represents this Assembly Unit"); // NOI18N
219: ep
220: .setProperty(
221: IcanproProjectProperties.APPLICATION_SUB_ASSEMBLY_ALIAS,
222: "This Application Sub-Assembly"); // NOI18N
223: ep
224: .setProperty(
225: IcanproProjectProperties.APPLICATION_SUB_ASSEMBLY_DESCRIPTION,
226: NbBundle.getMessage(
227: SQLproProjectGenerator.class,
228: "APP_SUB_ASSEMBLY")); // NOI18N
229: ep.setProperty(
230: IcanproProjectProperties.JBI_COMPONENT_CONF_ROOT,
231: "nbproject/private"); // NOI18N
232: ep.setProperty(
233: IcanproProjectProperties.JBI_DEPLOYMENT_CONF_ROOT,
234: "nbproject/deployment"); // NOI18N
235:
236: ep.setProperty(IcanproProjectProperties.BC_DEPLOYMENT_JAR, "${"
237: + IcanproProjectProperties.BUILD_DIR + "}/"
238: + "BCDeployment.jar");
239: ep.setProperty(IcanproProjectProperties.SE_DEPLOYMENT_JAR, "${"
240: + IcanproProjectProperties.BUILD_DIR + "}/"
241: + "SEDeployment.jar");
242: //============= End of IcanPro========================================//
243:
244: h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
245:
246: ep = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
247: if (serverInstanceID != null) {
248: ep.setProperty(
249: IcanproProjectProperties.J2EE_SERVER_INSTANCE,
250: serverInstanceID);
251: }
252: //============= Start of IcanPro========================================//
253: ep.setProperty(
254: IcanproProjectProperties.JBI_COMPONENT_CONF_FILE,
255: "ComponentInformation.xml"); // NOI18N
256: ep.setProperty(
257: IcanproProjectProperties.JBI_DEPLOYMENT_CONF_FILE,
258: "default.xml"); // NOI18N
259: //============= End of IcanPro========================================//
260:
261: h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
262: Project p = ProjectManager.getDefault().findProject(dirFO);
263: ProjectManager.getDefault().saveProject(p);
264: return h;
265: }
266:
267: }
|