dion 2003/08/13 22:53:09
Modified: src/test/java/org/apache/maven/plugin Tag: MAVEN_RC1_STABLE
PluginManagerTest.java
src/java/org/apache/maven/plugin Tag: MAVEN_RC1_STABLE
PluginManager.java
Added: src/test/java/org/apache/maven/plugin Tag: MAVEN_RC1_STABLE
forehead.conf maven-java-plugin-1.3.jar
Log:
Add the ability for PluginManager to install plugins on the fly
Revision Changes Path
No revision
No revision
1.2.2.3 +67 -11
maven/src/test/java/org/apache/maven/plugin/Attic/PluginManagerTest.java
Index: PluginManagerTest.java
===================================================================
RCS file:
/home/cvs/maven/src/test/java/org/apache/maven/plugin/Attic/PluginManagerTest.java,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- PluginManagerTest.java 13 Aug 2003 08:53:27 -0000 1.2.2.2
+++ PluginManagerTest.java 14 Aug 2003 05:53:09 -0000 1.2.2.3
@@ -54,6 +54,8 @@
* <http://www.apache.org/>.
*/
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.MavenConstants;
@@ -62,6 +64,8 @@
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.project.Project;
+import com.werken.forehead.Forehead;
+
import junit.framework.TestCase;
/**
@@ -72,17 +76,26 @@
{
/** instance being tested */
- private PluginManager pluginManager = null;
+ private PluginManager pluginManager;
/** project to test with */
- private Project project = null;
+ private Project project;
/** directory for fake data */
private static String FAKE_BASE = "/target/PluginManagerTest/";
/** source base */
- private static String SOURCE_BASE = "/src/test/java/org/apache/maven/plugin";
+ private static String SOURCE_BASE = "/src/test/java/org/apache/maven/plugin/";
+
+ /** base directory */
+ private String basedir;
+ /** plugin to install */
+ private File pluginToInstall;
+
+ /** fake maven.home */
+ String fakeHome;
+
/**
* Constructor for PluginManagerTest.
* @param name
@@ -95,8 +108,10 @@
public void setUp() throws Exception
{
super.setUp();
- String basedir = System.getProperty("basedir");
+ basedir = System.getProperty("basedir");
assertNotNull(basedir);
+ fakeHome = basedir + SOURCE_BASE + "maven.home";
+ deleteFakeBase();
MavenJellyContext context = MavenUtils.createContext( new File(
System.getProperty("user.dir") ) );
assertNotNull(context);
// 1) need to fake out maven home, so that the unpacked plugin dir in the
test
@@ -123,20 +138,61 @@
pluginManager = mavenSession.getPluginManager();
// 2) need to fake out the maven.repo.remote so that it downloads from the
test
// directory
+ pluginToInstall = new File(basedir + SOURCE_BASE +
"maven-java-plugin-1.3.jar");
+ // fake forehead up
+ Forehead.getInstance().config(new FileInputStream(basedir + SOURCE_BASE +
"forehead.conf"));
}
+ /**
+ * Delete the fake directory
+ */
public void tearDown() throws Exception
{
- // clean up directories
- String basedir = System.getProperty("basedir");
- String fake = basedir + FAKE_BASE;
- // delete it
- FileUtils.deleteDirectory(fake);
+ // pluginManager's caching causes this to fail sometimes, so it's being
+ // done at setUp and tearDown
+ deleteFakeBase();
}
- public void testXXX()
+
+ private void deleteFakeBase()
+ {
+ try
+ {
+ // clean up directories
+ String fake = basedir + FAKE_BASE;
+ // delete it
+ FileUtils.deleteDirectory(fake);
+ String installedPlugin = fakeHome +
"/plugins/maven-java-plugin-1.3.jar";
+ new File(installedPlugin).delete();
+ }
+ catch (IOException e)
+ {
+ // ignore
+ }
+ }
+
+ /**
+ * Make sure the plugin manager has loaded the plugins from the directory
specified
+ */
+ public void testLoading() throws Exception
{
assertNotNull(pluginManager);
+ pluginManager.initialize();
+ assertTrue("clean plugin is not loaded properly",
pluginManager.getGoalNames().contains("clean"));
+ assertTrue("clean plugin is not loaded properly",
pluginManager.getGoalNames().contains("clean:clean"));
}
-
+ /**
+ * Make sure the plugin manager can install a plugin
+ */
+ public void testInstall() throws Exception
+ {
+ assertNotNull(pluginManager);
+ pluginManager.initialize();
+ File pluginToInstall = new File(basedir + SOURCE_BASE +
"maven-java-plugin-1.3.jar");
+ pluginManager.installPlugin(project, pluginToInstall);
+
+ assertTrue("java plugin is not loaded properly",
+ pluginManager.getGoalNames().contains("java:compile"));
+ }
+
}
No revision
Index: PluginManagerTest.java
===================================================================
RCS file:
/home/cvs/maven/src/test/java/org/apache/maven/plugin/Attic/PluginManagerTest.java,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- PluginManagerTest.java 13 Aug 2003 08:53:27 -0000 1.2.2.2
+++ PluginManagerTest.java 14 Aug 2003 05:53:09 -0000 1.2.2.3
@@ -54,6 +54,8 @@
* <http://www.apache.org/>.
*/
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.MavenConstants;
@@ -62,6 +64,8 @@
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.project.Project;
+import com.werken.forehead.Forehead;
+
import junit.framework.TestCase;
/**
@@ -72,17 +76,26 @@
{
/** instance being tested */
- private PluginManager pluginManager = null;
+ private PluginManager pluginManager;
/** project to test with */
- private Project project = null;
+ private Project project;
/** directory for fake data */
private static String FAKE_BASE = "/target/PluginManagerTest/";
/** source base */
- private static String SOURCE_BASE = "/src/test/java/org/apache/maven/plugin";
+ private static String SOURCE_BASE = "/src/test/java/org/apache/maven/plugin/";
+
+ /** base directory */
+ private String basedir;
+ /** plugin to install */
+ private File pluginToInstall;
+
+ /** fake maven.home */
+ String fakeHome;
+
/**
* Constructor for PluginManagerTest.
* @param name
@@ -95,8 +108,10 @@
public void setUp() throws Exception
{
super.setUp();
- String basedir = System.getProperty("basedir");
+ basedir = System.getProperty("basedir");
assertNotNull(basedir);
+ fakeHome = basedir + SOURCE_BASE + "maven.home";
+ deleteFakeBase();
MavenJellyContext context = MavenUtils.createContext( new File(
System.getProperty("user.dir") ) );
assertNotNull(context);
// 1) need to fake out maven home, so that the unpacked plugin dir in the
test
@@ -123,20 +138,61 @@
pluginManager = mavenSession.getPluginManager();
// 2) need to fake out the maven.repo.remote so that it downloads from the
test
// directory
+ pluginToInstall = new File(basedir + SOURCE_BASE +
"maven-java-plugin-1.3.jar");
+ // fake forehead up
+ Forehead.getInstance().config(new FileInputStream(basedir + SOURCE_BASE +
"forehead.conf"));
}
+ /**
+ * Delete the fake directory
+ */
public void tearDown() throws Exception
{
- // clean up directories
- String basedir = System.getProperty("basedir");
- String fake = basedir + FAKE_BASE;
- // delete it
- FileUtils.deleteDirectory(fake);
+ // pluginManager's caching causes this to fail sometimes, so it's being
+ // done at setUp and tearDown
+ deleteFakeBase();
}
- public void testXXX()
+
+ private void deleteFakeBase()
+ {
+ try
+ {
+ // clean up directories
+ String fake = basedir + FAKE_BASE;
+ // delete it
+ FileUtils.deleteDirectory(fake);
+ String installedPlugin = fakeHome +
"/plugins/maven-java-plugin-1.3.jar";
+ new File(installedPlugin).delete();
+ }
+ catch (IOException e)
+ {
+ // ignore
+ }
+ }
+
+ /**
+ * Make sure the plugin manager has loaded the plugins from the directory
specified
+ */
+ public void testLoading() throws Exception
{
assertNotNull(pluginManager);
+ pluginManager.initialize();
+ assertTrue("clean plugin is not loaded properly",
pluginManager.getGoalNames().contains("clean"));
+ assertTrue("clean plugin is not loaded properly",
pluginManager.getGoalNames().contains("clean:clean"));
}
-
+ /**
+ * Make sure the plugin manager can install a plugin
+ */
+ public void testInstall() throws Exception
+ {
+ assertNotNull(pluginManager);
+ pluginManager.initialize();
+ File pluginToInstall = new File(basedir + SOURCE_BASE +
"maven-java-plugin-1.3.jar");
+ pluginManager.installPlugin(project, pluginToInstall);
+
+ assertTrue("java plugin is not loaded properly",
+ pluginManager.getGoalNames().contains("java:compile"));
+ }
+
}
No revision
Index: PluginManagerTest.java
===================================================================
RCS file:
/home/cvs/maven/src/test/java/org/apache/maven/plugin/Attic/PluginManagerTest.java,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- PluginManagerTest.java 13 Aug 2003 08:53:27 -0000 1.2.2.2
+++ PluginManagerTest.java 14 Aug 2003 05:53:09 -0000 1.2.2.3
@@ -54,6 +54,8 @@
* <http://www.apache.org/>.
*/
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.MavenConstants;
@@ -62,6 +64,8 @@
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.project.Project;
+import com.werken.forehead.Forehead;
+
import junit.framework.TestCase;
/**
@@ -72,17 +76,26 @@
{
/** instance being tested */
- private PluginManager pluginManager = null;
+ private PluginManager pluginManager;
/** project to test with */
- private Project project = null;
+ private Project project;
/** directory for fake data */
private static String FAKE_BASE = "/target/PluginManagerTest/";
/** source base */
- private static String SOURCE_BASE = "/src/test/java/org/apache/maven/plugin";
+ private static String SOURCE_BASE = "/src/test/java/org/apache/maven/plugin/";
+
+ /** base directory */
+ private String basedir;
+ /** plugin to install */
+ private File pluginToInstall;
+
+ /** fake maven.home */
+ String fakeHome;
+
/**
* Constructor for PluginManagerTest.
* @param name
@@ -95,8 +108,10 @@
public void setUp() throws Exception
{
super.setUp();
- String basedir = System.getProperty("basedir");
+ basedir = System.getProperty("basedir");
assertNotNull(basedir);
+ fakeHome = basedir + SOURCE_BASE + "maven.home";
+ deleteFakeBase();
MavenJellyContext context = MavenUtils.createContext( new File(
System.getProperty("user.dir") ) );
assertNotNull(context);
// 1) need to fake out maven home, so that the unpacked plugin dir in the
test
@@ -123,20 +138,61 @@
pluginManager = mavenSession.getPluginManager();
// 2) need to fake out the maven.repo.remote so that it downloads from the
test
// directory
+ pluginToInstall = new File(basedir + SOURCE_BASE +
"maven-java-plugin-1.3.jar");
+ // fake forehead up
+ Forehead.getInstance().config(new FileInputStream(basedir + SOURCE_BASE +
"forehead.conf"));
}
+ /**
+ * Delete the fake directory
+ */
public void tearDown() throws Exception
{
- // clean up directories
- String basedir = System.getProperty("basedir");
- String fake = basedir + FAKE_BASE;
- // delete it
- FileUtils.deleteDirectory(fake);
+ // pluginManager's caching causes this to fail sometimes, so it's being
+ // done at setUp and tearDown
+ deleteFakeBase();
}
- public void testXXX()
+
+ private void deleteFakeBase()
+ {
+ try
+ {
+ // clean up directories
+ String fake = basedir + FAKE_BASE;
+ // delete it
+ FileUtils.deleteDirectory(fake);
+ String installedPlugin = fakeHome +
"/plugins/maven-java-plugin-1.3.jar";
+ new File(installedPlugin).delete();
+ }
+ catch (IOException e)
+ {
+ // ignore
+ }
+ }
+
+ /**
+ * Make sure the plugin manager has loaded the plugins from the directory
specified
+ */
+ public void testLoading() throws Exception
{
assertNotNull(pluginManager);
+ pluginManager.initialize();
+ assertTrue("clean plugin is not loaded properly",
pluginManager.getGoalNames().contains("clean"));
+ assertTrue("clean plugin is not loaded properly",
pluginManager.getGoalNames().contains("clean:clean"));
}
-
+ /**
+ * Make sure the plugin manager can install a plugin
+ */
+ public void testInstall() throws Exception
+ {
+ assertNotNull(pluginManager);
+ pluginManager.initialize();
+ File pluginToInstall = new File(basedir + SOURCE_BASE +
"maven-java-plugin-1.3.jar");
+ pluginManager.installPlugin(project, pluginToInstall);
+
+ assertTrue("java plugin is not loaded properly",
+ pluginManager.getGoalNames().contains("java:compile"));
+ }
+
}
1.1.2.1 +10 -0 maven/src/test/java/org/apache/maven/plugin/Attic/forehead.conf
1.1.2.1 +21 -0
maven/src/test/java/org/apache/maven/plugin/Attic/maven-java-plugin-1.3.jar
<<Binary file>>
No revision
No revision
1.45.2.4 +27 -3 maven/src/java/org/apache/maven/plugin/PluginManager.java
Index: PluginManager.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/PluginManager.java,v
retrieving revision 1.45.2.3
retrieving revision 1.45.2.4
diff -u -r1.45.2.3 -r1.45.2.4
--- PluginManager.java 11 Aug 2003 06:16:11 -0000 1.45.2.3
+++ PluginManager.java 14 Aug 2003 05:53:09 -0000 1.45.2.4
@@ -668,7 +668,7 @@
*
* @throws Exception If an error occurs while initializing the plugin.
*/
- void loadPlugin( String name, Project project )
+ public void loadPlugin( String name, Project project )
throws Exception
{
if ( isLoaded( project, name ) )
@@ -779,7 +779,7 @@
*
* @param name The plugin name.
*
- * @throws Exception If an error occurs while attempting toa analyze
+ * @throws Exception If an error occurs while attempting to analyze
* and cache plugin information.
*/
void cachePlugin( String name )
@@ -997,5 +997,29 @@
File getUnpackedPluginsDir()
{
return unpackedPluginsDir;
+ }
+
+ /**
+ * Load and install a plugin
+ * @param file
+ */
+ public void installPlugin(Project project, File file) throws Exception
+ {
+ // copy the file to the unpacked plugins dir
+ FileUtils.copyFileToDirectory(file, getPluginsDir());
+ String pluginName = file.getCanonicalFile().getName();
+ pluginName = pluginName.substring(0, pluginName.indexOf(".jar"));
+ String newFileName = getPluginsDir().getCanonicalPath()
+ + File.separator + file.getCanonicalFile().getName();
+ // expand it
+ Expand unzipper = new Expand();
+ unzipper.setSrc( new File(newFileName));
+ File unzipDir = new File( getUnpackedPluginsDir(), pluginName);
+ unzipper.setDest( unzipDir );
+ unzipper.execute();
+ // load it
+ loadPlugin(pluginName, project);
+ cachePlugin(pluginName);
+ // FIXME: Does it need caching too?
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]