This is an automated email from the ASF dual-hosted git repository. jlahoda pushed a commit to branch jdk-javac in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/jdk-javac by this push: new 824ab39 Adding ability to start on JDK 8 and show a dialog to download nb-javac. 824ab39 is described below commit 824ab395d5ba04d5cb5ab0e533533b974d8fcefb Author: Jan Lahoda <jlah...@netbeans.org> AuthorDate: Fri Dec 15 22:58:11 2017 +0100 Adding ability to start on JDK 8 and show a dialog to download nb-javac. --- java.source.base/manifest.mf | 1 - java.source.base/nbproject/project.xml | 8 ++ .../org/netbeans/api/java/source/JavaSource.java | 3 + .../modules/java/source/NoJavacHelper.java | 99 ++++++++++++++++++++++ .../netbeans/modules/java/source/base/layer.xml | 4 - .../java/source/indexing/JavaCustomIndexer.java | 9 +- .../java/source/parsing/JavacParserFactory.java | 3 + .../modules/java/source/save/Reformatter.java | 3 + .../modules/java/source/save/Reindenter.java | 3 + java.source.jdk9.req/build.xml | 5 -- java.source.jdk9.req/manifest.mf | 7 -- java.source.jdk9.req/nbproject/project.properties | 3 - java.source.jdk9.req/nbproject/project.xml | 11 --- .../modules/java/source/jdk9/req/Bundle.properties | 1 - java.source/nbproject/project.xml | 8 ++ .../modules/java/source/JBrowseModule.java | 62 +++++++++++++- nbbuild/cluster.properties | 1 - .../updatecenters/resources/Bundle.properties | 3 +- 18 files changed, 197 insertions(+), 37 deletions(-) diff --git a/java.source.base/manifest.mf b/java.source.base/manifest.mf index 21b5540..09331a8 100644 --- a/java.source.base/manifest.mf +++ b/java.source.base/manifest.mf @@ -3,4 +3,3 @@ OpenIDE-Module: org.netbeans.modules.java.source.base OpenIDE-Module-Implementation-Version: 2 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/base/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/java/source/base/layer.xml -OpenIDE-Module-Requires: org.netbeans.modules.javac diff --git a/java.source.base/nbproject/project.xml b/java.source.base/nbproject/project.xml index fa276ea..d012fd5 100644 --- a/java.source.base/nbproject/project.xml +++ b/java.source.base/nbproject/project.xml @@ -70,6 +70,14 @@ </run-dependency> </dependency> <dependency> + <code-name-base>org.netbeans.libs.asm</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>5.4</specification-version> + </run-dependency> + </dependency> + <dependency> <code-name-base>org.netbeans.libs.javacapi</code-name-base> <build-prerequisite/> <compile-dependency/> diff --git a/java.source.base/src/org/netbeans/api/java/source/JavaSource.java b/java.source.base/src/org/netbeans/api/java/source/JavaSource.java index 2b66dfb..89acf16 100644 --- a/java.source.base/src/org/netbeans/api/java/source/JavaSource.java +++ b/java.source.base/src/org/netbeans/api/java/source/JavaSource.java @@ -48,6 +48,7 @@ import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.JavaClassPathConstants; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.modules.java.source.JavaSourceAccessor; +import org.netbeans.modules.java.source.NoJavacHelper; import org.netbeans.modules.java.source.parsing.CachingArchiveProvider; import org.netbeans.modules.java.source.parsing.ClassParser; import org.netbeans.modules.java.source.parsing.ClasspathInfoTask; @@ -185,6 +186,8 @@ public final class JavaSource { if (files == null) { throw new IllegalArgumentException (); } + if (!NoJavacHelper.hasWorkingJavac()) + return null; try { return new JavaSource(cpInfo, files); // TODO: Split diff --git a/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java b/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java new file mode 100644 index 0000000..27c612e --- /dev/null +++ b/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java @@ -0,0 +1,99 @@ + /* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 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): + */ +package org.netbeans.modules.java.source; + +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.openide.modules.OnStart; +import sun.misc.Unsafe; + +/** + * + * @author lahvac + */ +public class NoJavacHelper { + + public static boolean hasWorkingJavac() { + try { + Class.forName("javax.lang.model.element.ModuleElement"); + return true; + } catch (ClassNotFoundException ex) { + //OK + return false; + } + } + + public static boolean hasNbJavac() { + try { + Class.forName("com.sun.tools.javac.comp.Repair"); + return true; + } catch (ClassNotFoundException ex) { + //OK + return false; + } + } + + @OnStart + public static class FixClasses implements Runnable { + + @Override + public void run() { + if (!hasWorkingJavac()) { + ClassWriter w = new ClassWriter(0); + w.visit(Opcodes.V1_8, Opcodes.ACC_ABSTRACT | Opcodes.ACC_PUBLIC, "com/sun/tools/javac/code/Scope$WriteableScope", null, "com/sun/tools/javac/code/Scope", null); + byte[] classData = w.toByteArray(); + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + Unsafe unsafe = (Unsafe) theUnsafe.get(null); + Class scopeClass = Class.forName("com.sun.tools.javac.code.Scope"); + unsafe.defineClass("com.sun.tools.javac.code.Scope$WriteableScope", classData, 0, classData.length, scopeClass.getClassLoader(), scopeClass.getProtectionDomain()); + } catch (Throwable t) { + //ignore... + Logger.getLogger(NoJavacHelper.class.getName()).log(Level.FINE, null, t); + } + } + } + + } +} diff --git a/java.source.base/src/org/netbeans/modules/java/source/base/layer.xml b/java.source.base/src/org/netbeans/modules/java/source/base/layer.xml index 7716cef..1dad21e 100644 --- a/java.source.base/src/org/netbeans/modules/java/source/base/layer.xml +++ b/java.source.base/src/org/netbeans/modules/java/source/base/layer.xml @@ -37,10 +37,6 @@ <file name="Reindenter.instance"> <attr name="instanceClass" stringvalue="org.netbeans.modules.java.source.save.Reindenter$Factory"/> </file> - <file name="JavaIndexer.instance"> - <attr name="instanceClass" stringvalue="org.netbeans.modules.java.source.indexing.JavaCustomIndexer$Factory"/> - <!--attr name="position" intvalue="1000"/--> - </file> <file name="SourcePathCheck.instance"> <attr name="instanceClass" stringvalue="org.netbeans.modules.java.source.classpath.SourcePathCheck$Factory"/> </file> diff --git a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java b/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java index 9c2d0ba..8e5a3b0 100644 --- a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java +++ b/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java @@ -66,6 +66,7 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; +import org.netbeans.api.editor.mimelookup.MimeRegistration; //import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.JavaClassPathConstants; @@ -79,6 +80,7 @@ import org.netbeans.api.project.Project; import org.netbeans.modules.java.source.ElementHandleAccessor; import org.netbeans.modules.java.source.JavaSourceTaskFactoryManager; import org.netbeans.modules.java.source.ModuleNames; +import org.netbeans.modules.java.source.NoJavacHelper; import org.netbeans.modules.java.source.base.Module; import org.netbeans.modules.java.source.parsing.FileManagerTransaction; import org.netbeans.modules.java.source.parsing.FileObjects; @@ -1175,7 +1177,12 @@ public class JavaCustomIndexer extends CustomIndexer { @Override public int hashCode() { return getIndexerName().hashCode(); - } + } + + @MimeRegistration(mimeType="text/x-java", service=CustomIndexerFactory.class) + public static Factory register() { + return NoJavacHelper.hasWorkingJavac() ? new Factory() : null; + } } public static final class CompileTuple { diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParserFactory.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParserFactory.java index 85b26db..68e21e2 100644 --- a/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParserFactory.java +++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParserFactory.java @@ -26,6 +26,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.modules.java.source.NoJavacHelper; import org.netbeans.modules.parsing.api.Snapshot; import org.netbeans.modules.parsing.spi.ParserFactory; import org.openide.filesystems.FileObject; @@ -49,6 +50,8 @@ public class JavacParserFactory extends ParserFactory { @Override public JavacParser createParser(final Collection<Snapshot> snapshots) { + if (!NoJavacHelper.hasWorkingJavac()) + return null; assert snapshots != null; if (snapshots.size() == 1) { final FileObject fo = snapshots.iterator().next().getSource().getFileObject(); diff --git a/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java b/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java index 4cb8a31..433493d 100644 --- a/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java +++ b/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java @@ -52,6 +52,7 @@ import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.editor.indent.spi.ExtraLock; import org.netbeans.modules.editor.indent.spi.ReformatTask; import org.netbeans.modules.java.source.JavaSourceAccessor; +import org.netbeans.modules.java.source.NoJavacHelper; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.modules.parsing.api.Embedding; @@ -384,6 +385,8 @@ public class Reformatter implements ReformatTask { public static class Factory implements ReformatTask.Factory { public ReformatTask createTask(Context context) { + if (!NoJavacHelper.hasWorkingJavac()) + return null; Source source = Source.create(context.document()); return source != null ? new Reformatter(source, context) : null; } diff --git a/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java b/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java index b719866..99b2f7c 100644 --- a/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java +++ b/java.source.base/src/org/netbeans/modules/java/source/save/Reindenter.java @@ -75,6 +75,7 @@ import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.editor.indent.spi.Context.Region; import org.netbeans.modules.editor.indent.spi.ExtraLock; import org.netbeans.modules.editor.indent.spi.IndentTask; +import org.netbeans.modules.java.source.NoJavacHelper; import org.netbeans.modules.java.source.parsing.FileObjects; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.modules.java.source.parsing.ParsingUtils; @@ -1203,6 +1204,8 @@ public class Reindenter implements IndentTask { @Override public IndentTask createTask(Context context) { + if (!NoJavacHelper.hasWorkingJavac()) + return null; return new Reindenter(context); } } diff --git a/java.source.jdk9.req/build.xml b/java.source.jdk9.req/build.xml deleted file mode 100644 index 3ee732c..0000000 --- a/java.source.jdk9.req/build.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project basedir="." default="netbeans" name="java.source.jdk9.req"> - <description>Builds, tests, and runs the project org.netbeans.modules.java.source.jdk9.req</description> - <import file="../nbbuild/templates/projectized.xml"/> -</project> diff --git a/java.source.jdk9.req/manifest.mf b/java.source.jdk9.req/manifest.mf deleted file mode 100644 index 9ab42f9..0000000 --- a/java.source.jdk9.req/manifest.mf +++ /dev/null @@ -1,7 +0,0 @@ -Manifest-Version: 1.0 -AutoUpdate-Show-In-Client: false -OpenIDE-Module: org.netbeans.modules.java.source.jdk9.req -OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/jdk9/req/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 -OpenIDE-Module-Package-Dependencies: [com.sun.source.tree.ModuleTree] -OpenIDE-Module-Provides: org.netbeans.modules.javac diff --git a/java.source.jdk9.req/nbproject/project.properties b/java.source.jdk9.req/nbproject/project.properties deleted file mode 100644 index ff160e0..0000000 --- a/java.source.jdk9.req/nbproject/project.properties +++ /dev/null @@ -1,3 +0,0 @@ -is.eager=true -javac.source=1.7 -javac.compilerargs=-Xlint -Xlint:-serial diff --git a/java.source.jdk9.req/nbproject/project.xml b/java.source.jdk9.req/nbproject/project.xml deleted file mode 100644 index 43d5e53..0000000 --- a/java.source.jdk9.req/nbproject/project.xml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>org.netbeans.modules.java.source.jdk9.req</code-name-base> - <module-dependencies/> - <public-packages/> - </data> - </configuration> -</project> diff --git a/java.source.jdk9.req/src/org/netbeans/modules/java/source/jdk9/req/Bundle.properties b/java.source.jdk9.req/src/org/netbeans/modules/java/source/jdk9/req/Bundle.properties deleted file mode 100644 index 3991227..0000000 --- a/java.source.jdk9.req/src/org/netbeans/modules/java/source/jdk9/req/Bundle.properties +++ /dev/null @@ -1 +0,0 @@ -OpenIDE-Module-Name=Java Source JDK 9 Required diff --git a/java.source/nbproject/project.xml b/java.source/nbproject/project.xml index 9474f22..8b375b2 100644 --- a/java.source/nbproject/project.xml +++ b/java.source/nbproject/project.xml @@ -121,6 +121,14 @@ </run-dependency> </dependency> <dependency> + <code-name-base>org.netbeans.modules.autoupdate.ui</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.46</specification-version> + </run-dependency> + </dependency> + <dependency> <code-name-base>org.netbeans.modules.classfile</code-name-base> <build-prerequisite/> <compile-dependency/> diff --git a/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java b/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java index 2ea38ba..ebc853a 100644 --- a/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java +++ b/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java @@ -19,8 +19,23 @@ package org.netbeans.modules.java.source; +import java.awt.Dialog; +import java.util.Arrays; +import java.util.HashSet; +import java.util.prefs.Preferences; +import org.netbeans.modules.autoupdate.ui.api.PluginManager; import org.netbeans.modules.java.source.usages.ClassIndexManager; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.awt.NotificationDisplayer; +import org.openide.awt.NotificationDisplayer.Priority; +import org.openide.awt.StatusDisplayer; import org.openide.modules.ModuleInstall; +import org.openide.util.HelpCtx; +import org.openide.util.ImageUtilities; +import org.openide.util.NbBundle; +import org.openide.util.NbPreferences; +import org.openide.windows.WindowManager; /** * @@ -34,8 +49,51 @@ public class JBrowseModule extends ModuleInstall { /** Creates a new instance of JBrowseModule */ public JBrowseModule() { } - - + + public static final String KEY_WARNING_SHOWN = "nb-javac.warning.shown"; + + @Override + @NbBundle.Messages({ + "TITLE_FeaturesLimited=Java features limited", + "DESC_FeaturesLimited=<html>No supported javac library available." + + " Most Java editing features are disabled." + + " Please either:" + + "<ul>" + + "<li>install nb-javac library (<b>highly recommended</b>)</li>" + + "<li>run NetBeans on JDK 9 or later</li>" + + "</ul>", + "BN_Install=Install nb-javac", + "DN_nbjavac=nb-javac library" + }) + public void restored() { + WindowManager.getDefault().invokeWhenUIReady(() -> { + WindowManager.getDefault().invokeWhenUIReady(() -> { + Preferences prefs = NbPreferences.forModule(NoJavacHelper.class); + if (!NoJavacHelper.hasWorkingJavac() && !prefs.getBoolean(KEY_WARNING_SHOWN, false)) { + String install = Bundle.BN_Install(); + Dialog[] d = new Dialog[1]; + DialogDescriptor dd = new DialogDescriptor(Bundle.DESC_FeaturesLimited(), Bundle.TITLE_FeaturesLimited(), true, new Object[] {install, DialogDescriptor.CANCEL_OPTION}, install, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, evt -> { + if (install.equals(evt.getActionCommand())) { + PluginManager.installSingle("org.netbeans.modules.nbjavac", Bundle.DN_nbjavac()); + } + d[0].setVisible(false); + }); + d[0] = DialogDisplayer.getDefault().createDialog(dd); + d[0].setVisible(true); + prefs.putBoolean(KEY_WARNING_SHOWN, true); + } + + if (!NoJavacHelper.hasNbJavac()) { + NotificationDisplayer.getDefault().notify("Install nb-javac Library", ImageUtilities.loadImageIcon("/org/netbeans/modules/java/source/resources/icons/warning.png", false), "It is recommended to install nb-javac Library to improve Java editing experience.", evt -> { + PluginManager.installSingle("org.netbeans.modules.nbjavac", Bundle.DN_nbjavac()); + }, prefs.getBoolean(KEY_WARNING_SHOWN, false) ? Priority.SILENT : Priority.HIGH); + prefs.putBoolean(KEY_WARNING_SHOWN, true); + } + }); + }); + super.restored(); + } + @Override public void close () { super.close(); diff --git a/nbbuild/cluster.properties b/nbbuild/cluster.properties index 6c8f868..e0ff36b 100644 --- a/nbbuild/cluster.properties +++ b/nbbuild/cluster.properties @@ -621,7 +621,6 @@ nb.cluster.java=\ java.source.ant,\ java.source.base,\ java.source.compat8,\ - java.source.jdk9.req,\ java.source.nbjavac,\ java.source.queries,\ java.source.queriesimpl,\ diff --git a/updatecenters/src/org/netbeans/modules/updatecenters/resources/Bundle.properties b/updatecenters/src/org/netbeans/modules/updatecenters/resources/Bundle.properties index 7f6e4b5..a96dae0 100644 --- a/updatecenters/src/org/netbeans/modules/updatecenters/resources/Bundle.properties +++ b/updatecenters/src/org/netbeans/modules/updatecenters/resources/Bundle.properties @@ -31,4 +31,5 @@ URL_LatestBuild=http://bits.netbeans.org/dev/nbms-and-javadoc/lastSuccessfulBuil #NOI18N URL_Default_N=http://updates.netbeans.org/netbeans/updates/dev/uc/final/main/catalog.xml.gz?{$netbeans.hash.code} #NOI18N -URL_PluginPortal=http://plugins.netbeans.org/nbpluginportal/updates/8.2/catalog.xml.gz +#URL_PluginPortal=http://plugins.netbeans.org/nbpluginportal/updates/8.2/catalog.xml.gz +URL_PluginPortal=http://lahoda.info/hudson/job/nb-javac_Library/lastSuccessfulBuild/artifact/make/netbeans/nb-javac-modules/build/updates/updates.xml -- To stop receiving notification emails like this one, please contact ['"comm...@netbeans.apache.org" <comm...@netbeans.apache.org>'].