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.

View | Details | Raw Unified | Return to bug 233481
Collapse All | Expand All

(-)a/glassfish.common/src/org/netbeans/modules/glassfish/spi/Utils.java (-4 / +5 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2009-2011 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2009-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 61-68 Link Here
61
import org.openide.filesystems.FileUtil;
61
import org.openide.filesystems.FileUtil;
62
62
63
/**
63
/**
64
 *
64
 * Utilities.
65
 * @author vbk
65
 * <p/>
66
 * @author Vince Kraemer
66
 */
67
 */
67
public class Utils {
68
public class Utils {
68
69
Lines 416-422 Link Here
416
417
417
    /** 
418
    /** 
418
     * Use the server instance id for a project to decide whether the server specific DD/resource
419
     * Use the server instance id for a project to decide whether the server specific DD/resource
419
     * file should use the glassfish- prefix.
420
     * file should use the {@code glassfish-} prefix.
420
     * 
421
     * 
421
     * @param serverInstanceID
422
     * @param serverInstanceID
422
     * @return
423
     * @return
(-)a/glassfish.eecommon/nbproject/project.xml (+7 lines)
Lines 219-224 Link Here
219
                    <test-dependency>
219
                    <test-dependency>
220
                        <code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
220
                        <code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
221
                    </test-dependency>
221
                    </test-dependency>
222
                    <test-dependency>
223
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
224
                        <compile-dependency/>
225
                    </test-dependency>
226
                    <test-dependency>
227
                        <code-name-base>org.netbeans.insane</code-name-base>
228
                    </test-dependency>
222
                </test-type>
229
                </test-type>
223
            </test-dependencies>
230
            </test-dependencies>
224
            <friend-packages>
231
            <friend-packages>
(-)a/glassfish.eecommon/src/org/netbeans/modules/glassfish/eecommon/api/config/GlassfishConfiguration.java (-29 / +218 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2008-2011 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2008-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 42-48 Link Here
42
42
43
package org.netbeans.modules.glassfish.eecommon.api.config;
43
package org.netbeans.modules.glassfish.eecommon.api.config;
44
44
45
import org.netbeans.modules.glassfish.eecommon.api.*;
46
import java.io.File;
45
import java.io.File;
47
import java.io.IOException;
46
import java.io.IOException;
48
import java.io.OutputStream;
47
import java.io.OutputStream;
Lines 54-59 Link Here
54
import java.util.logging.Logger;
53
import java.util.logging.Logger;
55
import org.netbeans.api.project.FileOwnerQuery;
54
import org.netbeans.api.project.FileOwnerQuery;
56
import org.netbeans.api.project.Project;
55
import org.netbeans.api.project.Project;
56
import org.netbeans.modules.glassfish.eecommon.api.Utils;
57
import org.netbeans.modules.glassfish.eecommon.api.XmlFileCreator;
58
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
59
import org.netbeans.modules.glassfish.tooling.utils.OsUtils;
57
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
60
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
58
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
61
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
59
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
62
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
Lines 89-125 Link Here
89
import org.openide.util.RequestProcessor;
92
import org.openide.util.RequestProcessor;
90
93
91
/**
94
/**
92
 * Basic j2eeserver configuration api support for V2 and V3 plugins
95
 * Basic Java EE server configuration API support for V2, V3 and V4 plugins.
93
 *
96
 * <p/>
94
 * @author Peter Williams
97
 * @author Peter Williams, Tomas Kraus
95
 */
98
 */
96
public abstract class GlassfishConfiguration implements
99
public abstract class GlassfishConfiguration implements
97
        ContextRootConfiguration,
100
        ContextRootConfiguration,
98
        EjbResourceConfiguration,
101
        EjbResourceConfiguration,
99
        MessageDestinationConfiguration,
102
        MessageDestinationConfiguration,
100
        DatasourceConfiguration
103
        DatasourceConfiguration {
101
    {
104
105
    ////////////////////////////////////////////////////////////////////////////
106
    // Class attributes                                                       //
107
    ////////////////////////////////////////////////////////////////////////////
108
109
    /** GlassFish Java EE common module Logger. */
110
    private static final Logger LOGGER = Logger.getLogger("glassfish-eecommon");
111
112
    /** GlassFish resource file suffix is {@code .xml}. */
113
    private static final String RESOURCE_FILES_SUFFIX = ".xml";
114
115
   /** List of base file names containing server resources:<ul>
116
      * <li><i>[0]</i> points to current name used since GlassFich v3.</li>
117
      * <li><i>[1]</i> points to old name used before GlassFich v3.</li>
118
      * <ul>*/
119
    static final String[] RESOURCE_FILES = {
120
        "glassfish-resources" + RESOURCE_FILES_SUFFIX,
121
        "sun-resources" + RESOURCE_FILES_SUFFIX
122
    };
123
124
    ////////////////////////////////////////////////////////////////////////////
125
    // Static methods                                                         //
126
    ////////////////////////////////////////////////////////////////////////////
127
128
    /**
129
     * Create resource file path fragment for given Java EE module.
130
     * <i>Internal helper method.</i>
131
     * <p/>
132
     * @param module   Java EE module (project).
133
     * @param fileName Resources file name.
134
     * @return Resource file path fragment for given Java EE module.
135
     */
136
    private static String resourceFilePath(final J2eeModule module,final String fileName) {
137
        String configDir = JavaEEModule.getConfigDir(module.getType());
138
        if (configDir == null) {
139
            throw new IllegalArgumentException("Unknown Java EE module type.");
140
        }
141
        return OsUtils.joinPaths(configDir, fileName);
142
    }
143
144
    /**
145
     * Get existing {@code RESOURCE_FILES} array indexes for provided GlassFish
146
     * server version.
147
     * <br/>
148
     * <i>Internal {@link #getExistingResourceFile(J2eeModule, GlassFishVersion)
149
     * helper method.</i>
150
     * <p/>
151
     * @param version GlassFish server version.
152
     * @return An array of {@code RESOURCE_FILES} array indexes pointing
153
     *         to resource files to search for.
154
     */
155
    private static int[] versionToResourceFilesIndexes(
156
            final GlassFishVersion version) {
157
        // All files for unknown version.
158
        if (version == null) {
159
            return new int[]{0,1};
160
        }
161
        // glassfish-resources.xml for v4
162
        if (GlassFishVersion.ge(version, GlassFishVersion.GF_4)) {
163
            return new int[]{0};
164
        }
165
        // glassfish-resources.xml and sun-resources.xml for v3
166
        if (GlassFishVersion.ge(version, GlassFishVersion.GF_3_1)) {
167
            return new int[]{0,1};
168
        // sun-resources.xml for older
169
        } else {
170
            return new int[]{1};
171
        }
172
    }
173
174
    /**
175
     * Get new {@code RESOURCE_FILES} array index for provided GlassFish
176
     * server version.
177
     * <p/>
178
     * @param version GlassFish server version.
179
     * @return An {@code RESOURCE_FILES} array index pointing
180
     *         to resource file to be created.
181
     */
182
    private static int versionToNewResourceFilesIndex(
183
            final GlassFishVersion version) {
184
        // glassfish-resources.xml is returned for versions 3.1 and higher
185
        // or as default for unknown version.
186
        if (version == null
187
                || GlassFishVersion.ge(version, GlassFishVersion.GF_3_1)) {
188
            return 0;
189
        // sun-resources.xml is returned for versions before 3.1
190
        } else {
191
            return 1;
192
        }
193
    }
194
195
    /**
196
     * Get existing GlassFish resources file name.
197
     * GlassFish resources file depends on server version and used storage.
198
     * GlassFish v3 supports old {@code sun-resources.xml} together with new
199
     * {@code glassfish-resources.xml}. GlassFish v4 supports only
200
     * new {@code glassfish-resources.xml} file.
201
     * Those files can be found in server configuration directory (to be included
202
     * into target project archive) or in server resources directory (won't be
203
     * included into target project archive).
204
     * Search works with following priorities:<ul>
205
     * <li><i>GlassFish v2:</i> Only {@code sun-resources.xml} is checked.</li>
206
     * <li><i>GlassFish v3:</i> {@code glassfish-resources.xml} is checked first,
207
     *                          {@code sun-resources.xml} as fallback.</li>
208
     * <li><i>GlassFish v4:</i> Only {@code glassfish-resources.xml} is checked.</li>
209
     * <li><i>Configuration directory</i> is checked first, <i>resources directory</i>
210
     *        as fallback.</li>
211
     * </ul>
212
     * 
213
     * @param module  Java EE module (project).
214
     * @param version Resources file names depend on GlassFish server version.
215
     * @return Existing GlassFish resources file or {@code null} when no resources
216
     *         file was found.
217
     */
218
    public static final File getExistingResourceFile(
219
            final J2eeModule module, final GlassFishVersion version) {
220
        // RESOURCE_FILES indexes to search for.
221
        final int[] indexes = versionToResourceFilesIndexes(version);
222
        for (int index : indexes) {
223
            // Check configuration directory first.
224
            final String name = resourceFilePath(module, RESOURCE_FILES[index]);
225
            File file = module.getDeploymentConfigurationFile(name);
226
            if (file != null && file.isFile() && file.canRead()) {
227
                return file;
228
            }
229
            // Check resiources directory as a fallback.
230
            file = new File(module.getResourceDirectory(), RESOURCE_FILES[index]);
231
            if (file.isFile() && file.canRead()) {
232
                return file;
233
            }
234
        }
235
        return null;
236
    }
237
238
    /**
239
     * Get new GlassFish resources file name for creation.
240
     * <p/>
241
     * @param module  Java EE module (project).
242
     * @param version Resources file names depend on GlassFish server version.
243
     * @return GlassFish resources file to be created.
244
     */
245
    public static final File getNewResourceFile(
246
            final J2eeModule module, final GlassFishVersion version) {
247
        final int index = versionToNewResourceFilesIndex(version);
248
        final String name = resourceFilePath(module, RESOURCE_FILES[index]);
249
        return module.getDeploymentConfigurationFile(name);
250
    }
251
252
    ////////////////////////////////////////////////////////////////////////////
253
    // Instance attributes                                                    //
254
    ////////////////////////////////////////////////////////////////////////////
102
255
103
    protected final J2eeModule module;
256
    protected final J2eeModule module;
104
    protected final J2eeModuleHelper moduleHelper;
257
    protected final J2eeModuleHelper moduleHelper;
105
    protected final File primarySunDD;
258
    protected final File primarySunDD;
106
    protected final File secondarySunDD;
259
    protected final File secondarySunDD;
107
    protected DescriptorListener descriptorListener;
260
    protected DescriptorListener descriptorListener;
108
261
    /** GlassFish server version. */
262
    protected GlassFishVersion version;
109
    private ASDDVersion appServerVersion;
263
    private ASDDVersion appServerVersion;
110
    private ASDDVersion minASVersion;
264
    private ASDDVersion minASVersion;
111
    private ASDDVersion maxASVersion;
265
    private ASDDVersion maxASVersion;
112
    private boolean deferredAppServerChange;
266
    private boolean deferredAppServerChange;
113
    private final String defaultcr;
267
    private final String defaultcr;
114
268
269
    ////////////////////////////////////////////////////////////////////////////
270
    // Constructors                                                           //
271
    ////////////////////////////////////////////////////////////////////////////
115
272
116
    protected GlassfishConfiguration(J2eeModule module) throws ConfigurationException {
273
    /**
117
        this(module, J2eeModuleHelper.getSunDDModuleHelper(module.getType()));
274
     * Creates an instance of Java EE server configuration API support.
275
     * {@link J2eeModuleHelper} instance is added depending on Java EE module type.
276
     * <p/>
277
     * @param module  Java EE module (project).
278
     * @param version GlassFish server version.
279
     * @throws ConfigurationException when there is a problem with Java EE server
280
     *         configuration initialization.
281
     */
282
    protected GlassfishConfiguration(
283
            final J2eeModule module, final GlassFishVersion version
284
    ) throws ConfigurationException {
285
        this(module, J2eeModuleHelper.getSunDDModuleHelper(module.getType()), version);
118
    }
286
    }
119
287
120
    protected GlassfishConfiguration(J2eeModule module, J2eeModuleHelper moduleHelper) throws ConfigurationException {
288
    /**
289
     * Creates an instance of Java EE server configuration API support with existing
290
     * {@link J2eeModuleHelper} instance.
291
     * <p/>
292
     * @param module       Java EE module (project).
293
     * @param moduleHelper Already existing {@link J2eeModuleHelper} instance.
294
     * @param version      GlassFish server version.
295
     * @throws ConfigurationException when there is a problem with Java EE server
296
     *         configuration initialization.
297
     */
298
    @SuppressWarnings("LeakingThisInConstructor")
299
    protected GlassfishConfiguration(
300
            final J2eeModule module, final J2eeModuleHelper moduleHelper,
301
            final GlassFishVersion version
302
    ) throws ConfigurationException {
121
        this.module = module;
303
        this.module = module;
122
        this.moduleHelper = moduleHelper;
304
        this.moduleHelper = moduleHelper;
305
        this.version = version;
123
        if(moduleHelper != null) {
306
        if(moduleHelper != null) {
124
            this.primarySunDD = moduleHelper.getPrimarySunDDFile(module);
307
            this.primarySunDD = moduleHelper.getPrimarySunDDFile(module);
125
            this.secondarySunDD = moduleHelper.getSecondarySunDDFile(module);
308
            this.secondarySunDD = moduleHelper.getSecondarySunDDFile(module);
Lines 210-215 Link Here
210
        throw new UnsupportedOperationException("JSR-88 configuration not supported.");
393
        throw new UnsupportedOperationException("JSR-88 configuration not supported.");
211
    }
394
    }
212
395
396
    ////////////////////////////////////////////////////////////////////////////
397
    // Methods                                                                //
398
    ////////////////////////////////////////////////////////////////////////////
399
213
    public void dispose() {
400
    public void dispose() {
214
        if(descriptorListener != null) {
401
        if(descriptorListener != null) {
215
            descriptorListener.removeListeners();
402
            descriptorListener.removeListeners();
Lines 218-224 Link Here
218
405
219
        GlassfishConfiguration storedCfg = getConfiguration(primarySunDD);
406
        GlassfishConfiguration storedCfg = getConfiguration(primarySunDD);
220
        if (storedCfg != this) {
407
        if (storedCfg != this) {
221
            Logger.getLogger("glassfish-eecommon").log(Level.INFO, 
408
            LOGGER.log(Level.INFO, 
222
                    "Stored DeploymentConfiguration ({0}) instance not the one being disposed of ({1}).",
409
                    "Stored DeploymentConfiguration ({0}) instance not the one being disposed of ({1}).",
223
                    new Object[]{storedCfg, this});
410
                    new Object[]{storedCfg, this});
224
        }
411
        }
Lines 232-238 Link Here
232
    // Appserver version support
419
    // Appserver version support
233
    // ------------------------------------------------------------------------
420
    // ------------------------------------------------------------------------
234
    private ASDDVersion computeMinASVersion(String j2eeModuleVersion) {
421
    private ASDDVersion computeMinASVersion(String j2eeModuleVersion) {
235
        return moduleHelper.getMinASVersion(j2eeModuleVersion, ASDDVersion.SUN_APPSERVER_7_0);
422
        return moduleHelper.getMinASVersion(
423
                j2eeModuleVersion, ASDDVersion.SUN_APPSERVER_7_0);
236
    }
424
    }
237
425
238
    private ASDDVersion computeMaxASVersion() {
426
    private ASDDVersion computeMaxASVersion() {
Lines 244-251 Link Here
244
                result = ASDDVersion.SUN_APPSERVER_10_1;
432
                result = ASDDVersion.SUN_APPSERVER_10_1;
245
            else
433
            else
246
                result = ASDDVersion.SUN_APPSERVER_10_0;
434
                result = ASDDVersion.SUN_APPSERVER_10_0;
247
            Logger.getLogger("glassfish-eecommon").log(Level.WARNING, NbBundle.getMessage(
435
            LOGGER.log(Level.WARNING,
248
                    GlassfishConfiguration.class, "ERR_UnidentifiedTargetServer", result.toString())); // NOI18N
436
                    NbBundle.getMessage(GlassfishConfiguration.class,
437
                    "ERR_UnidentifiedTargetServer", result.toString())); // NOI18N
249
        }
438
        }
250
        return result;
439
        return result;
251
    }
440
    }
Lines 353-362 Link Here
353
                    }
542
                    }
354
                } catch (IndexOutOfBoundsException ex) {
543
                } catch (IndexOutOfBoundsException ex) {
355
                    // Can't identify server install folder.
544
                    // Can't identify server install folder.
356
                    Logger.getLogger("glassfish-eecommon").log(Level.WARNING, NbBundle.getMessage(
545
                    LOGGER.log(Level.WARNING, NbBundle.getMessage(
357
                            GlassfishConfiguration.class, "ERR_NoServerInstallLocation", instance)); // NOI18N
546
                            GlassfishConfiguration.class, "ERR_NoServerInstallLocation", instance)); // NOI18N
358
                } catch (NullPointerException ex) {
547
                } catch (NullPointerException ex) {
359
                    Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
548
                    LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
360
                }
549
                }
361
            }
550
            }
362
        } else if ("SUNWebserver7".equals(serverType)) {
551
        } else if ("SUNWebserver7".equals(serverType)) {
Lines 634-645 Link Here
634
                    }
823
                    }
635
                }
