[hg] main-silver: #194090

  • From: Milos Kleint < >
  • To: ,
  • Subject: [hg] main-silver: #194090
  • Date: Fri, 05 Apr 2013 19:43:05 -0700

changeset 71289f0dadeb in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/71289f0dadeb
description:
        #194090
        1. create an EventSpy component and inject it into 3.x maven builds.
        2. parse the events it's sending over to the IDE via output in JSON
        3. add a Context object to OutputVisitor populate it with Project 
owning current output.
        4. make use of it in the output processors.

diffstat:

 
maven.apisupport/src/org/netbeans/modules/maven/apisupport/IDEOutputListenerProvider.java
 |    9 +-
 maven/build.xml                                                              
             |   16 +-
 maven/mavensrc/org/netbeans/modules/maven/event/NbEventSpy.java              
             |  151 ++++++++++
 maven/mavensrc/META-INF/plexus/components.xml                                
             |    4 +-
 maven/mavensrc/META-INF/plexus/components.xml                                
             |    0 
 maven/nbproject/project.properties                                           
             |    4 +-
 maven/nbproject/project.xml                                                  
             |   17 +-
 maven/src/org/netbeans/modules/maven/api/output/OutputVisitor.java           
             |   22 +-
 maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java      
             |    4 +-
 maven/src/org/netbeans/modules/maven/execute/CommandLineOutputHandler.java   
             |   84 +++++-
 maven/src/org/netbeans/modules/maven/execute/ExecutionEventObject.java       
             |  150 +++++++++
 maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java   
             |   33 +-
 
maven/src/org/netbeans/modules/maven/output/DependencyAnalyzeOutputProcessor.java
         |   16 +-
 
maven/src/org/netbeans/modules/maven/output/ExecPluginOutputListenerProvider.java
         |   10 +-
 maven/src/org/netbeans/modules/maven/output/JavaOutputListenerProvider.java  
             |    2 +-
 maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java         
             |    6 +
 16 files changed, 500 insertions(+), 28 deletions(-)

diffs (835 lines):

diff --git 
a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/IDEOutputListenerProvider.java
 
b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/IDEOutputListenerProvider.java
--- 
a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/IDEOutputListenerProvider.java
+++ 
b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/IDEOutputListenerProvider.java
@@ -68,7 +68,7 @@
         "mojo-execute#nbm:run-ide", //NOI18N
         "mojo-execute#nbm:run-platform" //NOI18N
     };
-    private Project project;
+    private final Project project;
     private ClassPath classpath;
     
     /** Creates a new instance of TestOutputListenerProvider */
@@ -119,7 +119,12 @@
 
     @Override
     public void sequenceStart(String sequenceId, OutputVisitor visitor) {
-        classpath = createCP(project, new HashSet<Project>());
+        OutputVisitor.Context context = visitor.getContext();
+        Project prj = project;
+        if (context != null) {
+            prj = context.getCurrentProject();
+        }        
+        classpath = createCP(prj, new HashSet<Project>());
     }
 
     @Override
diff --git a/maven/build.xml b/maven/build.xml
--- a/maven/build.xml
+++ b/maven/build.xml
@@ -55,12 +55,22 @@
                 <pathelement path="${antsrc.cp}"/>
             </classpath>
         </javac>
-        <copy todir="build/mavenclasses">
-            <fileset dir="mavensrc" excludes="${jar-excludes}"/>
+        <copy overwrite="true" 
tofile="build/mavenclasses/META-INF/plexus/components.xml" 
file="mavensrc/org/netbeans/modules/maven/workspace/reader/components.xml">
         </copy>
         <mkdir dir="${cluster}/maven/nblib"/>
         <jar jarfile="${cluster}/maven/nblib/netbeans-cos.jar" 
compress="false">
-            <fileset dir="build/mavenclasses"/>
+            <fileset dir="build/mavenclasses" >
+                <include 
name="org/netbeans/modules/maven/workspace/reader/**"/>
+                <include name="META-INF/plexus/**"/>
+            </fileset>
+        </jar>
+        <copy overwrite="true" 
tofile="build/mavenclasses/META-INF/plexus/components.xml" 
file="mavensrc/org/netbeans/modules/maven/event/components.xml">
+        </copy>
+        <jar jarfile="${cluster}/maven/nblib/netbeans-eventspy.jar" 
compress="false">
+            <fileset dir="build/mavenclasses" >
+                <include name="org/netbeans/modules/maven/event/**"/>
+                <include name="META-INF/plexus/**"/>
+            </fileset>
         </jar>
     </target>
 
