Revision: 6411
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6411&view=rev
Author: manningr
Date: 2011-09-25 15:58:33 +0000 (Sun, 25 Sep 2011)
Log Message:
-----------
Fixed issue where package was not the same as the directory structure of the java source. Also, now the package as well as the plugin name are properties specified during project creation, rather than being hard-coded.
Modified Paths:
--------------
trunk/sql12/plugins/squirrelsql-plugin-archetype/pom.xml
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/it/projects/firsttest/test.properties
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/test/resources/projects/basic/archetype.properties
Added Paths:
-----------
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleExceptionFormatter.java
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleSqlExecutionListener.java
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/__pluginName__Plugin.java
Removed Paths:
-------------
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml
Property Changed:
----------------
trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/
Modified: trunk/sql12/plugins/squirrelsql-plugin-archetype/pom.xml
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/pom.xml 2011-09-24 18:40:50 UTC (rev 6410)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/pom.xml 2011-09-25 15:58:33 UTC (rev 6411)
@@ -11,7 +11,6 @@
<groupId>net.sf.squirrel-sql.plugins</groupId>
<artifactId>squirrelsql-plugin-archetype</artifactId>
- <version>3.3.0-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>SQuirreL Plugin Archetype</name>
@@ -94,72 +93,6 @@
</pluginManagement>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.1</version>
- <executions>
- <execution>
- <id>copy-example-project-java</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack-dependencies</goal>
- </goals>
- <configuration>
- <includeArtifactIds>example</includeArtifactIds>
- <includeClassifiers>sources</includeClassifiers>
- <includes>**\/*.java</includes>
- <excludes>**\/*Test.java</excludes>
- <outputDirectory>src/main/resources/archetype-resources/src/main/java</outputDirectory>
- <markersDirectory>target/dependency-maven-plugin-markers-java</markersDirectory>
- </configuration>
- </execution>
- <execution>
- <id>copy-example-project-java-tests</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack-dependencies</goal>
- </goals>
- <configuration>
- <includeArtifactIds>example</includeArtifactIds>
- <includeClassifiers>test-sources</includeClassifiers>
- <includes>**\/*Test.java</includes>
- <outputDirectory>src/main/resources/archetype-resources/src/test/java</outputDirectory>
- <markersDirectory>target/dependency-maven-plugin-markers-test-java</markersDirectory>
- </configuration>
- </execution>
- <execution>
- <id>copy-example-project-properties</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack-dependencies</goal>
- </goals>
- <configuration>
- <includeArtifactIds>example</includeArtifactIds>
- <includeClassifiers>sources</includeClassifiers>
- <includes>**\/*.properties</includes>
- <outputDirectory>src/main/resources/archetype-resources/src/main/resources</outputDirectory>
- <markersDirectory>target/dependency-maven-plugin-markers-properties</markersDirectory>
- </configuration>
- </execution>
- <execution>
- <id>copy-example-project-docs</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack-dependencies</goal>
- </goals>
- <configuration>
- <includeArtifactIds>example</includeArtifactIds>
- <includeClassifiers>sources</includeClassifiers>
- <includes>**\/*.txt</includes>
- <outputDirectory>src/main/resources/archetype-resources/src/main/resources</outputDirectory>
- <markersDirectory>target/dependency-maven-plugin-markers-docs</markersDirectory>
- </configuration>
- </execution>
-
- </executions>
-
- </plugin>
<!-- This will test that the archetype can be used to create a new plugin
project (in target/it/projects) and that the plugin project will successfully
build. This pattern was found in a discussion about how to test archetypes
@@ -190,6 +123,7 @@
<archetypeGroupId>${project.groupId}</archetypeGroupId>
<archetypeVersion>${project.version}</archetypeVersion>
<interactiveMode>false</interactiveMode>
+ <pluginName>Example</pluginName>
</properties>
</configuration>
</execution>
Modified: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/it/projects/firsttest/test.properties
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/it/projects/firsttest/test.properties 2011-09-24 18:40:50 UTC (rev 6410)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/it/projects/firsttest/test.properties 2011-09-25 15:58:33 UTC (rev 6411)
@@ -1,5 +1,6 @@
-groupId=com.foo
-artifactId=firsttest
+groupId=net.sf.squirrel-sql.plugins
+artifactId=example
version=1.0.0
-package=com.foo.firsttest
+package=net.sourceforge.squirrel_sql.plugins.example
+pluginName=Example
Modified: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml 2011-09-24 18:40:50 UTC (rev 6410)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml 2011-09-25 15:58:33 UTC (rev 6411)
@@ -1,26 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
-<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="example"
- xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <fileSets>
- <fileSet filtered="true" packaged="true" encoding="UTF-8">
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.java</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" encoding="UTF-8">
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*.properties</include>
- <include>**/*.txt</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" packaged="true" encoding="UTF-8">
- <directory>src/test/java</directory>
- <includes>
- <include>**/*.java</include>
- </includes>
- </fileSet>
- </fileSets>
+<archetype-descriptor
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
+ name="example"
+ xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <requiredProperties>
+ <requiredProperty key="pluginName" />
+<!-- <defaultValue>Example</defaultValue> -->
+<!-- </requiredProperty> -->
+ </requiredProperties>
+
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.txt</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
</archetype-descriptor>
Property changes on: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources
___________________________________________________________________
Modified: svn:ignore
- src
+
Deleted: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml 2011-09-24 18:40:50 UTC (rev 6410)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml 2011-09-25 15:58:33 UTC (rev 6411)
@@ -1,129 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>net.sf.squirrel-sql.plugins</groupId>
- <artifactId>squirrelsql-plugins-parent-pom</artifactId>
- <version>3.3.0-SNAPSHOT</version>
- </parent>
-
- <groupId>${groupId}</groupId>
- <artifactId>${artifactId}</artifactId>
- <version>${version}</version>
- <packaging>jar</packaging>
- <description>Example Plugin</description>
- <inceptionYear>2001</inceptionYear>
- <developers>
- <developer>
- <name>Gerd Wagner</name>
- <roles>
- <role>Administrator</role>
- <role>Developer</role>
- </roles>
- </developer>
- <developer>
- <name>Rob Manning</name>
- <roles>
- <role>Developer</role>
- <role>Release Manager</role>
- </roles>
- </developer>
- </developers>
- <licenses>
- <license>
- <name>GNU Lesser General Public License</name>
- <url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- <url>http://www.squirrelsql.org/</url>
- <scm>
- <connection>scm:svn:https://squirrel-sql.svn.sourceforge.net/svnroot/squirrel-sql/trunk/sql12/plugins/oracle</connection>
- <developerConnection>scm:svn:https://squirrel-sql.svn.sourceforge.net/svnroot/squirrel-sql/trunk/sql12/plugins/oracle</developerConnection>
- <url>http://squirrel-sql.svn.sourceforge.net/viewvc/squirrel-sql/trunk/sql12/plugins/oracle</url>
- </scm>
- <issueManagement>
- <system>SourceForge Tracker</system>
- <url>http://sourceforge.net/tracker/?group_id=28383%26atid=393414</url>
- </issueManagement>
- <ciManagement>
- <system>Hudson</system>
- <url>https://www.squirrel-sql.org/hudson/</url>
- </ciManagement>
- <dependencies>
- <dependency>
- <groupId>net.sf.squirrel-sql</groupId>
- <artifactId>fw</artifactId>
- </dependency>
- <dependency>
- <groupId>net.sf.squirrel-sql</groupId>
- <artifactId>fw</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>net.sf.squirrel-sql</groupId>
- <artifactId>squirrel-sql</artifactId>
- </dependency>
- <dependency>
- <groupId>net.sf.squirrel-sql</groupId>
- <artifactId>squirrel-sql</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>gsbase</groupId>
- <artifactId>gsbase</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymockclassextension</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- </dependency>
- <dependency>
- <groupId>net.sf.squirrel-sql.thirdparty-non-maven</groupId>
- <artifactId>treetable</artifactId>
- <version>20040121</version>
- </dependency>
- </dependencies>
- <properties>
- <pluginClassName>net.sourceforge.squirrel_sql.plugins.example.ExamplePlugin</pluginClassName>
- </properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
-</project>
Added: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml (rev 0)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml 2011-09-25 15:58:33 UTC (rev 6411)
@@ -0,0 +1,129 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>net.sf.squirrel-sql.plugins</groupId>
+ <artifactId>squirrelsql-plugins-parent-pom</artifactId>
+ <version>3.3.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+ <packaging>jar</packaging>
+ <description>Example Plugin</description>
+ <inceptionYear>2001</inceptionYear>
+ <developers>
+ <developer>
+ <name>Gerd Wagner</name>
+ <roles>
+ <role>Administrator</role>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <name>Rob Manning</name>
+ <roles>
+ <role>Developer</role>
+ <role>Release Manager</role>
+ </roles>
+ </developer>
+ </developers>
+ <licenses>
+ <license>
+ <name>GNU Lesser General Public License</name>
+ <url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <url>http://www.squirrelsql.org/</url>
+ <scm>
+ <connection>scm:svn:https://squirrel-sql.svn.sourceforge.net/svnroot/squirrel-sql/trunk/sql12/plugins/oracle</connection>
+ <developerConnection>scm:svn:https://squirrel-sql.svn.sourceforge.net/svnroot/squirrel-sql/trunk/sql12/plugins/oracle</developerConnection>
+ <url>http://squirrel-sql.svn.sourceforge.net/viewvc/squirrel-sql/trunk/sql12/plugins/oracle</url>
+ </scm>
+ <issueManagement>
+ <system>SourceForge Tracker</system>
+ <url>http://sourceforge.net/tracker/?group_id=28383%26atid=393414</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Hudson</system>
+ <url>https://www.squirrel-sql.org/hudson/</url>
+ </ciManagement>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>fw</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>fw</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrel-sql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrel-sql</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>gsbase</groupId>
+ <artifactId>gsbase</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql.thirdparty-non-maven</groupId>
+ <artifactId>treetable</artifactId>
+ <version>20040121</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <pluginClassName>net.sourceforge.squirrel_sql.plugins.example.ExamplePlugin</pluginClassName>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleExceptionFormatter.java
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleExceptionFormatter.java (rev 0)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleExceptionFormatter.java 2011-09-25 15:58:33 UTC (rev 6411)
@@ -0,0 +1,61 @@
+package ${package};
+
+import static net.sourceforge.squirrel_sql.fw.util.Utilities.checkNull;
+import net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+public class ExampleExceptionFormatter implements ExceptionFormatter
+{
+
+ /**
+ * In this example, we simply prefix the original exception message with a string that lets us know that
+ * the Example plugin applied a custom format. In a real implementation, you might want to call the
+ * getCause() method on the Throwable to determine if there were chained exceptions available to drill
+ * down to the actual exception that contains the stack trace and message to the very first place in code
+ * where an exception was encountered.
+ *
+ * @see net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter#format(java.lang.Throwable)
+ */
+ @Override
+ public String format(Throwable t) throws Exception
+ {
+ checkNull("format", "t", t);
+ return "ExampleExceptionFormatter: exception message was: "+t.getMessage();
+ }
+
+ /**
+ * In this example if the throwable is not null, we say that we want to format it. This lets SQuirreL
+ * know that it should not apply it's own formatting, but rather use the format applied by this formatter's
+ * format method. In a real implementation which is specific to a vendor's JDBC driver, the Throwable will
+ * be a particular vendor type and probably has a package like com.{vendor}. Also, if the vendor adds
+ * custom methods for accessing the message, they should be called using the Java reflection API so that
+ * compiling this class does not require proprietary class libraries.
+ *
+ * @see net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter#formatsException(java.lang.Throwable)
+ */
+ @Override
+ public boolean formatsException(Throwable t)
+ {
+ checkNull("formatsException", "t", t);
+ return true;
+ }
+
+}
Added: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleSqlExecutionListener.java
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleSqlExecutionListener.java (rev 0)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExampleSqlExecutionListener.java 2011-09-25 15:58:33 UTC (rev 6411)
@@ -0,0 +1,59 @@
+package ${package};
+
+import net.sourceforge.squirrel_sql.client.session.event.ISQLExecutionListener;
+import net.sourceforge.squirrel_sql.client.session.event.SQLExecutionAdapter;
+import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * A simple ISQLExecutionListener that displays the SQL as it is being executed in the main application
+ * message panel (at the bottom of the application).
+ */
+public class ExampleSqlExecutionListener extends SQLExecutionAdapter
+{
+ /** This is what gives the ability to print a message to the message panel */
+ private final IMessageHandler _messageHandler;
+
+ public ExampleSqlExecutionListener(IMessageHandler messageHandler) {
+ _messageHandler = messageHandler;
+ }
+
+ @Override
+ public void statementExecuted(String sql)
+ {
+ _messageHandler.showMessage("statementExecuted: "+sql);
+ }
+
+ @Override
+ public String statementExecuting(String sql)
+ {
+ _messageHandler.showMessage("statementExecuting: "+sql);
+
+ // We don't modify the SQL in this example. in addition to modifying it, we could veto it's execution
+ // by returning null.
+ return sql;
+ }
+
+ public void executionFinished()
+ {
+ }
+
+}
Added: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java (rev 0)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java 2011-09-25 15:58:33 UTC (rev 6411)
@@ -0,0 +1,82 @@
+package ${package};
+
+import java.awt.event.ActionEvent;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.IProcedureInfo;
+import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
+import net.sourceforge.squirrel_sql.fw.util.Resources;
+
+public class ScriptDB2ProcedureAction extends SquirrelAction {
+ private static final long serialVersionUID = 1L;
+
+ transient private ISession _session;
+
+ // /////////////////////////////////////////////////////////
+ // IBM DB 2 specific code to read procedure definitions.
+ private static final String SQL =
+ "SELECT TEXT " +
+ "FROM SYSIBM.SYSPROCEDURES " +
+ "WHERE PROCNAME = ? ";
+
+ public ScriptDB2ProcedureAction(IApplication app, Resources rsrc,
+ ISession session) {
+ super(app, rsrc);
+ _session = session;
+ }
+
+ public void actionPerformed(ActionEvent evt) {
+ PreparedStatement stat = null;
+ ResultSet res = null;
+ try {
+
+ IDatabaseObjectInfo[] dbObjs = _session.getSessionInternalFrame()
+ .getObjectTreeAPI().getSelectedDatabaseObjects();
+
+ stat = _session.getSQLConnection().prepareStatement(SQL);
+
+ StringBuffer script = new StringBuffer();
+ for (int i = 0; i < dbObjs.length; i++) {
+ IProcedureInfo pi = (IProcedureInfo) dbObjs[i];
+ stat.setString(1, pi.getSimpleName());
+ res = stat.executeQuery();
+ res.next();
+ res.getString("TEXT");
+
+ script.append(res.getString("TEXT"));
+ script.append(getStatementSeparator());
+ res.close();
+ }
+ stat.close();
+
+ SessionInternalFrame sessMainFrm = _session
+ .getSessionInternalFrame();
+ sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());
+ sessMainFrm.getSessionPanel().selectMainTab(
+ ISession.IMainPanelTabIndexes.SQL_TAB);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ SQLUtilities.closeResultSet(res);
+ SQLUtilities.closeStatement(stat);
+ }
+ }
+
+ private String getStatementSeparator() {
+ String statementSeparator = _session.getQueryTokenizer()
+ .getSQLStatementSeparator();
+
+ if (1 < statementSeparator.length()) {
+ statementSeparator = "\n" + statementSeparator + "\n";
+ }
+
+ return statementSeparator;
+ }
+
+}
Added: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java (rev 0)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java 2011-09-25 15:58:33 UTC (rev 6411)
@@ -0,0 +1,85 @@
+package ${package};
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.util.Resources;
+
+import java.awt.event.ActionEvent;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+public class ScriptDB2ViewAction extends SquirrelAction
+{
+ private static final long serialVersionUID = 1L;
+
+ private ISession _session;
+
+
+ public ScriptDB2ViewAction(IApplication app, Resources rsrc, ISession session)
+ {
+ super(app, rsrc);
+ _session = session;
+ }
+
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ try
+ {
+ Statement stat = _session.getSQLConnection().createStatement();
+
+ SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame();
+ IDatabaseObjectInfo[] dbObjs = sessMainFrm.getObjectTreeAPI().getSelectedDatabaseObjects();
+
+
+ StringBuffer script = new StringBuffer();
+ for (int i = 0; i < dbObjs.length; i++)
+ {
+ ITableInfo ti = (ITableInfo) dbObjs[i];
+
+ ///////////////////////////////////////////////////////////
+ // IBM DB 2 specific code to read view definitions.
+ String sql =
+ "SELECT TEXT " +
+ "FROM SYSIBM.SYSVIEWS " +
+ "WHERE NAME = '" + ti.getSimpleName() + "'";
+
+ ResultSet res = stat.executeQuery(sql);
+ res.next();
+
+ script.append(res.getString("TEXT"));
+ script.append(getStatementSeparator());
+ res.close();
+ //
+ ///////////////////////////////////////////////////////////
+ }
+
+ stat.close();
+
+ sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());
+ sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String getStatementSeparator()
+ {
+ String statementSeparator = _session.getQueryTokenizer().getSQLStatementSeparator();
+
+ if (1 < statementSeparator.length())
+ {
+ statementSeparator = "\n" + statementSeparator + "\n";
+ }
+
+ return statementSeparator;
+ }
+
+
+}
Added: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/__pluginName__Plugin.java
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/__pluginName__Plugin.java (rev 0)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/__pluginName__Plugin.java 2011-09-25 15:58:33 UTC (rev 6411)
@@ -0,0 +1,180 @@
+package ${package};
+
+import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
+import net.sourceforge.squirrel_sql.client.plugin.PluginException;
+import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
+import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
+import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallbackAdaptor;
+import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
+import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
+import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
+
+/**
+ * <pre>
+ * The Example plugin class. If the database session's type is DB2, this plugin registers a menu action in
+ * the popup menu for view and procedure nodes in the ObjectTree.
+ *
+ * For detailed information and usage of the Plugin API see the following:
+ *
+ * https://sourceforge.net/apps/trac/squirrel-sql/wiki/SQuirreLSQLClientPluginAPI
+ * </pre>
+ */
+public class ${pluginName}Plugin extends DefaultSessionPlugin
+{
+ private PluginResources _resources;
+
+ /**
+ * Return the internal name of this plugin.
+ *
+ * @return the internal name of this plugin.
+ */
+ public String getInternalName()
+ {
+ return "${artifactId}";
+ }
+
+ /**
+ * Return the descriptive name of this plugin.
+ *
+ * @return the descriptive name of this plugin.
+ */
+ public String getDescriptiveName()
+ {
+ return "${pluginName} Plugin";
+ }
+
+ /**
+ * Returns the current version of this plugin.
+ *
+ * @return the current version of this plugin.
+ */
+ public String getVersion()
+ {
+ return "0.01";
+ }
+
+ /**
+ * Returns the authors name.
+ *
+ * @return the authors name.
+ */
+ public String getAuthor()
+ {
+ return "Your Name Here";
+ }
+
+ /**
+ * Returns the name of the change log for the plugin. This should be a text or HTML file residing in the
+ * <TT>getPluginAppSettingsFolder</TT> directory.
+ *
+ * @return the changelog file name or <TT>null</TT> if plugin doesn't have a change log.
+ */
+ public String getChangeLogFileName()
+ {
+ return "changes.txt";
+ }
+
+ /**
+ * Returns the name of the Help file for the plugin. This should be a text or HTML file residing in the
+ * <TT>getPluginAppSettingsFolder</TT> directory.
+ *
+ * @return the Help file name or <TT>null</TT> if plugin doesn't have a help file.
+ */
+ public String getHelpFileName()
+ {
+ return "readme.txt";
+ }
+
+ /**
+ * Returns the name of the Licence file for the plugin. This should be a text or HTML file residing in the
+ * <TT>getPluginAppSettingsFolder</TT> directory.
+ *
+ * @return the Licence file name or <TT>null</TT> if plugin doesn't have a licence file.
+ */
+ public String getLicenceFileName()
+ {
+ return "licence.txt";
+ }
+
+ /**
+ * @return Comma separated list of contributors.
+ */
+ public String getContributors()
+ {
+ return "";
+ }
+
+ /**
+ * Create preferences panel for the Global Preferences dialog.
+ *
+ * @return Preferences panel.
+ */
+ public IGlobalPreferencesPanel[] getGlobalPreferencePanels()
+ {
+ return new IGlobalPreferencesPanel[0];
+ }
+
+ /**
+ * Initialize this plugin.
+ */
+ public synchronized void initialize() throws PluginException
+ {
+ _resources = new PluginResources("${package}.${artifactId}", this);
+ }
+
+ /**
+ * Called when a session started. Add commands to popup menu in object tree.
+ *
+ * @param session
+ * The session that is starting.
+ * @return An implementation of PluginSessionCallback or null to indicate the plugin does not work with
+ * this session
+ */
+ public PluginSessionCallback sessionStarted(ISession session)
+ {
+ // Adds the view and procedure script actions if the session is DB2.
+ addTreeNodeMenuActionsForDB2(session);
+
+ // Register a custom ISQLExecutionListener implementation that simply prints all SQL being executed to
+ // the message panel.
+ IMessageHandler messageHandler = session.getApplication().getMessageHandler();
+ ExampleSqlExecutionListener sqlExecutionListener = new ExampleSqlExecutionListener(messageHandler);
+ session.getSessionSheet().getSQLPaneAPI().addSQLExecutionListener(sqlExecutionListener);
+
+ // We will override the default behavior of formatting exception messages that SQuirreL provides for
+ // this session with our own. If this was a real plugin implementation, care would need to be taken
+ // that the custom formatter is only applied to database vendor sessions that this plugin was written
+ // for. SQuirreL doesn't support registering multiple exception formatters for a single session. The
+ // last one to register overrides all former registrations and results in a log warning message.
+ session.setExceptionFormatter(new ExampleExceptionFormatter());
+
+ return new PluginSessionCallbackAdaptor(this);
+ }
+
+ private void addTreeNodeMenuActionsForDB2(ISession session)
+ {
+ try
+ {
+ if (DialectFactory.isDB2(session.getMetaData()))
+ {
+ // Plugin knows only how to script Views and Stored Procedures on DB2.
+ // So if it's not a DB2 Session we tell SQuirreL the Plugin should not be used.
+
+ // Add context menu items to the object tree's view and procedure nodes.
+ IObjectTreeAPI otApi = session.getSessionInternalFrame().getObjectTreeAPI();
+ otApi.addToPopup(DatabaseObjectType.VIEW, new ScriptDB2ViewAction(session.getApplication(),
+ _resources, session));
+ otApi.addToPopup(DatabaseObjectType.PROCEDURE, new ScriptDB2ProcedureAction(
+ session.getApplication(), _resources, session));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Modified: trunk/sql12/plugins/squirrelsql-plugin-archetype/src/test/resources/projects/basic/archetype.properties
===================================================================
--- trunk/sql12/plugins/squirrelsql-plugin-archetype/src/test/resources/projects/basic/archetype.properties 2011-09-24 18:40:50 UTC (rev 6410)
+++ trunk/sql12/plugins/squirrelsql-plugin-archetype/src/test/resources/projects/basic/archetype.properties 2011-09-25 15:58:33 UTC (rev 6411)
@@ -1,3 +1,4 @@
version=0.1-SNAPSHOT
groupId=archetype.it
artifactId=basic
+pluginName=Example
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|