Commit 1a9c00b1 authored by NicolaiO's avatar NicolaiO 🐼

Code cleanup

parent 7515af23
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="GENERATE_FINAL_LOCALS" value="true" />
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
<option name="CLASS_NAMES_IN_JAVADOC" value="3" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
</JavaCodeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
......@@ -4,9 +4,9 @@
<option name="selectedGlobalProfile">
<Settings>
<option name="formatter" value="ECLIPSE" />
<option name="id" value="1480100693696" />
<option name="importOrderConfigFilePath" value="$PROJECT_DIR$/coding/Sumatra.importorder"/>
<option name="importOrderFromFile" value="true"/>
<option name="id" value="1474474120699" />
<option name="importOrderConfigFilePath" value="$PROJECT_DIR$/../Sumatra/coding/Sumatra.importorder" />
<option name="importOrderFromFile" value="true" />
<option name="name" value="default" />
<option name="pathToConfigFileJava" value="$PROJECT_DIR$/../Sumatra/coding/TigersFormatterProfile.xml" />
<option name="selectedJavaProfile" value="TIGERs" />
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.tigers.moduli</groupId>
<artifactId>moduli</artifactId>
<version>2.2</version>
<name>moduli</name>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.tigers.moduli</groupId>
<artifactId>moduli</artifactId>
<version>2.2</version>
<name>moduli</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependencies>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<outputXML>true</outputXML>
<distributionManagement>
<repository>
<id>tigers</id>
<name>Internal Releases</name>
<url>https://tigers-mannheim.de/nexus/content/repositories/tigers</url>
</repository>
<snapshotRepository>
<id>snapshot_tigers</id>
<name>Internal Releases</name>
<url>https://tigers-mannheim.de/nexus/content/repositories/snapshot_tigers</url>
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
<ignoredUnusedDeclaredDependencies>
<!-- dependency is required on runtime only -->
<ignoredUnusedDeclaredDependencie>
commons-collections:commons-collections:*
</ignoredUnusedDeclaredDependencie>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>tigers</id>
<name>Internal Releases</name>
<url>https://tigers-mannheim.de/nexus/content/repositories/tigers</url>
</repository>
<snapshotRepository>
<id>snapshot_tigers</id>
<name>Internal Releases</name>
<url>https://tigers-mannheim.de/nexus/content/repositories/snapshot_tigers</url>
</snapshotRepository>
</distributionManagement>
</project>
......@@ -46,8 +46,8 @@ public class Moduli
private SubnodeConfiguration globalConfiguration;
private ModulesStateVariable modulesState = new ModulesStateVariable();
private XMLConfiguration config;
/**
* Getter modulesState.
*
......@@ -57,8 +57,8 @@ public class Moduli
{
return modulesState;
}
/**
* Setter modulesState.
* Only to use if you know what you are doing ;).
......@@ -69,8 +69,8 @@ public class Moduli
{
this.modulesState = modulesState;
}
/**
* Getter global configuration
*
......@@ -80,8 +80,8 @@ public class Moduli
{
return globalConfiguration;
}
/**
* Loads all available modules from configuration-file into modulesList.
*
......@@ -92,27 +92,27 @@ public class Moduli
{
modules.clear();
orderedModules.clear();
modulesState.set(ModulesState.NOT_LOADED);
loadModulesFromFile(xmlFile);
DirectedGraph<AModule, DefaultEdge> dependencyGraph = buildDependencyGraph();
new TopologicalOrderIterator<>(dependencyGraph).forEachRemaining(m -> orderedModules.add(0, m));
modulesState.set(ModulesState.RESOLVED);
}
private void loadModulesFromFile(String xmlFile) throws LoadModulesException
{
try
{
config = new XMLConfiguration(xmlFile);
setGlobalConfiguration();
constructModules();
} catch (ConfigurationException e)
{
throw new LoadModulesException("Configuration contains errors: " + e.getMessage(), e);
......@@ -130,14 +130,14 @@ public class Moduli
throw new LoadModulesException("An argument isn't valid : " + e.getMessage(), e);
}
}
private void setGlobalConfiguration()
{
globalConfiguration = getModuleConfig("globalConfiguration");
}
@SuppressWarnings("unchecked")
private void constructModules() throws ClassNotFoundException, LoadModulesException
{
......@@ -145,19 +145,19 @@ public class Moduli
{
Class<? extends AModule> id = (Class<? extends AModule>) Class
.forName(config.getString(moduleMessage(i, "[@id]")));
Class<? extends AModule> clazz = getImplementation(i, id);
SubnodeConfiguration moduleConfig = getModuleConfig(moduleMessage(i, ".properties"));
AModule module = (AModule) createObject(clazz);
module.setSubnodeConfiguration(moduleConfig);
module.setId(id);
checkModuleIsUnique(module);
// --- set dependency-list ---
String[] rawDependencyList = config.getStringArray(moduleMessage(i, ".dependency"));
List<Class<? extends AModule>> dependencyList = new ArrayList<>();
......@@ -166,15 +166,15 @@ public class Moduli
dependencyList.add((Class<? extends AModule>) Class.forName(dependency));
}
module.setDependencies(dependencyList);
modules.put(id, module);
log.trace("Module created: " + module);
}
}
@SuppressWarnings("unchecked")
private Class<? extends AModule> getImplementation(final int i, final Class<? extends AModule> id)
throws ClassNotFoundException
......@@ -186,8 +186,8 @@ public class Moduli
}
return id;
}
private SubnodeConfiguration getModuleConfig(final String key)
{
try
......@@ -198,8 +198,8 @@ public class Moduli
return new SubnodeConfiguration(new HierarchicalConfiguration(), new DefaultConfigurationNode());
}
}
private void checkModuleIsUnique(final AModule module) throws LoadModulesException
{
if (modules.containsKey(module.getId()))
......@@ -207,8 +207,8 @@ public class Moduli
throw new LoadModulesException("module-id '" + module.getId() + "' isn't unique.");
}
}
/**
* Load modules and catch exceptions
*
......@@ -226,25 +226,23 @@ public class Moduli
+ "') ", e);
}
}
/**
* Starts all modules in modulesList.
*
* @throws InitModuleException if the initialization of a module fails
* @throws StartModuleException if the start of a module fails
*/
@SuppressWarnings("unchecked")
public void startModules() throws InitModuleException, StartModuleException
{
initModules(orderedModules);
startUpModules(orderedModules);
modulesState.set(ModulesState.ACTIVE);
}
private DirectedGraph<AModule, DefaultEdge> buildDependencyGraph() throws DependencyException
{
try
......@@ -271,8 +269,8 @@ public class Moduli
throw new DependencyException("Cycle in dependencies: ", e);
}
}
private void initModules(List<AModule> orderedModules) throws InitModuleException
{
for (AModule m : orderedModules)
......@@ -288,8 +286,8 @@ public class Moduli
}
}
}
private void startUpModules(List<AModule> orderedModules) throws StartModuleException
{
for (AModule m : orderedModules)
......@@ -309,8 +307,8 @@ public class Moduli
}
}
}
/**
* Stops all modules in modulesList.
*/
......@@ -318,15 +316,15 @@ public class Moduli
{
List<AModule> reversedModules = new ArrayList<>(orderedModules);
Collections.reverse(reversedModules);
internalStopModules(reversedModules);
deinitModules(reversedModules);
modulesState.set(ModulesState.RESOLVED);
}
private void internalStopModules(final List<AModule> reversedModules)
{
for (AModule m : reversedModules)
......@@ -345,8 +343,8 @@ public class Moduli
}
}
}
private void deinitModules(final List<AModule> reversedModules)
{
for (AModule m : reversedModules)
......@@ -361,8 +359,8 @@ public class Moduli
}
}
}
/**
* Returns a list with all loaded modules.
*
......@@ -372,8 +370,8 @@ public class Moduli
{
return new ArrayList<>(modules.values());
}
/**
* Gets a module from current module-list.
*
......@@ -381,14 +379,13 @@ public class Moduli
* @return the instance of the module for the id
* @throws ModuleNotFoundException if the module couldn't be found
*/
@SuppressWarnings("unchecked")
public <T extends AModule> T getModule(Class<T> moduleId)
{
return getModuleOpt(moduleId)
.orElseThrow(() -> new ModuleNotFoundException(moduleMessage(moduleId, "not found")));
}
/**
* Gets a module from current module-list.
*
......@@ -408,11 +405,11 @@ public class Moduli
.map(a -> (T) a)
.findFirst();
}
/**
* Check whether a module is loaded.
*
*
* @param moduleId the Class of the module
* @return if the module is loaded
*/
......@@ -421,11 +418,11 @@ public class Moduli
return modules.containsKey(moduleId)
|| modules.values().stream().map(Object::getClass).anyMatch(c -> c.equals(moduleId));
}
/**
* Creates an object from a clazz.
*
*
* @param clazz
*/
private Object createObject(final Class<? extends AModule> clazz)
......@@ -441,14 +438,14 @@ public class Moduli
throw new IllegalArgumentException("Error constructing module", e);
}
}
private String moduleMessage(Object module, String message)
{
return "Module " + module + " " + message;
}
private String moduleMessage(int moduleNumber, String property)
{
return "module(" + moduleNumber + ")" + property;
......
......@@ -14,11 +14,9 @@ package edu.tigers.moduli.exceptions;
*/
public class DependencyException extends Exception
{
/** */
private static final long serialVersionUID = -688270423190284593L;
/**
* @param msg of the exception