diff --git a/maven/mavensrc/org/netbeans/modules/maven/event/NbEventSpy.java 
b/maven/mavensrc/org/netbeans/modules/maven/event/NbEventSpy.java
new file mode 100644
--- /dev/null
+++ b/maven/mavensrc/org/netbeans/modules/maven/event/NbEventSpy.java
@@ -0,0 +1,151 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 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 2013 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.maven.event;
+
+import org.apache.maven.eventspy.AbstractEventSpy;
+import org.apache.maven.execution.ExecutionEvent;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ *
+ * @author mkleint
+ */
+public class NbEventSpy extends AbstractEventSpy {
+
+    private Logger logger;
+    
+    @Override
+    public void init(Context context) throws Exception {
+        //as as by MavenCLI.java
+        //data.put( "plexus", container );
+        //data.put( "workingDirectory", cliRequest.workingDirectory );
+        //data.put( "systemProperties", cliRequest.systemProperties );
+        //data.put( "userProperties", cliRequest.userProperties );
+        //data.put( "versionProperties", 
CLIReportingUtils.getBuildProperties() );
+        super.init(context); 
+    }
+
+    @Override
+    public void onEvent(Object event) throws Exception {
+        //event can be:
+        //org.apache.maven.execution.ExecutionEvent
+        //org.sonatype.aether.RepositoryEvent
+        //org.apache.maven.project.DefaultDependencyResolutionRequest
+        //org.apache.maven.project.DependencyResolutionResult
+        //org.apache.maven.execution.MavenExecutionRequest
+        //org.apache.maven.execution.MavenExecutionResult
+        //org.apache.maven.settings.building.SettingsBuildingRequest
+        //org.apache.maven.settings.building.SettingsBuildingResult
+        super.onEvent(event); 
+        if (event instanceof ExecutionEvent) {
+            ExecutionEvent ex = (ExecutionEvent) event;
+            StringBuffer sb = new StringBuffer();
+            //use base64 for complex structures or unknown values?
+            sb.append("{");
+            {
+                
sb.append("\"type\":\"").append(ex.getType().name()).append("\"");
+                //TODO only in Project* related event types?
+                if (ex.getProject() != null) { // && not superpom
+                    MavenProject mp = ex.getProject();
+                    sb.append(" \"prj\":{");
+                    {
+                        sb.append("\"id\": 
\"").append(mp.getId()).append("\" ");
+                        if (mp.getFile() != null) {
+                            
sb.append("\"file\":\"").append(mp.getFile().getParentFile().getAbsolutePath()).append("\"");
+                        }
+                    }
+                    sb.append("}");
+                }
+                if (ExecutionEvent.Type.SessionStarted.equals(ex.getType())) 
{
+                    sb.append(" 
\"prjcount\":").append(ex.getSession().getProjects().size());
+                }
+                if (ex.getMojoExecution() != null) {
+                    MojoExecution me = ex.getMojoExecution();
+                    sb.append(" \"mojo\": {");
+                    {
+                        
sb.append("\"id\":\"").append(me.getGroupId()).append(":").append(me.getArtifactId()).append(":").append(me.getVersion()).append("\"
 ");
+                        if (me.getGoal() != null) {
+                            
sb.append("\"goal\":\"").append(me.getGoal()).append("\" ");
+                        }
+                        if (me.getSource() != null) {
+                            
sb.append("\"source\":\"").append(me.getSource().name()).append("\" ");
+                        }
+                        if (me.getExecutionId() != null) {
+                            
sb.append("\"execId\":\"").append(me.getExecutionId()).append("\" ");
+                        }
+                        if (me.getLifecyclePhase() != null) {
+                            
sb.append("\"phase\":\"").append(me.getLifecyclePhase()).append("\"");
+                        }
+                    }
+                    sb.append("}");
+                }
+//                if (ex.getException() != null) {
+//                    Exception exc = ex.getException();
+//                    sb.append("\"exc\": {");
+//                    {
+//                        String message = exc.getMessage();
+//                        byte[] enc = 
Base64.encodeBase64(message.getBytes("UTF-8")); //NOW are these conversions 
correct?
+//                        String encString = new String(enc, "UTF-8");
+//                        
sb.append("\"msg\":\"").append(encString).append("\"");
+//                    }
+//                    sb.append("}");
+//                    
+//                }
+            }    
+            sb.append("}");
+            logger.info("NETBEANS-ExecEvent:"  + sb);
+        }
+//        if (event instanceof RepositoryEvent) {
+//            RepositoryEvent re = (RepositoryEvent) event;
+//            logger.info("NETBEANS-RE:" + re.getType() + ":" + 
re.getFile());
+//        }
+    }
+
+    @Override
+    public void close() throws Exception {
+        super.close(); 
+    }
+
+}
diff --git a/maven/mavensrc/META-INF/plexus/components.xml 
b/maven/mavensrc/org/netbeans/modules/maven/event/components.xml
rename from maven/mavensrc/META-INF/plexus/components.xml
rename to maven/mavensrc/org/netbeans/modules/maven/event/components.xml
--- a/maven/mavensrc/META-INF/plexus/components.xml
+++ b/maven/mavensrc/org/netbeans/modules/maven/event/components.xml
@@ -2,9 +2,9 @@
 <component-set>
   <components>
     <component>
