Java 类org.apache.maven.plugin.AbstractMojo 实例源码

项目:exec-maven-plugin    文件:ExecJavaMojoTest.java   
private void setUpProject( File pomFile, AbstractMojo mojo )
    throws Exception
{
    MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );

    ArtifactRepositoryLayout localRepositoryLayout =
        (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );

    String path = "src/test/repository";

    ArtifactRepository localRepository =
        new DefaultArtifactRepository( "local", "file://" + new File( path ).getAbsolutePath(),
                                       localRepositoryLayout );

    MavenProject project = builder.buildWithDependencies( pomFile, localRepository, null );
    // this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test
    project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() );
    setVariableValueToObject( mojo, "project", project );
}
项目:webstart    文件:AbstractJnlpMojoTest.java   
private void setUpProject( File pomFile, AbstractMojo mojo )
    throws Exception
{
    MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );

    ArtifactRepositoryFactory artifactRepositoryFactory =
        (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );

    ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, "never", "never" );

    String localRepoUrl = "file://" + System.getProperty( "user.home" ) + "/.m2/repository";

    ArtifactRepository localRepository =
        artifactRepositoryFactory.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(),
                                                            policy, policy );

    ProfileManager profileManager = new DefaultProfileManager( getContainer() );

    MavenProject project = projectBuilder.buildWithDependencies( pomFile, localRepository, profileManager );

    //this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test
    project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() );
    setVariableValueToObject( mojo, "project", project );
}
项目:roboconf-maven-plugin    文件:ValidateProjectMojoTest.java   
protected AbstractMojo findMojo( String projectName, String goalName ) throws Exception {

        // Find the project
        File baseDir = this.resources.getBasedir( projectName );
        Assert.assertNotNull( baseDir );
        Assert.assertTrue( baseDir.exists());
        Assert.assertTrue( baseDir.isDirectory());

        File pom = new File( baseDir, "pom.xml" );
        AbstractMojo mojo = (AbstractMojo) this.rule.lookupMojo( goalName, pom );
        Assert.assertNotNull( mojo );

        // Create the Maven project by hand (...)
        final MavenProject mvnProject = new MavenProject() ;
        mvnProject.setFile( pom ) ;

        this.rule.setVariableValueToObject( mojo, "project", mvnProject );
        Assert.assertNotNull( this.rule.getVariableValueFromObject( mojo, "project" ));

        // Initialize the project
        InitializeMojo initMojo = new InitializeMojo();
        initMojo.setProject( mvnProject );
        initMojo.execute();

        return mojo;
    }
项目:brooklyn-maven-plugin    文件:AbstractBrooklynMojoTest.java   
/**
 * Executes the given mojo and fails if it does not succeed within the given period.
 * @see AbstractInvokeBrooklynMojo#setPollPeriod(int, TimeUnit)
 */
protected void executeMojoWithTimeout(final AbstractMojo mojo, int timeout, TimeUnit unit) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Exception> exception = new AtomicReference<Exception>();
    Thread t = new Thread() {
        @Override
        public void run() {
            try {
                mojo.execute();
            } catch (Exception e) {
                exception.set(e);
            } finally {
                latch.countDown();
            }
        }
    };
    t.start();
    boolean threadComplete = latch.await(timeout, unit);
    if (exception.get() != null) {
        if (t.isAlive()) t.interrupt();
        throw exception.get();
    } else if (!threadComplete) {
        t.interrupt();
        fail(mojo + " incomplete after " + timeout + " " + unit.name().toLowerCase());
    }
}
项目:roboconf-platform    文件:AbstractTest.java   
protected AbstractMojo findMojo( String projectName, String goalName ) throws Exception {

        // Find the project
        File baseDir = this.resources.getBasedir( projectName );
        Assert.assertNotNull( baseDir );
        Assert.assertTrue( baseDir.isDirectory());

        File pom = new File( baseDir, "pom.xml" );
        AbstractMojo mojo = (AbstractMojo) this.rule.lookupMojo( goalName, pom );
        Assert.assertNotNull( mojo );

        // Create the Maven project by hand (...)
        final MavenProject mvnProject = new MavenProject() ;
        mvnProject.setFile( pom ) ;

        this.rule.setVariableValueToObject( mojo, "project", mvnProject );
        Assert.assertNotNull( this.rule.getVariableValueFromObject( mojo, "project" ));

        // Initialize the project
        InitializeMojo initMojo = new InitializeMojo();
        initMojo.setProject( mvnProject );
        initMojo.execute();

        return mojo;
    }
项目:m2e-nar    文件:NarClassloader.java   
public INarExecutionBuilder createNarExecutionBuilder(final MavenProject mavenProject, final AbstractMojo mojo) throws CoreException {
    try {
        Class<?> clazz = Class.forName(builder, true, this);
        Constructor<?> constructor = clazz.getConstructor(MavenProject.class, AbstractMojo.class);
        return (INarExecutionBuilder) constructor.newInstance(mavenProject, mojo);
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "NAR Classloader problem", e));
    }
}
项目:brooklyn-maven-plugin    文件:AbstractBrooklynMojoTest.java   
/**
 * Executes the given mojo and fails if it does not succeed in a timely manner.
 * The timeout can be injected by setting {@link #TIMEOUT_PROPERTY} as a system
 * property.
 *
 * @see AbstractInvokeBrooklynMojo#setPollPeriod(int, TimeUnit)
 */
