Author: gmazza
Date: Sun Jul 21 01:32:25 2013
New Revision: 1505251
URL: http://svn.apache.org/r1505251
Log:
Duplicated SQLScriptRunner into app module to break its runtime dependency on
test-utils, various pom simplifications.
Added:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/SQLScriptRunner.java
Modified:
roller/trunk/app/pom.xml
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/DatabaseInstaller.java
roller/trunk/pom.xml
roller/trunk/test-utils/pom.xml
Modified: roller/trunk/app/pom.xml
URL:
http://svn.apache.org/viewvc/roller/trunk/app/pom.xml?rev=1505251&r1=1505250&r2=1505251&view=diff
==============================================================================
--- roller/trunk/app/pom.xml (original)
+++ roller/trunk/app/pom.xml Sun Jul 21 01:32:25 2013
@@ -57,12 +57,6 @@
<dependencies>
- <dependency>
- <groupId>org.apache.roller</groupId>
- <artifactId>test-utils</artifactId>
- <version>${roller.version}</version>
- </dependency>
-
<!-- Eclipselink JPA is the default JPA implementation used by
Roller, comment out this dependency and uncomment Hibernate's
to use that stack instead.
@@ -400,19 +394,6 @@
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>6.1.10</version>
- <scope>provided</scope>
- <exclusions>
- <exclusion>
- <artifactId>servlet-api-2.5</artifactId>
- <groupId>org.mortbay.jetty</groupId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>crowd-integration-client-rest</artifactId>
<version>2.4.0</version>
@@ -449,23 +430,18 @@
<!-- test deps -->
<dependency>
- <groupId>org.apache.derby</groupId>
- <version>${derby.version}</version>
- <artifactId>derby</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbynet</artifactId>
- <version>${derby.version}</version>
- <scope>provided</scope>
+ <groupId>org.apache.roller</groupId>
+ <artifactId>test-utils</artifactId>
+ <version>${roller.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>${derby.version}</version>
- <scope>provided</scope>
</dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -479,26 +455,7 @@
<pluginManagement>
<plugins>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.12.4</version>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-antrun-plugin</artifactId>
- <version>1.7</version>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.6</version>
- </plugin>
-
- <!-- Allow for standalone Tomcat deployment
+ <!-- Allow for standalone Tomcat deployment
using mvn tomcat7:redeploy (See
http://www.jroller.com/gmazza/entry/web_service_tutorial#maventomcat
for necessary config info)
@@ -529,11 +486,6 @@
</plugin>
<plugin>
- <groupId>org.apache.tomcat.maven</groupId>
- <artifactId>tomcat7-maven-plugin</artifactId>
- </plugin>
-
- <plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
@@ -551,41 +503,24 @@
</systemProperties>
</configuration>
<dependencies>
- <dependency>
- <groupId>org.apache.roller</groupId>
- <artifactId>test-utils</artifactId>
- <version>${roller.version}</version>
- </dependency>
-
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.12</version>
- </dependency>
-
+ <!-- Dependencies not needed during testing but when using
mvn jetty:run -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${derby.version}</version>
</dependency>
-
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbynet</artifactId>
- <version>${derby.version}</version>
- </dependency>
-
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>${derby.version}</version>
- </dependency>
+ </dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
-
+ <version>2.6</version>
+
<executions>
<execution>
@@ -653,6 +588,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <version>2.12.4</version>
<configuration>
<forkMode>once</forkMode>
@@ -676,31 +612,9 @@
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.apache.roller</groupId>
- <artifactId>test-utils</artifactId>
- <version>${roller.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- <version>${derby.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbynet</artifactId>
- <version>${derby.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbyclient</artifactId>
- <version>${derby.version}</version>
- </dependency>
- </dependencies>
+ <version>1.7</version>
<executions>
-
<execution>
<id>gen-db-scripts</id>
<phase>compile</phase>
@@ -751,7 +665,7 @@
</goals>
<configuration>
<target>
- <!-- Derby only for unit testing: skip when
maven.text.skip is set -->
+ <!-- Derby only for unit testing: skip when
maven.test.skip is set -->
<taskdef name="stopdb"
classname="org.apache.roller.weblogger.ant.StopDerbyTask"
classpathref="maven.test.classpath"/>
<stopdb
databaseDir="${basedir}/target/derby-system"
@@ -816,12 +730,11 @@
</excludes>
</resource>
<resource>
- <!-- ensure version and persistence files get substitutions -->
+ <!-- ensure version gets substitution -->
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>roller-version.properties</include>
- <include>META-INF/**</include>
</includes>
</resource>
</resources>
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/DatabaseInstaller.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/DatabaseInstaller.java?rev=1505251&r1=1505250&r2=1505251&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/DatabaseInstaller.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/DatabaseInstaller.java
Sun Jul 21 01:32:25 2013
@@ -18,7 +18,6 @@
package org.apache.roller.weblogger.business.startup;
-import org.apache.roller.util.SQLScriptRunner;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
Added:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/SQLScriptRunner.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/SQLScriptRunner.java?rev=1505251&view=auto
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/SQLScriptRunner.java
(added)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/startup/SQLScriptRunner.java
Sun Jul 21 01:32:25 2013
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.business.startup;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.io.*;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * SQL script runner, parses script and allows you to run it.
+ * You can run the script multiple times if necessary.
+ * Assumes that anything on an input line after "--" or ";" can be ignored.
+ */
+public class SQLScriptRunner {
+
+ private List<String> commands = new ArrayList<String>();
+ private List<String> messages = new ArrayList<String>();
+ private boolean failed = false;
+ private boolean errors = false;
+
+
+ /** Creates a new instance of SQLScriptRunner */
+ public SQLScriptRunner(InputStream is) throws IOException {
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
+ String command = "";
+ String line;
+ while ((line = in.readLine()) != null) {
+ line = line.trim();
+
+ if (!line.startsWith("--")) { // ignore lines starting with "--"
+
+ if (line.indexOf("--") > 0) {
+ // trim comment off end of line
+ line = line.substring(0, line.indexOf("--")).trim();
+ }
+
+ // add line to current command
+ command += line.trim();
+ if (command.endsWith(";")) {
+ // ";" is end of command, so add completed command to list
+ String cmd = command.substring(0, command.length() - 1);
+ String[] cmdArray = StringUtils.split(cmd);
+ cmd = StringUtils.join(cmdArray, " ");
+ commands.add(cmd);
+ command = "";
+ } else if (StringUtils.isNotEmpty(command)) {
+ command += " "; // still more command coming so add space
+ }
+ }
+ }
+ in.close();
+ }
+
+
+ /** Creates a new instance of SQLScriptRunner */
+ public SQLScriptRunner(String scriptPath) throws IOException {
+ this(new FileInputStream(scriptPath));
+ }
+
+
+ /** Number of SQL commands in script */
+ public int getCommandCount() {
+ return commands.size();
+ }
+
+
+ /** Return messages from last run of script, empty if no previous run */
+ public List<String> getMessages() {
+ return messages;
+ }
+
+
+ /** Returns true if last call to runScript() threw an exception */
+ public boolean getFailed() {
+ return failed;
+ }
+
+
+ /** Returns true if last run had any errors */
+ public boolean getErrors() {
+ return errors;
+ }
+
+
+ /** Run script, logs messages, and optionally throws exception on error */
+ public void runScript(
+ Connection con, boolean stopOnError) throws SQLException {
+ failed = false;
+ errors = false;
+ for (String command : commands) {
+
+ // run each command
+ try {
+ Statement stmt = con.createStatement();
+ stmt.executeUpdate(command);
+ if (!con.getAutoCommit()) con.commit();
+
+ // on success, echo command to messages
+ successMessage(command);
+
+ } catch (SQLException ex) {
+ // add error message with text of SQL command to messages
+ errorMessage("ERROR: SQLException executing SQL [" + command
+ + "] : " + ex.getLocalizedMessage());
+ // add stack trace to messages
+ StringWriter sw = new StringWriter();
+ ex.printStackTrace(new PrintWriter(sw));
+ errorMessage(sw.toString());
+ if (stopOnError) {
+ failed = true;
+ throw ex;
+ }
+ }
+ }
+ }
+
+
+ private void errorMessage(String msg) {
+ messages.add(msg);
+ }
+
+
+ private void successMessage(String msg) {
+ messages.add(msg);
+ }
+
+}
Modified: roller/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/roller/trunk/pom.xml?rev=1505251&r1=1505250&r2=1505251&view=diff
==============================================================================
--- roller/trunk/pom.xml (original)
+++ roller/trunk/pom.xml Sun Jul 21 01:32:25 2013
@@ -66,24 +66,6 @@
<dependencyManagement>
<dependencies>
<dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- <version>${derby.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbyclient</artifactId>
- <version>${derby.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbynet</artifactId>
- <version>${derby.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
Modified: roller/trunk/test-utils/pom.xml
URL:
http://svn.apache.org/viewvc/roller/trunk/test-utils/pom.xml?rev=1505251&r1=1505250&r2=1505251&view=diff
==============================================================================
--- roller/trunk/test-utils/pom.xml (original)
+++ roller/trunk/test-utils/pom.xml Sun Jul 21 01:32:25 2013
@@ -27,6 +27,12 @@
<dependencies>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.10</version>
+ </dependency>
+
+ <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
@@ -46,23 +52,8 @@
<dependency>
<groupId>org.apache.derby</groupId>
- <artifactId>derbyclient</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.derby</groupId>
<artifactId>derbynet</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>6.1.10</version>
+ <version>${derby.version}</version>
</dependency>
<dependency>