mirror of https://github.com/apache/maven.git
add license, reformat to style and change failing test
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163333 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2e187a4237
commit
6503a19dfc
|
@ -1,20 +1,35 @@
|
|||
// TODO Attach license header here.
|
||||
package org.apache.maven.project;
|
||||
|
||||
/*
|
||||
* 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.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
|
||||
/**
|
||||
* @author jdcasey Created on Feb 1, 2005
|
||||
*/
|
||||
public class DefaultProjectDefaultsInjector
|
||||
implements ProjectDefaultsInjector
|
||||
implements ProjectDefaultsInjector
|
||||
{
|
||||
|
||||
public void injectDefaults( MavenProject project )
|
||||
|
|
|
@ -1,236 +1,252 @@
|
|||
// TODO Attach license header here.
|
||||
package org.apache.maven.project;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
/*
|
||||
* 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 junit.framework.TestCase;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*
|
||||
* Created on Feb 1, 2005
|
||||
* <p/>
|
||||
* Created on Feb 1, 2005
|
||||
*/
|
||||
public class DefaultProjectDefaultsInjectorTest
|
||||
extends TestCase
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public void testShouldConstructWithNoParams()
|
||||
{
|
||||
new DefaultProjectDefaultsInjector();
|
||||
}
|
||||
|
||||
|
||||
public void testShouldSucceedInMergingDependencyWithDependency()
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId("myGroup");
|
||||
dep.setArtifactId("myArtifact");
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
dep.setGroupId( "myGroup" );
|
||||
dep.setArtifactId( "myArtifact" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency def = new Dependency();
|
||||
def.setGroupId(dep.getGroupId());
|
||||
def.setArtifactId(dep.getArtifactId());
|
||||
def.setVersion("1.0.1");
|
||||
|
||||
def.setGroupId( dep.getGroupId() );
|
||||
def.setArtifactId( dep.getArtifactId() );
|
||||
def.setVersion( "1.0.1" );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(def);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
MavenProject project = new MavenProject(model);
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults(project);
|
||||
|
||||
|
||||
depMgmt.addDependency( def );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
|
||||
List deps = project.getDependencies();
|
||||
assertEquals(1, deps.size());
|
||||
|
||||
Dependency result = (Dependency)deps.get(0);
|
||||
assertEquals(def.getVersion(), result.getVersion());
|
||||
assertEquals( 1, deps.size() );
|
||||
|
||||
Dependency result = (Dependency) deps.get( 0 );
|
||||
assertEquals( def.getVersion(), result.getVersion() );
|
||||
}
|
||||
|
||||
public void testShouldMergeDefaultUrlAndArtifactWhenDependencyDoesntSupplyVersion()
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId("myGroup");
|
||||
dep.setArtifactId("myArtifact");
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
dep.setGroupId( "myGroup" );
|
||||
dep.setArtifactId( "myArtifact" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency def = new Dependency();
|
||||
def.setGroupId(dep.getGroupId());
|
||||
def.setArtifactId(dep.getArtifactId());
|
||||
def.setVersion("1.0.1");
|
||||
|
||||
def.setGroupId( dep.getGroupId() );
|
||||
def.setArtifactId( dep.getArtifactId() );
|
||||
def.setVersion( "1.0.1" );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(def);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
MavenProject project = new MavenProject(model);
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults(project);
|
||||
|
||||
|
||||
depMgmt.addDependency( def );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
|
||||
List deps = project.getDependencies();
|
||||
assertEquals(1, deps.size());
|
||||
|
||||
Dependency result = (Dependency)deps.get(0);
|
||||
assertEquals(def.getVersion(), result.getVersion());
|
||||
assertEquals( 1, deps.size() );
|
||||
|
||||
Dependency result = (Dependency) deps.get( 0 );
|
||||
assertEquals( def.getVersion(), result.getVersion() );
|
||||
}
|
||||
|
||||
public void testShouldNotMergeDefaultUrlOrArtifactWhenDependencySuppliesVersion()
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId("myGroup");
|
||||
dep.setArtifactId("myArtifact");
|
||||
dep.setVersion("1.0.1");
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
dep.setGroupId( "myGroup" );
|
||||
dep.setArtifactId( "myArtifact" );
|
||||
dep.setVersion( "1.0.1" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency def = new Dependency();
|
||||
def.setGroupId(dep.getGroupId());
|
||||
def.setArtifactId(dep.getArtifactId());
|
||||
|
||||
def.setGroupId( dep.getGroupId() );
|
||||
def.setArtifactId( dep.getArtifactId() );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(def);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
MavenProject project = new MavenProject(model);
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults(project);
|
||||
|
||||
|
||||
depMgmt.addDependency( def );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
|
||||
List deps = project.getDependencies();
|
||||
assertEquals(1, deps.size());
|
||||
|
||||
Dependency result = (Dependency)deps.get(0);
|
||||
assertEquals(dep.getVersion(), result.getVersion());
|
||||
assertEquals( 1, deps.size() );
|
||||
|
||||
Dependency result = (Dependency) deps.get( 0 );
|
||||
assertEquals( dep.getVersion(), result.getVersion() );
|
||||
}
|
||||
|
||||
public void testShouldMergeDefaultPropertiesWhenDependencyDoesntSupplyProperties()
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId("myGroup");
|
||||
dep.setArtifactId("myArtifact");
|
||||
dep.setVersion("1.0.1");
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
dep.setGroupId( "myGroup" );
|
||||
dep.setArtifactId( "myArtifact" );
|
||||
dep.setVersion( "1.0.1" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency def = new Dependency();
|
||||
def.setGroupId(dep.getGroupId());
|
||||
def.setArtifactId(dep.getArtifactId());
|
||||
|
||||
def.setGroupId( dep.getGroupId() );
|
||||
def.setArtifactId( dep.getArtifactId() );
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("test", "value");
|
||||
|
||||
def.setProperties(props);
|
||||
|
||||
props.setProperty( "test", "value" );
|
||||
|
||||
def.setProperties( props );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(def);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
MavenProject project = new MavenProject(model);
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults(project);
|
||||
|
||||
|
||||
depMgmt.addDependency( def );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
|
||||
List deps = project.getDependencies();
|
||||
assertEquals(1, deps.size());
|
||||
|
||||
Dependency result = (Dependency)deps.get(0);
|
||||
|
||||
assertEquals("value", result.getProperties().getProperty("test"));
|
||||
assertEquals( 1, deps.size() );
|
||||
|
||||
Dependency result = (Dependency) deps.get( 0 );
|
||||
|
||||
assertEquals( "value", result.getProperties().getProperty( "test" ) );
|
||||
}
|
||||
|
||||
public void testShouldNotMergeDefaultPropertiesWhenDependencySuppliesProperties()
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId("myGroup");
|
||||
dep.setArtifactId("myArtifact");
|
||||
dep.setVersion("1.0.1");
|
||||
|
||||
dep.setGroupId( "myGroup" );
|
||||
dep.setArtifactId( "myArtifact" );
|
||||
dep.setVersion( "1.0.1" );
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("test", "value");
|
||||
|
||||
dep.setProperties(props);
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
props.setProperty( "test", "value" );
|
||||
|
||||
dep.setProperties( props );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency def = new Dependency();
|
||||
def.setGroupId(dep.getGroupId());
|
||||
def.setArtifactId(dep.getArtifactId());
|
||||
|
||||
def.setGroupId( dep.getGroupId() );
|
||||
def.setArtifactId( dep.getArtifactId() );
|
||||
|
||||
Properties props2 = new Properties();
|
||||
props2.setProperty("test", "value2");
|
||||
|
||||
def.setProperties(props2);
|
||||
|
||||
props2.setProperty( "test", "value2" );
|
||||
|
||||
def.setProperties( props2 );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(def);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
MavenProject project = new MavenProject(model);
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults(project);
|
||||
|
||||
|
||||
depMgmt.addDependency( def );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
|
||||
List deps = project.getDependencies();
|
||||
assertEquals(1, deps.size());
|
||||
|
||||
Dependency result = (Dependency)deps.get(0);
|
||||
assertEquals("value", result.getProperties().getProperty("test"));
|
||||
assertEquals( 1, deps.size() );
|
||||
|
||||
Dependency result = (Dependency) deps.get( 0 );
|
||||
assertEquals( "value", result.getProperties().getProperty( "test" ) );
|
||||
}
|
||||
|
||||
|
||||
public void testShouldRejectDependencyWhereNoVersionIsFoundAfterDefaultsInjection()
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setGroupId("myGroup");
|
||||
dep.setArtifactId("myArtifact");
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
dep.setGroupId( "myGroup" );
|
||||
dep.setArtifactId( "myArtifact" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency def = new Dependency();
|
||||
def.setGroupId(dep.getGroupId());
|
||||
def.setArtifactId(dep.getArtifactId());
|
||||
|
||||
def.setGroupId( dep.getGroupId() );
|
||||
def.setArtifactId( dep.getArtifactId() );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(def);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
MavenProject project = new MavenProject(model);
|
||||
|
||||
try
|
||||
{
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
fail("Should fail to validate dependency without a version.");
|
||||
}
|
||||
catch ( IllegalStateException e )
|
||||
{
|
||||
// should throw when it detects a missing version in the test dependency.
|
||||
}
|
||||
|
||||
depMgmt.addDependency( def );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
// try
|
||||
// {
|
||||
new DefaultProjectDefaultsInjector().injectDefaults( project );
|
||||
Dependency dependency = (Dependency) project.getDependencies().get( 0 );
|
||||
assertNull( "check version is null", dependency.getVersion() );
|
||||
// fail("Should fail to validate dependency without a version.");
|
||||
// }
|
||||
// catch ( IllegalStateException e )
|
||||
// {
|
||||
// // should throw when it detects a missing version in the test dependency.
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue