Example usage for org.eclipse.jdt.core IJavaProject getOutputLocation

List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getOutputLocation.

Prototype

IPath getOutputLocation() throws JavaModelException;

Source Link

Document

Returns the default output location for this project as a workspace- relative absolute path.

Usage

From source file:edu.rice.cs.drjava.plugins.eclipse.repl.EclipseInteractionsModel.java

License:BSD License

private void _addProjectToClasspath(IJavaProject jProj, IJavaModel jModel, IWorkspaceRoot root)
        throws CoreException {
    // Get the project's location on disk
    IProject proj = jProj.getProject();//  www.  j a va 2 s.c o  m
    URI projRoot = proj.getDescription().getLocationURI();
    // Note: getLocation returns null if the default location is used
    //  (brilliant...)

    // Get the resolved classpath entries - this should filter out
    //   all CPE_VARIABLE and CPE_CONTAINER entries.
    IClasspathEntry entries[] = jProj.getResolvedClasspath(true);

    // For each of the classpath entries...
    for (int j = 0; j < entries.length; j++) {
        IClasspathEntry entry = entries[j];

        // Check what kind of entry it is...
        int kind = entry.getEntryKind();

        // And get the appropriate path.
        IPath path;
        switch (kind) {
        case IClasspathEntry.CPE_LIBRARY:
            // The raw location of a JAR.
            path = entry.getPath();
            //System.out.println("Adding library: " + path.toOSString());
            addToClassPath(path.toOSString());
            break;
        case IClasspathEntry.CPE_SOURCE:
            // The output location of source.
            // Need to append it to the user's workspace directory.
            path = entry.getOutputLocation();
            if (path == null) {
                path = jProj.getOutputLocation();
                //System.out.println(" output location from proj: " + path);
            }

            // At this point, the output location contains the project
            //  name followed by the actual output folder name

            if (projRoot != null && (!projRoot.isAbsolute() || projRoot.getScheme().equals("file"))) {
                // We have a custom project location, so the project name
                //  is not part of the *actual* output directory.  We need
                //  to remove the project name (first segment) and then
                //  append the rest of the output location to projRoot.
                path = path.removeFirstSegments(1);
                path = new Path(projRoot.getPath()).append(path);
            } else {
                // A null projRoot means use the default location, which
                //  *does* include the project name in the output directory.
                path = root.getLocation().append(path);
            }

            //System.out.println("Adding source: " + path.toOSString());
            //addToClassPath(path.toOSString());
            addBuildDirectoryClassPath(path.toOSString());
            break;
        case IClasspathEntry.CPE_PROJECT:
            // In this case, just the project name is given.
            // We don't actually need to add anything to the classpath,
            //  since the project is open and we will get its classpath
            //  on another pass.
            break;
        default:
            // This should never happen.
            throw new RuntimeException("Unsupported classpath entry type.");
        }
    }
}

From source file:es.bsc.servicess.ide.wizards.ServiceSsCommonWizardPage.java

License:Apache License

/**
 * A hook method that gets called when the package field has changed. The
 * method validates the package name and returns the status of the
 * validation. The validation also updates the package fragment model.
 * <p>//from   w  ww .  ja va 2s.com
 * Subclasses may extend this method to perform their own validation.
 * </p>
 * 
 * @return the status of the validation
 */
protected IStatus packageChanged() {
    StatusInfo status = new StatusInfo();
    IPackageFragmentRoot root = getPackageFragmentRoot();
    fPackageDialogField.enableButton(root != null);

    IJavaProject project = root != null ? root.getJavaProject() : null;

    String packName = getPackageText();
    if (packName.length() > 0) {
        IStatus val = validatePackageName(packName, project);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName,
                    val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(Messages.format(
                    NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
            // continue
        }
    } else {
        status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
    }

    if (project != null) {
        if (project.exists() && packName.length() > 0) {
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = project.getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow
                    // to name a package
                    // like the bin folder
                    IPath packagePath = rootPath.append(packName.replace('.', '/'));
                    if (outputPath.isPrefixOf(packagePath)) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                        return status;
                    }
                }
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
                // let pass
            }
        }

        fCurrPackage = root.getPackageFragment(packName);
    } else {
        status.setError(""); //$NON-NLS-1$
    }
    return status;
}

From source file:es.bsc.servicess.ide.wizards.ServiceSsNewProjectWizard.java

License:Apache License

