Author: jmcconnell Date: Thu Jul 12 14:06:32 2007 New Revision: 555766 URL: http://svn.apache.org/viewvc?view=rev&rev=555766 Log: [MSANDBOX-28] added new goals and a bit of cleanup, submitted by eredmond
Added: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterMojo.java maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterScmMojo.java maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Coordinate.java maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Parent.java Modified: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractMultipleAlterationMojo.java maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractSingleAlterationMojo.java maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterParentMojo.java maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Dependency.java Modified: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractMultipleAlterationMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractMultipleAlterationMojo.java?view=diff&rev=555766&r1=555765&r2=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractMultipleAlterationMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractMultipleAlterationMojo.java Thu Jul 12 14:06:32 2007 @@ -46,7 +46,7 @@ /** * @parameter default-value="**\/test\/**" */ - private String projectExcludes; + protected String projectExcludes; /** * */ Modified: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractSingleAlterationMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractSingleAlterationMojo.java?view=diff&rev=555766&r1=555765&r2=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractSingleAlterationMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AbstractSingleAlterationMojo.java Thu Jul 12 14:06:32 2007 @@ -35,7 +35,7 @@ { /** - * @parameter + * @parameter expression="${projectFile}" * @required */ protected String projectFile; Added: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterMojo.java?view=auto&rev=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterMojo.java (added) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterMojo.java Thu Jul 12 14:06:32 2007 @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.maven.plugins.pom; + +import java.util.ArrayList; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * Alter a Mojo by the specified elements + * @author eredmond + * + * @goal alter + * @phase process-resources + */ +public class AlterMojo extends AbstractMultipleAlterationMojo +{ + /** + * @parameter + */ + Map alteredProperties; + + /** + * @parameter + */ + ArrayList dependencies; + + /** + * @parameter + */ + Parent parent; + + /** + * @parameter + */ + boolean applyToSubprojects; + + /** + * @parameter + */ + String projectFile; + + public void execute() throws MojoExecutionException, MojoFailureException + { + if( parent != null ) + { + AlterParentMojo alterParent = new AlterParentMojo(); + + alterParent.newParentGroupId = parent.getGroupId(); + alterParent.newParentArtifactId = parent.getArtifactId(); + alterParent.newParentVersion = parent.getVersion(); + alterParent.relativePath = parent.getRelativePath(); + alterParent.suppressRelativePath = parent.isRemoveRelativePath(); + alterParent.projectFile = projectFile; + + alterParent.execute(); + } + + if( alteredProperties != null && !alteredProperties.isEmpty() ) + { + AlterPropertiesMojo alterProperties = new AlterPropertiesMojo(); + + alterProperties.alteredProperties = new TreeMap( alteredProperties ); + alterProperties.projectFile = projectFile; + + alterProperties.execute(); + } + + if ( dependencies != null && !dependencies.isEmpty() ) + { + AlterDependenciesMojo alterDependencies = new AlterDependenciesMojo(); + + alterDependencies.dependencies = new ArrayList( dependencies ); + alterDependencies.target = target; + alterDependencies.projectExcludes = projectExcludes; + + alterDependencies.execute(); + } + + } +} Modified: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterParentMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterParentMojo.java?view=diff&rev=555766&r1=555765&r2=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterParentMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterParentMojo.java Thu Jul 12 14:06:32 2007 @@ -43,30 +43,30 @@ * @parameter * @required */ - private String newParentGroupId; + String newParentGroupId; /** * @parameter * @required */ - private String newParentArtifactId; + String newParentArtifactId; /** * @parameter * @required */ - private String newParentVersion; + String newParentVersion; /** * @parameter * @parameter */ - private String relativePath; + String relativePath; /** * @parameter default-value="false" */ - private boolean suppressRelativePath; + boolean suppressRelativePath; public void execute() throws MojoExecutionException, MojoFailureException { Added: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterScmMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterScmMojo.java?view=auto&rev=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterScmMojo.java (added) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/AlterScmMojo.java Thu Jul 12 14:06:32 2007 @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.maven.plugins.pom; + +import java.io.File; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.pom.util.XMLException; +import org.apache.maven.plugins.pom.util.XMLTool; +import org.dom4j.Element; + +/** + * Alter a project's SCM elements + * + * @author eredmond + * + * @phase process-resources + * @goal alter-scm + */ +public class AlterScmMojo extends AbstractSingleAlterationMojo +{ + /** + * @parameter expression="${connection}" + */ + String connection; + + /** + * @parameter expression="${developerConnection}" + */ + String developerConnection; + + /** + * @parameter expression="${url}" + */ + String url; + + public void execute() throws MojoExecutionException, MojoFailureException + { + try + { + XMLTool xmlTool = new XMLTool( "project", new File( projectFile ) ); + + xmlTool.removeNamespaces(); + + Element scm = null; + + if ( xmlTool.hasElement( "//project/scm" ) ) + { + scm = xmlTool.getElement( "//project/scm" ); + } + else + { + Element project = xmlTool.getElement( "//project" ); + + scm = project.addElement( "scm" ); + } + + getScmElement( xmlTool, scm, "connection", connection ); + + getScmElement( xmlTool, scm, "developerConnection", developerConnection ); + + getScmElement( xmlTool, scm, "url", url ); + + xmlTool.writeDocument( projectFile ); + } + catch ( XMLException e ) + { + throw new MojoExecutionException( "error processing: " + projectFile, e ); + } + } + + private void getScmElement( XMLTool xmlTool, Element scm, String elementName, String value ) + throws XMLException + { + if ( value == null || value.length() == 0 ) + { + return; + } + + if ( xmlTool.hasElement( "//project/scm/" + elementName ) ) + { + xmlTool.updateElement( "//project/scm/" + elementName, connection ); + } + else + { + Element scmElement = scm.addElement( elementName ); + scmElement.setText( connection ); + } + } +} Added: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Coordinate.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Coordinate.java?view=auto&rev=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Coordinate.java (added) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Coordinate.java Thu Jul 12 14:06:32 2007 @@ -0,0 +1,44 @@ +package org.apache.maven.plugins.pom; + +/** + * A base for groupId, artifactId, version + * @author eredmond + */ +public class Coordinate +{ + private String groupId; + + private String artifactId; + + private String version; + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } +} Modified: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Dependency.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Dependency.java?view=diff&rev=555766&r1=555765&r2=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Dependency.java (original) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Dependency.java Thu Jul 12 14:06:32 2007 @@ -24,53 +24,17 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Jesse McConnell</a> * @version $Id:$ */ -public class Dependency +public class Dependency extends Coordinate { - - private String groupId; - - private String artifactId; - - private String version; - private String scope; - - public String getArtifactId() - { - return artifactId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public String getVersion() - { - return version; - } - - public void setVersion( String version ) - { - this.version = version; - } - public String getScope() { + public String getScope() + { return scope; } - public void setScope(String scope) { + public void setScope(String scope) + { this.scope = scope; } - } Added: maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Parent.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Parent.java?view=auto&rev=555766 ============================================================================== --- maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Parent.java (added) +++ maven/sandbox/trunk/plugins/maven-pom-plugin/src/main/java/org/apache/maven/plugins/pom/Parent.java Thu Jul 12 14:06:32 2007 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.maven.plugins.pom; + +/** + * A Parent element + * @author eredmond + */ +public class Parent extends Coordinate +{ + private String relativePath; + + private boolean removeRelativePath; + + public String getRelativePath() + { + return relativePath; + } + + public void setRelativePath( String relativePath ) + { + this.relativePath = relativePath; + } + + public boolean isRemoveRelativePath() + { + return removeRelativePath; + } + + public void setRemoveRelativePath( boolean removeRelativePath ) + { + this.removeRelativePath = removeRelativePath; + } +}