Skip to content

Commit

Permalink
#117 extract .common plugin with CommonDialogs and CommonConsole
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvi committed Jan 25, 2014
1 parent 8a4d79d commit 43c4765
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 51 deletions.
7 changes: 7 additions & 0 deletions org.nodeclipse.common/.classpath
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions org.nodeclipse.common/.project
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.nodeclipse.common</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
15 changes: 15 additions & 0 deletions org.nodeclipse.common/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Nodeclipse Common
Bundle-SymbolicName: org.nodeclipse.common; singleton:=true
Bundle-Version: 0.9.0.qualifier
Bundle-Activator: org.nodeclipse.common.Activator
Bundle-Vendor: Enide
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.ui.console
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.nodeclipse.common.preferences,
org.nodeclipse.common.ui
2 changes: 2 additions & 0 deletions org.nodeclipse.common/README.md
@@ -0,0 +1,2 @@

Wow: Ctrl+V with some code in clipboard on java package will create new class and add that code into main() method
8 changes: 8 additions & 0 deletions org.nodeclipse.common/build.properties
@@ -0,0 +1,8 @@
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/,\
help/,\
HelpToc.xml
5 changes: 5 additions & 0 deletions org.nodeclipse.common/plugin.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

</plugin>
19 changes: 19 additions & 0 deletions org.nodeclipse.common/pom.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.nodeclipse.nodeclipse-1</groupId>
<artifactId>parent</artifactId>
<version>0.9.0-SNAPSHOT</version>
</parent>

<artifactId>org.nodeclipse.common</artifactId>
<packaging>eclipse-plugin</packaging>

<name>org.nodeclipse.common</name>
<description>org.nodeclipse.common</description>
</project>

51 changes: 51 additions & 0 deletions org.nodeclipse.common/src/org/nodeclipse/common/Activator.java
@@ -0,0 +1,51 @@
package org.nodeclipse.common;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.nodeclipse.common.preferences.CommonConstants;
import org.osgi.framework.BundleContext;

/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {

// The plug-in ID
public static final String PLUGIN_ID = CommonConstants.PLUGIN_ID;

// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}

/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}

}
@@ -0,0 +1,7 @@
package org.nodeclipse.common.preferences;