protected void executeMojoWithTimeout(AbstractMojo mojo) throws Exception {
    String configuredTimeout = System.getProperty(TIMEOUT_PROPERTY);
    Integer timeout = configuredTimeout != null
            ? Integer.parseInt(configuredTimeout)
            : 2;

    // The timeout is overkill on a normal machine but plausible on Travis, etc.
    executeMojoWithTimeout(mojo, timeout, TimeUnit.SECONDS);
}
项目:roboconf-platform    文件:ResolveMojoTest.java   
@Test( expected = MojoExecutionException.class )
public void testWithInvalidRoboconfDependencies() throws Exception {

    // Prepare the project
    final String projectName = "project--valid";

    File baseDir = this.resources.getBasedir( projectName );
    Assert.assertNotNull( baseDir );
    Assert.assertTrue( baseDir.isDirectory());

    AbstractMojo mojo = findMojo( projectName, "resolve" );
    this.rule.setVariableValueToObject( mojo, "repoSystem", newRepositorySystem());
    this.rule.setVariableValueToObject( mojo, "repositories", new ArrayList<RemoteRepository>( 0 ));

    // Add dependencies
    MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" );
    project.setDependencyArtifacts( new HashSet<Artifact> ());

    Artifact notRbcfArtifact1 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
    project.getDependencyArtifacts().add( notRbcfArtifact1 );

    Artifact notRbcfArtifact2 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
    notRbcfArtifact2.setFile( new File( "file that does not exist" ));
    project.getDependencyArtifacts().add( notRbcfArtifact2 );

    Artifact notRbcfArtifact3 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
    File temp = this.folder.newFile( "toto.zip" );
    Assert.assertTrue( temp.exists());

    notRbcfArtifact3.setFile( temp );
    project.getDependencyArtifacts().add( notRbcfArtifact3 );

    // Execute it
    File targetDir = new File( baseDir, MavenPluginConstants.TARGET_MODEL_DIRECTORY + "/" + Constants.PROJECT_DIR_GRAPH );
    Assert.assertFalse( targetDir.isDirectory());
    mojo.execute();
}
项目:cougar    文件:TestExceptionMessageHandling.java   
@Before
public void setup() throws Exception {
    final String baseDir = System.getProperty("user.dir");

    mojo = new IdlToDSMojo();
    mojo.setBaseDir(baseDir);
    mojo.setWsdlXslResource(RSRC);
    mojo.setXsdXslResource(RSRC);

    Field projectField = IdlToDSMojo.class.getDeclaredField("project");
    projectField.setAccessible(true);
    projectField.set(mojo, mock(MavenProject.class));

    Field iddAsResourceField = IdlToDSMojo.class.getDeclaredField("iddAsResource");
    iddAsResourceField.setAccessible(true);
    iddAsResourceField.setBoolean(mojo, true);

    Field logField = AbstractMojo.class.getDeclaredField("log");
    logField.setAccessible(true);
    logField.set(mojo, mock(Log.class));

    Service s = new Service();
    Field f = Service.class.getDeclaredField("serviceName");
    f.setAccessible(true);
    f.set(s, SERVICE_NAME);

    mojo.setServices(new Service[]{s});
}
项目:jsweet-maven-plugin    文件:JSweetWatchMojo.java   
public TranspilatorThread(AbstractMojo mojo, MavenProject project) {
    setPriority(Thread.MAX_PRIORITY);
    this.project = project;
    this.mojo = mojo;
}
项目:m2e-nar    文件:NarExecutionBuilder.java   
public NarExecutionBuilder(final AbstractMojo compileMojo, final MojoExecution mojoExceution) {
    this.narCompileMojo = (INarCompileMojo) compileMojo;
    this.mojoExecution = mojoExceution;
    parseNarVersionNumbers();
}
项目:ocamljava-maven-plugin    文件:OcamlRuntimeContainer.java   
public Builder setMojo(final AbstractMojo mojo) {
    this.abstractMojo = mojo;
    return this;
}
项目:ocamljava-maven-plugin    文件:JarAppender.java   
public JarAppender(final AbstractMojo abstractMojo) {
    this.abstractMojo = Preconditions.checkNotNull(abstractMojo);
}
项目:ocamljava-maven-plugin    文件:FileGatherer.java   
public FileGatherer(final AbstractMojo abstractMojo) {
    this.mojo = Preconditions.checkNotNull(abstractMojo);
}
项目:ocamljava-maven-plugin    文件:JarExtractor.java   
public JarExtractor(final AbstractMojo abstractMojo) {
    this.abstractMojo = Preconditions.checkNotNull(abstractMojo);
}
项目:ocamljava-maven-plugin    文件:JarMerger.java   
public JarMerger(final AbstractMojo abstractMojo) {
    this.abstractMojo = Preconditions.checkNotNull(abstractMojo);
}
项目:ocamljava-maven-plugin    文件:JarEntryReader.java   
public JarEntryReader(final AbstractMojo abstractMojo) {
    this.abstractMojo = Preconditions.checkNotNull(abstractMojo);
}
项目:ocamljava-maven-plugin    文件:ClassPathGatherer.java   
public ClassPathGatherer(final AbstractMojo mojo)
{
    this.mojo = Preconditions.checkNotNull(mojo);
}
项目:ocamljava-maven-plugin    文件:FilesByExtensionGatherer.java   
public FilesByExtensionGatherer(final AbstractMojo project, final String extension) {
    this(project, ImmutableSet.of(extension));
}
项目:ocamljava-maven-plugin    文件:FilesByExtensionGatherer.java   
public FilesByExtensionGatherer(final AbstractMojo project, final Set<String> extensions) {
    this.project = Preconditions.checkNotNull(project);
    this.extensions = Preconditions.checkNotNull(extensions);
}
项目:ocamljava-maven-plugin    文件:DependencyExtractor.java   
public DependencyExtractor(final AbstractMojo abstractMojo) {
    this(abstractMojo, true);
}
项目:ocamljava-maven-plugin    文件:DependencyExtractor.java   
public DependencyExtractor(final AbstractMojo abstractMojo, final boolean scanningEnabled) {
    this.abstractMojo = Preconditions.checkNotNull(abstractMojo);
    this.scanningEnabled = scanningEnabled;
}
项目:bigfoot-maven-plugins    文件:SnippetHandler.java   
public SnippetHandler(AbstractMojo mojo, File cache, URL base) {
    super();
    this.mojo = mojo;
    this.cache = cache;
    this.base = base;
}
项目:roboconf-platform    文件:ResolveMojoTest.java   
@Test
public void testWithValidRoboconfDependencies() throws Exception {

    // Prepare the project
    final String projectName = "project--valid";

    File baseDir = this.resources.getBasedir( projectName );
    Assert.assertNotNull( baseDir );
    Assert.assertTrue( baseDir.isDirectory());

    AbstractMojo mojo = findMojo( projectName, "resolve" );
    this.rule.setVariableValueToObject( mojo, "repoSystem", newRepositorySystem());
    this.rule.setVariableValueToObject( mojo, "repositories", new ArrayList<RemoteRepository>( 0 ));

    // Create a Roboconf application
    File dir = this.folder.newFolder();
    File targetZipFile = this.folder.newFile();
    Assert.assertTrue( targetZipFile.delete());

    CreationBean bean = new CreationBean()
            .projectDescription( "some desc" ).projectName( "my-project" )
            .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ).mavenProject( false );

    ProjectUtils.createProjectSkeleton( dir, bean );
    ZipArchiver zipArchiver = new ZipArchiver();
    zipArchiver.addDirectory( dir );
    zipArchiver.setCompress( true );
    zipArchiver.setDestFile( targetZipFile );
    zipArchiver.createArchive();

    Assert.assertTrue( targetZipFile.isFile());

    // Add dependencies
    MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" );
    project.setDependencyArtifacts( new HashSet<Artifact> ());

    Artifact rbcfArtifact3 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
    rbcfArtifact3.setFile( targetZipFile );
    project.getDependencyArtifacts().add( rbcfArtifact3 );

    // Add it to our "local" repository
    this.artifactIdToArtifact.put( rbcfArtifact3.getArtifactId(), rbcfArtifact3 );

    // Execute it
    File targetDir = new File( baseDir, MavenPluginConstants.TARGET_MODEL_DIRECTORY + "/" + Constants.PROJECT_DIR_GRAPH );
    Assert.assertFalse( targetDir.isDirectory());
    mojo.execute();

    // Verify the import was copied in the right location
    File importDir = new File( targetDir, "net.roboconf/roboconf-core" );
    Assert.assertTrue( importDir.isDirectory());
    Assert.assertTrue( new File( importDir, "main.graph" ).isFile());
}
项目:jenkinsmvn    文件:AbstractActionHandler.java   
public void setOwner(AbstractMojo owner) {
    this.owner = owner;
}
项目:jsweet-maven-plugin    文件:JSweetWatchMojo.java   
public RegisteringFileTreeScanner(List<Path> directories, WatchService watchService, AbstractMojo mojo) {

            this.directories = directories;
            this.watchService = watchService;
            this.mojo = mojo;

        }
项目:android-ndk-maven-plugin    文件:AbstractAndroidMojoTestCase.java   
/**
 * Get the project directory used for this mojo.
 * 
 * @param mojo the mojo to query.
 * @return the project directory.
 * @throws IllegalAccessException if unable to get the project directory.
 */
public File getProjectDir(AbstractMojo mojo) throws IllegalAccessException {
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    return project.getFile().getParentFile();
}