diff --git a/.gitignore b/.gitignore index 50b2ed416..6037c90e3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ bin/ *.ipr *.iws *.db +alitheia/cache/tmp/ +alitheia/core/tmp/ +alitheia/runner/ diff --git a/alitheia/cache/pom.xml b/alitheia/cache/pom.xml index e1b37f292..f21e6a52a 100644 --- a/alitheia/cache/pom.xml +++ b/alitheia/cache/pom.xml @@ -67,5 +67,11 @@ 4.6 test + + org.mockito + mockito-core + 1.9.5 + test + diff --git a/alitheia/cache/src/main/java/eu/sqooss/service/cache/Activator.java b/alitheia/cache/src/main/java/eu/sqooss/service/cache/Activator.java index aed689f8d..15cd190bd 100644 --- a/alitheia/cache/src/main/java/eu/sqooss/service/cache/Activator.java +++ b/alitheia/cache/src/main/java/eu/sqooss/service/cache/Activator.java @@ -7,8 +7,27 @@ public class Activator implements BundleActivator { + public static final String CACHE_IMPL_DEFAULT = "eu.sqooss.service.cache.OnDiskCache"; + public static final String CACHE_IMPL_KEY = "eu.sqooss.service.cache.impl"; + + /** + * Registers CacheService implementation. If a system property with key + * CACHE_IMPL_KEY exists, the value is used as class. Otherwise, + * CACHE_IMPL_DFAULT is used. + * + * @param bc + * @throws Exception + */ public void start(BundleContext bc) throws Exception { - AlitheiaCore.getInstance().registerService(CacheService.class, CacheServiceImpl.class); + String impl = bc.getProperty(CACHE_IMPL_KEY); + + if (impl == null) { + impl = CACHE_IMPL_DEFAULT; + } + + Class clazz = Thread.currentThread().getContextClassLoader().loadClass(impl); + + AlitheiaCore.getInstance().registerService(CacheService.class, clazz); } public void stop(BundleContext bc) throws Exception { diff --git a/alitheia/cache/src/main/java/eu/sqooss/service/cache/BaseCacheServiceImpl.java b/alitheia/cache/src/main/java/eu/sqooss/service/cache/BaseCacheServiceImpl.java new file mode 100644 index 000000000..f1a29f959 --- /dev/null +++ b/alitheia/cache/src/main/java/eu/sqooss/service/cache/BaseCacheServiceImpl.java @@ -0,0 +1,56 @@ +package eu.sqooss.service.cache; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import eu.sqooss.service.logging.Logger; +import org.osgi.framework.BundleContext; + +public abstract class BaseCacheServiceImpl implements CacheService { + + private BundleContext bundleContext; + private Logger logger; + + @Override + public void setInitParams(BundleContext bundleContext, Logger logger) { + this.bundleContext = bundleContext; + this.logger = logger; + } + + @Override + public InputStream getStream(String key) { + byte[] buff = get(key); + + if (buff == null) { + return null; + } + + ByteArrayInputStream bais = new ByteArrayInputStream(buff); + return bais; + } + + @Override + public void setStream(String key, InputStream in) { + try { + int nRead; + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + byte[] data = new byte[4096]; + + while ((nRead = in.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, nRead); + } + + buffer.flush(); + set(key, buffer.toByteArray()); + + } catch (IOException e) { + logger.error("Error"); + } + } + + protected Logger getLogger() { + return logger; + } +} diff --git a/alitheia/cache/src/main/java/eu/sqooss/service/cache/CacheServiceImpl.java b/alitheia/cache/src/main/java/eu/sqooss/service/cache/CacheServiceImpl.java deleted file mode 100644 index 3f36bbba6..000000000 --- a/alitheia/cache/src/main/java/eu/sqooss/service/cache/CacheServiceImpl.java +++ /dev/null @@ -1,102 +0,0 @@ -package eu.sqooss.service.cache; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.osgi.framework.BundleContext; - -import eu.sqooss.service.logging.Logger; - -public class CacheServiceImpl implements CacheService { - - public static final String CACHE_IMPL = "eu.sqooss.service.cache.OnDiskCache"; - - private static List> impls; - - static { - impls = new ArrayList>(); - impls.add(OnDiskCache.class); - impls.add(InMemoryCache.class); - } - - private CacheService c; - private BundleContext bc; - private Logger log; - - public CacheServiceImpl() {} - - @Override - public byte[] get(String key) { - return c.get(key); - } - - @Override - public InputStream getStream(String key) { - byte[] buff = c.get(key); - - if (buff == null) - return null; - - ByteArrayInputStream bais = new ByteArrayInputStream(buff); - return bais; - } - - @Override - public void set(String key, byte[] data) { - c.set(key, data); - } - - @Override - public void setStream(String key, InputStream in) { - try { - int nRead; - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - byte[] data = new byte[4096]; - - while ((nRead = in.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); - } - - buffer.flush(); - set(key, buffer.toByteArray()); - - } catch (IOException e) { - log.error("Error"); - } - } - - @Override - public boolean startUp() { - String impl = System.getProperty(CACHE_IMPL); - - if (impl == null) - impl = "eu.sqooss.service.cache.OnDiskCache"; - - try { - Class clazz = Thread.currentThread().getContextClassLoader().loadClass(impl); - c = (CacheService) clazz.newInstance(); - } catch (ClassNotFoundException e) { - log.error("Cannot load cache implementation:" + impl); - } catch (InstantiationException e) { - log.error("Cannot initialize cache implementation:" + impl + " Error:" + e.getMessage()); - } catch (IllegalAccessException e) { - log.error("Cannot initialize cache implementation:" + impl + " Error:" + e.getMessage()); - } - return true; - } - - @Override - public void shutDown() { - c = null; - } - - @Override - public void setInitParams(BundleContext bc, Logger l) { - this.bc = bc; - this.log = l; - } -} diff --git a/alitheia/cache/src/main/java/eu/sqooss/service/cache/InMemoryCache.java b/alitheia/cache/src/main/java/eu/sqooss/service/cache/InMemoryCache.java index 1ed36e564..0e60edd4c 100644 --- a/alitheia/cache/src/main/java/eu/sqooss/service/cache/InMemoryCache.java +++ b/alitheia/cache/src/main/java/eu/sqooss/service/cache/InMemoryCache.java @@ -2,12 +2,22 @@ import java.util.concurrent.ConcurrentHashMap; -public class InMemoryCache extends CacheServiceImpl { +public class InMemoryCache extends BaseCacheServiceImpl { ConcurrentHashMap cache = new ConcurrentHashMap(1024); public InMemoryCache() {} - + + @Override + public boolean startUp() { + return true; + } + + @Override + public void shutDown() { + + } + @Override public byte[] get(String key) { return cache.get(key); diff --git a/alitheia/cache/src/main/java/eu/sqooss/service/cache/OnDiskCache.java b/alitheia/cache/src/main/java/eu/sqooss/service/cache/OnDiskCache.java index cf49bfbc8..a624c7f49 100644 --- a/alitheia/cache/src/main/java/eu/sqooss/service/cache/OnDiskCache.java +++ b/alitheia/cache/src/main/java/eu/sqooss/service/cache/OnDiskCache.java @@ -36,36 +36,44 @@ * * */ -public class OnDiskCache extends CacheServiceImpl { +public class OnDiskCache extends BaseCacheServiceImpl { public static final String CACHE_DIR = "eu.sqooss.service.cache.dir"; - + private File dir; - private Logger log; - public OnDiskCache(String cachedir) throws Exception { initDir(cachedir); } public OnDiskCache() throws Exception { - String dirpath = System.getProperty(CACHE_DIR); if (dirpath == null) { dirpath = System.getProperty("java.io.tmpdir"); - if (dirpath == null) + if (dirpath == null) { dirpath = "tmp"; + } } initDir(dirpath); - + } + + @Override + public boolean startUp() { + return true; + } + + @Override + public void shutDown() { + } private void initDir(String path) throws Exception { dir = new File(path); - if (!dir.exists()) + if (!dir.exists()) { dir.mkdirs(); + } } @Override @@ -170,15 +178,20 @@ public void set(String key, byte[] data) { private String md5(String...args) throws NoSuchAlgorithmException { MessageDigest m = MessageDigest.getInstance("MD5"); - for (String arg : args) + for (String arg : args) { m.update(arg.getBytes(), 0, arg.length()); + } + return new BigInteger(1, m.digest()).toString(16); } private void warn(String message) { - if (log != null) - log.warn(message); - else + Logger logger = getLogger(); + + if (logger != null) { + logger.warn(message); + } else { System.err.println(message); + } } } diff --git a/alitheia/cache/src/test/java/eu/sqooss/service/cache/test/ActivatorTest.java b/alitheia/cache/src/test/java/eu/sqooss/service/cache/test/ActivatorTest.java new file mode 100644 index 000000000..f6397bb62 --- /dev/null +++ b/alitheia/cache/src/test/java/eu/sqooss/service/cache/test/ActivatorTest.java @@ -0,0 +1,41 @@ +package eu.sqooss.service.cache.test; + +import eu.sqooss.core.AlitheiaCore; +import eu.sqooss.service.cache.Activator; +import eu.sqooss.service.cache.CacheService; +import eu.sqooss.service.cache.InMemoryCache; +import eu.sqooss.service.cache.OnDiskCache; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.BundleContext; + +import static org.mockito.Mockito.*; + +public class ActivatorTest { + + AlitheiaCore alitheiaCore = mock(AlitheiaCore.class); + BundleContext bc = mock(BundleContext.class); + @Before + public void setUp() { + AlitheiaCore.setInstance(alitheiaCore); + } + + @Test + public void testStart() throws Exception { + Activator activator = new Activator(); + activator.start(bc); + + verify(alitheiaCore, times(1)).registerService(CacheService.class, OnDiskCache.class); + } + + @Test + public void testStartWithProperty() throws Exception { + when(bc.getProperty("eu.sqooss.service.cache.impl")).thenReturn("eu.sqooss.service.cache.InMemoryCache"); + + Activator activator = new Activator(); + activator.start(bc); + + verify(alitheiaCore, times(1)).registerService(CacheService.class, InMemoryCache.class); + } + +} diff --git a/alitheia/core/src/main/java/eu/sqooss/core/AlitheiaCore.java b/alitheia/core/src/main/java/eu/sqooss/core/AlitheiaCore.java index 63610d55f..0e3bb77bd 100644 --- a/alitheia/core/src/main/java/eu/sqooss/core/AlitheiaCore.java +++ b/alitheia/core/src/main/java/eu/sqooss/core/AlitheiaCore.java @@ -40,11 +40,12 @@ import java.util.Map; import java.util.Vector; +import eu.sqooss.impl.service.db.DBServiceFactory; import org.osgi.framework.BundleContext; import eu.sqooss.impl.service.admin.AdminServiceImpl; import eu.sqooss.impl.service.cluster.ClusterNodeServiceImpl; -import eu.sqooss.impl.service.db.DBServiceImpl; +import eu.sqooss.impl.service.db.BaseDBServiceImpl; import eu.sqooss.impl.service.fds.FDSServiceImpl; import eu.sqooss.impl.service.logging.LogManagerImpl; import eu.sqooss.impl.service.metricactivator.MetricActivatorImpl; @@ -81,7 +82,8 @@ public class AlitheiaCore { /** The parent bundle's context object. */ private BundleContext bc; - + + /** The Core is singleton-line because it has a special instance */ private static AlitheiaCore instance = null; @@ -116,7 +118,7 @@ public class AlitheiaCore { services.add(AdminService.class); implementations.put(LogManager.class, LogManagerImpl.class); - implementations.put(DBService.class, DBServiceImpl.class); + implementations.put(DBService.class, BaseDBServiceImpl.class); implementations.put(PluginAdmin.class, PAServiceImpl.class); implementations.put(Scheduler.class, SchedulerServiceImpl.class); implementations.put(TDSService.class, TDSServiceImpl.class); @@ -134,13 +136,13 @@ public class AlitheiaCore { * * @param bc The parent bundle's context object. */ - public AlitheiaCore(BundleContext bc) { + public AlitheiaCore(BundleContext bc, DBServiceFactory dbServiceFactory) throws IllegalAccessException, InstantiationException, ClassNotFoundException { this.bc = bc; instance = this; err("Instance Created"); instances = new HashMap, Object>(); - init(); + init(dbServiceFactory); } /** @@ -155,10 +157,17 @@ public AlitheiaCore(BundleContext bc) { public static AlitheiaCore getInstance() { return instance; } - + + + + public static void setInstance(AlitheiaCore alitheiaCore) { + instance = alitheiaCore; + } + /*Create a temp instance to use for testing.*/ - public static AlitheiaCore testInstance() { - instance = new AlitheiaCore(null); + public static AlitheiaCore testInstance() throws IllegalAccessException, ClassNotFoundException, + InstantiationException { + instance = new AlitheiaCore(null, null); return instance; } @@ -195,10 +204,10 @@ public synchronized void unregisterService( * method on their service interface. Failures are reported but do not * block the instatiation process). */ - private void init() { - + private void init(DBServiceFactory dbServiceFactory) throws ClassNotFoundException, IllegalAccessException, InstantiationException { err("Required services online, initialising"); + // Logger logger = new LogManagerImpl(); logger.setInitParams(bc, null); if (!logger.startUp()) { @@ -207,18 +216,18 @@ private void init() { instances.put(LogManager.class, logger); err("Service " + LogManagerImpl.class.getName() + " started"); - DBService db = DBServiceImpl.getInstance(); - db.setInitParams(bc, logger.createLogger("sqooss.db")); - if (!db.startUp()) { + DBService dbService = dbServiceFactory.getDBService(); + dbService.setInitParams(bc, logger.createLogger("sqooss.db")); + + if (!dbService.startUp()) { err("Cannot start the DB service, aborting"); } - instances.put(DBService.class, db); - err("Service " + DBServiceImpl.class.getName() + " started"); + instances.put(DBService.class, dbService); + err("Service " + BaseDBServiceImpl.class.getName() + " started"); for (Class s : services) { initService(s); } - } private synchronized void initService(Class s) { @@ -307,8 +316,8 @@ public PluginAdmin getPluginAdmin() { * @return The DB component's instance. */ public DBService getDBService() { - //return (DBServiceImpl)instances.get(DBService.class); - return DBServiceImpl.getInstance(); // <-- Ugly but required for testing. + return (DBService) instances.get(DBService.class); +// return BaseDBServiceImpl.getInstance(); // <-- Ugly but required for testing. } /** diff --git a/alitheia/core/src/main/java/eu/sqooss/core/CoreActivator.java b/alitheia/core/src/main/java/eu/sqooss/core/CoreActivator.java index 4cabd4e10..3920ed51d 100644 --- a/alitheia/core/src/main/java/eu/sqooss/core/CoreActivator.java +++ b/alitheia/core/src/main/java/eu/sqooss/core/CoreActivator.java @@ -33,6 +33,7 @@ package eu.sqooss.core; +import eu.sqooss.impl.service.db.DBServiceFactory; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -47,7 +48,7 @@ public class CoreActivator implements BundleActivator { private ServiceRegistration sregCore; public void start(BundleContext bc) throws Exception { - core = new AlitheiaCore(bc); + core = new AlitheiaCore(bc, new DBServiceFactory(bc)); sregCore = bc.registerService(AlitheiaCore.class.getName(), core, null); } diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/DBServiceImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/BaseDBServiceImpl.java similarity index 94% rename from alitheia/core/src/main/java/eu/sqooss/impl/service/db/DBServiceImpl.java rename to alitheia/core/src/main/java/eu/sqooss/impl/service/db/BaseDBServiceImpl.java index 546b4addd..8d960f6af 100644 --- a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/DBServiceImpl.java +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/BaseDBServiceImpl.java @@ -75,36 +75,8 @@ * @author Romain Pokrzywka, Georgios Gousios * */ -public class DBServiceImpl implements DBService, AlitheiaCoreService { - +public abstract class BaseDBServiceImpl implements DBService, AlitheiaCoreService { private static DBService instance; - - public static Map drivers = new HashMap(); - - static { - drivers.put("mysql", "com.mysql.jdbc.Driver"); - drivers.put("hsqldb", "org.hsqldb.jdbcDriver"); - drivers.put("postgres", "org.postgresql.Driver"); - drivers.put("h2", "org.h2.Driver"); - } - - public static Map connString = new HashMap(); - - static { - connString.put("mysql", "jdbc:mysql:///?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8"); - connString.put("hsqldb", "jdbc:hsqldb:file:"); - connString.put("postgres", "jdbc:postgresql:///"); - connString.put("h2", "jdbc:h2:"); - } - - public static Map hbmDialects = new HashMap(); - - static { - hbmDialects.put("mysql", "org.hibernate.dialect.MySQLInnoDBDialect"); - hbmDialects.put("hsqldb", "org.hibernate.dialect.HSQLDialect"); - hbmDialects.put("postgres", "org.hibernate.dialect.PostgreSQLDialect"); - hbmDialects.put("h2", "org.h2.Driver"); - } public static Map conPools = new HashMap(); @@ -113,7 +85,6 @@ public class DBServiceImpl implements DBService, AlitheiaCoreService { conPools.put("c3p0", "org.hibernate.connection.C3P0ConnectionProvider"); } - private static final String DB = "eu.sqooss.db"; private static final String DB_HOST = "eu.sqooss.db.host"; private static final String DB_SCHEMA = "eu.sqooss.db.schema"; private static final String DB_USERNAME = "eu.sqooss.db.user"; @@ -283,21 +254,15 @@ public boolean accept(File dir, String name) { return true; } - public DBServiceImpl() { } + public BaseDBServiceImpl() { } - public DBServiceImpl(Properties p, URL configFileURL, Logger l) { + public BaseDBServiceImpl(Properties p, URL configFileURL, Logger l) { this.conProp = p; this.logger = l; initHibernate(configFileURL); isInitialised.compareAndSet(false, true); instance = this; } - - public static DBService getInstance() { - if (instance == null) - instance = new DBServiceImpl(); - return instance; - } public T findObjectById(Class daoClass, long id) { return doFindObjectById(daoClass, id, false); @@ -775,16 +740,15 @@ public int executeUpdate(String hql, Map params) @Override public boolean startUp() { - String db = bc.getProperty(DB).toLowerCase(); - String cs = connString.get(db); + String cs = getConnectionString(); cs = cs.replaceAll("", bc.getProperty(DB_HOST)); cs = cs.replaceAll("", bc.getProperty(DB_SCHEMA)); - conProp.setProperty("hibernate.connection.driver_class", drivers.get(db)); + conProp.setProperty("hibernate.connection.driver_class", getDriver()); conProp.setProperty("hibernate.connection.url", cs); conProp.setProperty("hibernate.connection.username", bc.getProperty(DB_USERNAME)); conProp.setProperty("hibernate.connection.password", bc.getProperty(DB_PASSWORD)); - conProp.setProperty("hibernate.connection.dialect", hbmDialects.get(db)); + conProp.setProperty("hibernate.connection.dialect", getHbmDialect()); conProp.setProperty("hibernate.connection.provider_class", conPools.get(bc.getProperty(DB_CONPOOL))); if (!getJDBCConnection()) { @@ -810,6 +774,12 @@ public void setInitParams(BundleContext bc, Logger l) { this.bc = bc; this.logger = l; } + + protected abstract String getConnectionString(); + + protected abstract String getDriver(); + + protected abstract String getHbmDialect(); } //vi: ai nosi sw=4 ts=4 expandtab diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/DBServiceFactory.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/DBServiceFactory.java new file mode 100644 index 000000000..20affad64 --- /dev/null +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/DBServiceFactory.java @@ -0,0 +1,22 @@ +package eu.sqooss.impl.service.db; + +import eu.sqooss.service.db.DBService; +import org.osgi.framework.BundleContext; + +public class DBServiceFactory { + + private static final String DB = "eu.sqooss.db"; + private final BundleContext bc; + + public DBServiceFactory(BundleContext bc) { + this.bc = bc; + } + + public DBService getDBService() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + String impl = bc.getProperty(DB); + Class clazz = Thread.currentThread().getContextClassLoader().loadClass(impl); + + DBService dbService = (DBService) clazz.newInstance(); + return dbService; + } +} diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/H2DBServiceImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/H2DBServiceImpl.java new file mode 100644 index 000000000..d7dbe6bd6 --- /dev/null +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/H2DBServiceImpl.java @@ -0,0 +1,32 @@ +package eu.sqooss.impl.service.db; + +import eu.sqooss.service.logging.Logger; + +import java.net.URL; +import java.util.Properties; + +public class H2DBServiceImpl extends BaseDBServiceImpl { + + public H2DBServiceImpl(Properties conProp, URL url, Logger l) { + super(conProp, url, l); + } + + public H2DBServiceImpl() { + + } + @Override + protected String getConnectionString() { + return "jdbc:h2:"; + } + + @Override + protected String getDriver() { + return "org.h2.Driver"; + } + + @Override + protected String getHbmDialect() { + return "org.h2.Driver"; + } + +} diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/HSQLDBServiceImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/HSQLDBServiceImpl.java new file mode 100644 index 000000000..f55ece668 --- /dev/null +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/HSQLDBServiceImpl.java @@ -0,0 +1,32 @@ +package eu.sqooss.impl.service.db; + +import eu.sqooss.service.logging.Logger; + +import java.net.URL; +import java.util.Properties; + +public class HSQLDBServiceImpl extends BaseDBServiceImpl { + + public HSQLDBServiceImpl(Properties conProp, URL url, Logger l) { + super(conProp, url, l); + } + + public HSQLDBServiceImpl() { + + } + @Override + protected String getConnectionString() { + return "jdbc:hsqldb:file:"; + } + + @Override + protected String getDriver() { + return "org.hsqldb.jdbcDriver"; + } + + @Override + protected String getHbmDialect() { + return "org.hibernate.dialect.HSQLDialect"; + } + +} diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/MySQLDBServiceImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/MySQLDBServiceImpl.java new file mode 100644 index 000000000..fe4068073 --- /dev/null +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/MySQLDBServiceImpl.java @@ -0,0 +1,33 @@ +package eu.sqooss.impl.service.db; + +import java.net.URL; +import java.util.Properties; + +import eu.sqooss.service.logging.Logger; + +public class MySQLDBServiceImpl extends BaseDBServiceImpl { + + public MySQLDBServiceImpl(Properties conProp, URL url, Logger l) { + super(conProp, url, l); + } + + public MySQLDBServiceImpl() { + + } + + @Override + protected String getConnectionString() { + return "jdbc:mysql:///?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8"; + } + + @Override + protected String getDriver() { + return "com.mysql.jdbc.Driver"; + } + + @Override + protected String getHbmDialect() { + return "org.hibernate.dialect.MySQLInnoDBDialect"; + } + +} diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/db/PostgresDBServiceImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/PostgresDBServiceImpl.java new file mode 100644 index 000000000..7c5e82580 --- /dev/null +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/db/PostgresDBServiceImpl.java @@ -0,0 +1,35 @@ +package eu.sqooss.impl.service.db; + + +import eu.sqooss.service.logging.Logger; + +import java.net.URL; +import java.util.Properties; + +public class PostgresDBServiceImpl extends BaseDBServiceImpl { + + + public PostgresDBServiceImpl(Properties conProp, URL url, Logger l) { + super(conProp, url, l); + } + + public PostgresDBServiceImpl() { + + } + + @Override + protected String getConnectionString() { + return "jdbc:postgresql:///"; + } + + @Override + protected String getDriver() { + return "org.postgresql.Driver"; + } + + @Override + protected String getHbmDialect() { + return "org.hibernate.dialect.PostgreSQLDialect"; + } + +} diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryCheckoutImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryCheckoutImpl.java index 1b72274a0..ace92e8cd 100644 --- a/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryCheckoutImpl.java +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryCheckoutImpl.java @@ -62,7 +62,7 @@ class InMemoryCheckoutImpl implements InMemoryCheckout { } protected void createCheckout() { - root = new InMemoryDirectory(this); + root = new InMemoryDirectoryImpl(this); List projectFiles = revision.getFiles(); if (projectFiles != null && projectFiles.size() != 0) { diff --git a/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryDirectoryImpl.java b/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryDirectoryImpl.java new file mode 100644 index 000000000..e9d650e55 --- /dev/null +++ b/alitheia/core/src/main/java/eu/sqooss/impl/service/fds/InMemoryDirectoryImpl.java @@ -0,0 +1,337 @@ +/* + * 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.impl.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.fds.InMemoryCheckout; +import eu.sqooss.service.fds.InMemoryDirectory; +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 InMemoryDirectoryImpl implements InMemoryDirectory { + + private InMemoryCheckout checkout; + private InMemoryDirectory parentDirectory; + + private String name; + + private List files; + private List directories; + + public InMemoryDirectoryImpl() { + name = new String(); + files = new LinkedList(); + directories = new LinkedList(); + } + + public InMemoryDirectoryImpl(String name) { + this(); + this.name = name; + } + + public InMemoryDirectoryImpl(InMemoryCheckout checkout) { + this(""); + this.checkout = checkout; + } + + public InMemoryDirectoryImpl(InMemoryDirectoryImpl 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); + + 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