public class CommonConstants {

public static final String PLUGIN_ID = "org.nodeclipse.common"; //$NON-NLS-1$

}
@@ -1,4 +1,4 @@
package org.nodeclipse.enide.gradle.preferences;
package org.nodeclipse.common.preferences;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceDialog;
Expand All @@ -11,7 +11,7 @@
* Dialogs used in .enide.maven, .enide.gradle
* @author Paul Verest, Pushkar Gupte
*/
public class Dialogs {
public class CommonDialogs {


public static void showPreferencesDialog(final String preferencesPage, final String message) {
Expand Down
@@ -0,0 +1,66 @@
package org.nodeclipse.common.ui;

import java.io.IOException;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IOConsoleOutputStream;
import org.eclipse.ui.console.MessageConsole;

/**
* Console showing executable's options and launch parameters
* and also runtime errors
*
* @author pverest
*/
public class CommonConsole {

private static CommonConsole instance = null;
private static IOConsoleOutputStream stream = null;

public CommonConsole() {
MessageConsole console = new MessageConsole("Common Console", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager()
.addConsoles(new IConsole[] { console });
stream = console.newOutputStream();
}

static {
getInstance();
//write(VersionUtil.getLongString());
write("visit http://www.nodeclipse.org/\n\n");
}

private static CommonConsole getInstance() {
if (instance == null)
instance = new CommonConsole();
return instance;
}

public static void write(String s) {
// IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
// boolean nodeclipseConsoleEnabled = preferenceStore.getBoolean(PreferenceConstants.NODECLIPSE_CONSOLE_ENABLED);//@since 0.7
// if (!nodeclipseConsoleEnabled)
// return;

instance = getInstance();
try {
stream.write(s);
} catch (IOException e) {
//TODO how to show?
//e.printStackTrace();
}
}

@Override
public void finalize() {
try {
stream.close();
} catch (IOException e) {
//TODO how to show?
//e.printStackTrace();
}
}

}
3 changes: 2 additions & 1 deletion org.nodeclipse.enide.gradle/META-INF/MANIFEST.MF
Expand Up @@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.debug.ui,
org.eclipse.core.variables
org.eclipse.core.variables,
org.nodeclipse.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Expand Up @@ -16,8 +16,8 @@
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.preference.IPreferenceStore;
import org.nodeclipse.common.preferences.CommonDialogs;
import org.nodeclipse.enide.gradle.Activator;
import org.nodeclipse.enide.gradle.preferences.Dialogs;
//import org.eclipse.jface.preference.IPreferenceStore;
//import org.nodeclipse.debug.util.Constants;
//import org.nodeclipse.debug.util.VariablesUtil;
Expand All @@ -26,6 +26,7 @@
//import org.nodeclipse.ui.preferences.PreferenceConstants;
//import org.nodeclipse.ui.util.NodeclipseConsole;
import org.nodeclipse.enide.gradle.preferences.GradleConstants;
import org.nodeclipse.enide.gradle.util.NodeclipseLogger;
import org.nodeclipse.enide.gradle.util.VariablesUtil;

/**
Expand All @@ -52,7 +53,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
File mavenFile = new File(gradlePath);
if(!mavenFile.exists()){
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
Dialogs.showPreferencesDialog(GradleConstants.PREFERENCES_PAGE,
CommonDialogs.showPreferencesDialog(GradleConstants.PREFERENCES_PAGE,
"Gradle installation is not correctly configured.\n\n"
+ "Please goto Window -> Preferences -> "+GradleConstants.PREFERENCE_PAGE_NAME
+" and configure the correct location");
Expand Down Expand Up @@ -125,6 +126,10 @@ public void launch(ILaunchConfiguration configuration, String mode,
// for(String s : cmdLine) NodeclipseConsole.write(s+" ");
// NodeclipseConsole.write("\n");

StringBuilder sb = new StringBuilder(100);
for(String s : cmdLine) sb.append(s).append(' ');
NodeclipseLogger.log(sb.append('\n').toString());

String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to debug.eg,
Expand Down
Expand Up @@ -16,6 +16,8 @@
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.preference.IPreferenceStore;
import org.nodeclipse.common.preferences.CommonDialogs;
import org.nodeclipse.enide.gradle.Activator;
//import org.eclipse.jface.preference.IPreferenceStore;
//import org.nodeclipse.debug.util.Constants;
//import org.nodeclipse.debug.util.VariablesUtil;
Expand All @@ -24,9 +26,8 @@
//import org.nodeclipse.ui.preferences.PreferenceConstants;
//import org.nodeclipse.ui.util.NodeclipseConsole;
import org.nodeclipse.enide.gradle.preferences.GradleConstants;
import org.nodeclipse.enide.gradle.util.NodeclipseLogger;
import org.nodeclipse.enide.gradle.util.VariablesUtil;
import org.nodeclipse.enide.gradle.Activator;
import org.nodeclipse.enide.gradle.preferences.Dialogs;

/**
* `build.gradle` Run As Gradle GUI<br>
Expand All @@ -52,7 +53,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
File mavenFile = new File(gradlePath);
if(!mavenFile.exists()){
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
Dialogs.showPreferencesDialog(GradleConstants.PREFERENCES_PAGE,
CommonDialogs.showPreferencesDialog(GradleConstants.PREFERENCES_PAGE,
"Gradle installation is not correctly configured.\n\n"
+ "Please goto Window -> Preferences -> "+GradleConstants.PREFERENCE_PAGE_NAME
+" and configure the correct location");
Expand Down Expand Up @@ -100,6 +101,10 @@ public void launch(ILaunchConfiguration configuration, String mode,
// for(String s : cmdLine) NodeclipseConsole.write(s+" ");
// NodeclipseConsole.write("\n");

StringBuilder sb = new StringBuilder(100);
for(String s : cmdLine) sb.append(s).append(' ');
NodeclipseLogger.log(sb.append('\n').toString());

String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to debug.eg,
Expand Down
@@ -1,5 +1,7 @@
package org.nodeclipse.enide.gradle.util;

import org.nodeclipse.common.ui.CommonConsole;

/**
* Allow to use any logger
* @author pverest
Expand All @@ -9,7 +11,7 @@ public class NodeclipseLogger {

public static void log(String message){
System.out.print(message);
//NodeclipseConsole.write(message);
CommonConsole.write(message);
}

}
3 changes: 2 additions & 1 deletion org.nodeclipse.enide.maven/META-INF/MANIFEST.MF
Expand Up @@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.debug.ui,
org.eclipse.core.variables
org.eclipse.core.variables,
org.nodeclipse.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Expand Up @@ -16,15 +16,16 @@
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.preference.IPreferenceStore;
import org.nodeclipse.common.preferences.CommonDialogs;
import org.nodeclipse.enide.maven.Activator;
import org.nodeclipse.enide.maven.preferences.Dialogs;
//import org.nodeclipse.debug.util.Constants;
//import org.nodeclipse.debug.util.VariablesUtil;
//import org.nodeclipse.ui.Activator;
//import org.nodeclipse.ui.preferences.Dialogs;
//import org.nodeclipse.ui.preferences.PreferenceConstants;
//import org.nodeclipse.ui.util.NodeclipseConsole;
import org.nodeclipse.enide.maven.preferences.MavenConstants;
import org.nodeclipse.enide.maven.util.NodeclipseLogger;
import org.nodeclipse.enide.maven.util.VariablesUtil;

/**
Expand All @@ -51,7 +52,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
File mavenFile = new File(mavenPath);
if(!mavenFile.exists()){
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
Dialogs.showPreferencesDialog(MavenConstants.PREFERENCES_PAGE,
CommonDialogs.showPreferencesDialog(MavenConstants.PREFERENCES_PAGE,
"Maven installation is not correctly configured.\n\n"
+ "Please goto Window -> Preferences -> "+MavenConstants.PREFERENCE_PAGE_NAME
+" and configure the correct location");
Expand Down Expand Up @@ -114,6 +115,10 @@ public void launch(ILaunchConfiguration configuration, String mode,
// for(String s : cmdLine) NodeclipseConsole.write(s+" ");
// NodeclipseConsole.write("\n");

StringBuilder sb = new StringBuilder(100);
for(String s : cmdLine) sb.append(s).append(' ');
NodeclipseLogger.log(sb.append('\n').toString());

String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to debug.eg,
Expand Down

0 comments on commit 43c4765

Please sign in to comment.