Java Code Examples for org.openide.filesystems.FileUtil#copyFile()

The following examples show how to use org.openide.filesystems.FileUtil#copyFile() . 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: SourceForBinaryImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCompletionWorks_69735() throws Exception {
    SuiteProject suite = generateSuite("suite");
    NbModuleProject project = TestBase.generateSuiteComponent(suite, "module");
    File library = new File(getWorkDir(), "test-library-0.1_01.jar");
    createJar(library, Collections.<String,String>emptyMap(), new Manifest());
    FileObject libraryFO = FileUtil.toFileObject(library);
    FileObject yyJar = FileUtil.copyFile(libraryFO, FileUtil.toFileObject(getWorkDir()), "yy");
    
    // library wrapper
    File suiteDir = suite.getProjectDirectoryFile();
    File wrapperDirF = new File(new File(getWorkDir(), "suite"), "wrapper");
    NbModuleProjectGenerator.createSuiteLibraryModule(
            wrapperDirF,
            "yy", // 69735 - the same name as jar
            "Testing Wrapper (yy)", // display name
            "org/example/wrapper/resources/Bundle.properties",
            suiteDir, // suite directory
            null,
            new File[] { FileUtil.toFile(yyJar)} );
    
    ApisupportAntUtils.addDependency(project, "yy", null, null, true, null);
    ProjectManager.getDefault().saveProject(project);
    
    URL wrappedJar = FileUtil.urlForArchiveOrDir(new File(wrapperDirF, "release/modules/ext/yy.jar"));
    assertEquals("no sources for wrapper", 0, SourceForBinaryQuery.findSourceRoots(wrappedJar).getRoots().length);
}
 
Example 2
Source File: ProjectOperations.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void rememberConfigurations () {
    FileObject fo = project.getProjectDirectory().getFileObject(ProjectConfigurations.CONFIG_PROPS_PATH);
    if (fo != null) {
        //Has configurations
        try {
            FileSystem fs = FileUtil.createMemoryFileSystem();
            FileUtil.copyFile(fo, fs.getRoot(),fo.getName());
            fo = project.getProjectDirectory().getFileObject("nbproject/private/configs");      //NOI18N
            if (fo != null && fo.isFolder()) {
                FileObject cfgs = fs.getRoot().createFolder("configs");                         //NOI18N
                for (FileObject child : fo.getChildren()) {
                    FileUtil.copyFile(child, cfgs, child.getName());
                }
            }
            configs = fs;
        } catch (IOException ioe) {
            Exceptions.printStackTrace(ioe);
        }
    }
}
 
Example 3
Source File: ProjectParserTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testParseJSFLibraryRegistryV2() throws IOException {
    FileObject fo = FileUtil.toFileObject(new File(getDataDir(), "org.eclipse.wst.common.project.facet.core.xml"));
    FileObject dest = FileUtil.createFolder(new File(getWorkDir(), "ep/.settings/"));
    FileUtil.copyFile(fo, dest, fo.getName(), fo.getExt());
    Facets facets = ProjectParser.readProjectFacets(new File(getWorkDir(), "ep/"), 
        Collections.<String>singleton("org.eclipse.wst.common.project.facet.core.nature"));
    assertNotNull(facets);
    assertEquals(3, facets.getInstalled().size());
    assertEquals("jst.java", facets.getInstalled().get(0).getName());
    assertEquals("6.0", facets.getInstalled().get(0).getVersion());
    assertEquals("jst.web", facets.getInstalled().get(1).getName());
    assertEquals("2.4", facets.getInstalled().get(1).getVersion());
    assertEquals("jst.jsf", facets.getInstalled().get(2).getName());
    assertEquals("1.1", facets.getInstalled().get(2).getVersion());
    facets = ProjectParser.readProjectFacets(new File(getWorkDir(), "ep/"), 
        Collections.<String>singleton("org.XXX"));
    assertNull(facets);
}
 
