Example usage for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.

Prototype

int CPE_SOURCE

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.

Usage

From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java

License:Open Source License

public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) {
    IClasspathEntry newEntry = null;// w w w.  j  a  v  a  2 s.  c o  m
    IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath);

    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes,
                entry.isExported());
        break;
    case IClasspathEntry.CPE_LIBRARY:
        newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported());
        break;
    case IClasspathEntry.CPE_VARIABLE:
        newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported());
        break;
    case IClasspathEntry.CPE_PROJECT:
        newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(),
                newAttributes, entry.isExported());
        break;
    case IClasspathEntry.CPE_SOURCE:
        newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes);
        break;
    }
    return newEntry;
}

From source file:org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator.java

License:Open Source License

/**
 * Checks if the specified Java classpath entry is a valid WTP virtual component reference.
 * Does not check the runtime path./*from   ww w .ja va2  s .  c o m*/
 * @param entry Raw or resolved classpath entry to validate. 
 * @param attrib The WTP classpath component dependency attribute. Null if it has not yet been set.
 * @param isWebApp True if the target project is associated with a web project.
 * @param project The parent project.
 * @param data Data required for validation. Can be computed once for the project and reused.
 * @return IMessages representing validation results.
 */
public static IMessage[] validateVirtualComponentEntry(final IClasspathEntry entry,
        final IClasspathAttribute attrib, final boolean isWebApp, final IProject project,
        final ClasspathDependencyValidatorData data) {
    List results = new ArrayList();
    if (entry == null) {
        return (IMessage[]) results.toArray(new IMessage[results.size()]);
    }

    final int kind = entry.getEntryKind();
    final boolean isFile = !ClasspathDependencyUtil.isClassFolderEntry(entry);

    if (kind == IClasspathEntry.CPE_PROJECT) {
        // Project cp entry
        // Allow faceted projects only, and not plain java projects
        boolean isFacetedProject = false;
        IProject referencedProject = ResourcesPlugin.getWorkspace().getRoot()
                .getProject(entry.getPath().toString());
        try {
            isFacetedProject = FacetedProjectFramework.isFacetedProject(referencedProject);
        } catch (CoreException ce) {
            //Ignore. Thrown when project metadata cannot be read. In that case we will treat the project as non faceted 
        }
        if (!isFacetedProject) {
            results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                    IMessage.HIGH_SEVERITY, ProjectClasspathEntry, new String[] { entry.getPath().toString() },
                    project));
            return (IMessage[]) results.toArray(new IMessage[results.size()]);
        }
    } else if (kind == IClasspathEntry.CPE_SOURCE) {

        // Source cp entry

        results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                IMessage.HIGH_SEVERITY, SourceEntry, new String[] { entry.getPath().toString() }, project));
        return (IMessage[]) results.toArray(new IMessage[results.size()]);
    } else if (kind == IClasspathEntry.CPE_CONTAINER) {

        // get the set of classpath container IDs that should be filtered
        List filteredIDs = ClasspathDependencyExtensions.get().getFilteredClasspathContainerIDs();
        final IPath path = entry.getPath();
        for (int i = 0; i < filteredIDs.size(); i++) {
            final String id = (String) filteredIDs.get(i);
            if (path.segment(0).equals(id)) {
                // filtered classpath container
                results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                        IMessage.HIGH_SEVERITY, FilteredContainer, new String[] { entry.getPath().toString() },
                        project));
                return (IMessage[]) results.toArray(new IMessage[results.size()]);
            }
        }

    } else if (kind == IClasspathEntry.CPE_LIBRARY) {
        if (!isFile) {
            final IContainer[] mappedClassFolders = data.getMappedClassFolders();
            final IResource resource = ClasspathDependencyUtil.getEntryResource(entry);
            if (resource != null) {
                final IPath fullClassFolderPath = resource.getFullPath();
                boolean alreadyMapped = false;
                for (int j = 0; j < mappedClassFolders.length; j++) {
                    if (fullClassFolderPath.equals(mappedClassFolders[j].getFullPath())) {
                        // entry resolves to same file as existing class folder mapping, skip
                        alreadyMapped = true;
                        break;
                    }
                }

                // Class folder reference; ensure this is not already mapped via the component file.
                if (alreadyMapped) {
                    results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                            IMessage.HIGH_SEVERITY, DuplicateClassFolderEntry,
                            new String[] { entry.getPath().toString() }, project));
                }
            }
        }
    }

    //       final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp, !isFile);
    //       if (!isWebApp) {
    //          // only a ../ or / mapping is currently legal in a non-web context
    //          if (!(runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH) 
    //                || runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_COMPONENT_PATH))) { 
    //             results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
    //                   IMessage.HIGH_SEVERITY, InvalidNonWebRuntimePath, new String[]{entry.getPath().toString(), runtimePath.toString()}, project));
    //          }
    //       } else {
    //          String pathStr = runtimePath.toString();
    //          // can only be ../, /WEB-INF/lib or /WEB-INF/classes
    //          if (!runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH) 
    //             && !runtimePath.equals(IClasspathDependencyConstants.WEB_INF_LIB_PATH)
    //             && !runtimePath.equals(IClasspathDependencyConstants.WEB_INF_CLASSES_PATH)) { 
    //             results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
    //                   IMessage.HIGH_SEVERITY, InvalidWebRuntimePath, new String[]{entry.getPath().toString(), pathStr}, project));
    //          }
    //       }

    return (IMessage[]) results.toArray(new IMessage[results.size()]);
}

