CCM NG: Fixed some warnings from FindBugs

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3604 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-09-05 19:54:48 +00:00
parent ee8e0e52df
commit 47ac2a9d43
3 changed files with 101 additions and 87 deletions

View File

@ -182,13 +182,16 @@ public class CcmIntegrator implements Integrator {
flyway.info().current().getVersion());
if (newModule) {
final Statement statement = connection.createStatement();
statement.execute(String.format(
"INSERT INTO ccm_core.installed_modules "
+ "(module_id, module_class_name, status) "
+ "VALUES (%d, '%s', 'NEW')",
module.getName().hashCode(),
module.getName()));
try (Statement statement = connection.createStatement()) {
statement.execute(String.format(
"INSERT INTO ccm_core.installed_modules "
+ "(module_id, module_class_name, status) "
+ "VALUES (%d, '%s', 'NEW')",
module.getName().hashCode(),
module.getName()));
} catch (SQLException ex) {
throw new IntegrationException("Failed to integrate.", ex);
}
}
}
@ -196,7 +199,7 @@ public class CcmIntegrator implements Integrator {
public void integrate(final MetadataImplementor metadata,
final SessionFactoryImplementor sessionFactory,
final SessionFactoryServiceRegistry registry) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//Nothing
}
@Override
@ -218,41 +221,52 @@ public class CcmIntegrator implements Integrator {
final ModuleInfo moduleInfo = new ModuleInfo();
moduleInfo.load(module);
final Statement query = connection.createStatement();
final ResultSet result = query.executeQuery(
String.format("SELECT module_class_name, status "
+ "FROM ccm_core.installed_modules "
+ "WHERE module_class_name = '%s'",
module.getClass().getName()));
System.out.printf("Checking status of module %s...\n",
module.getClass().getName());
try (Statement query = connection.createStatement();
ResultSet result = query.executeQuery(
String.format("SELECT module_class_name, status "
+ "FROM ccm_core.installed_modules "
+ "WHERE module_class_name = '%s'",
module.getClass().getName()))) {
if (result.next() && ModuleStatus.UNINSTALL.toString().equals(
result.getString("status"))) {
System.out.printf("Checking status of module %s...%n",
module.getClass().getName());
LOGGER.info("Removing schema for module %s...",
module.getClass().getName());
final Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setSchemas(getSchemaName(moduleInfo));
flyway.setLocations(getLocation(moduleInfo, connection));
LOGGER.warn("Deleting schema for module {}...",
moduleInfo.getModuleName());
flyway.clean();
if (result.next() && ModuleStatus.UNINSTALL.toString()
.equals(
result.getString("status"))) {
final Statement statement = connection.createStatement();
statement.addBatch(String.format(
"DELETE FROM ccm_core.installed_modules "
+ "WHERE module_class_name = '%s'",
module.getClass().getName()));
statement.executeBatch();
LOGGER.info("Done.");
LOGGER.info("Removing schema for module %s...",
module.getClass().getName());
final Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setSchemas(getSchemaName(moduleInfo));
flyway.setLocations(getLocation(moduleInfo, connection));
LOGGER.warn("Deleting schema for module {}...",
moduleInfo.getModuleName());
flyway.clean();
try (final Statement statement = connection
.createStatement()) {
statement.addBatch(String.format(
"DELETE FROM ccm_core.installed_modules "
+ "WHERE module_class_name = '%s'",
module.getClass().getName()));
statement.executeBatch();
LOGGER.info("Done.");
} catch (SQLException ex) {
throw new IntegrationException(
"Failed to desintegrate", ex);
}
}
} catch (SQLException ex) {
throw new IntegrationException("Failed to desintegrate.");
}
}
} catch (SQLException ex) {
LOGGER.error("Desintegration failed: ", ex);
System.err.println("Desintration failed");
System.err.println("Desintegration failed");
ex.printStackTrace(System.err);
System.err.println();
SQLException next = ex.getNextException();
@ -262,13 +276,8 @@ public class CcmIntegrator implements Integrator {
next = next.getNextException();
}
if (next == null) {
throw new IntegrationException(
"Failed to desintegrate. No root cause.");
} else {
throw new IntegrationException(
"Failed to desintegrate. No root cause.");
}
throw new IntegrationException("Failed to desintegrate.");
} finally {
JdbcUtils.closeConnection(connection);
}

