getFileNames() {
+ return this.files;
+ }
+
+ /**
+ * Search if the provided path exists in this directory or below
+ *
+ * @return true, if the provided path can be reached from the current
+ * directory
+ */
+ public boolean pathExists(String path) {
+ //Check if the path points to a dir first
+ InMemoryDirectory dir = getSubdirectoryByName(path);
+
+ if (dir != null) {
+ return true;
+ }
+
+ // Split directory part from (possible) file part and re-check
+ String file = path.substring(path.lastIndexOf('/') + 1, path.length());
+ path = path.substring(0, path.lastIndexOf('/'));
+ dir = getSubdirectoryByName(path);
+
+ if (dir == null) {
+ // Dir not found
+ return false;
+ }
+
+ //Dir found, search files for matching file name
+ if (dir.getFiles().contains(file)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Adds a file.
+ *
+ * @param path The filename relative to this directory.
+ */
+ public void addFile(String path) {
+ if (path.indexOf('/') == -1 ) {
+ if (!files.contains(path)) {
+ files.add(path);
+ }
+ } else {
+ String pathName = path.substring(0, path.indexOf('/'));
+ String fileName = path.substring(path.indexOf('/') + 1);
+ InMemoryDirectory dir = getOrCreateSubdirectoryByName(pathName);
+ dir.addFile(fileName);
+ }
+ }
+
+ /**
+ * Deletes a file.
+ * @param path The filename relative to this directory.
+ */
+ public void deleteFile(String path) {
+ if (path.indexOf('/') == -1) {
+ // might be a file
+ files.remove(path);
+ // but it might even be a directory...
+ directories.remove(getSubdirectoryByName(path));
+ } else {
+ String pathName = path.substring(0, path.indexOf('/'));
+ String fileName = path.substring(path.indexOf('/') + 1);
+ InMemoryDirectory dir = getSubdirectoryByName(pathName);
+ if (dir != null ) {
+ dir.deleteFile(fileName);
+ }
+ }
+ }
+
+ /**
+ * Gets a subdirectory.
+ * @param path The name of the directory.
+ * @return An InMemoryDirectory reference.
+ */
+ public InMemoryDirectory getSubdirectoryByName(String path) {
+ if (path == null || path.equals("")) {
+ return this;
+ } else if (path.indexOf('/') == -1 ) {
+ for (InMemoryDirectory dir : directories) {
+ if (dir.getName().equals(path)) {
+ return dir;
+ }
+ }
+ return null;
+ }
+ String pathName = path.substring(0, path.indexOf('/'));
+ String fileName = path.substring(path.indexOf('/') + 1);
+
+ return getSubdirectoryByName(pathName).getSubdirectoryByName(fileName);
+ }
+
+ /**
+ * Creates a subdirectory
+ * @param name The name of the subdirectory to create.
+ * @return A reference to the new directory.
+ */
+ public InMemoryDirectory createSubDirectory(String name) {
+ if (name == null || name.equals("")) {
+ return this;
+ } else if (name.indexOf('/') == -1) {
+ InMemoryDirectory dir = getSubdirectoryByName(name);
+ if (dir == null ) {
+ dir = new InMemoryDirectoryImpl(this, name);
+ }
+ if (!directories.contains(dir)) {
+ directories.add(dir);
+ }
+ return getSubdirectoryByName(name);
+ } else {
+ String pathName = name.substring(0, name.indexOf('/'));
+ String fileName = name.substring(name.indexOf('/') + 1);
+ InMemoryDirectory dir = getOrCreateSubdirectoryByName(pathName);
+ return dir.createSubDirectory(fileName);
+ }
+
+ }
+
+ /**
+ * Gets a subdirectory. If the wanted one couldn't be found, it's created.
+ * @param name The name of the directory.
+ * @return An InMemoryDirectory reference.
+ */
+ protected InMemoryDirectory getOrCreateSubdirectoryByName(String name) {
+ // if it's empty, it's us!
+ if (name.length() == 0) {
+ return this;
+ }
+
+ for (InMemoryDirectory dir : directories) {
+ if (dir.getName().equals(name) ) {
+ return dir;
+ }
+ }
+
+ // not found? create it
+ return createSubDirectory(name);
+ }
+
+ /**
+ * Nice formatting of this directory including subdirectories and files.
+ * @param indentation The indentation of the root.
+ * @return A String containing a nicely formatted directory tree.
+ */
+ public String toString(int indentation) {
+ String result = "";
+ String indent = "";
+ for (int i=0; i < indentation; ++i)
+ indent = indent + " ";
+
+ result = result + indent + getName() + "\n";
+
+ for (InMemoryDirectory d: directories) {
+ result = result + d.toString(indentation + 1);
+ }
+ for (String file: files) {
+ result = result + indent + " " + file + "\n";
+ }
+
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return toString(0);
+ }
+}
+
+// vi: ai nosi sw=4 ts=4 expandtab
diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/scheduler/WorkerThreadImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/scheduler/WorkerThreadImpl.java
index c5399e7a4..d670eb71b 100644
--- a/alitheia/core/src/main/java/eu/sqooss/impl/service/scheduler/WorkerThreadImpl.java
+++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/scheduler/WorkerThreadImpl.java
@@ -35,11 +35,7 @@
import eu.sqooss.core.AlitheiaCore;
import eu.sqooss.service.logging.Logger;
-import eu.sqooss.service.scheduler.Job;
-import eu.sqooss.service.scheduler.ResumePoint;
-import eu.sqooss.service.scheduler.Scheduler;
-import eu.sqooss.service.scheduler.SchedulerException;
-import eu.sqooss.service.scheduler.WorkerThread;
+import eu.sqooss.service.scheduler.*;
/**
* Worker thread executing jobs given by a scheduler.
@@ -120,8 +116,9 @@ protected void executeJob(Job j) {
m_job = j;
if (m_job.state() == Job.State.Yielded) {
time = m_job.resume();
- } else {
- time = m_job.execute();
+ } else {
+ JobExecutor jobExecutor = new JobExecutor();
+ time = jobExecutor.execute(m_job);
}
} catch (ClassCastException cce) {
AlitheiaCore.getInstance().getLogManager().createLogger(
diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/webadmin/ProjectsView.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/webadmin/ProjectsView.java
index 2975b36d6..16c8fdee2 100644
--- a/alitheia/core/src/main/java/eu/sqooss/impl/service/webadmin/ProjectsView.java
+++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/webadmin/ProjectsView.java
@@ -40,6 +40,7 @@
import javax.servlet.http.HttpServletRequest;
+import eu.sqooss.service.db.*;
import org.apache.velocity.VelocityContext;
import org.osgi.framework.BundleContext;
@@ -49,11 +50,6 @@
import eu.sqooss.service.admin.AdminService;
import eu.sqooss.service.admin.actions.AddProject;
import eu.sqooss.service.admin.actions.UpdateProject;
-import eu.sqooss.service.db.Bug;
-import eu.sqooss.service.db.ClusterNode;
-import eu.sqooss.service.db.MailMessage;
-import eu.sqooss.service.db.ProjectVersion;
-import eu.sqooss.service.db.StoredProject;
import eu.sqooss.service.pa.PluginInfo;
import eu.sqooss.service.scheduler.SchedulerException;
import eu.sqooss.service.updater.Updater;
@@ -490,7 +486,8 @@ else if ((reqValAction.equals(ACT_REQ_REM_PROJECT))
+ ((mm == null)?getLbl("l0051"):mm.getSendDate())
+ "\n");
// ID of the last known bug entry
- Bug bug = Bug.getLastUpdate(nextPrj);
+ BugRepository bugRepository = new BugRepository();
+ Bug bug = bugRepository.getLastUpdate(nextPrj);
b.append(sp(in) + "| "
+ ((bug == null)?getLbl("l0051"):bug.getBugID())
+ " | \n");
diff --git a/alitheia/core/src/main/java/eu/sqooss/service/db/Bug.java b/alitheia/core/src/main/java/eu/sqooss/service/db/Bug.java
index 78b67dad8..92702fd81 100644
--- a/alitheia/core/src/main/java/eu/sqooss/service/db/Bug.java
+++ b/alitheia/core/src/main/java/eu/sqooss/service/db/Bug.java
@@ -231,87 +231,9 @@ public Date getUpdateRun() {
public void setUpdateRun(Date updateRun) {
this.updateRun = updateRun;
}
+
- /**
- * Get the latest entry processed by the bug updater
- */
- @SuppressWarnings("unchecked")
- public static Bug getLastUpdate(StoredProject sp) {
- DBService dbs = AlitheiaCore.getInstance().getDBService();
-
- if (sp == null)
- return null;
-
- String paramStoredProject = "storedProject";
-
- String query = " select b " +
- " from Bug b, StoredProject sp" +
- " where b.project=sp" +
- " and sp = :" + paramStoredProject +
- " order by b.updateRun desc";
-
- Map params = new HashMap();
- params.put(paramStoredProject, sp);
-
- List buglist = (List) dbs.doHQL(query, params,1);
-
- if (buglist.isEmpty())
- return null;
-
- return buglist.get(0);
- }
-
- /**
- * Get a list of all bug report comments for this specific bug,
- * ordered by the time the comment was left (old to new).
- */
- @SuppressWarnings("unchecked")
- public List getAllReportComments() {
- DBService dbs = AlitheiaCore.getInstance().getDBService();
-
- String paramBugID = "paramBugID";
- String paramStoredProject = "stroredProject";
-
- String query = "select brm " +
- "from Bug b, BugReportMessage brm " +
- "where brm.bug = b " +
- "and b.bugID = :" + paramBugID +
- " and b.project =:" + paramStoredProject +
- " order by brm.timestamp asc" ;
-
- Map params = new HashMap();
- params.put(paramBugID, bugID);
- params.put(paramStoredProject, project);
-
- return (List) dbs.doHQL(query, params);
- }
-
- /**
- * Get the latest entry for the bug with the provided Id.
- */
- public static Bug getBug(String bugID, StoredProject sp) {
- DBService dbs = AlitheiaCore.getInstance().getDBService();
-
- String paramBugID = "paramBugID";
- String paramStoredProject = "stroredProject";
-
- String query = "select b " +
- "from Bug b " +
- "where b.bugID = :" + paramBugID +
- " and b.project = :" + paramStoredProject +
- " order by b.timestamp desc";
-
- Map params = new HashMap();
- params.put(paramBugID, bugID);
- params.put(paramStoredProject, sp);
-
- List bug = (List) dbs.doHQL(query, params, 1);
-
- if (bug.isEmpty())
- return null;
- else
- return bug.get(0);
- }
+
}
//vi: ai nosi sw=4 ts=4 expandtab
diff --git a/alitheia/core/src/main/java/eu/sqooss/service/db/BugRepository.java b/alitheia/core/src/main/java/eu/sqooss/service/db/BugRepository.java
new file mode 100644
index 000000000..2ec157b9e
--- /dev/null
+++ b/alitheia/core/src/main/java/eu/sqooss/service/db/BugRepository.java
@@ -0,0 +1,92 @@
+package eu.sqooss.service.db;
+
+import eu.sqooss.core.AlitheiaCore;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class BugRepository {
+
+ /**
+ * Get a list of all bug report comments for a specific bug,
+ * ordered by the time the comment was left (old to new).
+ */
+ @SuppressWarnings("unchecked")
+ public List getAllReportComments(Bug bug) {
+ DBService dbs = AlitheiaCore.getInstance().getDBService();
+
+ String paramBugID = "paramBugID";
+ String paramStoredProject = "storedProject";
+
+ String query = "select brm " +
+ "from Bug b, BugReportMessage brm " +
+ "where brm.bug = b " +
+ "and b.bugID = :" + paramBugID +
+ " and b.project =:" + paramStoredProject +
+ " order by brm.timestamp asc" ;
+
+ Map params = new HashMap();
+ params.put(paramBugID, bug.getBugID());
+ params.put(paramStoredProject, bug.getProject());
+
+ return (List) dbs.doHQL(query, params);
+ }
+
+ /**
+ * Get the latest entry for the bug with the provided Id.
+ */
+ public Bug getBug(String bugID, StoredProject sp) {
+ DBService dbs = AlitheiaCore.getInstance().getDBService();
+
+ String paramBugID = "paramBugID";
+ String paramStoredProject = "storedProject";
+
+ String query = "select b " +
+ "from Bug b " +
+ "where b.bugID = :" + paramBugID +
+ " and b.project = :" + paramStoredProject +
+ " order by b.timestamp desc";
+
+ Map params = new HashMap();
+ params.put(paramBugID, bugID);
+ params.put(paramStoredProject, sp);
+
+ List bug = (List) dbs.doHQL(query, params, 1);
+
+ if (bug.isEmpty())
+ return null;
+ else
+ return bug.get(0);
+ }
+
+ /**
+ * Get the latest entry processed by the bug updater
+ */
+ @SuppressWarnings("unchecked")
+ public Bug getLastUpdate(StoredProject sp) {
+ DBService dbs = AlitheiaCore.getInstance().getDBService();
+
+ if (sp == null)
+ return null;
+
+ String paramStoredProject = "storedProject";
+
+ String query = " select b " +
+ " from Bug b, StoredProject sp" +
+ " where b.project=sp" +
+ " and sp = :" + paramStoredProject +
+ " order by b.updateRun desc";
+
+ Map params = new HashMap();
+ params.put(paramStoredProject, sp);
+
+ List buglist = (List) dbs.doHQL(query, params,1);
+
+ if (buglist.isEmpty())
+ return null;
+
+ return buglist.get(0);
+ }
+
+}
diff --git a/alitheia/core/src/main/java/eu/sqooss/service/fds/InMemoryDirectory.java b/alitheia/core/src/main/java/eu/sqooss/service/fds/InMemoryDirectory.java
index d8344b814..7c3e8350b 100644
--- a/alitheia/core/src/main/java/eu/sqooss/service/fds/InMemoryDirectory.java
+++ b/alitheia/core/src/main/java/eu/sqooss/service/fds/InMemoryDirectory.java
@@ -1,335 +1,25 @@
-/*
- * This file is part of the Alitheia system, developed by the SQO-OSS
- * consortium as part of the IST FP6 SQO-OSS project, number 033331.
- *
- * Copyright 2007 - 2010 - Organization for Free and Open Source Software,
- * Athens, Greece.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
package eu.sqooss.service.fds;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import eu.sqooss.service.db.Directory;
import eu.sqooss.service.db.ProjectFile;
-import eu.sqooss.service.db.ProjectVersion;
-import eu.sqooss.service.util.FileUtils;
-
-/**
- * An InMemoryDirectory object represents part of an in-memory
- * checkout. InMemoryDirectory objects hang together in a tree
- * for a directory hierarchy. Each directory may contain
- * files; you can use getFile() to retrieve references to
- * project files from the checkout.
- */
-public class InMemoryDirectory {
-
- private InMemoryCheckout checkout;
- private InMemoryDirectory parentDirectory;
-
- private String name;
-
- private List files;
- private List directories;
-
- public InMemoryDirectory() {
- name = new String();
- files = new LinkedList();
- directories = new LinkedList();
- }
-
- public InMemoryDirectory(String name) {
- this();
- this.name = name;
- }
-
- public InMemoryDirectory(InMemoryCheckout checkout) {
- this("");
- this.checkout = checkout;
- }
-
- public InMemoryDirectory(InMemoryDirectory parent, String name) {
- this(name);
- this.parentDirectory = parent;
- }
-
- /**
- * Returns the name of the directory.
- * Returns an empty string for the project's root directory.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the complete path of this directory.
- */
- public String getPath() {
- if (parentDirectory==null) {
- return "/" + getName();
- } else {
- String parentPath = parentDirectory.getPath();
- if (!parentPath.endsWith("/")) {
- parentPath = parentPath + "/";
- }
- return parentPath + getName();
- }
- }
-
- /**
- * Returns this directory's parent directory.
- * Might be null, if this is the root directory.
- */
- public InMemoryDirectory getParentDirectory() {
- return parentDirectory;
- }
-
- /**
- * Returns the checkout this directory belongs to.
- */
- public InMemoryCheckout getCheckout() {
- return checkout == null ? parentDirectory.getCheckout() : checkout;
- }
-
- /**
- * Returns the list of subdirectories this directory has.
- */
- public List getSubDirectories() {
- return directories;
- }
-
- /**
- * Returns one file living in this directory or below.
- * @param name The filename relative to this directory.
- * @return A reference to a ProjectFile
- */
- public ProjectFile getFile(String name) {
-
- /*Recursively traverse the directories of the provided file path*/
- if (name.indexOf('/') != -1 ) {
- String pathName = name.substring(0, name.indexOf('/'));
- String fileName = name.substring(name.indexOf('/') + 1);
- InMemoryDirectory dir = getSubdirectoryByName(pathName);
- return dir == null ? null : dir.getFile(fileName);
- }
- return ProjectFile.findFile(
- getCheckout().getProjectVersion().getProject().getId(),
- FileUtils.basename(name),
- FileUtils.dirname(name),
- getCheckout().getProjectVersion().getRevisionId());
-
- }
-
- /**
- * Returns the list of files this directory contains.
- */
- public List getFiles() {
- @SuppressWarnings("unused")
- ArrayList result = new ArrayList(files.size());
-
- return getCheckout().getProjectVersion().getFiles(
- Directory.getDirectory(getPath(), false),
- ProjectVersion.MASK_FILES);
- }
-
- public List getFileNames() {
- return this.files;
- }
-
- /**
- * Search if the provided path exists in this directory or below
- *
- * @return true, if the provided path can be reached from the current
- * directory
- */
- public boolean pathExists(String path) {
- //Check if the path points to a dir first
- InMemoryDirectory dir = getSubdirectoryByName(path);
-
- if (dir != null) {
- return true;
- }
-
- // Split directory part from (possible) file part and re-check
- String file = path.substring(path.lastIndexOf('/') + 1, path.length());
- path = path.substring(0, path.lastIndexOf('/'));
- dir = getSubdirectoryByName(path);
-
- if (dir == null) {
- // Dir not found
- return false;
- }
-
- //Dir found, search files for matching file name
- if (dir.getFiles().contains(file)) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Adds a file.
- *
- * @param path The filename relative to this directory.
- */
- public void addFile(String path) {
- if (path.indexOf('/') == -1 ) {
- if (!files.contains(path)) {
- files.add(path);
- }
- } else {
- String pathName = path.substring(0, path.indexOf('/'));
- String fileName = path.substring(path.indexOf('/') + 1);
- InMemoryDirectory dir = getOrCreateSubdirectoryByName(pathName);
- dir.addFile(fileName);
- }
- }
-
- /**
- * Deletes a file.
- * @param path The filename relative to this directory.
- */
- public void deleteFile(String path) {
- if (path.indexOf('/') == -1) {
- // might be a file
- files.remove(path);
- // but it might even be a directory...
- directories.remove(getSubdirectoryByName(path));
- } else {
- String pathName = path.substring(0, path.indexOf('/'));
- String fileName = path.substring(path.indexOf('/') + 1);
- InMemoryDirectory dir = getSubdirectoryByName(pathName);
- if (dir != null ) {
- dir.deleteFile(fileName);
- }
- }
- }
-
- /**
- * Gets a subdirectory.
- * @param path The name of the directory.
- * @return An InMemoryDirectory reference.
- */
- public InMemoryDirectory getSubdirectoryByName(String path) {
- if (path == null || path.equals("")) {
- return this;
- } else if (path.indexOf('/') == -1 ) {
- for (InMemoryDirectory dir : directories) {
- if (dir.getName().equals(path)) {
- return dir;
- }
- }
- return null;
- }
- String pathName = path.substring(0, path.indexOf('/'));
- String fileName = path.substring(path.indexOf('/') + 1);
+import java.util.List;
- return getSubdirectoryByName(pathName).getSubdirectoryByName(fileName);
- }
-
- /**
- * Creates a subdirectory
- * @param name The name of the subdirectory to create.
- * @return A reference to the new directory.
- */
- public InMemoryDirectory createSubDirectory(String name) {
- if (name == null || name.equals("")) {
- return this;
- } else if (name.indexOf('/') == -1) {
- InMemoryDirectory dir = getSubdirectoryByName(name);
- if (dir == null ) {
- dir = new InMemoryDirectory(this, name);
- }
- if (!directories.contains(dir)) {
- directories.add(dir);
- }
- return getSubdirectoryByName(name);
- } else {
- String pathName = name.substring(0, name.indexOf('/'));
- String fileName = name.substring(name.indexOf('/') + 1);
- InMemoryDirectory dir = getOrCreateSubdirectoryByName(pathName);
- return dir.createSubDirectory(fileName);
- }
-
- }
-
- /**
- * Gets a subdirectory. If the wanted one couldn't be found, it's created.
- * @param name The name of the directory.
- * @return An InMemoryDirectory reference.
- */
- protected InMemoryDirectory getOrCreateSubdirectoryByName(String name) {
- // if it's empty, it's us!
- if (name.length() == 0) {
- return this;
- }
-
- for (InMemoryDirectory dir : directories) {
- if (dir.getName().equals(name) ) {
- return dir;
- }
- }
+public interface InMemoryDirectory {
+
+ public String getName();
+ public String getPath();
+ public InMemoryDirectory getParentDirectory();
+ public InMemoryCheckout getCheckout();
+ public List getSubDirectories();
+ public ProjectFile getFile(String name);
+ public List getFiles();
+ public List getFileNames();
+ public boolean pathExists(String path);
+ public void addFile(String path);
+ public void deleteFile(String path);
+ public InMemoryDirectory getSubdirectoryByName(String path);
+ public InMemoryDirectory createSubDirectory(String name);
+ public String toString(int indentation);
- // not found? create it
- return createSubDirectory(name);
- }
-
- /**
- * Nice formatting of this directory including subdirectories and files.
- * @param indentation The indentation of the root.
- * @return A String containing a nicely formatted directory tree.
- */
- protected String toString(int indentation) {
- String result = "";
- String indent = "";
- for (int i=0; i < indentation; ++i)
- indent = indent + " ";
-
- result = result + indent + getName() + "\n";
-
- for (InMemoryDirectory d: directories) {
- result = result + d.toString(indentation + 1);
- }
- for (String file: files) {
- result = result + indent + " " + file + "\n";
- }
-
- return result;
- }
-
- /** {@inheritDoc} */
- public String toString() {
- return toString(0);
- }
}
-// vi: ai nosi sw=4 ts=4 expandtab
diff --git a/alitheia/core/src/main/java/eu/sqooss/service/scheduler/Job.java b/alitheia/core/src/main/java/eu/sqooss/service/scheduler/Job.java
index 62e9745cc..5a729e062 100644
--- a/alitheia/core/src/main/java/eu/sqooss/service/scheduler/Job.java
+++ b/alitheia/core/src/main/java/eu/sqooss/service/scheduler/Job.java
@@ -208,42 +208,7 @@ private final synchronized void removeDependee(Job other) {
}
}
- /**
- * Executes the job. Makes sure that all dependencies are met.
- *
- * @return The time required to execute the Job in milliseconds.
- * @throws Exception
- */
- final public long execute() throws Exception {
- DBService dbs = AlitheiaCore.getInstance().getDBService();
- long timer = System.currentTimeMillis();
- try {
- setState(State.Running);
- restart();
-
- /*Idiot/bad programmer proofing*/
- assert (!dbs.isDBSessionActive());
- if (dbs.isDBSessionActive()) {
- dbs.rollbackDBSession();
- setState(State.Error); //No uncommitted sessions are tolerated
- } else {
- if (state() != State.Yielded)
- setState(State.Finished);
- }
- } catch(Exception e) {
-
- if (dbs.isDBSessionActive()) {
- dbs.rollbackDBSession();
- }
-
- // In case of an exception, state becomes Error
- m_errorException = e;
- setState(State.Error);
- // the Exception itself is forwarded
- throw e;
- }
- return System.currentTimeMillis() - timer;
- }
+
/**
* Sets the job's state to Queued and informs the job about the new
@@ -303,41 +268,6 @@ public final List dependencies() {
return result;
}
- /**
- * Waits for the job to finish.
- * Note that this method even returns when the job's state changes to Error.
- */
- public final void waitForFinished() {
- try {
- synchronized (this) {
- // if this method is running inside of a WorkerThread
- // we try to pass the job we're waiting for to the thread.
- if (Thread.currentThread() instanceof WorkerThread) {
- WorkerThread t = (WorkerThread) Thread.currentThread();
- t.takeJob(this);
- } else {
- throw new Exception();
- }
- }
- } catch (Exception e) {
- // if something went wrong with taking the job
- // ok - we might be stuck...
- if (m_scheduler.getSchedulerStats().getIdleWorkerThreads() == 0) {
- m_scheduler.startOneShotWorkerThread();
- }
- }
- synchronized (this) {
- while (state() != State.Finished) {
- if (state() == State.Error) {
- return;
- }
- try {
- wait();
- } catch (InterruptedException e) {
- }
- }
- }
- }
/**
* Checks, whether all dependencies are met and the job can be executed.
@@ -363,6 +293,10 @@ public final Exception getErrorException() {
return this.m_errorException;
}
+ /* package */ final void setErrorException(Exception e) {
+ m_errorException = e;
+ }
+
/**
* XXX bogus method, only used for putting it in into a Pair.
*/
@@ -384,7 +318,7 @@ protected Job() {
* Sets the job's state.
* @param s The new state.
*/
- protected final void setState(State s) {
+ /* package */ final void setState(State s) {
if (m_state == s) {
return;
}
@@ -456,7 +390,7 @@ protected final void callDependenciesChanged() {
* @throws Exception to signify that the maximum number of restarts
* was reached
*/
- protected void restart() throws Exception {
+ public void restart() throws Exception {
restarts++;
if (restarts >= 5) {
throw new Exception("Too many restarts - failing job");
diff --git a/alitheia/core/src/main/java/eu/sqooss/service/scheduler/JobExecutor.java b/alitheia/core/src/main/java/eu/sqooss/service/scheduler/JobExecutor.java
new file mode 100644
index 000000000..75c63192c
--- /dev/null
+++ b/alitheia/core/src/main/java/eu/sqooss/service/scheduler/JobExecutor.java
@@ -0,0 +1,81 @@
+package eu.sqooss.service.scheduler;
+
+import eu.sqooss.core.AlitheiaCore;
+import eu.sqooss.service.db.DBService;
+
+public class JobExecutor {
+
+ /**
+ * Executes the job. Makes sure that all dependencies are met.
+ *
+ * @return The time required to execute the Job in milliseconds.
+ * @throws Exception
+ */
+ final public long execute(Job job) throws Exception {
+ DBService dbs = AlitheiaCore.getInstance().getDBService();
+ long timer = System.currentTimeMillis();
+ try {
+ job.setState(Job.State.Running);
+ job.restart();
+
+ /*Idiot/bad programmer proofing*/
+ assert (!dbs.isDBSessionActive());
+ if (dbs.isDBSessionActive()) {
+ dbs.rollbackDBSession();
+ job.setState(Job.State.Error); //No uncommitted sessions are tolerated
+ } else {
+ if (job.state() != Job.State.Yielded)
+ job.setState(Job.State.Finished);
+ }
+ } catch(Exception e) {
+
+ if (dbs.isDBSessionActive()) {
+ dbs.rollbackDBSession();
+ }
+
+ // In case of an exception, state becomes Error
+ job.setErrorException(e);
+ job.setState(Job.State.Error);
+ // the Exception itself is forwarded
+ throw e;
+ }
+ return System.currentTimeMillis() - timer;
+ }
+
+ /**
+ * Waits for the job to finish.
+ * Note that this method even returns when the job's state changes to Error.
+ */
+ public final void waitForFinished(Job job) {
+ try {
+ synchronized (this) {
+ // if this method is running inside of a WorkerThread
+ // we try to pass the job we're waiting for to the thread.
+ if (Thread.currentThread() instanceof WorkerThread) {
+ WorkerThread t = (WorkerThread) Thread.currentThread();
+ t.takeJob(job);
+ } else {
+ throw new Exception();
+ }
+ }
+ } catch (Exception e) {
+ // if something went wrong with taking the job
+ // ok - we might be stuck...
+
+ if (job.getScheduler().getSchedulerStats().getIdleWorkerThreads() == 0) {
+ job.getScheduler().startOneShotWorkerThread();
+ }
+ }
+ synchronized (this) {
+ while (job.state() != Job.State.Finished) {
+ if (job.state() == Job.State.Error) {
+ return;
+ }
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+}
diff --git a/alitheia/core/src/test/java/eu/sqooss/impl/service/db/DBServiceFactoryTest.java b/alitheia/core/src/test/java/eu/sqooss/impl/service/db/DBServiceFactoryTest.java
new file mode 100644
index 000000000..769c2a9bb
--- /dev/null
+++ b/alitheia/core/src/test/java/eu/sqooss/impl/service/db/DBServiceFactoryTest.java
@@ -0,0 +1,42 @@
+package eu.sqooss.impl.service.db;
+
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DBServiceFactoryTest {
+
+ BundleContext bc = mock(BundleContext.class);
+
+ @Test
+ public void testGetMysqlDBServiceImpl() throws IllegalAccessException, ClassNotFoundException, InstantiationException {
+ when(bc.getProperty("eu.sqooss.db")).thenReturn("eu.sqooss.impl.service.db.MySQLDBServiceImpl");
+ DBServiceFactory dbServiceFactory = new DBServiceFactory(bc);
+ assertThat(dbServiceFactory.getDBService(), instanceOf(MySQLDBServiceImpl.class));
+ }
+
+ @Test
+ public void testGetPostgresDBServiceImpl() throws IllegalAccessException, ClassNotFoundException, InstantiationException {
+ when(bc.getProperty("eu.sqooss.db")).thenReturn("eu.sqooss.impl.service.db.PostgresDBServiceImpl");
+ DBServiceFactory dbServiceFactory = new DBServiceFactory(bc);
+ assertThat(dbServiceFactory.getDBService(), instanceOf(PostgresDBServiceImpl.class));
+ }
+
+ @Test
+ public void testGetHSQLDBServiceImpl() throws IllegalAccessException, ClassNotFoundException, InstantiationException {
+ when(bc.getProperty("eu.sqooss.db")).thenReturn("eu.sqooss.impl.service.db.HSQLDBServiceImpl");
+ DBServiceFactory dbServiceFactory = new DBServiceFactory(bc);
+ assertThat(dbServiceFactory.getDBService(), instanceOf(HSQLDBServiceImpl.class));
+ }
+
+ @Test
+ public void testGetH2DBServiceImpl() throws IllegalAccessException, ClassNotFoundException, InstantiationException {
+ when(bc.getProperty("eu.sqooss.db")).thenReturn("eu.sqooss.impl.service.db.H2DBServiceImpl");
+ DBServiceFactory dbServiceFactory = new DBServiceFactory(bc);
+ assertThat(dbServiceFactory.getDBService(), instanceOf(H2DBServiceImpl.class));
+ }
+}
diff --git a/alitheia/core/src/test/java/eu/sqooss/service/db/BugRepositoryTest.java b/alitheia/core/src/test/java/eu/sqooss/service/db/BugRepositoryTest.java
new file mode 100644
index 000000000..dcac8f742
--- /dev/null
+++ b/alitheia/core/src/test/java/eu/sqooss/service/db/BugRepositoryTest.java
@@ -0,0 +1,106 @@
+package eu.sqooss.service.db;
+
+import eu.sqooss.core.AlitheiaCore;
+import eu.sqooss.impl.service.db.BaseDBServiceImpl;
+import eu.sqooss.service.db.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class BugRepositoryTest {
+
+ AlitheiaCore alitheiaCore = mock(AlitheiaCore.class);
+ DBService dbService = mock(BaseDBServiceImpl.class);
+
+ @Before
+ public void setUp() {
+ AlitheiaCore.setInstance(alitheiaCore);
+ when(alitheiaCore.getDBService()).thenReturn(dbService);
+ }
+
+ @Test
+ public void testGetAllReportComments() {
+ List bugReportMessages = new ArrayList<>();
+ bugReportMessages.add(new BugReportMessage());
+ bugReportMessages.add(new BugReportMessage());
+ bugReportMessages.add(new BugReportMessage());
+ when(dbService.doHQL(anyString(), anyMap())).thenReturn(bugReportMessages);
+
+ BugRepository bugRepository = new BugRepository();
+ List> result = bugRepository.getAllReportComments(new Bug());
+
+ assertThat(result, is(bugReportMessages));
+ }
+
+ @Test
+ public void testGetBug() {
+ List bugs = new ArrayList();
+ Bug bug = new Bug();
+ bugs.add(bug);
+ when(dbService.doHQL(anyString(), anyMap(), anyInt())).thenReturn(bugs);
+
+ BugRepository bugRepository = new BugRepository();
+ Bug result = bugRepository.getBug("1", null);
+
+ assertThat(result, is(bug));
+ }
+
+ @Test
+ public void testGetBugEmptyResult() {
+ List bugs = new ArrayList();
+ when(dbService.doHQL(anyString(), anyMap(), anyInt())).thenReturn(bugs);
+
+ BugRepository bugRepository = new BugRepository();
+ Bug result = bugRepository.getBug("1", new StoredProject());
+
+ assertNull(result);
+ }
+
+ @Test
+ public void testGetLastUpdate() {
+ List bugs = new ArrayList();
+ Bug bug = new Bug();
+ bugs.add(bug);
+ when(dbService.doHQL(anyString(), anyMap(), anyInt())).thenReturn(bugs);
+
+ BugRepository bugRepository = new BugRepository();
+ Bug result = bugRepository.getLastUpdate(new StoredProject());
+
+ assertThat(result, is(bug));
+ }
+
+ @Test
+ public void testGetLastUpdateNoStoredProject() {
+ List bugs = new ArrayList();
+ Bug bug = new Bug();
+ bugs.add(bug);
+ when(dbService.doHQL(anyString(), anyMap(), anyInt())).thenReturn(bugs);
+
+ BugRepository bugRepository = new BugRepository();
+ Bug result = bugRepository.getLastUpdate(null);
+
+ assertNull(result);
+ }
+
+ @Test
+ public void testGetLastUpdateEmptyResult() {
+ List bugs = new ArrayList();
+ when(dbService.doHQL(anyString(), anyMap(), anyInt())).thenReturn(bugs);
+
+ BugRepository bugRepository = new BugRepository();
+ Bug result = bugRepository.getLastUpdate(new StoredProject());
+
+ assertNull(result);
+ }
+
+
+}
diff --git a/alitheia/core/src/test/java/eu/sqooss/service/scheduler/JobExecutorTest.java b/alitheia/core/src/test/java/eu/sqooss/service/scheduler/JobExecutorTest.java
new file mode 100644
index 000000000..3b71f7f3f
--- /dev/null
+++ b/alitheia/core/src/test/java/eu/sqooss/service/scheduler/JobExecutorTest.java
@@ -0,0 +1,94 @@
+package eu.sqooss.service.scheduler;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.spy;
+import static org.powermock.api.mockito.PowerMockito.mock;
+
+import eu.sqooss.core.AlitheiaCore;
+import eu.sqooss.service.db.DBService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Spy;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(Job.class)
+public class JobExecutorTest {
+
+ AlitheiaCore alitheiaCore = mock(AlitheiaCore.class);
+ DBService dbService = mock(DBService.class);
+ Job job = mock(Job.class);
+
+ @Before
+ public void setUp() {
+ AlitheiaCore.setInstance(alitheiaCore);
+ when(alitheiaCore.getDBService()).thenReturn(dbService);
+ }
+
+ @Test
+ public void testExecuteRunning() throws Exception {
+ when(dbService.isDBSessionActive()).thenReturn(false);
+ when(job.state()).thenReturn(Job.State.Running);
+
+ JobExecutor jobExecutor = new JobExecutor();
+ long executionTime = jobExecutor.execute(job);
+
+ verify(job, times(1)).setState(Job.State.Running);
+ verify(job, times(1)).restart();
+ verify(job, times(1)).setState(Job.State.Finished);
+ assertTrue(executionTime >= 0);
+ }
+
+ @Test(expected = Exception.class)
+ public void testExecuteException() throws Exception {
+ Exception e = new Exception();
+ when(dbService.isDBSessionActive()).thenThrow(e).thenReturn(true);
+
+ JobExecutor jobExecutor = new JobExecutor();
+ jobExecutor.execute(job);
+ }
+
+ @Spy
+ WorkerThread workerThread = new TestWorkerThread();
+
+ @Test
+ public void testWaitForFinished() throws InterruptedException, SchedulerException {
+ workerThread.start();
+ synchronized (workerThread) {
+ workerThread.wait(2000);
+ }
+ verify(workerThread, times(1)).takeJob(job);
+
+ }
+
+ class TestWorkerThread extends Thread implements WorkerThread {
+ @Override
+ public void stopProcessing() {
+
+ }
+
+ @Override
+ public Job executedJob() {
+ return null;
+ }
+
+ @Override
+ public void takeJob(Job job) throws SchedulerException {
+ }
+
+ @Override
+ public void run() {
+ when(job.state()).thenReturn(Job.State.Finished);
+ JobExecutor jobExecutor = new JobExecutor();
+ jobExecutor.waitForFinished(job);
+ synchronized (this) {
+ this.notifyAll();
+ }
+ }
+ }
+}
diff --git a/alitheia/core/src/test/java/eu/sqooss/test/service/scheduler/SchedulerTests.java b/alitheia/core/src/test/java/eu/sqooss/test/service/scheduler/SchedulerTests.java
index f30f92f84..58144c1eb 100644
--- a/alitheia/core/src/test/java/eu/sqooss/test/service/scheduler/SchedulerTests.java
+++ b/alitheia/core/src/test/java/eu/sqooss/test/service/scheduler/SchedulerTests.java
@@ -32,11 +32,13 @@ public void testJobYield() throws SchedulerException {
@AfterClass
public static void tearDown() {
+ /*
while (sched.getSchedulerStats().getWaitingJobs() > 0)
try {
Thread.sleep(500);
} catch (InterruptedException e) {}
sched.stopExecute();
+ */
}
}
\ No newline at end of file
diff --git a/alitheia/pom.xml b/alitheia/pom.xml
index e44d25b72..42cebb2f5 100644
--- a/alitheia/pom.xml
+++ b/alitheia/pom.xml
@@ -13,6 +13,10 @@
0.95-SNAPSHOT
+
+ UTF-8
+
+
pom
diff --git a/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaUpdater.java b/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaUpdater.java
index 0a9849965..23a6e832d 100644
--- a/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaUpdater.java
+++ b/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaUpdater.java
@@ -40,6 +40,7 @@
import eu.sqooss.core.AlitheiaCore;
import eu.sqooss.service.db.Bug;
+import eu.sqooss.service.db.BugRepository;
import eu.sqooss.service.db.DBService;
import eu.sqooss.service.db.StoredProject;
import eu.sqooss.service.logging.Logger;
@@ -97,8 +98,9 @@ public void update() throws Exception {
this.bts = AlitheiaCore.getInstance().getTDSService().getAccessor(
project.getId()).getBTSAccessor();
- if (Bug.getLastUpdate(project) != null) {
- bugIds = bts.getBugsNewerThan(Bug.getLastUpdate(project).getUpdateRun());
+ BugRepository bugRepository = new BugRepository();
+ if (bugRepository.getLastUpdate(project) != null) {
+ bugIds = bts.getBugsNewerThan(bugRepository.getLastUpdate(project).getUpdateRun());
} else {
bugIds = bts.getAllBugs();
}
diff --git a/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaXMLJob.java b/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaXMLJob.java
index 56eecbd2f..9cf54a59a 100644
--- a/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaXMLJob.java
+++ b/plug-ins/bugzilla/src/main/java/eu/sqooss/plugins/bugzilla/BugzillaXMLJob.java
@@ -38,15 +38,7 @@
import java.util.Set;
import eu.sqooss.core.AlitheiaCore;
-import eu.sqooss.service.db.Bug;
-import eu.sqooss.service.db.BugPriority;
-import eu.sqooss.service.db.BugReportMessage;
-import eu.sqooss.service.db.BugResolution;
-import eu.sqooss.service.db.BugSeverity;
-import eu.sqooss.service.db.BugStatus;
-import eu.sqooss.service.db.DBService;
-import eu.sqooss.service.db.Developer;
-import eu.sqooss.service.db.StoredProject;
+import eu.sqooss.service.db.*;
import eu.sqooss.service.db.BugPriority.Priority;
import eu.sqooss.service.db.BugResolution.Resolution;
import eu.sqooss.service.db.BugSeverity.Severity;
@@ -93,11 +85,13 @@ protected void run() throws Exception {
return;
}
+ BugRepository bugRepository = new BugRepository();
+
// Filter out duplicate report messages
if (bugExists(project, bugID)) {
logger.debug(project.getName() + ": Updating existing bug "
+ bugID);
- List msgs = bug.getAllReportComments();
+ List msgs = bugRepository.getAllReportComments(bug);
Set newmsgs = bug.getReportMessages();
Set toadd = new LinkedHashSet();
diff --git a/plug-ins/git/src/test/java/eu/sqooss/plugins/git/test/TestGitUpdater.java b/plug-ins/git/src/test/java/eu/sqooss/plugins/git/test/TestGitUpdater.java
index c156b2c65..282ec0d7c 100644
--- a/plug-ins/git/src/test/java/eu/sqooss/plugins/git/test/TestGitUpdater.java
+++ b/plug-ins/git/src/test/java/eu/sqooss/plugins/git/test/TestGitUpdater.java
@@ -7,12 +7,11 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
+import eu.sqooss.service.db.MySQLDbServiceImpl;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -25,7 +24,7 @@
import org.junit.Test;
import eu.sqooss.core.AlitheiaCore;
-import eu.sqooss.impl.service.db.DBServiceImpl;
+import eu.sqooss.impl.service.db.BaseDBServiceImpl;
import eu.sqooss.impl.service.logging.LogManagerImpl;
import eu.sqooss.plugins.updater.git.GitUpdater;
import eu.sqooss.service.db.DBService;
@@ -38,9 +37,6 @@
import eu.sqooss.service.logging.LogManager;
import eu.sqooss.service.logging.Logger;
import eu.sqooss.service.tds.AccessorException;
-import eu.sqooss.service.tds.CommitLog;
-import eu.sqooss.service.tds.InvalidProjectRevisionException;
-import eu.sqooss.service.tds.InvalidRepositoryException;
import eu.sqooss.service.tds.Revision;
public class TestGitUpdater extends TestGitSetup {
@@ -51,7 +47,7 @@ public class TestGitUpdater extends TestGitSetup {
static StoredProject sp ;
@BeforeClass
- public static void setup() throws IOException, URISyntaxException {
+ public static void setup() throws IOException, URISyntaxException, IllegalAccessException, InstantiationException, ClassNotFoundException {
initTestRepo();
Properties conProp = new Properties();
@@ -95,10 +91,10 @@ public static void setup() throws IOException, URISyntaxException {
LogManager lm = new LogManagerImpl(true);
l = lm.createLogger("sqooss.updater");
-
+
AlitheiaCore.testInstance();
- db = new DBServiceImpl(conProp, config.toURL() , l);
+ db = new MySQLDbServiceImpl(conProp, config.toURL() , l);
db.startDBSession();
sp = new StoredProject();
sp.setName(projectName);
diff --git a/pom.xml b/pom.xml
index 12683f1ee..6507b55d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,7 +58,7 @@
c3p0
-->
- H2
+ eu.sqooss.service.db.H2DBServiceImpl
localhost
alitheia;LOCK_MODE=3;MULTI_THREADED=true
sa
@@ -225,7 +225,6 @@
maven-surefire-plugin
2.7.1
- true