netbeans-no-javac-patch / add-javac-action

# HG changeset patch
# Parent 1a16e507382166ef7c55d3fdb67f06e83097924a

diff -r 1a16e5073821 java.debug/nbproject/project.xml
--- a/java.debug/nbproject/project.xml	Wed Aug 08 22:04:32 2012 +0200
+++ b/java.debug/nbproject/project.xml	Sat Oct 06 10:28:48 2012 -0700
@@ -119,6 +119,14 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.openide.awt</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>7.50</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.openide.explorer</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -143,6 +151,14 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.openide.modules</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>7.33</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.openide.nodes</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -174,6 +190,14 @@
                         <specification-version>8.0</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.openide.windows</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>6.57</specification-version>
+                    </run-dependency>
+                </dependency>
             </module-dependencies>
             <public-packages/>
         </data>
diff -r 1a16e5073821 java.debug/src/org/netbeans/modules/java/debug/SetDifferentJavac.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java.debug/src/org/netbeans/modules/java/debug/SetDifferentJavac.java	Sat Oct 06 10:28:48 2012 -0700
@@ -0,0 +1,130 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.java.debug;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.regex.Pattern;
+import javax.swing.JFileChooser;
+import org.openide.LifecycleManager;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.filesystems.FileUtil;
+import org.openide.modules.InstalledFileLocator;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.WindowManager;
+
+@ActionID(
+    category = "Tools",
+id = "org.netbeans.modules.java.debug.SetDifferentJavac")
+@ActionRegistration(
+    displayName = "#CTL_SetDifferentJavac")
+@ActionReference(path = "Menu/Tools", position = 1400)
+@Messages("CTL_SetDifferentJavac=Set Different Javac")
+public final class SetDifferentJavac implements ActionListener {
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        try {
+            Pattern apiPattern = Pattern.compile("(com/sun/javadoc/|com/sun/source/|javax/lang/|javax/tools/|javax/annotation/).*");
+            File ext = InstalledFileLocator.getDefault().locate("modules/ext/nb-javac-api.jar", null, false);
+            
+            if (ext == null || !ext.canRead()) {
+                //TODO: show warning to the user
+                return ;
+            }
+            
+            ext = ext.getParentFile();
+            
+            JFileChooser pickJavac = new JFileChooser();
+            
+            pickJavac.setDialogTitle("Select javac");
+            
+            if (pickJavac.showDialog(WindowManager.getDefault().getMainWindow(), "Install") != JFileChooser.APPROVE_OPTION) return ;
+            
+            JarInputStream javacJar = new JarInputStream(new BufferedInputStream(new FileInputStream(pickJavac.getSelectedFile())));
+            
+            File javacApi = new File(ext, "nb-javac-api.jar");
+            File javacImpl = new File(ext, "nb-javac-impl.jar");
+            File javacApiOrig = new File(ext, "nb-javac-api.jar.orig");
+            File javacImplOrig = new File(ext, "nb-javac-impl.jar.orig");
+            
+            if (!javacApiOrig.canRead()) javacApi.renameTo(javacApiOrig);
+            if (!javacImplOrig.canRead()) javacApi.renameTo(javacImplOrig);
+            
+            JarOutputStream javacApiJar = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(javacApi)));
+            JarOutputStream javacImplJar = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(javacImpl)));
+            
+            JarEntry je;
+            
+            while ((je = javacJar.getNextJarEntry()) != null) {
+                if (apiPattern.matcher(je.getName()).matches()) {
+                    javacApiJar.putNextEntry(je);
+                    FileUtil.copy(javacJar, javacApiJar);
+                } else {
+                    javacImplJar.putNextEntry(je);
+                    FileUtil.copy(javacJar, javacImplJar);
+                }
+            }
+            
+            javacApiJar.close();
+            javacImplJar.close();
+            javacJar.close();
+            
+            LifecycleManager.getDefault().markForRestart();
+            LifecycleManager.getDefault().exit();
+        } catch (IOException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.