Example 4
Source File: ResultsManager.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void exportSnapshot(FileObject selectedSnapshot, FileObject targetFolder, String fileName, String fileExt) {
    if (checkFileExists(new SelectedFile(targetFolder, fileName, fileExt))) {
        try {
            FileUtil.copyFile(selectedSnapshot, targetFolder, fileName, fileExt);
        } catch (Throwable t) {
            LOGGER.log(Level.INFO, t.getMessage(), t);
            String msg = t.getLocalizedMessage().replace("<", "&lt;").replace(">", "&gt;"); // NOI18N
            ProfilerDialogs.displayError(Bundle.ResultsManager_SnapshotExportFailedMsg(msg));
        }
    }
}
 
Example 5
Source File: PersistenceEditorTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initDataObject() throws IOException{
    String persistenceFile = getDataDir().getAbsolutePath() + PATH;
    FileObject original = FileUtil.toFileObject(new File(persistenceFile));
    
    FileObject workDirFO = FileUtil.toFileObject(getWorkDir());
    this.ddFile = FileUtil.copyFile(original, workDirFO, "persistence_copy");
    this.dataObject = (PUDataObject) DataObject.find(ddFile);
    MockLookup.setInstances(dataObject);
    this.mvElement = new PersistenceToolBarMVElement(MockLookup.getDefault());
    
    Persistence persistence = dataObject.getPersistence();
    assertSame(2, persistence.getPersistenceUnit().length);
    assertEquals("em", persistence.getPersistenceUnit(0).getName());
    assertEquals("em2", persistence.getPersistenceUnit(1).getName());
}
 
Example 6
Source File: LibraryCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - library name",
    "# {1} - version name",
    "LibraryCustomizer.installingLibrary=Installing version {1} of {0}."
})
private void installLibrary(FileObject librariesFolder,
        Library.Version version, File[] libraryFiles) throws IOException {
    progressHandle.progress(Bundle.LibraryCustomizer_installingLibrary(version.getLibrary().getName(), version.getName()));
    String libraryName = version.getLibrary().getName();
    FileObject libraryFob = FileUtil.createFolder(librariesFolder, libraryName);

    FileObject projectFob = project.getProjectDirectory();
    File projectDir = FileUtil.toFile(projectFob);
    String[] fileNames = version.getFiles();
    String[] localFiles = new String[fileNames.length];
    for (int i=0; i<fileNames.length; i++) {
        FileObject tmpFob = FileUtil.toFileObject(libraryFiles[i]);
        String fileName = fileNames[i];
        int index = fileName.lastIndexOf('.');
        if (index != -1) {
            fileName = fileName.substring(0, index);
        }
        String[] path = fileName.split("/"); // NOI18N
        FileObject fileFolder = libraryFob;
        for (int j=0; j<path.length-1; j++) {
            fileFolder = FileUtil.createFolder(fileFolder, path[j]);
        }
        FileObject fob = FileUtil.copyFile(tmpFob, fileFolder, path[path.length-1]);
        if (!libraryFiles[i].delete()) {
            LOGGER.log(Level.INFO, "Cannot delete file {0}", libraryFiles[i]);
        }
        File file = FileUtil.toFile(fob);
        localFiles[i] = PropertyUtils.relativizeFile(projectDir, file);
    }
    version.setFileInfo(fileNames, localFiles);
}
 
Example 7
Source File: CreateFromTemplateHandlerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FileObject createFromTemplate(
    FileObject orig, FileObject f, String n,
    Map<String, Object> p
) throws IOException {
    origObject.add(orig);
    fileObject.add(f);
    name = n;
    parameters = p;

    return FileUtil.copyFile(orig, f, name);
}
 