@Override
protected void finishPage(IProgressMonitor arg0) {
    IJavaProject project;
    try {/* ww  w .  j av a 2s.c  o  m*/
        page2.performFinish(arg0);
        project = page2.getJavaProject();
        IPackageFragmentRoot[] pfr = project.getPackageFragmentRoots();

        if (pfr.length > 0) {
            // TODO: Try another way to get the main package fragment root, currently prf[0]
            IPackageFragment frag = pfr[0].createPackageFragment(page0.getPackageName(), true, arg0);
            IPackageFragment ce_frag = pfr[0].createPackageFragment(page0.getPackageName() + ".coreelements",
                    true, arg0);
            System.out.println("Created packages: " + frag.getElementName() + ", " + ce_frag.getElementName());
            IFolder out_folder = project.getProject().getFolder(ProjectMetadata.OUTPUT_FOLDER);
            out_folder.create(true, true, arg0);
            System.out.println("Folder created: " + out_folder.getFullPath().toOSString());
            IFolder classes_folder = out_folder.getFolder(ProjectMetadata.CLASSES_FOLDER);
            classes_folder.create(true, true, arg0);
            System.out.println("Folder created: " + classes_folder.getFullPath().toOSString());
            project.setOutputLocation(classes_folder.getFullPath(), arg0);
            System.out.println("OutpuLocation: " + project.getOutputLocation().toOSString());
            IFolder folder = project.getProject().getFolder(ProjectMetadata.METADATA_FOLDER);
            folder.create(true, true, arg0);

            IFile meta = folder.getFile(ProjectMetadata.METADATA_FILENAME);
            ProjectMetadata pr_meta;
            pr_meta = new ProjectMetadata(page1.getProjectName());
            pr_meta.setRuntimeLocation(page0.getRuntimeLocation());
            pr_meta.setSourceDir(pfr[0].getElementName());
            pr_meta.setMainPackageName(page0.getPackageName());
            pr_meta.addDependency(page0.getRuntimeLocation() + ProjectMetadata.ITJAR_EXT,
                    ProjectMetadata.JAR_DEP_TYPE);
            System.out.println(pr_meta.getString());
            meta.create(new ByteArrayInputStream(pr_meta.getString().getBytes()), true, arg0);
            createClasspathEntries(project, arg0);
            IFile projectFile = project.getProject().getFile(
                    frag.getPath().makeRelativeTo(project.getProject().getFullPath()).append("project.xml"));
            projectFile.create(initialProjectStream(), true, arg0);
            IFile resourcesFile = project.getProject().getFile(
                    frag.getPath().makeRelativeTo(project.getProject().getFullPath()).append("resources.xml"));
            resourcesFile.create(initialResourcesStream(), true, arg0);

        } else {
            MessageDialog.openError(getShell(), "Error creating metadata file ",
                    "There are not enough fragment roots for the project");
            page2.performCancel();
        }

    } catch (InterruptedException e) {
        MessageDialog.openError(getShell(), "Error creating project ", e.getMessage());
        page2.performCancel();
        // project.getProject().delete(true, arg0);
        e.printStackTrace();
    } catch (CoreException e) {
        MessageDialog.openError(getShell(), "Error creating project elements ", e.getMessage());
        page2.performCancel();
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        MessageDialog.openError(getShell(), "Error creating metadata file ", e.getMessage());
        page2.performCancel();
        e.printStackTrace();
    } catch (TransformerException e) {
        MessageDialog.openError(getShell(), "Error creating metadata file ", e.getMessage());
        page2.performCancel();
        e.printStackTrace();
    }

}

From source file:es.bsc.servicess.ide.wizards.ServiceSsNewServiceClassPage.java

License:Apache License

/**
 * A hook method that gets called when the package field has changed. The
 * method validates the package name and returns the status of the
 * validation. The validation also updates the package fragment model.
 * <p>/*from   ww w . j av  a 2 s  .  c  o m*/
 * Subclasses may extend this method to perform their own validation.
 * </p>
 * 
 * @return the status of the validation
 */
protected IStatus packageChanged() {
    StatusInfo status = new StatusInfo();
    IPackageFragmentRoot root = getPackageFragmentRoot();
    fPackageDialogField.enableButton(root != null);

    IJavaProject project = root != null ? root.getJavaProject() : null;

    String packName = getPackageText();
    if (packName.length() > 0) {
        IStatus val = validatePackageName(packName, project);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName,
                    val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(Messages.format(
                    NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
            // continue
        }
    } else {
        status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
    }

    if (project != null) {
        if (project.exists() && packName.length() > 0) {
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = project.getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow
                    // to name a package
                    // like the bin folder
                    IPath packagePath = rootPath.append(packName.replace('.', '/'));
                    if (outputPath.isPrefixOf(packagePath)) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                        return status;
                    }
                }
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
                // let pass
            }
        }
        fCurrPackage = root.getPackageFragment(packName);
    } else {
        status.setError(""); //$NON-NLS-1$
    }
    return status;
}