From source file:org.eclipse.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java

License:Open Source License

/**
 * Updates the specified Java project so that only the specified classpath entries have
 * the WTP component dependency attribute.
 * @param javaProject Target Java project.
 * @param entries Classpath entries that should have the component dependency attribute. Map from IClasspathEntry
 * to the IClasspathAttribute for the WTP classpath component dependency.
 * @param modifyComponentDep True if modifying the dependency attribute, false if modifying the non-dependency attribute.
 * @throws CoreException Thrown if an error is encountered.
 */// ww w  .  jav a 2  s .co m
private void updateDependencyAttributes(final IJavaProject javaProject, final Map entriesWithAttrib,
        final boolean modifyComponentDep, final boolean isLegacyJ2EE) throws CoreException {
    if (javaProject == null || !javaProject.getProject().isAccessible()) {
        return;
    }

    final List updatedClasspath = new ArrayList();
    final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    boolean needToUpdateClasspath = false;
    IClasspathAttribute attrib = UpdateClasspathAttributeUtil.createDependencyAttribute();
    if (!modifyComponentDep) {
        attrib = UpdateClasspathAttributeUtil.createNonDependencyAttribute();
    }
    for (int i = 0; i < rawClasspath.length; i++) {
        IClasspathEntry entry = rawClasspath[i];
        final int kind = entry.getEntryKind();
        boolean hasAttribute = ClasspathDependencyUtil
                .checkForComponentDependencyAttribute(entry,
                        modifyComponentDep ? DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY
                                : DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY,
                        isLegacyJ2EE) != null;
        boolean shouldHaveAttribute = entriesWithAttrib.containsKey(entry);
        boolean updateAttributes = false;
        IClasspathAttribute[] updatedAttributes = null;
        if (shouldHaveAttribute) {
            if (!hasAttribute) {
                // should have the attribute and currently missing it
                attrib = (IClasspathAttribute) entriesWithAttrib.get(entry);
                updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, true);
                needToUpdateClasspath = true;
                updateAttributes = true;
            }
        } else if (hasAttribute) {
            // should not have the attribute and currently has it
            updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, false);
            needToUpdateClasspath = true;
            updateAttributes = true;
        }

        if (updateAttributes) {
            switch (kind) {
            case IClasspathEntry.CPE_CONTAINER:
                entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), updatedAttributes,
                        entry.isExported());
                break;
            case IClasspathEntry.CPE_LIBRARY:
                entry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                        entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes,
                        entry.isExported());
                break;
            case IClasspathEntry.CPE_VARIABLE:
                entry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                        entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes,
                        entry.isExported());
                break;
            case IClasspathEntry.CPE_PROJECT: // although project entries are not yet supported, allow the attribute here and let the validator flag as an error
                entry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(),
                        entry.combineAccessRules(), updatedAttributes, entry.isExported());
                break;
            case IClasspathEntry.CPE_SOURCE: // although source entries are not supported, allow the attribute here and let the validator flag as an error
                entry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                        entry.getExclusionPatterns(), entry.getOutputLocation(), updatedAttributes);
                break;
            }
        }

        updatedClasspath.add(entry);
    }
    if (needToUpdateClasspath) {
        final IClasspathEntry[] updatedCPArray = (IClasspathEntry[]) updatedClasspath
                .toArray(new IClasspathEntry[updatedClasspath.size()]);
        javaProject.setRawClasspath(updatedCPArray, null);
    }
}