-      <role>org.sonatype.aether.repository.WorkspaceReader</role>
+      <role>org.apache.maven.eventspy.EventSpy</role>
       <role-hint>ide</role-hint>
-      
<implementation>org.netbeans.modules.maven.workspace.reader.IDEWorkspaceReader</implementation>
+      
<implementation>org.netbeans.modules.maven.event.NbEventSpy</implementation>
       <description />
       <isolated-realm>false</isolated-realm>
       <requirements>
diff --git a/maven/mavensrc/META-INF/plexus/components.xml 
b/maven/mavensrc/org/netbeans/modules/maven/workspace/reader/components.xml
copy from maven/mavensrc/META-INF/plexus/components.xml
copy to 
maven/mavensrc/org/netbeans/modules/maven/workspace/reader/components.xml
diff --git a/maven/nbproject/project.properties 
b/maven/nbproject/project.properties
--- a/maven/nbproject/project.properties
+++ b/maven/nbproject/project.properties
@@ -53,4 +53,6 @@
     **/ProjectOpenedHookImplTest.class
 
 antsrc.cp=\
-    
${maven.embedder.dir}/maven/lib/aether-api-1.13.1.jar:\${maven.embedder.dir}/maven/lib/sisu-inject-plexus-2.3.0.jar
+    
${maven.embedder.dir}/maven/lib/aether-api-1.13.1.jar:\${maven.embedder.dir}/maven/lib/sisu-inject-plexus-2.3.0.jar:\${maven.embedder.dir}/maven/lib/maven-core-3.0.5.jar
+
+##:\${maven.embedder.dir}/maven/lib/plexus-utils-2.0.6.jar
diff --git a/maven/nbproject/project.xml b/maven/nbproject/project.xml
--- a/maven/nbproject/project.xml
+++ b/maven/nbproject/project.xml
@@ -50,6 +50,10 @@
             <code-name-base>org.netbeans.modules.maven</code-name-base>
             <module-dependencies>
                 <dependency>
+                    <code-name-base>org.apache.commons.codec</code-name-base>
+                    <run-dependency/>
+                </dependency>
+                <dependency>
                     
<code-name-base>org.netbeans.api.annotations.common</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -112,6 +116,15 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    
<code-name-base>org.netbeans.libs.json_simple</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>0.5</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     
<code-name-base>org.netbeans.modules.autoupdate.ui</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -495,9 +508,9 @@
                 <package-root>mavensrc</package-root>
                 <classpath>${antsrc.cp}</classpath>
                 <built-to>build/mavenclasses</built-to>
-                
<built-to>${cluster}/maven/nblib/${code.name.base.dashes}.jar</built-to>
+                <built-to>${cluster}/maven/nblib/netbeans-cos.jar</built-to>
+                
<built-to>${cluster}/maven/nblib/netbeans-eventspy.jar</built-to>
             </extra-compilation-unit>            
         </data>