Example 8
Source File: WSITModelSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void copyImports(final WSDLModel model, final FileObject srcFolder, Collection<FileObject> createdFiles) throws CatalogModelException {
    
    FileObject modelFO = Utilities.getFileObject(model.getModelSource());
    
    try {
        FileObject configFO = FileUtil.copyFile(modelFO, srcFolder, modelFO.getName(), CONFIG_WSDL_EXTENSION);
        if (createdFiles != null) {
            createdFiles.add(configFO);
        }
        
        WSDLModel newModel = getModelFromFO(configFO, true);
        
        removePolicies(newModel);
        removeTypes(newModel);
        
        Collection<Import> oldImports = model.getDefinitions().getImports();
        Collection<Import> newImports = newModel.getDefinitions().getImports();
        Iterator<Import> newImportsIt = newImports.iterator();
        for (Import i : oldImports) {
            WSDLModel oldImportedModel = i.getImportedWSDLModel();
            FileObject oldImportFO = Utilities.getFileObject(oldImportedModel.getModelSource());
            newModel.startTransaction();
            try {
                newImportsIt.next().setLocation(oldImportFO.getName() + "." + CONFIG_WSDL_EXTENSION);
            } finally {
                newModel.endTransaction();
            }
            copyImports(oldImportedModel, srcFolder, createdFiles);
        }
    } catch (IOException e) {
        // ignore - this happens when files are imported recursively
        logger.log(Level.FINE, null, e);
    }
}
 
Example 9
Source File: JFXProjectUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Adds FX specific build script jfx-impl.xml to project build system
 * @param p
 * @param dirFO
 * @param type
 * @throws IOException 
 */
static void createJfxExtension(Project p, FileObject dirFO, WizardType type) throws IOException {
    FileObject templateFO = FileUtil.getConfigFile("Templates/JFX/jfx-impl.xml"); // NOI18N
    if (templateFO != null) {
        FileObject nbprojectFO = dirFO.getFileObject("nbproject"); // NOI18N
        FileObject jfxBuildFile = FileUtil.copyFile(templateFO, nbprojectFO, "jfx-impl"); // NOI18N
        if (type == JavaFXProjectWizardIterator.WizardType.SWING) {
            FileObject templatesFO = nbprojectFO.getFileObject("templates"); // NOI18N
            if (templatesFO == null) {
                templatesFO = nbprojectFO.createFolder("templates"); // NOI18N
            }
            FileObject swingTemplateFO1 = FileUtil.getConfigFile("Templates/JFX/FXSwingTemplate.html"); // NOI18N
            if (swingTemplateFO1 != null) {
                FileUtil.copyFile(swingTemplateFO1, templatesFO, "FXSwingTemplate"); // NOI18N
            }
            FileObject swingTemplateFO2 = FileUtil.getConfigFile("Templates/JFX/FXSwingTemplateApplet.jnlp"); // NOI18N
            if (swingTemplateFO1 != null) {
                FileUtil.copyFile(swingTemplateFO2, templatesFO, "FXSwingTemplateApplet"); // NOI18N
            }
            FileObject swingTemplateFO3 = FileUtil.getConfigFile("Templates/JFX/FXSwingTemplateApplication.jnlp"); // NOI18N
            if (swingTemplateFO1 != null) {
                FileUtil.copyFile(swingTemplateFO3, templatesFO, "FXSwingTemplateApplication"); // NOI18N
            }
        }
        JFXProjectUtils.addExtension(p);
    }
}
 