From source file:org.eclipse.jst.j2ee.internal.dialogs.TypeJavaSearchScope.java

License:Open Source License

/**
 * Method addProject. This method adds all the classpath entries for the
 * current project to the search scope.//from   w  ww.j a  v  a 2  s .  c o m
 * 
 * @param javaProject
 * @param includesPrereqProjects
 * @param visitedProjects
 * @throws JavaModelException
 */
public void addProject(IJavaProject javaProject, boolean includesPrereqProjects, HashSet visitedProjects)
        throws JavaModelException {
    IProject project = javaProject.getProject();
    if (!project.isAccessible() || !visitedProjects.add(project))
        return;

    this.addEnclosingProjectOrJar(project.getFullPath());

    IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
    IJavaModel model = javaProject.getJavaModel();
    for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            IPath path = entry.getPath();
            this.add(path, true);
            this.addEnclosingProjectOrJar(path);
            break;
        case IClasspathEntry.CPE_PROJECT:
            if (includesPrereqProjects) {
                this.add(model.getJavaProject(entry.getPath().lastSegment()), true, visitedProjects);
            }
            break;
        case IClasspathEntry.CPE_SOURCE:
            this.add(entry.getPath(), true);
            break;
        }
    }
}

From source file:org.eclipse.jst.j2ee.internal.dialogs.TypeJavaSearchScope.java

License:Open Source License

/**
 * Method add. This method filters out all the classpath entries of the
 * project which are not exported./*from w  w w. j  a  v a2 s.c om*/
 * 
 * @param javaProject
 * @param includesPrereqProjects
 * @param visitedProjects
 * @throws JavaModelException
 */
public void add(IJavaProject javaProject, boolean includesPrereqProjects, HashSet visitedProjects)
        throws JavaModelException {
    IProject project = javaProject.getProject();
    if (!project.isAccessible() || !visitedProjects.add(project))
        return;

    this.addEnclosingProjectOrJar(project.getFullPath());

    IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
    IJavaModel model = javaProject.getJavaModel();
    for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        if (includeExportedClassPathEntriesOnly()) {
            if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE)
                continue;
        }
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            IPath path = entry.getPath();
            this.add(path, true);
            this.addEnclosingProjectOrJar(path);
            break;
        case IClasspathEntry.CPE_PROJECT:
            if (includesPrereqProjects) {
                this.add(model.getJavaProject(entry.getPath().lastSegment()), true, visitedProjects);
            }
            break;
        case IClasspathEntry.CPE_SOURCE:
            this.add(entry.getPath(), true);
            break;
        }
    }
}

From source file:org.eclipse.jst.j2ee.internal.J2EEComponentProjectMigrator.java

License:Open Source License

