You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2006/06/26 17:43:36 UTC
svn commit: r417215 - in /lenya/trunk/tools/anttasks: build/ build/classes/
build/classes/org/ build/classes/org/apache/
build/classes/org/apache/lenya/ build/classes/org/apache/lenya/cms/
build/classes/org/apache/lenya/cms/ant/ build/classes/org/apach...
Author: michi
Date: Mon Jun 26 08:43:35 2006
New Revision: 417215
URL: http://svn.apache.org/viewvc?rev=417215&view=rev
Log:
classes and sources separated
Added:
lenya/trunk/tools/anttasks/build/
lenya/trunk/tools/anttasks/build/classes/
lenya/trunk/tools/anttasks/build/classes/org/
lenya/trunk/tools/anttasks/build/classes/org/apache/
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/BulkCopyTask.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyJavaSourcesTask.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyPublicationsTask.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/GenerateModuleList.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/JavaFilenameFilter.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/SCMFilenameFilter.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/TwoTuple.class (with props)
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/xml/
lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/xml/AntDocumentHelper.class (with props)
lenya/trunk/tools/anttasks/src/org/
lenya/trunk/tools/anttasks/src/org/apache/
lenya/trunk/tools/anttasks/src/org/apache/lenya/
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/BulkCopyTask.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyJavaSourcesTask.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyPublicationsTask.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/GenerateModuleList.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/JavaFilenameFilter.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/SCMFilenameFilter.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/TwoTuple.java
lenya/trunk/tools/anttasks/src/org/apache/lenya/xml/
lenya/trunk/tools/anttasks/src/org/apache/lenya/xml/AntDocumentHelper.java
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/BulkCopyTask.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/BulkCopyTask.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/BulkCopyTask.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyJavaSourcesTask.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyJavaSourcesTask.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyJavaSourcesTask.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyPublicationsTask.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyPublicationsTask.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/CopyPublicationsTask.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/GenerateModuleList.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/GenerateModuleList.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/GenerateModuleList.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/JavaFilenameFilter.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/JavaFilenameFilter.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/JavaFilenameFilter.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/SCMFilenameFilter.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/SCMFilenameFilter.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/SCMFilenameFilter.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/TwoTuple.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/TwoTuple.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/cms/ant/TwoTuple.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/xml/AntDocumentHelper.class
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/xml/AntDocumentHelper.class?rev=417215&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lenya/trunk/tools/anttasks/build/classes/org/apache/lenya/xml/AntDocumentHelper.class
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/BulkCopyTask.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/BulkCopyTask.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/BulkCopyTask.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/BulkCopyTask.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: BulkCopyTask.java 416058 2006-06-21 18:24:05Z andreas $ */
+
+package org.apache.lenya.cms.ant;
+
+import java.io.File;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+
+/**
+ * Copies all files matching filename or a all specififed filesets from each source directory.
+ * <br/><br/>
+ * Usage:
+ * <bulkCopy
+ * sourcedirs="dirOne:dirTwo"
+ * todir="WEB-INF/"
+ * flatten="true">
+ * <fileset includes="java/lib/*"/>
+ * </bulkCopy>
+ * <br/><br/>
+ * The above sample copies <em>dirOne/java/lib/*</em> and <em>dirTwo/java/lib/*</em>
+ * to <em>WEB-INF/lib</em>.
+ */
+public class BulkCopyTask extends Copy {
+
+ private Path sourceDirs;
+
+ /**
+ * @see org.apache.tools.ant.taskdefs.Copy#execute()
+ */
+ public void execute() throws BuildException {
+
+ final StringTokenizer sourceDirTokens = new StringTokenizer(this.sourceDirs.toString(), File.pathSeparator);
+
+ while (sourceDirTokens.hasMoreTokens()) {
+ final String sourceDir = sourceDirTokens.nextToken();
+
+ for(int i=0; i<getFileSets().size(); i++)
+ ((FileSet) getFileSets().get(i)).setDir(new File(sourceDir));
+
+ super.execute();
+ }
+ }
+
+ /**
+ * @param _sourceDirs Colon separated list of source directories
+ */
+ public void setSourceDirs(Path _sourceDirs) {
+ this.sourceDirs = _sourceDirs;
+ }
+
+ /**
+ * @return Returns the fileSet.
+ */
+ private List getFileSets() {
+ return super.filesets;
+ }
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyJavaSourcesTask.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyJavaSourcesTask.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyJavaSourcesTask.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyJavaSourcesTask.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,260 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: CopyJavaSourcesTask.java 416059 2006-06-21 18:27:27Z andreas $ */
+
+package org.apache.lenya.cms.ant;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.StringTokenizer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+
+/**
+ * Task to copy java sources.
+ */
+public class CopyJavaSourcesTask extends Task {
+
+ private Path pubsRootDirs;
+ private String javaDir;
+ private String buildDir;
+
+ /**
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() throws BuildException {
+ int numberOfDirectoriesCreated = 0;
+ int numberOfFilesCopied = 0;
+ TwoTuple twoTuple = new TwoTuple(numberOfDirectoriesCreated, numberOfFilesCopied);
+
+ String translatedBuildDir = Project.translatePath(this.buildDir);
+ File absoluteBuildDir = null;
+ if (translatedBuildDir != null && translatedBuildDir.startsWith(File.separator)) {
+ absoluteBuildDir = new File(translatedBuildDir);
+ } else {
+ absoluteBuildDir = new File(getProject().getBaseDir(), translatedBuildDir);
+ }
+
+ StringTokenizer st = new StringTokenizer(this.pubsRootDirs.toString(), File.pathSeparator);
+
+ while (st.hasMoreTokens()) {
+ String pubsRootDir = st.nextToken();
+
+ File path = new File(pubsRootDir);
+
+ if (path.isDirectory()) {
+ // In the case of a publication
+ if (new File(path, "publication.xml").isFile()) {
+ copyContentOfDir(new File(path, this.javaDir),
+ absoluteBuildDir,
+ twoTuple,
+ new JavaFilenameFilter(),
+ this);
+ // In the case of a module
+ } else if (new File(path, "module.xml").isFile()) {
+ copyContentOfDir(new File(path, this.javaDir),
+ absoluteBuildDir,
+ twoTuple,
+ new JavaFilenameFilter(),
+ this);
+ } else {
+ // FIXME: Look for publications defined by the file "publication.xml" or modules
+ // defined by the file "module.xml"
+ String[] pubs = path.list();
+
+ for (int i = 0; i < pubs.length; i++) {
+ File pubJavaDir = new File(path, new File(pubs[i], this.javaDir).toString());
+
+ copyContentOfDir(pubJavaDir,
+ absoluteBuildDir,
+ twoTuple,
+ new JavaFilenameFilter(),
+ this);
+ }
+ }
+ } else {
+ throw new BuildException("No such directory: " + path);
+ }
+ }
+
+ numberOfDirectoriesCreated = twoTuple.x;
+ numberOfFilesCopied = twoTuple.y;
+ log("Copying " + numberOfDirectoriesCreated + " directories to " + absoluteBuildDir,
+ Project.MSG_INFO);
+ log("Copying " + numberOfFilesCopied + " files to " + absoluteBuildDir, Project.MSG_INFO);
+ }
+
+ /**
+ * Copies the directory "source" into the directory "destination"
+ * @param source The source directory
+ * @param destination The destination directory
+ * @param twoTuple The twoTuple to use
+ * @param filenameFilter The filename filter to apply
+ * @param client The client task
+ */
+ public static void copyDir(File source, File destination, TwoTuple twoTuple,
+ FilenameFilter filenameFilter, Task client) {
+ File actualDestination = new File(destination, source.getName());
+ actualDestination.mkdirs();
+ copyContentOfDir(source, actualDestination, twoTuple, filenameFilter, client);
+ }
+
+ /**
+ * Copies the content of a directory into another directory
+ * @param source The source directory
+ * @param destination The destination directory
+ * @param twoTuple The twoTuple to use
+ * @param filenameFilter The filename filter to use
+ * @param client The client task
+ */
+ public static void copyContentOfDir(File source, File destination, TwoTuple twoTuple,
+ FilenameFilter filenameFilter, Task client) {
+ if (source.isDirectory()) {
+ String[] files;
+
+ if (filenameFilter != null) {
+ files = source.list(filenameFilter);
+ } else {
+ files = source.list();
+ }
+
+ for (int i = 0; i < files.length; i++) {
+ File file = new File(source, files[i]);
+
+ if (file.isFile()) {
+ copyFile(file, new File(destination, files[i]), twoTuple, client, false);
+ } else if (file.isDirectory()) {
+ copyContentOfDir(file,
+ new File(destination, files[i]),
+ twoTuple,
+ filenameFilter,
+ client);
+ } else {
+ client.log("CopyJavaSourcesTask.copyContentOfDir(): Neither file nor directory: "
+ + file,
+ Project.MSG_ERR);
+ }
+ }
+ }
+ }
+
+ /**
+ * Copies the content of a file into another file
+ * @param source The source file (not a directory!)
+ * @param destination File (not a directory!)
+ * @param twoTuple The twoTuple to use
+ * @param client The client task
+ */
+ public static void copyFile(File source, File destination, TwoTuple twoTuple, Task client,
+ boolean force) {
+ if (source.isFile()) {
+ File parentDest = new File(destination.getParent());
+
+ if (!parentDest.exists()) {
+ parentDest.mkdirs();
+
+ int numberOfDirectoriesCreated = twoTuple.x;
+ numberOfDirectoriesCreated++;
+ twoTuple.x = numberOfDirectoriesCreated;
+ }
+
+ if (destination.isFile()) {
+ if (destination.lastModified() > source.lastModified() && !force) {
+ return;
+ }
+ }
+
+ byte[] buffer = new byte[1024];
+ int bytesRead = -1;
+ InputStream in = null;
+ OutputStream out = null;
+
+ try {
+ in = new FileInputStream(source);
+ out = new FileOutputStream(destination);
+
+ while ((bytesRead = in.read(buffer)) >= 0) {
+ out.write(buffer, 0, bytesRead);
+ }
+ } catch (final FileNotFoundException e) {
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ client.log("Exception caught: " + writer.toString());
+ } catch (final IOException e) {
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ client.log("Exception caught: " + writer.toString());
+ } finally {
+ try {
+ if (out != null) {
+ out.close();
+ }
+ if (in != null) {
+ in.close();
+ }
+ } catch (final IOException e1) {
+ StringWriter writer = new StringWriter();
+ e1.printStackTrace(new PrintWriter(writer));
+ client.log("Exception closing stream: " + writer.toString());
+ }
+ }
+
+ int numberOfFilesCopied = twoTuple.y;
+ numberOfFilesCopied++;
+ twoTuple.y = numberOfFilesCopied;
+
+ } else {
+ client.log("No such file: " + source, Project.MSG_ERR);
+ }
+ }
+
+ /**
+ * Set the root publication root directories
+ * @param _pubsRootDirs The root directories
+ */
+ public void setPubsRootDirs(Path _pubsRootDirs) {
+ this.pubsRootDirs = _pubsRootDirs;
+ }
+
+ /**
+ * Set the java directory
+ * @param _javaDir The java directory
+ */
+ public void setJavaDir(String _javaDir) {
+ this.javaDir = _javaDir;
+ }
+
+ /**
+ * Set the build directory
+ * @param _buildDir The build directory
+ */
+ public void setBuildDir(String _buildDir) {
+ this.buildDir = _buildDir;
+ }
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyPublicationsTask.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyPublicationsTask.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyPublicationsTask.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/CopyPublicationsTask.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,126 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: CopyPublicationsTask.java 416058 2006-06-21 18:24:05Z andreas $ */
+
+package org.apache.lenya.cms.ant;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.StringTokenizer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+
+
+/**
+ * Task to copy files of publications and modules
+ */
+public class CopyPublicationsTask extends Task {
+ private Path pubsRootDirs;
+ private Path toDir;
+ private String excludes;
+
+ /** (non-Javadoc)
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() throws BuildException {
+ int numberOfDirectoriesCreated = 0;
+ int numberOfFilesCopied = 0;
+ TwoTuple twoTuple = new TwoTuple(numberOfDirectoriesCreated, numberOfFilesCopied);
+
+ StringTokenizer st = new StringTokenizer(this.pubsRootDirs.toString(), File.pathSeparator);
+
+ log("Excludes " + this.excludes);
+ FilenameFilter filter = new SCMFilenameFilter(this.excludes);
+
+ while (st.hasMoreTokens()) {
+ String pubsRootDir = st.nextToken();
+
+ copy(pubsRootDir, filter, twoTuple);
+ }
+
+ numberOfDirectoriesCreated = twoTuple.x;
+ numberOfFilesCopied = twoTuple.y;
+ log("Copying " + numberOfDirectoriesCreated + " directories to " + this.toDir);
+ log("Copying " + numberOfFilesCopied + " files to " + this.toDir);
+ }
+
+ /**
+ *
+ */
+ public void copy(String pubsRootDir, FilenameFilter filter, TwoTuple twoTuple) {
+ // In the case the pubsRootDir is publication dir
+ if (new File(pubsRootDir, "publication.xml").isFile()) {
+ File pubDir = new File(pubsRootDir);
+ log("Copy publication: " + pubDir);
+ CopyJavaSourcesTask.copyDir(pubDir, new File(this.toDir.toString()), twoTuple, filter, this);
+ File localPublicationXConf = new File(pubDir, "/config/local.publication.xconf");
+ if (localPublicationXConf.isFile()) {
+ File publicationXConf = new File(this.toDir.toString() + "/" + pubDir.getName() + "/config/publication.xconf");
+ log("Patch config file with local version: " + localPublicationXConf + " " + publicationXConf);
+ CopyJavaSourcesTask.copyFile(localPublicationXConf, publicationXConf, twoTuple, this, true);
+ }
+
+ File localAccessControlXConf = new File(pubDir, "/config/ac/local.ac.xconf");
+ if (localAccessControlXConf.isFile()) {
+ File accessControlXConf = new File(this.toDir.toString() + "/" + pubDir.getName() + "/config/ac/ac.xconf");
+ log("Patch access control config file with local version: " + localAccessControlXConf + " " + accessControlXConf);
+ CopyJavaSourcesTask.copyFile(localAccessControlXConf, accessControlXConf, twoTuple, this, true);
+ }
+
+ // In the case the pubsRootDir is module dir
+ } else if (new File(pubsRootDir, "module.xml").isFile()) {
+ log("Copy module: " + pubsRootDir);
+ CopyJavaSourcesTask.copyDir(new File(pubsRootDir), new File(this.toDir.toString()), twoTuple, filter, this);
+ } else {
+ File[] files = new File(pubsRootDir).listFiles(filter);
+ for (int i = 0; i < files.length; i++) {
+ copy(files[i].getAbsolutePath(), filter, twoTuple);
+ }
+ if (files.length < 1) log("ERROR: No children: " + pubsRootDir);
+ }
+ }
+
+ /**
+ * Where the publications are located
+ *
+ * @param _pubsRootDirs
+ */
+ public void setPubsRootDirs(Path _pubsRootDirs) {
+ this.pubsRootDirs = _pubsRootDirs;
+ }
+
+ /**
+ * Where the publications shall be copied to
+ *
+ * @param _toDir
+ */
+ public void setToDir(Path _toDir) {
+ this.toDir = _toDir;
+ }
+
+ /**
+ * Which filenames shall be excluded
+ *
+ * @param _excludes
+ */
+ public void setExcludes(String _excludes) {
+ this.excludes = _excludes;
+ }
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/GenerateModuleList.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/GenerateModuleList.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/GenerateModuleList.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/GenerateModuleList.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,116 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: BulkCopyTask.java 383219 2006-03-04 23:04:55Z michi $ */
+package org.apache.lenya.cms.ant;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.lenya.xml.AntDocumentHelper;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Generate an XML containing modules.
+ */
+public class GenerateModuleList extends Task {
+
+ private Path moduleDirectories;
+ private String moduleFile;
+
+ /**
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() throws BuildException {
+
+ List descriptors = new ArrayList();
+
+ StringTokenizer st = new StringTokenizer(this.moduleDirectories.toString(),
+ File.pathSeparator);
+
+ while (st.hasMoreTokens()) {
+ String moduleDir = st.nextToken();
+ File path = new File(moduleDir);
+
+ if (path.isDirectory()) {
+ if (isModuleDirectory(path)) {
+ descriptors.add(path);
+ } else {
+ String[] dirs = path.list();
+ boolean matched = false;
+ for (int i = 0; i < dirs.length; i++) {
+ File moduleSubDir = new File(path, dirs[i]);
+ if (isModuleDirectory(moduleSubDir)) {
+ descriptors.add(moduleSubDir);
+ matched = true;
+ }
+ }
+ if (!matched) {
+ log("No module(s) found in directory [" + path + "]");
+ }
+ }
+ } else {
+ throw new BuildException("No such directory: " + path);
+ }
+ }
+
+ try {
+ Document doc = AntDocumentHelper.createDocument(NAMESPACE, "modules", null);
+ File[] modules = (File[]) descriptors.toArray(new File[descriptors.size()]);
+ for (int i = 0; i < modules.length; i++) {
+ Element element = doc.createElementNS(NAMESPACE, "module");
+ element.setAttribute("src", modules[i].getAbsolutePath());
+ doc.getDocumentElement().appendChild(element);
+ }
+ File file = new File(this.moduleFile.replace('/', File.separatorChar));
+ AntDocumentHelper.writeDocument(doc, file);
+ } catch (Exception e) {
+ throw new BuildException(e);
+ }
+
+ }
+
+ protected static final String NAMESPACE = "http://apache.org/lenya/module-list/1.0";
+
+ protected boolean isModuleDirectory(File path) {
+ File moduleFile = new File(path, "module.xml");
+ return moduleFile.isFile();
+ }
+
+ /**
+ * Set the module source directories.
+ * @param dirs The module directories.
+ */
+ public void setModuleDirs(Path dirs) {
+ this.moduleDirectories = dirs;
+ }
+
+ /**
+ * Set the file to generate.
+ * @param file The file.
+ */
+ public void setModuleFile(String file) {
+ this.moduleFile = file;
+ }
+
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/JavaFilenameFilter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/JavaFilenameFilter.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/JavaFilenameFilter.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/JavaFilenameFilter.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: JavaFilenameFilter.java 416058 2006-06-21 18:24:05Z andreas $ */
+
+package org.apache.lenya.cms.ant;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Arrays;
+import java.util.StringTokenizer;
+
+/**
+ * A filename filter for .java, .properties, .xml and .xsl files
+ * FIXME this class is named badly
+ */
+public class JavaFilenameFilter implements FilenameFilter {
+
+ private static final String[] SUFFIXES = { "java", "properties", "xml", "xsl" };
+
+ /**
+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+ */
+ public boolean accept(File dir, String name) {
+ boolean accept = true;
+ if (new File(dir, name).isFile()) {
+ String suffix = getExtension(name);
+ if (!Arrays.asList(SUFFIXES).contains(suffix)) {
+ accept = false;
+ }
+ }
+ return accept;
+ }
+
+ /**
+ * Get the extension
+ * @param filename the file name from which the extension is extracted
+ * @return the extension
+ */
+ static public String getExtension(String filename) {
+ StringTokenizer st = new StringTokenizer(filename, ".");
+ st.nextToken();
+
+ String extension = "";
+
+ while (st.hasMoreTokens()) {
+ extension = st.nextToken();
+ }
+
+ return extension;
+ }
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/SCMFilenameFilter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/SCMFilenameFilter.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/SCMFilenameFilter.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/SCMFilenameFilter.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: SCMFilenameFilter.java 416058 2006-06-21 18:24:05Z andreas $ */
+
+package org.apache.lenya.cms.ant;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Filter to exclude SCM files, such as CVS and .svn.
+ * A set of filenames (provided as comma-separated list) is excluded.
+ */
+public class SCMFilenameFilter implements FilenameFilter {
+
+ private List excludes;
+
+ /**
+ * Ctor.
+ * @param _excludes A comma-separated list of file names, e.g. CVS,.svn
+ */
+ public SCMFilenameFilter(String _excludes) {
+ this.excludes = Arrays.asList(_excludes.split(","));
+ }
+
+ /**
+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+ */
+ public boolean accept(File dir, String name) {
+ return !this.excludes.contains(name);
+ }
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/TwoTuple.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/TwoTuple.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/TwoTuple.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/cms/ant/TwoTuple.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id: TwoTuple.java 416058 2006-06-21 18:24:05Z andreas $ */
+
+package org.apache.lenya.cms.ant;
+
+/**
+ * Helper class to hold two values.
+ */
+public class TwoTuple {
+ /**
+ * <code>x</code> The x value
+ */
+ public int x;
+ /**
+ * <code>y</code> The y value
+ */
+ public int y;
+
+ /**
+ * Constructor
+ * @param _x The x value
+ * @param _y The y value
+ *
+ */
+ public TwoTuple(int _x, int _y) {
+ this.x = _x;
+ this.y = _y;
+ }
+}
Added: lenya/trunk/tools/anttasks/src/org/apache/lenya/xml/AntDocumentHelper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/tools/anttasks/src/org/apache/lenya/xml/AntDocumentHelper.java?rev=417215&view=auto
==============================================================================
--- lenya/trunk/tools/anttasks/src/org/apache/lenya/xml/AntDocumentHelper.java (added)
+++ lenya/trunk/tools/anttasks/src/org/apache/lenya/xml/AntDocumentHelper.java Mon Jun 26 08:43:35 2006
@@ -0,0 +1,184 @@
+package org.apache.lenya.xml;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+
+/**
+ * Slightly modified version of Lenya's DocumentBuilder to be used in Ant tasks.
+ */
+public class AntDocumentHelper {
+
+ /**
+ * Creates a non-validating and namespace-aware DocumentBuilder.
+ * @return A new DocumentBuilder object.
+ * @throws ParserConfigurationException if an error occurs
+ */
+ public static DocumentBuilder createBuilder() throws ParserConfigurationException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+
+ /**
+ * Creates a document. A xmlns:prefix="namespaceUri" attribute is added to the document element.
+ * @param namespaceUri The namespace URL of the root element.
+ * @param qualifiedName The qualified name of the root element.
+ * @param documentType The type of document to be created or null. When doctype is not null, its
+ * Node.ownerDocument attribute is set to the document being created.
+ * @return A new Document object.
+ * @throws DOMException if an error occurs
+ * @throws ParserConfigurationException if an error occurs
+ * @see org.w3c.dom.DOMImplementation#createDocument(String, String, DocumentType)
+ */
+ public static Document createDocument(String namespaceUri, String qualifiedName,
+ DocumentType documentType) throws DOMException, ParserConfigurationException {
+ DocumentBuilder builder = createBuilder();
+ Document document = builder.getDOMImplementation().createDocument(namespaceUri,
+ qualifiedName,
+ documentType);
+
+ // add xmlns:prefix attribute
+ String name = "xmlns";
+ int index = qualifiedName.indexOf(":");
+
+ if (index > -1) {
+ name += (":" + qualifiedName.substring(0, index));
+ }
+
+ document.getDocumentElement().setAttributeNS("http://www.w3.org/2000/xmlns/",
+ name,
+ namespaceUri);
+
+ return document;
+ }
+
+ /**
+ * Writes a document to a file. A new file is created if it does not exist.
+ * @param document The document to save.
+ * @param file The file to save the document to.
+ * @throws IOException if an error occurs
+ * @throws TransformerConfigurationException if an error occurs
+ * @throws TransformerException if an error occurs
+ */
+ public static void writeDocument(Document document, File file)
+ throws TransformerConfigurationException, TransformerException, IOException {
+ // sanity checks
+ if (document == null)
+ throw new IllegalArgumentException("illegal usage, parameter document may not be null");
+ if (file == null)
+ throw new IllegalArgumentException("illegal usage, parameter file may not be null");
+
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+
+ DOMSource source = new DOMSource(document);
+ FileOutputStream out = new FileOutputStream(file);
+ StreamResult result = new StreamResult(out);
+ getTransformer(document.getDoctype()).transform(source, result);
+ out.close();
+ }
+
+ /**
+ * Get the transformer.
+ * @param documentType the document type
+ * @return a transformer
+ * @throws TransformerConfigurationException if an error occurs
+ */
+ protected static Transformer getTransformer(DocumentType documentType)
+ throws TransformerConfigurationException {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+
+ if (documentType != null) {
+ if (documentType.getPublicId() != null)
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, documentType.getPublicId());
+ if (documentType.getSystemId() != null)
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, documentType.getSystemId());
+ }
+
+ return transformer;
+ }
+
+ /**
+ * Reads a document from a file.
+ * @return A document.
+ * @param file The file to load the document from.
+ * @throws ParserConfigurationException if an error occurs
+ * @throws SAXException if an error occurs
+ * @throws IOException if an error occurs
+ */
+ public static Document readDocument(File file) throws ParserConfigurationException,
+ SAXException, IOException {
+ DocumentBuilder builder = createBuilder();
+ return builder.parse(file);
+ }
+
+ /**
+ * Returns all child elements of an element that belong to a certain
+ * namespace and have a certain local name.
+ * @param element The parent element.
+ * @param namespaceUri The namespace that the childen must belong to.
+ * @param localName The local name of the children.
+ * @return The child elements.
+ */
+ public static Element[] getChildren(Element element, String namespaceUri, String localName) {
+ List childElements = new ArrayList();
+ NodeList children = element.getElementsByTagNameNS(namespaceUri, localName);
+
+ for (int i = 0; i < children.getLength(); i++) {
+ if (children.item(i).getParentNode() == element) {
+ childElements.add(children.item(i));
+ }
+ }
+
+ return (Element[]) childElements.toArray(new Element[childElements.size()]);
+ }
+
+ /**
+ * Returns the text inside an element. Only the child text nodes of this
+ * element are collected.
+ * @param element The element.
+ * @return The text inside the element.
+ */
+ public static String getSimpleElementText(Element element) {
+ StringBuffer buffer = new StringBuffer();
+ NodeList children = element.getChildNodes();
+
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+
+ if (child instanceof Text) {
+ buffer.append(child.getNodeValue());
+ }
+ }
+
+ return buffer.toString();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org