From source file:es.optsicom.res.client.launcher.local.LocalVersionedJavaShortcut.java

License:Eclipse Public License

private String creacionFicheros(IType type) {

    List<File> listaZip = new ArrayList<File>();

    //Creacion del fichero comprimido
    IProject project = type.getResource().getProject();
    IJavaProject jp = JavaCore.create(project);
    nombreProyecto = jp.getElementName();

    //Obtencion del directorio de trabajo
    IWorkspace ws = type.getResource().getWorkspace();
    nombreWorkspace = ws.getRoot().getLocation().toOSString();

    String nombreZip = "";
    try {//from www .j av  a2  s .  c  om
        String dirBinarios = nombreWorkspace + jp.getOutputLocation().toOSString();
        File binarios = new File(dirBinarios);
        IClasspathEntry[] cpe = jp.getRawClasspath();
        listaZip = getFicheros(cpe, type, listaZip, nombreProyecto);
        vaciarDependencias();

        listaZip.add(binarios);
        File[] filesZip = listaZip.toArray(new File[listaZip.size()]);
        ZipCreator zc = new ZipCreator();
        File zipFileFolder = new File(nombreWorkspace, nombreProyecto);
        File zipFile = new File(zipFileFolder, nombreProyecto + RESClientPlugin.getTimeStamp() + ".zip");
        nombreZip = zipFile.getAbsolutePath();
        zc.zip(filesZip, nombreZip);
    } catch (JavaModelException e) {
        RESClientPlugin.log(e);
        MessageDialog.openError(getShell(), "Error while retrieving project classpath files", e.getMessage());
    } catch (ZipCreatorException e) {
        RESClientPlugin.log(e);
        MessageDialog.openError(getShell(), "Error while creating zip file", e.getMessage());
    }

    return nombreZip;
}

From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java

License:Eclipse Public License

private void calculateDependencies(IClasspathEntry[] cpe, IProject project)
        throws DependenciesResolverException {
    try {/*from ww  w  .  j a  v a2 s .co  m*/

        IWorkspace workspace = project.getWorkspace();
        IPath workspacePath = workspace.getRoot().getLocation();
        String nombreWorkspace = workspacePath.toString();
        IJavaProject jp = JavaCore.create(project);

        if (!dependencies.contains(project.getLocation().toString())) {
            // Aadimos la carpeta bin
            classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile());
            classpath.add(jp.getOutputLocation().toString());
        }

        for (IClasspathEntry cpEntry : cpe) {

            String path = cpEntry.getPath().toString();
            String dependency = nombreWorkspace.concat(path);

            if (!dependencies.contains(dependency)) {
                RESClientPlugin.log("Adding dependency: " + dependency);
                dependencies.add(dependency);

                if (cpEntry.getOutputLocation() != null) {
                    RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString());
                    classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString());
                    classpathFiles.add(cpEntry.getOutputLocation().toFile());
                }

                int tipo = cpEntry.getEntryKind();

                //Si la dependencia es de una libreria(

                if (tipo == IClasspathEntry.CPE_LIBRARY) {

                    String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString();
                    //mgarcia: Optsicom res Evolution
                    if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) {
                        classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString()));

                        //Aadimos las dependencias a las properties
                        RESClientPlugin.log("Adding library: " + dep);
                        classpath.add(cpEntry.getPath().toString());
                    } else {
                        throw new DependenciesResolverException();
                    }

                } else if (tipo == IClasspathEntry.CPE_PROJECT) {

                    //                  File[] files = new File(dependency).listFiles();
                    //                  for (File f : files){
                    //                     lista.add(f);
                    //                     String dep = f.getPath();
                    //                     RESClientPlugin.log("Adding dependency: " + dep);
                    //                     dependencies.add(dep);
                    //                  }

                    IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment());
                    IJavaProject projectDependency = JavaCore.create(p);
                    IClasspathEntry[] cp = projectDependency.getRawClasspath();

                    classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile());
                    classpath.add(projectDependency.getOutputLocation().toString());

                    RESClientPlugin.log("Populating files from: " + p.getName());
                    calculateDependencies(cp, p);

                } else if (tipo == IClasspathEntry.CPE_SOURCE) {

                    File f = new File(dependency);
                    classpathFiles.add(f);
                    RESClientPlugin.log("Adding source: " + dependency);

                } else if (tipo == IClasspathEntry.CPE_VARIABLE) {

                    IClasspathEntry[] clpe = new IClasspathEntry[1];
                    clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry);
                    if (clpe[0] != null) {
                        RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString());
                        calculateDependencies(clpe, project);
                    }

                } else if (tipo == IClasspathEntry.CPE_CONTAINER) {

                    if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER")
                            || cpEntry.getPath().toOSString().contains("requiredPlugins")) {
                        continue;
                    }

                    IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp);
                    IClasspathEntry[] entradas = cc.getClasspathEntries();

                    RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString());
                    calculateDependencies(entradas, project);

                }
            }
        }
    } catch (JavaModelException e) {
        RESClientPlugin.log(e);
    }

    for (String path : classpath) {
        RESClientPlugin.log("Classpath: " + path);
    }
    for (File file : classpathFiles) {
        RESClientPlugin.log("Classpath file: " + file.getAbsolutePath());
    }
}

