Java Code Examples for org.netbeans.api.project.ProjectUtils#hasSubprojectCycles()

The following examples show how to use org.netbeans.api.project.ProjectUtils#hasSubprojectCycles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EarProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Gets all subprojects recursively
 */
static private void addSubprojects( Project project, List<Project> result ) {
    SubprojectProvider spp = project.getLookup().lookup( SubprojectProvider.class );
    
    if ( spp == null ) {
        return;
    }
    
    for( Iterator/*<Project>*/ it = spp.getSubprojects().iterator(); it.hasNext(); ) {
        Project sp = (Project) it.next();
        if (ProjectUtils.hasSubprojectCycles(project, sp)) {
            Logger.getLogger("global").log(Level.WARNING, "There would be cyclic " + // NOI18N
                    "dependencies if the " + sp + " would be added. Skipping..."); // NOI18N
            continue;
        }
        if ( !result.contains( sp ) ) {
            result.add( sp );
        }
        addSubprojects( sp, result );            
    }
}
 
Example 2
Source File: ProjectXMLManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if <code>candidates</code> dependencies introduce dependency cycle.
 * In such case returns localized message about which dependency causes the cycle.
 * @param candidates Module dependencies about to be added. May be empty but not <code>null</code>.
 * @return Localized warning message about introduced dependency cycle,
 * <code>null</code> otherwise.
 */
@Messages({"# {0} - candidate project name", "# {1} - this project name", "MSG_cyclic_dep=Adding project {0} as dependency to {1} would introduce cyclic dependency! Dependency was not added."})
public String getDependencyCycleWarning(final Set<ModuleDependency> candidates) {
    for (ModuleDependency md : candidates) {
        File srcLoc = md.getModuleEntry().getSourceLocation();
        if (srcLoc == null) {
            continue;
        }
        FileObject srcLocFO = FileUtil.toFileObject(srcLoc);
        if (srcLocFO == null) {
            continue;
        }
        Project candidate;
        try {
            candidate = ProjectManager.getDefault().findProject(srcLocFO);
        } catch (IOException x) {
            continue;
        }
        if (candidate == null) {
            continue;
        }
        boolean cyclicDep = ProjectUtils.hasSubprojectCycles(project, candidate);
        if (cyclicDep) {
            if (ProjectUtils.hasSubprojectCycles(project, null)) {
                LOG.log(Level.WARNING, "Starting out with subproject cycles in {0} before even changing them", project);
                return null;
            } else {
                String c = ProjectUtils.getInformation(candidate).getDisplayName();
                String m = ProjectUtils.getInformation(project).getDisplayName();
                return MSG_cyclic_dep(c, m);
            }
        }
    }
    return null;
}
 
Example 3
Source File: AntArtifactChooser.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Shows dialog with the artifact chooser 
 * @return null if canceled selected jars if some jars selected
 */
static AntArtifactItem[] showDialog( String[] artifactTypes, Project master, Component parent ) {
    
    JFileChooser chooser = ProjectChooser.projectChooser();
    chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
    chooser.setApproveButtonText( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_SelectProject" ) ); // NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (AntArtifactChooser.class,"AD_AACH_SelectProject"));
    AntArtifactChooser accessory = new AntArtifactChooser( artifactTypes, chooser );
    chooser.setAccessory( accessory );
    chooser.setPreferredSize( new Dimension( 650, 380 ) );        
    File defaultFolder = null;
    FileObject defFo = master.getProjectDirectory();
    if (defFo != null) {
        defFo = defFo.getParent();
        if (defFo != null) {
            defaultFolder = FileUtil.toFile(defFo);
        }
    }
    chooser.setCurrentDirectory (getLastUsedArtifactFolder(defaultFolder));

    int option = chooser.showOpenDialog( parent ); // Show the chooser
          
    if ( option == JFileChooser.APPROVE_OPTION ) {

        File dir = chooser.getSelectedFile();
        dir = FileUtil.normalizeFile (dir);
        Project selectedProject = accessory.getProject( dir );

        if ( selectedProject == null ) {
            return null;
        }
        
        if ( selectedProject.getProjectDirectory().equals( master.getProjectDirectory() ) ) {
            DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( 
                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_RefToItself" ),
                NotifyDescriptor.INFORMATION_MESSAGE ) );
            return null;
        }
        
        if ( ProjectUtils.hasSubprojectCycles( master, selectedProject ) ) {
            DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( 
                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
                NotifyDescriptor.INFORMATION_MESSAGE ) );
            return null;
        }

        boolean noSuitableOutput = true;
        for (String type : artifactTypes) {
            if (AntArtifactQuery.findArtifactsByType(selectedProject, type).length > 0) {
                noSuitableOutput = false;
                break;
            }
        }
        if (noSuitableOutput) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    NbBundle.getMessage (AntArtifactChooser.class,"MSG_NO_JAR_OUTPUT")));
            return null;
        }
        
        setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
        
        Object[] tmp = new Object[accessory.jListArtifacts.getModel().getSize()];
        int count = 0;
        for(int i = 0; i < tmp.length; i++) {
            if (accessory.jListArtifacts.isSelectedIndex(i)) {
                tmp[count] = accessory.jListArtifacts.getModel().getElementAt(i);
                count++;
            }
        }
        AntArtifactItem artifactItems[] = new AntArtifactItem[count];
        System.arraycopy(tmp, 0, artifactItems, 0, count);
        return artifactItems;
    }
    else {
        return null; 
    }
            
}