de.matthias_burbach.deputy.core
Class Deputy

java.lang.Object
  extended byde.matthias_burbach.deputy.core.Deputy
All Implemented Interfaces:
ProjectChangeListener, RuleSetChangeListener

public class Deputy
extends java.lang.Object
implements RuleSetChangeListener, ProjectChangeListener

Is the main class of the core application.

Author:
Matthias Burbach

Field Summary
static int CHANGE_ACTION_APPLY_RULES
          Flags that the last change action was 'Apply Rules'.
static int CHANGE_ACTION_CHANGE_DEPENDENCIES
          Flags that the last change action was 'Add Dependency' or 'Remove Dependency'.
static int CHANGE_ACTION_CHANGE_RULES
          Flags that the last change action was 'Change Default Rule', 'Add Enforcement Rule', 'Add Deprecation Rule', 'Add Replacement Rule' or 'Remove Rule'.
static int CHANGE_ACTION_UNKNOWN
          Flags that the last change action is unknown.
static int FORMAT_DEPUTYXML
          The export format 'Deputy XML'.
static int FORMAT_GRAPHML
          The export format 'GraphML'.
 
Constructor Summary
Deputy(Log log)
          Constructs and starts the application.
 
Method Summary
 void addChangeListener(DeputyChangeListener listener)
          Adds a listener to be notified on changes in the current project.
 void addedDependency(Project addedDependency, int index)
          Is fired when a dependency has been added to the project.
 void addedRule(Rule addedRule, int index)
          Is fired when a rule has been added to the rule set.
 Project applyRulesToProject()
          Loads the currently set project file into Deputy and applies rules on the fly.
 void changedDefaultRule()
          Is fired when the default rule has been changed.
 void deriveEnforcementsFromProject(java.lang.String aProjectFile)
          Adds an enforcement rule for each dependency in the given project.
 void exitApplication()
          Cleans up the application on exit.
 void exportDependencyGraph(int format)
          Exports the currently loaded project as a dependency graph XML that can be imported into Rational Rose or yEd for diagramming purposes.
 java.lang.String getDependencyGraphFile()
           
 java.lang.String getImportFile()
           
 int getLastChangeAction()
           
 Log getLog()
           
 java.lang.String getProjectFile()
           
 java.lang.String getProperty(java.lang.String key)
           
 java.util.List getRepositoryConfigs()
           
 Project getRootProject()
           
 java.lang.String getVersion()
           
 boolean isSaved()
           
 boolean isVirtualRepositoryActive()
           
static void main(java.lang.String[] args)
          Executes Deputy in batch mode.
 Project openProjectAsIs()
          Loads the currently set project file 'as is' into Deputy.
 void removeChangeListener(DeputyChangeListener listener)
          Removes a listener to be notified on changes in the current project.
 void removedDependency(Project removedDependency)
          Is fired when a dependency has been removed from the project.
 void removedIndirectDependency(Project removedDependency)
          Is fired when an indirect dependency has been removed from the project.
 void removedRule(Rule removedRule)
          Is fired when a rule has been removed from the rule set.
 void saveProjectAs(java.lang.String newProjectFileName)
          Saves the currently loaded project under the new project file name.
 void setDependencyGraphFile(java.lang.String dependencyGraphFile)
           
 void setImportFile(java.lang.String importProjectFile)
           
 void setLog(Log log)
           
 void setProjectFile(java.lang.String projectFile)
           
 void setProperty(java.lang.String key, java.lang.String value)
           
 void setRepositoryConfigs(java.util.List repositoryConfigs)
           
 void setVirtualRepositoryActive(boolean virtualRepositoryActive)
           
 void sortSnapshotsTopologically()
          Retrieves all direct and indirect SNAPSHOT dependencies of the current root project and prints them to the log in topological order such that leaves in the topological order occur first.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_GRAPHML

public static final int FORMAT_GRAPHML
The export format 'GraphML'.

See Also:
Constant Field Values

FORMAT_DEPUTYXML

