public static IStatus addNatures ( IProject project , IProgressMonitor monitor , String ... natureIdentifiers ) { if ( project != null && natureIdentifiers != null && natureIdentifiers . length > 0 ) { try { final SubMonitor subMonitor = SubMonitor . convert ( monitor , natureIdentifiers . length + 2 ) ; final IProjectDescription description = project . getDescription ( ) ; final List < String > natures = new LinkedList <> ( Arrays . asList ( description . getNatureIds ( ) ) ) ; for ( final String natureIdentifier : natureIdentifiers ) { if ( ! Strings . isNullOrEmpty ( natureIdentifier ) && ! natures . contains ( natureIdentifier ) ) { natures . add ( 0 , natureIdentifier ) ; } subMonitor . worked ( 1 ) ; } final String [ ] newNatures = natures . toArray ( new String [ natures . size ( ) ] ) ; final IStatus status = ResourcesPlugin . getWorkspace ( ) . validateNatureSet ( newNatures ) ; subMonitor . worked ( 1 ) ; // check the status and decide what to do if ( status . getCode ( ) == IStatus . OK ) { description . setNatureIds ( newNatures ) ; project . setDescription ( description , subMonitor . newChild ( 1 ) ) ; } subMonitor . done ( ) ; return status ; } catch ( CoreException exception ) { return SARLEclipsePlugin . getDefault ( ) . createStatus ( IStatus . ERROR , exception ) ; } } return SARLEclipsePlugin . getDefault ( ) . createOkStatus ( ) ; }
Add the natures to the given project .