From source file:fede.workspace.eclipse.composition.copy.exporter.JavaClassRefExporter.java

License:Apache License

protected Map<IPath, FolderExportedContent> findLocations(FolderExportedContent folderContent,
        String exporterType) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem());

    Map<IPath, FolderExportedContent> outputLocations = new HashMap<IPath, FolderExportedContent>();
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();

    if (exporterType.equals(JAVA_REF_EXPORTER_TYPE)) {
        for (IClasspathEntry entry : rawClasspath) {
            if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE)
                continue;

            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputPath = entry.getOutputLocation();
                if (outputPath == null)
                    outputPath = javaProject.getOutputLocation();

                outputLocations.put(getRelativePath(outputPath), folderContent);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath outputPath = entry.getPath();
                if (outputPath != null)
                    outputLocations.put(getRelativePath(outputPath), folderContent);
            }//  ww  w . j  a  va  2s . co m
        }
    } else {
        for (IClasspathEntry entry : rawClasspath) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputPath = entry.getPath();
                if (outputPath != null)
                    outputLocations.put(getRelativePath(outputPath), folderContent);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath outputPath = entry.getSourceAttachmentPath();
                if (outputPath != null)
                    outputLocations.put(getRelativePath(outputPath), folderContent);
            }
        }
    }
    return outputLocations;
}

From source file:fede.workspace.eclipse.composition.java.JavaProjectExporter.java

License:Apache License

/**
 * Updates an existing packaged binary version of the content of the item in
 * this project./*from www  . j  a  v  a 2s  .  c om*/
 * 
 * Scans all output directories of the java project and updates all modified
 * classes in the packaged item version.
 * 
 * If no resource delta is specified all the binary contents are copied to
 * the packaged version.
 * 
 * @param monitor
 *            the monitor
 * @param eclipseExportedContent
 *            the eclipse exported content
 * @param projectDelta
 *            the project delta
 * @param exporterType
 *            the exporter type
 * 
 * @throws CoreException
 *             the core exception
 */
@Override
protected void exportItem(EclipseExportedContent eclipseExportedContent, IResourceDelta projectDelta,
        IProgressMonitor monitor, String exporterType) throws CoreException {

    /*
     * skip empty notifications
     */
    if ((projectDelta != null) && (projectDelta.getKind() == IResourceDelta.NO_CHANGE)) {
        return;
    }

    /*
     * Verify this item is actually hosted in a Java Project
     */
    if (!JavaProjectManager.isJavaProject(MelusineProjectManager.getProject(getItem()))) {
        return;
    }

    IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem());

    /*
     * TODO We scan all output directories, we should only scan the output
     * directory associated with the item.
     * 
     * We need to handle mapping variants in which there are many composites
     * in a single java project, this is the case for example when a
     * composite has parts that are themselves java composites.
     */
    Set<IPath> outputLocations = new HashSet<IPath>();
    for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) {
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            continue;
        }

        IPath outputPath = entry.getOutputLocation();
        if (outputPath == null) {
            outputPath = javaProject.getOutputLocation();
        }

        outputLocations.add(getRelativePath(outputPath));
    }

    Scanner scanner = new Scanner(eclipseExportedContent);
    for (IPath outputPath : outputLocations) {
        IFolder outputRoot = getFolder(outputPath);
        IResourceDelta outputDelta = (projectDelta != null)
                ? projectDelta.findMember(outputRoot.getProjectRelativePath())
                : null;

        // If no modification of the output location just skip it
        if ((projectDelta != null) && (outputDelta == null)) {
            return;
        }

        scanner.scan(outputRoot, outputDelta, monitor);
    }
}