private void replaceDeployablesOutputIfNecessary(IProject proj) {

    IJavaProject jproj = JemProjectUtilities.getJavaProject(proj);
    final IClasspathEntry[] current;
    boolean deployablesFound = false;
    try {/*from   w w  w .  j  a  v  a2  s. c o  m*/
        current = jproj.getRawClasspath();
        List updatedList = new ArrayList();
        IPath sourcePath = null;
        for (int i = 0; i < current.length; i++) {
            IClasspathEntry entry = current[i];
            if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) && (entry.getOutputLocation() != null
                    && entry.getOutputLocation().toString().indexOf(OLD_DEPLOYABLES_PATH) != -1)) {
                sourcePath = entry.getPath();
                updatedList.add(JavaCore.newSourceEntry(sourcePath));
                deployablesFound = true;
            } else
                updatedList.add(entry);
        }
        if (deployablesFound) {
            IClasspathEntry[] updated = (IClasspathEntry[]) updatedList
                    .toArray(new IClasspathEntry[updatedList.size()]);
            jproj.setRawClasspath(updated, null);
            jproj.save(null, true);
        }
    } catch (JavaModelException e) {
        J2EEUIPlugin.logError(e);
    }

}

From source file:org.eclipse.jst.j2ee.internal.project.facet.UtilityFacetInstallDataModelProvider.java

License:Open Source License

@Override
public Object getDefaultProperty(String propertyName) {
    if (FACET_ID.equals(propertyName)) {
        return UTILITY;
    } else if (propertyName.equals(MODULE_URI)) {
        String projectName = model.getStringProperty(FACET_PROJECT_NAME).replace(' ', '_');
        return projectName + IJ2EEModuleConstants.JAR_EXT;
    } else if (propertyName.equals(CONFIG_FOLDER)) {
        final IFacetedProjectWorkingCopy fpjwc = (IFacetedProjectWorkingCopy) getProperty(
                FACETED_PROJECT_WORKING_COPY);

        if (this.javaFacetInstallConfig != null) {
            final List<IPath> sourceFolders = this.javaFacetInstallConfig.getSourceFolders();

            if (!sourceFolders.isEmpty()) {
                return sourceFolders.get(0).toPortableString();
            }//from   w  w w .  j a  va  2s .  co  m
        } else {
            final IFacetedProject fpj = fpjwc.getFacetedProject();

            if (fpj.hasProjectFacet(JavaFacet.FACET)) {
                try {
                    final IJavaProject jpj = JavaCore.create(fpj.getProject());

                    for (IClasspathEntry cpe : jpj.getRawClasspath()) {
                        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                            return cpe.getPath().removeFirstSegments(1).toPortableString();
                        }
                    }
                } catch (CoreException e) {
                    J2EEPlugin.logError(e);
                }
            }
        }
    }
    return super.getDefaultProperty(propertyName);
}

From source file:org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities.java

License:Open Source License

public static IPath getSourcePathOrFirst(IProject p, String defaultSourceName) {
    IJavaProject javaProj = JemProjectUtilities.getJavaProject(p);
    if (javaProj == null)
        return null;
    IClasspathEntry[] cp = null;/*from  w  w w. j av a  2  s  . c  o m*/
    try {
        cp = javaProj.getRawClasspath();
    } catch (JavaModelException ex) {
        J2EEPlugin.logError(ex);
        return null;
    }
    IClasspathEntry firstSource = null;
    IPath defaultSourcePath = null;
    if (defaultSourceName != null)
        defaultSourcePath = createPath(p, defaultSourceName);
    boolean found = false;
    for (int i = 0; i < cp.length; i++) {
        if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            // check if it contains /META-INF/MANIFEST.MF
            IPath sourceFolderPath = cp[i].getPath().removeFirstSegments(1);
            IFolder sourceFolder = p.getFolder(sourceFolderPath);
            if (isSourceFolderAnInputContainer(sourceFolder)) {
                found = true;
                if (firstSource == null) {
                    firstSource = cp[i];
                    if (defaultSourcePath == null)
                        break;
                }
                if (cp[i].getPath().equals(defaultSourcePath) && defaultSourcePath != null)
                    return defaultSourcePath.removeFirstSegments(1);
            }
        }
    }
    if (!found) {
        for (int i = 0; i < cp.length; i++) {
            if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                if (firstSource == null) {
                    firstSource = cp[i];
                    if (defaultSourcePath == null)
                        break;
                }
                if (cp[i].getPath().equals(defaultSourcePath) && defaultSourcePath != null)
                    return defaultSourcePath.removeFirstSegments(1);
            }
        }
    }
    if (firstSource == null)
        return null;
    if (firstSource.getPath().segment(0).equals(p.getName()))
        return firstSource.getPath().removeFirstSegments(1);
    return null;
}

