http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ant/nbproject/project.properties ---------------------------------------------------------------------- diff --git a/cmdline/ant/nbproject/project.properties b/cmdline/ant/nbproject/project.properties new file mode 100644 index 0000000..8dcf0b7 --- /dev/null +++ b/cmdline/ant/nbproject/project.properties @@ -0,0 +1,119 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Jackpot 3.0 Command Line Tool Ant Bridge +application.vendor=lahvac +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/jackpot-ant.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.ant-testutil.jar=${var.nbplatform.default.netbeans.dest.dir}/extide/ant/lib/ant-testutil.jar +file.reference.ant.jar=${var.nbplatform.default.netbeans.dest.dir}/extide/ant/lib/ant.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.ant.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${file.reference.ant-testutil.jar}:\ + ${libs.junit.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ant.Ant +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ant/nbproject/project.xml ---------------------------------------------------------------------- diff --git a/cmdline/ant/nbproject/project.xml b/cmdline/ant/nbproject/project.xml new file mode 100644 index 0000000..ec7d544 --- /dev/null +++ b/cmdline/ant/nbproject/project.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-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]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +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. +--> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.java.j2seproject</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/j2se-project/3"> + <name>Jackpot 3.0 Command Line Tool Ant Bridge</name> + <source-roots> + <root id="src.dir"/> + </source-roots> + <test-roots> + <root id="test.src.dir"/> + </test-roots> + </data> + </configuration> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ant/src/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTask.java ---------------------------------------------------------------------- diff --git a/cmdline/ant/src/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTask.java b/cmdline/ant/src/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTask.java new file mode 100644 index 0000000..1a6f523 --- /dev/null +++ b/cmdline/ant/src/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTask.java @@ -0,0 +1,139 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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.jackpot30.cmdline.ant; + +import java.io.IOException; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.LogStreamHandler; +import org.apache.tools.ant.types.CommandlineJava; +import org.apache.tools.ant.types.Path; + +/** + * + * @author lahvac + */ +public class JackpotTask extends Task { + + private String jackpotHome; + + public void setJackpotHome(String jackpotHome) { + this.jackpotHome = jackpotHome; + } + + private Path src; + + public Path createSrc() { + return src = new Path(getProject()); + } + + private String sourcepath; + + public void setSourcepath(String sourcepath) { + this.sourcepath = sourcepath; + } + + private String sourcelevel; + + public void setSource(String sourcelevel) { + this.sourcelevel = sourcelevel; + } + + private Path classpath; + + public Path createClasspath() { + return this.classpath = new Path(getProject()); + } + + public Path getClasspath() { + return classpath != null ? classpath : createClasspath(); + } + + private String configFile; + + public void setConfigfile(String file) { + this.configFile = file; + } + + @Override + public void execute() throws BuildException { + try { + CommandlineJava cmdLine = new CommandlineJava(); + + if (jackpotHome == null) { + throw new BuildException("Must specify jackpotHome"); + } + + Path srcPath = src; + + if (srcPath == null) { + if (sourcepath == null) { + throw new BuildException("Must specify either src subelement or sourcepath"); + } + + srcPath = new Path(getProject(), sourcepath); + } + + cmdLine.createClasspath(getProject()).add(new Path(getProject(), jackpotHome + "/jackpot.jar")); + cmdLine.setClassname("org.netbeans.modules.jackpot30.cmdline.Main"); + + addArguments(cmdLine, "-no-apply"); + addArguments(cmdLine, "-sourcepath", srcPath.toString()); + addArguments(cmdLine, "-classpath", getClasspath().toString()); + if (sourcelevel != null) addArguments(cmdLine, "--source", sourcelevel); + if (configFile != null) addArguments(cmdLine, "--config-file", configFile); + addArguments(cmdLine, srcPath.list()); + + Execute exec = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN)); + exec.setCommandline(cmdLine.getCommandline()); + exec.execute(); + } catch (IOException ex) { + throw new BuildException(ex); + } + } + + private static void addArguments(CommandlineJava cmdLine, String... args) { + for (String arg : args) { + cmdLine.createArgument().setValue(arg); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ant/test/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTaskTest.java ---------------------------------------------------------------------- diff --git a/cmdline/ant/test/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTaskTest.java b/cmdline/ant/test/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTaskTest.java new file mode 100644 index 0000000..09730a6 --- /dev/null +++ b/cmdline/ant/test/org/netbeans/modules/jackpot30/cmdline/ant/JackpotTaskTest.java @@ -0,0 +1,84 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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.jackpot30.cmdline.ant; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import org.apache.tools.ant.BuildFileTest; + +/** + * + * @author lahvac + */ +public class JackpotTaskTest extends BuildFileTest { + + public JackpotTaskTest(String testName) { + super(testName); + } + + public void testFailNoHome() throws Exception { + prepareTest("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<project name=\"test\" default=\"run\" basedir=\".\">\n" + + " <target name=\"run\">\n" + + " <taskdef name=\"jackpot\" classname=\"org.netbeans.modules.jackpot30.cmdline.ant.JackpotTask\" classpath=\"" + System.getProperty("java.class.path") + "\"/>\n" + + " <jackpot>\n" + + " <src>\n" + + " <pathelement path=\"src\" />\n" + + " </src>\n" + + " </jackpot>\n" + + " </target>\n" + + "</project>\n"); + expectBuildException("run", "Must specify jackpotHome"); + } + + private void prepareTest(String code) throws IOException { + File tempBuild = File.createTempFile("jackpot-ant-test", ".xml"); + + tempBuild.deleteOnExit(); + + OutputStream out = new FileOutputStream(tempBuild); + + out.write(code.getBytes("UTF-8")); + out.close(); + + configureProject(tempBuild.getAbsolutePath()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/build.xml ---------------------------------------------------------------------- diff --git a/cmdline/ap/build.xml b/cmdline/ap/build.xml new file mode 100644 index 0000000..eeacbd0 --- /dev/null +++ b/cmdline/ap/build.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-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]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +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. +--> +<!-- You may freely edit this file. See harness/README in the NetBeans platform --> +<!-- for some information on what you could do (e.g. targets to override). --> +<!-- If you delete this file and reopen the project it will be recreated. --> +<project name="org.netbeans.modules.jackpot30.ap" default="netbeans" basedir="."> + <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.ap.</description> + <import file="nbproject/build-impl.xml"/> + <property name="bootclasspath.prepend" value="" /> + <import file="${suite.dir}/../findbugs-import.xml"/> + + <target name="-check-lib-exists" depends="files-init"> + <condition property="jackpot.lib.exists" value="true"> + <available file="${build.dir}/jackpot-ap-lib.jar" /> + </condition> + </target> + <target name="build-init" depends="harness.build-init,-check-lib-exists" unless="jackpot.lib.exists"> + <mkdir dir="${build.dir}/" /> + <ant dir="../lib" target="test" inheritall="false" inheritrefs="false"> + <property name="test.config.standalone.includes" value="org/netbeans/modules/jackpot30/cmdline/lib/CreateAPLibJar.class"/> + <property name="test.config" value="standalone"/> + <property name="test-unit-sys-prop.outputDir" location="${build.dir}/" /> + </ant> + </target> + <target name="build-ap-jar" depends="compile"> + <delete dir="${build.dir}/temp-unpack" failonerror="false"/> + <mkdir dir="${build.dir}/temp-unpack" /> + <unjar src="${build.dir}/jackpot-ap-lib.jar" dest="${build.dir}/temp-unpack" /> + <copy todir="${build.dir}/temp-unpack"> + <fileset dir="${build.classes.dir}"/> + </copy> + <jar destfile="${build.dir}/jackpot-ap.jar" basedir="${build.dir}/temp-unpack" /> + </target> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/manifest.mf ---------------------------------------------------------------------- diff --git a/cmdline/ap/manifest.mf b/cmdline/ap/manifest.mf new file mode 100644 index 0000000..b85e04a --- /dev/null +++ b/cmdline/ap/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +AutoUpdate-Show-In-Client: true +OpenIDE-Module: org.netbeans.modules.jackpot30.ap +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/ap/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/nbproject/build-impl.xml ---------------------------------------------------------------------- diff --git a/cmdline/ap/nbproject/build-impl.xml b/cmdline/ap/nbproject/build-impl.xml new file mode 100644 index 0000000..cafa5ab --- /dev/null +++ b/cmdline/ap/nbproject/build-impl.xml @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-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]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +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. +--> +<!-- +*** GENERATED FROM project.xml - DO NOT EDIT *** +*** EDIT ../build.xml INSTEAD *** +--> +<project name="org.netbeans.modules.jackpot30.ap-impl" basedir=".."> + <fail message="Please build using Ant 1.7.1 or higher."> + <condition> + <not> + <antversion atleast="1.7.1"/> + </not> + </condition> + </fail> + <property file="nbproject/private/suite-private.properties"/> + <property file="nbproject/suite.properties"/> + <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail> + <property file="${suite.dir}/nbproject/private/platform-private.properties"/> + <property file="${suite.dir}/nbproject/platform.properties"/> + <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2"> + <attribute name="property"/> + <attribute name="value"/> + <sequential> + <property name="@{property}" value="@{value}"/> + </sequential> + </macrodef> + <property file="${user.properties.file}"/> + <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness)."> + <condition> + <not> + <contains string="${cluster.path.evaluated}" substring="platform"/> + </not> + </condition> + </fail> + <import file="${harness.dir}/build.xml"/> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/nbproject/genfiles.properties ---------------------------------------------------------------------- diff --git a/cmdline/ap/nbproject/genfiles.properties b/cmdline/ap/nbproject/genfiles.properties new file mode 100644 index 0000000..63813c3 --- /dev/null +++ b/cmdline/ap/nbproject/genfiles.properties @@ -0,0 +1,49 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. +build.xml.data.CRC32=abf35b3d +build.xml.script.CRC32=434ef419 [email protected] +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=abf35b3d +nbproject/build-impl.xml.script.CRC32=dd901283 +nbproject/[email protected] http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/nbproject/project.properties ---------------------------------------------------------------------- diff --git a/cmdline/ap/nbproject/project.properties b/cmdline/ap/nbproject/project.properties new file mode 100644 index 0000000..cc6e499 --- /dev/null +++ b/cmdline/ap/nbproject/project.properties @@ -0,0 +1,44 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. +javac.source=1.7 +javac.compilerargs=-Xlint -Xlint:-serial +cp.extra=build/jackpot-ap-lib.jar:${tools.jar} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/nbproject/project.xml ---------------------------------------------------------------------- diff --git a/cmdline/ap/nbproject/project.xml b/cmdline/ap/nbproject/project.xml new file mode 100644 index 0000000..eaa7cb1 --- /dev/null +++ b/cmdline/ap/nbproject/project.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-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]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +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. +--> +<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.jackpot30.ap</code-name-base> + <suite-component/> + <module-dependencies/> + <test-dependencies> + <test-type> + <name>unit</name> + <test-dependency> + <code-name-base>org.netbeans.libs.junit4</code-name-base> + <compile-dependency/> + </test-dependency> + <test-dependency> + <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base> + <compile-dependency/> + </test-dependency> + <test-dependency> + <code-name-base>org.netbeans.modules.nbjunit</code-name-base> + <recursive/> + <compile-dependency/> + </test-dependency> + </test-type> + </test-dependencies> + <public-packages/> + </data> + </configuration> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/nbproject/suite.properties ---------------------------------------------------------------------- diff --git a/cmdline/ap/nbproject/suite.properties b/cmdline/ap/nbproject/suite.properties new file mode 100644 index 0000000..942e12b --- /dev/null +++ b/cmdline/ap/nbproject/suite.properties @@ -0,0 +1,42 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. +suite.dir=${basedir}/.. http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/src/META-INF/services/javax.annotation.processing.Processor ---------------------------------------------------------------------- diff --git a/cmdline/ap/src/META-INF/services/javax.annotation.processing.Processor b/cmdline/ap/src/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..d71e298 --- /dev/null +++ b/cmdline/ap/src/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,43 @@ + # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + # + # Copyright 2009-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]" + # + # Contributor(s): + # + # The Original Software is NetBeans. The Initial Developer of the Original + # Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun + # Microsystems, Inc. All Rights Reserved. + # + # 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. + +org.netbeans.modules.jackpot30.ap.ProcessorImpl http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/Bundle.properties ---------------------------------------------------------------------- diff --git a/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/Bundle.properties b/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/Bundle.properties new file mode 100644 index 0000000..d79e3fa --- /dev/null +++ b/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/Bundle.properties @@ -0,0 +1,42 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. +OpenIDE-Module-Name=Jackpot 3.0 Annotation Processing http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/ProcessorImpl.java ---------------------------------------------------------------------- diff --git a/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/ProcessorImpl.java b/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/ProcessorImpl.java new file mode 100644 index 0000000..4bacc97 --- /dev/null +++ b/cmdline/ap/src/org/netbeans/modules/jackpot30/ap/ProcessorImpl.java @@ -0,0 +1,402 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2015 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 2015 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.ap; + +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.Tree; +import com.sun.source.util.SourcePositions; +import com.sun.source.util.TreePath; +import com.sun.source.util.TreePathScanner; +import com.sun.source.util.Trees; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.prefs.AbstractPreferences; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedOptions; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaFileManager; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.source.ClasspathInfo; +import org.netbeans.api.java.source.CompilationController; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.Task; +import org.netbeans.modules.editor.tools.storage.api.ToolPreferences; +import org.netbeans.modules.jackpot30.cmdline.lib.Utils; +import org.netbeans.modules.java.hints.providers.spi.HintDescription; +import org.netbeans.modules.java.hints.providers.spi.HintMetadata; +import org.netbeans.modules.java.hints.spiimpl.RulesManager; +import org.netbeans.modules.java.hints.spiimpl.hints.HintsInvoker; +import org.netbeans.modules.java.hints.spiimpl.options.HintsSettings; +import org.netbeans.modules.parsing.impl.indexing.CacheFolder; +import org.netbeans.spi.editor.hints.ErrorDescription; +import org.netbeans.spi.editor.hints.Severity; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.URLMapper; +import org.openide.util.Lookup; + +/** + * + * @author lahvac + */ +@SupportedAnnotationTypes("*") +@SupportedOptions("hintsConfiguration") +public class ProcessorImpl extends AbstractProcessor { + + public static final String CONFIGURATION_OPTION = "hintsConfiguration"; + private final Map<URL, String> sources = new HashMap<>(); + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + final Trees trees = Trees.instance(processingEnv); + + if (!roundEnv.processingOver()) { + for (Element root : roundEnv.getRootElements()) { + TypeElement outtermost = outtermostType(root); + TreePath path = trees.getPath(outtermost); + + if (path == null) { + //TODO: log + continue; + } + + try { + sources.put(path.getCompilationUnit().getSourceFile().toUri().toURL(), outtermost.getQualifiedName().toString()); + } catch (MalformedURLException ex) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Unexpected exception: " + ex.getMessage()); + Logger.getLogger(ProcessorImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + } else { + try { + Field contextField = processingEnv.getClass().getDeclaredField("context"); + contextField.setAccessible(true); + Object context = contextField.get(processingEnv); + Method get = context.getClass().getDeclaredMethod("get", Class.class); + JavaFileManager fileManager = (JavaFileManager) get.invoke(context, JavaFileManager.class); + + if (!(fileManager instanceof StandardJavaFileManager)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "The file manager is not a StandardJavaFileManager, cannot run Jackpot 3.0."); + return false; + } + + setupCache(); + + StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager; + + ClassPath bootCP = toClassPath(sfm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)); + ClassPath compileCP = toClassPath(sfm.getLocation(StandardLocation.CLASS_PATH)); + Iterable<? extends File> sourcePathLocation = sfm.getLocation(StandardLocation.SOURCE_PATH); + ClassPath sourceCP = sourcePathLocation != null ? toClassPath(sourcePathLocation) : inferSourcePath(); + + final Map<FileObject, String> sourceFiles = new HashMap<>(); + + for (Entry<URL, String> e : sources.entrySet()) { + FileObject fo = URLMapper.findFileObject(e.getKey()); + if (fo == null) { + //XXX: + return false; + } + sourceFiles.put(fo, e.getValue()); + } + + final Map<HintMetadata, ? extends Collection<? extends HintDescription>> allHints = RulesManager.getInstance().readHints(null, Arrays.asList(bootCP, compileCP, sourceCP), new AtomicBoolean()); + List<HintDescription> hints = new ArrayList<>(); + for (Collection<? extends HintDescription> v : allHints.values()) { + hints.addAll(v); + } + final Map<String, String> id2DisplayName = Utils.computeId2DisplayName(hints); + final Map<HintMetadata, ? extends Collection<? extends HintDescription>> hardcodedHints = RulesManager.getInstance().readHints(null, null, new AtomicBoolean()); + final HintsSettings settings; + String configurationFileLoc = processingEnv.getOptions().get(CONFIGURATION_OPTION); + File configurationFile = configurationFileLoc != null ? new File(configurationFileLoc) : null; + + if (configurationFile == null || !configurationFile.canRead()) { + settings = new HintsSettings() { + + @Override + public boolean isEnabled(HintMetadata hm) { + return !hardcodedHints.containsKey(hm) ? hm.enabled : false; + } + + @Override + public void setEnabled(HintMetadata hm, boolean bln) { + throw new UnsupportedOperationException(); + } + + @Override + public Preferences getHintPreferences(HintMetadata hm) { + return new DummyPreferences(null, ""); + } + + @Override + public Severity getSeverity(HintMetadata hm) { + return hm.severity; + } + + @Override + public void setSeverity(HintMetadata hm, Severity svrt) { + throw new UnsupportedOperationException(); + } + }; + } else { + settings = HintsSettings.createPreferencesBasedHintsSettings(ToolPreferences.from(configurationFile.toURI()).getPreferences("hints", "text/x-java"), true, null); + } + + ClasspathInfo cpInfo = ClasspathInfo.create(bootCP, compileCP, sourceCP); + + JavaSource.create(cpInfo, sourceFiles.keySet()).runUserActionTask(new Task<CompilationController>() { + + @Override + public void run(CompilationController parameter) throws Exception { + if (parameter.toPhase(JavaSource.Phase.RESOLVED).compareTo(JavaSource.Phase.RESOLVED) < 0) { + return; + } + + List<ErrorDescription> eds = new HintsInvoker(settings, /*XXX*/new AtomicBoolean()).computeHints(parameter); + + if (eds != null) { + for (ErrorDescription ed : eds) { + String outtermost = sourceFiles.get(ed.getFile()); + TypeElement type = processingEnv.getElementUtils().getTypeElement(outtermost); //XXX: package-info!!! + TreePath typePath = trees.getPath(type); + TreePath posPath = pathFor(typePath.getCompilationUnit(), trees.getSourcePositions(), ed.getRange().getBegin().getOffset()); + String category = Utils.categoryName(ed.getId(), id2DisplayName); + Kind diagKind; + switch (ed.getSeverity()) { + case ERROR: diagKind = Kind.ERROR; break; + case VERIFIER: + case WARNING: diagKind = Kind.WARNING; break; + case HINT: + default: diagKind = Kind.NOTE; break; + } + trees.printMessage(diagKind, category + ed.getDescription(), posPath.getLeaf(), posPath.getCompilationUnit()); + } + } + } + }, true); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | IOException ex) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Unexpected exception: " + ex.getMessage()); + Logger.getLogger(ProcessorImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + + return false; + } + + private static ClassPath toClassPath(Iterable<? extends File> files) throws MalformedURLException { + Collection<URL> roots = new ArrayList<>(); + + if (files != null) { + for (File f : files) { + roots.add(FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(f))); + } + } + + return ClassPathSupport.createClassPath(roots.toArray(new URL[0])); + } + + private void setupCache() throws IOException { + File tmp = File.createTempFile("jackpot30", null); + + tmp.delete(); + tmp.mkdirs(); + tmp.deleteOnExit(); + + tmp = FileUtil.normalizeFile(tmp); + FileUtil.refreshFor(tmp.getParentFile()); + + org.openide.filesystems.FileObject tmpFO = FileUtil.toFileObject(tmp); + + if (tmpFO != null) { + CacheFolder.setCacheFolder(tmpFO); + } + } + + private TypeElement outtermostType(Element el) { + while (el.getEnclosingElement().getKind() != ElementKind.PACKAGE) { //XXX: package-info! + el = el.getEnclosingElement(); + } + return (TypeElement) el; + } + + private TreePath pathFor(final CompilationUnitTree cut, final SourcePositions sp, final long pos) { + class Result extends RuntimeException { + final TreePath result; + public Result(TreePath result) { + this.result = result; + } + } + try { + new TreePathScanner<Void, Void>() { + @Override + public Void scan(Tree tree, Void p) { + long s = sp.getStartPosition(cut, tree); + long e = sp.getEndPosition(cut, tree); + if (s <= pos && pos <= e) { + super.scan(tree, p); + throw new Result(getCurrentPath()); + } + return null; + } + }.scan(cut, null); + } catch (Result r) { + return r.result; + } + return null; + } + + private ClassPath inferSourcePath() { + if (sources.isEmpty()) + return ClassPath.EMPTY; + Entry<URL, String> e = sources.entrySet().iterator().next(); + FileObject sourceRoot = URLMapper.findFileObject(e.getKey()); + if (sourceRoot == null) { + //unexpected + return ClassPath.EMPTY; + } + for (String part : e.getValue().split("\\.")) { + sourceRoot = sourceRoot.getParent(); + } + return ClassPathSupport.createClassPath(sourceRoot); + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + static { + ClassLoader origContext = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(ProcessorImpl.class.getClassLoader()); + Lookup.getDefault(); + } finally { + Thread.currentThread().setContextClassLoader(origContext); + } + } + + private static final class DummyPreferences extends AbstractPreferences { + + private final Map<String, String> values = new HashMap<>(); + private final Map<String, DummyPreferences> subNodes = new HashMap<>(); + + public DummyPreferences(AbstractPreferences parent, String name) { + super(parent, name); + } + + @Override + protected void putSpi(String key, String value) { + values.put(key, value); + } + + @Override + protected String getSpi(String key) { + return values.get(key); + } + + @Override + protected void removeSpi(String key) { + values.remove(key); + } + + @Override + protected void removeNodeSpi() throws BackingStoreException { + ((DummyPreferences) parent()).subNodes.remove(name()); + } + + @Override + protected String[] keysSpi() throws BackingStoreException { + return values.keySet().toArray(new String[0]); + } + + @Override + protected String[] childrenNamesSpi() throws BackingStoreException { + return subNodes.keySet().toArray(new String[0]); + } + + @Override + protected AbstractPreferences childSpi(String name) { + DummyPreferences n = subNodes.get(name); + if (n == null) { + subNodes.put(name, n = new DummyPreferences(this, name)); + } + return n; + } + + @Override + protected void syncSpi() throws BackingStoreException { + } + + @Override + protected void flushSpi() throws BackingStoreException { + } + + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/ap/test/unit/src/org/netbeans/modules/jackpot30/ap/ProcessorImplTest.java ---------------------------------------------------------------------- diff --git a/cmdline/ap/test/unit/src/org/netbeans/modules/jackpot30/ap/ProcessorImplTest.java b/cmdline/ap/test/unit/src/org/netbeans/modules/jackpot30/ap/ProcessorImplTest.java new file mode 100644 index 0000000..7a5f8b3 --- /dev/null +++ b/cmdline/ap/test/unit/src/org/netbeans/modules/jackpot30/ap/ProcessorImplTest.java @@ -0,0 +1,244 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2015 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 2015 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.ap; + +import com.sun.tools.javac.Main; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; +import org.netbeans.api.java.source.TestUtilities; +import org.netbeans.junit.NbTestCase; + +/** + * + * @author lahvac + */ +public class ProcessorImplTest extends NbTestCase { + + public ProcessorImplTest(String name) { + super(name); + } + + public void testHardcoded1() throws Exception { + doRunCompiler("", + "", + "src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " private void test(java.util.Collection c) {\n" + + " boolean b1 = c.size() == 0;\n" + + "\tboolean b2 = c.size() == 0;\n" + + " }\n" + + "}\n", + null, + "-source", + "7", + "-Xlint:-options"); + } + + public void testHardcodedWithConfiguration() throws Exception { + doRunCompiler("", + "${workdir}/src/test/Test.java:4: warning: [Usage_of_size_equals_0] Usage of .size() == 0 can be replaced with .isEmpty()\n" + + " boolean b1 = c.size() == 0;\n" + + " ^\n" + + "${workdir}/src/test/Test.java:5: warning: [Usage_of_size_equals_0] Usage of .size() == 0 can be replaced with .isEmpty()\n" + + "\tboolean b2 = c.size() == 0;\n" + + "\t ^\n" + + "2 warnings\n", + "src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " private void test(java.util.Collection c) {\n" + + " boolean b1 = c.size() == 0;\n" + + "\tboolean b2 = c.size() == 0;\n" + + " }\n" + + "}\n", + "cfg_hints.xml", + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<!DOCTYPE configuration PUBLIC \"-//NetBeans//DTD Tool Configuration 1.0//EN\" \"http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd\">\n" + + "<configuration>\n" + + " <tool kind=\"hints\" type=\"text/x-java\">\n" + + " </tool>\n" + + "</configuration>\n", + null, + "-source", + "7", + "-Xlint:-options", + "-A" + ProcessorImpl.CONFIGURATION_OPTION + "=" + new File(getWorkDir(), "cfg_hints.xml").getAbsolutePath()); + } + + public void testCustomWithSourcePath() throws Exception { + doRunCompiler("", + "${workdir}/src/test/Test.java:4: warning: [test] test\n" + + " boolean b1 = c.size() == 0;\n" + + " ^\n" + + "${workdir}/src/test/Test.java:5: warning: [test] test\n" + + "\tboolean b2 = c.size() == 0;\n" + + "\t ^\n" + + "2 warnings\n", + "src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " private void test(java.util.Collection c) {\n" + + " boolean b1 = c.size() == 0;\n" + + "\tboolean b2 = c.size() == 0;\n" + + " }\n" + + "}\n", + "src/META-INF/upgrade/test.hint", + "$coll.size() == 0 :: $coll instanceof java.util.Collection;;\n", + null, + "-source", + "7", + "-Xlint:-options", + "-sourcepath", + new File(getWorkDir(), "src").getAbsolutePath()); + } + + public void testCustomWithOutSourcePath() throws Exception { + doRunCompiler("", + "${workdir}/src/test/Test.java:4: warning: [test] test\n" + + " boolean b1 = c.size() == 0;\n" + + " ^\n" + + "${workdir}/src/test/Test.java:5: warning: [test] test\n" + + "\tboolean b2 = c.size() == 0;\n" + + "\t ^\n" + + "2 warnings\n", + "src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " private void test(java.util.Collection c) {\n" + + " boolean b1 = c.size() == 0;\n" + + "\tboolean b2 = c.size() == 0;\n" + + " }\n" + + "}\n", + "src/META-INF/upgrade/test.hint", + "$coll.size() == 0 :: $coll instanceof java.util.Collection;;\n", + null, + "-source", + "7", + "-Xlint:-options"); + } + + private void doRunCompiler(String stdOut, String stdErr, String... fileContentAndExtraOptions) throws Exception { + List<String> fileAndContent = new LinkedList<String>(); + List<String> extraOptions = new LinkedList<String>(); + List<String> fileContentAndExtraOptionsList = Arrays.asList(fileContentAndExtraOptions); + int nullPos = fileContentAndExtraOptionsList.indexOf(null); + + if (nullPos == (-1)) { + fileAndContent = fileContentAndExtraOptionsList; + extraOptions = Collections.emptyList(); + } else { + fileAndContent = fileContentAndExtraOptionsList.subList(0, nullPos); + extraOptions = fileContentAndExtraOptionsList.subList(nullPos + 1, fileContentAndExtraOptionsList.size()); + } + + assertTrue(fileAndContent.size() % 2 == 0); + + clearWorkDir(); + + List<String> params = new ArrayList<>(); + + for (int cntr = 0; cntr < fileAndContent.size(); cntr += 2) { + File target = new File(getWorkDir(), fileAndContent.get(cntr)); + + target.getParentFile().mkdirs(); + + TestUtilities.copyStringToFile(target, fileAndContent.get(cntr + 1)); + + if (target.getName().endsWith(".java")) + params.add(target.getAbsolutePath()); + } + + params.addAll(extraOptions); + + File wd = getWorkDir(); + String[] output = new String[2]; + reallyRunCompiler(wd, output, params.toArray(new String[0])); + + if (stdOut != null) { + assertEquals(stdOut, output[0].replaceAll(Pattern.quote(wd.getAbsolutePath()), Matcher.quoteReplacement("${workdir}"))); + } + + if (stdErr != null) { + assertEquals(stdErr, output[1].replaceAll(Pattern.quote(wd.getAbsolutePath()), Matcher.quoteReplacement("${workdir}"))); + } + } + + protected void reallyRunCompiler(File workDir, String[] output, String... params) throws Exception { + String oldUserDir = System.getProperty("user.dir"); + + System.setProperty("user.dir", workDir.getAbsolutePath()); + + PrintStream oldOut = System.out; + ByteArrayOutputStream outData = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outData, true, "UTF-8")); + + PrintStream oldErr = System.err; + ByteArrayOutputStream errData = new ByteArrayOutputStream(); + System.setErr(new PrintStream(errData, true, "UTF-8")); + + try { + assertEquals(0, Main.compile(params)); + } finally { + System.setProperty("user.dir", oldUserDir); + System.out.close(); + output[0] = new String(outData.toByteArray(), "UTF-8"); + System.setOut(oldOut); + System.err.close(); + output[1] = new String(errData.toByteArray(), "UTF-8"); + System.setErr(oldErr); + + System.err.println("stdout: " + output[0]); + System.err.println("stderr: " + output[1]); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/build.sh ---------------------------------------------------------------------- diff --git a/cmdline/build.sh b/cmdline/build.sh new file mode 100755 index 0000000..5e64be7 --- /dev/null +++ b/cmdline/build.sh @@ -0,0 +1,52 @@ +#!/bin/bash -x + +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. + +ant "$@" clean && ant "$@" build && ant "$@" test && (cd compiler; ant "$@" create-standalone-compiler && build/test/scripted/run ) && (cd tool; ant "$@" create-standalone-tool && build/test/scripted/run ) && (cd lib; ant "$@" create-cmdline-lib ) && (cd ap; ant "$@" build-ap-jar ) || exit 1 +mvn $MAVEN_EXTRA_ARGS install:install-file -Dfile=tool/build/jackpot/jackpot.jar -DgroupId=org.netbeans.modules.jackpot30 -DartifactId=tool -Dversion=8.1-SNAPSHOT -Dpackaging=jar -DgeneratePom=true +(cd maven; mvn $MAVEN_EXTRA_ARGS install -DskipTests; mvn $MAVEN_EXTRA_ARGS -Dmaven.executable=`which mvn` test) +MAVEN_REPO=`pwd`/build/.m2 +mkdir -p "$MAVEN_REPO" +mvn $MAVEN_EXTRA_ARGS deploy:deploy-file -Dfile=tool/build/jackpot/jackpot.jar -DgroupId=org.netbeans.modules.jackpot30 -DartifactId=tool -Dversion=8.1-SNAPSHOT -Dpackaging=jar -DgeneratePom=true -DaltDeploymentRepository=temp::default::file://"$MAVEN_REPO" -Durl=file://"$MAVEN_REPO" +(cd maven; mvn $MAVEN_EXTRA_ARGS -DskipTests -DaltDeploymentRepository=temp::default::file://"$MAVEN_REPO" deploy) +(cd build; zip -r .m2.zip .m2) http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/build.xml ---------------------------------------------------------------------- diff --git a/cmdline/build.xml b/cmdline/build.xml new file mode 100644 index 0000000..b2e3d2a --- /dev/null +++ b/cmdline/build.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-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]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +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. +--> +<!-- You may freely edit this file. See harness/README in the NetBeans platform --> +<!-- for some information on what you could do (e.g. targets to override). --> +<!-- If you delete this file and reopen the project it will be recreated. --> +<project name="cmdline" basedir="."> + <description>Builds the module suite cmdline.</description> + <import file="nbproject/build-impl.xml"/> + <import file="../suite-common.xml"/> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/cmdline/compiler/antsrc/org/netbeans/modules/jackpot30/compiler/ant/JackpotCompiler.java ---------------------------------------------------------------------- diff --git a/cmdline/compiler/antsrc/org/netbeans/modules/jackpot30/compiler/ant/JackpotCompiler.java b/cmdline/compiler/antsrc/org/netbeans/modules/jackpot30/compiler/ant/JackpotCompiler.java new file mode 100644 index 0000000..cd2ec2b --- /dev/null +++ b/cmdline/compiler/antsrc/org/netbeans/modules/jackpot30/compiler/ant/JackpotCompiler.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.jackpot30.compiler.ant; + +import java.lang.reflect.Field; +import java.net.URL; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.taskdefs.compilers.JavacExternal; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Commandline.Argument; +import org.netbeans.modules.jackpot30.compiler.HintsAnnotationProcessing; +import org.netbeans.modules.jackpot30.compiler.IndexingAnnotationProcessor; +import org.openide.util.Exceptions; + +/** + * + * @author lahvac + */ +public class JackpotCompiler extends JavacExternal { + + @Override + public boolean execute() throws BuildException { + try { + Field forkField = Javac.class.getDeclaredField("fork"); + + forkField.setAccessible(true); + forkField.set(getJavac(), true); + } catch (IllegalArgumentException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalAccessException ex) { + Exceptions.printStackTrace(ex); + } catch (NoSuchFieldException ex) { + Exceptions.printStackTrace(ex); + } catch (SecurityException ex) { + Exceptions.printStackTrace(ex); + } + + return super.execute(); + } + + @Override + protected Commandline setupJavacCommandlineSwitches(Commandline cmd, boolean useDebugLevel) { + super.setupJavacCommandlineSwitches(cmd, useDebugLevel); + + URL jackpotCompiler = HintsAnnotationProcessing.class.getProtectionDomain().getCodeSource().getLocation(); + String jackpotCompilerPath = jackpotCompiler.getPath(); + Argument arg = cmd.createArgument(true); + List<String> options = new LinkedList<String>(); + StringBuilder enabledHintsProp = new StringBuilder(); + + options.addAll(HintsAnnotationProcessing.OPTIONS); + options.addAll(IndexingAnnotationProcessor.OPTIONS); + + for (String prop : options) { + String val = getProject().getProperty(prop); + + if (val != null) { + enabledHintsProp.append(" -A").append(prop).append("=").append(val); + } + } + + arg.setLine("-J-Xbootclasspath/p:" + jackpotCompilerPath + " -Xjcov -J-Xmx256m" + enabledHintsProp); //XXX: Xmx! + + return cmd; + } + + +}