public static final int FORMAT_DEPUTYXML
The export format 'Deputy XML'.

See Also:
Constant Field Values

CHANGE_ACTION_UNKNOWN

public static final int CHANGE_ACTION_UNKNOWN
Flags that the last change action is unknown.

See Also:
Constant Field Values

CHANGE_ACTION_APPLY_RULES

public static final int CHANGE_ACTION_APPLY_RULES
Flags that the last change action was 'Apply Rules'.

See Also:
Constant Field Values

CHANGE_ACTION_CHANGE_DEPENDENCIES

public static final int CHANGE_ACTION_CHANGE_DEPENDENCIES
Flags that the last change action was 'Add Dependency' or 'Remove Dependency'.

See Also:
Constant Field Values

CHANGE_ACTION_CHANGE_RULES

public static final int CHANGE_ACTION_CHANGE_RULES
Flags that the last change action was 'Change Default Rule', 'Add Enforcement Rule', 'Add Deprecation Rule', 'Add Replacement Rule' or 'Remove Rule'.

See Also:
Constant Field Values
Constructor Detail

Deputy

public Deputy(Log log)
       throws java.lang.Exception
Constructs and starts the application.

Parameters:
log - The log for messages.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong
Method Detail

exitApplication

public void exitApplication()
Cleans up the application on exit.


getVersion

public java.lang.String getVersion()
Returns:
The Deputy application version.

getProjectFile

public java.lang.String getProjectFile()
Returns:
The absolute file path and name of the project that is currently loaded into Deputy or which is to be loaded next into Deputy.

setProjectFile

public void setProjectFile(java.lang.String projectFile)
Parameters:
projectFile - The absolute file path and name of the project that is currently loaded into Deputy or which is to be loaded next into Deputy.

getImportFile

public java.lang.String getImportFile()
Returns:
The absolute file path and name of the project that was last imported from.

setImportFile

public void setImportFile(java.lang.String importProjectFile)
Parameters:
importProjectFile - The absolute file path and name of the project that was last imported from.

isVirtualRepositoryActive

public boolean isVirtualRepositoryActive()
Returns:
Returns the virtualRepositoryActive.

setVirtualRepositoryActive

public void setVirtualRepositoryActive(boolean virtualRepositoryActive)
Parameters:
virtualRepositoryActive - The virtualRepositoryActive to set.

openProjectAsIs

public Project openProjectAsIs()
                        throws java.lang.Exception
Loads the currently set project file 'as is' into Deputy. 'As is' means that no rules are applied yet.

Returns:
The project opened.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong.

deriveEnforcementsFromProject

public void deriveEnforcementsFromProject(java.lang.String aProjectFile)
                                   throws java.lang.Exception
Adds an enforcement rule for each dependency in the given project.

Parameters:
aProjectFile - Absolute path of the project whose dependencies to derive the enforcement rules from.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong.

applyRulesToProject

public Project applyRulesToProject()
                            throws java.lang.Exception
Loads the currently set project file into Deputy and applies rules on the fly.

Returns:
The project after applying the rules to it.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong.

sortSnapshotsTopologically

public void sortSnapshotsTopologically()
Retrieves all direct and indirect SNAPSHOT dependencies of the current root project and prints them to the log in topological order such that leaves in the topological order occur first.


getRootProject

public Project getRootProject()
Returns:
The currently active root project loaded into Deputy. Can be null.

saveProjectAs

public void saveProjectAs(java.lang.String newProjectFileName)
                   throws java.lang.Exception
Saves the currently loaded project under the new project file name.

Parameters:
newProjectFileName - The absolute path and name to save the project under.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

isSaved

public boolean isSaved()
Returns:
true if the current state of the project is saved.

getDependencyGraphFile

public java.lang.String getDependencyGraphFile()
Returns:
The absolute path and name of the file to export the dependency graph under.

setDependencyGraphFile

