Author: brett
Date: Tue Jun 7 20:37:15 2005
New Revision: 189512
URL: http://svn.apache.org/viewcvs?rev=189512&view=rev
Log:
add missing file for the set properties capabilities
Added:
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java
(with props)
Added:
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java?rev=189512&view=auto
==============================================================================
---
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java
(added)
+++
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java
Tue Jun 7 20:37:15 2005
@@ -0,0 +1,112 @@
+package org.apache.maven.artifact.ant;
+
+/*
+ * 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 org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.tools.ant.BuildException;
+import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
+
+/**
+ * Set a property from a POM.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ * @version $Id$
+ */
+public class SetPropertyTask
+ extends AbstractArtifactTask
+{
+ private String ref;
+
+ private String property;
+
+ private String expression;
+
+ public void execute()
+ throws BuildException
+ {
+ ArtifactRepository localRepo = createLocalArtifactRepository();
+
+ MavenProjectBuilder builder = (MavenProjectBuilder) lookup(
MavenProjectBuilder.ROLE );
+ Pom pom = buildPom( builder, localRepo );
+
+ if ( expression == null )
+ {
+ throw new BuildException( "the expression attribute is required" );
+ }
+
+ if ( property == null && ref == null )
+ {
+ throw new BuildException( "the property or ref attribute is
required" );
+ }
+
+ else if ( property != null && ref != null )
+ {
+ throw new BuildException( "only one of the property or ref
attribute is allowed" );
+
+ }
+
+ Object value = null;
+ try
+ {
+ value = ReflectionValueExtractor.evaluate( expression,
pom.getMavenProject() );
+ }
+ catch ( Exception e )
+ {
+ throw new BuildException( "Error extracting expression from POM",
e );
+ }
+
+ if ( property != null )
+ {
+ getProject().setProperty( property, value.toString() );
+ }
+ else
+ {
+ getProject().addReference( ref, value );
+ }
+ }
+
+ public String getProperty()
+ {
+ return property;
+ }
+
+ public void setProperty( String property )
+ {
+ this.property = property;
+ }
+
+ public String getExpression()
+ {
+ return expression;
+ }
+
+ public void setExpression( String expression )
+ {
+ this.expression = expression;
+ }
+
+ public String getRef()
+ {
+ return ref;
+ }
+
+ public void setRef( String ref )
+ {
+ this.ref = ref;
+ }
+}
Propchange:
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/SetPropertyTask.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]