org.apache.commons.lang.reflect.FieldUtils#readField ( )源码实例Demo

下面列出了org.apache.commons.lang.reflect.FieldUtils#readField ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pom-manipulation-ext   文件: CliTest.java
@Test
public void checkLocalRepositoryWithDefaults() throws Exception
{
    Cli c = new Cli();
    File settings = writeSettings( temp.newFile());

    TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-s", settings.toString()} } );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
    assertEquals( "File " + new File( ms.getRequest().getLocalRepository().getBasedir() ).getParentFile().toString()
                                  + " was not equal to " + System.getProperty( "user.home" ) + File.separatorChar
                                  + ".m2",
                  new File( ms.getRequest().getLocalRepository().getBasedir() ).getParentFile().toString(),
                  System.getProperty( "user.home" ) + File.separatorChar + ".m2" );

}
 
源代码2 项目: pom-manipulation-ext   文件: CliTest.java
@Test
public void checkLocalRepositoryWithExplicitMavenRepoAndSettings() throws Exception
{
    File folder = temp.newFolder();
    Cli c = new Cli();
    TestUtils.executeMethod( c, "run", new Object[] { new String[]
                    { "--settings=" + getClass().getResource("/settings-test.xml").getFile(),
                                    "-Dmaven.repo.local=" + folder.toString() }} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getLocalRepository().getBasedir(), folder.toString() );
    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
}
 
源代码3 项目: das   文件: Serializer.java
default Object readField(Object target, String fieldName) {
    try {
        return FieldUtils.readField(target, fieldName, true);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
源代码4 项目: pom-manipulation-ext   文件: CliTest.java
@Test
public void checkTargetDefaultMatches() throws Exception
{
    Cli c = new Cli();
    c.run( new String[] {} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    File defaultTarget = (File) FieldUtils.readField( c, "target", true );

    assertEquals( "Session file should match", defaultTarget, session.getPom() );
}
 
源代码5 项目: pom-manipulation-ext   文件: CliTest.java
@Test
public void checkLocalRepositoryWithSettings() throws Exception
{
    Cli c = new Cli();
    TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-settings=" + getClass().getResource( "/settings-test.xml").getFile() }} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
}
 
源代码6 项目: pom-manipulation-ext   文件: CliTest.java
@Test
public void checkLocalRepositoryWithExplicitMavenRepo() throws Exception
{
    File folder = temp.newFolder();
    Cli c = new Cli();
    TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-Dmaven.repo.local=" + folder.toString() }} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
}
 
<T extends AmazonWebServiceClient> String getEndpointFor(T client) {
    try {
        URI endpointUri = (URI) FieldUtils.readField(client, "endpoint", true);

        return endpointUri.toASCIIString();
    } catch (Exception e) {
        return null;
    }
}
 
源代码8 项目: openhab1-addons   文件: PropertyUtils.java
/**
 * Returns the object of the (nested) property.
 */
public static Object getNestedObject(Object instance, String propertyName) throws IllegalAccessException {
    if (PropertyUtils.isWeatherProperty(propertyName)) {
        return instance;
    }

    while (PropertyResolver.hasNested(propertyName)) {
        instance = FieldUtils.readField(instance, PropertyResolver.first(propertyName), true);
        propertyName = PropertyResolver.removeFirst(propertyName);
    }
    return instance;
}
 
源代码9 项目: pom-manipulation-ext   文件: CliTest.java
@Test
public void checkLocalRepositoryWithDefaultsAndModifiedUserSettings() throws Exception
{
    boolean restore = false;
    Path source = Paths.get ( System.getProperty( "user.home" ) + File.separatorChar + ".m2" + File.separatorChar + "settings.xml");
    Path backup = Paths.get( source.toString() + '.' + UUID.randomUUID().toString() );
    Path tmpSettings = Paths.get ( getClass().getResource("/settings-test.xml").toURI() );

    try
    {
        if ( source.toFile().exists() )
        {
            System.out.println ("Backing up settings.xml to " + backup);
            restore = true;
            Files.move( source, backup, StandardCopyOption.ATOMIC_MOVE);
        }
        Files.copy( tmpSettings, source );

        Cli c = new Cli();
        TestUtils.executeMethod( c, "run", new Object[] { new String[] {} } );

        ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
        MavenSession ms = (MavenSession) FieldUtils.readField( session, "mavenSession", true );

        assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                      ms.getRequest().getLocalRepositoryPath().toString() );
        assertEquals( ms.getLocalRepository().getBasedir(),
                      System.getProperty( "user.home" ) + File.separatorChar + ".m2-mead-test" );

    }
    finally
    {
        if ( restore )
        {
            Files.move( backup, source, StandardCopyOption.ATOMIC_MOVE);
        }
        else
        {
            Files.delete( source );
        }
    }
}