public void setDependencyGraphFile(java.lang.String dependencyGraphFile)
Parameters:
dependencyGraphFile - The absolute path and name of the file to export the dependency graph under.

exportDependencyGraph

public void exportDependencyGraph(int format)
                           throws java.lang.Exception
Exports the currently loaded project as a dependency graph XML that can be imported into Rational Rose or yEd for diagramming purposes.

Parameters:
format - The export format. Can be FORMAT_GRAPHML or FORMAT_DEPUTYXML.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

getRepositoryConfigs

public java.util.List getRepositoryConfigs()
                                    throws java.lang.Exception
Returns:
The list of configs of type RepositoryConfig.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

setRepositoryConfigs

public void setRepositoryConfigs(java.util.List repositoryConfigs)
                          throws java.lang.Exception
Parameters:
repositoryConfigs - A list of configs of type RepositoryConfig.
Throws:
java.lang.Exception - if anything goes unexpectedly wrong

addChangeListener

public void addChangeListener(DeputyChangeListener listener)
Adds a listener to be notified on changes in the current project.

Parameters:
listener - The listener to be added.

removeChangeListener

public void removeChangeListener(DeputyChangeListener listener)
Removes a listener to be notified on changes in the current project.

Parameters:
listener - The listener to be removed.

changedDefaultRule

public void changedDefaultRule()
Is fired when the default rule has been changed.

Specified by:
changedDefaultRule in interface RuleSetChangeListener

addedRule

public void addedRule(Rule addedRule,
                      int index)
Is fired when a rule has been added to the rule set.

Specified by:
addedRule in interface RuleSetChangeListener
Parameters:
addedRule - The added rule.
index - The index of the added rule in the sorted list of rules of the rule set.

removedRule

public void removedRule(Rule removedRule)
Is fired when a rule has been removed from the rule set.

Specified by:
removedRule in interface RuleSetChangeListener
Parameters:
removedRule - The removed rule.

getLog

public Log getLog()
Returns:
The log Deputy currently writes messages to. Can be null. Can change, don't cache a reference.

setLog

public void setLog(Log log)
Parameters:
log - The log to write messages to. Can be set by the creator of this class to define where to log to.

getLastChangeAction

public int getLastChangeAction()
Returns:
One of CHANGE_ACTION_UNKNOWN, CHANGE_ACTION_APPLY_RULES, CHANGE_ACTION_CHANGE_DEPENDENCIES,

addedDependency

public void addedDependency(Project addedDependency,
                            int index)
Is fired when a dependency has been added to the project.

Specified by:
addedDependency in interface ProjectChangeListener
Parameters:
addedDependency - The added dependency.
index - The index of the dependency in the sorted list of the project's dependencies.

removedDependency

public void removedDependency(Project removedDependency)
Is fired when a dependency has been removed from the project.

Specified by:
removedDependency in interface ProjectChangeListener
Parameters:
removedDependency - The removed dependency.

removedIndirectDependency

public void removedIndirectDependency(Project removedDependency)
Is fired when an indirect dependency has been removed from the project.

Specified by:
removedIndirectDependency in interface ProjectChangeListener
Parameters:
removedDependency - The removed indirect dependency.

getProperty

public java.lang.String getProperty(java.lang.String key)
Parameters:
key - The property's key.
Returns:
The property value or null if the property does not exist.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Parameters:
key - The property's key. Must not be null.
value - The property's value. Must not be null.

main

public static void main(java.lang.String[] args)
Executes Deputy in batch mode. Opens the project file specified, applies the rules on it, and optionally saves the diff report and/or the processed project file.

Exits with return code 0 if processing was successful, exits with return code -1 if an error occurred.

Parameters:
args - The command line arguments:
  • -projectFile=absolute path of the project file to process
    is mandatory
  • -diffFile=absolute path to save the diff report under
    is optional, defaults to not saving the diff report after processing
  • -saveAsFile=absolute path to save the processed project file under
    is optional, defaults to not saving the file after processing


Copyright © 2005-2007 . All Rights Reserved.