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 181635
Collapse All | Expand All

(-)a/derby/src/org/netbeans/modules/derby/DerbyOptions.java (-3 / +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 1997-2009 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 135-140 Link Here
135
        return location;
135
        return location;
136
    }
136
    }
137
137
138
    private String getCurrentLocation() {
139
        String location = getProperty(PROP_DERBY_LOCATION);
140
        if (location == null) {
141
            location = ""; // NOI18N
142
        }
143
        return location;
144
    }
145
138
    /**
146
    /**
139
     * Returns true if the Derby location is null. This method is needed
147
     * Returns true if the Derby location is null. This method is needed
140
     * since getLocation() will never return a null value.
148
     * since getLocation() will never return a null value.
Lines 181-187 Link Here
181
189
182
    public synchronized boolean trySetLocation(String location) {
190
    public synchronized boolean trySetLocation(String location) {
183
        LOGGER.log(Level.FINE, "trySetLocation: Trying to set location to {0}", location); // NOI18N
191
        LOGGER.log(Level.FINE, "trySetLocation: Trying to set location to {0}", location); // NOI18N
184
        String current = getLocation();
192
        String current = getCurrentLocation();
185
        if (current.length() == 0) {
193
        if (current.length() == 0) {
186
            setLocation(location);
194
            setLocation(location);
187
            LOGGER.fine("trysetLocation: Succeeded"); // NOI18N
195
            LOGGER.fine("trysetLocation: Succeeded"); // NOI18N
(-)cc70edb97d7a (+151 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.derby;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileUtil;
50
51
/**
52
 * Registers installation of JavaDB by creating instance file in cluster config
53
 * directory. Designed to be called from installer.
54
 * The DerbyRegistration can called multiple times but only the first invocation
55
 * is stored.
56
 * <p>
57
 * Sample command line<br>
58
 *
59
 * java -cp platform/core/core.jar:platform/lib/boot.jar:platform/lib/org-openide-modules.jar:
60
 *          platform/core/org-openide-filesystems.jar:platform/lib/org-openide-util.jar:
61
 *          platform/lib/org-openide-util-lookup.jar:ide/modules/org-netbeans-modules-derby.jar
62
 *             org.netbeans.modules.derby.DerbyRegistration nb /usr/local/share/java/jdk1.6.0_18/db
63
 *
64
 * @author Jiri Rechtacek
65
 * @see #main(args)
66
 */
