ProjectUtils { public static void createProjectSkeleton( File targetDirectory, CreationBean creationBean ) throws IOException { if( creationBean.isMavenProject()) createMavenProject( targetDirectory, creationBean ); else createSimpleProject( targetDirectory, creationBean ); } private  ProjectUtils(); static void createProjectSkeleton( File targetDirectory, CreationBean creationBean ); static List<String> listMavenPluginVersions(); static List<File> createRecipeDirectories( File applicationDirectory ); static final String GRAPH_EP; static final String INSTANCES_EP; }
@Test public void testSimpleProject() throws Exception { File dir = this.folder.newFolder(); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my-project" ) .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ).mavenProject( false ); Assert.assertEquals( 0, dir.listFiles().length ); ProjectUtils.createProjectSkeleton( dir, bean ); Assert.assertEquals( 6, dir.listFiles().length ); ApplicationLoadResult alr = RuntimeModelIo.loadApplication( dir ); Assert.assertEquals( 2, alr.getLoadErrors().size()); for( RoboconfError roboconfError : alr.getLoadErrors()) Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, roboconfError.getErrorCode()); Assert.assertEquals( bean.getProjectDescription(), alr.getApplicationTemplate().getDescription()); Assert.assertEquals( bean.getProjectName(), alr.getApplicationTemplate().getName()); Assert.assertEquals( bean.getProjectVersion(), alr.getApplicationTemplate().getVersion()); }
@Test public void testSimpleProjectForReusableRecipe() throws Exception { File dir = this.folder.newFolder(); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my-project" ) .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ) .mavenProject( false ).reusableRecipe( true ); Assert.assertEquals( 0, dir.listFiles().length ); ProjectUtils.createProjectSkeleton( dir, bean ); Assert.assertEquals( 2, dir.listFiles().length ); ApplicationLoadResult alr = RuntimeModelIo.loadApplication( dir ); List<RoboconfError> errors = new ArrayList<>( alr.getLoadErrors()); Assert.assertEquals( 2, errors.size()); Assert.assertEquals( ErrorCode.PROJ_NO_DESC_DIR, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_UNREACHABLE_FILE, errors.get( 1 ).getErrorCode()); }
@Test public void testMavenProject() throws Exception { File dir = this.folder.newFolder(); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my-project" ) .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ) .pluginVersion( "1.0.0" ); Assert.assertEquals( 0, dir.listFiles().length ); ProjectUtils.createProjectSkeleton( dir, bean ); Assert.assertEquals( 2, dir.listFiles().length ); Assert.assertTrue( new File( dir, "pom.xml" ).exists()); File modelDir = new File( dir, Constants.MAVEN_SRC_MAIN_MODEL ); Assert.assertTrue( modelDir.exists()); Assert.assertEquals( 6, modelDir.listFiles().length ); ApplicationLoadResult alr = RuntimeModelIo.loadApplication( modelDir ); List<RoboconfError> errors = new ArrayList<>( alr.getLoadErrors()); Assert.assertEquals( 3, errors.size()); Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_VERSION, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 1 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 2 ).getErrorCode()); Assert.assertEquals( "${project.description}", alr.getApplicationTemplate().getDescription()); Assert.assertEquals( bean.getProjectName(), alr.getApplicationTemplate().getName()); Assert.assertEquals( "${project.version}", alr.getApplicationTemplate().getVersion()); }
@Test public void testMavenProjectForReusableRecipe() throws Exception { File dir = this.folder.newFolder(); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my-project" ) .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ) .pluginVersion( "1.0.0" ).reusableRecipe( true ); Assert.assertEquals( 0, dir.listFiles().length ); ProjectUtils.createProjectSkeleton( dir, bean ); Assert.assertEquals( 2, dir.listFiles().length ); Assert.assertTrue( new File( dir, "pom.xml" ).exists()); File modelDir = new File( dir, Constants.MAVEN_SRC_MAIN_MODEL ); Assert.assertTrue( modelDir.exists()); Assert.assertEquals( 2, modelDir.listFiles().length ); ApplicationLoadResult alr = RuntimeModelIo.loadApplication( modelDir ); List<RoboconfError> errors = new ArrayList<>( alr.getLoadErrors()); Assert.assertEquals( 2, errors.size()); Assert.assertEquals( ErrorCode.PROJ_NO_DESC_DIR, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_UNREACHABLE_FILE, errors.get( 1 ).getErrorCode()); }
@Test public void testMavenProjectWithCustomPom() throws Exception { File dir = this.folder.newFolder(); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my project" ) .projectVersion( "1.0-SNAPSHOT" ).pluginVersion( "1.0.0" ) .groupId( "net.roboconf" ).artifactId( "roboconf-sample" ); File pomSkeleton = TestUtils.findTestFile( "/test-pom-skeleton.xml" ); Assert.assertTrue( pomSkeleton.exists()); bean.customPomLocation( pomSkeleton.getAbsolutePath()); Assert.assertEquals( 0, dir.listFiles().length ); ProjectUtils.createProjectSkeleton( dir, bean ); Assert.assertEquals( 2, dir.listFiles().length ); File pomFile = new File( dir, "pom.xml" ); File expectedPom = TestUtils.findTestFile( "/expected-pom.xml" ); Assert.assertTrue( expectedPom.exists()); Assert.assertTrue( pomFile.exists()); String actual = Utils.readFileContent( pomFile ); String expected = Utils.readFileContent( expectedPom ); Assert.assertEquals( expected, actual ); File modelDir = new File( dir, Constants.MAVEN_SRC_MAIN_MODEL ); Assert.assertTrue( modelDir.exists()); Assert.assertEquals( 6, modelDir.listFiles().length ); ApplicationLoadResult alr = RuntimeModelIo.loadApplication( modelDir ); List<RoboconfError> errors = new ArrayList<>( alr.getLoadErrors()); Assert.assertEquals( 3, errors.size()); Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_VERSION, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 1 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 2 ).getErrorCode()); Assert.assertEquals( "${project.description}", alr.getApplicationTemplate().getDescription()); Assert.assertEquals( bean.getProjectName(), alr.getApplicationTemplate().getName()); Assert.assertEquals( "${project.version}", alr.getApplicationTemplate().getVersion()); }