-        
     </configuration>
 </project>
diff --git 
a/maven/src/org/netbeans/modules/maven/api/output/OutputVisitor.java 
b/maven/src/org/netbeans/modules/maven/api/output/OutputVisitor.java
--- a/maven/src/org/netbeans/modules/maven/api/output/OutputVisitor.java
+++ b/maven/src/org/netbeans/modules/maven/api/output/OutputVisitor.java
@@ -44,6 +44,8 @@
 
 import java.awt.Color;
 import javax.swing.Action;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.api.project.Project;
 import org.openide.windows.OutputListener;
 
 /**
@@ -58,6 +60,7 @@
     private String line;
     private boolean skipLine = false;
     private Color color;
+    private Context context;
     
     /**
      * property for success Action. Holds question text.
@@ -74,6 +77,11 @@
     public OutputVisitor() {
     }
 
+    /** Creates a new instance of OutputVisitor */
+    public OutputVisitor(Context context) {
+        this.context = context;
+    }
+
     /**
      * not to be called by the OutputProcessors.
      */
@@ -86,7 +94,6 @@
         color = null;
     }
     
-
     public OutputListener getOutputListener() {
         return outputListener;
     }
@@ -156,4 +163,17 @@
         this.color = color;
     }
     
+    public @CheckForNull Context getContext() {
+        return context;
 }
+
+    public static interface Context {
+
+        
+        @CheckForNull Project getCurrentProject();
+        
+        
+        
+    }
+        
+}
diff --git 
a/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java 
b/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java
--- a/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java
+++ b/maven/src/org/netbeans/modules/maven/execute/AbstractOutputHandler.java
@@ -86,10 +86,10 @@
     private RequestProcessor.Task sleepTask;
     private static final int SLEEP_DELAY = 5000;
 