67
public class DerbyRegistration {
68
69
    private static final String DERBY_REGISTRATION_DIR = "JavaDB"; // NOI18N
70
    private static final String DERBY_REGISTRATION_FILE = "registration_instance"; // NOI18N
71
    private static final String ATTR_DERBY_HOME = "javadb_installation_home"; // NOI18N
72
    private static final Logger LOGGER = Logger.getLogger(DerbyRegistration.class.getName());
73
74
    /**
75
     * Performs registration.
76
     *
77
     * Exit codes:<p>
78
     * <ul>
79
     *   <li> 2: could not find/create config/JavaDB folder
80
     *   <li> 3: could not find JavaDB installation home
81
     *   <li> 4: JavaDB installation doesn't contain expected libraries, i.e. lib/derbyclient.jar
82
     *   <li> 5: could not write registration FileObject
83
     * </ul>
84
     * @param args command line arguments - cluster path and Derby home expected
85
     */
86
    public static void main(String[] args) throws IOException {
87
        if (args.length < 2) {
88
            System.out.println("Parameters: <nb clusterDir> <Derby home>");
89
            System.exit(-1);
90
        }
91
92
        int status = registerDerbyInstallation(args[0], args[1]);
93
        System.exit(status);
94
    }
95
96
    private static int registerDerbyInstallation(String cluster, String derbyHome) throws IOException {
97
        LOGGER.log(Level.FINE, "Cluster for JavaDB registration is " + cluster);
98
        System.setProperty("netbeans.user", cluster); // NOI18N
99
        // check writable cluster
100
        FileObject javaDBRegistrationDir = FileUtil.getConfigFile(DERBY_REGISTRATION_DIR);
101
102
        if (javaDBRegistrationDir == null) {
103
            javaDBRegistrationDir = FileUtil.createFolder(FileUtil.getConfigRoot(), DERBY_REGISTRATION_DIR);
104
            if (javaDBRegistrationDir == null) {
105
                LOGGER.log(Level.INFO, "Cannot register the default JavaDB. The config/" + DERBY_REGISTRATION_DIR + " folder cannot be created."); // NOI18N
106
                return 2;
107
            }
108
        }
109
110
        // check if exists
111
        File derbyHomeFile = new File(derbyHome);
112
        if (!derbyHomeFile.exists()) {
113
            LOGGER.log(Level.INFO, "Cannot register the default JavaDB. " // NOI18N
114
                    + "The JavaDB installation directory " + derbyHome // NOI18N
115
                    + " does not exist."); // NOI18N
116
            return 3;
117
        }
118
119
        // check if solid JavaDB home
120
        if (! Util.isDerbyInstallLocation(derbyHomeFile)) {
121
            LOGGER.log(Level.INFO, "Cannot register the default JavaDB. " // NOI18N
122
                    + "The JavaDB installation directory " + derbyHome // NOI18N
123
                    + " does not contain expected libraries."); // NOI18N
124
            return 4;
125
        }
126
127
        FileObject registrationFO = FileUtil.getConfigFile(DERBY_REGISTRATION_DIR + "/" + DERBY_REGISTRATION_FILE); // NOI18N
128
        if (registrationFO == null) {
129
            try {
130
                registrationFO = javaDBRegistrationDir.createData(DERBY_REGISTRATION_FILE);
131
                registrationFO.setAttribute(ATTR_DERBY_HOME, derbyHome);
132
                LOGGER.log(Level.FINE, "New registration links to " + registrationFO.getAttribute(ATTR_DERBY_HOME)); // NOI18N
133
            } catch (IOException e) {
134
                LOGGER.log(Level.INFO, "Cannot register JavaDB, cause " + e.getLocalizedMessage(), e); // NOI18N
135
                return 5;
136
            }
137
        } else {
138
            LOGGER.log(Level.INFO, "The previous registration found. Links to " + registrationFO.getAttribute(ATTR_DERBY_HOME)); // NOI18N
139
        }
140
141
        return 0;
142
    }
143
144
    public static String getRegisteredDerbyHome () {
145
        FileObject registrationFO = FileUtil.getConfigFile(DERBY_REGISTRATION_DIR + "/" + DERBY_REGISTRATION_FILE); // NOI18N
146
        String home = (String) (registrationFO == null ? null : registrationFO.getAttribute(ATTR_DERBY_HOME));
147
        LOGGER.log(Level.FINE, "Registered home is " + home);
148
        return home;
149
    }
150
151
}
(-)a/derby/src/org/netbeans/modules/derby/JDKDerbyHelper.java (+12 lines)
Lines 75-80 Link Here
75
        if (!canBundleDerby()) {
75
        if (!canBundleDerby()) {
76
            return null;
76
            return null;
77
        }
77
        }
78
        // find in registration by NBI
79
        String derbyHome = DerbyRegistration.getRegisteredDerbyHome();
80
        if (derbyHome != null) {
81
            LOGGER.log(Level.FINE, "Registered JavaDB:  " + derbyHome);
82
            File derbyHomeFile = new File(derbyHome);
83
            String result = testDerbyInstallLocation(derbyHomeFile);
84
            if (result != null) {
85
                return result;
86
            }
87
        }
88
89
        // find in JDK
78
        File locInJDK = getLocationInJDK(javaHome);
90
        File locInJDK = getLocationInJDK(javaHome);
79
        if (locInJDK != null) {
91
        if (locInJDK != null) {
80
            LOGGER.log(Level.FINE, "JavaDB in JDK(" + javaVersion + "):  " + locInJDK);
92
            LOGGER.log(Level.FINE, "JavaDB in JDK(" + javaVersion + "):  " + locInJDK);
(-)a/derby/src/org/netbeans/modules/derby/Util.java (+3 lines)
Lines 115-120 Link Here
115
    }
115
    }
116
116
117
    public static boolean isDerbyInstallLocation(File location) {
117
    public static boolean isDerbyInstallLocation(File location) {
118
        if (location == null || ! location.exists()) {
119
            return false;
120
        }
118
        File libDir = new File(location, "lib"); // NOI18N
121
        File libDir = new File(location, "lib"); // NOI18N
119
        if (!libDir.exists()) {
122
        if (!libDir.exists()) {
120
            return false;
123
            return false;

Return to bug 181635