From source file:org.eclipse.jst.j2ee.internal.servertarget.ServerTargetHelper.java

License:Open Source License

public static List getExistingNonServerTargetClasspath(IProject project) {
    IJavaProject javaProject = null;//from   w  w  w.  ja  va2 s  .c  o m
    List list = new ArrayList();
    try {
        javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
    } catch (Exception e) {
    }
    if (javaProject != null) {
        try {
            IClasspathEntry[] cp = javaProject.getRawClasspath();
            int size = cp.length;
            for (int i = 0; i < size; i++) {
                int entryKind = cp[i].getEntryKind();
                if (entryKind != IClasspathEntry.CPE_SOURCE && entryKind != IClasspathEntry.CPE_LIBRARY
                        && entryKind != IClasspathEntry.CPE_PROJECT
                        && (entryKind == IClasspathEntry.CPE_VARIABLE && isWASVariable(cp[i]))
                        && (entryKind != IClasspathEntry.CPE_CONTAINER
                                || !cp[i].getPath().segment(0).equals(SERVER_CONTAINER))) {
                    list.add(cp[i]);
                }
            }
        } catch (Exception e) {
        }
        return list;
    }
    return list;
}

From source file:org.eclipse.jst.j2ee.jca.project.facet.ConnectorFacetInstallDelegate.java

License:Open Source License

