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 ); }
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 ); }
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; }
/** * 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()); } }
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; }
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)); } }
/** * 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); }
@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(); }
@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}); }
public TranspilatorThread(AbstractMojo mojo, MavenProject project) { setPriority(Thread.MAX_PRIORITY); this.project = project; this.mojo = mojo; }
public NarExecutionBuilder(final AbstractMojo compileMojo, final MojoExecution mojoExceution) { this.narCompileMojo = (INarCompileMojo) compileMojo; this.mojoExecution = mojoExceution; parseNarVersionNumbers(); }
public Builder setMojo(final AbstractMojo mojo) { this.abstractMojo = mojo; return this; }
public JarAppender(final AbstractMojo abstractMojo) { this.abstractMojo = Preconditions.checkNotNull(abstractMojo); }
public FileGatherer(final AbstractMojo abstractMojo) { this.mojo = Preconditions.checkNotNull(abstractMojo); }
public JarExtractor(final AbstractMojo abstractMojo) { this.abstractMojo = Preconditions.checkNotNull(abstractMojo); }
public JarMerger(final AbstractMojo abstractMojo) { this.abstractMojo = Preconditions.checkNotNull(abstractMojo); }
public JarEntryReader(final AbstractMojo abstractMojo) { this.abstractMojo = Preconditions.checkNotNull(abstractMojo); }
public ClassPathGatherer(final AbstractMojo mojo) { this.mojo = Preconditions.checkNotNull(mojo); }
public FilesByExtensionGatherer(final AbstractMojo project, final String extension) { this(project, ImmutableSet.of(extension)); }
public FilesByExtensionGatherer(final AbstractMojo project, final Set<String> extensions) { this.project = Preconditions.checkNotNull(project); this.extensions = Preconditions.checkNotNull(extensions); }
public DependencyExtractor(final AbstractMojo abstractMojo) { this(abstractMojo, true); }
public DependencyExtractor(final AbstractMojo abstractMojo, final boolean scanningEnabled) { this.abstractMojo = Preconditions.checkNotNull(abstractMojo); this.scanningEnabled = scanningEnabled; }
public SnippetHandler(AbstractMojo mojo, File cache, URL base) { super(); this.mojo = mojo; this.cache = cache; this.base = base; }
@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()); }
public void setOwner(AbstractMojo owner) { this.owner = owner; }
public RegisteringFileTreeScanner(List<Path> directories, WatchService watchService, AbstractMojo mojo) { this.directories = directories; this.watchService = watchService; this.mojo = mojo; }
/** * 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(); }