From 6b229cd09abed09b4b1987a42ea9035ed181d5ea Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 12 Sep 2005 05:32:22 +0000 Subject: [PATCH] PR: MNG-824 Submitted by: Edwin Punzalan Reviewed by: Brett Porter add goals that are in the m1 version git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280260 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/eclipse/AddMavenRepoMojo.java | 78 +++++++++++++++++++ .../plugin/eclipse/EclipseCleanMojo.java | 65 ++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java create mode 100644 maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java diff --git a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java new file mode 100644 index 0000000000..45428630b2 --- /dev/null +++ b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java @@ -0,0 +1,78 @@ +package org.apache.maven.plugin.eclipse; + +/* + * Copyright 2001-2005 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. + */ + + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +/** + * A Maven2 plugin to ensure that the classpath variable MAVEN_REPO exists in the Eclipse environment. + * + * @goal add-maven-repo + */ +public class AddMavenRepoMojo extends AbstractMojo +{ + /** + * Location of the Eclipse workspace that holds your configuration and source. + * + * On Windows, this will be the workspace directory under your eclipse + * installation. For example, if you installed eclipse into c:\eclipse, the + * workspace is c:\eclipse\workspace. + * + * @parameter + * @required + */ + private String workspace; + + /** + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + public void execute() throws MojoExecutionException + { + workspace += "X"; + + File workDir = new File( workspace, ".metadata/.plugins/org.eclipse.core.runtime/.settings" ); + + workDir.mkdirs(); + + File f = new File( workDir.getAbsolutePath(), "org.eclipse.jdt.core.prefs" ); + + try + { + FileWriter fWriter = new FileWriter( f ); + + fWriter.write( "\norg.eclipse.jdt.core.classpathVariable.MAVEN_REPO=" + localRepository.getBasedir() ); + + fWriter.flush(); + + fWriter.close(); + } + catch( IOException ioe ) + { + throw new MojoExecutionException( "Unable to write to file: " + f.getAbsolutePath() ); + } + } +} diff --git a/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java new file mode 100644 index 0000000000..55d98997ca --- /dev/null +++ b/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java @@ -0,0 +1,65 @@ +package org.apache.maven.plugin.eclipse; + +/* + * Copyright 2001-2005 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. + */ + + +import java.io.File; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + + +/** + * A Maven2 plugin to delete the .project and .classpath files needed for Eclipse + * + * @goal clean + */ +public class EclipseCleanMojo extends AbstractMojo +{ + /** + * @parameter expression="${project.basedir}" + */ + private String basedir; + + public void execute() throws MojoExecutionException + { + File f = new File( basedir, ".project" ); + + getLog().info( "Deleting project file..." ); + if ( f.exists() ) + { + if ( !f.delete() ) + { + throw new MojoExecutionException( "Failed to delete project file: " + f.getAbsolutePath() ); + } + } + else + getLog().info( "No .project file found." ); + + f = new File( basedir, ".classpath" ); + + getLog().info( "Deleting classpath file..." ); + if ( f.exists() ) + { + if ( !f.delete() ) + { + throw new MojoExecutionException( "Failed to delete classpath file: " + f.getAbsolutePath() ); + } + } + else + getLog().info( "No .classpath file found." ); + } +}