public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
        throws CoreException {
    if (monitor != null) {
        monitor.beginTask("", 1); //$NON-NLS-1$
    }//from   ww  w. j  ava 2 s  .com

    try {
        IDataModel model = (IDataModel) config;

        final IJavaProject jproj = JavaCore.create(project);

        // Add WTP natures.

        WtpUtils.addNatures(project);

        // Create the directory structure.

        final IWorkspace ws = ResourcesPlugin.getWorkspace();
        final IPath pjpath = project.getFullPath();

        // Setup the flexible project structure.

        final IVirtualComponent c = ComponentCore.createComponent(project, false);

        c.create(0, null);
        setOutputFolder(model, c);

        final IVirtualFolder root = c.getRootFolder();
        IFolder sourceFolder = null;
        String configFolder = null;
        configFolder = model.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER);
        Path configFolderPath = new Path(configFolder);
        root.createLink(configFolderPath, 0, null);
        J2EEModuleVirtualComponent.setDefaultDeploymentDescriptorFolder(root, configFolderPath, null);
        String configFolderName = model
                .getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER);
        IPath configFolderpath = pjpath.append(configFolderName);
        sourceFolder = ws.getRoot().getFolder(configFolderpath);

        if (fv == IJ2EEFacetConstants.JCA_17) {
            if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) {
                // Create the deployment descriptor (ra.xml) if one doesn't exist
                IFile rarFile = sourceFolder.getFile(new Path(J2EEConstants.RAR_DD_URI));
                if (!rarFile.exists()) {
                    try {
                        if (!rarFile.getParent().exists()
                                && (rarFile.getParent().getType() == IResource.FOLDER)) {
                            ((IFolder) rarFile.getParent()).create(true, true, monitor);
                        }
                        InputStream in = getClass().getResourceAsStream(CONNECTOR_XML_TEMPLATE_17);
                        rarFile.create(in, true, monitor);
                        populateDefaultContent(project, fv);
                    } catch (CoreException e) {
                        J2EEPlugin.logError(e);
                    }
                }
            }
        } else if (fv == IJ2EEFacetConstants.JCA_16) {
            if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) {
                // Create the deployment descriptor (ra.xml) if one doesn't exist
                IFile rarFile = sourceFolder.getFile(new Path(J2EEConstants.RAR_DD_URI));
                if (!rarFile.exists()) {
                    try {
                        if (!rarFile.getParent().exists()
                                && (rarFile.getParent().getType() == IResource.FOLDER)) {
                            ((IFolder) rarFile.getParent()).create(true, true, monitor);
                        }
                        InputStream in = getClass().getResourceAsStream(CONNECTOR_XML_TEMPLATE_16);
                        rarFile.create(in, true, monitor);
                        populateDefaultContent(project, fv);
                    } catch (CoreException e) {
                        J2EEPlugin.logError(e);
                    }
                }
            }
        } else if (!sourceFolder.getFile(J2EEConstants.RAR_DD_URI).exists()) {
            String ver = model.getStringProperty(IFacetDataModelProperties.FACET_VERSION_STR);
            int nVer = J2EEVersionUtil.convertVersionStringToInt(ver);

            IFile aFile = sourceFolder.getFile(new Path(J2EEConstants.RAR_DD_URI));
            OutputStream out = new WorkbenchByteArrayOutputStream(aFile);

            String template = null;
            if (nVer == J2EEVersionConstants.JCA_1_0_ID) {
                template = CONNECTOR_XML_TEMPLATE_10;
            } else if (nVer == J2EEVersionConstants.JCA_1_5_ID) {
                template = CONNECTOR_XML_TEMPLATE_15;
            }
            //            JCA 1.6 handled separately
            //            else {
            //               template = CONNECTOR_XML_TEMPLATE_16;
            //            }

            InputStream in = getClass().getResourceAsStream(template);
            if (in != null) {
                try {
                    ArchiveUtil.copy(in, out);
                } catch (IOException ioe) {
                    Logger.getLogger().logError(ioe);
                } finally {
                    try {
                        out.close();
                    } catch (IOException ioe) {
                        Logger.getLogger().logError(ioe);
                    } finally {
                        try {
                            in.close();
                        } catch (IOException ioe) {
                            Logger.getLogger().logError(ioe);
                        }
                    }
                }

                ConnectorArtifactEdit edit = null;
                try {
                    edit = new ConnectorArtifactEdit(project, false, true);
                    org.eclipse.jst.j2ee.jca.Connector connector = edit.getConnector();
                    connector.setDisplayName(project.getName());
                    // TODO: investigate setting the version and the impact on adopters
                    //connector.setVersion(ver);
                    edit.saveIfNecessary(new SubProgressMonitor(monitor, 1));
                } finally {
                    if (edit != null) {
                        edit.dispose();
                    }
                }
            } else {
                //without a template
                ConnectorArtifactEdit.createDeploymentDescriptor(project, nVer);
            } // if            
        }

        // add source folder maps
        final IClasspathEntry[] cp = jproj.getRawClasspath();
        for (int i = 0; i < cp.length; i++) {
            final IClasspathEntry cpe = cp[i];
            if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                root.createLink(cpe.getPath().removeFirstSegments(1), 0, null);
            }
        }

        IVirtualFile vf = c.getRootFolder().getFile(new Path(J2EEConstants.MANIFEST_URI));
        IFile manifestmf = vf.getUnderlyingFile();
        if (manifestmf == null || !manifestmf.exists()) {
            try {
                createManifest(project, c.getRootFolder().getUnderlyingFolder(), monitor);
            } catch (InvocationTargetException e) {
                Logger.getLogger().logError(e);
            } catch (InterruptedException e) {
                Logger.getLogger().logError(e);
            }
        }

        // Setup the classpath.
        ClasspathHelper.removeClasspathEntries(project, fv);

        if (!ClasspathHelper.addClasspathEntries(project, fv)) {
            // TODO: Support the no runtime case.
            // ClasspathHelper.addClasspathEntries( project, fv, <something> );
        }

        if (model.getBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.INSTALL_EAR_LIBRARY)) {
            final IPath earLibContainer = new Path(J2EEComponentClasspathContainer.CONTAINER_ID);
            addToClasspath(jproj, JavaCore.newContainerEntry(earLibContainer));
        }

        try {
            ((IDataModelOperation) model.getProperty(FacetDataModelProvider.NOTIFICATION_OPERATION))
                    .execute(monitor, null);
        } catch (ExecutionException e) {
            Logger.getLogger().logError(e);
        }

        if (monitor != null) {
            monitor.worked(1);
        }
    }

    finally {
        if (monitor != null) {
            monitor.done();
        }
    }

}