824
                }
636
            } catch (IOException ex) {
825
            } catch (IOException ex) {
637
                Logger.getLogger("glassfish-eecommon").log(Level.WARNING, ex.getLocalizedMessage(), ex);
826
                LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
638
                String defaultMessage = " retrieving context-root from sun-web.xml";
827
                String defaultMessage = " retrieving context-root from sun-web.xml";
639
                displayError(ex, defaultMessage);
828
                displayError(ex, defaultMessage);
640
            }
829
            }
641
        } else {
830
        } else {
642
            Logger.getLogger("glassfish-eecommon").log(Level.WARNING,
831
            LOGGER.log(Level.WARNING,
643
                    "GlassfishConfiguration.getContextRoot() invoked on incorrect module type: {0}",
832
                    "GlassfishConfiguration.getContextRoot() invoked on incorrect module type: {0}",
644
                    module.getType());
833
                    module.getType());
645
        }
834
        }
Lines 671-681 Link Here
671
                                        }
860
                                        }
672
                                    }
861
                                    }
673
                                } catch (IOException ex) {
862
                                } catch (IOException ex) {
674
                                    Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
863
                                    LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
675
                                    String defaultMessage = " trying set context-root in sun-web.xml";
864
                                    String defaultMessage = " trying set context-root in sun-web.xml";
676
                                    displayError(ex, defaultMessage);
865
                                    displayError(ex, defaultMessage);
677
                                } catch (Exception ex) {
866
                                } catch (Exception ex) {
678
                                    Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
867
                                    LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
679
                                    String defaultMessage = " trying set context-root in sun-web.xml";
868
                                    String defaultMessage = " trying set context-root in sun-web.xml";
680
                                    displayError(ex, defaultMessage);
869
                                    displayError(ex, defaultMessage);
681
                                }
870
                                }
Lines 703-713 Link Here
703
                                    }
892
                                    }
704
                                }
893
                                }
705
                            } catch (IOException ex) {
894
                            } catch (IOException ex) {
706
                                Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
895
                                LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
707
                                String defaultMessage = " trying set context-root in sun-web.xml";
896
                                String defaultMessage = " trying set context-root in sun-web.xml";
708
                                displayError(ex, defaultMessage);
897
                                displayError(ex, defaultMessage);
709
                            } catch (Exception ex) {
898
                            } catch (Exception ex) {
710
                                Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
899
                                LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
711
                                String defaultMessage = " trying set context-root in sun-web.xml";
900
                                String defaultMessage = " trying set context-root in sun-web.xml";
712
                                displayError(ex, defaultMessage);
901
                                displayError(ex, defaultMessage);
713
                            }
902
                            }
Lines 715-721 Link Here
715
                    });
904
                    });
716
                }
905
                }
717
            } else {
906
            } else {
718
                Logger.getLogger("glassfish-eecommon").log(Level.WARNING,  // NOI18N
907
                LOGGER.log(Level.WARNING,  // NOI18N
719
                        "GlassfishConfiguration.setContextRoot() invoked on incorrect module type: {0}",  // NOI18N
908
                        "GlassfishConfiguration.setContextRoot() invoked on incorrect module type: {0}",  // NOI18N
720
                        module.getType());
909
                        module.getType());
721
            }
910
            }
Lines 988-994 Link Here
988
                return;
1177
                return;
989
            }
1178
            }
990
        } catch(NumberFormatException ex) {
1179
        } catch(NumberFormatException ex) {
991
            Logger.getLogger("glassfish-eecommon").log(Level.WARNING, ex.getLocalizedMessage(), ex);
1180
            LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
992
        }
1181
        }
993
1182
994
        try {
1183
        try {
Lines 1049-1055 Link Here
1049
                return;
1238
                return;
1050
            }
1239
            }
1051
        } catch(NumberFormatException ex) {
1240
        } catch(NumberFormatException ex) {
1052
            Logger.getLogger("glassfish-eecommon").log(Level.WARNING, ex.getLocalizedMessage(), ex);
1241
            LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
1053
        }
1242
        }
1054
1243
1055
        try {
1244
        try {
Lines 1384-1390 Link Here
1384
                    rootDD.write(outputStream);
1573
                    rootDD.write(outputStream);
1385
                }
1574
                }
1386
            } else {
1575
            } else {
1387
                Logger.getLogger("glassfish-eecommon").log(Level.WARNING,
1576
                LOGGER.log(Level.WARNING,
1388
                        "Deployment plan not supported in GlassfishConfiguration.save()");
1577
                        "Deployment plan not supported in GlassfishConfiguration.save()");
1389
            }
1578
            }
1390
        } catch(Exception ex) {
1579
        } catch(Exception ex) {
Lines 1480-1486 Link Here
1480
        // writing the changed descriptor to disk.
1669
        // writing the changed descriptor to disk.
1481
        // !PW FIXME notify user
1670
        // !PW FIXME notify user
1482
        // RR = could do handleEventRelatedException(ex) instead
1671
        // RR = could do handleEventRelatedException(ex) instead
1483
        Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
1672
        LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
1484
    }
1673
    }
1485
1674
1486
    protected void handleEventRelatedException(Exception ex) {
1675
    protected void handleEventRelatedException(Exception ex) {
Lines 1488-1494 Link Here
1488
        // must trap it here so it doesn't cause trouble upstream.
1677
        // must trap it here so it doesn't cause trouble upstream.
1489
        // We handle it the same as above for now.
1678
        // We handle it the same as above for now.
1490
        // !PW FIXME should we notify here, or just log?
1679
        // !PW FIXME should we notify here, or just log?
1491
        Logger.getLogger("glassfish-eecommon").log(Level.INFO, ex.getLocalizedMessage(), ex);
1680
        LOGGER.log(Level.INFO, ex.getLocalizedMessage(), ex);
1492
    }
1681
    }
1493
1682
1494
    // ------------------------------------------------------------------------
1683
    // ------------------------------------------------------------------------
