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:
042: package org.netbeans.modules.compapp.projects.jbi;
043:
044: import org.netbeans.modules.compapp.projects.jbi.api.JbiProjectConstants;
045: import org.netbeans.modules.compapp.projects.jbi.api.JbiDefaultComponentInfo;
046: import org.netbeans.modules.compapp.projects.jbi.api.JbiProjectHelper;
047: import org.netbeans.modules.compapp.projects.jbi.ui.JbiCustomizerProvider;
048: import org.netbeans.modules.compapp.projects.jbi.ui.JbiLogicalViewProvider;
049: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiProjectProperties;
050: import org.netbeans.api.java.project.JavaProjectConstants;
051: import org.netbeans.api.project.FileOwnerQuery;
052: import org.netbeans.api.project.Project;
053: import org.netbeans.api.project.ProjectInformation;
054: import org.netbeans.api.project.ProjectManager;
055: import org.netbeans.api.project.ant.AntArtifact;
056: import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport;
057: import org.netbeans.spi.project.AuxiliaryConfiguration;
058: import org.netbeans.spi.project.SubprojectProvider;
059: import org.netbeans.spi.project.ant.AntArtifactProvider;
060: import org.netbeans.spi.project.support.ant.*;
061: import org.netbeans.spi.project.ui.PrivilegedTemplates;
062: import org.netbeans.spi.project.ui.ProjectOpenedHook;
063: import org.netbeans.spi.project.ui.RecommendedTemplates;
064: import org.netbeans.spi.queries.FileBuiltQueryImplementation;
065: import org.openide.ErrorManager;
066: import org.openide.filesystems.FileEvent;
067: import org.openide.filesystems.FileObject;
068: import org.openide.modules.InstalledFileLocator;
069: import org.openide.util.Lookup;
070: import org.openide.util.Mutex;
071: import org.openide.util.Utilities;
072: import org.openide.util.lookup.Lookups;
073: import org.openide.windows.TopComponent;
074: import org.w3c.dom.Element;
075: import org.w3c.dom.Node;
076: import org.w3c.dom.NodeList;
077: import org.w3c.dom.Text;
078: import java.beans.PropertyChangeListener;
079: import java.beans.PropertyChangeSupport;
080: import java.io.File;
081: import java.io.IOException;
082: import java.nio.charset.Charset;
083: import java.nio.charset.IllegalCharsetNameException;
084: import java.nio.charset.UnsupportedCharsetException;
085: import java.util.*;
086: import java.util.logging.Logger;
087: import javax.swing.Icon;
088: import javax.swing.ImageIcon;
089: import javax.swing.SwingUtilities;
090: import org.netbeans.api.queries.FileEncodingQuery;
091: import org.netbeans.modules.compapp.projects.jbi.ComponentInfoGenerator;
092: import org.netbeans.modules.compapp.projects.jbi.queries.JbiProjectEncodingQueryImpl;
093: import org.netbeans.modules.sun.manager.jbi.management.model.ComponentInformationParser;
094: import org.netbeans.modules.sun.manager.jbi.management.model.JBIComponentDocument;
095: import org.netbeans.modules.sun.manager.jbi.management.model.JBIComponentStatus;
096: import org.openide.filesystems.FileChangeAdapter;
097: import org.openide.filesystems.FileChangeListener;
098: import org.openide.filesystems.FileUtil;
099:
100: /**
101: * Represents one ejb module project
102: *
103: * @author Chris Webster
104: */
105: public final class JbiProject implements Project, AntProjectListener,
106: ProjectPropertyProvider {
107: private static final Icon PROJECT_ICON = new ImageIcon(
108: Utilities
109: .loadImage("org/netbeans/modules/compapp/projects/jbi/ui/resources/composite_application_project.png" // NOI18N
110: )); // NOI18N
111:
112: /**
113: * DOCUMENT ME!
114: */
115: public static final String SOURCES_TYPE_JBI = "JBI"; // NOI18N
116:
117: /**
118: * DOCUMENT ME!
119: */
120: //public static final String MODULE_INSTALL_NAME = "modules/org-netbeans-modules-compapp-projects-jbi.jar"; // NOI18N
121: public static final String JAVA_MODULE_INSTALL_NAME = "modules/org-netbeans-modules-junit.jar"; // NOI18N
122: public static final String ENTERPRISE_MODULE_INSTALL_NAME = "modules/org-netbeans-modules-j2ee-sun-appsrv.jar"; // NOI18N
123: public static final String XML_MODULE_INSTALL_NAME = "modules/org-netbeans-modules-xml-wsdl-extensions.jar"; // NOI18N
124: public static final String IDE_MODULE_INSTALL_NAME = "modules/org-netbeans-modules-xml-wsdl-model.jar"; // NOI18N
125: public static final String SOA_MODULE_INSTALL_NAME = "modules/org-netbeans-modules-compapp-projects-jbi.jar"; // NOI18N
126:
127: /**
128: * DOCUMENT ME!
129: */
130: //public static final String MODULE_INSTALL_CBN = "org.netbeans.modules.compapp.projects.jbi"; // NOI18N
131: public static final String JAVA_MODULE_INSTALL_CBN = "org.netbeans.modules.junit"; // NOI18N
132: public static final String ENTERPRISE_MODULE_INSTALL_CBN = "org.netbeans.modules.j2ee.sun.api"; // NOI18N
133: public static final String XML_MODULE_INSTALL_CBN = "org.netbeans.modules.xml.wsdl.model.extensions"; // NOI18N
134: public static final String IDE_MODULE_INSTALL_CBN = "org.netbeans.modules.xml.wsdl.model"; // NOI18N
135: public static final String SOA_MODULE_INSTALL_CBN = "org.netbeans.modules.compapp.projects.jbi"; // NOI18N
136:
137: /**
138: * DOCUMENT ME!
139: */
140: //public static final String MODULE_INSTALL_DIR = "module.install.dir"; // NOI18N
141: public static final String JAVA_MODULE_INSTALL_DIR = "java.module.install.dir"; // NOI18N
142: public static final String ENTERPRISE_MODULE_INSTALL_DIR = "enterprise.module.install.dir"; // NOI18N
143: public static final String XML_MODULE_INSTALL_DIR = "xml.module.install.dir"; // NOI18N
144: public static final String IDE_MODULE_INSTALL_DIR = "ide.module.install.dir"; // NOI18N
145: public static final String SOA_MODULE_INSTALL_DIR = "soa.module.install.dir"; // NOI18N
146:
147: public static final String COMPONENT_INFO_FILE_NAME = "ComponentInformation.xml"; // NOI18N
148: public static final String BINDING_COMPONENT_INFO_FILE_NAME = "BindingComponentInformation.xml"; // NOI18N
149: public static final String ASSEMBLY_INFO_FILE_NAME = "AssemblyInformation.xml"; // NOI18N
150:
151: // /** Last time in ms when the Broken References alert was shown. */
152: // private static long brokenAlertLastTime = 0;
153: //
154: // /** Is Broken References alert shown now? */
155: // private static boolean brokenAlertShown = false;
156: //
157: // /** Timeout within which request to show alert will be ignored. */
158: // private static int BROKEN_ALERT_TIMEOUT = 1000;
159:
160: private final AntProjectHelper helper;
161: private final PropertyEvaluator eval;
162: private final ReferenceHelper refHelper;
163: private final GeneratedFilesHelper genFilesHelper;
164: private final Lookup lookup;
165: private AntBasedProjectType abpt;
166: private JbiLogicalViewProvider lvp;
167: private FileChangeListener casaFileListener;
168:
169: private static final Logger LOG = Logger.getLogger(JbiProject.class
170: .getName());
171:
172: /**
173: * Creates a new JbiProject object.
174: *
175: * @param helper DOCUMENT ME!
176: * @param abpt DOCUMENT ME!
177: *
178: * @throws IOException DOCUMENT ME!
179: */
180: public JbiProject(final AntProjectHelper helper,
181: AntBasedProjectType abpt) throws IOException {
182: this .helper = helper;
183: this .abpt = abpt;
184: eval = createEvaluator();
185:
186: AuxiliaryConfiguration aux = helper
187: .createAuxiliaryConfiguration();
188: refHelper = new ReferenceHelper(helper, aux, helper
189: .getStandardPropertyEvaluator());
190: genFilesHelper = new GeneratedFilesHelper(helper);
191: lookup = createLookup(aux);
192: helper.addAntProjectListener(this );
193:
194: // SwingUtilities.invokeLater(new Runnable() {
195: // public void run() {
196: // JbiProject.this.lvp.refreshRootNode();
197: // CasaHelper.registerCasaFileListener(JbiProject.this);
198: // }
199: // });
200: }
201:
202: /**
203: * DOCUMENT ME!
204: *
205: * @return DOCUMENT ME!
206: */
207: public AntBasedProjectType getAntBasedProjectType() {
208: return abpt;
209: }
210:
211: /**
212: * DOCUMENT ME!
213: *
214: * @return DOCUMENT ME!
215: */
216: public FileObject getProjectDirectory() {
217: return helper.getProjectDirectory();
218: }
219:
220: /**
221: * DOCUMENT ME!
222: *
223: * @return DOCUMENT ME!
224: */
225: public String toString() {
226: return "JbiProject[" + getProjectDirectory() + "]"; // NOI18N
227: }
228:
229: private PropertyEvaluator createEvaluator() {
230: // XXX might need to use a custom evaluator to handle active platform substitutions... TBD
231: return helper.getStandardPropertyEvaluator();
232: }
233:
234: /**
235: * DOCUMENT ME!
236: *
237: * @return DOCUMENT ME!
238: */
239: public PropertyEvaluator evaluator() {
240: return eval;
241: }
242:
243: public ReferenceHelper getReferenceHelper() {
244: return this .refHelper;
245: }
246:
247: /**
248: * DOCUMENT ME!
249: *
250: * @return DOCUMENT ME!
251: */
252: public Lookup getLookup() {
253: return lookup;
254: }
255:
256: public AntProjectHelper getAntProjectHelper() {
257: return helper;
258: }
259:
260: private Lookup createLookup(AuxiliaryConfiguration aux) {
261: SubprojectProvider spp = new JbiSubprojectProvider(refHelper
262: .createSubprojectProvider());
263: FileBuiltQueryImplementation fileBuilt = helper
264: .createGlobFileBuiltQuery(helper
265: .getStandardPropertyEvaluator(),
266: new String[] { "${src.dir}/*.java" }, // NOI18N
267: new String[] { "${build.classes.dir}/*.class" } // NOI18N
268: );
269: final SourcesHelper sourcesHelper = new SourcesHelper(helper,
270: evaluator());
271: String webModuleLabel = org.openide.util.NbBundle.getMessage(
272: JbiCustomizerProvider.class, "LBL_Node_EJBModule" // NOI18N
273: );
274: String srcJavaLabel = org.openide.util.NbBundle.getMessage(
275: JbiCustomizerProvider.class, "LBL_Node_Sources" // NOI18N
276: );
277:
278: sourcesHelper.addPrincipalSourceRoot("${"
279: + JbiProjectProperties.SOURCE_ROOT + "}",
280: webModuleLabel, // NOI18N
281: null, null);
282: sourcesHelper.addPrincipalSourceRoot("${"
283: + JbiProjectProperties.SRC_DIR + "}", srcJavaLabel, // NOI18N
284: null, null);
285:
286: sourcesHelper.addTypedSourceRoot("${"
287: + JbiProjectProperties.SRC_DIR + "}", SOURCES_TYPE_JBI,
288: srcJavaLabel, // NOI18N
289: null, null);
290: sourcesHelper.addTypedSourceRoot("${"
291: + JbiProjectProperties.SRC_DIR + "}",
292: JavaProjectConstants.SOURCES_TYPE_JAVA, // NOI18N
293: srcJavaLabel, /*XXX*/
294: null, null);
295: ProjectManager.mutex().postWriteRequest(new Runnable() {
296: public void run() {
297: sourcesHelper
298: .registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
299: }
300: });
301:
302: casaFileListener = new FileChangeAdapter() {
303: @Override
304: public void fileChanged(FileEvent fe) {
305: refreshRootNode();
306: }
307:
308: @Override
309: public void fileDeleted(FileEvent fe) {
310: refreshRootNode();
311: }
312:
313: private void refreshRootNode() {
314: SwingUtilities.invokeLater(new Runnable() {
315: public void run() {
316: JbiProject.this .lvp.refreshRootNode();
317: }
318: });
319: }
320: };
321:
322: return Lookups
323: .fixed(new Object[] {
324: this ,
325: new Info(),
326: aux,
327: helper.createCacheDirectoryProvider(),
328: helper,
329: spp,
330: new JbiActionProvider(this , helper, refHelper),
331: lvp = new JbiLogicalViewProvider(this , helper,
332: evaluator(), spp, refHelper),
333: new JbiCustomizerProvider(this , helper,
334: refHelper),
335: new AntArtifactProviderImpl(),
336: new ProjectXmlSavedHookImpl(),
337: new ProjectOpenedHookImpl(),
338: new JbiProjectOperations(this ),
339: new HashSet<TopComponent>(),
340: fileBuilt,
341: new RecommendedTemplatesImpl(),
342: new JbiProjectEncodingQueryImpl(evaluator()),
343: refHelper,
344: sourcesHelper.createSources(),
345: casaFileListener,
346: helper
347: .createSharabilityQuery(
348: evaluator(),
349: new String[] { "${"
350: + JbiProjectProperties.SOURCE_ROOT
351: + "}" }, // NOI18N
352: new String[] {
353: "${"
354: + JbiProjectProperties.BUILD_DIR
355: + "}", // NOI18N
356: "${"
357: + JbiProjectProperties.DIST_DIR
358: + "}", // NOI18N
359: "${"
360: + JbiProjectProperties.TEST_RESULTS_DIR
361: + "}", // NOI18N
362: "${"
363: + JbiProjectProperties.SRC_BUILD_DIR
364: + "}" // NOI18N
365: }) });
366: }
367:
368: /**
369: * DOCUMENT ME!
370: *
371: * @param ev DOCUMENT ME!
372: */
373: public void configurationXmlChanged(AntProjectEvent ev) {
374: if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) {
375: // Could be various kinds of changes, but name & displayName might have changed.
376: Info info = (Info) getLookup().lookup(
377: ProjectInformation.class);
378: info.firePropertyChange(ProjectInformation.PROP_NAME);
379: info
380: .firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME);
381: }
382: }
383:
384: /**
385: * DOCUMENT ME!
386: *
387: * @param ev DOCUMENT ME!
388: */
389: public void propertiesChanged(AntProjectEvent ev) {
390: if (lvp != null) {
391: lvp.refreshRootNode();
392: }
393: }
394:
395: /**
396: * DOCUMENT ME!
397: *
398: * @return DOCUMENT ME!
399: */
400: public String getBuildXmlName() {
401: String storedName = helper.getStandardPropertyEvaluator()
402: .getProperty(JbiProjectProperties.BUILD_FILE);
403:
404: return (storedName == null) ? GeneratedFilesHelper.BUILD_XML_PATH
405: : storedName;
406: }
407:
408: /**
409: * Return the test directory of a JBI project
410: *
411: * @return JBI test directory
412: */
413: public FileObject getTestDirectory() {
414: String testDir = helper.getStandardPropertyEvaluator()
415: .getProperty(JbiProjectProperties.TEST_DIR);
416:
417: try {
418: return helper.resolveFileObject(testDir);
419: } catch (Exception e) {
420: return null;
421: }
422: }
423:
424: /**
425: * Create the test directory of a JBI project
426: *
427: * @return JBI test directory
428: */
429: public FileObject createTestDirectory() {
430: String testDir = helper.getStandardPropertyEvaluator()
431: .getProperty(JbiProjectProperties.TEST_DIR); // NOI18N
432:
433: if (helper.resolveFileObject(testDir) == null) {
434: try {
435: getProjectDirectory().createFolder(testDir);
436: } catch (java.io.IOException ex) {
437: ex.printStackTrace();
438: }
439: }
440:
441: return helper.resolveFileObject(testDir);
442: }
443:
444: /**
445: * Return the test results directory of a JBI project
446: *
447: * @return JBI test results directory
448: */
449: public FileObject getTestResultsDirectory() {
450: String testResultsDir = helper.getStandardPropertyEvaluator()
451: .getProperty(JbiProjectProperties.TEST_RESULTS_DIR);
452:
453: return helper.resolveFileObject(testResultsDir);
454: }
455:
456: // Package private methods -------------------------------------------------
457: FileObject getSourceDirectory() {
458: String srcDir = helper.getStandardPropertyEvaluator()
459: .getProperty(JbiProjectProperties.SRC_DIR); // NOI18N
460:
461: return srcDir == null ? null : helper.resolveFileObject(srcDir);
462: }
463:
464: /**
465: * Return configured project name.
466: *
467: * @return DOCUMENT ME!
468: */
469: public String getName() {
470: return (String) ProjectManager.mutex().readAccess(
471: new Mutex.Action() {
472: public Object run() {
473: Element data = helper
474: .getPrimaryConfigurationData(true);
475:
476: // XXX replace by XMLUtil when that has findElement, findText, etc.
477: NodeList nl = data
478: .getElementsByTagNameNS(
479: JbiProjectType.PROJECT_CONFIGURATION_NAMESPACE,
480: "name" // NOI18N
481: );
482:
483: if (nl.getLength() == 1) {
484: nl = nl.item(0).getChildNodes();
485:
486: if ((nl.getLength() == 1)
487: && (nl.item(0).getNodeType() == Node.TEXT_NODE)) {
488: return ((Text) nl.item(0))
489: .getNodeValue();
490: }
491: }
492:
493: return "???"; // NOI18N
494: }
495: });
496: }
497:
498: /** Store configured project name. */
499: public void setName(final String name) {
500: ProjectManager.mutex().writeAccess(new Mutex.Action() {
501: public Object run() {
502: Element data = helper.getPrimaryConfigurationData(true);
503: // XXX replace by XMLUtil when that has findElement, findText, etc.
504: NodeList nl = data.getElementsByTagNameNS(
505: JbiProjectType.PROJECT_CONFIGURATION_NAMESPACE,
506: "name"); // NOI18N
507: Element nameEl;
508: if (nl.getLength() == 1) {
509: nameEl = (Element) nl.item(0);
510: NodeList deadKids = nameEl.getChildNodes();
511: while (deadKids.getLength() > 0) {
512: nameEl.removeChild(deadKids.item(0));
513: }
514: } else {
515: nameEl = data
516: .getOwnerDocument()
517: .createElementNS(
518: JbiProjectType.PROJECT_CONFIGURATION_NAMESPACE,
519: "name"); // NOI18N
520: data.insertBefore(nameEl, /* OK if null */data
521: .getChildNodes().item(0));
522: }
523: nameEl.appendChild(data.getOwnerDocument()
524: .createTextNode(name));
525: helper.putPrimaryConfigurationData(data, true);
526: return null;
527: }
528: });
529: }
530:
531: /**
532: * DOCUMENT ME!
533: *
534: * @return DOCUMENT ME!
535: */
536: public JbiProjectProperties getProjectProperties() {
537: return new JbiProjectProperties(this , helper, refHelper);
538: }
539:
540: // Private innerclasses ----------------------------------------------------
541: private final class Info implements ProjectInformation {
542: private final PropertyChangeSupport pcs = new PropertyChangeSupport(
543: this );
544:
545: /**
546: * Creates a new Info object.
547: */
548: Info() {
549: }
550:
551: /**
552: * DOCUMENT ME!
553: *
554: * @param prop DOCUMENT ME!
555: */
556: void firePropertyChange(String prop) {
557: pcs.firePropertyChange(prop, null, null);
558: }
559:
560: /**
561: * DOCUMENT ME!
562: *
563: * @return DOCUMENT ME!
564: */
565: public String getName() {
566: return JbiProject.this .getName();
567: }
568:
569: /**
570: * DOCUMENT ME!
571: *
572: * @return DOCUMENT ME!
573: */
574: public String getDisplayName() {
575: return JbiProject.this .getName();
576: }
577:
578: /**
579: * DOCUMENT ME!
580: *
581: * @return DOCUMENT ME!
582: */
583: public Icon getIcon() {
584: return PROJECT_ICON;
585: }
586:
587: /**
588: * DOCUMENT ME!
589: *
590: * @return DOCUMENT ME!
591: */
592: public Project getProject() {
593: return JbiProject.this ;
594: }
595:
596: /**
597: * DOCUMENT ME!
598: *
599: * @param listener DOCUMENT ME!
600: */
601: public void addPropertyChangeListener(
602: PropertyChangeListener listener) {
603: pcs.addPropertyChangeListener(listener);
604: }
605:
606: /**
607: * DOCUMENT ME!
608: *
609: * @param listener DOCUMENT ME!
610: */
611: public void removePropertyChangeListener(
612: PropertyChangeListener listener) {
613: pcs.removePropertyChangeListener(listener);
614: }
615: }
616:
617: private final class ProjectXmlSavedHookImpl extends
618: ProjectXmlSavedHook {
619: /**
620: * Creates a new ProjectXmlSavedHookImpl object.
621: */
622: ProjectXmlSavedHookImpl() {
623: }
624:
625: /**
626: * DOCUMENT ME!
627: *
628: * @throws IOException DOCUMENT ME!
629: */
630: protected void projectXmlSaved() throws IOException {
631: genFilesHelper.refreshBuildScript(
632: GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
633: JbiProject.class
634: .getResource("resources/build-impl.xsl"),
635: false // NOI18N
636: );
637: genFilesHelper
638: .refreshBuildScript(
639: getBuildXmlName(),
640: JbiProject.class
641: .getResource("resources/build.xsl"),
642: false // NOI18N
643: );
644: }
645: }
646:
647: private final class ProjectOpenedHookImpl extends ProjectOpenedHook {
648: /**
649: * Creates a new ProjectOpenedHookImpl object.
650: */
651: ProjectOpenedHookImpl() {
652: }
653:
654: /**
655: * DOCUMENT ME!
656: */
657: protected void projectOpened() {
658: try {
659: // Check up on build scripts.
660: genFilesHelper
661: .refreshBuildScript(
662: GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
663: JbiProject.class
664: .getResource("resources/build-impl.xsl"),
665: true // NOI18N
666: );
667: genFilesHelper.refreshBuildScript(getBuildXmlName(),
668: JbiProject.class
669: .getResource("resources/build.xsl"),
670: true // NOI18N
671: );
672: } catch (IOException e) {
673: ErrorManager.getDefault().notify(
674: ErrorManager.INFORMATIONAL, e);
675: }
676:
677: // Make it easier to run headless builds on the same machine at least.
678: ProjectManager.mutex().writeAccess(new Mutex.Action() {
679: public Object run() {
680:
681: // 1. Update component info and binding component info if needed...
682: String name = JbiProject.this .getName();
683: // On Solaris x86, JbiProject.this.getProjectDirectory().getPath()
684: // is missing the preceding "/".
685: //System.out.println("projPath is " + JbiProject.this.getProjectDirectory().getPath());
686: //System.out.println("projPath (absolute) is " + FileUtil.toFile(JbiProject.this.getProjectDirectory()).getAbsolutePath());
687: //String confDir = JbiProject.this.getProjectDirectory().getPath() + "/src/conf"; // NOI18N
688: FileObject projDir = JbiProject.this
689: .getProjectDirectory();
690: String confDir = FileUtil.toFile(projDir)
691: .getAbsolutePath()
692: + File.separator
693: + "src"
694: + File.separator
695: + "conf"; // NOI18N
696: updateComponentDocuments(confDir);
697:
698: // 2. Make sure the component target list is not corrupted.
699: JbiProjectProperties projectProperties = getProjectProperties();
700: try {
701: projectProperties.fixComponentTargetList();
702: } catch (Exception e) {
703: // The failure is probably due to unresolved references.
704: // Once the reference problem is fixed, we will try
705: // fixing the component target list again.
706: return null;
707: }
708:
709: // 3.1 Migrate old casa.wsdl to <Proj>.wsdl, if applicable
710: String projDirLoc = JbiProject.this
711: .getProjectDirectory().getPath();
712: String srcDirLoc = projDirLoc
713: + File.separator
714: + helper
715: .getStandardPropertyEvaluator()
716: .getProperty(
717: JbiProjectProperties.SOURCE_ROOT);
718: String projName = JbiProjectHelper
719: .getJbiProjectName(JbiProject.this );
720: MigrationHelper
721: .migrateCasaWSDL(srcDirLoc, projName);
722:
723: // 3.2 Migrate old compapp properties
724: EditableProperties projectEP = helper
725: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
726: MigrationHelper.migrateCompAppProperties(
727: projDirLoc, projectEP);
728:
729: // 3.3 Add project encoding for old projects
730: if (projectEP
731: .getProperty(JbiProjectProperties.SOURCE_ENCODING) == null) {
732: projectEP.setProperty(
733: JbiProjectProperties.SOURCE_ENCODING,
734: // FIXME: maybe we should use Charset.defaultCharset() instead?
735: // See comments in JbiProjectEncodingQueryImpl.java
736: FileEncodingQuery.getDefaultEncoding()
737: .name());
738: }
739:
740: helper.putProperties(
741: AntProjectHelper.PROJECT_PROPERTIES_PATH,
742: projectEP);
743:
744: // 4. Set private properties
745: EditableProperties privateEP = helper
746: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
747: privateEP.setProperty("netbeans.user", System
748: .getProperty("netbeans.user")); // NOI18N
749:
750: InstalledFileLocator installedFileLocator = InstalledFileLocator
751: .getDefault();
752:
753: File f = installedFileLocator.locate(
754: SOA_MODULE_INSTALL_NAME,
755: SOA_MODULE_INSTALL_CBN, false);
756: if (f != null) {
757: privateEP.setProperty(SOA_MODULE_INSTALL_DIR, f
758: .getParentFile().getPath());
759: }
760:
761: f = installedFileLocator.locate(
762: JAVA_MODULE_INSTALL_NAME,
763: JAVA_MODULE_INSTALL_CBN, false);
764: if (f != null) {
765: privateEP.setProperty(JAVA_MODULE_INSTALL_DIR,
766: f.getParentFile().getPath());
767: }
768:
769: f = installedFileLocator.locate(
770: XML_MODULE_INSTALL_NAME,
771: XML_MODULE_INSTALL_CBN, false);
772: if (f != null) {
773: privateEP.setProperty(XML_MODULE_INSTALL_DIR, f
774: .getParentFile().getPath());
775: }
776:
777: f = installedFileLocator.locate(
778: IDE_MODULE_INSTALL_NAME,
779: IDE_MODULE_INSTALL_CBN, false);
780: if (f != null) {
781: privateEP.setProperty(IDE_MODULE_INSTALL_DIR, f
782: .getParentFile().getPath());
783: }
784:
785: f = installedFileLocator.locate(
786: ENTERPRISE_MODULE_INSTALL_NAME,
787: ENTERPRISE_MODULE_INSTALL_CBN, false);
788: if (f != null) {
789: privateEP.setProperty(
790: ENTERPRISE_MODULE_INSTALL_DIR, f
791: .getParentFile().getPath());
792: }
793:
794: helper.putProperties(
795: AntProjectHelper.PRIVATE_PROPERTIES_PATH,
796: privateEP);
797:
798: try {
799: ProjectManager.getDefault().saveProject(
800: JbiProject.this );
801: } catch (IOException e) {
802: ErrorManager.getDefault().notify(e);
803: }
804:
805: // 5. Create casa file if it doesn't exist yet.
806: CasaHelper.getCasaFileObject(JbiProject.this , true);
807:
808: // 6. Update ASI.xml
809: getProjectProperties().saveAssemblyInfo();
810:
811: // 7. Clean up locks.
812: CasaHelper.cleanupLocks(JbiProject.this );
813:
814: return null;
815: }
816: });
817:
818: if (JbiLogicalViewProvider
819: .hasBrokenLinks(helper, refHelper)) {
820: BrokenReferencesSupport.showAlert();
821: }
822:
823: String prop = eval
824: .getProperty(JbiProjectProperties.SOURCE_ENCODING);
825: if (prop != null) {
826: try {
827: Charset c = Charset.forName(prop);
828: } catch (IllegalCharsetNameException e) {
829: //Broken property, log & ignore
830: LOG
831: .warning("Illegal charset: "
832: + prop
833: + " in project: "
834: + // NOI18N
835: FileUtil
836: .getFileDisplayName(getProjectDirectory()));
837: } catch (UnsupportedCharsetException e) {
838: //todo: Needs UI notification like broken references.
839: LOG
840: .warning("Unsupported charset: "
841: + prop
842: + " in project: "
843: + // NOI18N
844: FileUtil
845: .getFileDisplayName(getProjectDirectory()));
846: }
847: }
848: }
849:
850: private void updateComponentDocuments(String confDir) {
851:
852: try {
853: // Load component info..
854: File compFile = new File(confDir + File.separator
855: + JbiProject.COMPONENT_INFO_FILE_NAME);
856: List<JBIComponentStatus> compList = ComponentInformationParser
857: .parse(compFile);
858:
859: // Load binding component info..
860: File bindingCompFile = new File(confDir
861: + File.separator
862: + JbiProject.BINDING_COMPONENT_INFO_FILE_NAME);
863: List<JBIComponentStatus> bindingCompList = ComponentInformationParser
864: .parse(bindingCompFile);
865:
866: // Update component namespaces using info from binding component doc
867: for (JBIComponentStatus bindingComp : bindingCompList) {
868: String name = bindingComp.getName();
869: List<String> nsList = bindingComp.getNamespaces();
870: for (JBIComponentStatus comp : compList) {
871: if (comp.getName().equals(name)) {
872: comp.setNamespaces(nsList);
873: break;
874: }
875: }
876: }
877:
878: // Get known SE/BCs at design-time
879: JbiDefaultComponentInfo defaultCompInfo = JbiDefaultComponentInfo
880: .getJbiDefaultComponentInfo();
881: Map<String, JBIComponentStatus> defaultCompInfoMap = defaultCompInfo
882: .getComponentHash();
883:
884: List<JBIComponentStatus> deltaList = new ArrayList<JBIComponentStatus>();
885:
886: boolean nsListUpdated = false;
887:
888: for (String name : defaultCompInfoMap.keySet()) {
889: JBIComponentStatus compInMap = defaultCompInfoMap
890: .get(name);
891: boolean found = false;
892: for (JBIComponentStatus comp : compList) {
893: if (comp.getName().equals(name)) {
894: for (String ns : compInMap.getNamespaces()) {
895: if (comp.addNamespace(ns)) {
896: nsListUpdated = true;
897: }
898: }
899: found = true;
900: break;
901: }
902: }
903: if (!found) {
904: deltaList.add(compInMap);
905: }
906: }
907:
908: if (deltaList != null && deltaList.size() > 0
909: || nsListUpdated) {
910: List<JBIComponentStatus> list = new ArrayList<JBIComponentStatus>();
911: list.addAll(compList);
912: list.addAll(deltaList);
913: new ComponentInfoGenerator(confDir, list).doIt();
914: }
915: } catch (Exception e) {
916: e.printStackTrace();
917: }
918: }
919:
920: /**
921: * DOCUMENT ME!
922: */
923: protected void projectClosed() {
924: Set topComponentSet = (Set) JbiProject.this .getLookup()
925: .lookup(HashSet.class);
926: if (topComponentSet != null) {
927: for (Object tc : topComponentSet) {
928: if (tc instanceof TopComponent) {
929: ((TopComponent) tc).close();
930: }
931: }
932: }
933:
934: // Probably unnecessary, but just in case:
935: try {
936: ProjectManager.getDefault()
937: .saveProject(JbiProject.this );
938: } catch (IOException e) {
939: ErrorManager.getDefault().notify(e);
940: }
941: }
942: }
943:
944: /**
945: * Exports the main JAR as an official build product for use from other scripts. The type of
946: * the artifact will be {@link AntArtifact}.
947: */
948: private final class AntArtifactProviderImpl implements
949: AntArtifactProvider {
950: /**
951: * DOCUMENT ME!
952: *
953: * @return DOCUMENT ME!
954: */
955: public AntArtifact[] getBuildArtifacts() {
956: return new AntArtifact[] { helper.createSimpleAntArtifact(
957: JbiProjectConstants.ARTIFACT_TYPE_JBI_AU,
958: "dist.jar", // NOI18N
959: helper.getStandardPropertyEvaluator(), "dist",
960: "clean" // NOI18N
961: ), // NOI18N
962: };
963: }
964: }
965:
966: private static final class RecommendedTemplatesImpl implements
967: RecommendedTemplates, PrivilegedTemplates {
968:
969: // List of primarily supported templates
970: private static final String[] TYPES = new String[] { "XML", // NOI18N
971: "simple-files" // NOI18N
972: };
973:
974: private static final String[] PRIVILEGED_NAMES = new String[] {
975: "Templates/XML/WSDL.wsdl", // NOI18N
976: "Templates/XML/XmlSchema.xsd", // NOI18N
977: "Templates/XML/retrieveSchemaResource", // NOI18N
978: "Templates/XML/retrieveWSDLResource", // NOI18N
979: };
980:
981: public String[] getRecommendedTypes() {
982: return TYPES;
983: }
984:
985: public String[] getPrivilegedTemplates() {
986: return PRIVILEGED_NAMES;
987: }
988: }
989: }
|