notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1397 - in development/laboratory/maven/magic-migrate: . src/main/net/dpml/magic/maven/migrate src/test/net/dpml/magic/maven/migrate
- From: mraad23 AT earthlink.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1397 - in development/laboratory/maven/magic-migrate: . src/main/net/dpml/magic/maven/migrate src/test/net/dpml/magic/maven/migrate
- Date: Fri, 07 Jan 2005 00:24:36 +0100
Author: mraad23 AT earthlink.net
Date: Fri Jan 7 00:24:36 2005
New Revision: 1397
Added:
development/laboratory/maven/magic-migrate/build.properties
development/laboratory/maven/magic-migrate/project.properties
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/FileExistsException.java
Modified:
development/laboratory/maven/magic-migrate/plugin.properties
development/laboratory/maven/magic-migrate/project.xml
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/Migrate.java
development/laboratory/maven/magic-migrate/src/test/net/dpml/magic/maven/migrate/MigateTest.java
Log:
Added generation of index.xml
Added: development/laboratory/maven/magic-migrate/build.properties
==============================================================================
--- (empty file)
+++ development/laboratory/maven/magic-migrate/build.properties Fri Jan 7
00:24:36 2005
@@ -0,0 +1 @@
+dpml.host = http://www.dpml.net/repository,http://www.ibiblio.org/maven
Modified: development/laboratory/maven/magic-migrate/plugin.properties
==============================================================================
--- development/laboratory/maven/magic-migrate/plugin.properties
(original)
+++ development/laboratory/maven/magic-migrate/plugin.properties Fri
Jan 7 00:24:36 2005
@@ -1,4 +1,3 @@
-
# Copyright 2004 Stephen J McConnell
# Copyright 2004 Niclas Hedhman
#
@@ -21,5 +20,3 @@
# -------------------------------------------------------------------
# DPML - Maven to Magic Migration plugin.
# -------------------------------------------------------------------
-
-
Added: development/laboratory/maven/magic-migrate/project.properties
==============================================================================
--- (empty file)
+++ development/laboratory/maven/magic-migrate/project.properties Fri
Jan 7 00:24:36 2005
@@ -0,0 +1 @@
+maven.repo.remote =
http://www.apache.org/dist/java-repository,http://www.ibiblio.org/maven,http://www.dpml.net/repository
Modified: development/laboratory/maven/magic-migrate/project.xml
==============================================================================
--- development/laboratory/maven/magic-migrate/project.xml (original)
+++ development/laboratory/maven/magic-migrate/project.xml Fri Jan 7
00:24:36 2005
@@ -395,6 +395,12 @@
<version>1.1.3.3</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+
</dependencies>
<build>
<!-- Useful if your plugin uses some beans -->
Added:
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/FileExistsException.java
==============================================================================
--- (empty file)
+++
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/FileExistsException.java
Fri Jan 7 00:24:36 2005
@@ -0,0 +1,24 @@
+package net.dpml.magic.maven.migrate;
+
+/**
+ * Exception to be thrown when a file already exists.
+ */
+public class FileExistsException extends java.io.IOException {
+ private java.io.File _file;
+
+ /**
+ * Create a instance with a reference to the existing file.
+ *
+ * @param file the existing file.
+ */
+ public FileExistsException(java.io.File file) {
+ _file = file;
+ }
+
+ /**
+ * @return the file that already exists.
+ */
+ public java.io.File getFile() {
+ return _file;
+ }
+}
Modified:
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/Migrate.java
==============================================================================
---
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/Migrate.java
(original)
+++
development/laboratory/maven/magic-migrate/src/main/net/dpml/magic/maven/migrate/Migrate.java
Fri Jan 7 00:24:36 2005
@@ -1,60 +1,55 @@
/*
- Copyright 2004 Stephen J McConnell
- Copyright 2004 Niclas Hedhman
+ Copyright 2004 Stephen J McConnell
+ Copyright 2004 Niclas Hedhman
- 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.
-*/
+ 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.
+ */
package net.dpml.magic.maven.migrate;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import org.apache.maven.project.Project;
+/**
+ * TODO Create a map of the version numbers.
+ */
public class Migrate {
- public void migrate(
- Project proj,
- String dpml
- ) {
+
+ public void migrate(org.apache.maven.project.Project proj,
+ String dpml) {
}
- public void createDpml(
- Project proj,
- String dpml
- ) {
+ public void createDpml(org.apache.maven.project.Project proj,
+ String dpml) {
System.out.println("Project:" + proj.getName());
System.out.println("DPML_HOME=" + dpml);
if (dpml == null) {
dpml = System.getProperty("user.home" + "/.dpml");
}
System.out.println("dpml = " + dpml);
- File dpml_home = new File(dpml);
+ java.io.File dpml_home = new java.io.File(dpml);
dpml_home.mkdirs();
- File bindir = new File(dpml_home, "bin");
+ java.io.File bindir = new java.io.File(dpml_home, "bin");
bindir.mkdirs();
- File transitdir = new File(dpml_home, "transit/authority");
+ java.io.File transitdir = new java.io.File(dpml_home,
"transit/authority");
transitdir.mkdirs();
- File cachedir = new File(dpml_home, "main");
+ java.io.File cachedir = new java.io.File(dpml_home, "main");
cachedir.mkdirs();
- File docsdir = new File(dpml_home, "docs");
+ java.io.File docsdir = new java.io.File(dpml_home, "docs");
docsdir.mkdirs();
String magicPath = proj.getDependencyPath("dpml-magic");
@@ -66,47 +61,196 @@
}
- public void createBuilds(
- Project proj,
- String dpml
- )
- throws IOException {
- File cwd = new File(".");
+ public void createBuilds(org.apache.maven.project.Project proj,
+ String dpml)
+ throws java.io.IOException, org.apache.maven.MavenException {
+ java.io.File cwd = new java.io.File(".");
processDir(cwd);
}
- private void processDir(File dir)
- throws IOException {
- File[] entries = dir.listFiles();
- if (isProjectDir(dir, entries)) {
- createStandardBuild(dir);
+ /**
+ * Create build and index file recursuvely from the given base dir.
+ *
+ * @param basedir the base directory.
+ * @throws java.io.IOException if and IO error occured.
+ * @throws org.apache.maven.MavenException
+ * if a maven error occured.
+ */
+ public void createBuilds(final java.io.File basedir) throws
java.io.IOException, org.apache.maven.MavenException {
+ processDir(basedir);
+ }
+
+ /**
+ * Process the current directory. Here we get a list of all the entries
in the current directory.
+ * If the current entry contains a project.xml file, then we create a
standard build.xml and an index.xml.
+ * Otherwise we create a reactor build.xml file and dive into that entry
and repeat the above process.
+ *
+ * @param basedir the base directory.
+ * @throws java.io.IOException if an IO error occured.
+ * @throws org.apache.maven.MavenException
+ * if a maven error occured.
+ */
+ private void processDir(java.io.File basedir)
+ throws java.io.IOException, org.apache.maven.MavenException {
+ java.io.File[] entries = basedir.listFiles();
+ if (isProjectDir(entries)) {
+ final org.apache.maven.project.Project mavenProject =
getMavenProject(basedir);
+ createStandardBuild(basedir, mavenProject);
+ createStandardIndex(basedir, mavenProject);
} else {
- createReactorBuild(dir);
+ createReactorBuild(basedir);
recurse(entries);
}
}
- private void recurse(File[] entries) throws java.io.IOException {
+ /**
+ * Create index.xml file.
+ *
+ * @param basedir the base directory.
+ * @param project the maven project.
+ */
+ private void createStandardIndex(java.io.File basedir,
org.apache.maven.project.Project project) throws java.io.IOException {
+
+ final org.dom4j.Document document =
org.dom4j.DocumentHelper.createDocument();
+ final org.dom4j.Element index = document.addElement("index");
+ // importMetroModule(index);
+ createProject(index, project);
+ writeIndexDotXml(basedir, document);
+ }
+
+ private org.apache.maven.project.Project getMavenProject(java.io.File
basedir) throws org.apache.maven.MavenException {
+ final java.io.File mavenFile = new java.io.File(basedir, "project.xml");
// Create file with parent file, or NPE will be thrown.
+ return org.apache.maven.MavenUtils.getProject(mavenFile, null, false);
+ }
+
+ /**
+ * Write a document to index.xml.
+ *
+ * @param basedir where to write the file.
+ * @param document the document to write.
+ * @throws java.io.IOException if IO error occured.
+ */
+ private void writeIndexDotXml(java.io.File basedir, org.dom4j.Document
document) throws java.io.IOException {
+ final java.io.FileWriter fileWriter = new java.io.FileWriter(new
java.io.File(basedir, "index.xml"));
+ try {
+ final org.dom4j.io.OutputFormat outputFormat =
org.dom4j.io.OutputFormat.createPrettyPrint();
+ outputFormat.setEncoding("ISO-8859-1");
+ final org.dom4j.io.XMLWriter xmlWriter = new
org.dom4j.io.XMLWriter(fileWriter, outputFormat);
+ xmlWriter.write(document);
+ xmlWriter.flush();
+ } finally {
+ fileWriter.close();
+ }
+ }
+
+ /**
+ * Create the project tag.
+ *
+ * @param index the index element.
+ * @param project the maven project.
+ */
+ private void createProject(org.dom4j.Element index,
org.apache.maven.project.Project project) {
+ addResources(index, project);
+ final org.dom4j.Element projectElement = index.addElement("project");
+ projectElement.addAttribute("basedir", ".");
+ final org.dom4j.Element infoElement = projectElement.addElement("info");
+ infoElement.addElement("group").addText(project.getGroupId());
+ infoElement.addElement("name").addText(project.getName());
+ infoElement.addElement("version").addText(project.getCurrentVersion());
+ addDependencies(projectElement, project);
+ }
+
+ /**
+ * Add the project dependencies.
+ *
+ * @param projectElement the project element.
+ * @param project the maven project.
+ */
+ private void addDependencies(org.dom4j.Element projectElement,
org.apache.maven.project.Project project) {
+ final org.dom4j.Element dependenciesElement =
projectElement.addElement("dependencies");
+ final java.util.List list = project.getDependencies();
+ final int size = list.size();
+ for (int i = 0; i < size; i++) {
+ final org.apache.maven.project.Dependency dependency =
(org.apache.maven.project.Dependency) list.get(i);
+ final org.dom4j.Element dependencyElement =
dependenciesElement.addElement("dependency");
+ dependencyElement.addAttribute("key", dependency.getArtifactId());
+ // Handle special case if artifactId is junit
+ if ("junit".equals(dependency.getArtifactId())) {
+ dependencyElement.addAttribute("test",
"true").addAttribute("runtime", "false");
+ }
+ }
+ }
+
+ /**
+ * Add the project resources.
+ *
+ * @param index the index element.
+ * @param project the maven project.
+ */
+ private void addResources(org.dom4j.Element index,
org.apache.maven.project.Project project) {
+ final java.util.List list = project.getDependencies();
+ int size = list.size();
+ for (int i = 0; i < size; i++) {
+ final org.apache.maven.project.Dependency dependency =
(org.apache.maven.project.Dependency) list.get(i);
+ final org.dom4j.Element infoElement =
index.addElement("resource").addElement("info");
+ infoElement.addElement("group").addText(dependency.getGroupId());
+ infoElement.addElement("name").addText(dependency.getArtifactId());
+ infoElement.addElement("version").addText(dependency.getVersion());
+ infoElement.addElement("type").addText(dependency.getType());
+ }
+ }
+
+ /**
+ * import metro module tag.
+ *
+ * @param indexElement the index element.
+ */
+ private void importMetroModule(org.dom4j.Element indexElement) {
+ indexElement.addElement("import").addAttribute("uri",
"artifact:module:dpml/metro/dpml-metro#SNAPSHOT");
+ }
+
+ private void recurse(java.io.File[] entries) throws java.io.IOException,
org.apache.maven.MavenException {
for (int i = 0; i < entries.length; i++)
processDir(entries[i]);
}
- private boolean isProjectDir(
- File dir,
- File[] entries
- ) {
- for (int i = 0; i < entries.length; i++) {
- if (entries[i].getName().equals("src"))
- return true;
+ /**
+ * Check if the directory contains a 'src' entry..
+ *
+ * @param files array of files.
+ * @return true if one of the entries is 'src', false otherwise.
+ */
+ private boolean isProjectDir(java.io.File[] files) {
+ boolean foundProjectDotXml = false;
+ for (int i = 0; i < files.length; i++) {
+ if ("src".equals(files[i].getName())) {
+ foundProjectDotXml = true;
+ break;
+ }
}
- return false;
+ return foundProjectDotXml;
}
- private void createStandardBuild(File dir)
- throws IOException {
+
+ /**
+ * <project name="dpml-tutorial-hello" default="install" basedir="."
+ * xmlns:magic="antlib:net.dpml.magic"
xmlns:x="plugin:dpml/magic/dpml-magic-core" >
+ * <p/>
+ * <magic:import uri="artifact:template:dpml/magic/standard"/>
+ * <p/>
+ * <target name="build" depends="standard.build">
+ * <x:block name="tutorial" embed="MAIN">
+ * <x:component name="hello" class="tutorial.HelloComponent"/>
+ * </x:block>
+ * </target>
+ * <p/>
+ * </project>
+ */
+ private void createStandardBuild(java.io.File dir,
org.apache.maven.project.Project mavenProject)
+ throws java.io.IOException {
StringBuffer content = new StringBuffer(500);
content.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
- content.append("<project name=\"dpml-runtime\" default=\"default\"
basedir=\".\"\n");
+ content.append("<project name=\"" + mavenProject.getName() + "\"
default=\"install\" basedir=\".\"\n");
content.append(" xmlns:magic=\"antlib:net.dpml.magic\">\n");
content.append("\n");
content.append(" <magic:import
uri=\"artifact:template:dpml/magic/standard\"/>\n");
@@ -116,11 +260,11 @@
}
- private void createReactorBuild(File dir)
- throws IOException {
+ private void createReactorBuild(java.io.File dir)
+ throws java.io.IOException {
StringBuffer content = new StringBuffer(500);
content.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
- content.append("<project name=\"dpml-runtime\" default=\"default\"
basedir=\".\"\n");
+ content.append("<project name=\"maven-migrate\" default=\"default\"
basedir=\".\"\n");
content.append(" xmlns:magic=\"antlib:net.dpml.magic\">\n");
content.append("\n");
content.append(" <magic:import
uri=\"artifact:template:dpml/magic/reactor\"/>\n");
@@ -129,15 +273,22 @@
write(dir, content.toString());
}
- private void write(
- File dir,
- String content
- )
- throws IOException {
- File f = new File(dir, "build.xml");
- if (f.exists())
- throw new IOException("File already exists: " + f);
- final java.io.FileOutputStream fos = new FileOutputStream(f);
+ /**
+ * Write the content of a string to a file.
+ *
+ * @param dir where to write the file.
+ * @param content the content to write.
+ * @throws FileExistsException if the file already exists.
+ * @throws java.io.IOException if cannot write the file.
+ */
+ private void write(java.io.File dir,
+ String content)
+ throws FileExistsException, java.io.IOException {
+ java.io.File f = new java.io.File(dir, "build.xml");
+ if (f.exists()) {
+ throw new FileExistsException(f);
+ }
+ final java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
try {
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(fos,
"UTF-8");
java.io.BufferedWriter writer = new java.io.BufferedWriter(osw);
@@ -149,6 +300,4 @@
}
}
-}
-
-
+}
\ No newline at end of file
Modified:
development/laboratory/maven/magic-migrate/src/test/net/dpml/magic/maven/migrate/MigateTest.java
==============================================================================
---
development/laboratory/maven/magic-migrate/src/test/net/dpml/magic/maven/migrate/MigateTest.java
(original)
+++
development/laboratory/maven/magic-migrate/src/test/net/dpml/magic/maven/migrate/MigateTest.java
Fri Jan 7 00:24:36 2005
@@ -8,10 +8,18 @@
extends junit.framework.TestCase {
public void testMigrate() throws java.net.URISyntaxException,
org.apache.maven.MavenException, java.io.IOException {
+ final Migrate migrate = new Migrate();
final java.io.File basedir = new java.io.File(".");
+/*
final java.io.File mavenFile = new java.io.File(basedir, "project.xml");
// Create file with parent file, or NPE will be thrown.
final org.apache.maven.project.Project project =
org.apache.maven.MavenUtils.getProject(mavenFile, null, false);
- final Migrate migrate = new Migrate();
migrate.createBuilds(project, null);
+ final java.util.List list = project.getDependencies();
+ for (int i = 0; i < list.size(); i++) {
+ final org.apache.maven.project.Dependency dependency =
(org.apache.maven.project.Dependency) list.get(i);
+ System.out.println(dependency.getGroupId()+"
"+dependency.getArtifact()+" "+dependency.getVersion());
+ }
+*/
+ migrate.createBuilds(basedir);
}
-}
+}
\ No newline at end of file
- svn commit: r1397 - in development/laboratory/maven/magic-migrate: . src/main/net/dpml/magic/maven/migrate src/test/net/dpml/magic/maven/migrate, mraad23, 01/06/2005
Archive powered by MHonArc 2.6.24.