directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r698455 - in /directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins: AbstractStudioMojo.java StudioCleanMojo.java StudioEclipseMojo.java
Date Wed, 24 Sep 2008 08:09:11 GMT
Author: felixk
Date: Wed Sep 24 01:09:10 2008
New Revision: 698455

URL: http://svn.apache.org/viewvc?rev=698455&view=rev
Log:
Formatting with respect to http://cwiki.apache.org/DIRxDEV/coding-standards.html.

My bad. Somehow I didn't had load the correct formatting.xml and codetemplates.xml
from the beginning of coding and then just moved straight on forward with some
custom formatting rules.

Modified:
    directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
    directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java
    directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java

Modified: directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java?rev=698455&r1=698454&r2=698455&view=diff
==============================================================================
--- directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
(original)
+++ directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
Wed Sep 24 01:09:10 2008
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.studio.maven.plugins;
 
+
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -53,504 +54,563 @@
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.Commandline;
 
+
 /**
  * The abstract studio mojo
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class AbstractStudioMojo extends AbstractMojo {
+public abstract class AbstractStudioMojo extends AbstractMojo
+{
 
-	/**
-	 * To look up Archiver/UnArchiver implementations
-	 * 
-	 * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
-	 * @required
-	 * @readonly
-	 */
-	protected ArchiverManager archiverManager;
-
-	/**
-	 * Location of the file.
-	 * 
-	 * @parameter expression="${project.build.directory}"
-	 * @required
-	 * @readonly
-	 */
-	protected String buildDirectory;
-
-	/**
-	 * Used to look up Artifacts in the remote repository.
-	 * 
-	 * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
-	 * @required
-	 * @readonly
-	 */
-	protected org.apache.maven.artifact.factory.ArtifactFactory factory;
-
-	/**
-	 * Used to look up Artifacts in the remote repository.
-	 * 
-	 * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
-	 * @required
-	 * @readonly
-	 */
-	protected org.apache.maven.artifact.resolver.ArtifactResolver resolver;
-
-	/**
-	 * Flag if execution shall be skipped. Defaults to true.
-	 * 
-	 * @parameter expression="true"
-	 * @required
-	 */
-	protected boolean skip;
-
-	/**
-	 * Relativ Path to copy libraries to. Defaults to lib
-	 * 
-	 * @parameter expression="lib"
-	 * @required
-	 * @readonly
-	 */
-	protected String libraryPath;
-
-	/**
-	 * Artifact collector, needed to resolve dependencies.
-	 * 
-	 * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
-	 * @required
-	 * @readonly
-	 */
-	protected ArtifactCollector artifactCollector;
-
-	/**
-	 * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
-	 *            hint="maven"
-	 * @required
-	 * @readonly
-	 */
-	protected ArtifactMetadataSource artifactMetadataSource;
-
-	/**
-	 * Location of the local repository.
-	 * 
-	 * @parameter expression="${localRepository}"
-	 * @readonly
-	 * @required
-	 */
-	protected org.apache.maven.artifact.repository.ArtifactRepository local;
-
-	/**
-	 * List of Remote Repositories used by the resolver
-	 * 
-	 * @parameter expression="${project.remoteArtifactRepositories}"
-	 * @readonly
-	 * @required
-	 */
-	protected List<ArtifactRepository> remoteRepos;
-
-	/**
-	 * POM
-	 * 
-	 * @parameter expression="${project}"
-	 * @readonly
-	 * @required
-	 */
-	protected MavenProject project;
-
-	/**
-	 * Output absolute filename for resolved artifacts
-	 * 
-	 * @optional
-	 * @since 2.0
-	 * @parameter expression="${outputAbsoluteArtifactFilename}"
-	 *            default-value="false"
-	 */
-	protected boolean outputAbsoluteArtifactFilename;
-
-	/**
-	 * Unpack a file to a location
-	 * 
-	 * @param location
-	 *            The location to unpack the file to
-	 * @param file
-	 *            The file to unpack
-	 */
-	protected void unpackToLocation(final File location, final File file)
-			throws Exception {
-		try {
-			getLog().info(
-					"Unpacking " + file + " to\n                 " + location);
-			location.mkdirs();
-			UnArchiver unArchiver = archiverManager.getUnArchiver(file);
-			unArchiver.setSourceFile(file);
-			unArchiver.setDestDirectory(location);
-			unArchiver.extract();
-		} catch (NoSuchArchiverException e) {
-			throw new MojoExecutionException("Unknown archiver type", e);
-		} catch (ArchiverException e) {
-			e.printStackTrace();
-			throw new MojoExecutionException("Error unpacking file: " + file
-					+ " to: " + location + "\r\n" + e.toString(), e);
-		}
-	}
-
-	/**
-	 * Pack a given location into a file
-	 * 
-	 * @param location
-	 *            A location to pack
-	 * @param file
-	 *            The file to pack the location into
-	 * @throws Exception
-	 *             If an error occurs
-	 */
-	protected void packFromLocation(final File location, final File file)
-			throws MojoExecutionException {
-		try {
-			getLog()
-					.info("Packing " + location + " to\n               " + file);
-			Archiver archiver = archiverManager.getArchiver(file);
-			archiver.setDestFile(file);
-			archiver.setIncludeEmptyDirs(true);
-			archiver.addDirectory(location);
-			archiver.createArchive();
-		} catch (NoSuchArchiverException e) {
-			throw new MojoExecutionException("Unknown archiver type", e);
-		} catch (IOException e) {
-			throw new MojoExecutionException("Error creating archive", e);
-		} catch (ArchiverException e) {
-			e.printStackTrace();
-			throw new MojoExecutionException("Error packing file: " + file
-					+ " to: " + location + "\r\n" + e.toString(), e);
-		}
-	}
-
-	/**
-	 * Fork a maven goal
-	 * 
-	 * @param goal
-	 *            the goal
-	 * @return the result
-	 * @throws MavenExecutorException
-	 * @throws CommandLineException
-	 */
-	protected int forkMvnGoal(final String goal) throws MavenExecutorException,
-			CommandLineException {
-		CommandLineFactory commandLineFactory = new DefaultCommandLineFactory();
-		Commandline cl = commandLineFactory.createCommandLine("mvn");
-
-		cl.setWorkingDirectory(project.getBasedir().getAbsolutePath());
-
-		cl.addEnvironment("MAVEN_TERMINATE_CMD", "on");
-		cl.createArg().setValue(goal);
-		cl.createArg().setValue("--no-plugin-updates");
-		cl.createArg().setValue("--batch-mode");
-		TeeOutputStream stdOut = new TeeOutputStream(System.out);
-		TeeOutputStream stdErr = new TeeOutputStream(System.err);
-		return ForkedMavenExecutor.executeCommandLine(cl, System.in, stdOut,
-				stdErr);
-
-	}
-
-	/**
-	 * Resolves the Artifact from the remote repository if nessessary. If no
-	 * version is specified, it will be retrieved from the dependency list or
-	 * from the DependencyManagement section of the pom.
-	 * 
-	 * @param artifactItem
-	 *            containing information about artifact from plugin
-	 *            configuration.
-	 * @return Artifact object representing the specified file.
-	 * 
-	 * @throws MojoExecutionException
-	 *             with a message if the version can't be found in
-	 *             DependencyManagement.
-	 */
-	protected Artifact getArtifact(ArtifactItem artifactItem)
-			throws MojoExecutionException {
-		Artifact artifact;
-
-		VersionRange vr;
-		try {
-			vr = VersionRange.createFromVersionSpec(artifactItem.getVersion());
-		} catch (InvalidVersionSpecificationException e1) {
-			e1.printStackTrace();
-			vr = VersionRange.createFromVersion(artifactItem.getVersion());
-		}
-
-		if (StringUtils.isEmpty(artifactItem.getClassifier())) {
-			artifact = factory.createDependencyArtifact(artifactItem
-					.getGroupId(), artifactItem.getArtifactId(), vr,
-					artifactItem.getType(), null, Artifact.SCOPE_COMPILE);
-		} else {
-			artifact = factory.createDependencyArtifact(artifactItem
-					.getGroupId(), artifactItem.getArtifactId(), vr,
-					artifactItem.getType(), artifactItem.getClassifier(),
-					Artifact.SCOPE_COMPILE);
-		}
-
-		try {
-			resolver.resolve(artifact, remoteRepos, local);
-		} catch (ArtifactResolutionException e) {
-			throw new MojoExecutionException("Unable to resolve artifact.", e);
-		} catch (ArtifactNotFoundException e) {
-			throw new MojoExecutionException("Unable to find artifact.", e);
-		}
-
-		return artifact;
-	}
-
-	/**
-	 * Tries to find missing version from dependancy list and dependency
-	 * management. If found, the artifact is updated with the correct version.
-	 * 
-	 * It will first look for an exact match on
-	 * artifactId/groupId/classifier/type and if it doesn't find a match, it
-	 * will try again looking for artifactId and groupId only.
-	 * 
-	 * @param artifact
-	 *            representing configured file.
-	 * @throws MojoExecutionException
-	 */
-	protected void fillMissingArtifactVersion(ArtifactItem artifact)
-			throws MojoExecutionException {
-		if (!findDependencyVersion(artifact, project.getDependencies(), false)
-				&& (project.getDependencyManagement() == null || !findDependencyVersion(
-						artifact, project.getDependencyManagement()
-								.getDependencies(), false))
-				&& !findDependencyVersion(artifact, project.getDependencies(),
-						true)
-				&& (project.getDependencyManagement() == null || !findDependencyVersion(
-						artifact, project.getDependencyManagement()
-								.getDependencies(), true))) {
-			throw new MojoExecutionException(
-					"Unable to find artifact version of "
-							+ artifact.getGroupId()
-							+ ":"
-							+ artifact.getArtifactId()
-							+ " in either dependency list or in project's dependency management.");
-		}
-	}
-
-	/**
-	 * Tries to find missing version from a list of dependencies. If found, the
-	 * artifact is updated with the correct version.
-	 * 
-	 * @param artifact
-	 *            representing configured file.
-	 * @param list
-	 *            list of dependencies to search.
-	 * @param looseMatch
-	 *            only look at artifactId and groupId
-	 * @return the found dependency
-	 */
-	protected boolean findDependencyVersion(ArtifactItem artifact,
-			List<Dependency> list, boolean looseMatch) {
-		boolean result = false;
-
-		for (int i = 0; i < list.size(); i++) {
-			Dependency dependency = list.get(i);
-			if (StringUtils.equals(dependency.getArtifactId(), artifact
-					.getArtifactId())
-					&& StringUtils.equals(dependency.getGroupId(), artifact
-							.getGroupId())
-					&& (looseMatch || StringUtils.equals(dependency
-							.getClassifier(), artifact.getClassifier()))
-					&& (looseMatch || StringUtils.equals(dependency.getType(),
-							artifact.getType()))) {
-
-				artifact.setVersion(dependency.getVersion());
-				result = true;
-				break;
-			}
-		}
-		return result;
-	}
-
-	/**
-	 * Complete the artifacts in the artifactItems list (e.g. complete with
-	 * version number)
-	 * 
-	 * @throws MojoExecutionException
-	 */
-	protected void completeArtifactItems(List<ArtifactItem> artifactItems)
-			throws MojoExecutionException {
-		try {
-			// Get and complete artifacts
-			for (Iterator<ArtifactItem> artifactItem = artifactItems.iterator(); artifactItem
-					.hasNext();) {
-				ArtifactItem item = artifactItem.next();
-				// make sure we have a version.
-				if (StringUtils.isEmpty(item.getVersion())) {
-					fillMissingArtifactVersion(item);
-				}
-				item.setArtifact(this.getArtifact(item));
-			}
-		} catch (Exception e) {
-			throw new MojoExecutionException("", e);
-		}
-	}
-
-	/**
-	 * Delete a directory
-	 * 
-	 * @param path
-	 * @return
-	 */
-	protected static boolean deleteDirectory(File path) {
-		if (path.exists() && path.isDirectory()) {
-			for (File file : path.listFiles()) {
-				if (file.isDirectory()) {
-					deleteDirectory(file);
-				} else {
-					file.delete();
-				}
-			}
-		}
-		return (path.delete());
-	}
-
-	/**
-	 * Return a list of artifacts nonscoped "provided"
-	 * 
-	 * @return
-	 */
-	protected List<Artifact> createArtifactList() {
-		List<Artifact> list = new ArrayList<Artifact>();
-
-		// Copying only artifacts with 'provided' scope
-		for (Iterator<Artifact> artifactItem = project.getArtifacts()
-				.iterator(); artifactItem.hasNext();) {
-			Artifact artifact = (Artifact) artifactItem.next();
-			if (!artifact.getScope().equalsIgnoreCase("provided")) {
-				list.add(artifact);
-			}
-		}
-
-		// Sorting list before returning it
-		Collections.sort(list, new Comparator<Artifact>() {
-			public int compare(Artifact o1, Artifact o2) {
-				String artifactId1 = o1.getArtifactId();
-				String artifactId2 = o2.getArtifactId();
-
-				if ((artifactId1 != null) && (artifactId2 != null)) {
-					return artifactId1.compareToIgnoreCase(artifactId2);
-				}
-
-				// Default
-				return o1.toString().compareToIgnoreCase(o2.toString());
-			}
-		});
-
-		return list;
-	}
-
-	/**
-	 * @return Returns the factory.
-	 */
-	public org.apache.maven.artifact.factory.ArtifactFactory getFactory() {
-		return this.factory;
-	}
-
-	/**
-	 * @param factory
-	 *            The factory to set.
-	 */
-	public void setFactory(
-			org.apache.maven.artifact.factory.ArtifactFactory factory) {
-		this.factory = factory;
-	}
-
-	/**
-	 * @return Returns the project.
-	 */
-	public MavenProject getProject() {
-		return this.project;
-	}
-
-	/**
-	 * @return Returns the local.
-	 */
-	public org.apache.maven.artifact.repository.ArtifactRepository getLocal() {
-		return this.local;
-	}
-
-	/**
-	 * @param local
-	 *            The local to set.
-	 */
-	public void setLocal(
-			org.apache.maven.artifact.repository.ArtifactRepository local) {
-		this.local = local;
-	}
-
-	/**
-	 * @return Returns the remoteRepos.
-	 */
-	public List<ArtifactRepository> getRemoteRepos() {
-		return this.remoteRepos;
-	}
-
-	/**
-	 * @param remoteRepos
-	 *            The remoteRepos to set.
-	 */
-	public void setRemoteRepos(List<ArtifactRepository> remoteRepos) {
-		this.remoteRepos = remoteRepos;
-	}
-
-	/**
-	 * @return Returns the resolver.
-	 */
-	public org.apache.maven.artifact.resolver.ArtifactResolver getResolver() {
-		return this.resolver;
-	}
-
-	/**
-	 * @param resolver
-	 *            The resolver to set.
-	 */
-	public void setResolver(
-			org.apache.maven.artifact.resolver.ArtifactResolver resolver) {
-		this.resolver = resolver;
-	}
-
-	/**
-	 * @return Returns the artifactCollector.
-	 */
-	public ArtifactCollector getArtifactCollector() {
-		return this.artifactCollector;
-	}
-
-	/**
-	 * @param theArtifactCollector
-	 *            The artifactCollector to set.
-	 */
-	public void setArtifactCollector(ArtifactCollector theArtifactCollector) {
-		this.artifactCollector = theArtifactCollector;
-	}
-
-	/**
-	 * @return Returns the artifactMetadataSource.
-	 */
-	public ArtifactMetadataSource getArtifactMetadataSource() {
-		return this.artifactMetadataSource;
-	}
-
-	/**
-	 * @param theArtifactMetadataSource
-	 *            The artifactMetadataSource to set.
-	 */
-	public void setArtifactMetadataSource(
-			ArtifactMetadataSource theArtifactMetadataSource) {
-		this.artifactMetadataSource = theArtifactMetadataSource;
-	}
-
-	/**
-	 * @param libraryPath
-	 *            the libraryPath to set
-	 */
-	public void setLibraryPath(String pLibraryPath) {
-		this.libraryPath = pLibraryPath;
-	}
+    /**
+     * To look up Archiver/UnArchiver implementations
+     * 
+     * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
+     * @required
+     * @readonly
+     */
+    protected ArchiverManager archiverManager;
+
+    /**
+     * Location of the file.
+     * 
+     * @parameter expression="${project.build.directory}"
+     * @required
+     * @readonly
+     */
+    protected String buildDirectory;
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     * 
+     * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+     * @required
+     * @readonly
+     */
+    protected org.apache.maven.artifact.factory.ArtifactFactory factory;
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     * 
+     * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+     * @required
+     * @readonly
+     */
+    protected org.apache.maven.artifact.resolver.ArtifactResolver resolver;
+
+    /**
+     * Flag if execution shall be skipped. Defaults to true.
+     * 
+     * @parameter expression="true"
+     * @required
+     */
+    protected boolean skip;
+
+    /**
+     * Relativ Path to copy libraries to. Defaults to lib
+     * 
+     * @parameter expression="lib"
+     * @required
+     * @readonly
+     */
+    protected String libraryPath;
+
+    /**
+     * Artifact collector, needed to resolve dependencies.
+     * 
+     * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
+     * @required
+     * @readonly
+     */
+    protected ArtifactCollector artifactCollector;
+
+    /**
+     * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
+     *            hint="maven"
+     * @required
+     * @readonly
+     */
+    protected ArtifactMetadataSource artifactMetadataSource;
+
+    /**
+     * Location of the local repository.
+     * 
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     */
+    protected org.apache.maven.artifact.repository.ArtifactRepository local;
+
+    /**
+     * List of Remote Repositories used by the resolver
+     * 
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     * @readonly
+     * @required
+     */
+    protected List<ArtifactRepository> remoteRepos;
+
+    /**
+     * POM
+     * 
+     * @parameter expression="${project}"
+     * @readonly
+     * @required
+     */
+    protected MavenProject project;
+
+    /**
+     * Output absolute filename for resolved artifacts
+     * 
+     * @optional
+     * @since 2.0
+     * @parameter expression="${outputAbsoluteArtifactFilename}"
+     *            default-value="false"
+     */
+    protected boolean outputAbsoluteArtifactFilename;
+
+
+    /**
+     * Unpack a file to a location
+     * 
+     * @param location
+     *            The location to unpack the file to
+     * @param file
+     *            The file to unpack
+     */
+    protected void unpackToLocation( final File location, final File file ) throws Exception
+    {
+        try
+        {
+            getLog().info( "Unpacking " + file + " to\n                 " + location );
+            location.mkdirs();
+            UnArchiver unArchiver = archiverManager.getUnArchiver( file );
+            unArchiver.setSourceFile( file );
+            unArchiver.setDestDirectory( location );
+            unArchiver.extract();
+        }
+        catch ( NoSuchArchiverException e )
+        {
+            throw new MojoExecutionException( "Unknown archiver type", e );
+        }
+        catch ( ArchiverException e )
+        {
+            e.printStackTrace();
+            throw new MojoExecutionException( "Error unpacking file: " + file + " to: " +
location + "\r\n"
+                + e.toString(), e );
+        }
+    }
+
+
+    /**
+     * Pack a given location into a file
+     * 
+     * @param location
+     *            A location to pack
+     * @param file
+     *            The file to pack the location into
+     * @throws Exception
+     *             If an error occurs
+     */
+    protected void packFromLocation( final File location, final File file ) throws MojoExecutionException
+    {
+        try
+        {
+            getLog().info( "Packing " + location + " to\n               " + file );
+            Archiver archiver = archiverManager.getArchiver( file );
+            archiver.setDestFile( file );
+            archiver.setIncludeEmptyDirs( true );
+            archiver.addDirectory( location );
+            archiver.createArchive();
+        }
+        catch ( NoSuchArchiverException e )
+        {
+            throw new MojoExecutionException( "Unknown archiver type", e );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error creating archive", e );
+        }
+        catch ( ArchiverException e )
+        {
+            e.printStackTrace();
+            throw new MojoExecutionException( "Error packing file: " + file + " to: " + location
+ "\r\n"
+                + e.toString(), e );
+        }
+    }
+
+
+    /**
+     * Fork a maven goal
+     * 
+     * @param goal
+     *            the goal
+     * @return the result
+     * @throws MavenExecutorException
+     * @throws CommandLineException
+     */
+    protected int forkMvnGoal( final String goal ) throws MavenExecutorException, CommandLineException
+    {
+        CommandLineFactory commandLineFactory = new DefaultCommandLineFactory();
+        Commandline cl = commandLineFactory.createCommandLine( "mvn" );
+
+        cl.setWorkingDirectory( project.getBasedir().getAbsolutePath() );
+
+        cl.addEnvironment( "MAVEN_TERMINATE_CMD", "on" );
+        cl.createArg().setValue( goal );
+        cl.createArg().setValue( "--no-plugin-updates" );
+        cl.createArg().setValue( "--batch-mode" );
+        TeeOutputStream stdOut = new TeeOutputStream( System.out );
+        TeeOutputStream stdErr = new TeeOutputStream( System.err );
+        return ForkedMavenExecutor.executeCommandLine( cl, System.in, stdOut, stdErr );
+
+    }
+
+
+    /**
+     * Resolves the Artifact from the remote repository if nessessary. If no
+     * version is specified, it will be retrieved from the dependency list or
+     * from the DependencyManagement section of the pom.
+     * 
+     * @param artifactItem
+     *            containing information about artifact from plugin
+     *            configuration.
+     * @return Artifact object representing the specified file.
+     * 
+     * @throws MojoExecutionException
+     *             with a message if the version can't be found in
+     *             DependencyManagement.
+     */
+    protected Artifact getArtifact( ArtifactItem artifactItem ) throws MojoExecutionException
+    {
+        Artifact artifact;
+
+        VersionRange vr;
+        try
+        {
+            vr = VersionRange.createFromVersionSpec( artifactItem.getVersion() );
+        }
+        catch ( InvalidVersionSpecificationException e1 )
+        {
+            e1.printStackTrace();
+            vr = VersionRange.createFromVersion( artifactItem.getVersion() );
+        }
+
+        if ( StringUtils.isEmpty( artifactItem.getClassifier() ) )
+        {
+            artifact = factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(),
vr,
+                artifactItem.getType(), null, Artifact.SCOPE_COMPILE );
+        }
+        else
+        {
+            artifact = factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(),
vr,
+                artifactItem.getType(), artifactItem.getClassifier(), Artifact.SCOPE_COMPILE
);
+        }
+
+        try
+        {
+            resolver.resolve( artifact, remoteRepos, local );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new MojoExecutionException( "Unable to resolve artifact.", e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new MojoExecutionException( "Unable to find artifact.", e );
+        }
+
+        return artifact;
+    }
+
+
+    /**
+     * Tries to find missing version from dependancy list and dependency
+     * management. If found, the artifact is updated with the correct version.
+     * 
+     * It will first look for an exact match on
+     * artifactId/groupId/classifier/type and if it doesn't find a match, it
+     * will try again looking for artifactId and groupId only.
+     * 
+     * @param artifact
+     *            representing configured file.
+     * @throws MojoExecutionException
+     */
+    protected void fillMissingArtifactVersion( ArtifactItem artifact ) throws MojoExecutionException
+    {
+        if ( !findDependencyVersion( artifact, project.getDependencies(), false )
+            && ( project.getDependencyManagement() == null || !findDependencyVersion(
artifact, project
+                .getDependencyManagement().getDependencies(), false ) )
+            && !findDependencyVersion( artifact, project.getDependencies(), true
)
+            && ( project.getDependencyManagement() == null || !findDependencyVersion(
artifact, project
+                .getDependencyManagement().getDependencies(), true ) ) )
+        {
+            throw new MojoExecutionException( "Unable to find artifact version of " + artifact.getGroupId()
+ ":"
+                + artifact.getArtifactId() + " in either dependency list or in project's
dependency management." );
+        }
+    }
+
+
+    /**
+     * Tries to find missing version from a list of dependencies. If found, the
+     * artifact is updated with the correct version.
+     * 
+     * @param artifact
+     *            representing configured file.
+     * @param list
+     *            list of dependencies to search.
+     * @param looseMatch
+     *            only look at artifactId and groupId
+     * @return the found dependency
+     */
+    protected boolean findDependencyVersion( ArtifactItem artifact, List<Dependency>
list, boolean looseMatch )
+    {
+        boolean result = false;
+
+        for ( int i = 0; i < list.size(); i++ )
+        {
+            Dependency dependency = list.get( i );
+            if ( StringUtils.equals( dependency.getArtifactId(), artifact.getArtifactId()
)
+                && StringUtils.equals( dependency.getGroupId(), artifact.getGroupId()
)
+                && ( looseMatch || StringUtils.equals( dependency.getClassifier(),
artifact.getClassifier() ) )
+                && ( looseMatch || StringUtils.equals( dependency.getType(), artifact.getType()
) ) )
+            {
+
+                artifact.setVersion( dependency.getVersion() );
+                result = true;
+                break;
+            }
+        }
+        return result;
+    }
+
+
+    /**
+     * Complete the artifacts in the artifactItems list (e.g. complete with
+     * version number)
+     * 
+     * @throws MojoExecutionException
+     */
+    protected void completeArtifactItems( List<ArtifactItem> artifactItems ) throws
MojoExecutionException
+    {
+        try
+        {
+            // Get and complete artifacts
+            for ( Iterator<ArtifactItem> artifactItem = artifactItems.iterator(); artifactItem.hasNext();
)
+            {
+                ArtifactItem item = artifactItem.next();
+                // make sure we have a version.
+                if ( StringUtils.isEmpty( item.getVersion() ) )
+                {
+                    fillMissingArtifactVersion( item );
+                }
+                item.setArtifact( this.getArtifact( item ) );
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "", e );
+        }
+    }
+
+
+    /**
+     * Delete a directory
+     * 
+     * @param path
+     * @return
+     */
+    protected static boolean deleteDirectory( File path )
+    {
+        if ( path.exists() && path.isDirectory() )
+        {
+            for ( File file : path.listFiles() )
+            {
+                if ( file.isDirectory() )
+                {
+                    deleteDirectory( file );
+                }
+                else
+                {
+                    file.delete();
+                }
+            }
+        }
+        return ( path.delete() );
+    }
+
+
+    /**
+     * Return a list of artifacts nonscoped "provided"
+     * 
+     * @return
+     */
+    protected List<Artifact> createArtifactList()
+    {
+        List<Artifact> list = new ArrayList<Artifact>();
+
+        // Copying only artifacts with 'provided' scope
+        for ( Iterator<Artifact> artifactItem = project.getArtifacts().iterator();
artifactItem.hasNext(); )
+        {
+            Artifact artifact = ( Artifact ) artifactItem.next();
+            if ( !artifact.getScope().equalsIgnoreCase( "provided" ) )
+            {
+                list.add( artifact );
+            }
+        }
+
+        // Sorting list before returning it
+        Collections.sort( list, new Comparator<Artifact>()
+        {
+            public int compare( Artifact o1, Artifact o2 )
+            {
+                String artifactId1 = o1.getArtifactId();
+                String artifactId2 = o2.getArtifactId();
+
+                if ( ( artifactId1 != null ) && ( artifactId2 != null ) )
+                {
+                    return artifactId1.compareToIgnoreCase( artifactId2 );
+                }
+
+                // Default
+                return o1.toString().compareToIgnoreCase( o2.toString() );
+            }
+        } );
+
+        return list;
+    }
+
+
+    /**
+     * @return Returns the factory.
+     */
+    public org.apache.maven.artifact.factory.ArtifactFactory getFactory()
+    {
+        return this.factory;
+    }
+
+
+    /**
+     * @param factory
+     *            The factory to set.
+     */
+    public void setFactory( org.apache.maven.artifact.factory.ArtifactFactory factory )
+    {
+        this.factory = factory;
+    }
+
+
+    /**
+     * @return Returns the project.
+     */
+    public MavenProject getProject()
+    {
+        return this.project;
+    }
+
+
+    /**
+     * @return Returns the local.
+     */
+    public org.apache.maven.artifact.repository.ArtifactRepository getLocal()
+    {
+        return this.local;
+    }
+
+
+    /**
+     * @param local
+     *            The local to set.
+     */
+    public void setLocal( org.apache.maven.artifact.repository.ArtifactRepository local )
+    {
+        this.local = local;
+    }
+
+
+    /**
+     * @return Returns the remoteRepos.
+     */
+    public List<ArtifactRepository> getRemoteRepos()
+    {
+        return this.remoteRepos;
+    }
+
+
+    /**
+     * @param remoteRepos
+     *            The remoteRepos to set.
+     */
+    public void setRemoteRepos( List<ArtifactRepository> remoteRepos )
+    {
+        this.remoteRepos = remoteRepos;
+    }
+
+
+    /**
+     * @return Returns the resolver.
+     */
+    public org.apache.maven.artifact.resolver.ArtifactResolver getResolver()
+    {
+        return this.resolver;
+    }
+
+
+    /**
+     * @param resolver
+     *            The resolver to set.
+     */
+    public void setResolver( org.apache.maven.artifact.resolver.ArtifactResolver resolver
)
+    {
+        this.resolver = resolver;
+    }
+
+
+    /**
+     * @return Returns the artifactCollector.
+     */
+    public ArtifactCollector getArtifactCollector()
+    {
+        return this.artifactCollector;
+    }
+
+
+    /**
+     * @param theArtifactCollector
+     *            The artifactCollector to set.
+     */
+    public void setArtifactCollector( ArtifactCollector theArtifactCollector )
+    {
+        this.artifactCollector = theArtifactCollector;
+    }
+
+
+    /**
+     * @return Returns the artifactMetadataSource.
+     */
+    public ArtifactMetadataSource getArtifactMetadataSource()
+    {
+        return this.artifactMetadataSource;
+    }
+
+
+    /**
+     * @param theArtifactMetadataSource
+     *            The artifactMetadataSource to set.
+     */
+    public void setArtifactMetadataSource( ArtifactMetadataSource theArtifactMetadataSource
)
+    {
+        this.artifactMetadataSource = theArtifactMetadataSource;
+    }
+
+
+    /**
+     * @param libraryPath
+     *            the libraryPath to set
+     */
+    public void setLibraryPath( String pLibraryPath )
+    {
+        this.libraryPath = pLibraryPath;
+    }
 }