From source file:fr.imag.adele.cadse.builder.iPojo.IPojoBuilder.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from w  w w.j av  a 2 s  . c o  m*/
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    IJavaProject jp = JavaCore.create(getProject());

    IProject directoryProject = getProject();

    IFile manifestFile = directoryProject.getFile(new Path("META-INF/MANIFEST.MF"));
    if (!manifestFile.exists()) {
        manifestFile = directoryProject.getFile(new Path("src/main/resources/META-INF/MANIFEST.MF"));
        if (!manifestFile.exists()) {
            manifestFile = directoryProject.getFile("sources/main/resources/META-INF/MANIFEST.MF");
        }
        if (!manifestFile.exists()) {
            return new IProject[0];
        }
    }
    IFile metadataFile = directoryProject.getFile("metadata.xml");
    if (!metadataFile.exists()) {
        metadataFile = directoryProject.getFile(new Path("src/main/resources/metadata.xml"));
        if (!metadataFile.exists()) {
            metadataFile = directoryProject.getFile(new Path("sources/main/resources/metadata.xml"));
        }
        if (!metadataFile.exists()) {
            metadataFile = null;
        }
    }
    try {
        IContainer outClasses = (IContainer) ResourcesPlugin.getWorkspace().getRoot()
                .findMember(jp.getOutputLocation());
        EclipsePojoization p = new EclipsePojoization();
        p.setOutClasses(outClasses);
        p.monitor = monitor;
        MarkerIpojoProblem.unmark(getProject());

        p.directoryPojoization(outClasses.getLocation().toFile(),
                metadataFile == null ? null : metadataFile.getLocation().toFile(),
                manifestFile.getLocation().toFile());

        showErrors(getProject(), p);

        getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);

    } catch (Throwable e) {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
    }
    return new IProject[0];
}

From source file:fr.imag.adele.cadse.cadseg.menu.ExportBundlePagesAction.java

License:Apache License

