@Test public void testWithValidRoboconfDependencies() throws Exception { 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 )); 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()); 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 ); this.artifactIdToArtifact.put( rbcfArtifact3.getArtifactId(), rbcfArtifact3 ); File targetDir = new File( baseDir, MavenPluginConstants.TARGET_MODEL_DIRECTORY + "/" + Constants.PROJECT_DIR_GRAPH ); Assert.assertFalse( targetDir.isDirectory()); mojo.execute(); File importDir = new File( targetDir, "net.roboconf/roboconf-core" ); Assert.assertTrue( importDir.isDirectory()); Assert.assertTrue( new File( importDir, "main.graph" ).isFile()); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { File completeAppDirectory = new File( this.project.getBuild().getOutputDirectory()); Set<Artifact> artifacts = new HashSet<> (); if( this.project.getDependencyArtifacts() != null ) artifacts.addAll( this.project.getDependencyArtifacts()); for( Artifact unresolvedArtifact : artifacts ) { String artifactId = unresolvedArtifact.getArtifactId(); String groupId = unresolvedArtifact.getGroupId(); org.eclipse.aether.artifact.Artifact aetherArtifact = new DefaultArtifact( groupId, artifactId, unresolvedArtifact.getClassifier(), unresolvedArtifact.getType(), unresolvedArtifact.getVersion()); ArtifactRequest req = new ArtifactRequest().setRepositories( this.repositories ).setArtifact( aetherArtifact ); ArtifactResult resolutionResult; try { resolutionResult = this.repoSystem.resolveArtifact( this.repoSession, req ); } catch( ArtifactResolutionException e ) { throw new MojoExecutionException( "Artifact " + artifactId + " could not be resolved.", e ); } File file = resolutionResult.getArtifact().getFile(); if( file == null || ! file.exists()) { getLog().warn( "Artifact " + artifactId + " has no attached file. Its content will not be copied in the target model directory." ); continue; } File targetDirectory = new File( completeAppDirectory, Constants.PROJECT_DIR_GRAPH + "/" + groupId + "/" + artifactId ); getLog().debug( "Copying the content of artifact " + artifactId + " under " + targetDirectory ); try { Utils.extractZipArchive( file, targetDirectory, "graph/[^/]*\\.graph", "graph/" ); Utils.extractZipArchive( file, targetDirectory.getParentFile(), "graph/.*/.*", "graph/" ); } catch( IOException e ) { throw new MojoExecutionException( "The ZIP archive for artifact " + artifactId + " could not be extracted.", e ); } File temporaryDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-temp" ); try { Utils.extractZipArchive( file, temporaryDirectory ); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( temporaryDirectory ); if( alr.getApplicationTemplate().getGraphs() != null ) { for( File dir : ResourceUtils.findScopedInstancesDirectories( alr.getApplicationTemplate()).values()) { if( Utils.listAllFiles( dir ).isEmpty()) continue; getLog().warn( "Artifact " + artifactId + " contains target properties. Reusable target properties should be packaged separately." ); } } } catch( IOException e ) { getLog().debug( "The presence of target properties in the " + artifactId + " artifact could not be verified." ); } finally { Utils.deleteFilesRecursivelyAndQuietly( temporaryDirectory ); } } }
ResolveMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File completeAppDirectory = new File( this.project.getBuild().getOutputDirectory()); Set<Artifact> artifacts = new HashSet<> (); if( this.project.getDependencyArtifacts() != null ) artifacts.addAll( this.project.getDependencyArtifacts()); for( Artifact unresolvedArtifact : artifacts ) { String artifactId = unresolvedArtifact.getArtifactId(); String groupId = unresolvedArtifact.getGroupId(); org.eclipse.aether.artifact.Artifact aetherArtifact = new DefaultArtifact( groupId, artifactId, unresolvedArtifact.getClassifier(), unresolvedArtifact.getType(), unresolvedArtifact.getVersion()); ArtifactRequest req = new ArtifactRequest().setRepositories( this.repositories ).setArtifact( aetherArtifact ); ArtifactResult resolutionResult; try { resolutionResult = this.repoSystem.resolveArtifact( this.repoSession, req ); } catch( ArtifactResolutionException e ) { throw new MojoExecutionException( "Artifact " + artifactId + " could not be resolved.", e ); } File file = resolutionResult.getArtifact().getFile(); if( file == null || ! file.exists()) { getLog().warn( "Artifact " + artifactId + " has no attached file. Its content will not be copied in the target model directory." ); continue; } File targetDirectory = new File( completeAppDirectory, Constants.PROJECT_DIR_GRAPH + "/" + groupId + "/" + artifactId ); getLog().debug( "Copying the content of artifact " + artifactId + " under " + targetDirectory ); try { Utils.extractZipArchive( file, targetDirectory, "graph/[^/]*\\.graph", "graph/" ); Utils.extractZipArchive( file, targetDirectory.getParentFile(), "graph/.*/.*", "graph/" ); } catch( IOException e ) { throw new MojoExecutionException( "The ZIP archive for artifact " + artifactId + " could not be extracted.", e ); } File temporaryDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-temp" ); try { Utils.extractZipArchive( file, temporaryDirectory ); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( temporaryDirectory ); if( alr.getApplicationTemplate().getGraphs() != null ) { for( File dir : ResourceUtils.findScopedInstancesDirectories( alr.getApplicationTemplate()).values()) { if( Utils.listAllFiles( dir ).isEmpty()) continue; getLog().warn( "Artifact " + artifactId + " contains target properties. Reusable target properties should be packaged separately." ); } } } catch( IOException e ) { getLog().debug( "The presence of target properties in the " + artifactId + " artifact could not be verified." ); } finally { Utils.deleteFilesRecursivelyAndQuietly( temporaryDirectory ); } } } }
ResolveMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File completeAppDirectory = new File( this.project.getBuild().getOutputDirectory()); Set<Artifact> artifacts = new HashSet<> (); if( this.project.getDependencyArtifacts() != null ) artifacts.addAll( this.project.getDependencyArtifacts()); for( Artifact unresolvedArtifact : artifacts ) { String artifactId = unresolvedArtifact.getArtifactId(); String groupId = unresolvedArtifact.getGroupId(); org.eclipse.aether.artifact.Artifact aetherArtifact = new DefaultArtifact( groupId, artifactId, unresolvedArtifact.getClassifier(), unresolvedArtifact.getType(), unresolvedArtifact.getVersion()); ArtifactRequest req = new ArtifactRequest().setRepositories( this.repositories ).setArtifact( aetherArtifact ); ArtifactResult resolutionResult; try { resolutionResult = this.repoSystem.resolveArtifact( this.repoSession, req ); } catch( ArtifactResolutionException e ) { throw new MojoExecutionException( "Artifact " + artifactId + " could not be resolved.", e ); } File file = resolutionResult.getArtifact().getFile(); if( file == null || ! file.exists()) { getLog().warn( "Artifact " + artifactId + " has no attached file. Its content will not be copied in the target model directory." ); continue; } File targetDirectory = new File( completeAppDirectory, Constants.PROJECT_DIR_GRAPH + "/" + groupId + "/" + artifactId ); getLog().debug( "Copying the content of artifact " + artifactId + " under " + targetDirectory ); try { Utils.extractZipArchive( file, targetDirectory, "graph/[^/]*\\.graph", "graph/" ); Utils.extractZipArchive( file, targetDirectory.getParentFile(), "graph/.*/.*", "graph/" ); } catch( IOException e ) { throw new MojoExecutionException( "The ZIP archive for artifact " + artifactId + " could not be extracted.", e ); } File temporaryDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-temp" ); try { Utils.extractZipArchive( file, temporaryDirectory ); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( temporaryDirectory ); if( alr.getApplicationTemplate().getGraphs() != null ) { for( File dir : ResourceUtils.findScopedInstancesDirectories( alr.getApplicationTemplate()).values()) { if( Utils.listAllFiles( dir ).isEmpty()) continue; getLog().warn( "Artifact " + artifactId + " contains target properties. Reusable target properties should be packaged separately." ); } } } catch( IOException e ) { getLog().debug( "The presence of target properties in the " + artifactId + " artifact could not be verified." ); } finally { Utils.deleteFilesRecursivelyAndQuietly( temporaryDirectory ); } } }  }
ResolveMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File completeAppDirectory = new File( this.project.getBuild().getOutputDirectory()); Set<Artifact> artifacts = new HashSet<> (); if( this.project.getDependencyArtifacts() != null ) artifacts.addAll( this.project.getDependencyArtifacts()); for( Artifact unresolvedArtifact : artifacts ) { String artifactId = unresolvedArtifact.getArtifactId(); String groupId = unresolvedArtifact.getGroupId(); org.eclipse.aether.artifact.Artifact aetherArtifact = new DefaultArtifact( groupId, artifactId, unresolvedArtifact.getClassifier(), unresolvedArtifact.getType(), unresolvedArtifact.getVersion()); ArtifactRequest req = new ArtifactRequest().setRepositories( this.repositories ).setArtifact( aetherArtifact ); ArtifactResult resolutionResult; try { resolutionResult = this.repoSystem.resolveArtifact( this.repoSession, req ); } catch( ArtifactResolutionException e ) { throw new MojoExecutionException( "Artifact " + artifactId + " could not be resolved.", e ); } File file = resolutionResult.getArtifact().getFile(); if( file == null || ! file.exists()) { getLog().warn( "Artifact " + artifactId + " has no attached file. Its content will not be copied in the target model directory." ); continue; } File targetDirectory = new File( completeAppDirectory, Constants.PROJECT_DIR_GRAPH + "/" + groupId + "/" + artifactId ); getLog().debug( "Copying the content of artifact " + artifactId + " under " + targetDirectory ); try { Utils.extractZipArchive( file, targetDirectory, "graph/[^/]*\\.graph", "graph/" ); Utils.extractZipArchive( file, targetDirectory.getParentFile(), "graph/.*/.*", "graph/" ); } catch( IOException e ) { throw new MojoExecutionException( "The ZIP archive for artifact " + artifactId + " could not be extracted.", e ); } File temporaryDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-temp" ); try { Utils.extractZipArchive( file, temporaryDirectory ); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( temporaryDirectory ); if( alr.getApplicationTemplate().getGraphs() != null ) { for( File dir : ResourceUtils.findScopedInstancesDirectories( alr.getApplicationTemplate()).values()) { if( Utils.listAllFiles( dir ).isEmpty()) continue; getLog().warn( "Artifact " + artifactId + " contains target properties. Reusable target properties should be packaged separately." ); } } } catch( IOException e ) { getLog().debug( "The presence of target properties in the " + artifactId + " artifact could not be verified." ); } finally { Utils.deleteFilesRecursivelyAndQuietly( temporaryDirectory ); } } }  @Override void execute(); }
ResolveMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File completeAppDirectory = new File( this.project.getBuild().getOutputDirectory()); Set<Artifact> artifacts = new HashSet<> (); if( this.project.getDependencyArtifacts() != null ) artifacts.addAll( this.project.getDependencyArtifacts()); for( Artifact unresolvedArtifact : artifacts ) { String artifactId = unresolvedArtifact.getArtifactId(); String groupId = unresolvedArtifact.getGroupId(); org.eclipse.aether.artifact.Artifact aetherArtifact = new DefaultArtifact( groupId, artifactId, unresolvedArtifact.getClassifier(), unresolvedArtifact.getType(), unresolvedArtifact.getVersion()); ArtifactRequest req = new ArtifactRequest().setRepositories( this.repositories ).setArtifact( aetherArtifact ); ArtifactResult resolutionResult; try { resolutionResult = this.repoSystem.resolveArtifact( this.repoSession, req ); } catch( ArtifactResolutionException e ) { throw new MojoExecutionException( "Artifact " + artifactId + " could not be resolved.", e ); } File file = resolutionResult.getArtifact().getFile(); if( file == null || ! file.exists()) { getLog().warn( "Artifact " + artifactId + " has no attached file. Its content will not be copied in the target model directory." ); continue; } File targetDirectory = new File( completeAppDirectory, Constants.PROJECT_DIR_GRAPH + "/" + groupId + "/" + artifactId ); getLog().debug( "Copying the content of artifact " + artifactId + " under " + targetDirectory ); try { Utils.extractZipArchive( file, targetDirectory, "graph/[^/]*\\.graph", "graph/" ); Utils.extractZipArchive( file, targetDirectory.getParentFile(), "graph/.*/.*", "graph/" ); } catch( IOException e ) { throw new MojoExecutionException( "The ZIP archive for artifact " + artifactId + " could not be extracted.", e ); } File temporaryDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-temp" ); try { Utils.extractZipArchive( file, temporaryDirectory ); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( temporaryDirectory ); if( alr.getApplicationTemplate().getGraphs() != null ) { for( File dir : ResourceUtils.findScopedInstancesDirectories( alr.getApplicationTemplate()).values()) { if( Utils.listAllFiles( dir ).isEmpty()) continue; getLog().warn( "Artifact " + artifactId + " contains target properties. Reusable target properties should be packaged separately." ); } } } catch( IOException e ) { getLog().debug( "The presence of target properties in the " + artifactId + " artifact could not be verified." ); } finally { Utils.deleteFilesRecursivelyAndQuietly( temporaryDirectory ); } } }  @Override void execute();  }