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