\ No newline at end of file

Modified: directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java?rev=698455&r1=698454&r2=698455&view=diff
==============================================================================
--- directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java
(original)
+++ directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java
Wed Sep 24 01:09:10 2008
@@ -19,10 +19,12 @@
  */
 package org.apache.directory.studio.maven.plugins;
 
+
 import java.io.File;
 
 import org.apache.maven.plugin.MojoExecutionException;
 
+
 /**
  * Clean stuff generated by studio:eclipse
  * 
@@ -33,32 +35,42 @@
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StudioCleanMojo extends AbstractStudioMojo {
+public class StudioCleanMojo extends AbstractStudioMojo
+{
 
-	private final String MAVEN_ECLIPSE_XML = "maven-eclipse.xml";
-	private final String EXTERNAL_TOOL_BUILDERS_DIR = ".externalToolBuilders";
+    private final String MAVEN_ECLIPSE_XML = "maven-eclipse.xml";
+    private final String EXTERNAL_TOOL_BUILDERS_DIR = ".externalToolBuilders";
 
-	public void execute() throws MojoExecutionException {
 
-		if (project.isExecutionRoot()) {
-			try {
-				forkMvnGoal("eclipse:clean");
-			} catch (Exception e) {
-				throw new MojoExecutionException(e.getMessage());
-			}
-		}
-		try {
-			File file = new File(project.getBasedir(), MAVEN_ECLIPSE_XML);
-			getLog().info("Deleting " + file);
-			file.delete();
-			file = new File(project.getBasedir(), EXTERNAL_TOOL_BUILDERS_DIR);
-			getLog().info("Deleting " + file);
-			deleteDirectory(file);
-			file = new File(project.getBasedir(), libraryPath);
-			getLog().info("Deleting " + file);
-			deleteDirectory(file);
-		} catch (Exception e) {
-			getLog().error(e);
-		}
-	}
+    public void execute() throws MojoExecutionException
+    {
+
+        if ( project.isExecutionRoot() )
+        {
+            try
+            {
+                forkMvnGoal( "eclipse:clean" );
+            }
+            catch ( Exception e )
+            {
+                throw new MojoExecutionException( e.getMessage() );
+            }
+        }
+        try
+        {
+            File file = new File( project.getBasedir(), MAVEN_ECLIPSE_XML );
+            getLog().info( "Deleting " + file );
+            file.delete();
+            file = new File( project.getBasedir(), EXTERNAL_TOOL_BUILDERS_DIR );
+            getLog().info( "Deleting " + file );
+            deleteDirectory( file );
+            file = new File( project.getBasedir(), libraryPath );
+            getLog().info( "Deleting " + file );
+            deleteDirectory( file );
+        }
+        catch ( Exception e )
+        {
+            getLog().error( e );
+        }
+    }
 }

Modified: directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java?rev=698455&r1=698454&r2=698455&view=diff
==============================================================================
--- directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java
(original)
+++ directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java
Wed Sep 24 01:09:10 2008
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.studio.maven.plugins;
 
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -38,6 +39,7 @@
 import org.codehaus.plexus.util.xml.Xpp3DomWriter;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
+
 /**
  * Prepares for eclipse:
  * <p>
@@ -59,202 +61,230 @@
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class StudioEclipseMojo extends AbstractStudioMojo {
+public class StudioEclipseMojo extends AbstractStudioMojo
+{
 
-	/**
-	 * Bundle-ClassPath: updated with the list of dependencies.
-	 */
-	public final static String ENTRY_BUNDLE_CLASSPATH = "Bundle-ClassPath:";
-
-	/**
-	 * Bundle symbolic name: updated with the artifact id.
-	 */
-	public final static String ENTRY_BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName:";
-
-	/**
-	 * Bundle version: updated with the project version.
-	 */
-	public final static String ENTRY_BUNDLE_VERSION = "Bundle-Version:";
-
-	public void execute() throws MojoExecutionException {
-		if (project.isExecutionRoot()) {
-			try {
-				forkMvnGoal( "eclipse:eclipse" );
-			} catch (Exception e) {
-				throw new MojoExecutionException(e.getMessage());
-			}
-		}
-		if (!skip) {
-			try {
-				// Create list of used artifacts
-				final List<Artifact> artifactList = createArtifactList();
-
-				// copy Artifacts
-				copyArtifacts(artifactList);
-				
-				if (project.isExecutionRoot()) {
-			try {
-				forkMvnGoal( "bundle:manifest" );
-			} catch (Exception e) {
-				throw new MojoExecutionException(e.getMessage());
-			}
-		}
-
-				// Update .classpath
-				updateDotClasspath(artifactList);
-
-				updateDotProject();
-				removeMavenEclipseXml();
-				removeDotExternalToolBuilders();
-
-			} catch (FileNotFoundException e) {
-				getLog()
-						.error(
-								"Please run eclipse:eclipse first to create .classpath, e.g. mvn eclipse:eclipse
studio:eclipse.",
-								e);
-			} catch (Exception e) {
-				getLog().error(e);
-			}
-		}
-	}
-
-	/**
-	 * Copy artifacts to ${basedir}/lib
-	 * 
-	 * @param list
-	 * @throws IOException
-	 */
-	private void copyArtifacts(final List<Artifact> list) throws IOException {
-		// Only proceed when we have artifacts to process
-		if (!list.isEmpty()) {
-			final File copyDir = new File(project.getBasedir(), libraryPath);
-
-			if (!copyDir.exists())
-				copyDir.mkdirs();
-
-			for (Artifact artifact : list) {
-				if (!artifact.getScope().equalsIgnoreCase("test")) {
-					final File destFile = new File(copyDir, artifact.getFile()
-							.getName());
-					FileUtils.copyFile(artifact.getFile(), destFile);
-					getLog()
-							.info(
-									"Copying " + artifact.getFile() + " to "
-											+ destFile);
-				}
-			}
-		}
-	}
-
-	/**
-	 * Adapt the ${basedir}/.classpath
-	 * 
-	 * @param list
-	 */
-	private void updateDotClasspath(List<Artifact> list) throws IOException,
-			XmlPullParserException {
-		getLog().info("Update .classpath in " + project.getBasedir());
-		final InputStream is = new FileInputStream(new File(project
-				.getBasedir(), ".classpath"));
-		Xpp3Dom dom = Xpp3DomBuilder.build(is, "UTF-8");
-		int cnt = 0;
-		for (Xpp3Dom cpEntry : dom.getChildren("classpathentry")) {
-			if (cpEntry.getAttribute("kind").equals("lib")) {
-				dom.removeChild(cnt);
-				cnt--;
-			}
-			cnt++;
-		}
-
-		Xpp3Dom entry;
-		for (Artifact artifact : list) {
-			if (artifact.getScope().equalsIgnoreCase("test")) {
-				entry = new Xpp3Dom("classpathentry");
-				entry.setAttribute("kind", "lib");
-				entry.setAttribute("path", (new StringBuilder()).append(
-						libraryPath).append('/').append(
-						artifact.getFile().getName()).toString());
-			} else {
-				entry = new Xpp3Dom("classpathentry");
-				entry.setAttribute("exported", "true");
-				entry.setAttribute("kind", "lib");
-				entry.setAttribute("path", (new StringBuilder()).append(
-						libraryPath).append('/').append(
-						artifact.getFile().getName()).toString());
-			}
-			dom.addChild(entry);
-		}
-
-		is.close();
-		Writer w = new OutputStreamWriter(new FileOutputStream(new File(project
-				.getBasedir(), ".classpath")), "UTF-8");
-		org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter(
-				w);
-		Xpp3DomWriter.write(writer, dom);
-		w.flush();
-		w.close();
-	}
-
-	/**
-	 * Adapt the ${basedir}/.project
-	 * 
-	 * @param list
-	 */
-	private void updateDotProject() throws IOException, XmlPullParserException {
-		getLog().info("Update .project in " + project.getBasedir());
-		InputStream is = new FileInputStream(new File(project.getBasedir(),
-				".project"));
-		Xpp3Dom dom = Xpp3DomBuilder.build(is, "UTF-8");
-		int cnt = 0;
-		for (Xpp3Dom cpEntry : dom.getChild("buildSpec").getChildren(
-				"buildCommand")) {
-			if (cpEntry.getChild("name").getValue().equals(
-					"org.eclipse.ui.externaltools.ExternalToolBuilder")) {
-				dom.getChild("buildSpec").removeChild(cnt);
-				cnt--;
-			}
-			cnt++;
-		}
-
-		removeChildFromDom(dom, "linkedResources");
-		removeChildFromDom(dom, "projects");
-
-		is.close();
-		Writer w = new OutputStreamWriter(new FileOutputStream(new File(project
-				.getBasedir(), ".project")), "UTF-8");
-		org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter(
-				w);
-		Xpp3DomWriter.write(writer, dom);
-		w.flush();
-		w.close();
-	}
-
-	/**
-	 * remove ${basedir}/maven-eclipse.xml
-	 */
-	void removeMavenEclipseXml() {
-		File file = new File(project.getBasedir(), "maven-eclipse.xml");
-		if (file.exists())
-			file.delete();
-	}
-
-	/**
-	 * Adapt the ${basedir}/.externalToolBuilders
-	 */
-	void removeDotExternalToolBuilders() {
-		File file = new File(project.getBasedir(), ".externalToolBuilders");
-		if (file.exists())
-			deleteDirectory(file);
-	}
-
-	private void removeChildFromDom(Xpp3Dom dom, String childName) {
-		int cnt = 0;
-		for (Xpp3Dom child : dom.getChildren()) {
-			if (child.getName().equals(childName)) {
-				dom.removeChild(cnt);
-				cnt -= 1;
-			}
-			cnt += 1;
-		}
-	}
+    /**
+     * Bundle-ClassPath: updated with the list of dependencies.
+     */
+    public final static String ENTRY_BUNDLE_CLASSPATH = "Bundle-ClassPath:";
+
+    /**
+     * Bundle symbolic name: updated with the artifact id.
+     */
+    public final static String ENTRY_BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName:";
+
+    /**
+     * Bundle version: updated with the project version.
+     */
+    public final static String ENTRY_BUNDLE_VERSION = "Bundle-Version:";
+
+
+    public void execute() throws MojoExecutionException
+    {
+        if ( project.isExecutionRoot() )
+        {
+            try
+            {
+                forkMvnGoal( "eclipse:eclipse" );
+            }
+            catch ( Exception e )
+            {
+                throw new MojoExecutionException( e.getMessage() );
+            }
+        }
+        if ( !skip )
+        {
+            try
+            {
+                // Create list of used artifacts
+                final List<Artifact> artifactList = createArtifactList();
+
+                // copy Artifacts
+                copyArtifacts( artifactList );
+
+                if ( project.isExecutionRoot() )
+                {
+                    try
+                    {
+                        forkMvnGoal( "bundle:manifest" );
+                    }
+                    catch ( Exception e )
+                    {
+                        throw new MojoExecutionException( e.getMessage() );
+                    }
+                }
+
+                // Update .classpath
+                updateDotClasspath( artifactList );
+
+                updateDotProject();
+                removeMavenEclipseXml();
+                removeDotExternalToolBuilders();
+
+            }
+            catch ( FileNotFoundException e )
+            {
+                getLog().error(
+                    "Please run eclipse:eclipse first to create .classpath, e.g. mvn eclipse:eclipse
studio:eclipse.",
+                    e );
+            }
+            catch ( Exception e )
+            {
+                getLog().error( e );
+            }
+        }
+    }
+
+
+    /**
+     * Copy artifacts to ${basedir}/lib
+     * 
+     * @param list
+     * @throws IOException
+     */
+    private void copyArtifacts( final List<Artifact> list ) throws IOException
+    {
+        // Only proceed when we have artifacts to process
+        if ( !list.isEmpty() )
+        {
+            final File copyDir = new File( project.getBasedir(), libraryPath );
+
+            if ( !copyDir.exists() )
+                copyDir.mkdirs();
+
+            for ( Artifact artifact : list )
+            {
+                if ( !artifact.getScope().equalsIgnoreCase( "test" ) )
+                {
+                    final File destFile = new File( copyDir, artifact.getFile().getName()
);
+                    FileUtils.copyFile( artifact.getFile(), destFile );
+                    getLog().info( "Copying " + artifact.getFile() + " to " + destFile );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Adapt the ${basedir}/.classpath
+     * 
+     * @param list
+     */
+    private void updateDotClasspath( List<Artifact> list ) throws IOException, XmlPullParserException
+    {
+        getLog().info( "Update .classpath in " + project.getBasedir() );
+        final InputStream is = new FileInputStream( new File( project.getBasedir(), ".classpath"
) );
+        Xpp3Dom dom = Xpp3DomBuilder.build( is, "UTF-8" );
+        int cnt = 0;
+        for ( Xpp3Dom cpEntry : dom.getChildren( "classpathentry" ) )
+        {
+            if ( cpEntry.getAttribute( "kind" ).equals( "lib" ) )
+            {
+                dom.removeChild( cnt );
+                cnt--;
+            }
+            cnt++;
+        }
+
+        Xpp3Dom entry;
+        for ( Artifact artifact : list )
+        {
+            if ( artifact.getScope().equalsIgnoreCase( "test" ) )
+            {
+                entry = new Xpp3Dom( "classpathentry" );
+                entry.setAttribute( "kind", "lib" );
+                entry.setAttribute( "path", ( new StringBuilder() ).append( libraryPath ).append(
'/' ).append(
+                    artifact.getFile().getName() ).toString() );
+            }
+            else
+            {
+                entry = new Xpp3Dom( "classpathentry" );
+                entry.setAttribute( "exported", "true" );
+                entry.setAttribute( "kind", "lib" );
+                entry.setAttribute( "path", ( new StringBuilder() ).append( libraryPath ).append(
'/' ).append(
+                    artifact.getFile().getName() ).toString() );
+            }
+            dom.addChild( entry );
+        }
+
+        is.close();
+        Writer w = new OutputStreamWriter( new FileOutputStream( new File( project.getBasedir(),
".classpath" ) ),
+            "UTF-8" );
+        org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter( w );
+        Xpp3DomWriter.write( writer, dom );
+        w.flush();
+        w.close();
+    }
+
+
+    /**
+     * Adapt the ${basedir}/.project
+     * 
+     * @param list
+     */
+    private void updateDotProject() throws IOException, XmlPullParserException
+    {
+        getLog().info( "Update .project in " + project.getBasedir() );
+        InputStream is = new FileInputStream( new File( project.getBasedir(), ".project"
) );
+        Xpp3Dom dom = Xpp3DomBuilder.build( is, "UTF-8" );
+        int cnt = 0;
+        for ( Xpp3Dom cpEntry : dom.getChild( "buildSpec" ).getChildren( "buildCommand" )
)
+        {
+            if ( cpEntry.getChild( "name" ).getValue().equals( "org.eclipse.ui.externaltools.ExternalToolBuilder"
) )
+            {
+                dom.getChild( "buildSpec" ).removeChild( cnt );
+                cnt--;
+            }
+            cnt++;
+        }
+
+        removeChildFromDom( dom, "linkedResources" );
+        removeChildFromDom( dom, "projects" );
+
+        is.close();
+        Writer w = new OutputStreamWriter( new FileOutputStream( new File( project.getBasedir(),
".project" ) ),
+            "UTF-8" );
+        org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter( w );
+        Xpp3DomWriter.write( writer, dom );
+        w.flush();
+        w.close();
+    }
+
+
+    /**
+     * remove ${basedir}/maven-eclipse.xml
+     */
+    void removeMavenEclipseXml()
+    {
+        File file = new File( project.getBasedir(), "maven-eclipse.xml" );
+        if ( file.exists() )
+            file.delete();
+    }
+
+
+    /**
+     * Adapt the ${basedir}/.externalToolBuilders
+     */
+    void removeDotExternalToolBuilders()
+    {
+        File file = new File( project.getBasedir(), ".externalToolBuilders" );
+        if ( file.exists() )
+            deleteDirectory( file );
+    }
+
+
+    private void removeChildFromDom( Xpp3Dom dom, String childName )
+    {
+        int cnt = 0;
+        for ( Xpp3Dom child : dom.getChildren() )
+        {
+            if ( child.getName().equals( childName ) )
+            {
+                dom.removeChild( cnt );
+                cnt -= 1;
+            }
+            cnt += 1;
+        }
+    }
 }



Mime
View raw message