Example 10
Source File: DDEditorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private File getDDFile() {
    try {
        final FileObject originalDD = FileUtil.toFileObject(Helper.getDDFile(getDataDir()));
        FileObject result = FileUtil.copyFile(originalDD, FileUtil.toFileObject(getWorkDir()), originalDD.getName());
        return FileUtil.toFile(result);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
}
 
Example 11
Source File: JavaFXSampleProjectIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public java.util.Set<DataObject> instantiate(org.openide.loaders.TemplateWizard templateWizard) throws java.io.IOException {
    File projectLocation = (File) wiz.getProperty(WizardProperties.PROJECT_DIR);
    if(projectLocation == null) {
        warnIssue204880("Wizard property " + WizardProperties.PROJECT_DIR + " is null."); // NOI18N
        throw new IOException(); // return to wizard
    }
    String name = (String) wiz.getProperty(WizardProperties.NAME);
    if(name == null) {
        warnIssue204880("Wizard property " + WizardProperties.NAME + " is null."); // NOI18N
        throw new IOException(); // return to wizard
    }
    String platformName = (String) wiz.getProperty(JavaFXProjectUtils.PROP_JAVA_PLATFORM_NAME);
    if(platformName == null) {
        warnIssue204880("Wizard property " + JavaFXProjectUtils.PROP_JAVA_PLATFORM_NAME + " is null."); // NOI18N
        throw new IOException(); // return to wizard
    }
    FileObject templateFO = templateWizard.getTemplate().getPrimaryFile();
    FileObject prjLoc = JavaFXSampleProjectGenerator.createProjectFromTemplate(
            templateFO, projectLocation, name, platformName);
    java.util.Set<DataObject> set = new java.util.HashSet<DataObject>();
    set.add(DataObject.find(prjLoc));

    // open file from the project specified in the "defaultFileToOpen" attribute
    Object openFile = templateFO.getAttribute("defaultFileToOpen"); // NOI18N
    if (openFile instanceof String) {
        FileObject openFO = prjLoc.getFileObject((String) openFile);
        set.add(DataObject.find(openFO));
    }
    // also open a documentation file registered for this project
    // and copy the .url file for it to the project (#71985)
    FileObject docToOpen = FileUtil.getConfigFile(
            "org-netbeans-modules-javafx2-samples/OpenAfterCreated/" + templateFO.getName() + ".url"); // NOI18N
    if (docToOpen != null) {
        docToOpen = FileUtil.copyFile(docToOpen, prjLoc, "readme"); // NOI18N
        set.add(DataObject.find(docToOpen));
    }

    return set;
}
 
Example 12
Source File: SoapClientServletCodeGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void preGenerateRpcClient(SoapClientOperationInfo info, WSService service) throws IOException {
    WebServicesClientSupport support = WebServicesClientSupport.getWebServicesClientSupport(getTargetFile());
    if (support != null) {
        String wsdlLocation = info.getWsdlLocation();
        File wsdlFile = new File(wsdlLocation);
        FileObject wsdlFO = FileUtil.toFileObject(wsdlFile);  //wsdl file in user directory
        FileObject projectWsdlFolder = support.getWsdlFolder(true); //wsdl Folder in project
        //copy wsdl file to wsdl directory in project
        if (projectWsdlFolder.getFileObject(wsdlFO.getName(), wsdlFO.getExt()) == null) {
            FileUtil.copyFile(wsdlFO, projectWsdlFolder, wsdlFO.getName());
        }

        //look for the mapping file and copy it to project
        FileObject catalogDir = getCatalogDir(info);
        if (catalogDir != null) {
            FileObject mappingFO = catalogDir.getFileObject("mapping.xml");   //NOI18N
            if (mappingFO != null) {
                if (projectWsdlFolder.getFileObject(mappingFO.getName(), mappingFO.getExt()) == null) {
                    FileUtil.copyFile(mappingFO, projectWsdlFolder, mappingFO.getName());
                }
            }
        }
        String serviceName = "service/" + service.getName();  //NOI18N
        String fqServiceName = service.getJavaName();

        wsdlLocation = wsdlLocation.substring(wsdlLocation.lastIndexOf(File.separator) + 1);
        wsdlLocation = "WEB-INF/wsdl/" + wsdlLocation;  //NOI18N
        String mappingFile = "WEB-INF/wsdl/mapping.xml";   //NOI18N
        List<? extends WSPort> ports = service.getPorts();
        String[] portClasses = new String[ports.size()];
        for (int i = 0; i < ports.size(); i++) {
            portClasses[i] = ports.get(i).getJavaName();
        }
        support.addServiceClientReference(serviceName, fqServiceName, wsdlLocation, mappingFile, portClasses);
    }
}
 
Example 13
Source File: ProjectOperations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void restoreConfigurations (final Operations original) {
    final FileSystem fs = original.configs;
    original.configs = null;
    if (fs != null) {
        try {
            FileObject fo = fs.getRoot().getFileObject("config.properties");        //NOI18N
            if (fo != null) {
                FileObject privateFolder = FileUtil.createFolder(project.getProjectDirectory(), "nbproject/private");  //NOI18N
                if (privateFolder != null) {
                    // #131857: SyncFailedException : check for file existence before FileUtil.copyFile
                    FileObject oldFile = privateFolder.getFileObject(fo.getName(), fo.getExt());
                    if (oldFile != null) {
                        //Probably delete outside of IDE + move. First try to repair FS cache
                        privateFolder.refresh();
                        oldFile = privateFolder.getFileObject(fo.getName(), fo.getExt());
                        if (oldFile != null) {
                            //The file still exists, delete it.
                            oldFile.delete();
                        }
                    }

                    FileUtil.copyFile(fo, privateFolder, fo.getName());
                }
            }
            fo = fs.getRoot().getFileObject("configs");                             //NOI18N
            if (fo != null) {
                FileObject configsFolder = FileUtil.createFolder(project.getProjectDirectory(), "nbproject/private/configs");  //NOI18N
                if (configsFolder != null) {
                    for (FileObject child : fo.getChildren()) {
                        FileUtil.copyFile(child, configsFolder, child.getName());
                    }
                }
            }
        } catch (IOException ioe) {
            Exceptions.printStackTrace(ioe);
        }
    }
}
 
Example 14
Source File: TestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void copyEntityClasses() throws Exception {
    File entityClassDataDir = new File(getDataDir(), TESTSRC_ACME);
    FileObject entityClassDataDirFO = FileUtil.toFileObject(entityClassDataDir);
    for (FileObject fo : entityClassDataDirFO.getChildren()) {
        if (fo.isFolder()) continue;
        FileUtil.copyFile(fo, entityClassDirFO, fo.getName());
    }
}
 
Example 15
Source File: GeneratorTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void deepCopy(FileObject source, FileObject targetDirectory) throws IOException {
    for (FileObject child : source.getChildren()) {
        if (child.isFolder()) {
            FileObject target = targetDirectory.createFolder(child.getNameExt());
            
            deepCopy(child, target);
        } else {
            FileUtil.copyFile(child, targetDirectory, child.getName());
        }
    }
}
 
Example 16
Source File: JB7Deployer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static String deployFile(File file, File deployDir) throws IOException, InterruptedException {
    FileObject foIn = FileUtil.toFileObject(file);
    FileObject foDestDir = FileUtil.toFileObject(deployDir);
    if (foIn == null) {
        return NbBundle.getMessage(JB7Deployer.class, "MSG_DeployFileMissing", file.getAbsolutePath());
    } else if (foDestDir == null) {
        return NbBundle.getMessage(JB7Deployer.class, "MSG_DeployDirMissing", deployDir.getAbsolutePath());
    }

    File toDeploy = new File(deployDir + File.separator + file.getName());

    FileUtil.copyFile(foIn, foDestDir, foIn.getName());

    final long deployTime = toDeploy.lastModified();
    File statusFile = new File(deployDir, file.getName() + ".deployed"); // NOI18N
    File failedFile = new File(deployDir, file.getName() + ".failed"); // NOI18N
    File progressFile = new File(deployDir, file.getName() + ".isdeploying"); // NOI18N

    int i = 0;
    int limit = ((int) TIMEOUT / POLLING_INTERVAL);
    do {
        Thread.sleep(POLLING_INTERVAL);
        i++;
        // what this condition says
        // we are waiting and either there is progress file
        // or (there is not a new enough status file
        // and there is not a new enough failed file)
    } while (i < limit && progressFile.exists()
            || ((!statusFile.exists() || statusFile.lastModified() < deployTime)
            && (!failedFile.exists() || failedFile.lastModified() < deployTime)));

    if (failedFile.isFile()) {
        FileObject fo = FileUtil.toFileObject(failedFile);
        if (fo != null) {
            return fo.asText();
        }
        return NbBundle.getMessage(JBDeployer.class, "MSG_FAILED");
    } else if (!statusFile.isFile()) {
        return NbBundle.getMessage(JBDeployer.class, "MSG_TIMEOUT");
    }
    return null;
}
 
Example 17
Source File: XmlFileCreator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void run() throws IOException {
    result = FileUtil.copyFile(source, destFolder, name, ext);
}
 
Example 18
Source File: CopyOnSaveSupportTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void singleBasicTest(FileObject projectFileObject, String metaPrefix) throws Exception {
    File sampleXml = new File(getDataDir(), "ejb-jar.xml");
    FileObject sampleXmlFileObject = FileUtil.toFileObject(sampleXml);

    File destFolder = FileUtil.toFile(projectFileObject.getFileObject(metaPrefix));
    File destFile = new File(destFolder, "ejb-jar-backup.xml");
    FileObject toCheck = projectFileObject.getFileObject("build/jar/META-INF/ejb-jar-backup.xml");
    if (toCheck != null) {
        toCheck.delete();
    }

    FileObject webFileObject = FileUtil.toFileObject(destFile.getParentFile());

    // copy file
    FileObject destFileObject = FileUtil.copyFile(sampleXmlFileObject, webFileObject, "ejb-jar-backup");
    toCheck = projectFileObject.getFileObject("build/jar/META-INF/ejb-jar-backup.xml");
    assertFile(FileUtil.toFile(toCheck), sampleXml);

    // delete file
    destFileObject.delete();
    assertFalse(toCheck.isValid());

    // change file
    destFolder = FileUtil.toFile(projectFileObject.getFileObject(metaPrefix));
    File index = new File(destFolder, "ejb-jar.xml");
    FileObject indexFileObject = FileUtil.toFileObject(index);
    InputStream is = new BufferedInputStream(new FileInputStream(sampleXml));
    try {
        OutputStream os = new BufferedOutputStream(indexFileObject.getOutputStream());
        try {
            FileUtil.copy(is, os);
        } finally {
            os.close();
        }
    } finally {
        is.close();
    }

    toCheck = projectFileObject.getFileObject("build/jar/META-INF/ejb-jar.xml");
    assertFile(FileUtil.toFile(toCheck), sampleXml);

    // cleanup a bit
    toCheck.delete();
}
 
Example 19
Source File: SessionGenerator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void generateEJB21Xml() throws IOException {
    org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(pkg);
    FileObject ddFO = ejbModule.getDeploymentDescriptor();
    if (ddFO == null && ejbModule.getMetaInf() != null){
        String resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-2.1.xml";    //NOI18N
        ddFO = FileUtil.copyFile(FileUtil.getConfigFile(resource), ejbModule.getMetaInf(), "ejb-jar"); //NOI18N
    }
    org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = DDProvider.getDefault().getDDRoot(ddFO); // EJB 2.1
    if (ejbJar == null) {
        String fileName = ddFO == null ? null : FileUtil.getFileDisplayName(ddFO);
        Logger.getLogger(SessionGenerator.class.getName()).warning("EjbJar not found for " + fileName); //NOI18N
        return;
    }
    EnterpriseBeans beans = ejbJar.getEnterpriseBeans();
    Session session = null;
    if (beans == null) {
        beans  = ejbJar.newEnterpriseBeans();
        ejbJar.setEnterpriseBeans(beans);
    }
    session = beans.newSession();
    session.setEjbName(ejbName);
    session.setDisplayName(displayName);
    session.setEjbClass(packageNameWithDot + ejbClassName);

    if (hasRemote) {
        session.setRemote(packageNameWithDot + remoteName);
        session.setHome(packageNameWithDot + remoteHomeName);
    }
    if (hasLocal) {
        session.setLocal(packageNameWithDot + localName);
        session.setLocalHome(packageNameWithDot + localHomeName);
    }

    session.setSessionType(sessionType);
    session.setTransactionType("Container"); // NOI18N
    beans.addSession(session);
    // add transaction requirements
    AssemblyDescriptor assemblyDescriptor = ejbJar.getSingleAssemblyDescriptor();
    if (assemblyDescriptor == null) {
        assemblyDescriptor = ejbJar.newAssemblyDescriptor();
        ejbJar.setAssemblyDescriptor(assemblyDescriptor);
    }
    ContainerTransaction containerTransaction = assemblyDescriptor.newContainerTransaction();
    containerTransaction.setTransAttribute("Required"); //NOI18N
    org.netbeans.modules.j2ee.dd.api.ejb.Method method = containerTransaction.newMethod();
    method.setEjbName(ejbName);
    method.setMethodName("*"); //NOI18N
    containerTransaction.addMethod(method);
    assemblyDescriptor.addContainerTransaction(containerTransaction);
    ejbJar.write(ejbModule.getDeploymentDescriptor());
}
 
Example 20
Source File: EjbJarProjectGenerator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static AntProjectHelper createProjectImpl(final EjbJarProjectCreateData createData,
        final FileObject projectDir) throws IOException {

    String name = createData.getName();
    String serverInstanceID = createData.getServerInstanceID();

    FileObject srcRoot = projectDir.createFolder(DEFAULT_SRC_FOLDER); // NOI18N
    srcRoot.createFolder(DEFAULT_JAVA_FOLDER); //NOI18N
    if (!createData.skipTests()) {
        projectDir.createFolder(DEFAULT_TEST_FOLDER);
    }
    FileObject confRoot = srcRoot.createFolder(DEFAULT_DOC_BASE_FOLDER); // NOI18N
    
    //create a default manifest
    FileUtil.copyFile(FileUtil.getConfigFile("org-netbeans-modules-j2ee-ejbjarproject/MANIFEST.MF"), confRoot, "MANIFEST"); //NOI18N
    
    final AntProjectHelper h = setupProject(projectDir, name,
            "src", "test", null, null, null, createData.getJavaEEProfile(), serverInstanceID,
            createData.getLibrariesDefinition(), createData.skipTests());
    
    EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    ep.put(EjbJarProjectProperties.SOURCE_ROOT, DEFAULT_SRC_FOLDER); //NOI18N
    ep.setProperty(EjbJarProjectProperties.META_INF, "${"+EjbJarProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_DOC_BASE_FOLDER); //NOI18N
    ep.setProperty(EjbJarProjectProperties.SRC_DIR, "${"+EjbJarProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_JAVA_FOLDER); //NOI18N
    ep.setProperty(EjbJarProjectProperties.META_INF_EXCLUDES, "sun-cmp-mappings.xml"); // NOI18N
    Charset enc = FileEncodingQuery.getDefaultEncoding();
    ep.setProperty(EjbJarProjectProperties.SOURCE_ENCODING, enc.name());
    h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    
    EjbJarProject p = (EjbJarProject) ProjectManager.getDefault().findProject(h.getProjectDirectory());
    ProjectManager.getDefault().saveProject(p);
    
    final ReferenceHelper refHelper = p.getReferenceHelper();
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                copyRequiredLibraries(h, refHelper, createData);
                return null;
            }
        });
    } catch (MutexException ex) {
        Exceptions.printStackTrace(ex.getException());
    }
    
    // create ejb-jar.xml
    Profile profile = createData.getJavaEEProfile();
    if (!Profile.JAVA_EE_5.equals(profile) && !Profile.JAVA_EE_6_FULL.equals(profile) && !Profile.JAVA_EE_6_WEB.equals(profile) &&
            !Profile.JAVA_EE_7_FULL.equals(profile) && !Profile.JAVA_EE_7_WEB.equals(profile)) {
        String resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-2.1.xml";
        FileObject ddFile = FileUtil.copyFile(FileUtil.getConfigFile(resource), confRoot, "ejb-jar"); //NOI18N
        EjbJar ejbJar = DDProvider.getDefault().getDDRoot(ddFile);
        ejbJar.setDisplayName(name);
        ejbJar.write(ddFile);
    }
    if (createData.isCDIEnabled()) {
        DDHelper.createBeansXml(profile, confRoot);
    }
    
    return h;
}