(-)a/glassfish.eecommon/src/org/netbeans/modules/glassfish/eecommon/api/config/J2eeModuleHelper.java (-9 / +11 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2010-2013 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2010-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 57-77 Link Here
57
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
58
58
59
/**
59
/**
60
 *
60
 * Java EE module helper.
61
 * @author Peter Williams
61
 * <p/>
62
 * @author Peter Williams, Tomas Kraus
62
 */
63
 */
63
public abstract class J2eeModuleHelper {
64
public abstract class J2eeModuleHelper {
64
65
65
    /** Web application meta data directory. */
66
    /** Web application meta data directory. */
66
    public static final String WEB_INF = "WEB-INF";
67
    public static final String WEB_INF = JavaEEModule.WEB_INF;
67
68
68
    /** GlassFish specific meta data file for version 1 and 2. */
69
    /** GlassFish specific meta data file for version since version 3.1. */
70
    public static final String GF_WEB_XML_V2
71
            = WEB_INF + File.separatorChar + GlassfishConfiguration.RESOURCE_FILES[0];
72
73
    /** GlassFish specific meta data file for version 1, 2 and 3.0. */
69
    public static final String GF_WEB_XML_V1
74
    public static final String GF_WEB_XML_V1
70
            = WEB_INF + File.separatorChar + "sun-web.xml";
75
            = WEB_INF + File.separatorChar + GlassfishConfiguration.RESOURCE_FILES[1];
71
    
76
    
72
    /** GlassFish specific meta data file for version 3 and 4. */
73
    public static final String GF_WEB_XML_V2
74
            = WEB_INF + File.separatorChar + "glassfish-web.xml";
75
77
76
    private static final Map<Object, J2eeModuleHelper> helperMap;
78
    private static final Map<Object, J2eeModuleHelper> helperMap;
77
    private static final Map<Object, J2eeModuleHelper> gfhelperMap;
79
    private static final Map<Object, J2eeModuleHelper> gfhelperMap;
(-)3a3c32bf146f (+185 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.eecommon.api.config;
43
44
import java.util.HashMap;
45
import java.util.Map;
46
import java.util.logging.Logger;
47
import javax.enterprise.deploy.shared.ModuleType;
48
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
49
50
// This is J2eeModule.Type rewritten as Enum. I could not modify original class
51
// because it's API.
52
/**
53
 * Java EE module types.
54
 * <p/>
55
 * @author Tomas Kraus
56
 */
57
public enum JavaEEModule {
58
    
59
    ////////////////////////////////////////////////////////////////////////////
60
    // Enum values                                                            //
61
    ////////////////////////////////////////////////////////////////////////////
62
63
    /** Client application archive. */
64
    CAR(ModuleType.CAR),
65
    /** Enterprise application archive */
66
    EAR(ModuleType.EAR),
67
    /** Enterprise Java bean archive. */
68
    EJB(ModuleType.EJB),
69
    /** Connector archive. */
70
    RAR(ModuleType.RAR),
71
    /** Web application archive. */
72
    WAR(ModuleType.WAR);
73
74
    ////////////////////////////////////////////////////////////////////////////
75
    // Class attributes                                                       //
76
    ////////////////////////////////////////////////////////////////////////////
77
78
    /** GlassFish Java EE common module Logger. */
79
    private static final Logger LOGGER = Logger.getLogger("glassfish-eecommon");
80
81
    /** JavaEEModule version enumeration length. */
82
    public static final int length = JavaEEModule.values().length;
83
84
    /** Name of web application configuration directory. */
85
    public static final String WEB_INF = "WEB-INF";
86
87
    /** Name of java archive manifest directory. */
88
    public static final String META_INF = "META-INF";
89
90
    /** {@link J2eeModule.Type} to {@link JavaEEModule} conversion map. */
91
    private static final Map<J2eeModule.Type, JavaEEModule> j2eeModuleTypeToValue
92
            = new HashMap<J2eeModule.Type, JavaEEModule>(2*length);
93
94
    // Initialize J2eeModule.Type to JavaEEModule conversion map.
95
    static {
96
        j2eeModuleTypeToValue.put(J2eeModule.Type.CAR, CAR);
97
        j2eeModuleTypeToValue.put(J2eeModule.Type.EAR, EAR);
98
        j2eeModuleTypeToValue.put(J2eeModule.Type.EJB, EJB);
99
        j2eeModuleTypeToValue.put(J2eeModule.Type.RAR, RAR);
100
        j2eeModuleTypeToValue.put(J2eeModule.Type.WAR, WAR);
101
    }
102
103
    ////////////////////////////////////////////////////////////////////////////
104
    // Static methods                                                         //
105
    ////////////////////////////////////////////////////////////////////////////
106
107
   /**
108
     * Get Java EE module configuration directory (e.g. {@code "META-INF"}).
109
     * This is just {@link J2eeModule.Type} shortcut.
110
     * <p/>
111
     * @param type {@link J2eeModule.Type} instance of Java EE module type.
112
     * @return Java EE module configuration directory for known Java EE
113
     *         module type or {@code null} when provided Java EE module type
114
     *         is not known.
115
     */
116
    public static final String getConfigDir(J2eeModule.Type type) {
117
        JavaEEModule configDir = JavaEEModule.toValue(type);
118
        return type != null ? configDir.getConfigDir() : null;
119
    }
120
121
    /**
122
     * Convert {@link J2eeModule.Type} to {@link JavaEEModule}.
123
     * <p/>
124
     * @param type {@link ModuleType} value to be converted.
125
     * @return {@link J2eeModule.Type} value corresponding to provided
126
     *         {@link ModuleType} value.
127
     */
128
    @SuppressWarnings("deprecation")
129
    public static JavaEEModule toValue(final J2eeModule.Type type) {
130
        return j2eeModuleTypeToValue.get(type);
131
    }
132
133
    ////////////////////////////////////////////////////////////////////////////
134
    // Instance attributes                                                    //
135
    ////////////////////////////////////////////////////////////////////////////
136
137
    /** Java EE module type. */
138
    private final ModuleType moduleType;
139
140
    ////////////////////////////////////////////////////////////////////////////
141
    // Constructors                                                           //
142
    ////////////////////////////////////////////////////////////////////////////
143
144
    /**
145
     * Creates an instance of Java EE module type.
146
     * <p/>
147
     * @param moduleType Java EE module type.
148
     */
149
    private JavaEEModule(final ModuleType moduleType) {
150
        this.moduleType = moduleType;
151
    }
152
153
    ////////////////////////////////////////////////////////////////////////////
154
    // Methods                                                                //
155
    ////////////////////////////////////////////////////////////////////////////
156
157
    /**
158
     * Get stored {@link ModuleType} value.
159
     * <p/>
160
     * @return Stored {@link ModuleType} value.
161
     */
162
    private ModuleType getModuleType() {
163
        return moduleType;
164
    }
165
166
    /**
167
     * Get Java EE module configuration directory (e.g. {@code "META-INF"}).
168
     * <p/>
169
     * @return Java EE module configuration directory.
170
     */
171
    public String getConfigDir() {
172
        switch (this) {
173
            case CAR:
174
            case EAR:
175
            case EJB:
176
            case RAR:
177
                return META_INF;
178
            case WAR:
179
                return WEB_INF;
180
            default:
181
                throw new IllegalArgumentException("Unknown Java EE module type.");
182
        }
183
    }
184
185
}
(-)3a3c32bf146f (+138 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.eecommon.api.config;
43
44
import java.beans.PropertyChangeListener;
45
import java.io.File;
46
import java.util.Collections;
47
import java.util.Iterator;
48
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
49
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation2;
50
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
51
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
53
54
/**
55
 * Java EE module for GlassFish features tests.
56
 * <p/>
57
 * @author Tomas Kraus
58
 */
59
public class GFTestEEModuleImpl implements J2eeModuleImplementation2 {
60
    
61
    private final FileObject appRoot;
62
    private final File srcDir;
63
    private final File configDir;
64
    private final J2eeModule.Type moduleType;
65
    private final String moduleVersion;
66
67
    /** Creates a new instance of TestJ2eeModule
68
     * @param appRoot Application root directory.
69
     * @param moduleType Java EE module type.
70
     * @param moduleVersion Java EE version.
71
     */
72
    public GFTestEEModuleImpl(
73
            final FileObject appRoot, final J2eeModule.Type moduleType,
74
            final String moduleVersion
75
    ) {
76
        this.appRoot = appRoot;
77
        this.srcDir = new File(FileUtil.toFile(appRoot), "src");
78
        this.configDir = new File(srcDir, "conf");
79
        this.moduleType = moduleType;
80
        this.moduleVersion = moduleVersion;
81
    }
82
83
    @Override
84
    public FileObject getArchive() {
85
        return null;
86
    }
87
    
88
    @Override
89
    public Iterator<J2eeModule.RootedEntry> getArchiveContents() {
90
        return Collections.<J2eeModule.RootedEntry>emptySet().iterator();
91
    }
92
    
93
    @Override
94
    public FileObject getContentDirectory() {
95
        return appRoot;
96
    }
97
    
98
    @Override
99
    public J2eeModule.Type getModuleType() {
100
        return moduleType;
101
    }
102
    
103
    @Override
104
    public String getModuleVersion() {
105
        return moduleVersion;
106
    }
107
    
108
    @Override
109
    public String getUrl() {
110
        throw new UnsupportedOperationException("Not implemented.");
111
    }
112
    
113
    @Override
114
    public File getResourceDirectory() {
115
        return new File(FileUtil.toFile(appRoot), "setup");
116
    }
117
118
    @Override
119
    public File getDeploymentConfigurationFile(String name) {
120
        return new File(configDir, name);
121
    }
122
123
    @Override
124
    public void addPropertyChangeListener(PropertyChangeListener listener) {
125
        throw new UnsupportedOperationException("Not implemented.");
126
    }
127
128
    @Override
129
    public void removePropertyChangeListener(PropertyChangeListener listener) {
130
        throw new UnsupportedOperationException("Not implemented.");
131
    }
132
    
133
    @Override
134
    public <T> MetadataModel<T> getMetadataModel(Class<T> type) {
135
        throw new UnsupportedOperationException("Not implemented.");
136
    }
137
138
}
(-)3a3c32bf146f (+304 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.eecommon.api.config;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.lang.reflect.InvocationTargetException;
47
import java.lang.reflect.Method;
48
import java.util.HashSet;
49
import java.util.Set;
50
import org.junit.After;
51
import org.junit.AfterClass;
52
import org.junit.Before;
53
import org.junit.BeforeClass;
54
import org.junit.Test;
55
import org.netbeans.api.j2ee.core.Profile;
56
import org.netbeans.junit.NbTestCase;
57
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
58
import org.netbeans.modules.glassfish.tooling.utils.OsUtils;
59
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
60
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleFactory;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileUtil;
63
64
/**
65
 * GlassFish Java EE server configuration API support tests.
66
 * <p/>
67
 * @author Tomas Kraus
68
 */
69
public class GlassfishConfigurationTest extends NbTestCase {
70
    
71
    private GFTestEEModuleImpl moduleImplCar;
72
    private J2eeModule moduleCar;
73
    private GFTestEEModuleImpl moduleImplEjb;
74
    private J2eeModule moduleEjb;
75
    private GFTestEEModuleImpl moduleImplEar;
76
    private J2eeModule moduleEar;
77
    private GFTestEEModuleImpl moduleImplWar;
78
    private J2eeModule moduleWar;
79
    private GFTestEEModuleImpl moduleImplRar;
80
    private J2eeModule moduleRar;
81
82
    public GlassfishConfigurationTest(final String testName) {
83
        super(testName);
84
    }
85
86
   @BeforeClass
87
    public static void setUpClass() throws Exception {
88
    }
89
90
    @AfterClass
91
    public static void tearDownClass() throws Exception {
92
    }
93
94
    @Before
95
    @Override
96
    public void setUp() throws Exception {
97
        final File dataDir = getDataDir();
98
        final File rootFolder = new File(dataDir, "gfsample");
99
        rootFolder.mkdirs();
100
        final FileObject rootFolderFO = FileUtil.toFileObject(rootFolder);
101
        moduleImplCar = new GFTestEEModuleImpl(
102
                rootFolderFO, J2eeModule.Type.CAR, Profile.JAVA_EE_7_FULL.toPropertiesString());
103
        moduleCar = J2eeModuleFactory.createJ2eeModule(moduleImplCar);
104
        moduleImplEjb = new GFTestEEModuleImpl(
105
                rootFolderFO, J2eeModule.Type.EJB, Profile.JAVA_EE_7_FULL.toPropertiesString());
106
        moduleEjb = J2eeModuleFactory.createJ2eeModule(moduleImplEjb);
107
        moduleImplEar = new GFTestEEModuleImpl(
108
                rootFolderFO, J2eeModule.Type.EAR, Profile.JAVA_EE_7_FULL.toPropertiesString());
109
        moduleEar = J2eeModuleFactory.createJ2eeModule(moduleImplEar);
110
        moduleImplRar = new GFTestEEModuleImpl(
111
                rootFolderFO, J2eeModule.Type.RAR, Profile.JAVA_EE_7_FULL.toPropertiesString());
112
        moduleRar = J2eeModuleFactory.createJ2eeModule(moduleImplRar);
113
        moduleImplWar = new GFTestEEModuleImpl(
114
                rootFolderFO, J2eeModule.Type.WAR, Profile.JAVA_EE_7_WEB.toPropertiesString());
115
        moduleWar = J2eeModuleFactory.createJ2eeModule(moduleImplWar);
116
    }
117
118
    @After
119
    @Override
120
    public void tearDown() {
121
        // Pass everything to GC.
122
        moduleImplCar = null;
123
        moduleCar = null;
124
        moduleImplEjb = null;
125
        moduleEjb = null;
126
        moduleImplEar = null;
127
        moduleEar = null;
128
        moduleImplRar = null;
129
        moduleRar = null;
130
        moduleImplWar = null;
131
        moduleWar = null;
132
    }
133
134
    /**
135
     * Test Java EE module directory structure for resource file.
136
     * @throws NoSuchMethodException when there is a problem with reflection.
137
     * @throws IllegalAccessException when there is a problem with reflection.
138
     * @throws IllegalArgumentException when there is a problem with reflection.
139
     * @throws InvocationTargetException  when there is a problem with reflection.
140
     */
141
    @Test
142
    public void testResourceFilePath()
143
            throws NoSuchMethodException, IllegalAccessException,
144
            IllegalArgumentException, InvocationTargetException {
145
        final Method resourceFilePath = GlassfishConfiguration.class.getDeclaredMethod(
146
                "resourceFilePath", J2eeModule.class, String.class);
147
        resourceFilePath.setAccessible(true);
148
        
149
        final String pathFragment = "myDirectory";
150
        final String verifyConfigDirCar = OsUtils.joinPaths(JavaEEModule.META_INF, pathFragment);
151
        final String verifyConfigDirEjb = OsUtils.joinPaths(JavaEEModule.META_INF, pathFragment);
152
        final String verifyConfigDirEar = OsUtils.joinPaths(JavaEEModule.META_INF, pathFragment);
153
        final String verifyConfigDirRar = OsUtils.joinPaths(JavaEEModule.META_INF, pathFragment);
154
        final String verifyConfigDirWar = OsUtils.joinPaths(JavaEEModule.WEB_INF, pathFragment);
155
        final String configDirCar = (String)resourceFilePath.invoke(null, moduleCar, pathFragment);
156
        final String configDirEjb = (String)resourceFilePath.invoke(null, moduleEjb, pathFragment);
157
        final String configDirEar = (String)resourceFilePath.invoke(null, moduleEar, pathFragment);
158
        final String configDirRar = (String)resourceFilePath.invoke(null, moduleRar, pathFragment);
159
        final String configDirWar = (String)resourceFilePath.invoke(null, moduleWar, pathFragment);
160
        assertEquals("Expected resource file path for CAR is: " + verifyConfigDirCar,
161
                verifyConfigDirCar, configDirCar);
162
        assertEquals("Expected resource file path for EJB is: " + verifyConfigDirEjb,
163
                verifyConfigDirEjb, configDirEjb);
164
        assertEquals("Expected resource file path for EAR is: " + verifyConfigDirEar,
165
                verifyConfigDirEar, configDirEar);
166
        assertEquals("Expected resource file path for RAR is: " + verifyConfigDirRar,
167
                verifyConfigDirRar, configDirRar);
168
        assertEquals("Expected resource file path for WAR is: " + verifyConfigDirWar,
169
                verifyConfigDirWar, configDirWar);
170
    }
171
172
    /**
173
     * Test new GlassFish resources file name generation depending on passed {@link GlassFishVersion}.
174
     * Expected values are:<ul>
175
     * <li>PREFIX/src/conf/META_INF/sun-resources.xml for CAR, EAR, EJB and RAR
176
     *     on GlassFish older than 3.1</li\>
177
     * <li>PREFIX/src/conf/META_INF/sun-resources.xml for CAR, EAR, EJB and RAR
178
     *     on GlassFish 3.1 and later</li\>
179
     * <li>PREFIX/src/conf/WEB_INF/sun-resources.xml for WAR on GlassFish older than 3.1</li\>
180
     * <li>PREFIX/src/conf/WEB_INF/sun-resources.xml for WAR on GlassFish 3.1 and later</li\></ul>
181
     */
182
    @Test 
183
    public void testGetNewResourceFile() {
184
        for (GlassFishVersion version : GlassFishVersion.values()) {
185
            final File resourceFileCar = GlassfishConfiguration.getNewResourceFile(moduleCar, version);
186
            final File resourceFileEar = GlassfishConfiguration.getNewResourceFile(moduleEar, version);
187
            final File resourceFileEjb = GlassfishConfiguration.getNewResourceFile(moduleEjb, version);
188
            final File resourceFileRar = GlassfishConfiguration.getNewResourceFile(moduleRar, version);
189
            final File resourceFileWar = GlassfishConfiguration.getNewResourceFile(moduleWar, version);
190
            final File verifyPrefixCar = moduleCar.getDeploymentConfigurationFile(
191
                    JavaEEModule.getConfigDir(moduleCar.getType()));
192
            final File verifyPrefixEar = moduleEar.getDeploymentConfigurationFile(
193
                    JavaEEModule.getConfigDir(moduleEar.getType()));
194
            final File verifyPrefixEjb = moduleEjb.getDeploymentConfigurationFile(
195
                    JavaEEModule.getConfigDir(moduleEjb.getType()));
196
            final File verifyPrefixRar = moduleRar.getDeploymentConfigurationFile(
197
                    JavaEEModule.getConfigDir(moduleRar.getType()));
198
            final File verifyPrefixWar = moduleWar.getDeploymentConfigurationFile(
199
                    JavaEEModule.getConfigDir(moduleWar.getType()));
200
            final String fileName = GlassFishVersion.lt(version, GlassFishVersion.GF_3_1)
201
                    ? "sun-resources.xml"
202
                    : "glassfish-resources.xml";
203
            final File verifyFileCar = new File(verifyPrefixCar, fileName);
204
            final File verifyFileEar = new File(verifyPrefixEar, fileName);
205
            final File verifyFileEjb = new File(verifyPrefixEjb, fileName);
206
            final File verifyFileRar = new File(verifyPrefixRar, fileName);
207
            final File verifyFileWar = new File(verifyPrefixWar, fileName);
208
            assertTrue("New resource file for " + version.toString() + " CAR: " + verifyFileCar.toString(),
209
                    verifyFileCar.equals(resourceFileCar));
210
            assertTrue("New resource file for " + version.toString() + " EAR: " + verifyFileEar.toString(),
211
                    verifyFileEar.equals(resourceFileEar));
212
            assertTrue("New resource file for " + version.toString() + " EJB: " + verifyFileEjb.toString(),
213
                    verifyFileEjb.equals(resourceFileEjb));
214
            assertTrue("New resource file for " + version.toString() + " RAR: " + verifyFileRar.toString(),
215
                    verifyFileRar.equals(resourceFileRar));
216
            assertTrue("New resource file for " + version.toString() + " WAR: " + verifyFileWar.toString(),
217
                    verifyFileWar.equals(resourceFileWar));
218
        }
219
    }
220
221
222
    /**
223
     * Verify that proper resource file from Java EE module is returned.
224
     * Both {@code sun-resources.xml} and {@code glassfish-resources.xml} are available
225
     * in Java EE module configuration directory on the disk.
226
     * Expected values are:<ul>
227
     * <li>PREFIX/src/conf/META_INF/sun-resources.xml for CAR, EAR, EJB and RAR
228
     *     on GlassFish older than 3.1</li\>
229
     * <li>PREFIX/src/conf/META_INF/sun-resources.xml for CAR, EAR, EJB and RAR
230
     *     on GlassFish 3.1 and later</li\>
231
     * <li>PREFIX/src/conf/WEB_INF/sun-resources.xml for WAR on GlassFish older than 3.1</li\>
232
     * <li>PREFIX/src/conf/WEB_INF/sun-resources.xml for WAR on GlassFish 3.1 and later</li\></ul>
233
     */
234
    @Test 
235
    public void testGetExistingResourceFile() throws IOException {
236
        final File prefixCar = moduleCar.getDeploymentConfigurationFile(
237
                JavaEEModule.getConfigDir(moduleCar.getType()));
238
        final File prefixEar = moduleEar.getDeploymentConfigurationFile(
239
                JavaEEModule.getConfigDir(moduleEar.getType()));
240
        final File prefixEjb = moduleEjb.getDeploymentConfigurationFile(
241
                JavaEEModule.getConfigDir(moduleEjb.getType()));
242
        final File prefixRar = moduleRar.getDeploymentConfigurationFile(
243
                JavaEEModule.getConfigDir(moduleRar.getType()));
244
        final File prefixWar = moduleWar.getDeploymentConfigurationFile(
245
                JavaEEModule.getConfigDir(moduleWar.getType()));
246
        final Set<File> prefixes = new HashSet<File>(5);
247
        prefixes.add(prefixCar);
248
        prefixes.add(prefixEar);
249
        prefixes.add(prefixEjb);
250
        prefixes.add(prefixRar);
251
        prefixes.add(prefixWar);
252
        // Create all resource files (they are empty but it's enough for this test).
253
        for (File prefix : prefixes) {
254
            final File sunResource = new File(prefix, "sun-resources.xml");
255
            final File gfResource = new File(prefix, "glassfish-resources.xml");
256
            prefix.mkdirs();
257
            sunResource.createNewFile();
258
            gfResource.createNewFile();
259
        }
260
        for (GlassFishVersion version : GlassFishVersion.values()) {
261
            File resourcesCar = GlassfishConfiguration.getExistingResourceFile(moduleCar, version);
262
            File resourcesEar = GlassfishConfiguration.getExistingResourceFile(moduleEar, version);
263
            File resourcesEjb = GlassfishConfiguration.getExistingResourceFile(moduleEjb, version);
264
            File resourcesRar = GlassfishConfiguration.getExistingResourceFile(moduleRar, version);
265
            File resourcesWar = GlassfishConfiguration.getExistingResourceFile(moduleWar, version);
266
            final File verifyPrefixCar = moduleCar.getDeploymentConfigurationFile(
267
                    JavaEEModule.getConfigDir(moduleCar.getType()));
268
            final File verifyPrefixEar = moduleEar.getDeploymentConfigurationFile(
269
                    JavaEEModule.getConfigDir(moduleEar.getType()));
270
            final File verifyPrefixEjb = moduleEjb.getDeploymentConfigurationFile(
271
                    JavaEEModule.getConfigDir(moduleEjb.getType()));
272
            final File verifyPrefixRar = moduleRar.getDeploymentConfigurationFile(
273
                    JavaEEModule.getConfigDir(moduleRar.getType()));
274
            final File verifyPrefixWar = moduleWar.getDeploymentConfigurationFile(
275
                    JavaEEModule.getConfigDir(moduleWar.getType()));
276
            final String fileName = GlassFishVersion.lt(version, GlassFishVersion.GF_3_1)
277
                    ? "sun-resources.xml"
278
                    : "glassfish-resources.xml";
279
            final File verifyFileCar = new File(verifyPrefixCar, fileName);
280
            final File verifyFileEar = new File(verifyPrefixEar, fileName);
281
            final File verifyFileEjb = new File(verifyPrefixEjb, fileName);
282
            final File verifyFileRar = new File(verifyPrefixRar, fileName);
283
            final File verifyFileWar = new File(verifyPrefixWar, fileName);
284
            assertTrue("Existing resource file for " + version.toString() + " CAR: " + verifyFileCar.toString(),
285
                    verifyFileCar.equals(resourcesCar));
286
            assertTrue("Existing resource file for " + version.toString() + " EAR: " + verifyFileEar.toString(),
287
                    verifyFileEar.equals(resourcesEar));
288
            assertTrue("Existing resource file for " + version.toString() + " EJB: " + verifyFileEjb.toString(),
289
                    verifyFileEjb.equals(resourcesEjb));
290
            assertTrue("Existing resource file for " + version.toString() + " RAR: " + verifyFileRar.toString(),
291
                    verifyFileRar.equals(resourcesRar));
292
            assertTrue("Existing resource file for " + version.toString() + " WAR: " + verifyFileWar.toString(),
293
                    verifyFileWar.equals(resourcesWar));
294
        }
295
        // Delete all resource files.
296
        for (File prefix : prefixes) {
297
            final File sunResource = new File(prefix, "sun-resources.xml");
298
            final File gfResource = new File(prefix, "glassfish-resources.xml");
299
            sunResource.delete();
300
            gfResource.delete();
301
        }
302
    }
303
304
}
(-)3a3c32bf146f (+152 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.javaee;
43
44
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.modules.glassfish.common.GlassfishInstance;
46
import org.netbeans.modules.glassfish.common.GlassfishInstanceProvider;
47
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
48
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
49
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
50
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
51
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
52
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfigurationFactory2;
53
54
/**
55
 * Abstract factory to construct Java EE server configuration API support object.
56
 * <p/>
57
 * @author Vince Kraemer, Tomas Kraus
58
 */
59
abstract class AbstractHk2ConfigurationFactory implements ModuleConfigurationFactory2 {
60
    /** Deployment manager. */
61
    private final Hk2DeploymentManager hk2dm;
62
63
    /**
64
     * Creates a new instance of {@link GlassFishConfigurationFactory
65
     */
66
    AbstractHk2ConfigurationFactory(final Hk2DeploymentManager hk2dm) {
67
        this.hk2dm = hk2dm;
68
    }
69
70
    /**
71
     * Constructs proper module configuration object without having
72
     * GlassFish server.
73
     * <p/>
74
     * Proper configuration object is selected depending on GlassFish specific
75
     * web application meta data file (<code>WEB-INFsun-web.xml</code>
76
     * or <code>WEB-INF/glassfish-web.xml</code>) existence.
77
     * GlassFish version 3.0 is passed to old module configuration object
78
     * to rely on {@code sun-resources.xml} resource file.
79
     * GlassFish version 3.1 is passed to new module configuration object
80
     * to rely on {@code glassfish-resources.xml} resource file.
81
     * <p/>
82
     * @param module Java EE module.
83
     * @return Module configuration object.
84
     * @throws ConfigurationException if there is a problem with the server-specific
85
     *         configuration.
86
     */
87
    @Override
88
    public ModuleConfiguration create(final J2eeModule module)
89
            throws ConfigurationException {
90
        ModuleConfiguration retVal = null;
91
        try {
92
            if (J2eeModuleHelper.isGlassFishWeb(module)) {
93
                retVal = new ModuleConfigurationImpl(
94
                        module, new Three1Configuration(module, GlassFishVersion.GF_3_1), hk2dm);
95
            } else {
96
                retVal = new ModuleConfigurationImpl(
97
                        module, new Hk2Configuration(module, GlassFishVersion.GF_3), hk2dm);
98
            }
99
        } catch (ConfigurationException ce) {
100
            throw ce;
101
        } catch (Exception ex) {
102
            throw new ConfigurationException(module.toString(), ex);
103
        }
104
        return retVal;
105
    }
106
107
    /**
108
     * Constructs proper module configuration object depending on
109
     * GlassFish server.
110
     * <p/>
111
     * Proper configuration object is selected depending on GlassFish version.
112
     * Old module configuration object is created for server before version 3.1
113
     * and new module configuration object for server version 3.1 and later.
114
     * <p/>
115
     * @param module      Java EE module.
116
     * @param instanceUrl GlassFish server internal URL.
117
     * @return Module configuration object.
118
     * @throws ConfigurationException if there is a problem with the server-specific
119
     *         configuration.
120
     */
121
    @Override
122
    @SuppressWarnings("UseSpecificCatch")
123
    public ModuleConfiguration create(final @NonNull J2eeModule module,
124
            final @NonNull String instanceUrl) throws ConfigurationException {
125
        ModuleConfiguration retVal = null;
126
        final GlassfishInstance instance
127
                = GlassfishInstanceProvider.getProvider()
128
                .getGlassfishInstance(instanceUrl);
129
        final GlassFishVersion version = instance != null
130
                ? instance.getVersion() : null;
131
        try {
132
            final Hk2DeploymentManager dm = hk2dm != null
133
                    ? hk2dm
134
                    : (Hk2DeploymentManager) Hk2DeploymentFactory.createEe6()
135
                            .getDisconnectedDeploymentManager(instanceUrl);
136
            if (version != null
137
                    && GlassFishVersion.ge(version, GlassFishVersion.GF_3_1)) {
138
                retVal = new ModuleConfigurationImpl(
139
                        module, new Three1Configuration(module, version), dm);
140
            } else {
141
                retVal = new ModuleConfigurationImpl(
142
                        module, new Hk2Configuration(module, version), dm);
143
            }
144
        } catch (ConfigurationException ce) {
145
            throw ce;
146
        } catch (Exception ex) {
147
            throw new ConfigurationException(module.toString(), ex);
148
        }
149
        return retVal;
150
    }
151
152
}
(-)a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2Configuration.java (-23 / +44 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2011 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 1997-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 57-62 Link Here
57
import org.netbeans.modules.glassfish.eecommon.api.config.GlassfishConfiguration;
57
import org.netbeans.modules.glassfish.eecommon.api.config.GlassfishConfiguration;
58
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
58
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
59
import org.netbeans.modules.glassfish.javaee.db.Hk2DatasourceManager;
59
import org.netbeans.modules.glassfish.javaee.db.Hk2DatasourceManager;
60
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
60
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
61
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
61
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
62
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
62
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
63
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
Lines 65-82 Link Here
65
import org.openide.util.NbBundle;
66
import org.openide.util.NbBundle;
66
67
67
/**
68
/**
68
 * 
69
 * Java EE server configuration API support for GlassFish servers before 3.1.
69
 * @author Ludovic Champenois
70
 * Covers GlassFish servers before 3.1. Old {@code sun-resources.xml} files are used.
70
 * @author Peter Williams
71
 * <p/>
72
 * @author Ludovic Champenois, Peter Williams, Tomas Kraus
71
 */
73
 */
72
public class Hk2Configuration extends GlassfishConfiguration implements DeploymentConfiguration {
74
public class Hk2Configuration extends GlassfishConfiguration implements DeploymentConfiguration {
73
75
74
    public Hk2Configuration(J2eeModule module) throws ConfigurationException {
76
    /**
75
        super(module);
77
     * Creates an instance of Java EE server configuration API support
78
     * for GlassFish servers before 3.1.
79
     * <p/>
80
     * @param module  Java EE module (project).
81
     * @param version GlassFish server version.
82
     * @throws ConfigurationException when there is a problem with Java EE server
83
     *         configuration initialization.
84
     */
85
    public Hk2Configuration(
86
            final J2eeModule module, final GlassFishVersion version
87
    ) throws ConfigurationException {
88
        super(module, version);
76
    }
89
    }
77
90
78
    public Hk2Configuration(J2eeModule module, J2eeModuleHelper jmh) throws ConfigurationException {
91
    /**
79
        super(module, jmh);
92
     * Creates an instance of Java EE server configuration API support
93
     * for GlassFish servers before 3.1 with existing {@link J2eeModuleHelper} instance.
94
     * <p/>
95
     * @param module       Java EE module (project).
96
     * @param moduleHelper Already existing {@link J2eeModuleHelper} instance.
97
     * @param version      GlassFish server version.
98
     * @throws ConfigurationException when there is a problem with Java EE server
99
     *         configuration initialization.
100
     */
101
    public Hk2Configuration(
102
            final J2eeModule module, final J2eeModuleHelper jmh,
103
            final GlassFishVersion version
104
    ) throws ConfigurationException {
105
        super(module, jmh, version);
80
    }
106
    }
81
107
82
    @Deprecated
108
    @Deprecated
Lines 88-95 Link Here
88
    // DatasourceConfiguration support
114
    // DatasourceConfiguration support
89
    // ------------------------------------------------------------------------
115
    // ------------------------------------------------------------------------
90
    @Override
116
    @Override
91
    public Set<Datasource> getDatasources() throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException {
117
    public Set<Datasource> getDatasources() throws ConfigurationException {
92
        return Hk2DatasourceManager.getDatasources(module.getResourceDirectory());
118
        return Hk2DatasourceManager.getDatasources(module, version);
93
    }
119
    }
94
120
95
    @Override
121
    @Override
Lines 98-122 Link Here
98
    }
124
    }
99
125
100
    @Override
126
    @Override
101
    public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) throws UnsupportedOperationException, org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException, DatasourceAlreadyExistsException {
127
    public Datasource createDatasource(
102
        File resourceDir = module.getResourceDirectory();
128
            final String jndiName, final String url, final String username,
103
        if (resourceDir == null) {
129
            final String password, final String driver
104
            // Unable to create JDBC data source for resource ref.
130
    ) throws UnsupportedOperationException, ConfigurationException, DatasourceAlreadyExistsException {
105
//            postResourceError(NbBundle.getMessage(ModuleConfigurationImpl.class,
131
        return Hk2DatasourceManager.createDataSource(
106
//                    "ERR_NoRefJdbcDataSource", jndiName)); // NOI18N
132
                jndiName, url, username, password, driver, module, version);
107
            Logger.getLogger("glassfish-javaee").log(Level.WARNING, "Null Resource Folder");
108
            throw new ConfigurationException(NbBundle.getMessage(
109
                    ModuleConfigurationImpl.class, "ERR_NoRefJdbcDataSource", jndiName)); // NOI18N
110
        }
111
112
        return Hk2DatasourceManager.createDataSource(jndiName, url, username, password, driver, resourceDir,"sun-resources");
113
    }
133
    }
114
134
115
    // ------------------------------------------------------------------------
135
    // ------------------------------------------------------------------------
116
    // MessageDestinationConfiguration support
136
    // MessageDestinationConfiguration support
117
    // ------------------------------------------------------------------------
137
    // ------------------------------------------------------------------------
118
    @Override
138
    @Override
119
    public Set<MessageDestination> getMessageDestinations() throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException {
139
    public Set<MessageDestination> getMessageDestinations()
140
            throws ConfigurationException {
120
        return Hk2MessageDestinationManager.getMessageDestinations(module.getResourceDirectory(),"sun-resources");
141
        return Hk2MessageDestinationManager.getMessageDestinations(module.getResourceDirectory(),"sun-resources");
121
    }
142
    }
122
143
(-)a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2ModuleConfigFactory.java (-88 / +7 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 1997-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 39-55 Link Here
39
 * 
39
 * 
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.glassfish.javaee;
42
package org.netbeans.modules.glassfish.javaee;
44
43
45
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.modules.glassfish.common.GlassfishInstance;
48
import org.netbeans.modules.glassfish.common.GlassfishInstanceProvider;
49
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
50
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
51
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
52
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
53
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfigurationFactory2;
44
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfigurationFactory2;
54
45
55
/**
46
/**
Lines 57-142 Link Here
57
 * <p/>
48
 * <p/>
58
 * @author Vince Kraemer, Tomas Kraus
49
 * @author Vince Kraemer, Tomas Kraus
59
 */
50
 */
60
public class Hk2ModuleConfigFactory implements ModuleConfigurationFactory2 {
51
public class Hk2ModuleConfigFactory extends AbstractHk2ConfigurationFactory
52
implements ModuleConfigurationFactory2 {
61
    
53
    
62
    /** Creates a new instance of Hk2ModuleConfigFactory */
54
    /**
55
     * Creates a new instance of {@link Hk2ModuleConfigFactory}
56
     */
63
    public Hk2ModuleConfigFactory() {
57
    public Hk2ModuleConfigFactory() {
58
        super(null);
64
    }
59
    }
65
60
66
    /**
67
     * Constructs proper module configuration object without having
68
     * GlassFish server.
69
     * <p/>
70
     * Proper configuration object is selected depending on GlassFish specific
71
     * web application meta data file (<code>WEB-INFsun-web.xml</code>
72
     * or <code>WEB-INF/glassfish-web.xml</code>) existence.
73
     * <p/>
74
     * @param module Java EE module.
75
     * @return Module configuration object.
76
     * @throws ConfigurationException if there is a problem with
77
     *         the server-specific configuration.
78
     */
79
    @Override
80
    public ModuleConfiguration create(final J2eeModule module)
81
            throws ConfigurationException {
82
        ModuleConfiguration retVal = null;
83
        try {
84
            if (J2eeModuleHelper.isGlassFishWeb(module)) {
85
                retVal = new ModuleConfigurationImpl(
86
                        module, new Three1Configuration(module), null);
87
            } else {
88
                retVal = new ModuleConfigurationImpl(
89
                        module, new Hk2Configuration(module), null);
90
            }
91
        } catch (ConfigurationException ce) {
92
            throw ce;
93
        } catch (Exception ex) {
94
            throw new ConfigurationException(module.toString(), ex);
95
        }
96
        return retVal;
97
    }
98
99
    /**
100
     * Constructs proper module configuration object depending on
101
     * GlassFish server.
102
     * <p/>
103
     * Proper configuration object is selected depending on GlassFish version.
104
     * Old module configuration object is created for server before version 3.1
105
     * and new module configuration object for server version 3.1 and later.
106
     * 
107
     * @param module Java EE module.
108
     * @param instanceUrl GlassFish server internal URL.
109
     * @return Module configuration object.
110
     * @throws ConfigurationException if there is a problem with
111
     *         the server-specific configuration.
112
     */
113
    @Override
114
    public ModuleConfiguration create(final @NonNull J2eeModule module,
115
            final @NonNull String instanceUrl) throws ConfigurationException {
116
        ModuleConfiguration retVal = null;
117
        GlassfishInstance instance
118
                = GlassfishInstanceProvider.getProvider()
119
                .getGlassfishInstance(instanceUrl);
120
        GlassFishVersion version = instance != null
121
                ? instance.getVersion() : null;
122
        try {
123
            Hk2DeploymentManager hk2Dm =
124
                    (Hk2DeploymentManager) Hk2DeploymentFactory.createEe6()
125
                    .getDisconnectedDeploymentManager(instanceUrl);
126
            if (version != null
127
                    && version.ordinal() >= GlassFishVersion.GF_3_1.ordinal()) {
128
                retVal = new ModuleConfigurationImpl(
129
                        module, new Three1Configuration(module), hk2Dm);
130
            } else {
131
                retVal = new ModuleConfigurationImpl(
132
                        module, new Hk2Configuration(module), hk2Dm);
133
            }
134
        } catch (ConfigurationException ce) {
135
            throw ce;
136
        } catch (Exception ex) {
137
            throw new ConfigurationException(module.toString(), ex);
138
        }
139
        return retVal;
140
    }
141
    
142
}
61
}
(-)a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Three1Configuration.java (-19 / +21 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2011 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 1997-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 57-62 Link Here
57
import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
57
import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
58
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
58
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
59
import org.netbeans.modules.glassfish.javaee.db.Hk2DatasourceManager;
59
import org.netbeans.modules.glassfish.javaee.db.Hk2DatasourceManager;
60
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
60
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
61
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
61
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
62
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
62
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
63
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
Lines 67-80 Link Here
67
import org.openide.util.NbBundle;
68
import org.openide.util.NbBundle;
68
69
69
/**
70
/**
70
 * 
71
 * Java EE server configuration API support for GlassFish servers 3.1 and later.
71
 * @author Ludovic Champenois
72
 * <p/>
72
 * @author Peter Williams
73
 * @author Ludovic Champenois, Peter Williams, Tomas Kraus
73
 */
74
 */
74
public class Three1Configuration extends Hk2Configuration implements DeploymentConfiguration {
75
public class Three1Configuration extends Hk2Configuration implements DeploymentConfiguration {
75
76
76
    public Three1Configuration(J2eeModule module) throws ConfigurationException {
77
    /**
77
        super(module, J2eeModuleHelper.getGlassfishDDModuleHelper(module.getType()));
78
     * Creates an instance of Java EE server configuration API support
79
     * for GlassFish servers 3.1 and later.
80
     * <p/>
81
     * @param module  Java EE module (project).
82
     * @param version GlassFish server version.
83
     * @throws ConfigurationException when there is a problem with Java EE server
84
     *         configuration initialization.
85
     */
86
    public Three1Configuration(
87
            final J2eeModule module, final GlassFishVersion version
88
    ) throws ConfigurationException {
89
        super(module, J2eeModuleHelper.getGlassfishDDModuleHelper(module.getType()), version);
78
    }
90
    }
79
91
80
    @Deprecated
92
    @Deprecated
Lines 87-93 Link Here
87
    // ------------------------------------------------------------------------
99
    // ------------------------------------------------------------------------
88
    @Override
100
    @Override
89
    public Set<Datasource> getDatasources() throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException {
101
    public Set<Datasource> getDatasources() throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException {
90
        return Hk2DatasourceManager.getDatasources(module.getResourceDirectory());
102
        return Hk2DatasourceManager.getDatasources(module, version);
91
    }
103
    }
92
104
93
    @Override
105
    @Override
Lines 97-114 Link Here
97
109
98
    @Override
110
    @Override
99
    public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) throws UnsupportedOperationException, org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException, DatasourceAlreadyExistsException {
111
    public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) throws UnsupportedOperationException, org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException, DatasourceAlreadyExistsException {
100
        File resourceDir = module.getResourceDirectory();
112
        return Hk2DatasourceManager.createDataSource(
101
        if (resourceDir == null) {
113
                jndiName, url, username, password, driver, module, version);
102
            // Unable to create JDBC data source for resource ref.
103
//            postResourceError(NbBundle.getMessage(ModuleConfigurationImpl.class,
104
//                    "ERR_NoRefJdbcDataSource", jndiName)); // NOI18N
105
            Logger.getLogger("glassfish-javaee").log(Level.WARNING,
106
                    "Resource Folder " + resourceDir + " does not exist.");
107
            throw new ConfigurationException(NbBundle.getMessage(
108
                    ModuleConfigurationImpl.class, "ERR_NoRefJdbcDataSource", jndiName)); // NOI18N
109
        }
110
111
        return Hk2DatasourceManager.createDataSource(jndiName, url, username, password, driver, resourceDir,"glassfish-resources");
112
    }
114
    }
113
115
114
    // ------------------------------------------------------------------------
116
    // ------------------------------------------------------------------------
(-)a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Three1ModuleConfigFactory.java (-28 / +15 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2011 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 1997-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 42-77 Link Here
42
42
43
package org.netbeans.modules.glassfish.javaee;
43
package org.netbeans.modules.glassfish.javaee;
44
44
45
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
45
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfigurationFactory2;
46
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
47
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
48
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfigurationFactory;
49
46
50
/**
47
/**
51
 *
48
 * Factory to construct proper module configuration object.
52
 * @author vbk
49
 * <p/>
50
 * @author Vince Kraemer, Tomas Kraus
53
 */
51
 */
54
public class Three1ModuleConfigFactory implements ModuleConfigurationFactory {
52
public class Three1ModuleConfigFactory extends AbstractHk2ConfigurationFactory
55
    private final Hk2DeploymentManager hk2Dm;
53
implements ModuleConfigurationFactory2 {
56
    
54
    
57
    /** Creates a new instance of Hk2ModuleConfigFactory */
55
    /**
58
    public Three1ModuleConfigFactory(Hk2DeploymentManager hk2Dm) {
56
     * Creates a new instance of {@link Three1ModuleConfigFactory}.
59
        this.hk2Dm = hk2Dm;
57
     * <p/>
58
     * @param hk2dm Deployment manager.
59
     */
60
    public Three1ModuleConfigFactory(final Hk2DeploymentManager hk2dm) {
61
        super(hk2dm);
60
    }
62
    }
61
    
63
62
    @Override
63
    public ModuleConfiguration create(J2eeModule module) throws ConfigurationException {
64
        ModuleConfiguration retVal = null;
65
        try {
66
            retVal = new ModuleConfigurationImpl(module, new Three1Configuration(module), hk2Dm);
67
        } catch (ConfigurationException ce) {
68
            throw ce;
69
        } catch (Exception ex) {
70
            ConfigurationException ce = new ConfigurationException(module.toString());
71
            ce.initCause(ex);
72
            throw ce;
73
        }
74
        return retVal;
75
    }
76
    
77
}
64
}
(-)a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/Hk2DatasourceManager.java (-192 / +161 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2008-2013 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2008-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 60-76 Link Here
60
import javax.xml.parsers.DocumentBuilder;
60
import javax.xml.parsers.DocumentBuilder;
61
import javax.xml.parsers.DocumentBuilderFactory;
61
import javax.xml.parsers.DocumentBuilderFactory;
62
import javax.xml.parsers.ParserConfigurationException;
62
import javax.xml.parsers.ParserConfigurationException;
63
import org.netbeans.modules.glassfish.common.GlassFishState;
64
import org.netbeans.modules.glassfish.common.parser.TreeParser;
65
import org.netbeans.modules.glassfish.eecommon.api.UrlData;
66
import org.netbeans.modules.glassfish.eecommon.api.config.GlassfishConfiguration;
67
import org.netbeans.modules.glassfish.javaee.Hk2DeploymentManager;
63
import org.netbeans.modules.glassfish.tooling.data.GlassFishServer;
68
import org.netbeans.modules.glassfish.tooling.data.GlassFishServer;
64
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
69
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
65
import org.netbeans.modules.glassfish.tooling.utils.OsUtils;
70
import org.netbeans.modules.glassfish.tooling.utils.OsUtils;
66
import org.netbeans.modules.glassfish.tooling.utils.ServerUtils;
71
import org.netbeans.modules.glassfish.tooling.utils.ServerUtils;
67
import org.netbeans.modules.glassfish.common.GlassFishState;
68
import org.netbeans.modules.glassfish.eecommon.api.UrlData;
69
import org.netbeans.modules.glassfish.javaee.*;
70
import org.netbeans.modules.glassfish.common.parser.TreeParser;
71
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
72
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
72
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
73
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
73
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
74
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
75
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
74
import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager;
76
import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager;
75
import org.netbeans.modules.j2ee.sun.dd.api.RootInterface;
77
import org.netbeans.modules.j2ee.sun.dd.api.RootInterface;
76
import org.openide.filesystems.FileLock;
78
import org.openide.filesystems.FileLock;
Lines 105-116 Link Here
105
            ServerUtils.GF_DOMAIN_CONFIG_DIR_NAME,
107
            ServerUtils.GF_DOMAIN_CONFIG_DIR_NAME,
106
            ServerUtils.GF_DOMAIN_CONFIG_FILE_NAME);
108
            ServerUtils.GF_DOMAIN_CONFIG_FILE_NAME);
107
    
109
    
108
    /** List of base file names containing server resources. */
109
    public static final String[] RESOURCE_FILES = {
110
        "glassfish-resources",
111
        "sun-resources"
112
    };
113
114
    ////////////////////////////////////////////////////////////////////////////
110
    ////////////////////////////////////////////////////////////////////////////
115
    // Instance attributes                                                    //
111
    // Instance attributes                                                    //
116
    ////////////////////////////////////////////////////////////////////////////
112
    ////////////////////////////////////////////////////////////////////////////
Lines 162-168 Link Here
162
        if (!server.isRemote() && null != domainsDir) {
158
        if (!server.isRemote() && null != domainsDir) {
163
            File domainXml = new File(domainsDir, domainName + File.separatorChar + DOMAIN_XML_PATH);
159
            File domainXml = new File(domainsDir, domainName + File.separatorChar + DOMAIN_XML_PATH);
164
            return readDatasources(
160
            return readDatasources(
165
                    domainXml, "/domain/", null, server.getVersion());
161
                    domainXml, "/domain/", server.getVersion());
166
        } else {
162
        } else {
167
            return Collections.EMPTY_SET;
163
            return Collections.EMPTY_SET;
168
        }
164
        }
Lines 170-176 Link Here
170
166
171
    /**
167
    /**
172
     * Deploys the given set of data sources.
168
     * Deploys the given set of data sources.
173
     *
169
     * <p/>
174
     * @param Set of datasources to deploy.
170
     * @param Set of datasources to deploy.
175
     * @throws ConfigurationException if there is some problem with data source
171
     * @throws ConfigurationException if there is some problem with data source
176
     *         configuration.
172
     *         configuration.
Lines 180-276 Link Here
180
    @Override
176
    @Override
181
    public void deployDatasources(Set<Datasource> datasources) 
177
    public void deployDatasources(Set<Datasource> datasources) 
182
            throws ConfigurationException, DatasourceAlreadyExistsException {
178
            throws ConfigurationException, DatasourceAlreadyExistsException {
183
        // since a connection pool is not a Datasource, the deploy has to
179
        // Since a connection pool is not a Datasource, the deploy has to
184
        // happen in a different part of the deploy processing...
180
        // happen in a different part of the deploy processing...
185
    }
181
    }
186
    
182
 
187
188
    
189
    // ------------------------------------------------------------------------
190
    //  Used by ModuleConfigurationImpl since 
191
    // ------------------------------------------------------------------------
192
193
    // Making this method private because there is no reason to provide resources
194
    // file base names manually.
195
    /**
183
    /**
196
     * Get <code>Datasource</code> objects from first available resources file.
184
     * Get {@link Datasource} objects from first available resources file.
197
     *
185
     * <p/>
198
     * @param resourceDir Directory containing resource files.
186
     * @param version Resources file names depend on GlassFish server version.
199
     * @param baseNames List of resource file base names to search for.
187
     * @param module  Java EE module (project).
200
     * @return <code>Datasource</code> objects found in first available file.
188
     * @return {@link Datasource} objects found in first available file.
201
     */
189
     */
202
    private static Set<Datasource> getDatasources(
190
    public static Set<Datasource> getDatasources(
203
            final File resourceDir, final String[] baseNames,
191
            final J2eeModule module, final GlassFishVersion version) {
204
            final GlassFishVersion version) {
192
        File file = GlassfishConfiguration.getExistingResourceFile(module, version);
205
        for (String baseName : baseNames) {
193
        if (file != null) {
206
            File file = new File(resourceDir, baseName+".xml");
194
            return readDatasources(file, "/", version);
207
            // Return Datasource objects from first available file.
195
        } else {
208
            if (file.isFile())
196
            return new HashSet<>();
209
                return readDatasources(file, "/", resourceDir, version);
210
        }
197
        }
211
        // Return empty set when no resource file was found.
212
        return new HashSet<>();
213
    }
198
    }
214
199
215
    /**
216
     * Get <code>Datasource</code> objects from first available resources file.
217
     * Default resource base names list is used.
218
     *
219
     * @param resourceDir Directory containing resource files.
220
     * @return <code>Datasource</code> objects found in first available file.
221
     */
222
    public static Set<Datasource> getDatasources(File resourceDir) {
223
        return getDatasources(resourceDir, RESOURCE_FILES, null);
224
    }
225
226
//    public Datasource createDataSource(String jndiName, String url, String username,
227
//            String password, String driver, File resourceDir) throws DatasourceAlreadyExistsException {
228
//        SunDatasource result = null;
229
//        try {
230
//            // Throw an exception if the data source already exists.
231
//            for(Datasource ds: getDatasources(resourceDir)) {
232
//                if(jndiName.equals(ds.getJndiName())) {
233
//                    throw new DatasourceAlreadyExistsException(new SunDatasource(
234
//                            jndiName, url, username, password, driver));
235
//                }
236
//            }
237
//            
238
//            if(url != null) {
239
////                String vendorName = convertToValidName(url);
240
////                if(vendorName == null) {
241
////                    vendorName = jndiName;
242
////                }else{
243
////                    if(vendorName.equals("derby_embedded")){ //NOI18N
244
////                        NotifyDescriptor d = new NotifyDescriptor.Message(bundle.getString("Err_UnSupportedDerby"), NotifyDescriptor.WARNING_MESSAGE); // NOI18N
245
////                        DialogDisplayer.getDefault().notify(d);
246
////                        return null;
247
////                    }
248
////                }
249
//                if(resourceDir.exists()) {
250
//                    FileUtil.createFolder(resourceDir);
251
//                }
252
//                
253
//                // Create connection pool if needed.
254
//                String poolName = createCheckForConnectionPool(vendorName, url, username, password, driver, resourceDir);
255
//                boolean jdbcExists = requiredResourceExists(jndiName, resourceDir, JDBC_RESOURCE);
256
//                if (jdbcExists) {
257
//                    result = null;
258
//                } else {
259
//                    createJDBCResource(jndiName, poolName, resourceDir);
260
//                    result = new SunDatasource(jndiName, url, username, password, driver);
261
//                }
262
//            }
263
//        } catch(IOException ex) {
264
//            Logger.getLogger("glassfish-javaee").log(Level.WARNING, ex.getLocalizedMessage(), ex);
265
//        }
266
//        return result;
267
//    }    
268
    
269
    
270
    // ------------------------------------------------------------------------
200
    // ------------------------------------------------------------------------
271
    //  Internal logic
201
    //  Internal logic
272
    // ------------------------------------------------------------------------
202
    // ------------------------------------------------------------------------
273
203
204
    /** 
205
     * Get resource file for new data source creation and verify it.
206
     * Verifies existing resource file syntax and data sources or provides
207
     * a new file when no resource file exists.
208
     * <br/>
209
     * <i>Internal {@link #createDataSource(String, String, String,
210
     * String, String, J2eeModule, GlassFishVersion)} helper method.</i>
211
     * <p/>
212
     * @param jndiName Data source JNDI name.
213
     * @param url      Database URL.
214
     * @param username Database user name.
215
     * @param password Database user password.
216
     * @param driver   Database JDBC driver.
217
     * @param module   Java EE module (project).
218
     * @param version  GlassFish server version.
219
     * @param cpFinder Connection pool finder.
220
     * @return Resource file for new data source creation.
221
     * @throws ConfigurationException if there is a problem with resource
222
     *         file parsing.
223
     * @throws DatasourceAlreadyExistsException if the required data source
224
     *         already exists in resource file.
225
     */
226
    private static File resourceFileForDSCreation(
227
            final String jndiName, final String url, final String username,
228
            final String password, final String driver, final J2eeModule module,
229
            final GlassFishVersion version,final ConnectionPoolFinder cpFinder
230
    ) throws ConfigurationException, DatasourceAlreadyExistsException {
231
        final DuplicateJdbcResourceFinder jdbcFinder
232
                = new DuplicateJdbcResourceFinder(jndiName);
233
        File file = GlassfishConfiguration.getExistingResourceFile(module, version);
234
        if (file.exists()) {
235
            List<TreeParser.Path> pathList = new ArrayList<>();
236
            pathList.add(new TreeParser.Path("/resources/jdbc-resource", jdbcFinder));
237
            pathList.add(new TreeParser.Path("/resources/jdbc-connection-pool", cpFinder));
238
            try {
239
                TreeParser.readXml(file, pathList);
240
                if(jdbcFinder.isDuplicate()) {
241
                    throw new DatasourceAlreadyExistsException(new SunDatasource(
242
                            jndiName, url, username, password, driver));
243
                }
244
            } catch(IllegalStateException ex) {
245
                Logger.getLogger("glassfish-javaee").log(
246
                        Level.INFO, ex.getLocalizedMessage(), ex);
247
                throw new ConfigurationException(ex.getLocalizedMessage(), ex);
248
            }
249
        }
250
        return file != null
251
                ? file : GlassfishConfiguration.getNewResourceFile(module, version);
252
    }
253
    
254
    /**
255
     * Create a data source (jdbc-resource and jdbc-connection-pool) and add it
256
     * to sun-resources.xml in the specified resource folder.
257
     * 
258
     * @param jndiName Data source JNDI name.
259
     * @param url      Database URL.
260
     * @param username Database user name.
261
     * @param password Database user password.
262
     * @param driver   Database JDBC driver.
263
     * @param module   Java EE module (project).
264
     * @param version  GlassFish server version.
265
     * @return New {@link Datasource} object.
266
     * @throws ConfigurationException if there is a problem with resource
267
     *         file parsing.
268
     * @throws DatasourceAlreadyExistsException if the required data source
269
     *         already exists in resource file.
270
     */
271
    public static Datasource createDataSource(
272
            final String jndiName, final String url, final String username,
273
            final String password, final String driver,
274
            final J2eeModule module, final GlassFishVersion version
275
    ) throws ConfigurationException, DatasourceAlreadyExistsException {
276
        SunDatasource ds;
277
        ConnectionPoolFinder cpFinder = new ConnectionPoolFinder();
278
        
279
        File xmlFile = resourceFileForDSCreation(
280
                jndiName, url, username, password, driver, module, version, cpFinder);
281
282
        try {
283
            String vendorName = VendorNameMgr.vendorNameFromDbUrl(url);
284
            if(vendorName == null) {
285
                vendorName = jndiName;
286
            } else {
287
                if("derby_embedded".equals(vendorName)) {
288
                    // !PW FIXME display as dialog warning?
289
                    Logger.getLogger("glassfish-javaee").log(Level.WARNING, 
290
                            "Embedded derby not supported as a datasource");
291
                    return null;
292
                }
293
            }
294
295
            // Is there a connection pool we can reuse, or do we need to create one?
296
            String defaultPoolName = computePoolName(url, vendorName, username);
297
            Map<String, CPool> pools = cpFinder.getPoolData();
298
            CPool defaultPool = pools.get(defaultPoolName);
299
            
300
            String poolName = null;
301
            if(defaultPool != null && isSameDatabaseConnection(defaultPool, url, username, password)) {
302
                poolName = defaultPoolName;
303
            } else {
304
                for(CPool pool: pools.values()) {
305
                    if(isSameDatabaseConnection(pool, url, username, password)) {
306
                        poolName = pool.getPoolName();
307
                        break;
308
                    }
309
                }
310
            }
311
            
312
            if(poolName == null) {
313
                poolName = defaultPool == null ? defaultPoolName : generateUniqueName(defaultPoolName, pools.keySet());
314
                createConnectionPool(xmlFile, poolName, url, username, password, driver);
315
            }
316
            
317
            // create jdbc resource
318
            createJdbcResource(xmlFile, jndiName, poolName);
319
320
            ds = new SunDatasource(jndiName, url, username, password, driver);
321
        } catch(IOException ex) {
322
            Logger.getLogger("glassfish-javaee").log(Level.INFO, ex.getLocalizedMessage(), ex);
323
            throw new ConfigurationException(ex.getLocalizedMessage(), ex);
324
        }
325
        
326
        return ds;
327
    }
328
274
    /**
329
    /**
275
     * Parse resource file and build <code>Datasource</code> objects from it.
330
     * Parse resource file and build <code>Datasource</code> objects from it.
276
     * <p/>
331
     * <p/>
Lines 289-302 Link Here
289
     */
344
     */
290
    private static Set<Datasource> readDatasources(
345
    private static Set<Datasource> readDatasources(
291
            final File xmlFile, final String xPathPrefix,
346
            final File xmlFile, final String xPathPrefix,
292
            final File resourcesDir, final GlassFishVersion version) {
347
            final GlassFishVersion version) {
293
        Set<Datasource> dataSources = new HashSet<>();
348
        final Set<Datasource> dataSources = new HashSet<>();
294
349
295
        if (xmlFile.canRead()) {
350
        if (xmlFile.canRead()) {
296
            Map<String, JdbcResource> jdbcResourceMap = new HashMap<>();
351
            final Map<String, JdbcResource> jdbcResourceMap = new HashMap<>();
297
            Map<String, ConnectionPool> connectionPoolMap = new HashMap<>();
352
            final Map<String, ConnectionPool> connectionPoolMap = new HashMap<>();
298
353
299
            List<TreeParser.Path> pathList = new ArrayList<>();
354
            final List<TreeParser.Path> pathList = new ArrayList<>();
300
            pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-resource", new JdbcReader(jdbcResourceMap)));
355
            pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-resource", new JdbcReader(jdbcResourceMap)));
301
            pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-connection-pool", new ConnectionPoolReader(connectionPoolMap)));
356
            pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-connection-pool", new ConnectionPoolReader(connectionPoolMap)));
302
357
Lines 307-325 Link Here
307
            }
362
            }
308
363
309
            for (JdbcResource jdbc : jdbcResourceMap.values()) {
364
            for (JdbcResource jdbc : jdbcResourceMap.values()) {
310
                ConnectionPool pool = connectionPoolMap.get(jdbc.getPoolName());
365
                final ConnectionPool pool = connectionPoolMap.get(jdbc.getPoolName());
311
                if (pool != null) {
366
                if (pool != null) {
312
                    try {
367
                    try {
313
                        pool.normalize();
368
                        pool.normalize();
314
369
315
                        // add to sun datasource list
370
                        // add to sun datasource list
316
                        String url = pool.getProperty("URL"); //NOI18N
371
                        final String url = pool.getProperty("URL"); //NOI18N
317
                        String username = pool.getProperty("User"); //NOI18N
372
                        final String username = pool.getProperty("User"); //NOI18N
318
                        String password = pool.getProperty("Password"); //NOI18N
373
                        final String password = pool.getProperty("Password"); //NOI18N
319
                        String driverClassName = pool.getProperty("driverClass"); //NOI18N
374
                        final String driverClassName = pool.getProperty("driverClass"); //NOI18N
320
                        SunDatasource dataSource = new SunDatasource(
375
                        final SunDatasource dataSource = new SunDatasource(
321
                                jdbc.getJndiName(), url, username,
376
                                jdbc.getJndiName(), url, username,
322
                                password, driverClassName, resourcesDir);
377
                                password, driverClassName);
323
                        dataSources.add(dataSource);
378
                        dataSources.add(dataSource);
324
                        // Add Java EE 7 comp/DefaultDataSource data source
379
                        // Add Java EE 7 comp/DefaultDataSource data source
325
                        // as jdbc/__default clone (since GF 4).
380
                        // as jdbc/__default clone (since GF 4).
Lines 470-562 Link Here
470
            }
525
            }
471
        }
526
        }
472
    }    
527
    }    
473
528
   
474
    /**
475
     * Create a data source (jdbc-resource and jdbc-connection-pool) and add it
476
     * to sun-resources.xml in the specified resource folder.
477
     * 
478
     * @param jndiName
479
     * @param url
480
     * @param username
481
     * @param password
482
     * @param driver
483
     * @param resourceDir
484
     * @return
485
     * @throws DatasourceAlreadyExistsException if the required resources already
486
     *         exist.
487
     */
488
    public static Datasource createDataSource(String jndiName, String url, 
489
            String username, String password, String driver, File resourceDir, String baseName)
490
            throws ConfigurationException, DatasourceAlreadyExistsException {
491
        SunDatasource ds;
492
        DuplicateJdbcResourceFinder jdbcFinder = new DuplicateJdbcResourceFinder(jndiName);
493
        ConnectionPoolFinder cpFinder = new ConnectionPoolFinder();
494
        
495
        File xmlFile = new File(resourceDir, baseName+".xml");
496
        if(xmlFile.exists()) {
497
            List<TreeParser.Path> pathList = new ArrayList<>();
498
            pathList.add(new TreeParser.Path("/resources/jdbc-resource", jdbcFinder));
499
            pathList.add(new TreeParser.Path("/resources/jdbc-connection-pool", cpFinder));
500
            
501
            try {
502
                TreeParser.readXml(xmlFile, pathList);
503
                if(jdbcFinder.isDuplicate()) {
504
                    throw new DatasourceAlreadyExistsException(new SunDatasource(
505
                            jndiName, url, username, password, driver));
506
                }
507
            } catch(IllegalStateException ex) {
508
                Logger.getLogger("glassfish-javaee").log(Level.INFO, ex.getLocalizedMessage(), ex);
509
                throw new ConfigurationException(ex.getLocalizedMessage(), ex);
510
            }
511
        }
512
513
        try {
514
            String vendorName = VendorNameMgr.vendorNameFromDbUrl(url);
515
            if(vendorName == null) {
516
                vendorName = jndiName;
517
            } else {
518
                if("derby_embedded".equals(vendorName)) {
519
                    // !PW FIXME display as dialog warning?
520
                    Logger.getLogger("glassfish-javaee").log(Level.WARNING, 
521
                            "Embedded derby not supported as a datasource");
522
                    return null;
523
                }
524
            }
525
526
            // Is there a connection pool we can reuse, or do we need to create one?
527
            String defaultPoolName = computePoolName(url, vendorName, username);
528
            Map<String, CPool> pools = cpFinder.getPoolData();
529
            CPool defaultPool = pools.get(defaultPoolName);
530
            
531
            String poolName = null;
532
            if(defaultPool != null && isSameDatabaseConnection(defaultPool, url, username, password)) {
533
                poolName = defaultPoolName;
534
            } else {
535
                for(CPool pool: pools.values()) {
536
                    if(isSameDatabaseConnection(pool, url, username, password)) {
537
                        poolName = pool.getPoolName();
538
                        break;
539
                    }
540
                }
541
            }
542
            
543
            if(poolName == null) {
544
                poolName = defaultPool == null ? defaultPoolName : generateUniqueName(defaultPoolName, pools.keySet());
545
                createConnectionPool(xmlFile, poolName, url, username, password, driver);
546
            }
547
            
548
            // create jdbc resource
549
            createJdbcResource(xmlFile, jndiName, poolName);
550
551
            ds = new SunDatasource(jndiName, url, username, password, driver, resourceDir);
552
        } catch(IOException ex) {
553
            Logger.getLogger("glassfish-javaee").log(Level.INFO, ex.getLocalizedMessage(), ex);
554
            throw new ConfigurationException(ex.getLocalizedMessage(), ex);
555
        }
556
        
557
        return ds;
558
    }
559
    
560
    private static String generateUniqueName(String prefix, Set<String> keys) {
529
    private static String generateUniqueName(String prefix, Set<String> keys) {
561
        for(int i = 1; ; i++) {
530
        for(int i = 1; ; i++) {
562
            String candidate = prefix + "_" + i; // NOI18N
531
            String candidate = prefix + "_" + i; // NOI18N
(-)a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/SunDatasource.java (-20 / +6 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2010-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 42-48 Link Here
42
42
43
package org.netbeans.modules.glassfish.javaee.db;
43
package org.netbeans.modules.glassfish.javaee.db;
44
44
45
import java.io.File;
46
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
45
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
47
46
48
/**
47
/**
Lines 57-77 Link Here
57
    private final String username;
56
    private final String username;
58
    private final String password;
57
    private final String password;
59
    private final String driverClassName;
58
    private final String driverClassName;
60
    private File resourceDir;
61
    
59
    
62
    public SunDatasource(String jndiName, String url, String username, 
60
    public SunDatasource(String jndiName, String url, String username, 
63
            String password, String driverClassName) {
61
            String password, String driverClassName/*, File resourceDir*/) {
64
        this(jndiName, url, username, password, driverClassName, null);
65
    }
66
    
67
    public SunDatasource(String jndiName, String url, String username, 
68
            String password, String driverClassName, File resourceDir) {
69
        this.jndiName = jndiName;
62
        this.jndiName = jndiName;
70
        this.url = url;
63
        this.url = url;
71
        this.username = username;
64
        this.username = username;
72
        this.password = password;
65
        this.password = password;
73
        this.driverClassName = driverClassName;
66
        this.driverClassName = driverClassName;
74
        this.resourceDir = resourceDir;
75
    }
67
    }
76
    
68
    
77
    @Override
69
    @Override
Lines 104-117 Link Here
104
        return driverClassName;
96
        return driverClassName;
105
    }
97
    }
106
    
98
    
107
    File getResourceDir() {
108
        return resourceDir;
109
    }
110
    
111
    void setResourceDir(File resourceDir) {
112
        this.resourceDir = resourceDir;
113
    }
114
    
115
    @Override
99
    @Override
116
    public String toString() {
100
    public String toString() {
117
        return "[ " + jndiName + " : " + url 
101
        return "[ " + jndiName + " : " + url 
Lines 120-125 Link Here
120
    }
104
    }
121
    
105
    
122
    @Override
106
    @Override
107
    @SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
123
    public boolean equals(Object obj) {
108
    public boolean equals(Object obj) {
124
        if (obj == null) {
109
        if (obj == null) {
125
            return false;
110
            return false;
Lines 140-146 Link Here
140
        if (this.password == null || !this.password.equals(other.password)) {
125
        if (this.password == null || !this.password.equals(other.password)) {
141
            return false;
126
            return false;
142
        }
127
        }
143
        if (this.driverClassName == null || !this.driverClassName.equals(other.driverClassName)) {
128
        if (this.driverClassName == null
129
                || !this.driverClassName.equals(other.driverClassName)) {
144
            return false;
130
            return false;
145
        }
131
        }
146
        return true;
132
        return true;
Lines 159-165 Link Here
159
145
160
    public SunDatasource copy(String jndiName) {
146
    public SunDatasource copy(String jndiName) {
161
        return new SunDatasource(jndiName, this.url, this.username, 
147
        return new SunDatasource(jndiName, this.url, this.username, 
162
            this.password, this.driverClassName, this.resourceDir);
148
            this.password, this.driverClassName/*, this.resourceDir*/);
163
    }
149
    }
164
150
165
}
151
}
(-)3a3c32bf146f (+137 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.javaee.db;
43
44
import java.beans.PropertyChangeListener;
45
import java.io.File;
46
import java.util.Collections;
47
import java.util.Iterator;
48
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
49
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation2;
50
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
51
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
53
54
/**
55
 * Java EE module for GlassFish features tests.
56
 * <p/>
57
 * @author Tomas Kraus
58
 */
59
public class HK2TestEEModuleImpl implements J2eeModuleImplementation2 {
60
    
61
    private final FileObject appRoot;
62
    private final File srcDir;
63
    private final File configDir;
64
    private final J2eeModule.Type moduleType;
65
    private final String moduleVersion;
66
67
    /** Creates a new instance of TestJ2eeModule
68
     * @param appRoot Application root directory.
69
     * @param moduleType Java EE module type.
70
     * @param moduleVersion Java EE version.
71
     */
72
    public HK2TestEEModuleImpl(
73
            final FileObject appRoot, final J2eeModule.Type moduleType,
74
            final String moduleVersion
75
    ) {
76
        this.appRoot = appRoot;
77
        this.srcDir = new File(FileUtil.toFile(appRoot), "src");
78
        this.configDir = new File(srcDir, "conf");
79
        this.moduleType = moduleType;
80
        this.moduleVersion = moduleVersion;
81
    }
82
83
    @Override
84
    public FileObject getArchive() {
85
        return null;
86
    }
87
    
88
    @Override
89
    public Iterator<J2eeModule.RootedEntry> getArchiveContents() {
90
        return Collections.<J2eeModule.RootedEntry>emptySet().iterator();
91
    }
92
    
93
    @Override
94
    public FileObject getContentDirectory() {
95
        return appRoot;
96
    }
97
    
98
    @Override
99
    public J2eeModule.Type getModuleType() {
100
        return moduleType;
101
    }
102
    
103
    @Override
104
    public String getModuleVersion() {
105
        return moduleVersion;
106
    }
107
    
108
    @Override
109
    public String getUrl() {
110
        throw new UnsupportedOperationException("Not implemented.");
111
    }
112
    
113
    @Override
114
    public File getResourceDirectory() {
115
        return new File(FileUtil.toFile(appRoot), "setup");
116
    }
117
118
    @Override
119
    public File getDeploymentConfigurationFile(String name) {
120
        return new File(configDir, name);
121
    }
122
123
    @Override
124
    public void addPropertyChangeListener(PropertyChangeListener listener) {
125
        throw new UnsupportedOperationException("Not implemented.");
126
    }
127
128
    @Override
129
    public void removePropertyChangeListener(PropertyChangeListener listener) {
130
        throw new UnsupportedOperationException("Not implemented.");
131
    }
132
    
133
    @Override
134
    public <T> MetadataModel<T> getMetadataModel(Class<T> type) {
135
        throw new UnsupportedOperationException("Not implemented.");
136
    }
137
}
(-)a/glassfish.javaee/test/unit/src/org/netbeans/modules/glassfish/javaee/db/Hk2DatasourceManagerTest.java (-9 / +31 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2010-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 51-66 Link Here
51
import org.junit.Before;
51
import org.junit.Before;
52
import org.junit.BeforeClass;
52
import org.junit.BeforeClass;
53
import org.junit.Test;
53
import org.junit.Test;
54
import org.netbeans.api.j2ee.core.Profile;
55
import org.netbeans.junit.NbTestCase;
56
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
54
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
57
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
55
import static org.junit.Assert.*;
58
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
59
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleFactory;
60
import org.openide.filesystems.FileObject;
61
import org.openide.filesystems.FileUtil;
56
62
57
/**
63
/**
58
 *
64
 * GlassFish server data source manager tests.
59
 * @author vkraemer
65
 * <p/>
66
 * @author Vince Kraemer, Tomas Kraus
60
 */
67
 */
61
public class Hk2DatasourceManagerTest {
68
public class Hk2DatasourceManagerTest extends NbTestCase {
62
69
63
    public Hk2DatasourceManagerTest() {
70
    private J2eeModule j2eeModule;
71
    private HK2TestEEModuleImpl j2eeModuleImpl;
72
73
    public Hk2DatasourceManagerTest(String testName) {
74
        super(testName);
64
    }
75
    }
65
76
66
    @BeforeClass
77
    @BeforeClass
Lines 72-81 Link Here
72
    }
83
    }
73
84
74
    @Before
85
    @Before
75
    public void setUp() {
86
    @Override
87
    public void setUp() throws Exception {
88
        File dataDir = getDataDir();
89
        File rootFolder = new File(dataDir, "hk2sample");
90
        rootFolder.mkdirs();
91
        FileObject rootFolderFO = FileUtil.toFileObject(rootFolder);
92
        j2eeModuleImpl = new HK2TestEEModuleImpl(
93
                rootFolderFO, J2eeModule.Type.WAR, Profile.JAVA_EE_7_FULL.toPropertiesString());
94
        j2eeModule = J2eeModuleFactory.createJ2eeModule(j2eeModuleImpl);
76
    }
95
    }
77
96
78
    @After
97
    @After
98
    @Override
79
    public void tearDown() {
99
    public void tearDown() {
80
    }
100
    }
81
101
Lines 93-103 Link Here
93
        }
113
        }
94
        File resourceDir = null;
114
        File resourceDir = null;
95
        try {
115
        try {
96
            resourceDir = new File(new File(codebase.toURI()).getParentFile(), "data/178776");  // NOI18N
116
            resourceDir = new File(
117
                    new File(codebase.toURI()).getParentFile(), "data/178776");  // NOI18N
97
        } catch (URISyntaxException x) {
118
        } catch (URISyntaxException x) {
98
            throw new Error(x);
119
            throw new Error(x);
99
        }
120
        }
100
        Set<Datasource> result = Hk2DatasourceManager.getDatasources(resourceDir);
121
        Set<Datasource> result = Hk2DatasourceManager.getDatasources(
122
                j2eeModule, GlassFishVersion.GF_3);
101
//        assertEquals(expResult, result);
123
//        assertEquals(expResult, result);
102
        // TODO review the generated test code and remove the default call to fail.
124
        // TODO review the generated test code and remove the default call to fail.
103
        assert null != result : "null result";
125
        assert null != result : "null result";
(-)a/glassfish.tooling/nbproject/project.xml (+1 lines)
Lines 29-34 Link Here
29
                <friend>org.netbeans.modules.glassfish.eecommon</friend>
29
                <friend>org.netbeans.modules.glassfish.eecommon</friend>
30
                <friend>org.netbeans.modules.glassfish.javaee</friend>
30
                <friend>org.netbeans.modules.glassfish.javaee</friend>
31
                <friend>org.netbeans.modules.j2ee.sun.appsrv81</friend>
31
                <friend>org.netbeans.modules.j2ee.sun.appsrv81</friend>
32
                <friend>org.netbeans.modules.j2ee.sun.ddui</friend>
32
                <package>org.netbeans.modules.glassfish.tooling</package>
33
                <package>org.netbeans.modules.glassfish.tooling</package>
33
                <package>org.netbeans.modules.glassfish.tooling.data</package>
34
                <package>org.netbeans.modules.glassfish.tooling.data</package>
34
                <package>org.netbeans.modules.glassfish.tooling.data.cloud</package>
35
                <package>org.netbeans.modules.glassfish.tooling.data.cloud</package>
(-)a/glassfish.tooling/src/org/netbeans/modules/glassfish/tooling/data/GlassFishVersion.java (-2 / +34 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 2012-2013 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2012-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 42-47 Link Here
42
import java.util.HashMap;
42
import java.util.HashMap;
43
import java.util.Map;
43
import java.util.Map;
44
import org.netbeans.modules.glassfish.tooling.logging.Logger;
44
import org.netbeans.modules.glassfish.tooling.logging.Logger;
45
import org.netbeans.modules.glassfish.tooling.utils.EnumUtils;
45
46
46
/**
47
/**
47
 * GlassFish server version.
48
 * GlassFish server version.
Lines 271-277 Link Here
271
    }
272
    }
272
273
273
    ////////////////////////////////////////////////////////////////////////////
274
    ////////////////////////////////////////////////////////////////////////////
274
    // Class attributes                                                       //
275
    // Instance attributes                                                    //
275
    ////////////////////////////////////////////////////////////////////////////
276
    ////////////////////////////////////////////////////////////////////////////
276
277
277
    /** Major version number. */
278
    /** Major version number. */
Lines 372-377 Link Here
372
     * @return Value of <code>true</code> when all parts of version numbers are
373
     * @return Value of <code>true</code> when all parts of version numbers are
373
     *         the same or <code>false</code> otherwise.
374
     *         the same or <code>false</code> otherwise.
374
     */
375
     */
376
    @SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
375
    public boolean equals(final GlassFishVersion version) {
377
    public boolean equals(final GlassFishVersion version) {
376
        if (version == null) {
378
        if (version == null) {
377
            return false;
379
            return false;
Lines 383-388 Link Here
383
        }
385
        }
384
    }
386
    }
385
387
388
    /** {@inheritDoc} */
389
    public static boolean eq(Enum<GlassFishVersion> v1, Enum<GlassFishVersion> v2) {
390
        return EnumUtils.eq(v1, v2);
391
    }
392
393
     /** {@inheritDoc} */
394
    public static boolean ne(Enum<GlassFishVersion> v1, Enum<GlassFishVersion> v2) {
395
        return EnumUtils.ne(v1, v2);
396
    }
397
398
     /** {@inheritDoc} */
399
    public static boolean lt(Enum<GlassFishVersion> v1, Enum<GlassFishVersion> v2) {
400
        return EnumUtils.lt(v1, v2);
401
    }
402
403
     /** {@inheritDoc} */
404
    public static boolean le(Enum<GlassFishVersion> v1, Enum<GlassFishVersion> v2) {
405
        return EnumUtils.le(v1, v2);
406
    }
407
408
    /** {@inheritDoc} */
409
    public static boolean gt(Enum<GlassFishVersion> v1, Enum<GlassFishVersion> v2) {
410
        return EnumUtils.gt(v1, v2);
411
    }
412
413
     /** {@inheritDoc} */
414
    public static boolean ge(Enum<GlassFishVersion> v1, Enum<GlassFishVersion> v2) {
415
        return EnumUtils.ge(v1, v2);
416
    }
417
386
    /**
418
    /**
387
     * Convert <code>GlassFishVersion</code> value to <code>String</code>.
419
     * Convert <code>GlassFishVersion</code> value to <code>String</code>.
388
     * <p/>
420
     * <p/>
(-)3a3c32bf146f (+157 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.tooling.utils;
43
44
/**
45
 * Enumeration helper methods:<ul>
46
 * <li>Ordinal value based comparison.</li>
47
 * </ul>
48
 * @author Tomas Kraus
49
 */
50
public final class EnumUtils {
51
    
52
    /**
53
     * Ordinal value based comparison: <i>equals</i> {@code v1 == v2}.
54
     * <p/>
55
     * @param v1 First {@link Enum} instance to be compared.
56
     * @param v2 Second {@link Enum} instance to be compared.
57
     * @return Value of {@code true} when ordinal values of {@code v1}
58
     *         and {@code v2} are equal or both values are {@code null}.
59
     *         Value of {@code false} otherwise.
60
     */
61
    public static final boolean eq(
62
            final Enum<? extends Enum> v1, final Enum<? extends Enum> v2) {
63
        return v1 != null
64
                ? (v2 != null ? v1.ordinal() == v2.ordinal() : false)
65
                : v2 == null;
66
    }
67
68
    /**
69
     * Ordinal value based comparison: <i>not equals</i> {@code v1 != v2}.
70
     * <p/>
71
     * @param v1 First {@link Enum} instance to be compared.
72
     * @param v2 Second {@link Enum} instance to be compared.
73
     * @return Value of {@code true} when ordinal values of {@code v1}
74
     *         and {@code v2} are not equal or one of the values
75
     *         is {@code null} and second one is not {@code null}. Value
76
     *         of {@code false} otherwise.
77
     */
78
    public static final boolean ne(
79
            final Enum<? extends Enum> v1, final Enum<? extends Enum> v2) {
80
        return v1 != null
81
                ? (v2 != null ? v1.ordinal() != v2.ordinal() : true)
82
                : v2 != null;
83
    }
84
85
    /**
86
     * Ordinal value based comparison: <i>less than</i> {@code v1 < v2}.
87
     * Value of {@code null} is considered less than any ordinal value.
88
     * <p/>
89
     * @param v1 First {@link Enum} instance to be compared.
90
     * @param v2 Second {@link Enum} instance to be compared.
91
     * @return Value of {@code true} when ordinal values of {@code v1}
92
     *         is less than {@code v2} or {@code v1} is {@code null} 
93
     *         and {@code v2} is not {@code null}. Value of {@code false}
94
     *         otherwise. 
95
     */
96
    public static final boolean lt(
97
            final Enum<? extends Enum> v1, final Enum<? extends Enum> v2) {
98
        return v1 != null
99
                ? (v2 != null ? v1.ordinal() < v2.ordinal() : false)
100
                : v2 != null;
101
    }
102
103
    /**
104
     * Ordinal value based comparison: <i>less than or equal</i> {@code v1 <= v2}.
105
     * Value of {@code null} is considered less than any ordinal value.
106
     * <p/>
107
     * @param v1 First {@link Enum} instance to be compared.
108
     * @param v2 Second {@link Enum} instance to be compared.
109
     * @return Value of {@code true} when ordinal values of {@code v1}
110
     *         is less than or equal to {@code v2} or {@code v1} is {@code null} 
111
     *         and {@code v2} is not {@code null}. Value of {@code false}
112
     *         otherwise. 
113
     */
114
    public static final boolean le(
115
            final Enum<? extends Enum> v1, final Enum<? extends Enum> v2) {
116
        return v1 != null
117
                ? (v2 != null ? v1.ordinal() <= v2.ordinal() : false)
118
                : true;
119
    }
120
121
    /**
122
     * Ordinal value based comparison: <i>greater than</i> {@code v1 > v2}.
123
     * Value of {@code null} is considered less than any ordinal value.
124
     * <p/>
125
     * @param v1 First {@link Enum} instance to be compared.
126
     * @param v2 Second {@link Enum} instance to be compared.
127
     * @return Value of {@code true} when ordinal values of {@code v1}
128
     *         is greater than {@code v2} or {@code v1} is {@code null} 
129
     *         and {@code v2} is not {@code null}. Value of {@code false}
130
     *         otherwise. 
131
     */
132
    public static final boolean gt(
133
            final Enum<? extends Enum> v1, final Enum<? extends Enum> v2) {
134
        return v1 != null
135
                ? (v2 != null ? v1.ordinal() > v2.ordinal() : true)
136
                : false;
137
    }
138
139
    /**
140
     * Ordinal value based comparison: <i>greater than or equal</i> {@code v1 >= v2}.
141
     * Value of {@code null} is considered less than any ordinal value.
142
     * <p/>
143
     * @param v1 First {@link Enum} instance to be compared.
144
     * @param v2 Second {@link Enum} instance to be compared.
145
     * @return Value of {@code true} when ordinal values of {@code v1}
146
     *         is greater than or equal to {@code v2} or {@code v1} is not {@code null} 
147
     *         and {@code v2} is {@code null}. Value of {@code false}
148
     *         otherwise. 
149
     */
150
    public static final boolean ge(
151
            final Enum<? extends Enum> v1, final Enum<? extends Enum> v2) {
152
        return v1 != null
153
                ? (v2 != null ? v1.ordinal() >= v2.ordinal() : true)
154
                : v2 == null;
155
    }
156
157
}
(-)3a3c32bf146f (+179 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.glassfish.tooling.utils;
43
44
import static org.netbeans.modules.glassfish.tooling.data.GlassFishVersion.GF_3;
45
import static org.netbeans.modules.glassfish.tooling.data.GlassFishVersion.GF_4;
46
import static org.testng.Assert.assertFalse;
47
import static org.testng.Assert.assertTrue;
48
import org.testng.annotations.Test;
49
50
/**
51
 * Test enumeration utilities.
52
 * <p>
53
 * @author Tomas Kraus
54
 */
55
@Test(groups = {"unit-tests"})
56
public class EnumUtilsTest {
57
    
58
    
59
    /**
60
     * Test equals method.
61
     * Expected results:<ul>
62
     * <li>{@code a > b}: false</li>
63
     * <li>{@code a == b}: true</li>
64
     * <li>{@code a < b}: false</li>
65
     * <li>{@code a, null}: false</li>
66
     * <li>{@code null, b}: false</li>
67
     * <li>{@code null, null}: true</li></ul>
68
     */
69
    @Test
70
    public void testEq() {
71
        assertFalse(EnumUtils.eq(GF_4, GF_3), "Equals for a > b shall be false.");
72
        assertTrue(EnumUtils.eq(GF_4, GF_4), "Equals for a == b shall be true.");
73
        assertFalse(EnumUtils.eq(GF_3, GF_4), "Equals for a < b shall be false.");
74
        assertFalse(EnumUtils.eq(GF_3, null), "Equals for a, null shall be false.");
75
        assertFalse(EnumUtils.eq(null, GF_3), "Equals for null, b shall be false.");
76
        assertTrue(EnumUtils.eq(null, null), "Equals for null, null shall be true.");
77
    }
78
79
    /**
80
     * Test not equals method.
81
     * Expected results:<ul>
82
     * <li>{@code a > b}: true</li>
83
     * <li>{@code a == b}: false</li>
84
     * <li>{@code a < b}: true</li>
85
     * <li>{@code a, null}: true</li>
86
     * <li>{@code null, b}: true</li>
87
     * <li>{@code null, null}: false</li></ul>
88
     */
89
    @Test
90
    public void testNe() {
91
        assertTrue(EnumUtils.ne(GF_4, GF_3), "Not equals for a > b shall be true.");
92
        assertFalse(EnumUtils.ne(GF_4, GF_4), "Not equals for a == b shall be false.");
93
        assertTrue(EnumUtils.ne(GF_3, GF_4), "Not equals for a < b shall be true.");
94
        assertTrue(EnumUtils.ne(GF_3, null), "Not equals for a, null shall be true.");
95
        assertTrue(EnumUtils.ne(null, GF_3), "Not equals for null, b shall be true.");
96
        assertFalse(EnumUtils.ne(null, null), "Not equals for null, null shall be false.");
97
    }
98
99
    /**
100
     * Test less than method.
101
     * Expected results:<ul>
102
     * <li>{@code a > b}: false</li>
103
     * <li>{@code a == b}: false</li>
104
     * <li>{@code a < b}: true</li>
105
     * <li>{@code a, null}: false</li>
106
     * <li>{@code null, b}: true</li>
107
     * <li>{@code null, null}: false</li></ul>
108
     */
109
    @Test
110
    public void testLt() {
111
        assertFalse(EnumUtils.lt(GF_4, GF_3), "Less than for a > b shall be false.");
112
        assertFalse(EnumUtils.lt(GF_4, GF_4), "Less than for a == b shall be false.");
113
        assertTrue(EnumUtils.lt(GF_3, GF_4), "Less than for a < b shall be true.");
114
        assertFalse(EnumUtils.lt(GF_3, null), "Less than for a, null shall be false.");
115
        assertTrue(EnumUtils.lt(null, GF_3), "Less than for null, b shall be true.");
116
        assertFalse(EnumUtils.lt(null, null), "Less than for null, null shall be false.");
117
    }
118
119
    /**
120
     * Test less than or equal method.
121
     * Expected results:<ul>
122
     * <li>{@code a > b}: false</li>
123
     * <li>{@code a == b}: true</li>
124
     * <li>{@code a < b}: true</li>
125
     * <li>{@code a, null}: false</li>
126
     * <li>{@code null, b}: true</li>
127
     * <li>{@code null, null}: true</li></ul>
128
     */
129
    @Test
130
    public void testLe() {
131
        assertFalse(EnumUtils.le(GF_4, GF_3), "Less than or equal for a > b shall be false.");
132
        assertTrue(EnumUtils.le(GF_4, GF_4), "Less than or equal for a == b shall be true.");
133
        assertTrue(EnumUtils.le(GF_3, GF_4), "Less than or equal for a < b shall be true.");
134
        assertFalse(EnumUtils.le(GF_3, null), "Less than or equal for a, null shall be false.");
135
        assertTrue(EnumUtils.le(null, GF_3), "Less than or equal for null, b shall be true.");
136
        assertTrue(EnumUtils.le(null, null), "Less than or equal for null, null shall be true.");
137
    }
138
139
   /**
140
     * Test greater than method.
141
     * Expected results:<ul>
142
     * <li>{@code a > b}: true</li>
143
     * <li>{@code a == b}: false</li>
144
     * <li>{@code a < b}: false</li>
145
     * <li>{@code a, null}: true</li>
146
     * <li>{@code null, b}: false</li>
147
     * <li>{@code null, null}: false</li></ul>
148
     */
149
    @Test
150
    public void testGt() {
151
        assertTrue(EnumUtils.gt(GF_4, GF_3), "Greater than for a > b shall be true.");
152
        assertFalse(EnumUtils.gt(GF_4, GF_4), "Greater than for a == b shall be false.");
153
        assertFalse(EnumUtils.gt(GF_3, GF_4), "Greater than for a < b shall be false.");
154
        assertTrue(EnumUtils.gt(GF_3, null), "Greater than for a, null shall be true.");
155
        assertFalse(EnumUtils.gt(null, GF_3), "Greater than for null, b shall be false.");
156
        assertFalse(EnumUtils.gt(null, null), "Greater than for null, null shall be false.");
157
    }
158
159
    /**
160
     * Test greater than or equal method.
161
     * Expected results:<ul>
162
     * <li>{@code a > b}: true</li>
163
     * <li>{@code a == b}: true</li>
164
     * <li>{@code a < b}: false</li>
165
     * <li>{@code a, null}: true</li>
166
     * <li>{@code null, b}: false</li>
167
     * <li>{@code null, null}: true</li></ul>
168
     */
169
    @Test
170
    public void testGe() {
171
        assertTrue(EnumUtils.ge(GF_4, GF_3), "Greater than or equal for a > b shall be true.");
172
        assertTrue(EnumUtils.ge(GF_4, GF_4), "Greater than or equal for a == b shall be true.");
173
        assertFalse(EnumUtils.ge(GF_3, GF_4), "Greater than or equal for a < b shall be false.");
174
        assertTrue(EnumUtils.ge(GF_3, null), "Greater than or equal for a, null shall be true.");
175
        assertFalse(EnumUtils.ge(null, GF_3), "Greater than or equal for null, b shall be false.");
176
        assertTrue(EnumUtils.ge(null, null), "Greater than or equal for null, null shall be true.");
177
    }
178
179
}
(-)a/j2ee.sun.ddui/nbproject/project.xml (-8 / +17 lines)
Lines 130-135 Link Here
130
                    </run-dependency>
130
                    </run-dependency>
131
                </dependency>
131
                </dependency>
132
                <dependency>
132
                <dependency>
133
                    <code-name-base>org.netbeans.modules.glassfish.tooling</code-name-base>
134
                    <build-prerequisite/>
135
                    <compile-dependency/>
136
                    <run-dependency>
137
                        <release-version>0-1</release-version>
138
                        <specification-version>1.0</specification-version>
139
                    </run-dependency>
140
                </dependency>
141
                <dependency>
133
                    <code-name-base>org.netbeans.modules.j2ee.dd</code-name-base>
142
                    <code-name-base>org.netbeans.modules.j2ee.dd</code-name-base>
134
                    <build-prerequisite/>
143
                    <build-prerequisite/>
135
                    <compile-dependency/>
144
                    <compile-dependency/>
Lines 337-350 Link Here
337
                    </run-dependency>
346
                    </run-dependency>
338
                </dependency>
347
                </dependency>
339
                <dependency>
348
                <dependency>
340
                    <code-name-base>org.openide.util.ui</code-name-base>
341
                    <build-prerequisite/>
342
                    <compile-dependency/>
343
                    <run-dependency>
344
                        <specification-version>9.3</specification-version>
345
                    </run-dependency>
346
                </dependency>
347
                <dependency>
348
                    <code-name-base>org.openide.util</code-name-base>
349
                    <code-name-base>org.openide.util</code-name-base>
349
                    <build-prerequisite/>
350
                    <build-prerequisite/>
350
                    <compile-dependency/>
351
                    <compile-dependency/>
Lines 361-366 Link Here
361
                    </run-dependency>
362
                    </run-dependency>
362
                </dependency>
363
                </dependency>
363
                <dependency>
364
                <dependency>
365
                    <code-name-base>org.openide.util.ui</code-name-base>
366
                    <build-prerequisite/>
367
                    <compile-dependency/>
368
                    <run-dependency>
369
                        <specification-version>9.3</specification-version>
370
                    </run-dependency>
371
                </dependency>
372
                <dependency>
364
                    <code-name-base>org.openide.windows</code-name-base>
373
                    <code-name-base>org.openide.windows</code-name-base>
365
                    <build-prerequisite/>
374
                    <build-prerequisite/>
366
                    <compile-dependency/>
375
                    <compile-dependency/>
(-)a/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/SunONEDeploymentConfiguration.java (-17 / +29 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2011 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 1997-2015 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 44-51 Link Here
44
package org.netbeans.modules.j2ee.sun.share.configbean;
44
package org.netbeans.modules.j2ee.sun.share.configbean;
45
45
46
import java.io.File;
46
import java.io.File;
47
import java.io.IOException;
47
import java.io.InputStream;
48
import java.io.InputStream;
48
import java.io.IOException;
49
import java.io.OutputStream;
49
import java.io.OutputStream;
50
import java.util.Collections;
50
import java.util.Collections;
51
import java.util.Set;
51
import java.util.Set;
Lines 59-70 Link Here
59
import org.netbeans.api.project.ProjectUtils;
59
import org.netbeans.api.project.ProjectUtils;
60
import org.netbeans.modules.glassfish.eecommon.api.config.GlassfishConfiguration;
60
import org.netbeans.modules.glassfish.eecommon.api.config.GlassfishConfiguration;
61
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
61
import org.netbeans.modules.glassfish.eecommon.api.config.J2eeModuleHelper;
62
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion;
62
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
63
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
63
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
64
import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
64
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
65
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException;
65
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
66
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
66
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
67
import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
67
import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping;
68
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
68
import org.netbeans.modules.j2ee.sun.api.CmpMappingProvider;
69
import org.netbeans.modules.j2ee.sun.api.CmpMappingProvider;
69
import org.netbeans.modules.j2ee.sun.api.ResourceConfiguratorInterface;
70
import org.netbeans.modules.j2ee.sun.api.ResourceConfiguratorInterface;
70
import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
71
import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
Lines 84-95 Link Here
84
import org.openide.util.RequestProcessor;
85
import org.openide.util.RequestProcessor;
85
86
86
87
87
/** Manages the deployment plan I/O and access for initializing DConfigBeans
88
/**
88
 *
89
 * Manages the deployment plan I/O and access for initializing DConfigBeans
89
 * @author Vince Kraemer
90
 * <p/>
90
 * @author Peter Williams
91
 * @author Vince Kraemer, Peter Williams, Tomas Kraus
91
 */ 
92
 */ 
92
public class SunONEDeploymentConfiguration extends GlassfishConfiguration implements DeploymentConfiguration { //implements Constants, SunDeploymentConfigurationInterface {
93
public class SunONEDeploymentConfiguration
94
extends GlassfishConfiguration implements DeploymentConfiguration {
93
95
94
    /**
96
    /**
95
     * inject cmp bean & field update support into descriptor listener factories
97
     * inject cmp bean & field update support into descriptor listener factories
Lines 108-135 Link Here
108
    private SunDeploymentManagerInterface sdmi;
110
    private SunDeploymentManagerInterface sdmi;
109
    
111
    
110
112
111
    /** Create an instance of SunONEDeploymentConfiguration for GF V2
113
    /**
112
     *  and earlier servers.
114
     * Create an instance of SunONEDeploymentConfiguration for GF V2
115
     * and earlier servers.
113
     *
116
     *
114
     * @param module J2eeModule instance for the project represented by this config.
117
     * @param module  J2eeModule instance for the project represented by this config.
118
     * @param mySdmi  Sun deployment manager.
119
     * @param version GlassFish server version.
115
     *
120
     *
116
     * @throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException
121
     * @throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException
117
     */
122
     */
118
    public SunONEDeploymentConfiguration(J2eeModule module, SunDeploymentManagerInterface mySdmi)
123
    public SunONEDeploymentConfiguration(
119
            throws ConfigurationException {
124
            final J2eeModule module, final SunDeploymentManagerInterface mySdmi,
120
        super(module);
125
            final GlassFishVersion version
126
    ) throws ConfigurationException {
127
        super(module, version);
121
        this.sdmi = mySdmi;
128
        this.sdmi = mySdmi;
122
    }
129
    }
123
130
124
    /** Create an instance of SunONEDeploymentConfiguration for Webserver.
131
    /**
132
     * Create an instance of SunONEDeploymentConfiguration for Webserver.
125
     *
133
     *
126
     * @param module J2eeModule instance for the project represented by this config.
134
     * @param module J2eeModule instance for the project represented by this config.
127
     * @param webServerDDName short name for web server sun dd
135
     * @param webServerDDName short name for web server sun dd
136
     * @param version GlassFish server version.
128
     *
137
     *
129
     * @throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException
138
     * @throws org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException
130
     */
139
     */
131
    public SunONEDeploymentConfiguration(J2eeModule module, String webServerDDName) throws ConfigurationException {
140
    public SunONEDeploymentConfiguration(
132
        super(module, J2eeModuleHelper.getWsModuleHelper(webServerDDName));
141
            final J2eeModule module, final String webServerDDName,
142
            final GlassFishVersion version
143
    ) throws ConfigurationException {
144
        super(module, J2eeModuleHelper.getWsModuleHelper(webServerDDName), version);
133
    }
145
    }
134
146
135
    /** Deprecated form used for JSR-88.  Only exists to keep legacy parts of
147
    /** Deprecated form used for JSR-88.  Only exists to keep legacy parts of

Return to bug 233481