You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2010/02/25 10:38:28 UTC
svn commit: r916202 - in /db/torque/torque4/trunk/torque-generator/src:
main/java/org/apache/torque/gf/configuration/
main/java/org/apache/torque/gf/configuration/controller/
main/java/org/apache/torque/gf/control/
main/java/org/apache/torque/gf/source...
Author: tfischer
Date: Thu Feb 25 09:38:28 2010
New Revision: 916202
URL: http://svn.apache.org/viewvc?rev=916202&view=rev
Log:
allow source files to be overridden in an externally provided unit descriptor.
Modified:
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfiguration.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfigurationReader.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitDescriptor.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/FileSourcesImpl.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java
db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/ReadConfigurationTest.java
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfiguration.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfiguration.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfiguration.java Thu Feb 25 09:38:28 2010
@@ -27,6 +27,7 @@
import org.apache.torque.gf.configuration.controller.Loglevel;
import org.apache.torque.gf.configuration.controller.Output;
import org.apache.torque.gf.configuration.generator.GeneratorConfiguration;
+import org.apache.torque.gf.file.Fileset;
import org.apache.torque.gf.option.Options;
/**
@@ -39,10 +40,16 @@
/** The list of all activities of the generation unit. */
private List<Output> outputFiles = new ArrayList<Output>();
- /**
+ /**
* All options for the generation unit.
*/
private Options options;
+
+ /** Overrides the source files defined in the control file. */
+ private Fileset overrideSourceFileset;
+
+ /** Whether the overrideSourceFileset was initialized. */
+ private boolean overrideSourceFilesetInitialized = false;
/**
* The configuration for the available generators.
@@ -245,9 +252,16 @@
* Returns the Loglevel during generation.
*
* @return the Loglevel, not null.
+ *
+ * @throws IllegalStateException if the loglevel is not yet set.
*/
public Loglevel getLoglevel()
{
+ if (loglevel == null)
+ {
+ throw new IllegalStateException(
+ "loglevel is not initialized");
+ }
return loglevel;
}
@@ -268,6 +282,38 @@
}
/**
+ * Returns the fileset which overrides the source files defined
+ * in the control file.
+ *
+ * @return the fileset, or null to use the fileset defined in the
+ * control file.
+ *
+ * @throws NullPointerException if overrideSourceFileset was not yet set.
+ */
+ public Fileset getOverrideSourceFileset()
+ {
+ if (!overrideSourceFilesetInitialized)
+ {
+ throw new IllegalStateException(
+ "overrideSourceFileset is not initialized");
+ }
+ return overrideSourceFileset;
+ }
+
+ /**
+ * Sets the fileset which overrides the source files defined
+ * in the control file.
+ *
+ * @param overrideSourceFileset the override fileset, or null
+ * to use the fileset defined in the control file.
+ */
+ public void setOverrideSourceFileset(Fileset overrideSourceFileset)
+ {
+ this.overrideSourceFileset = overrideSourceFileset;
+ overrideSourceFilesetInitialized = true;
+ }
+
+ /**
* Checks whether the unit configuration is fully initialized.
*
* @return true if the unit configuration is fully initialized,
@@ -279,7 +325,9 @@
|| options == null
|| generatorConfiguration == null
|| newFileTargetDirectory == null
- || modifiedFileTargetDirectory == null)
+ || modifiedFileTargetDirectory == null
+ || loglevel == null
+ || !overrideSourceFilesetInitialized)
{
return false;
}
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfigurationReader.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfigurationReader.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfigurationReader.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitConfigurationReader.java Thu Feb 25 09:38:28 2010
@@ -90,6 +90,8 @@
unitDescriptor.getProjectPaths().getNewFileTargetPath());
unitConfiguration.setModifiedFileTargetDirectory(
unitDescriptor.getProjectPaths().getModifiedFileTargetPath());
+ unitConfiguration.setOverrideSourceFileset(
+ unitDescriptor.getOverrideSourceFileset());
ConfigurationProvider configurationProvider
= createConfigurationProvider(unitDescriptor);
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitDescriptor.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitDescriptor.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitDescriptor.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/UnitDescriptor.java Thu Feb 25 09:38:28 2010
@@ -21,8 +21,9 @@
import org.apache.torque.gf.configuration.controller.Loglevel;
import org.apache.torque.gf.configuration.option.OptionsConfiguration;
-import org.apache.torque.gf.configuration.paths.TorqueGfPaths;
import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.configuration.paths.TorqueGfPaths;
+import org.apache.torque.gf.file.Fileset;
/**
* Contains all necessary information about a generation unit.
@@ -62,6 +63,9 @@
*/
private UnitDescriptor inheritsFrom;
+ /** Overrides the source files defined in the templates control file. */
+ private Fileset overrideSourceFileset;
+
/** Options to override the settings in the project Directory. */
private OptionsConfiguration overrideOptions;
@@ -69,7 +73,8 @@
private Loglevel loglevel;
/**
- * Constructor without inheritance, override options and loglevel.
+ * Constructor without inheritance, override options, overrideSourceFileset
+ * and loglevel.
*
* @param packaging The packaging of the generation unit, not null.
* @param projectPaths The paths the code generator must know about
@@ -82,7 +87,13 @@
ProjectPaths projectPaths,
TorqueGfPaths configurationPaths)
{
- this(packaging, projectPaths, configurationPaths, null, null, null);
+ this(packaging,
+ projectPaths,
+ configurationPaths,
+ null,
+ null,
+ null,
+ null);
}
/**
@@ -95,8 +106,11 @@
* of the configuration unit, not null.
* @param inheritsFrom the parent of this generation unit,
* or null if it does not inherit from a generation unit.
+ * @param overrideSourceFileset a fileset which overrides the
+ * source files defined in the templates control file.
* @param overrideOptions Options to override the settings in the project
* Directory, or null if no options are overridden.
+ *
* @param loglevel The loglevel to override the log level, or null to use
* the log level defined in the configuration.
*/
@@ -105,6 +119,7 @@
ProjectPaths projectPaths,
TorqueGfPaths configurationPaths,
UnitDescriptor inheritsFrom,
+ Fileset overrideSourceFileset,
OptionsConfiguration overrideOptions,
Loglevel loglevel)
{
@@ -127,6 +142,7 @@
this.projectPaths = projectPaths;
this.configurationPaths = configurationPaths;
this.inheritsFrom = inheritsFrom;
+ this.overrideSourceFileset = overrideSourceFileset;
this.overrideOptions = overrideOptions;
this.loglevel = loglevel;
}
@@ -175,6 +191,18 @@
}
/**
+ * Returns the fileset overriding the source files defined in the
+ * templates control file, or null if the template control definition
+ * is not overridden.
+ *
+ * @return the configuration of the overriding options, or null.
+ */
+ public Fileset getOverrideSourceFileset()
+ {
+ return overrideSourceFileset;
+ }
+
+ /**
* Returns the configuration of the overriding options, if any.
*
* @return the configuration of the overriding options, or null.
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java Thu Feb 25 09:38:28 2010
@@ -230,13 +230,14 @@
+ " Known types are: " + sourceTypes);
}
}
- Fileset fileset = new Fileset(
+ Fileset sourceFileset = new Fileset(
projectPaths.getDefaultSourcePath(),
includes,
excludes);
+
sources = new FileSourcesImpl(
sourceType,
- fileset,
+ sourceFileset,
startElementsPath,
sourceFilter,
transformerDefinitions,
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java Thu Feb 25 09:38:28 2010
@@ -115,6 +115,12 @@
}
Sources sources = output.getSources();
+ if (unitConfiguration.getOverrideSourceFileset() != null)
+ {
+ sources.setSourceFileset(
+ unitConfiguration.getOverrideSourceFileset());
+ }
+ sources.init();
if (!sources.hasNext())
{
log.info("No sources found");
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/FileSourcesImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/FileSourcesImpl.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/FileSourcesImpl.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/FileSourcesImpl.java Thu Feb 25 09:38:28 2010
@@ -26,6 +26,8 @@
import java.util.List;
import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.torque.gf.configuration.ConfigurationException;
import org.apache.torque.gf.configuration.ConfigurationHandlers;
import org.apache.torque.gf.file.Fileset;
@@ -39,6 +41,9 @@
*/
public class FileSourcesImpl extends SimpleSourcesImpl
{
+ /** The class log. */
+ private static Log log = LogFactory.getLog(FileSourcesImpl.class);
+
/**
* The type of the file(s), or null if the type should be determined
* from the file name extension.
@@ -98,25 +103,47 @@
this.type = type;
this.sourceFileset = sourceFileset;
this.configurationHandlers = configurationHandlers;
+ }
+ /**
+ * Determines the files which match the source fileset.
+ * This method must be called before hasNext() or getPaths() are called.
+ *
+ * @throws ConfigurationException if the files cannot be determined.
+ */
+ public void init() throws ConfigurationException
+ {
+ if (paths != null)
+ {
+ log.warn("init() called more than once, ignoring this call");
+ return;
+ }
try
{
- paths = sourceFileset.getFiles();
+ paths = sourceFileset.getFiles();
}
catch (IOException e)
{
- throw new ConfigurationException(e);
+ throw new ConfigurationException(e);
}
pathIt = paths.iterator();
}
-
+
public boolean hasNext()
{
+ if (paths == null)
+ {
+ throw new IllegalStateException("init() was not yet called !");
+ }
return pathIt.hasNext();
}
public Source next()
{
+ if (paths == null)
+ {
+ throw new IllegalStateException("init() was not yet called !");
+ }
File currentPath = pathIt.next();
SourceType currentType = type;
if (currentType == null)
@@ -181,47 +208,51 @@
}
/**
- * Returns all included source file patterns, or null or an empty set
- * if all files are included.
+ * Returns the fileset which determines the source files to read.
*
- * @return all included file patterns, or null.
+ * @return the fileset which determines the source files to read.
*/
- public Set<String> getIncludes()
+ public Fileset getSourceFileset()
{
- if (sourceFileset.getIncludes() == null)
- {
- return null;
- }
- return Collections.unmodifiableSet(sourceFileset.getIncludes());
+ return sourceFileset;
}
/**
- * Returns all excluded source file patterns, or null or an empty set
- * if no files are excluded.
+ * Sets the fileset which determines the source files to read.
*
- * @return all excluded file patterns, or null.
+ * @param sourceFileset the new source fileset, not null.
+ *
+ * @throws NullPointerException if sourceFileset is null.
+ * @throws IllegalStateException if init() was called before.
*/
- public Set<String> getExcludes()
+ public void setSourceFileset(Fileset sourceFileset)
{
- if (sourceFileset.getExcludes() == null)
+ if (sourceFileset == null)
{
- return null;
+ throw new NullPointerException("sourceFileset is null");
}
- return Collections.unmodifiableSet(sourceFileset.getExcludes());
+ if (paths != null)
+ {
+ throw new IllegalStateException(
+ "Source files are already determined");
+ }
+ this.sourceFileset = sourceFileset;
}
/**
- * Returns the base directory for the source files.
+ * Returns all paths in the source Fileset. The method init() must be
+ * called beforehand.
*
- * @return the base directory for the source files, or null.
+ * @return all Paths in the source fileset, not null.
+ *
+ * @throws IllegalStateException if the init method was not yet called.
*/
- public File getBasedir()
- {
- return sourceFileset.getBasedir();
- }
-
public List<File> getPaths()
{
+ if (paths == null)
+ {
+ throw new IllegalStateException("init() was not yet called !");
+ }
return Collections.unmodifiableList(paths);
}
}
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/source/Sources.java Thu Feb 25 09:38:28 2010
@@ -21,11 +21,32 @@
import java.util.Iterator;
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.file.Fileset;
+
/**
* The input for an generation process.
* It can contain several Sources.
+ *
+ * @version $Id: $
*/
public interface Sources extends Iterator<Source>
{
-
+ /**
+ * Sets the fileset which determines the source files to read.
+ *
+ * @param sourceFileset the new source fileset, not null.
+ *
+ * @throws NullPointerException if sourceFileset is null.
+ * @throws IllegalStateException if init() was called before.
+ */
+ void setSourceFileset(Fileset sourceFileset);
+
+ /**
+ * Determines the files which match the source fileset.
+ * This method must be called before hasNext() or next() are called.
+ *
+ * @throws ConfigurationException if the files cannot be determined.
+ */
+ void init() throws ConfigurationException;
}
Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/ReadConfigurationTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/ReadConfigurationTest.java?rev=916202&r1=916201&r2=916202&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/ReadConfigurationTest.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/ReadConfigurationTest.java Thu Feb 25 09:38:28 2010
@@ -210,6 +210,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -269,6 +271,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -306,6 +310,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -453,6 +459,7 @@
projectPaths,
new DefaultTorqueGfPaths(),
null,
+ null,
optionConfiguration,
null);
ConfigurationHandlers configurationHandlers
@@ -501,6 +508,7 @@
new DefaultTorqueGfPaths(),
null,
null,
+ null,
null);
projectPaths = new CustomProjectPaths(
@@ -516,6 +524,7 @@
new DefaultTorqueGfPaths(),
parentUnitDescriptor,
null,
+ null,
null);
UnitConfigurationReader configurationReader
= new UnitConfigurationReader();
@@ -636,6 +645,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -682,6 +693,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -737,6 +750,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -771,6 +786,8 @@
null,
new ArrayList<TransformerDefinition>(),
configurationHandlers);
+ sources.init();
+ outputFile.getSources().init();
assertSourcesEquals(
sources,
(FileSourcesImpl) outputFile.getSources());
@@ -896,14 +913,14 @@
expected.getType(),
actual.getType());
assertEquals(
- expected.getIncludes(),
- actual.getIncludes());
+ expected.getSourceFileset().getIncludes(),
+ actual.getSourceFileset().getIncludes());
assertEquals(
- expected.getExcludes(),
- actual.getExcludes());
+ expected.getSourceFileset().getExcludes(),
+ actual.getSourceFileset().getExcludes());
assertEquals(
- expected.getBasedir(),
- actual.getBasedir());
+ expected.getSourceFileset().getBasedir(),
+ actual.getSourceFileset().getBasedir());
assertEquals(
expected.getPaths(),
actual.getPaths());
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org