-    protected AbstractOutputHandler(final ProgressHandle hand) {
+    protected AbstractOutputHandler(final ProgressHandle hand, OutputVisitor 
visitor) {
         processors = new HashMap<String, Set<OutputProcessor>>();
         currentProcessors = new HashSet<OutputProcessor>();
-        visitor = new OutputVisitor();
+        this.visitor = visitor;
         toFinishProcessors = new HashSet<NotifyFinishOutputProcessor>();
         sleepTask = new 
RequestProcessor(AbstractOutputHandler.class).create(new Runnable() {
             public @Override void run() {
diff --git 
a/maven/src/org/netbeans/modules/maven/execute/CommandLineOutputHandler.java 
b/maven/src/org/netbeans/modules/maven/execute/CommandLineOutputHandler.java
--- 
a/maven/src/org/netbeans/modules/maven/execute/CommandLineOutputHandler.java
+++ 
b/maven/src/org/netbeans/modules/maven/execute/CommandLineOutputHandler.java
@@ -42,6 +42,7 @@
 package org.netbeans.modules.maven.execute;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -50,9 +51,16 @@
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.apache.maven.execution.ExecutionEvent;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
 import org.netbeans.modules.maven.api.execute.RunConfig;
 import org.netbeans.api.progress.ProgressHandle;
 import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.maven.api.output.OutputVisitor;
+import org.openide.filesystems.FileUtil;
 import org.openide.util.Exceptions;
 import org.openide.util.RequestProcessor;
 import org.openide.util.RequestProcessor.Task;
@@ -84,14 +92,21 @@
     private ProgressHandle handle;
     /** {@link MavenProject#getName} of first project in reactor to fail, if 
any */
     String firstFailure;
+    private final JSONParser parser;
+    private ContextImpl contextImpl;
 
-    CommandLineOutputHandler(ProgressHandle hand) {
-        super(hand);
+    CommandLineOutputHandler(ProgressHandle hand, boolean 
createVisitorContext) {
+        super(hand, createVisitorContext ? new OutputVisitor(new 
ContextImpl()) : new OutputVisitor());
+        if (createVisitorContext) {
+            contextImpl = (ContextImpl) visitor.getContext();
+            assert contextImpl != null;
+        }
+        this.parser = new JSONParser();
         handle = hand;
     }
 
-    public CommandLineOutputHandler(InputOutput io, Project proj, 
ProgressHandle hand, RunConfig config) {
-        this(hand);
+    public CommandLineOutputHandler(InputOutput io, Project proj, 
ProgressHandle hand, RunConfig config, boolean createVisitorContext) {
+        this(hand, createVisitorContext);
         inputOutput = io;
         stdOut = inputOutput.getOut();
 //        logger = new Logger();
@@ -137,7 +152,10 @@
         }
     }
 
+
+
     private class Output implements Runnable {
+        private static final String INFO_NETBEANS_EXEC_EVENT = "[INFO] 
NETBEANS-ExecEvent:";
 
         private BufferedReader str;
         private boolean skipLF = false;
@@ -204,11 +222,18 @@
                         line = readLine();
                         continue;
                     }
+                    if (line.startsWith(INFO_NETBEANS_EXEC_EVENT)) {
+                        parseExecEvent(line);
+                        stdOut.println(line); //XXX temporary
+                        line = readLine();
+                        continue;
+                    }                    
                     if (line.startsWith("[INFO] Final Memory:")) { //NOI18N
                         // previous value [INFO] --------------- is too 
early, the compilation errors don't get processed in this case.
                         //heuristics..
                         closeCurrentTag();
                     }
+                    
                     String tag = null;
                     Matcher match = startPatternM3.matcher(line);
                     if (match.matches()) {
@@ -270,6 +295,36 @@
                 }
             }
         }
+
+        private void parseExecEvent(String line) {
+            String jsonContent = 
line.substring(INFO_NETBEANS_EXEC_EVENT.length());
+            try {
+                Object o = parser.parse(jsonContent);
+                System.out.println("o=" + o);
+                if (o instanceof JSONObject) {
+                    JSONObject json = (JSONObject) o;
+                    ExecutionEventObject obj = 
ExecutionEventObject.create(json);
+                    if (ExecutionEvent.Type.MojoStarted.equals(obj.type)) {
+                    }
+                    if (ExecutionEvent.Type.ProjectStarted.equals(obj.type)) 
{
+                        if (contextImpl != null) {
+                            File prjLoc = obj.currentProjectLocation;
+                            try {
+                                Project project = 
ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjLoc));
+                                contextImpl.setCurrentProject(project);
+                            } catch (IOException ex) {
+                                Exceptions.printStackTrace(ex);
+                            } catch (IllegalArgumentException ex) {
+                                Exceptions.printStackTrace(ex);
+                            }
+                        }
+                    }
+                }
+            } catch (ParseException ex) {
+                Exceptions.printStackTrace(ex);
+                System.out.println("exc=" + ex);
+            }
+        }
     }
 
     static class Input implements Runnable {
@@ -385,4 +440,25 @@
     private int reactorSize;
     private int projectCount;
 
+    private static class ContextImpl implements OutputVisitor.Context {
+
+        private Project currentProject;
+
+        public ContextImpl() {
 }
+
+        @Override
+        public Project getCurrentProject() {
+            return currentProject;
+        }
+        
+        public void setCurrentProject(Project currentProject) {
+            this.currentProject = currentProject;
+        }
+        
+        
+    }    
+
+}
+
+
diff --git 
a/maven/src/org/netbeans/modules/maven/execute/ExecutionEventObject.java 
b/maven/src/org/netbeans/modules/maven/execute/ExecutionEventObject.java
new file mode 100644
--- /dev/null
+++ b/maven/src/org/netbeans/modules/maven/execute/ExecutionEventObject.java
@@ -0,0 +1,150 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 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 2013 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.maven.execute;
+
+import java.io.File;
+import org.apache.maven.execution.ExecutionEvent;
+import org.json.simple.JSONObject;
+import org.netbeans.api.annotations.common.NonNull;
+import org.openide.filesystems.FileUtil;
+
+/**
+ * a stub to be filled with parsed JSON values, vaguely related to 
ExecutionEventObject in maven codebase.
+ * @author mkleint
+ */
+
+public final class ExecutionEventObject {
+
+    final ExecutionEvent.Type type;
+    final int projectCount;
+    final GAV currentProject;
+    final File currentProjectLocation;
+    final MojoExecution execution;
+
+    private  ExecutionEventObject(ExecutionEvent.Type type, GAV 
currentProject, File currentProjectLocation, MojoExecution execution, int 
projectCount) {
+        this.type = type;
+        this.currentProject = currentProject;
+        this.currentProjectLocation = currentProjectLocation;
+        this.execution = execution;
+        this.projectCount = projectCount;
+    }
+
+    public static class MojoExecution {
+
+        final String goal;
+        final GAV plugin;
+        final String phase;
+        final String executionId;
+
+        private MojoExecution(String goal, @NonNull GAV plugin, String 
phase, String executionId) {
+            this.goal = goal;
+            this.plugin = plugin;
+            this.phase = phase;
+            this.executionId = executionId;
+        }
+        
+    }
+    
+    public static class GAV {
+        final String groupId;
+        final String artifactId;
+        final String version;
+
+        private GAV(@NonNull String groupId, @NonNull String artifactId, 
@NonNull String version) {
+            this.groupId = groupId;
+            this.artifactId = artifactId;
+            this.version = version;
+        }
+        
+    }
+    
+    public static ExecutionEventObject create(JSONObject obj) {
+        String s = (String) obj.get("type");
+        ExecutionEvent.Type t = ExecutionEvent.Type.valueOf(s);
+        GAV prjGav = null;
+        File prjFile = null;
+        MojoExecution exec = null;
+        String excMessage = null;
+        Integer count = (Integer) obj.get("prjcount");
+        int prjCount = -1;
+        if (count != null) {
+            prjCount = count;
+        }
+        JSONObject prj = (JSONObject) obj.get("prj");
+        if (prj != null) {
+            String id = (String) prj.get("id");
+            String[] ids = id.split(":");
+            prjGav = new GAV(ids[0], ids[1], ids[2]);
+            String file = (String) prj.get("file");
+            if (file != null) {
+                prjFile = FileUtil.normalizeFile(new File(file));
+            }
+        }
+        JSONObject mojo = (JSONObject) obj.get("mojo");
+        if (mojo != null) {
+            String id = (String) mojo.get("id");
+            String[] ids = id.split(":");
+            GAV mojoGav = new GAV(ids[0], ids[1], ids[2]);
+            String goal = (String) mojo.get("goal");
+            String execId = (String) mojo.get("execId");
+            String phase = (String) mojo.get("phase");
+            exec = new MojoExecution(goal, mojoGav, phase, execId);
+        }
+//        JSONObject exc = (JSONObject) obj.get("exc");
+//        if (exc != null) {
+//            String message = (String) exc.get("msg");
+//            if (message != null) {
+//                try {
+//                    byte[] bytes = 
Base64.decodeBase64(message.getBytes("UTF-8"));
+//                    excMessage = new String(bytes, "UTF-8");
+//                    System.out.println("exc message=" + excMessage);
+//                } catch (UnsupportedEncodingException ex) {
+//                    Exceptions.printStackTrace(ex);
+//                }
+//            }
+//        }
+        
+        return new ExecutionEventObject(t, prjGav, prjFile, exec, prjCount);
+    }
+    
+}
diff --git 
a/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java 
b/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java
--- 
a/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java
+++ 
b/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java
@@ -84,6 +84,7 @@
 import org.openide.awt.HtmlBrowser;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
+import org.openide.modules.InstalledFileLocator;
 import org.openide.util.Exceptions;
 import org.openide.util.Lookup;
 import org.openide.util.RequestProcessor;
@@ -161,7 +162,16 @@
         actionStatesAtStart();
         handle.start();
         processInitialMessage();
-        CommandLineOutputHandler out = new CommandLineOutputHandler(ioput, 
clonedConfig.getProject(), handle, clonedConfig);
+        boolean isMaven2 = isMaven2();
+        if (!isMaven2) {
+            injectEventSpy( clonedConfig );
+            if (clonedConfig.getPreExecution() != null) {
+                injectEventSpy( (BeanRunConfig) 
clonedConfig.getPreExecution());
+            }
+        }
+
+        
+        CommandLineOutputHandler out = new CommandLineOutputHandler(ioput, 
clonedConfig.getProject(), handle, clonedConfig, !isMaven2);
         try {
             BuildExecutionSupport.registerRunningItem(item);
 
@@ -523,12 +533,29 @@
     private void printCoSWarning(BeanRunConfig clonedConfig, InputOutput 
ioput) {
         if 
(clonedConfig.getProperties().containsKey(CosChecker.NETBEANS_PROJECT_MAPPINGS))
 {
             printGray(ioput, "Running NetBeans Compile On Save execution. 
Phase execution is skipped and output directories of dependency projects 
(with Compile on Save turned on) will be used instead of their jar 
artifacts.");
+            if (isMaven2()) {
+                printGray(ioput, "WARNING: Using Maven 2.x for execution, 
NetBeans cannot establish links between current project and output 
directories of dependency projects with Compile on Save turned on. Only works 
with Maven 3.0+.");
+            }
+        }
+    }
+    
+    boolean isMaven2() {
             File mvnHome = EmbedderFactory.getEffectiveMavenHome();
             String version = 
MavenSettings.getCommandLineMavenVersion(mvnHome);
-            if (version != null && version.startsWith("2")) {
-                printGray(ioput, "WARNING: Using Maven 2.x for execution, 
NetBeans cannot establish links between current project and output 
directories of dependency projects with Compile on Save turned on. Only works 
with Maven 3.0+.");
+        return version != null && version.startsWith("2");
             }
+
+    private void injectEventSpy(final BeanRunConfig clonedConfig) {
+        //TEMP 
+        String mavenPath = 
clonedConfig.getProperties().get(CosChecker.MAVENEXTCLASSPATH);
+        if (mavenPath == null) {
+            mavenPath = "";
+        } else {
+            mavenPath = mavenPath + (Utilities.isWindows() ? ";" : ":");
         }
+        File jar = 
InstalledFileLocator.getDefault().locate("maven/nblib/netbeans-eventspy.jar", 
"org.netbeans.modules.maven", false);
+        mavenPath = mavenPath + jar.getAbsolutePath();
+        clonedConfig.setProperty(CosChecker.MAVENEXTCLASSPATH, mavenPath);
     }
 
     private static class FindByName implements ResumeFromFinder {
diff --git 
a/maven/src/org/netbeans/modules/maven/output/DependencyAnalyzeOutputProcessor.java
 
b/maven/src/org/netbeans/modules/maven/output/DependencyAnalyzeOutputProcessor.java
--- 
a/maven/src/org/netbeans/modules/maven/output/DependencyAnalyzeOutputProcessor.java
+++ 
b/maven/src/org/netbeans/modules/maven/output/DependencyAnalyzeOutputProcessor.java
@@ -44,6 +44,7 @@
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.netbeans.api.project.Project;
 import org.netbeans.modules.maven.NbMavenProjectImpl;
 import org.netbeans.modules.maven.api.ModelUtils;
 import org.netbeans.modules.maven.api.output.OutputProcessor;
@@ -67,10 +68,10 @@
     private final Pattern start;
     private boolean started;
     private final Pattern dependency;
-    private final NbMavenProjectImpl project;
+    private final Project project;
     
     /** Creates a new instance of JavadocOutputProcessor */
-    DependencyAnalyzeOutputProcessor(NbMavenProjectImpl project) {
+    DependencyAnalyzeOutputProcessor(Project project) {
         started = false;
         start = Pattern.compile(".*Used undeclared dependencies.*", 
Pattern.DOTALL); //NOI18N
         dependency = 
Pattern.compile("\\s*(?:\\[WARNING\\])?\\s*(.*):(.*):(.*):(.*):(.*)", 
Pattern.DOTALL); //NOI18N
@@ -93,7 +94,12 @@
                 String ver = match.group(4);
                 String sc = match.group(5);
                 visitor.setLine(line + " (Click to add to pom.xml)"); 
//NOI18N - part of maven output
-                visitor.setOutputListener(new Listener(project, gr, ar, 
type, ver, sc), false);
+                OutputVisitor.Context context = visitor.getContext();
+                Project prj = project;
+                if (context != null) {
+                    prj = context.getCurrentProject();
+                }
+                visitor.setOutputListener(new Listener(prj, gr, ar, type, 
ver, sc), false);
             } else {
                 started = false;
             }
@@ -125,9 +131,9 @@
         private final String version;
         private final String type;
         private final String artifact;
-        private final NbMavenProjectImpl project;
+        private final Project project;
         
-        private Listener(NbMavenProjectImpl prj, String gr, String ar, 
String type, String ver, String sc) {
+        private Listener(Project prj, String gr, String ar, String type, 
String ver, String sc) {
             group = gr;
             artifact = ar;
             this.type = type;
diff --git 
a/maven/src/org/netbeans/modules/maven/output/ExecPluginOutputListenerProvider.java
 
b/maven/src/org/netbeans/modules/maven/output/ExecPluginOutputListenerProvider.java
--- 
a/maven/src/org/netbeans/modules/maven/output/ExecPluginOutputListenerProvider.java
+++ 
b/maven/src/org/netbeans/modules/maven/output/ExecPluginOutputListenerProvider.java
@@ -46,6 +46,7 @@
 import org.netbeans.modules.maven.api.output.OutputUtils;
 import org.netbeans.modules.maven.api.output.OutputVisitor;
 import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.project.Project;
 import 
org.netbeans.modules.maven.api.classpath.ProjectSourcesClassPathProvider;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.windows.OutputListener;
@@ -63,7 +64,7 @@
         "mojo-execute#exec:exec", //NOI18N
         "mojo-execute#exec:java" //NOI18N
     };
-    private NbMavenProjectImpl project;
+    private final NbMavenProjectImpl project;
     
     /** Creates a new instance of ExecPluginOutputListenerProvider */
     public ExecPluginOutputListenerProvider(NbMavenProjectImpl proj) {
@@ -72,7 +73,12 @@
     
     @Override
     public void processLine(String line, OutputVisitor visitor) {
-        ClassPath[] cp = 
project.getLookup().lookup(ProjectSourcesClassPathProvider.class).getProjectClassPaths(ClassPath.EXECUTE);
+        OutputVisitor.Context context = visitor.getContext();
+        Project prj = project;
+        if (context != null) {
+            prj = context.getCurrentProject();
+        }
+        ClassPath[] cp = 
prj.getLookup().lookup(ProjectSourcesClassPathProvider.class).getProjectClassPaths(ClassPath.EXECUTE);
         OutputListener list = OutputUtils.matchStackTraceLine(line, 
ClassPathSupport.createProxyClassPath(cp));
         if (list != null) {
             visitor.setOutputListener(list);
diff --git 
a/maven/src/org/netbeans/modules/maven/output/JavaOutputListenerProvider.java 
b/maven/src/org/netbeans/modules/maven/output/JavaOutputListenerProvider.java
--- 
a/maven/src/org/netbeans/modules/maven/output/JavaOutputListenerProvider.java
+++ 
b/maven/src/org/netbeans/modules/maven/output/JavaOutputListenerProvider.java
@@ -67,7 +67,7 @@
         "mojo-execute#compiler:compile", //NOI18N
         "mojo-execute#compiler:testCompile" //NOI18N
     };
-    private Pattern failPattern;
+    private final Pattern failPattern;
     private String windowsDrive; // #197381
     /** @see org.codehaus.plexus.compiler.javac.JavacCompiler#compile */
     private static final Pattern windowsDriveInfoPattern = 
Pattern.compile("Compiling \\d+ source files? to ([A-Za-z]:)\\\\.+");
diff --git 
a/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java 
b/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java
--- a/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java
+++ b/maven/src/org/netbeans/modules/maven/output/SiteOutputProcessor.java
@@ -88,8 +88,14 @@
     @Override
     public void sequenceEnd(String sequenceId, OutputVisitor visitor) {
         visitor.setLine("     View Generated Project Site"); //NOI18N shows 
up in maven output.
+        OutputVisitor.Context con = visitor.getContext();
+        if (con != null && con.getCurrentProject() != null) {
+            visitor.setOutputListener(new Listener(con.getCurrentProject()), 
false);
+        } else {
+            //hope for the best, but generally the root project might not be 
the right project to use.
         visitor.setOutputListener(new Listener(project), false);
     }
+    }
     
     @Override
     public void sequenceFail(String sequenceId, OutputVisitor visitor) {

[hg] main-silver: #194090

Milos Kleint 04/06/2013

Project Features

About this Project

APIsupport was started in November 2009, is owned by Antonin Nebuzelsky, and has 43 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close