View File

@ -202,20 +202,19 @@ public class ModuleInfo {
LOGGER.info("Trying to retrieve module info for module {} from {}...",
moduleClass.getName(),
path);
final InputStream stream = moduleClass.getResourceAsStream(path);
if (stream == null) {
LOGGER.warn("No module info for {} found at {}",
moduleClass.getName(),
path);
} else {
try {
try (final InputStream stream = moduleClass.getResourceAsStream(path)) {
if (stream == null) {
LOGGER.warn("No module info for {} found at {}",
moduleClass.getName(),
path);
} else {
moduleInfo.load(stream);
} catch (IOException ex) {
LOGGER.error("Failed to read module info for {} at {}.",
moduleClass.getName(),
path);
LOGGER.error("Cause: ", ex);
}
} catch (IOException ex) {
LOGGER.error("Failed to read module info for {} at {}.",
moduleClass.getName(),
path);
LOGGER.error("Cause: ", ex);
}
return moduleInfo;
@ -224,12 +223,15 @@ public class ModuleInfo {
private String readModuleName(final Class<? extends CcmModule> moduleClass,
final Module annotation,
final Properties moduleInfo) {
@SuppressWarnings("PMD.LongVariable")
@SuppressWarnings(
"PMD.LongVariable")
final boolean annotationHasModuleName = annotation.name() != null
&& !annotation.name().isEmpty();
&& !annotation.name()
.isEmpty();
@SuppressWarnings("PMD.LongVariable")
final boolean moduleInfoHasModuleName = moduleInfo.getProperty(ARTIFACT_ID)
!= null && !moduleInfo
final boolean moduleInfoHasModuleName = moduleInfo.getProperty(
ARTIFACT_ID)
!= null && !moduleInfo
.getProperty(ARTIFACT_ID).isEmpty();
if (annotationHasModuleName) {
@ -250,14 +252,18 @@ public class ModuleInfo {
final Module annotation,
final Properties moduleInfo) {
@SuppressWarnings("PMD.LongVariable")
final boolean annotationHasPackageName = annotation.packageName() != null
&& !annotation.packageName()
@SuppressWarnings(
"PMD.LongVariable")
final boolean annotationHasPackageName = annotation.packageName()
!= null
&& !annotation
.packageName()
.isEmpty();
@SuppressWarnings("PMD.LongVariable")
final boolean moduleInfoHasPackageName = moduleInfo.getProperty(GROUP_ID)
!= null
&& !moduleInfo.getProperty(
final boolean moduleInfoHasPackageName = moduleInfo
.getProperty(GROUP_ID)
!= null
&& !moduleInfo.getProperty(
GROUP_ID).isEmpty();
if (annotationHasPackageName) {
return annotation.packageName();
@ -281,10 +287,13 @@ public class ModuleInfo {
@SuppressWarnings("PMD.LongVariable")
final boolean annotationHasVersion = annotation.version() != null
&& !annotation.version().isEmpty();
&& !annotation.version()
.isEmpty();
@SuppressWarnings("PMD.LongVariable")
final boolean moduleInfoHasVersion = moduleInfo.getProperty(VERSION) != null
&& !moduleInfo.getProperty(VERSION)
final boolean moduleInfoHasVersion = moduleInfo.getProperty(VERSION)
!= null
&& !moduleInfo.getProperty(
VERSION)
.isEmpty();
if (annotationHasVersion) {

View File

@ -83,7 +83,7 @@ public class ModuleManager {
installEvent.setEntityManager(entityManager);
final InstalledModule installedModule = entityManager.find(
InstalledModule.class,
InstalledModule.class,
node.getModule().getClass().getName().hashCode());
if (installedModule != null
&& installedModule.getStatus() == ModuleStatus.NEW) {
@ -114,21 +114,18 @@ public class ModuleManager {
private Properties getModuleInfo(final CcmModule module) {
final Properties moduleInfo = new Properties();
try {
// final String moduleInfoPath = String.format("/%s/module-info.properties",
// module.getClass().getName().replace(".", "/"));
final String moduleInfoPath = String.format(
"/module-info/%s.properties",
module.getClass().getName());
LOGGER.info("Path for module info: {}", moduleInfoPath);
final InputStream stream = module.getClass().getResourceAsStream(
moduleInfoPath);
// try {
final String moduleInfoPath = String.format(
"/module-info/%s.properties",
module.getClass().getName());
LOGGER.info("Path for module info: {}", moduleInfoPath);
try (final InputStream stream = module.getClass().getResourceAsStream(
moduleInfoPath)) {
if (stream == null) {
LOGGER.warn("No module info found.");
} else {
moduleInfo.load(stream);
}
} catch (IOException ex) {
LOGGER.error("Failed to read module-info.properties for module {}.",
module.getClass().getName());
@ -144,7 +141,6 @@ public class ModuleManager {
for (final TreeNode node : moduleNodes) {
final ShutdownEvent shutdownEvent = new ShutdownEvent();
shutdownEvent.setEntityManager(entityManager);
node.getModule().shutdown(shutdownEvent);
}
@ -152,7 +148,7 @@ public class ModuleManager {
System.out.println("Checking for modules to uninstall...");
for (final TreeNode node : moduleNodes) {
System.out.printf("Checking status of module %s\n",
System.out.printf("Checking status of module %s%n",
node.getModule().getClass().getName());
final InstalledModule installedModule = entityManager.find(
InstalledModule.class, node.
@ -161,19 +157,19 @@ public class ModuleManager {
node.getModuleInfo().getModuleName(),
node.getModule().getClass().getName(),
installedModule.getStatus());
System.out.printf("Status of module %s (%s): %s\n",
System.out.printf("Status of module %s (%s): %s%n",
node.getModuleInfo().getModuleName(),
node.getModule().getClass().getName(),
installedModule.getStatus());
System.out.printf("Checked status of module %s\n",
System.out.printf("Checked status of module %s%n",
node.getModule().getClass().getName());
if (ModuleStatus.UNINSTALL.equals(installedModule.getStatus())) {
System.out.printf("Module %s is scheduled for uninstall...\n",
System.out.printf("Module %s is scheduled for uninstall...%n",
node.getModuleInfo().getModuleName());
if (node.getDependentModules().isEmpty()) {
System.out.
printf("Calling uninstall method of module %s...\n",
printf("Calling uninstall method of module %s...%n",
node.getModuleInfo().getModuleName());
final UnInstallEvent unInstallEvent = new UnInstallEvent();
unInstallEvent.setEntityManager(entityManager);
@ -182,10 +178,10 @@ public class ModuleManager {
} else {
System.out.printf("There are other modules depending on "
+ "module %s. Module can't be "
+ "uninstalled. Depending modules:\n",
+ "uninstalled. Depending modules:%n",
node.getModuleInfo().getModuleName());
for (final TreeNode dependent : node.getDependentModules()) {
System.out.printf("\t%s\n",
System.out.printf("\t%s%n",
dependent.getModuleInfo()
.getModuleName());
}
@ -194,7 +190,7 @@ public class ModuleManager {
}
} else {
System.out.printf(
"Module %s is *not* scheduled for uninstall.\n",
"Module %s is *not* scheduled for uninstall.%n",
node.getModuleInfo().getModuleName());
}
}