@Override
public void doFinish(UIPlatform uiPlatform, Object monitor) throws Exception {
    super.doFinish(uiPlatform, monitor);
    IProgressMonitor pmo = (IProgressMonitor) monitor;
    try {// w  w  w  . ja v  a 2s .  c  o  m
        EclipsePluginContentManger project = (EclipsePluginContentManger) cadsedef.getContentItem();
        pmo.beginTask("export cadse " + cadsedef.getName(), 1);

        String qname = cadsedef.getQualifiedName();
        String qname_version = "";
        String version = "";
        IJavaProject jp = project.getMainMappingContent(IJavaProject.class);
        IProject eclipseProject = project.getProject();
        IPath eclipseProjectPath = eclipseProject.getFullPath();

        // jp.getProject().build(kind, pmo)
        IPath defaultOutputLocation = jp.getOutputLocation();

        IPath manifestPath = new Path(JarFile.MANIFEST_NAME);
        HashSet<IPath> excludePath = new HashSet<IPath>();
        excludePath.add(eclipseProjectPath.append(manifestPath));
        excludePath.add(eclipseProjectPath.append(".project"));
        excludePath.add(eclipseProjectPath.append(".classpath"));
        excludePath.add(eclipseProjectPath.append("run-cadse-" + cadsedef.getName() + ".launch"));
        excludePath.add(eclipseProjectPath.append(".melusine.ser"));
        excludePath.add(eclipseProjectPath.append(".melusine.xml"));

        Manifest mf = new Manifest(eclipseProject.getFile(manifestPath).getContents());
        File pf = new File(file, qname + ".jar");
        File sourceDir = new File(file, qname + ".Source");

        if (tstamp) {
            Date d = new Date(System.currentTimeMillis());
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
            String timeStamp = "v" + formatter.format(d);

            version = mf.getMainAttributes().getValue(OsgiManifest.BUNDLE_VERSION);
            String[] partVersion = version.split("\\.");
            if (partVersion.length == 4) {
                version = version + "-" + timeStamp;
            } else {
                version = version + "." + timeStamp;
            }
            mf.getMainAttributes().putValue(OsgiManifest.BUNDLE_VERSION, version);
            pf = new File(file, qname + "_" + version + ".jar");
            qname_version = qname + "_" + version;
            sourceDir = new File(file, qname + ".Source_" + version);
        }

        JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(pf), mf);
        HashMap<IFile, IPath> files = new HashMap<IFile, IPath>();

        IWorkspaceRoot eclipseRoot = eclipseProject.getWorkspace().getRoot();
        IContainer classesFolder = (IContainer) eclipseRoot.findMember(defaultOutputLocation);
        addFolder(files, excludePath, classesFolder, Path.EMPTY);

        IClasspathEntry[] classpaths = jp.getRawClasspath();
        for (IClasspathEntry entry : classpaths) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                if (entry.getOutputLocation() != null) {
                    classesFolder = (IContainer) eclipseRoot.findMember(entry.getOutputLocation());
                    addFolder(files, excludePath, classesFolder, Path.EMPTY);
                }
                IPath sourcePath = entry.getPath();
                excludePath.add(sourcePath);
                continue;
            }
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {

            }
        }

        addFolder(files, excludePath, eclipseProject, Path.EMPTY);
        pmo.beginTask("export cadse " + cadsedef.getName(), files.size());

        Set<IFile> keySet = new TreeSet<IFile>(new Comparator<IFile>() {
            public int compare(IFile o1, IFile o2) {
                return o1.getFullPath().toPortableString().compareTo(o2.getFullPath().toPortableString());
            }
        });
        keySet.addAll(files.keySet());
        for (IFile f : keySet) {
            IPath entryPath = files.get(f);
            pmo.worked(1);
            try {
                ZipUtil.addEntryZip(outputStream, f.getContents(), entryPath.toPortableString(),
                        f.getLocalTimeStamp());
            } catch (Throwable e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        outputStream.close();
        if (deleteOld) {
            File[] childrenFiles = file.listFiles();
            if (childrenFiles != null) {
                for (File f : childrenFiles) {
                    if (f.equals(pf)) {
                        continue;
                    }

                    String fileName = f.getName();

                    if (!fileName.startsWith(qname)) {
                        continue;
                    }
                    FileUtil.deleteDir(f);
                }
            }
        }
        if (exportSource && tstamp) {
            sourceDir.mkdir();
            File srcDir = new File(sourceDir, "src");
            srcDir.mkdir();
            File mfDir = new File(sourceDir, "META-INF");
            mfDir.mkdir();
            File modelDir = new File(srcDir, qname_version);
            modelDir.mkdir();
            FileUtil.setFile(new File(sourceDir, "plugin.xml"),
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.0\"?>\n"
                            + "<plugin>\n" + "<extension point=\"org.eclipse.pde.core.source\">\n"
                            + "<location path=\"src\"/>\n" + "</extension>\n" + "</plugin>\n");
            String vendor_info = CadseDefinitionManager.getVendorNameAttribute(cadsedef);
            FileUtil.setFile(new File(mfDir, "MANIFEST.MF"),
                    "Manifest-Version: 1.0\n" + "Bundle-ManifestVersion: 2\n" + "Bundle-SymbolicName: " + qname
                            + ".Source;singleton:=true\n" + "Bundle-Version: " + version + "\n"
                            + "Bundle-Localization: plugin\n" + "Bundle-Vendor: " + vendor_info + "\n"
                            + "Bundle-Name: " + qname + "\n");

            excludePath.clear();
            files.clear();
            classesFolder = (IContainer) eclipseRoot.findMember(defaultOutputLocation);
            excludePath.add(classesFolder.getFullPath());
            for (IClasspathEntry entry : classpaths) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    if (entry.getOutputLocation() != null) {
                        classesFolder = (IContainer) eclipseRoot.findMember(entry.getOutputLocation());
                        addFolder(files, excludePath, classesFolder, Path.EMPTY);
                    }
                    IPath sourcePath = entry.getPath();
                    excludePath.add(sourcePath);
                    ZipUtil.zipDirectory(eclipseRoot.findMember(sourcePath).getLocation().toFile(),
                            new File(modelDir, "src.zip"), null);
                    continue;
                }
            }
            addFolder(files, excludePath, eclipseProject, Path.EMPTY);
            keySet = files.keySet();
            for (IFile f : keySet) {
                IPath entryPath = files.get(f);
                try {
                    FileUtil.copy(f.getLocation().toFile(), new File(modelDir, entryPath.toOSString()), false);
                } catch (Throwable e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }
    } catch (RuntimeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {

    }
}